// $Id
// Missionphase		: PACS PV Phase
//
// Purpose :		Fully flexible spectrometer calibration block during PacsSlew
// Author		 : P Royer
//
// Arguments		:
//
// Prerequisite 	: PACS does not need to be on nor setup for spectroscopy
//
// Description		: Uses OBCP 35 and performs AOT prologue and epilogue
// 
// Comments		:
//
// Dependencies		: CONF_SPEC_params : The detector biases are read from column "Normal0"
//
// Version		: 1.2
// 
// History		:  1.0 19-Mar-2009 PR Creation from PacsCal_PacsSpecSlewCal35_Flex
// 		   1.1 07-May-2009 PR Upgrade ramp_fit_alg (match FS database) & nb_raw as parameters
//			                      Add parameter no_gratmove
//		   1.2  23-Jul-2009 PR add parameter initial_delay (see also PacsSpecSlewCal35_Flex). SPR PACS-1857
//                                                   29-Jul-2009 PR update history : last change referred to SPR PACS-1857 (SCR PHS-1128)
//
obs PacsEng_PacsSpecSlewCal35_Flex {
    /* Needed variables to call PacsSpecSlewCal */
    /* FW, WAVELENGTH & OBCP parameters */
    double[] waves = [60.0]; // Wavelengths
    int order = 2;
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int nb_up_dn = 1; //       	     nb_up_down  	   	OBCP35,DMC19 DMCSeq. P#1
    int nb_grat_steps = 16; //	     nb_grating_steps  	   	OBCP35,DMC19 DMCSeq. P#2
    int nb_cycles_grat = 2; //	     nb_chop_cycles_per_gratpos OBCP35,DMC19 DMCSeq. P#4
    int nb_ramps_grat_pos = 1; //nb_ramps_per_gratpos  		OBCP35,DMC19 DMCSeq. P#6
    int initial_delay = 30; // Fixed delay (for drifts) at the start of the OBCP (added to grat_(start)_time)
    bool no_gratmove = false; // false: gratstep read from CALU. True: gratstep forced to 0
    /* CRE & SPU PARAMETERS */
    int capa_blu = 12;
    int capa_red = 12;
    int nb_rdouts_ramp_blu = 64;
    int nb_rdouts_ramp_red = 64;
    int nb_rdouts_subramp_blu = 16;
    int nb_rdouts_subramp_red = 16;
    int ramp_fit_alg_blu = 1;
    int ramp_fit_alg_red = 1;
    int nb_raw_blu = 3;
    int nb_raw_red = 3;
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    bool verbose = true;
}{
    // FIXED CRE & SPU Parameters
    int glitch_det_blu = 1;
    int glitch_det_red = 1;
    int bias_d_blu_mV = ilookup("CONF_SPEC_params","bias_d_blu","Normal0");
    int bias_d_red_mV = ilookup("CONF_SPEC_params","bias_d_red","Normal0");
    int bias_r_blu_mV = ilookup("CONF_SPEC_params","bias_r_blu","Normal0");
    int bias_r_red_mV = ilookup("CONF_SPEC_params","bias_r_red","Normal0");
    // FIXED OBCP Parameters
    // OBCP 19 DMCSeq. P#3
    string order_str = "" + order;
    int grat_step_up = ilookup("SPEC_BAND_params",order_str,"HI");
    if(no_gratmove) {
        grat_step_up = 0;
    }
    // OBCP 19 DMCSeq. P#11
    int grat_step_dn = -1 * grat_step_up;
    // OBCP 19 DMCSeq. P#5 == P#9
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","SPEC","pos_CS1");
    // OBCP 19 DMCSeq. P#7 == P#10
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    // OBCP 19 DMCSeq. P#8
    int nb_cycles_cal = 0;
    // Synchronize on this detector 1:Blue 2:Red
    int detector = 1;
    // Chopped default position
    int chop_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int grat_pos = grat_park;
    // PacsSpecSlewCal_Flex parks the grating already
    //
    // compiting time for slw / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Verification for grating and chopper hard limits
    //double chopthrow = 30.0;
    //int[] gratpos = [0];
    //Pacs_HardLimitsCheck(gratpos,chopthrow);
    // Calibration time during slew
    // SPEC parameters for BLU and RED    
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{capa_blu,nb_rdouts_ramp_blu,nb_rdouts_subramp_blu,comp_mode_blu,glitch_det_blu,ramp_fit_alg_blu,nb_raw_blu,bias_r_blu_mV,bias_d_blu_mV}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{capa_red,nb_rdouts_ramp_red,nb_rdouts_subramp_red,comp_mode_red,glitch_det_red,ramp_fit_alg_red,nb_raw_red,bias_r_red_mV,bias_d_red_mV}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{nb_up_dn,nb_grat_steps,grat_step_up,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,nb_cycles_cal,detector,chop_def}];
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    //
    //
    //Initial hold
    int tih = duration(WriteOBSID($OBSID));
    //int tslewmin = 0;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int tepilog = duration(SPEC_aot_epilogue(grat_pos,grat_park,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(PacsSpecSlewCal35_Flex(verbose,confSPECblu,confSPECred,confOBCP,initial_delay,doPROLOG,waves,fltPOS,order));
    if(verbose) {
        debug_print("Duration of PacsSpecSlewCal_Flex" + tp + "sec");
    }
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
    debug_print("ts: " + ts);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            int tNOW = time();
            // 
            WriteOBSID($OBSID);
            data_rate(120.0);
            if(verbose) {
                debug_print("WriteOBSID at :" + tNOW + " sec");
            }
            tNOW = time();
            if(verbose) {
                debug_print("WriteOBSID ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                tNOW = time();
                PacsSpecSlewCal35_Flex(verbose,confSPECblu,confSPECred,confOBCP,initial_delay,doPROLOG,waves,fltPOS,order);
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 5) {
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold starts at :" + tNOW + " sec");
                    }
                    SPEC_aot_epilogue(grat_pos,grat_park,verbose);
                    data_rate(0.0);
                    WriteEndID();
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold ends at :" + tNOW + " sec");
                    }
                }
            }
        }
    }
    // End of Observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       : Exercise OBCP for chopper scan in photometry
//                  
//                 
//
// TCL author    : N/A
// TCL file      : N/A
// CUS author    : TM
// Script file   : OBCP_chop_scan_phot_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Exercise OBCP for chopper scan in photometry
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version      1.0
// History      0.1 09-oct-2006 TM
//              0.2 10-nov-2006 Calls PHOT_spu_reset (used to be PACS_spu_reset)
//		1.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
obs PacsEng_OBCP_chop_scan_phot {
    /* Needed variables to call PacsEng_OBCP_chop_scan_phot                        */
    int nb_up_down = 1; // P#1  number of up-down seqs.
    int nb_rdouts = 80; // P#2  number of readouts on step
    int nb_steps_up = 163; // P#3  number of steps up
    int nb_steps_dn = 163; // P#4  number of steps down
    int step_up = 287; // P#5  relative move up
    int step_dn = -287; // P#6  relative move down
    int detector = 4; // Detector to SYNCH on
    int comp_mode_blu = 0; // "Blue" compression
    int comp_mode_red = 0; // "Red" compression
    int chop_start = -23500; // Chopper start position
    int chop_def = 648; // Chopper default position
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_OBCP_chop_scan_phot                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_OBCP_chop_scan_phot(nb_up_down,nb_rdouts,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,comp_mode_blu,comp_mode_red,chop_start,chop_def)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_OBCP_chop_scan_phot(nb_up_down,nb_rdouts,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,comp_mode_blu,comp_mode_red,chop_start,chop_def);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PHOT_aot_epilogue.txt,v 1.2 2007/04/25 15:14:03 dcesarsk Exp $ 
// Missionphase  : 
// Purpose       : Stop PHOTOmeter observations at end of AOT
//                  
// TCL author    : 
// TCL file      : 
// CUS author    : Diego Cesarsky
// Script file   : PHOT_aot_epilogue.txt 
//
// Input arguments
// Type Name           Default   Description
//
// Description   : Not much for now (just STOP SPU)
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      :
//
// History       : 0.1 19-apr-2006 First creation
//   		 : 1.0 VDO implement data rates 
//
procedure PHOT_aot_epilogue_Data_Rates {
}{
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    data_rate(0.0);
    // Sync the bus (function duration will get the "true" duration)
    sync();
    // end of procedure
}

// CVS comments  : $Id: PacsPhotDefaults.txt,v 1.7 2008/05/06 13:34:53 vanessa Exp $ 
// Purpose       : Fill index=0 of OBCP and PHOTxxx tuples with known
//                 sensible default values
//
// CUS author    : DAC
// Script file   : PacsPhotDefaults_PV.txt 
//
// Input arguments
// type           name     Description
// string         srcID    HSPOT define source ID
//
// Return values
// Type    Name                  Description
// tuple   confPHOTx & confOBCP  electronics and OBCP default parameters
//
// Description   : Give default values to tuples OBCP and PHOT. May
// use more information from yet to be created CAL-U files. So far
// only "throw" (HSPOT defined) appears necessary as a call argument
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-may-2008 DAC. Based on PacsPhotDefaults
//                 Added name of PHOT configuration AL file
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} procedure PacsPhotDefaults_PV {
    string srcID = "pointSRC" in ["pointSRC","smallSRC","largeSRC"]; // SourceID
    string primePar = "Prime" in ["Prime","Parallel"]; // Observing mode
    string confphotparams = "CONF_PHOT_params"; //Configuration cal file name
    bool isBrightPacs = false;
    bool verbose = true; // Generate bla-bla
}{
    // Define variables to be used here
    {int,int,int,int,int,int,int,int,int} confPHOTblu = {0,0,0,0,0,0,0,0,0};
    {int,int,int,int,int,int,int,int,int} confPHOTred = {0,0,0,0,0,0,0,0,0};
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    // Open CAL-U with compression, raw pixels, etc. information
    // Verbose report
    if(verbose) {
        debug_print("%%PacsPhotDefaults: isBright: " + isBrightPacs);
    }
    if(!isBrightPacs) {
        int gain_red = ilookup(confphotparams,"gain_red",primePar);
    } else {
        gain_red = ilookup(confphotparams,"gain_red","BrightPacs");
    }
    confPHOTred{0} = gain_red;
    if(!isBrightPacs) {
        int gain_blu = ilookup(confphotparams,"gain_blu",primePar);
    } else {
        gain_blu = ilookup(confphotparams,"gain_blu","BrightPacs");
    }
    confPHOTblu{0} = gain_blu;
    if(!isBrightPacs) {
        int comp_mode_red = ilookup(confphotparams,"comp_mode_red",primePar);
    } else {
        comp_mode_red = ilookup(confphotparams,"comp_mode_red","BrightPacs");
    }
    confPHOTred{3} = comp_mode_red;
    if(!isBrightPacs) {
        int comp_mode_blu = ilookup(confphotparams,"comp_mode_blu",primePar);
    } else {
        comp_mode_blu = ilookup(confphotparams,"comp_mode_blu","BrightPacs");
    }
    confPHOTblu{3} = comp_mode_blu;
    if(!isBrightPacs) {
        int nb_raw_red = ilookup(confphotparams,"nb_raw_red",primePar);
    } else {
        nb_raw_red = ilookup(confphotparams,"nb_raw_red","BrightPacs");
    }
    confPHOTred{6} = nb_raw_red;
    if(!isBrightPacs) {
        int nb_raw_blu = ilookup(confphotparams,"nb_raw_blu",primePar);
    } else {
        nb_raw_blu = ilookup(confphotparams,"nb_raw_blu","BrightPacs");
    }
    confPHOTblu{6} = nb_raw_blu;
    // Chopper and grating expected at their default positions
    string calU = "SPEC_MEC_Defaults";
    int chop_def = ilookup(calU,"Photometry","chopper");
    confOBCP{17} = chop_def;
    // Position filter wheel at default position
    //   int fw_pos       = ilookup(calU,"Photometry","FW");
    // Initialize to don't care/don't know
    int fw_pos = 1;
    confOBCP{19} = fw_pos;
    int nb_cycles_obs_cal = 1;
    confOBCP{0} = nb_cycles_obs_cal;
    int nb_SRC_OFF = 1;
    confOBCP{3} = nb_SRC_OFF;
    int nb_rdouts_plateau = 4;
    confOBCP{4} = nb_rdouts_plateau;
    int nb_CS1_CS2 = 0;
    confOBCP{5} = nb_CS1_CS2;
    // Read chopper positions [arcsec] and convert to ENG units
    calU = "PHOT_CHOP_params";
    string convU = "PHOT_CHOP_sky";
    double auxSRC = dlookup(calU,srcID,"SRC");
    int onSRC = PacsReadChopSky(convU,auxSRC);
    double auxREF1 = dlookup(calU,srcID,"REF1");
    int onREF1 = PacsReadChopSky(convU,auxREF1);
    double auxREF2 = dlookup(calU,srcID,"REF2");
    int onREF2 = PacsReadChopSky(convU,auxREF2);
    // Report settings if verbose
    if(verbose) {
        debug_print("++PhotDefaults CHOPPER: " + auxSRC + " [arcsec] -> " + onSRC + " [ENG]");
        debug_print("++PhotDefaults CHOPPER: " + auxREF1 + " [arcsec] -> " + onREF1 + " [ENG]");
        debug_print("++PhotDefaults CHOPPER: " + auxREF2 + " [arcsec] -> " + onREF2 + " [ENG]");
    }
    confOBCP{12} = onSRC;
    confOBCP{13} = onREF1;
    confOBCP{14} = onREF2;
    // chop_pos_CS1     = confOBCP[0]{15};
    // chop_pos_CS2     = confOBCP[0]{16};
    int detector = 1;
    confOBCP{18} = detector;

    return {confPHOTblu,confPHOTred,confOBCP};
}

// Missionphase  : EQM IMT
//
// Purpose	: Record data in BOL-C test pattern mode
//
// Author	: Bart Vandenbussche
// CUS script	: PHOT_TestPattern
// CVS file	: 
//
// Arguments	: duration : time to stay in test pattern mode
//
// Description	: Switch to BOL-C HK+test pattern data mode
//                     wait <time_in_testmode> seconds
//                     Switch to BOL-C HK + bolometer data mode 
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on with configured BOLC
//                 
// Comments	: 
//
// Version	: 1.0
//               
// History	: 1.0 13-apr-2005 BV - First version
//
block PHOT_TestPattern PACS 204 {
    int time_in_testmode = 60; //time to stay in test pattern mode (sec)
}{
    // Register with environment
    WriteBBID($BBID);
    Pacs_BOLC_SET_DATA_MODE("Test_Pat_HK");
    delay(time_in_testmode);
    Pacs_BOLC_SET_DATA_MODE("Bolo_HK");
    // Mark End of Block
    WriteEndBB();
}

// Missionphase  : FM-ILT
//
// Purpose       : Prepare MEC for spectrometer, including filterwheel,
//                 chopper, grating and calibration sources  *REDUNDANT parameters*
//                  
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : This script will switch on and set all required
//                 REDUNDANT parameters for 
//                 - chopper
//                 - spectrometry filter wheel
//                 - grating,  and
//                 - calibration sources.
//                 This script should be executed just after the
//                 switch-on procedure and the bolometer setup
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version      10
// History
//       1.0  BV 11-04-2007 First version based on SPEC_dmc_setup
//       1.1 DAC 20-jun-2007 Call CONF_spec_fltw_redundant
procedure SPEC_dmc_setup_redundant {
    string spec_fltw_id = "POS A" in ["POS A","POS B"]; // Photometer filter ID
    int chop_def_pos = 0; // Chopper default position
    double temp_CS1 = 48.0; //  Temperature 55K for the PACS calibration source 1 
    double temp_CS2 = 58.0; //  Temperature 60K for the PACS calibration source 2
}{
    //-------------------
    // CHOPPER
    // Configure diagnostics HK for chopper
    // Read out every 5 ms
    int diag_hk_period_cho = 5;
    // DMC_CHOP_CTRL_ST  209
    // DMC_CHOP_CUR_POS  244
    // DMC_CHOP_SETPOIN  245
    // DMC_CHOP_TARGET   246
    // DMC_CHOP_PID_ERR  247
    // DMC_CHOP_PID_ACC  248
    // DMC_CHOP_MAX_DIT  249
    // DMC_CHOP_OUTPUT   258
    // DMC_CHOPPER_TEMP  407
    // DMC_CHOP_VA       557
    // DMC_CHOP_IA       561
    // DMC_CHOP_VB       565
    {int}[] parlist_cho = [{209},{244},{245},{246},{247},{248},{249},{258},{407},{557},{561},{565},{0xffff}];
    int[] aux_cho = [209,244,245,246,247,248,249,258,407,557,561,565,0xffff];
    int check_sum_cho = checksum("int",aux_cho);
    int diag_hk_length_cho = 13;
    Pacs_DMC_WRT_DIAG_HK_LIST(diag_hk_length_cho,parlist_cho,check_sum_cho);
    Pacs_DMC_START_DIAG_HK(diag_hk_period_cho);
    // DMC_WRT_CHOP_CONF_PAR (now modified for 20 parameters)
    CONF_chopper("CONFChopper","red_sky");
    CHOP_on_off("ON");
    Pacs_DMC_MOVE_CHOP_ABS(chop_def_pos);
    delay(1);
    //
    Pacs_DMC_STOP_DIAG_HK();
    //-------------------------
    // PACS CALIBRATION SOURCES
    CONF_cs("Both");
    CS_on_off("CS1","ON");
    CS_temp("CS1",temp_CS1);
    CS_on_off("CS2","ON");
    CS_temp("CS2",temp_CS2);
    // Grating
    // NOTE: The grating default position is set in CONF_grating
    int diag_hk_period_grat = 1;
    // Max number of requested diag HK parameters = 16
    // (including the last one, which is always forced to the same value)
    //
    //     DMC_GR_IND_SINE        539
    //     DMC_GR_IND_COS         540
    //     DMC_FWGRAT_HALLA       256
    //     DMC_FWGRAT_HALLB       257
    //     DMC_FW_GR_VMOTA        556
    //     DMC_FW_GR_VMOTB        564
    //     DMC_FW_GR_IMOTA        560
    //     DMC_FW_GR_IMOTB        567
    //     DMC_GRAT_CTRL_ST       208
    //     DMC_GRAT_CUR_POS       250
    //     DMC_GRAT_SETPOIN       251
    //     DMC_GRAT_TARGET        252
    //     DMC_GRAT_PID_ERR       253
    //     DMC_GRAT_OUTPUT        452
    //     DMC_GRAT_IND_READ      512
    {int}[] list_tuple = [{539},{540},{256},{257},{556},{564},{560},{567},{208},{250},{251},{252},{253},{452},{512},{0xffff}];
    int[] list_int = [539,540,256,257,556,564,560,567,208,250,251,252,253,452,512,0xffff];
    int chksum = checksum("int",list_int);
    int nbParams = length(list_int);
    Pacs_DMC_WRT_DIAG_HK_LIST(nbParams,list_tuple,chksum);
    delay(1);
    Pacs_DMC_START_DIAG_HK(diag_hk_period_grat);
    CONF_grating("CONFGrat","FMILT_R_Fast");
    // Stop HK
    Pacs_DMC_STOP_DIAG_HK();
    //-------------------
    // FILTERWHEEL
    // Configure diagnostics HK for filterwheel
    // Read out every 5 ms
    int diag_hk_period_fw = 5;
    // DMC_WRT_DIAG_HK_LIST
    // DMC_FW_SPEC_CTRL  210
    // DMC_FWGRAT_HALLA  256
    // DMC_FWGRAT_HALLB  257
    // DMC_FWSP_CUR_POS  255                    
    // DMC_FPU_T_SEN_ST  404
    // DMC_FW_SPEC_TEMP  405                    
    // DMC_FW_GR_VMOTA   556
    // DMC_FW_GR_IMOTA   560
    // DMC_FWSPEC_POS_A  555
    // DMC_FW_GR_VMOTB   564
    // DMC_FW_GR_IMOTB   567
    // DMC_FWSPEC_POS_B  559
    {int}[] parlist_fw = [{210},{256},{257},{255},{404},{405},{556},{560},{555},{564},{567},{559},{0xffff}];
    int[] aux_fw = [210,256,257,255,404,405,556,560,555,564,567,559,0xffff];
    int check_sum_fw = checksum("int",aux_fw);
    int diag_hk_length_fw = 13;
    Pacs_DMC_WRT_DIAG_HK_LIST(diag_hk_length_fw,parlist_fw,check_sum_fw);
    Pacs_DMC_START_DIAG_HK(diag_hk_period_fw);
    // CONFigure controller
    CONF_spec_fltw_redundant();
    // and move
    SPEC_fltw_move(spec_fltw_id);
    // Move to demanded position
    Pacs_DMC_STOP_DIAG_HK();
}

// CVS comments  : $Id
// Purpose       : Issue PACS commands at each raster position in order to
//                 observe all the HSPOT defined spectral lines
//
// CUS author    : DAC
// Script file   : PacsSpecCommand.txt 
//
// Input arguments
// Type                                                 Description
// {int,int,int,int,int,int,int,int,int}[] confSPECblu  BLUE SPU parameters
// {int,int,int,int,int,int,int,int,int}[] confSPECred  RED  SPU parameters
// {int,int,int,int,int,int,int,int,int,int,int,
//  int,int,int,int,int,int,int,int,int}[] confOBCP     OBCP parameters
// bool verbose                                         Print debug information
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per spectral line
//
// Description   : Loops over all wavelengths at current raster point. If raster
// identifier "rast_pnt" is a negative number, it means that we are in the
// "nodding" phase of "rast_pnt". Chopper pattern ABBA
// IMPORTANT NOTE: the duration for the first raster position
//                 may be different than the following raster points, due to the
//                 fact that we start at the default configuration whereas for
//                 any subsequent raster point, we start from where we ended at
//                 raster_point-1.
// NOTE: starting with version 3.0, grating is left at start position used by
//       first line in OBCP. This minimizes grating movements within a raster
//       or when nodding
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 3.0
// History       : 
// 0.1 DAC  6-May-2005
// 1.0 11-mar-2009 VD OBCP35
// 1.1 23-mar-2009 remove PacsSpecConfSet ... not allowed
// 2.x 24-feb-2010 VD PHS-1285 for Ranges .. could be actually for SED?
//                    add bool dither (if(sed) dither = false)
// 2.2 14-Apr-2010 VD PHS-1383 ...
// 3.0 28=apr-2010 VD PHS-1388/7 CLONED for OBCP28_dither
// 4.0 22-Nov-2010 VD PACS-3169 error grat time
//
int[][] procedure PacsSpecCommandOBCP28_dither {
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}]; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}]; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]; // OBCP parameters
    bool dither = false;
    bool verbose = true; // Print debug information
}{
    // Create array of durations; one duration per line
    int[][] time_array = [[0,0,0,0,0]];
    // Start grating position should be the 1st line to observe
    // later it will be commanded elsewhere
    int grat_def_pos = confOBCP[1]{8};
    // How many lines are we supposed to observe?
    int nbLines = length(confOBCP) - 1;
    // ========================= LOOP on lines ===============================
    for(int loop2 = 1 .. nbLines) {
        int[] quantum_time_array = [0,0,0,0,0];
        int[] dither_time_array = [0,0,0,0,0];
        //   Long sequence to "unpack" contents of tuples
        int capa_blu = confSPECblu[loop2]{0};
        int nb_rdouts_ramp_blu = confSPECblu[loop2]{1};
        int nb_rdouts_subramp_blu = confSPECblu[loop2]{2};
        int comp_mode_blu = confSPECblu[loop2]{3};
        int glitch_det_blu = confSPECblu[loop2]{4};
        int ramp_fit_alg_blu = confSPECblu[loop2]{5};
        int nb_raw_blu = confSPECblu[loop2]{6};
        int bias_r_blu_mV = confSPECblu[loop2]{7};
        int bias_d_blu_mV = confSPECblu[loop2]{8};
        int capa_red = confSPECred[loop2]{0};
        int nb_rdouts_ramp_red = confSPECred[loop2]{1};
        int nb_rdouts_subramp_red = confSPECred[loop2]{2};
        int comp_mode_red = confSPECred[loop2]{3};
        int glitch_det_red = confSPECred[loop2]{4};
        int ramp_fit_alg_red = confSPECred[loop2]{5};
        int nb_raw_red = confSPECred[loop2]{6};
        int bias_r_red_mV = confSPECred[loop2]{7};
        int bias_d_red_mV = confSPECred[loop2]{8};
        // ahhh that is the one to save .. then set to 1 then recover
        // PHS-1285
        int nb_up_down = confOBCP[loop2]{0};
        int grat_step_up = confOBCP[loop2]{1};
        // PHS-1285
        // also t be used for the dither
        int grat_step_dn = confOBCP[loop2]{2};
        // int nb_SRC_OFF = confOBCP[loop2]{3};
        int nb_ramps_grat_pos = confOBCP[loop2]{4};
        int nb_ramps_cs = nb_ramps_grat_pos;
        int nb_CS1_CS2 = confOBCP[loop2]{5};
        // PHS-1285
        // this one does NOT change
        int nb_grat_step_up = confOBCP[loop2]{6};
        int nb_grat_step_dn = confOBCP[loop2]{7};
        // PHS-1285
        // this one will be dithered
        int grat_start_pos = confOBCP[loop2]{8};
        //   int grat_start_time       = confOBCP[loop2]{ 9};
        //   int grat_def_pos          = confOBCP[loop2]{10};
        //   int grat_def_time         = confOBCP[loop2]{11};
        int chop_pos_SRC = confOBCP[loop2]{12};
        int chop_pos_REF1 = confOBCP[loop2]{13};
        int chop_pos_REF2 = confOBCP[loop2]{14};
        int chop_pos_CS1 = confOBCP[loop2]{15};
        int chop_pos_CS2 = confOBCP[loop2]{16};
        int chop_def = confOBCP[loop2]{17};
        int detector = confOBCP[loop2]{18};
        int filterPOS = confOBCP[loop2]{19};
        //   Bias voltages (needed by SPEC_aot_prologue) are commanded in 
        //  (double) volts
        double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
        double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
        double bias_r_red = double(bias_r_red_mV) / 1000.0;
        double bias_d_red = double(bias_d_red_mV) / 1000.0;
        //   Call OBCP once per spectral line (local loop) 
        //   (this module is invoked once per per raster position)
        //   Grating movement facts and strategy:
        //   0-  OBCP starts with grating already at grat_start_pos (done by SlewCal) 
        //   1-  OBCP moves grating from grat_start_pos to grat_start_pos 
        //   1a- above operation takes grat_start_time = 0 seconds
        //   2-  perform all the CHOPPER, CAL, loops
        //   2a- above operation takes whatever time
        //   3-  at end, OBCP moves grating to grat_start_pos for 1st line
        //   3a- above operation takes grat_def_time
        //
        //   This is up-down scan. Hence grating ends at position grat_start_pos
        //   If we set grat_def_pos position to grat_start_pos  for the next line, 
        //   we reduce grat_start_time to 0 [sec] for all lines but the first.
        //   At end of line "n", place grating at the position expected by line 
        //   "n+1" for all lines but last. For last observed wavelength use 
        //   grat_def_pos to ensure that next cycle will start exactly as this one,
        //   i.e. with grating parked at grat_def_pos
        //   Leave the grating where it is, i.e. end-of-DMC position
        // 
        // PHS-1285: carefull this also NEEDS to be saved and dithered...
        // 
        int new_grat_def_pos = confOBCP[loop2]{8};
        //   The last observed line should leave the grating ready to start
        //   all over again
        //
        //PHS-1285 here we start looping on the dither
        //
        double ext_grat_blu_pos = double(new_grat_def_pos);
        if(loop2 == nbLines) {
            new_grat_def_pos = confOBCP[1]{8};
        }
        // will set quantum up_down to calU by default ..
        string key = "" + filterPOS;
        int quantum_up_down = ilookup("OBCP28params",key,"nb_up_down");
        int nb_grat_scan = nb_up_down / quantum_up_down;
        int save_nb_up_down = nb_up_down;
        if(dither) {
            if(nb_grat_scan > 1) {
                for(int loopDith = 0 .. nb_grat_scan - 1) {
                    int nbDith = loopDith + 1;
                    //  debug_print("loopDith: " + nbDith + "/" + nb_grat_scan);
                    // the funtion??
                    double grat_dither = double(loopDith) * (double(grat_step_up) / double(nb_grat_scan));
                    double ext_grat_bluEdge_shift = ext_grat_blu_pos - grat_dither;
                    grat_start_pos = iround(ext_grat_bluEdge_shift);
                    grat_def_pos = grat_start_pos;
                    new_grat_def_pos = grat_start_pos;
                    nb_up_down = quantum_up_down;
                    //   Starting times, viz. grat_time.
                    //   NOTE: grat_start_pos is in OBCP tuple {8}
                    int steps_start = grat_def_pos - grat_start_pos;
                    int grat_start_time = SPEC_grat_time(steps_start);
                    if(verbose) {
                        debug_print("OBCP28:Observing line/of:" + loop2 + "/" + nbLines);
                        debug_print("OBCP28:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_start_time);
                    }
                    //   Ending times, viz. grat_def_time
                    //   NOTE: DMC of OBCP28 leaves grating at start position
                    int steps_end = grat_start_pos - new_grat_def_pos;
                    int grat_def_time = SPEC_grat_time(steps_end);
                    if(verbose) {
                        debug_print("OBCP28:GratEnd   from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
                    }
                    //   Call OBCP28 with derived parameters 
                    // PHS-1285 
                    // this is in a loop for nb_up_down to become the dither
                    quantum_time_array = OBCP_grat_scan_nochop(nb_up_down,nb_grat_step_up,grat_step_up,grat_step_dn,nb_ramps_grat_pos,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,nb_ramps_grat_pos,nb_grat_step_dn,chop_def,detector,grat_start_pos,grat_start_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,grat_def_time,nb_rdouts_ramp_red);
                    for(int array = 0 .. 4) {
                        dither_time_array[array] = quantum_time_array[array] + dither_time_array[array];
                    }
                    //   Prepare the grating to be ready for the next wavelength
                    grat_def_pos = new_grat_def_pos;
                }
                time_array[loop2 - 1] = dither_time_array;
            } else {
                nb_up_down = save_nb_up_down;
                steps_start = grat_def_pos - grat_start_pos;
                grat_start_time = SPEC_grat_time(steps_start);
                if(verbose) {
                    debug_print("OBCP28:Observing line/of:" + loop2 + "/" + nbLines);
                    debug_print("OBCP28:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_start_time);
                }
                //   Ending times, viz. grat_def_time
                //   NOTE: DMC of OBCP35 leaves grating at start position
                steps_end = grat_start_pos - new_grat_def_pos;
                grat_def_time = SPEC_grat_time(steps_end);
                if(verbose) {
                    debug_print("OBCP28:GratEnd   from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
                }
                //   Call OBCP35 with derived parameters 
                // PHS-1285 
                // this is in a loop for nb_up_down to become the dither
                time_array[loop2 - 1] = OBCP_grat_scan_nochop(nb_up_down,nb_grat_step_up,grat_step_up,grat_step_dn,nb_ramps_grat_pos,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,nb_ramps_grat_pos,nb_grat_step_dn,chop_def,detector,grat_start_pos,grat_start_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,grat_def_time,nb_rdouts_ramp_red);
                //   Prepare the grating to be ready for the next wavelength
                // 
                grat_def_pos = new_grat_def_pos;
            }
        } else {
            nb_up_down = save_nb_up_down;
            //   Starting times, viz. grat_time.
            //   NOTE: grat_start_pos is in OBCP tuple {8}
            steps_start = grat_def_pos - grat_start_pos;
            grat_start_time = SPEC_grat_time(steps_start);
            if(verbose) {
                debug_print("OBCP28:Observing line/of:" + loop2 + "/" + nbLines);
                debug_print("OBCP28:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_start_time);
            }
            //   Ending times, viz. grat_def_time
            //   NOTE: DMC of OBCP35 leaves grating at start position
            steps_end = grat_start_pos - new_grat_def_pos;
            grat_def_time = SPEC_grat_time(steps_end);
            if(verbose) {
                debug_print("OBCP28:GratEnd   from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
            }
            //   Call OBCP35 with derived parameters 
            // PHS-1285 
            // this is in a loop for nb_up_down to become the dither
            time_array[loop2 - 1] = OBCP_grat_scan_nochop(nb_up_down,nb_grat_step_up,grat_step_up,grat_step_dn,nb_ramps_grat_pos,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,nb_ramps_grat_pos,nb_grat_step_dn,chop_def,detector,grat_start_pos,grat_start_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,grat_def_time,nb_rdouts_ramp_red);
            //   Prepare the grating to be ready for the next wavelength
            // 
            grat_def_pos = new_grat_def_pos;
            // End of nbLines loop
        }
    }
    // time_array is indexed [wavelength][durations]     
    if(verbose) {
        debug_print("CmdOBCP28 returns " + time_array);
    }
    //SPR1707 Add sync()
    sync();

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
//
// Purpose : just to execute Phot_prepareEMC_direct
//
// Author : Koryo Okumura / Thomas Mueller
//
// CUS script : procedure Phot_prepareEMC_direct_OBS
//
// Argument : None
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + CSs are cold (connected only to the slow drifting satellite L1-level)
//
// Description :
//
// Dependencies : None
//
// Comments : 
//
// Version 	: 1.0
//History	: 0.1 Mon Jun 18 2007
//		: 1.0 translated into PV scipt VDP
//
obs PacsEng_Phot_prepareEMC_direct {
    /* Needed variables to call PacsEng_Phot_prepareEMC_direct                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_prepareEMC_direct                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Phot_prepareEMC_direct()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Phot_prepareEMC_direct();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
// Script        : PACS_Chopper_uk_move_18000_ast_OBS.cus
//
//
// Missionphase  : IST Chopper Day
//
// Purpose	: Move chopper to absolute position  
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-18000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched on and Chopper switched on.
//                 
// Comments	: This script is based on the commanding during the CQM/FM ILT.
//
// Version	: 4.0	
// 
// History 	: 1.0 02-03-07 HD. Script to do simple chopper cycle 
//
//		  2.0 05-07-07 HD. IST Chopper Day
//		  3.0 05-07-07 MN. edited for SVT/PV conformance
//                4.0  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Chopper_uk_move_18000_ast {
    /* Needed variables to call PacsEng_Chopper_uk_move_18000_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Chopper_uk_move_18000_ast                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Chopper_uk_move_18000_NoConf_ast()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Chopper_uk_move_18000_NoConf_ast();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_CS_SFT_Cold {
    /* No variables to call PacsEng_CS_SFT_Cold                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_CS_SFT_Cold                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_CS_SFT_Cold()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_CS_SFT_Cold();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS script    : OBCP_spec_freq_switch.txt
// Author        : Helmut Feuchtgruber
// CUS script    : Thomas G. Mueller
//
// Arguments needed to call OBCP
// Type  Name              DefCal   Description
//
// int   nb_obs_cal                number of full sequences
// int   chop_pos_start             initial chopper position
// int   nb_cycles                  nb of grating/readout cycles on the line
// int   grat_pos_LINE:             grating position 1
// int   nb_ramps_grat              number of ramps per grating position
// int   grat_pos_REF1              grating position 2
// int   grat_pos_REF2              grating position 3
// int   nb_CS1                     number of cycles on CS1
// int   chop_pos_CS1               chopper position on CS1
// int   nb_CS2                     number of cycles on CS2
// int   chop_pos_CS2               chopper position on CS2
//
// int   detector               1   Synchronize on this detector 1:Blue 2:Red
// int   grat_time          40000   Time for grating to move to start position
// int   comp_mode_blu         16   Blue compression
// int   comp_mode_red         16   Red compression 
// int   grat_def          500000   Grating default position
// int   chop_def               0   Chopper default position
// int   grat_def_time      20000   Gratting time to move to grat_def position
// int   nb_rdouts_ramp        64   Number of readouts per ramp
//
// Description:
// Wavelength switching will be required on extended sources. No chopping
// will be done. Instead, the grating will be moved in a 2 or 3 position
// pattern around the spectral line to be observed. The frequency of
// internal calibrations is adjusted by the top loop around observation
// and calibration loops.
// It is of course possible to have also calibrations outside the
// sequence, just before and/or after.
//
// Dependencies  : Calls "DMC_spec_freq_switch" DEC
//                 MEC sequence 4.2.7, DMC_spec_freq_switch
// Comments      : 
//
// Version       : 0.1 17-Aug-2004 Creation by TM 
// History       : 
//
int[] block OBCP_spec_freq_switch PACS 22 {
    int nb_obs_cal = 1; // number of full sequences
    int chop_pos_start = 1000; // initial chopper position
    int nb_cycles = 8; // nb of grating/readout cycles on the line
    int grat_pos_LINE = 461000; // grating position 1
    int nb_ramps_grat = 3; // number of ramps per grating position
    int grat_pos_REF1 = 454600; // grating position 2
    int grat_pos_REF2 = 467400; // grating position 3
    int nb_CS1 = 1; // number of cycles on CS1
    int chop_pos_CS1 = -25000; // chopper position on CS1
    int nb_CS2 = 1; // number of cycles on CS2
    int chop_pos_CS2 = 25000; // chopper position on CS2
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int grat_time = 40000; // Time for grating to move to start position
    int comp_mode_blu = 16; // Blue compression
    int comp_mode_red = 16; // Red compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopped default position
    int grat_def_time = 20000; // Grating time to move to grat_def [msec]
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Register with environment
    WriteBBID($BBID);
    // Variables for time_array
    int duree_ramps = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // duree of this OBCP (computed and returned in [msec])
    int duree_msec = 0;
    // OBCP pseudo code 
    // OBCP_WAVELENGTH_SWITCHING(seq, seq_time, P#1, ..., P#11,
    //                           detector, grat_time, cmp_par_blue, cmp_par_red,
    //                           grat_def, chop_def, grat_def_time)
    // begin
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(P#4)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM)
    // ; (all parameters filled by DPU based on seq parameter)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_time)
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    // DMC_START_SEQUENCE
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Call DEC/MEC sequence just to know the execution time
    int[] duree1 = DMC_spec_freq_switch(nb_obs_cal,nb_cycles,nb_ramps_grat,nb_CS1,nb_CS2);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    // WAIT(seq_time)
    // duree_msec(seq_time)
    duree_msec = duree_msec + t_cmd;
    duree_msec = duree_msec + seq_time;
    // ; check execution status of the sequence and in case of
    // failure stop OBCP and issue TM(1,8) + event
    // DMC_MOVE_GRAT_ABS(grat_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_def_time)
    // duree_msec(grat_def_time)
    duree_msec = duree_msec + grat_def_time;
    duree_OVR = duree_OVR + grat_def_time;
    // Issue TM(1,7)
    // end
    // Duration: 9 x 200ms + grat_time + grat_def_time + 0.5s
    // This procedure calls the sequence described in sec. 4.2.7.
    // Now trigger execution of OBCP
    // This OBCP is number 22, requires 20 parameters and calls DEC/MEC #10
    string obcp_ID = "WAVE_SWITCH_GRAT";
    int obcp_par_nb = 20;
    int seq_DMC = 10;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_obs_cal},{4,chop_pos_start},{5,nb_cycles},{6,grat_pos_LINE},{7,nb_ramps_grat},{8,grat_pos_REF1},{9,grat_pos_REF2},{10,nb_CS1},{11,chop_pos_CS1},{12,nb_CS2},{13,chop_pos_CS2},{14,detector},{15,grat_time},{16,comp_mode_blu},{17,comp_mode_red},{18,grat_def},{19,chop_def},{20,grat_def_time}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    delay(time_array[0]);
    // Return the array of times

    return time_array;
}

// Missionphase  : 
//
// Purpose       : Send the appropriate TC to set a determined bias voltage
//                 for a group 1 matrix. The bias voltage is expressed in
//                 volts
// Author        : Diego A. Cesarsky
// CUS script    : Diego A. Cesarsky
// CVS file      : PHOT_bias_group_1.txt
//
// Arguments     : 
// string  biasName    The bias name in accordance with the MIB convention
// float   bias        The corresponding bias voltage [volts]
//
// Description   : Extremely unsatisfactory code to find the bias name and
//                 issue the corresponding TC. If bias name is not found,
//                 the procedure sets an error condition
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : The code is awful since it has to use dedicated TCs for
//                 each bias of each group, namely 20 different TCs. There
//                 are similar CUS procedures for each of the other 5 groups.
//                 There are two "sanity checks":
//                 1- group number has to agree with procedure name
//                 2- bias number has to agree with bias name
//
// Version       : 0.1 07-aug-2006 Creation by DAC
// History       :
//               :
procedure PHOT_bias_group_3 {
    int grpNb = 3 in [3,3]; // The group number (sort of sanity check)
    int biasNb = 1; // The bias number (sort of sanity check)
    string biasName = "VH"; // The corresponding bias name as per MIB
    double bias = 1.62312; // The bias voltage to be set for biasName
}{
    //
    // Assume failure
    bool sentTC = false;
    // Start stupid "if" code
    // Bias name Pacs_BOLC_SET_VH
    if(biasName == "VH" && biasNb == 1) {
        Pacs_BOLC_SET_VH_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VL
    if(biasName == "VL" && biasNb == 2) {
        Pacs_BOLC_SET_VL_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VRL
    if(biasName == "VRL" && biasNb == 3) {
        Pacs_BOLC_SET_VRL_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VINJ 
    if(biasName == "VINJ" && biasNb == 4) {
        Pacs_BOLC_SET_VINJ_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VCH
    if(biasName == "VCH" && biasNb == 5) {
        Pacs_BOLC_SET_VCH_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL
    if(biasName == "VDL" && biasNb == 6) {
        Pacs_BOLC_SET_VDL_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS
    if(biasName == "VSS" && biasNb == 7) {
        Pacs_BOLC_SET_VSS_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL
    if(biasName == "VGL" && biasNb == 8) {
        Pacs_BOLC_SET_VGL_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLH
    if(biasName == "CKRLH" && biasNb == 9) {
        Pacs_BOLC_SET_CKRLH_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLL
    if(biasName == "CKRLL" && biasNb == 10) {
        Pacs_BOLC_SET_CKRLL_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_H
    if(biasName == "VDECX-H" && biasNb == 11) {
        Pacs_BOLC_SET_VDECX_H_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_L
    if(biasName == "VDECX-L" && biasNb == 12) {
        Pacs_BOLC_SET_VDECX_L_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_H
    if(biasName == "VSMS-H" && biasNb == 13) {
        Pacs_BOLC_SET_VSMS_H_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_L
    if(biasName == "VSMS-L" && biasNb == 14) {
        Pacs_BOLC_SET_VSMS_L_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGG
    if(biasName == "VGG" && biasNb == 15) {
        Pacs_BOLC_SET_VGG_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDD
    if(biasName == "VDD" && biasNb == 16) {
        Pacs_BOLC_SET_VDD_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS_BU
    if(biasName == "VSS-BU" && biasNb == 17) {
        Pacs_BOLC_SET_VSS_BU_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL_BU
    if(biasName == "VDL-BU" && biasNb == 18) {
        Pacs_BOLC_SET_VDL_BU_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL_BU
    if(biasName == "VGL-BU" && biasNb == 19) {
        Pacs_BOLC_SET_VGL_BU_G3(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VH_BLIND
    if(biasName == "VH-BLIND" && biasNb == 20) {
        Pacs_BOLC_SET_VH_BLIND_G3(bias);
        sentTC = true;
    }
    // Error condition if no bias was set
    if(!sentTC) {
        error("The combination " + biasName + "/" + biasNb + " is not correct");
    }
}

// Missionphase  : 
//
// Purpose       : Send the appropriate TC to set a determined bias voltage
//                 for a group 1 matrix. The bias voltage is expressed in
//                 volts
// Author        : Diego A. Cesarsky
// CUS script    : Diego A. Cesarsky
// CVS file      : PHOT_bias_group_2.txt
//
// Arguments     : 
// string  biasName    The bias name in accordance with the MIB convention
// float   bias        The corresponding bias voltage [volts]
//
// Description   : Extremely unsatisfactory code to find the bias name and
//                 issue the corresponding TC. If bias name is not found,
//                 the procedure sets an error condition
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : The code is awful since it has to use dedicated TCs for
//                 each bias of each group, namely 20 different TCs. There
//                 are similar CUS procedures for each of the other 5 groups.
//                 There are two "sanity checks":
//                 1- group number has to agree with procedure name
//                 2- bias number has to agree with bias name
//
// Version       : 0.1 07-aug-2006 Creation by DAC
// History       :
//               :
procedure PHOT_bias_group_2 {
    int grpNb = 2 in [2,2]; // The group number (sort of sanity check)
    int biasNb = 1; // The bias number (sort of sanity check)
    string biasName = "VH"; // The corresponding bias name as per MIB
    double bias = 1.62312; // The bias voltage to be set for biasName
}{
    //
    // Assume failure
    bool sentTC = false;
    // Start stupid "if" code
    // Bias name Pacs_BOLC_SET_VH
    if(biasName == "VH" && biasNb == 1) {
        Pacs_BOLC_SET_VH_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VL
    if(biasName == "VL" && biasNb == 2) {
        Pacs_BOLC_SET_VL_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VRL
    if(biasName == "VRL" && biasNb == 3) {
        Pacs_BOLC_SET_VRL_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VINJ 
    if(biasName == "VINJ" && biasNb == 4) {
        Pacs_BOLC_SET_VINJ_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VCH
    if(biasName == "VCH" && biasNb == 5) {
        Pacs_BOLC_SET_VCH_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL
    if(biasName == "VDL" && biasNb == 6) {
        Pacs_BOLC_SET_VDL_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS
    if(biasName == "VSS" && biasNb == 7) {
        Pacs_BOLC_SET_VSS_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL
    if(biasName == "VGL" && biasNb == 8) {
        Pacs_BOLC_SET_VGL_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLH
    if(biasName == "CKRLH" && biasNb == 9) {
        Pacs_BOLC_SET_CKRLH_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLL
    if(biasName == "CKRLL" && biasNb == 10) {
        Pacs_BOLC_SET_CKRLL_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_H
    if(biasName == "VDECX-H" && biasNb == 11) {
        Pacs_BOLC_SET_VDECX_H_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_L
    if(biasName == "VDECX-L" && biasNb == 12) {
        Pacs_BOLC_SET_VDECX_L_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_H
    if(biasName == "VSMS-H" && biasNb == 13) {
        Pacs_BOLC_SET_VSMS_H_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_L
    if(biasName == "VSMS-L" && biasNb == 14) {
        Pacs_BOLC_SET_VSMS_L_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGG
    if(biasName == "VGG" && biasNb == 15) {
        Pacs_BOLC_SET_VGG_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDD
    if(biasName == "VDD" && biasNb == 16) {
        Pacs_BOLC_SET_VDD_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS_BU
    if(biasName == "VSS-BU" && biasNb == 17) {
        Pacs_BOLC_SET_VSS_BU_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL_BU
    if(biasName == "VDL-BU" && biasNb == 18) {
        Pacs_BOLC_SET_VDL_BU_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL_BU
    if(biasName == "VGL-BU" && biasNb == 19) {
        Pacs_BOLC_SET_VGL_BU_G2(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VH_BLIND
    if(biasName == "VH-BLIND" && biasNb == 20) {
        Pacs_BOLC_SET_VH_BLIND_G2(bias);
        sentTC = true;
    }
    // Error condition if no bias was set
    if(!sentTC) {
        error("The combination " + biasName + "/" + biasNb + " is not correct");
    }
}

// Missionphase  : 
//
// Purpose       : Send the appropriate TC to set a determined bias voltage
//                 for a group 1 matrix. The bias voltage is expressed in
//                 volts
// Author        : Diego A. Cesarsky
// CUS script    : Diego A. Cesarsky
// CVS file      : PHOT_bias_group_1.txt
//
// Arguments     : 
// string  biasName    The bias name in accordance with the MIB convention
// float   bias        The corresponding bias voltage [volts]
//
// Description   : Extremely unsatisfactory code to find the bias name and
//                 issue the corresponding TC. If bias name is not found,
//                 the procedure sets an error condition
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : The code is awful since it has to use dedicated TCs for
//                 each bias of each group, namely 20 different TCs. There
//                 are similar CUS procedures for each of the other 5 groups.
//                 There are two "sanity checks":
//                 1- group number has to agree with procedure name
//                 2- bias number has to agree with bias name
//
// Version       : 0.1 07-aug-2006 Creation by DAC
// History       :
//               :
procedure PHOT_bias_group_1 {
    int grpNb = 1 in [1,1]; // The group number (sort of sanity check)
    int biasNb = 1; // The bias number (sort of sanity check)
    string biasName = "VH"; // The corresponding bias name as per MIB
    double bias = 1.62312; // The bias voltage to be set for biasName
}{
    //
    // Assume failure
    bool sentTC = false;
    // Start stupid "if" code
    // Bias name Pacs_BOLC_SET_VH
    if(biasName == "VH" && biasNb == 1) {
        Pacs_BOLC_SET_VH_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VL
    if(biasName == "VL" && biasNb == 2) {
        Pacs_BOLC_SET_VL_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VRL
    if(biasName == "VRL" && biasNb == 3) {
        Pacs_BOLC_SET_VRL_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VINJ 
    if(biasName == "VINJ" && biasNb == 4) {
        Pacs_BOLC_SET_VINJ_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VCH
    if(biasName == "VCH" && biasNb == 5) {
        Pacs_BOLC_SET_VCH_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL
    if(biasName == "VDL" && biasNb == 6) {
        Pacs_BOLC_SET_VDL_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS
    if(biasName == "VSS" && biasNb == 7) {
        Pacs_BOLC_SET_VSS_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL
    if(biasName == "VGL" && biasNb == 8) {
        Pacs_BOLC_SET_VGL_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLH
    if(biasName == "CKRLH" && biasNb == 9) {
        Pacs_BOLC_SET_CKRLH_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLL
    if(biasName == "CKRLL" && biasNb == 10) {
        Pacs_BOLC_SET_CKRLL_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_H
    if(biasName == "VDECX-H" && biasNb == 11) {
        Pacs_BOLC_SET_VDECX_H_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_L
    if(biasName == "VDECX-L" && biasNb == 12) {
        Pacs_BOLC_SET_VDECX_L_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_H
    if(biasName == "VSMS-H" && biasNb == 13) {
        Pacs_BOLC_SET_VSMS_H_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_L
    if(biasName == "VSMS-L" && biasNb == 14) {
        Pacs_BOLC_SET_VSMS_L_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGG
    if(biasName == "VGG" && biasNb == 15) {
        Pacs_BOLC_SET_VGG_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDD
    if(biasName == "VDD" && biasNb == 16) {
        Pacs_BOLC_SET_VDD_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS_BU
    if(biasName == "VSS-BU" && biasNb == 17) {
        Pacs_BOLC_SET_VSS_BU_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL_BU
    if(biasName == "VDL-BU" && biasNb == 18) {
        Pacs_BOLC_SET_VDL_BU_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL_BU
    if(biasName == "VGL-BU" && biasNb == 19) {
        Pacs_BOLC_SET_VGL_BU_G1(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VH_BLIND
    if(biasName == "VH-BLIND" && biasNb == 20) {
        Pacs_BOLC_SET_VH_BLIND_G1(bias);
        sentTC = true;
    }
    // Error condition if no bias was set
    if(!sentTC) {
        error("The combination " + biasName + "/" + biasNb + " is not correct");
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Script        : PACS_Chopper_uk_move_3000_ast_OBS.cus
//
//
// Missionphase  : IST Chopper Day
//
// Purpose	: Move chopper to absolute position  
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-3000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched on and Chopper switched on.
//                 
// Comments	: This script is based on the commanding during the CQM/FM ILT.
//
// Version	: 3.0	
// 
// History 	: 1.0 02-03-07 HD. Script to do simple chopper cycle 
//		  2.0 05-07-07 HD. IST Chopper Day
//		  3.0 05-07-07 MN. edited for SVT/PV conformance
//              : 4.0 04-mar-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Chopper_uk_move_3000_ast {
    /* Needed variables to call PacsEng_Chopper_uk_move_3000_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Chopper_uk_move_3000_ast                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Chopper_uk_move_3000_NoConf_ast()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Chopper_uk_move_3000_NoConf_ast();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : Send the appropriate TC to set a determined bias voltage
//                 for a group 1 matrix. The bias voltage is expressed in
//                 volts
// Author        : Diego A. Cesarsky
// CUS script    : Diego A. Cesarsky
// CVS file      : PHOT_bias_group_1.txt
//
// Arguments     : 
// string  biasName    The bias name in accordance with the MIB convention
// float   bias        The corresponding bias voltage [volts]
//
// Description   : Extremely unsatisfactory code to find the bias name and
//                 issue the corresponding TC. If bias name is not found,
//                 the procedure sets an error condition
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : The code is awful since it has to use dedicated TCs for
//                 each bias of each group, namely 20 different TCs. There
//                 are similar CUS procedures for each of the other 5 groups.
//                 There are two "sanity checks":
//                 1- group number has to agree with procedure name
//                 2- bias number has to agree with bias name
//
// Version       : 0.1 07-aug-2006 Creation by DAC
// History       :
//               :
procedure PHOT_bias_group_6 {
    int grpNb = 6 in [6,6]; // The group number (sort of sanity check)
    int biasNb = 1; // The bias number (sort of sanity check)
    string biasName = "VH"; // The corresponding bias name as per MIB
    double bias = 1.62312; // The bias voltage to be set for biasName
}{
    //
    // Assume failure
    bool sentTC = false;
    // Start stupid "if" code
    // Bias name Pacs_BOLC_SET_VH
    if(biasName == "VH" && biasNb == 1) {
        Pacs_BOLC_SET_VH_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VL
    if(biasName == "VL" && biasNb == 2) {
        Pacs_BOLC_SET_VL_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VRL
    if(biasName == "VRL" && biasNb == 3) {
        Pacs_BOLC_SET_VRL_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VINJ 
    if(biasName == "VINJ" && biasNb == 4) {
        Pacs_BOLC_SET_VINJ_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VCH
    if(biasName == "VCH" && biasNb == 5) {
        Pacs_BOLC_SET_VCH_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL
    if(biasName == "VDL" && biasNb == 6) {
        Pacs_BOLC_SET_VDL_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS
    if(biasName == "VSS" && biasNb == 7) {
        Pacs_BOLC_SET_VSS_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL
    if(biasName == "VGL" && biasNb == 8) {
        Pacs_BOLC_SET_VGL_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLH
    if(biasName == "CKRLH" && biasNb == 9) {
        Pacs_BOLC_SET_CKRLH_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLL
    if(biasName == "CKRLL" && biasNb == 10) {
        Pacs_BOLC_SET_CKRLL_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_H
    if(biasName == "VDECX-H" && biasNb == 11) {
        Pacs_BOLC_SET_VDECX_H_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_L
    if(biasName == "VDECX-L" && biasNb == 12) {
        Pacs_BOLC_SET_VDECX_L_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_H
    if(biasName == "VSMS-H" && biasNb == 13) {
        Pacs_BOLC_SET_VSMS_H_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_L
    if(biasName == "VSMS-L" && biasNb == 14) {
        Pacs_BOLC_SET_VSMS_L_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGG
    if(biasName == "VGG" && biasNb == 15) {
        Pacs_BOLC_SET_VGG_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDD
    if(biasName == "VDD" && biasNb == 16) {
        Pacs_BOLC_SET_VDD_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS_BU
    if(biasName == "VSS-BU" && biasNb == 17) {
        Pacs_BOLC_SET_VSS_BU_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL_BU
    if(biasName == "VDL-BU" && biasNb == 18) {
        Pacs_BOLC_SET_VDL_BU_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL_BU
    if(biasName == "VGL-BU" && biasNb == 19) {
        Pacs_BOLC_SET_VGL_BU_G6(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VH_BLIND
    if(biasName == "VH-BLIND" && biasNb == 20) {
        Pacs_BOLC_SET_VH_BLIND_G6(bias);
        sentTC = true;
    }
    // Error condition if no bias was set
    if(!sentTC) {
        error("The combination " + biasName + "/" + biasNb + " is not correct");
    }
}

// Missionphase  : 
//
// Purpose       : Send the appropriate TC to set a determined bias voltage
//                 for a group 1 matrix. The bias voltage is expressed in
//                 volts
// Author        : Diego A. Cesarsky
// CUS script    : Diego A. Cesarsky
// CVS file      : PHOT_bias_group_1.txt
//
// Arguments     : 
// string  biasName    The bias name in accordance with the MIB convention
// float   bias        The corresponding bias voltage [volts]
//
// Description   : Extremely unsatisfactory code to find the bias name and
//                 issue the corresponding TC. If bias name is not found,
//                 the procedure sets an error condition
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : The code is awful since it has to use dedicated TCs for
//                 each bias of each group, namely 20 different TCs. There
//                 are similar CUS procedures for each of the other 5 groups.
//                 There are two "sanity checks":
//                 1- group number has to agree with procedure name
//                 2- bias number has to agree with bias name
//
// Version       : 0.1 07-aug-2006 Creation by DAC
// History       :
//               :
procedure PHOT_bias_group_4 {
    int grpNb = 4 in [4,4]; // The group number (sort of sanity check)
    int biasNb = 1; // The bias number (sort of sanity check)
    string biasName = "VH"; // The corresponding bias name as per MIB
    double bias = 1.62312; // The bias voltage to be set for biasName
}{
    //
    // Assume failure
    bool sentTC = false;
    // Start stupid "if" code
    // Bias name Pacs_BOLC_SET_VH
    if(biasName == "VH" && biasNb == 1) {
        Pacs_BOLC_SET_VH_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VL
    if(biasName == "VL" && biasNb == 2) {
        Pacs_BOLC_SET_VL_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VRL
    if(biasName == "VRL" && biasNb == 3) {
        Pacs_BOLC_SET_VRL_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VINJ 
    if(biasName == "VINJ" && biasNb == 4) {
        Pacs_BOLC_SET_VINJ_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VCH
    if(biasName == "VCH" && biasNb == 5) {
        Pacs_BOLC_SET_VCH_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL
    if(biasName == "VDL" && biasNb == 6) {
        Pacs_BOLC_SET_VDL_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS
    if(biasName == "VSS" && biasNb == 7) {
        Pacs_BOLC_SET_VSS_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL
    if(biasName == "VGL" && biasNb == 8) {
        Pacs_BOLC_SET_VGL_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLH
    if(biasName == "CKRLH" && biasNb == 9) {
        Pacs_BOLC_SET_CKRLH_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLL
    if(biasName == "CKRLL" && biasNb == 10) {
        Pacs_BOLC_SET_CKRLL_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_H
    if(biasName == "VDECX-H" && biasNb == 11) {
        Pacs_BOLC_SET_VDECX_H_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_L
    if(biasName == "VDECX-L" && biasNb == 12) {
        Pacs_BOLC_SET_VDECX_L_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_H
    if(biasName == "VSMS-H" && biasNb == 13) {
        Pacs_BOLC_SET_VSMS_H_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_L
    if(biasName == "VSMS-L" && biasNb == 14) {
        Pacs_BOLC_SET_VSMS_L_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGG
    if(biasName == "VGG" && biasNb == 15) {
        Pacs_BOLC_SET_VGG_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDD
    if(biasName == "VDD" && biasNb == 16) {
        Pacs_BOLC_SET_VDD_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS_BU
    if(biasName == "VSS-BU" && biasNb == 17) {
        Pacs_BOLC_SET_VSS_BU_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL_BU
    if(biasName == "VDL-BU" && biasNb == 18) {
        Pacs_BOLC_SET_VDL_BU_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL_BU
    if(biasName == "VGL-BU" && biasNb == 19) {
        Pacs_BOLC_SET_VGL_BU_G4(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VH_BLIND
    if(biasName == "VH-BLIND" && biasNb == 20) {
        Pacs_BOLC_SET_VH_BLIND_G4(bias);
        sentTC = true;
    }
    // Error condition if no bias was set
    if(!sentTC) {
        error("The combination " + biasName + "/" + biasNb + " is not correct");
    }
}

// Missionphase  : 
//
// Purpose       : Send the appropriate TC to set a determined bias voltage
//                 for a group 1 matrix. The bias voltage is expressed in
//                 volts
// Author        : Diego A. Cesarsky
// CUS script    : Diego A. Cesarsky
// CVS file      : PHOT_bias_group_1.txt
//
// Arguments     : 
// string  biasName    The bias name in accordance with the MIB convention
// float   bias        The corresponding bias voltage [volts]
//
// Description   : Extremely unsatisfactory code to find the bias name and
//                 issue the corresponding TC. If bias name is not found,
//                 the procedure sets an error condition
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : The code is awful since it has to use dedicated TCs for
//                 each bias of each group, namely 20 different TCs. There
//                 are similar CUS procedures for each of the other 5 groups.
//                 There are two "sanity checks":
//                 1- group number has to agree with procedure name
//                 2- bias number has to agree with bias name
//
// Version       : 0.1 07-aug-2006 Creation by DAC
// History       :
//               :
procedure PHOT_bias_group_5 {
    int grpNb = 5 in [5,5]; // The group number (sort of sanity check)
    int biasNb = 1; // The bias number (sort of sanity check)
    string biasName = "VH"; // The corresponding bias name as per MIB
    double bias = 1.62312; // The bias voltage to be set for biasName
}{
    //
    // Assume failure
    bool sentTC = false;
    // Start stupid "if" code
    // Bias name Pacs_BOLC_SET_VH
    if(biasName == "VH" && biasNb == 1) {
        Pacs_BOLC_SET_VH_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VL
    if(biasName == "VL" && biasNb == 2) {
        Pacs_BOLC_SET_VL_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VRL
    if(biasName == "VRL" && biasNb == 3) {
        Pacs_BOLC_SET_VRL_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VINJ 
    if(biasName == "VINJ" && biasNb == 4) {
        Pacs_BOLC_SET_VINJ_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VCH
    if(biasName == "VCH" && biasNb == 5) {
        Pacs_BOLC_SET_VCH_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL
    if(biasName == "VDL" && biasNb == 6) {
        Pacs_BOLC_SET_VDL_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS
    if(biasName == "VSS" && biasNb == 7) {
        Pacs_BOLC_SET_VSS_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL
    if(biasName == "VGL" && biasNb == 8) {
        Pacs_BOLC_SET_VGL_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLH
    if(biasName == "CKRLH" && biasNb == 9) {
        Pacs_BOLC_SET_CKRLH_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_CKRLL
    if(biasName == "CKRLL" && biasNb == 10) {
        Pacs_BOLC_SET_CKRLL_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_H
    if(biasName == "VDECX-H" && biasNb == 11) {
        Pacs_BOLC_SET_VDECX_H_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDECX_L
    if(biasName == "VDECX-L" && biasNb == 12) {
        Pacs_BOLC_SET_VDECX_L_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_H
    if(biasName == "VSMS-H" && biasNb == 13) {
        Pacs_BOLC_SET_VSMS_H_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSMS_L
    if(biasName == "VSMS-L" && biasNb == 14) {
        Pacs_BOLC_SET_VSMS_L_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGG
    if(biasName == "VGG" && biasNb == 15) {
        Pacs_BOLC_SET_VGG_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDD
    if(biasName == "VDD" && biasNb == 16) {
        Pacs_BOLC_SET_VDD_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VSS_BU
    if(biasName == "VSS-BU" && biasNb == 17) {
        Pacs_BOLC_SET_VSS_BU_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VDL_BU
    if(biasName == "VDL-BU" && biasNb == 18) {
        Pacs_BOLC_SET_VDL_BU_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VGL_BU
    if(biasName == "VGL-BU" && biasNb == 19) {
        Pacs_BOLC_SET_VGL_BU_G5(bias);
        sentTC = true;
    }
    // Bias name Pacs_BOLC_SET_VH_BLIND
    if(biasName == "VH-BLIND" && biasNb == 20) {
        Pacs_BOLC_SET_VH_BLIND_G5(bias);
        sentTC = true;
    }
    // Error condition if no bias was set
    if(!sentTC) {
        error("The combination " + biasName + "/" + biasNb + " is not correct");
    }
}

// File          : PACS_Spec_Curing_Explore.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Flasher curing : short flashes with dead times -> Temp & signal evolutions
//		   Third part of the Flashers Performance check (curing schemes)
//
// Author        : P. Royer
//
// Arguments     : flasher current for the curing
//                       number & duration of flashes
//                       idle time between the flashes
//
// Prerequisite  : spectrometer detectors & chopper configured
//
// Description   :  SPU Setup
//                       position chopper on BB2 (reasonnable signal when trying to estimate quality of curing), grating supposed at default position, FW position not critical
//	    Flexible scheme for flasher curing : short flashes with dead times
// 	    chopper to default position
//                       SPU reset
//
// Dependencies : SPEC_spu_setup
//                        SPEC_spu_reset
//                        PACS_Spec_Flash_SWON
//	     PACS_Spec_Flash_Setup
//	     PACS_Spec_Flash_SWOF
//
// Comments      : 
//
// Version       : 1.1
// History       : 1.0 / 12-Mar-2008 initial version by PR
//                    1.1 /  01-Jul-2008 introduced CRE Setup & corresponding CALU, "final_delay" & grat_pos
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.1
// @purpose Flasher curing : short flashes with dead times -> Temp & signal evolutions
// @comment - 
//
procedure PACS_Spec_Curing_Explore {
    int blue_flasher_current = 819 in [0,820]; //4mA. [0,4095] = [0,20 mA]
    int red_flasher_current = 819 in [0,820]; //4mA. [0,4095] = [0,20 mA]
    int nflash = 1; // Number of flashes
    int flash_time = 60; // Duration of each flash
    int idle_time = 120; // Idle time between the flashes
    int nflash_fine = 6; // Number of flashes
    int flash_time_fine = 10; // Duration of each flash
    int idle_time_fine = 60; // Idle time between the flashes
    int final_delay = 120; // Idle time at the end of the test (flasher cooldown, detector stabilisation),
}{
    //
    // Internal parameters
    // -------------------
    int chop_pos_BB2 = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    //int chop_pos_BB2 = 21200;
    //
    // SPU RESET
    //
    PACS_Spec_SPU_Reset();
    delay(1);
    //
    // Setup CREs    -->    Largest Capacitance (No command to the heaters)
    //
    string calUname = "CONFCRECuring";
    // Calibration Table
    string calUrow = "PV";
    // Row in table = Instrument Configuration
    double bias_d_blue = dlookup(calUname,calUrow,"bias_d_blue");
    double bias_d_red = dlookup(calUname,calUrow,"bias_d_red");
    double bias_res_blue = dlookup(calUname,calUrow,"bias_res_blue");
    double bias_res_red = dlookup(calUname,calUrow,"bias_res_red");
    int ramp_blue = ilookup(calUname,calUrow,"ramp_blue");
    int ramp_red = ilookup(calUname,calUrow,"ramp_red");
    int capacity_blue = ilookup(calUname,calUrow,"capacity_blue");
    int capacity_red = ilookup(calUname,calUrow,"capacity_red");
    // CURING PARAMETER
    int curing_mode = 0;
    //
    SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red);
    //
    // SPU SETUP (default = slope fitting)
    //
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int nb_samp_subramp_blu = ilookup(calUname,calUrow,"ramp_blue");
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = ilookup(calUname,calUrow,"ramp_red");
    // Nb of red samples per sub-ramp
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //
    // SEND CHOPPER TO BB2
    PACS_Chop_Move_Abs(chop_pos_BB2);
    delay(1);
    //
    // Start Flashers DiagHK
    //
    // 1: synch w/ BLUE DET  2: synch w/ RED DET  >4: period in ms   0: 1KHz (not to use w/ science)
    int diag_hk_period = 100;
    PACS_Spec_FlashHeat_Diaghk_Setup(diag_hk_period);
    delay(10);
    //
    // SWON FLASHERS
    //
    PACS_Spec_Flash_SWON();
    delay(10);
    //
    //
    // Flashers Loop I : Coarse curing, 1 minute / iteration
    // -------------
    for(int loopin = 1 .. nflash) {
        PACS_Spec_SPU_Reset();
        delay(1);
        curing_mode = 1;
        SPEC_CRE_Curing_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red,curing_mode);
        delay(1);
        PACS_Spec_Flash_Setup(blue_flasher_current,red_flasher_current);
        delay(flash_time);
        PACS_Spec_Flash_Setup(0,0);
        curing_mode = 0;
        SPEC_CRE_Curing_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red,curing_mode);
        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
        delay(idle_time);
    }
    //
    // Flashers Loop II : Fine tuning, 10 sec / iteration
    // -------------
    for(int loopin2 = 1 .. nflash_fine) {
        PACS_Spec_SPU_Reset();
        delay(1);
        curing_mode = 1;
        SPEC_CRE_Curing_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red,curing_mode);
        delay(1);
        PACS_Spec_Flash_Setup(blue_flasher_current,red_flasher_current);
        delay(flash_time_fine);
        PACS_Spec_Flash_Setup(0,0);
        curing_mode = 0;
        SPEC_CRE_Curing_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red,curing_mode);
        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
        delay(idle_time_fine);
    }
    //
    // SWOF FLASHERS
    //
    PACS_Spec_Flash_SWOF();
    delay(10);
    // 
    // Detector stabilisation / cooldown / recovery
    // --------------------------------------------
    delay(final_delay);
    //
    // SEND CHOPPER TO DEFAULT
    PACS_Chop_Move_Abs(0);
    delay(1);
    //
    // RESET DIAGHK
    //
    PACS_Diaghk_Reset();
    //
    // RESET SPU
    //
    PACS_Spec_SPU_Reset();
    delay(1);
    //
    // SYNC
    //= = =
    sync();
}

// Script        : PacsEng_Chopper_AutoOpt.txt
// Missionphase  : Commissioning
//
// Purpose	: Check a series of different chopper controller settings by
//                chopping between +/- 12000 units (~4 deg)
//                  
// Author	: Markus Nielbock/Helmut Dannerbauer
// CUS author 	: MN/HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-12000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions: PACS switched on and Chopper switched off.
//                 
// Comments	: This script is based on the commanding script
//                PACS_Chopper_uk_move_12000_OBS.cus
//
// Version	: 1.2
// 
// History 	: 1.0 20-Nov-2007 (MN) Script to do simple chopper cycle 
//         	  1.1 10-Mar-2008 (MN) adopted extended CUS naming conventions
//         	  1.2 19-May-2008 (MN) added +3 to all parameters (XHSPOT bug)
//
// Initialise input parameters:
// Defines control parameter range, loops run from k(p,i,c,f)min to
// k(p,i,c,f)max defining the inverse of the ratio of parameter change w.r.t.
// the default value.
obs PacsEng_Chopper_AutoOpt_bug {
    int kpmin = 3 in [0,6]; //min Kp+3
    int kpmax = 3 in [0,6]; //max Kp+3
    int kimin = 3 in [0,6]; //min Ki+3
    int kimax = 3 in [0,6]; //max Ki+3
    int kcmin = 3 in [0,6]; //min KiCurr+3
    int kcmax = 3 in [0,6]; //max KiCurr+3
    int kfmin = 3 in [0,6]; //min Kf+3
    int kfmax = 3 in [0,6]; //max Kf+3
}{
    // duration
    int tOPT = duration(Pacs_Chopper_AutoOpt_bug(kpmin,kpmax,kimin,kimax,kcmin,kcmax,kfmin,kfmax));
    int tOBSID = duration(WriteOBSID($OBSID));
    int tEndID = duration(WriteEndID());
    int tp = tOPT + tOBSID + tEndID;
    // Issue the pointing request
    int[] fromPntReq = no_pointing(true,0,0,tp);
}{
    // The state machine
    int[] stateVar = [0];
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 3) {
            // Get OBSID from environment
            //Send OBSID to DMC
            WriteOBSID($OBSID);
            data_rate(120.0);
            Pacs_Chopper_AutoOpt_bug(kpmin,kpmax,kimin,kimax,kcmin,kcmax,kfmin,kfmax);
            // Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

/////////////////////////////////////////////////////////////////////////////
/// $Id: PacsCal_FieldDistort.txt,v 1.4 2008/11/12 11:40:20 vanessad Exp $
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsCal_PacsLineSpec
//
// CUS author    : DAC
//
// Input arguments: see after module identification
//
// Return values
// {int,int,int} {totalDuration,slewDuration,obsOverPACSandSC}
//
// Comments      :
//
// History: 
// 22-may-2008 0.1  DAC PV version based on PacsLineSpecObs
//                  - reads PV version of EstimatorOBCP27
//                  - removed most of AOT features
//                  - only one line per AOT 
//                  - either raster or scan w/off pointing modes 
//                  - chopping without nodding for both pointing modes
//                  - chopper throw is user defined
//                  Be ready to find several unused variables, inherited
//                  from the AOT code; some variables are forced to a fix
//                  value (user defined for the AOT code)
// 14-jul-2008 0.2 DAC
//                  - Move unused input parameters away from input list
//                  - Allow use of repeatOBS
//                  - set grating step to zero; i.e. confOBCP{1}=confOBCP{2}=0
//                  - Deal with chopper offset and S/C offsets
//                  - Renamed from PacsCal_PacsLineSpec to PacsCal_FieldDistort
// 18-jul-2008 0.3 DAC
//                  - Add user defined "fixed" for pointing requests, called
//                    skyCoord       
// 03-nov-2008 0.4 VD
// 	       	   - Swapped chopSRC and chopREF in confOBCP to fix the
//		   fact that on Hspot the OFF position appears on the source	
//		   and the "on source raster/ scan? appears on OFF position
//NOT USED anymore BUT updated SPR 5447
{int,int,int} obs PacsCal_FieldDistort {
    string lineId = "Alessandra lonely line"; //Line ID
    double lWave = 82.0 in [55.0,210.0]; //Rest wavelength [micron]
    int repeatOBS = 1; //Number of up/down grating cycles (SRC)
    int repeatOFF = 1; //Number of up/down grating cycles (OFF)
    double lineFlux = 1.0; //Expected line flux
    double contFlux = 2.0; //Expected continuum flux [mJy]
    double lineWdth = 30.0;
    string fluxUnit = "Jy/m2";
    string wdthUnit = "kms";
    string orderSel = "order2" in ["order2","order3"]; //Used to select FILTER
    /* Define default values for SCAN mode                                  */
    string pmode = "raster" in ["raster","scan"]; //Choose RASTER or line SCAN
    int noOFF = 0; //0 for noOFF, READ DOCS for noOFF>0
    /* Raster parameters */
    int m = 2 in [2,100]; //Number of points
    int n = 1 in [1,100]; //Number of lines
    double pointStep = 2.3 in [2.0,480.0]; // Raster point step [arcsec]
    double lineStep = 2.3 in [2.0,480.0]; // Raster line  step [arcsec]
    /* Scan parameters */
    double rateScan = 3.0; // Scan rate [arcsec/sec]
    double legScanLength = 15.0 in [1.0,1200.0]; //Scan leg [arcmin]
    int numScanLegs = 4 in [1,1500]; //Number of scan legs
    double mapScanAngle = 0.0 in [0.0,360.0];
    double separationScanLeg = 2.3 in [2.0,480.0]; //Scan leg separation [arcsec]
    /* Chop parameters */
    bool useAOTDefaults = true; // use AOT defaults?
    bool src_at_OFF = false; // Put the SRC at OFF chopper beam?
    double chopthrow = 180.0; // Chopper throw [arcsec]
    double chopoffset = 0.0; // Chopper offset [arcsec]
    double mapRasterAngle = 0.0 in [0.0,360.0];
    double[] planetOffsets = [0.0,0.0]; //PlanetOffsets: Extra y,z offsets for naifid>0 [arcmin]
    bool skyCoord = true; //TRUE for sky coordinates; false for S/C coordinates
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    double raoff = 0.0 in [0.0,360.0];
    double decoff = 0.0 in [-90.0,90.0];
    bool refSelected = false; // OFF position needed 
    int naifid = 0; // RA,DEC or SSO
}{
    //  Formerly as input parameters
    // "lines" is defined as an array; its elements (and hence its dimension) 
    //  are provided by HSPOT in the AOT version. Here they are filled in-situ
    //   {id,redshifted wavelength,repeat factor,line flux,continuum flux, 
    //    line width,line flux unit,line width unit}  
    {string,double,int,double,double,double,string,string}[] lines = [];
    int userNODcycles = 1;
    bool faintLines = true;
    bool chopper = true;
    bool nodding = false;
    int obsOverhead = 180;
    // Slew overhead
    lines[0] = {lineId,lWave,repeatOBS,lineFlux,contFlux,lineWdth,fluxUnit,wdthUnit};
    // Start of "Pointing" section
    // 
    // Overall control of debugging messages
    bool verbose = true;
    // New variable to start at nodded position
    bool startAtOFF = false;
    // extraConf: whatever affects PACS default configuration 
    // Currently: the option faintLines calls for an extraConf
    string extraConf = "normal";
    // For bright lines
    if(!faintLines) {
        extraConf = "bright";
    }
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // Need switching boolean
    bool chopNod = true;
    bool switching = !chopNod;
    // Decode more HSPOT information
    int nbLines = length(lines);
    int nbLines1 = nbLines - 1;
    // Cannot call with empty "lines"
    if(nbLines == 0) {
        error("STOP!! There are no spectral lines defined!");
    }
    // Chopping always true; nodding slways false
    nodding = false;
    chopper = true;
    // Establish now the applicable Pointing Mode (use same pointCase convention
    // used in PacsPhoto)
    // Set pointing mode is undefined. If it remains undefined at the end of
    // the next tests, then there is a problem with the source definition
    int pointCase = 0;
    // Based on the definitions of PacsPhoto, and since there is no staring case,
    // pointCase is of the form 31 (raster no nod), 32 (raster w/nod) or 33 (scan
    // mode)
    if(pmode == "raster") {
        pointCase = 31;
        string pointMode = "raster_pointing";
        string userMode = "Raster, no chopper,  no nodding";
        if(chopper) {
            userMode = "Raster, chopper,  no nodding";
        }
    }
    if(pmode == "scan") {
        pointCase = 33;
        pointMode = "line_scan_pointing";
        userMode = "ScanChopNoNod";
    }
    // Establish pointing offsets (index into PACSyzoffsets CAL file)
    string yzoffsetROW = "S" + pointCase;
    // For symmetrical chopping, virtual apertures are dependent on the chopper
    // throw. The chopperthrow will be used to compute yzoffsets
    yzoffsetROW = yzoffsetROW;
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("     PointCase ID: " + pointCase);
        debug_print("     PointMode   : " + pointMode);
        debug_print("     CALU entry  : " + yzoffsetROW);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Define array of wavelengths (will be needed by the SORT procedure)
    double[] lineWave = [55.0];
    // Populate the array of wavelengths (inherited from AOT where several lines
    // are allowed)
    lineWave[0] = lines[0]{1};
    // For each line obtain the grating order and the grating position 
    int[] orders = [0];
    double[] grat_pos = [0.0];
    // Fill the tuple waveTuple {waveLen,order,gratPos,nbStep,gratStep}
    {double,int,int,int,int}[] waveTuple = [{0.0,0,0,0,0}];
    waveTuple[0] = SPEC_get_grat_info_PV(lineWave[0],"HI",switching,extraConf,orderSel,verbose);
    // Create vector of intermediate results
    orders[0] = waveTuple[0]{1};
    grat_pos[0] = double(waveTuple[0]{2});
    // Determine the filter needed with given lines
    // No filter needed, i.e. ORDER=1
    int filter = 1;
    // Determine filter based on HSPOT input
    if(orderSel == "order2") {
        filter = 2;
    }
    if(orderSel == "order3") {
        filter = 3;
    }
    if(verbose) {
        debug_print("ORDER array: " + orders);
    }
    // Filter below will be set by SPEC_aot_prologue via SlewCal
    if(verbose) {
        debug_print("MAIN:The full OBS will be performed with filter " + filter);
    }
    // The tuple arrays confOBCP, confSPECred, and confSPECblu play a major
    // role. They contain the parameters related to commanding different PACS
    // subsystems. They are susceptible of changing with the observing conditions.
    // Hence, they have to be watched for changes since these imply sending one or
    // more TCs (usually invoking a building block)
    // Define confOBCP array
    // confOBCP{0 -> 19} contains:
    // nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
    // nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
    // grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
    // chop_pos_SRC     chop_pos_REF1    chop_pos_REF2    chop_pos_CS1
    // chop_pos_CS2     chop_def         detector         order
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confSPECblu and confSPECred
    // confSPEC contains:
    //   capa,       nb_rdouts_ramp, nb_rdouts_subramp, comp_mode,
    //   glitch_det, ramp_fit_alg,   nb_raw,            bias_r,    bias_d
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // Estimator module returns {confSPECblu,confSPECred,confOBCP}
    // Reunite all three tuples into paramsSPECdef
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    // AOT code uses "throwUsage" as a description of allowed chopper throws
    // Here the throw is user defined. Use "large" to please the script and
    // compute the ENG throw below.
    paramsSPECdef = PacsSpecDefaults("large",extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    if(useAOTDefaults) {
        double chopSRC = -180.0;
        double chopREF = 180.0;
        string convU = "SPEC_CHOP_sky";
        if(src_at_OFF) {
            confOBCP[0]{12} = PacsReadChopSky(convU,chopREF);
            confOBCP[0]{13} = PacsReadChopSky(convU,chopSRC);
        } else {
            // SRC on REF??? SRC back to where it should be
            confOBCP[0]{13} = PacsReadChopSky(convU,chopREF);
            confOBCP[0]{12} = PacsReadChopSky(convU,chopSRC);
        }
    } else {
        // Convert chopperthrow into into ENG values
        // Take account of desired chopper offset (all in arcsec)
        chopSRC = chopoffset + chopthrow / 2.0;
        chopREF = chopoffset - chopthrow / 2.0;
        convU = "SPEC_CHOP_sky";
        if(src_at_OFF) {
            confOBCP[0]{12} = PacsReadChopSky(convU,chopREF);
            confOBCP[0]{13} = PacsReadChopSky(convU,chopSRC);
        } else {
            // SRC on REF??? SRC back to where it should be
            confOBCP[0]{13} = PacsReadChopSky(convU,chopREF);
            confOBCP[0]{12} = PacsReadChopSky(convU,chopSRC);
        }
    }
    confOBCP[0]{14} = confOBCP[0]{13};
    if(verbose) {
        debug_print("CHOPPER SRC: " + chopSRC + " [arcsec]==> " + confOBCP[0]{12});
        debug_print("CHOPPER REF: " + chopREF + " [arcsec]==> " + confOBCP[0]{13});
    }
    // Here comes the module(s) to estimate OBS times as a function of the
    // input given by the HSPOT user.
    // Define tuple to contain the "variable" parameters
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPEC = clone(paramsSPECdef);
    // Need more info... create paramsSPECext (zut alors!)
    // paramsSPECext (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,nb_up_dn,timeOBS,aux2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for each wavelength. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("MAIN.confOBCP[0]: " + confOBCP[0]);
    }
    int nbNods = 0;
    // Accumulator total OBS time
    int totalOBS = 0;
    // For each demanded wavelength compute minimum duration (only one wave
    // in PV version)
    // Always use OBCP27
    // Here we perform chopping
    // SCR-2942: consider case of faintLines = false
    string forDEBUG = "chop/nod";
    paramsSPECext = PacsLineSpecEstimatorOBCP27_PV(lines[0],waveTuple[0],paramsSPEC,nodding,faintLines,verbose);
    // Copy estimates to respective tuples
    confSPECblu[1] = paramsSPECext{0};
    confSPECred[1] = paramsSPECext{1};
    confOBCP[1] = paramsSPECext{2};
    //  Save nb_SRC_REF
    debug_print("nb_SRC_REF1:" + confOBCP[1]{3});
    int nb_SRC_REF = confOBCP[1]{3};
    // SPECIAL FOR SINGLE GRATING POSITION
    confOBCP[1]{1} = 0;
    confOBCP[1]{2} = 0;
    // Accumulate total OBS time
    totalOBS = totalOBS + paramsSPECext{3}{2};
    if(verbose) {
        debug_print("MAIN.Wavelength: " + lines[0]{1});
        debug_print("MAIN.confOBCP[" + 1 + "]: " + confOBCP[1]);
        debug_print("MAIN.confSPEC[" + 1 + "]: " + confSPECblu[1]);
        debug_print("MAIN.Minimum required time: " + totalOBS + " [sec]");
    }
    if(nodding) {
        // Here we perform nodding/chopping
        nbNods = userNODcycles;
        if(verbose) {
            debug_print("MAIN.The PointReq will contain " + nbNods + " nod cycles");
        }
    } else {
        // Here we perform freq switch
        nbNods = 0;
    }
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Minimum required OBStime: " + totalOBS + " [sec]</p>";
    lineCnt = lineCnt + 1;
    int nodTotal = nbNods * totalOBS;
    if(nodding) {
        msgLine[lineCnt] = "<p>With the specified NOD count, " + nbNods + ", the total OBS time amounts to " + nodTotal + "[sec]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Since no NOD was specified the total OBS time is equal" + " to the minimum required time. The time can be changed" + " by changing the line(s) repeat factor</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("Accumulated SRC+REF time estimation",lineCnt,msgLine);
    // Messages on general Detector/SPU parameters
    lineCnt = 0;
    msgLine[lineCnt] = "<p>Red channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECred[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    int subRamps = confSPECred[0]{1} / confSPECred[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECred[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECred[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Blue channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECblu[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    subRamps = confSPECblu[0]{1} / confSPECblu[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECblu[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECblu[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Selected PACS setup parameters",lineCnt,msgLine);
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source
    // First operation is to set the OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // Will call PacsSpecSlewCal to perform AOT prologue and CAL during
    // slew to source. Establish an array of key wavelengths, one per order,
    // commensurate with user given wavelengths
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    double[] refWL = [lWave];
    double keyW = PacsSpecKeyWaves(orderSel,refWL);
    double[] keyWAVE = [keyW];
    //    int nbKeyWAVE = length(keyWAVE); == 1 
    int nbKeyWAVE = 1;
    // With current versions of CommandOBCP27 and CommandOBCP32, the grating is
    // supposed to be left by SlewCal at the position needed for the 1st line
    // The OBCPs will leave the grating at that same position
    int frstLstGratPos = confOBCP[1]{8};
    if(verbose) {
        debug_print("MAIN:waveTuple: " + waveTuple);
        debug_print("MAIN:keyWAVES " + keyWAVE);
        debug_print("MAIN:SlewCal should leave grating at: " + frstLstGratPos);
    }
    // Time needed to perform these activities during slew (includes AOT
    // prologue)
    bool doAOTprologue = true;
    int timeSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel));
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during slew: " + timeSlewCal);
    }
    // CAL for HOLD 
    doAOTprologue = false;
    int timeHoldCal = duration(PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,0,frstLstGratPos,orderSel));
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during HOLD: " + timeHoldCal);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsSpecCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsSpecCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // IMPORTANT NOTE: the duration could be different for the first cycle through 
    // all wavelengths than for the following ones owing to differing initial state.
    // However, all steps have been taken so that PACS starts the actual observation
    // in the same state as it would be left at the end of any wavelength cycle
    // Duration of any nod leg or staring observation
    // Different OBCP for wavelength switch
    if(!switching) {
        // Here we perform chopping
        int timeOBS = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
        // Compute timeOFF (uses repeatOFF).
        // Save OBS value, use OFF one, and replace OBS value
        int saveOBS = confOBCP[1]{0};
        confOBCP[1]{0} = repeatOFF;
        int timeOFF = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
        confOBCP[1]{0} = saveOBS;
        if(verbose) {
            debug_print("Duration OBCP27 OBS: " + timeOBS + " [sec] per pointing");
            debug_print("Duration OBCP27 OFF: " + timeOFF + " [sec] per pointing");
            debug_print("confSPEC_1: " + confSPECblu[1]);
            debug_print("confSPEC_0: " + confSPECblu[0]);
        }
    } else {
        // Here we perform freq switch
        timeOBS = duration(PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,verbose));
        if(verbose) {
            debug_print("Duration OBCP32: " + timeOBS + " [sec] per pointing");
        }
    }
    // Get duration of module to close AOT operations
    // This includes parking the grating
    // Park position
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // The grating was left by OBCPs at frstLstGratPos
    int timeEpilogue = duration(SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose));
    // WriteEndID will be the last TC; get its duration
    int timeEndID = duration(WriteEndID());
    // Summary of relevant data collected so far
    // timeSlewCal: duration of the leading CAL, including AOT_prologue
    // timeOBS    : duration of a single pointed OBS
    // nb_nods    : number of nods for staring mode or per raster position
    // chopNod : invoke nodding or not (nb_nods = 0 is equivalent to no nod)
    // m, n       : raster nb_points/line, nbLines per RREQ
    // pointStep,lineStep: more raster parameters
    // ra,dec: more pointing parameters
    //
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Ready to issue a FinePointing mode with/without nodding or
    // a RasterReq with/without nodding. Either one will use time during
    // slew to perform SlewCal.
    // Issue pointing request (when possible use JBr's variable names for clarity)
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    // Virtual aperture
    string ib = "P02_0";
    // Here since the chopper throw is user defined, compute the yoffset
    // DAC CHECK in flight that sign below is correct
    if(useAOTDefaults) {
        double yoffset = 0.0;
        double zoffset = 0.0;
    } else {
        yoffset = chopSRC;
        zoffset = 0.0;
    }
    //  For planets, add user given offsets to y,z offsets 
    if(naifid > 0) {
        yoffset = yoffset + 60.0 * planetOffsets[0];
        zoffset = zoffset + 60.0 * planetOffsets[1];
    }
    double skewCorrec = 0.0;
    if(verbose) {
        debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("#### skewCorrec : " + skewCorrec);
    }
    int tslewmin = timeSetOBSID + timeSlewCal;
    int tinithold = 0;
    int tfinalhold = timeEndID + timeEpilogue;
    int tp = timeOBS;
    double patt = 0.0;
    double pattnod = 270.0 + skewCorrec;
    int k = noOFF;
    // DAC Test ONLY
    int thold = timeHoldCal;
    int nhold = 0;
    int nload = 0;
    int tloadslewmin = 0;
    bool fixed = skyCoord;
    if(pointCase == 21 || pointCase == 31) {
        //     RasterMode repeated_raster_with_hold_and_OFF, section 3.5
        ib = "P02_0";
        //     Raster in sky/instrument coordinates
        fixed = skyCoord;
        double d1 = pointStep;
        double d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        k = noOFF;
        int top = timeOFF;
        int nrepeat = 1;
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        //     SPR-3237 (map orientation parameter) applies only to raster
        if(pointCase == 31) {
            fixed = skyCoord;
            patt = mapRasterAngle;
        }
        int[] fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
    }
    if(pointCase == 33) {
        //    for Alessandra boresight to spec
        ib = "P02_0";
        //   Use sky/instrument coordinates
        fixed = skyCoord;
        //  Scan orientation
        patt = mapScanAngle;
        n = numScanLegs;
        //      Only for message info
        m = 1;
        //      Perform OFF at begin and end	
        k = noOFF;
        d1 = 60.0 * legScanLength;
        d2 = separationScanLeg;
        thold = timeSlewCal;
        nhold = 0;
        nload = 0;
        nrepeat = 1;
        tloadmin = 0;
        //      Use modified confOBCP for the OFF measurement	
        top = timeOFF;
        fromPntReq = line_scan_with_off_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,n,d1,d2,rateScan,k,top,raoff,decoff,nrepeat,thold,nhold,tloadmin,nload);
        //    Define tdwell for the scan mode (dwell time = leg time). The OBCP should
        //    be parametrized to last at least tdwell seconds
        int tdwell = fromPntReq[4];
        if(verbose) {
            debug_print("SCAN: tdwell must be " + tdwell + " seconds");
        }
        //    Estimate duration of OBCP as a function of np_SRC_REF
        //    Use "rule of three"
        //    nb_SRC_REF = 1
        confOBCP[1]{3} = 1;
        int timeOBS1 = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
        //    nb_SRC_REF = 20
        confOBCP[1]{3} = 20;
        int timeOBS2 = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
        //    Slope per unit nb_SRC_REF, offset  
        double slope = double(timeOBS2 - timeOBS1) / 19.0;
        double offset = double(timeOBS1) - slope;
        //   Compute nb_SRC_REF so that OBCP runs during the whole scan leg
        nb_SRC_REF = iceil((double(tdwell) - offset) / slope);
        // Logic to make sure timeOBS3 is smaller than tdwell: reduce nb_SRC_REF
        // until durstion condition is met
        bool foundDwell = false;
        confOBCP[1]{3} = nb_SRC_REF;
        nb_SRC_REF = nb_SRC_REF + 1;
        while(!foundDwell) {
            nb_SRC_REF = nb_SRC_REF - 1;
            confOBCP[1]{3} = nb_SRC_REF;
            int timeOBS3 = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
            if(timeOBS3 <= tdwell) {
                foundDwell = true;
            }
            if(verbose) {
                debug_print("Needed nb_SRC_REF to fill scan leg: " + nb_SRC_REF);
                debug_print("OBCP duration: " + timeOBS3);
            }
        }
    }
    // Parameters returned by PointReq
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Issue PointRequest now");
        debug_print("Return from PointReq: " + fromPntReq);
    }
    //Info from API (nomenclature from Jon Br)
    tobs = fromPntReq[0];
    tslew = fromPntReq[1];
    ///////////////////////// end of "timing" section //////////////////////////
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + userMode);
        int tNOW = time();
        debug_print("=====Issued PointReq Time_now: " + tNOW);
    }
    // Issue TCs
    int[] stateVar = [0];
    int nbOBS = 0;
    int nbOFF = 0;
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            // Write OBSID (logical part of SlewCal)
            WriteOBSID($OBSID);
            data_rate(120.0);
            int[][] calTime = PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel);
            // Define accumulated Cal time
            int[][] sumUpCalTime = calTime;
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW ends at: " + tNOW);
                debug_print("    SumUpCalTime: " + sumUpCalTime);
            }
        } else {
            if(stateVar[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== POINT starts at: " + tNOW);
                }
                //       Regular OBCP or frequency switched OBCP?
                if(!switching) {
                    int[][] obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                } else {
                    obsTime = PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                }
                nbOBS = nbOBS + 1;
                // Logic to sum up obsTime
                if(nbOBS == 1) {
                    int[][] sumUpObsTime = obsTime;
                }
                if(nbOBS > 1) {
                    sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("    SumUpObsTime: " + sumUpObsTime);
                    debug_print("=== POINT ends at: " + tNOW);
                }
            } else {
                if(stateVar[0] == 4) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF starts at: " + tNOW);
                    }
                    //       Regular OBCP or frequency switched OBCP?
                    if(!switching) {
                        //                    Save OBS value, use OFF one, and replace OBS value
                        saveOBS = confOBCP[1]{0};
                        confOBCP[1]{0} = repeatOFF;
                        //                    Use nb_SRC_REF = 1		      
                        confOBCP[1]{3} = 1;
                        PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                        confOBCP[1]{0} = saveOBS;
                        confOBCP[1]{3} = nb_SRC_REF;
                    } else {
                        ///            obsTime =  
                        PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                    }
                    nbOFF = nbOFF + 1;
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF ends at: " + tNOW);
                    }
                } else {
                    if(stateVar[0] == 7) {
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== NOD starts at: " + tNOW);
                        }
                        obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                        nbOBS = nbOBS + 1;
                        // Logic to sum up obsTime
                        if(nbOBS == 1) {
                            sumUpObsTime = obsTime;
                        }
                        if(nbOBS > 1) {
                            sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                        }
                        if(verbose) {
                            tNOW = time();
                            debug_print("    SumUpObsTime: " + sumUpObsTime);
                            debug_print("=== NOD ends at: " + tNOW);
                        }
                    } else {
                        if(stateVar[0] == 8) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== LINE starts at: " + tNOW);
                            }
                            obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                            nbOBS = nbOBS + 1;
                            // Logic to sum up obsTime
                            if(nbOBS == 1) {
                                sumUpObsTime = obsTime;
                            }
                            if(nbOBS > 1) {
                                sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                            }
                            if(verbose) {
                                debug_print("    SumUpObsTime: " + sumUpObsTime);
                                int tLINE = tNOW + tdwell;
                                debug_print("=== LINE ends at: " + tLINE);
                                tNOW = time();
                                debug_print("=== OBCP ends at: " + tNOW);
                            }
                        } else {
                            if(stateVar[0] == 6) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== HOLD starts at: " + tNOW);
                                }
                                calTime = PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel);
                                sumUpCalTime = SumFunction(calTime,sumUpCalTime);
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("    SumUpCalTime: " + sumUpCalTime);
                                    debug_print("=== HOLD ends at: " + tNOW);
                                }
                            } else {
                                if(stateVar[0] == 5) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== FinalHOLD  starts at: " + tNOW);
                                    }
                                    SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose);
                                    data_rate(0.0);
                                    WriteEndID();
                                    tNOW = time();
                                    if(verbose) {
                                        debug_print("=== FinalHOLD  ends at: " + tNOW);
                                    }
                                } else {
                                    if(stateVar[0] == -1) {
                                        if(verbose) {
                                            tNOW = time();
                                            debug_print("=== AOT  ends at: " + tNOW);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    if(verbose) {
        debug_print("OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("Ending with NbOFF: " + nbOFF);
    }
    // The original concept of returning durations did not take into 
    // account the bandwidth of the TC bus (2 TCs/sec). The "real" 
    // duration is given by the result from the "duration()" function. Hence
    // the true total duration of the SlewCal phase is given by
    ///   calTime[0] = timeSlewCal;
    // as a result, the overheads are now
    ///   calTime[4] = calTime[0]-(calTime[1]+calTime[2]+calTime[3]); 
    if(verbose) {
        debug_print("Slew & HOLD Cal return: " + sumUpCalTime);
    }
    // The same holds true for the OBCP27 phase. However, I cannot make the
    // break-down by wavelength (the OBCP27 duration is given for ALL lines).
    // We may add up the SRC, CAL, and OVR components of OBCP27 duration. For
    // this we need a tuple so we can add the wavelength and other relevant
    // information to the (per wave) duration arrays.
    //
    //  infoArray[] contains a "fixed" global information part
    //  infoArray[0]: {Slew,   intTime,TotDur,nbRanges,nnods,m*n}
    //  infoArray[1]: {Point,  intTime,TotDur,nbRanges,nnods,m*n}
    //  infoArray[2]: {AOTinfo,intTime,TotDur,nbRanges,nnods,m*n}
    //
    // and a per wavelength array:
    //    [waveSTART,waveEND,order,gratStep,nbGratStep,TOT,SRC,REF,CAL,OVR]
    // TotDur as given by duration(); TOT,SRC,REF,CAL,OVR are also in [sec]
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    // Fill 1st dimension of infoArray with data from SlewCal
    // Instead of using timeSlewCal, use tslew time returned by PointReq
    // infoArray[0] = {{"SlewCal",0.0,timeSlewCal,0,0,0},[{0.,0.,0,0,0,0,0,0,0,0}]};
    infoArray[0] = {{"SlewCal",0.0,tslew,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Compute integration time per chopper plateau
    // intTime = nbRamps/plateau x nbRdouts/ramp x sampleInterval 
    // Sampling frequency
    double specSample = dlookup("PACSparams","spec_sample","freq_time");
    // Number of readouts per ramp
    int nbRdoutRamp = confSPECblu[1]{1};
    // NOTE: WAIT=1 are now counted as useful ramps; hence
    int wait1 = 1;
    // but there is no wait in FreqSwitch
    // Count the WAIT=1 for grating as a useful SRC
    if(switching) {
        wait1 = 1;
    }
    int nbRampPlateau = confOBCP[1]{4} + wait1;
    // 
    double intTime = double(nbRampPlateau * nbRdoutRamp) / specSample;
    if(verbose) {
        debug_print("MAIN:AOT          : " + userMode);
        debug_print("MAIN:Rdouts/ramp  : " + nbRdoutRamp);
        debug_print("MAIN:Ramps/plateau: " + nbRampPlateau);
        debug_print("MAIN:IntTime      : " + intTime);
    }
    // Replace timeOBS (per raster and per nod) with tobs from PntReq (matching
    // change in PacsProcessInfoArray)   
    // infoArray[1] = {{userMode,intTime,timeOBS,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    infoArray[1] = {{userMode,intTime,tobs,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    for(int loop3 = 0 .. nbLines1) {
        //     for some reason it has to be "initialized"
        infoArray[1]{1}[loop3] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the START wavelength (for LINE START = END = line wave)
        infoArray[1]{1}[loop3]{0} = lines[loop3]{1};
        //     copy the END   wavelength (for LINE START = END = line wave)
        infoArray[1]{1}[loop3]{1} = lines[loop3]{1};
        //     copy the grating order
        infoArray[1]{1}[loop3]{2} = waveTuple[loop3]{1};
        //     copy the grating step
        infoArray[1]{1}[loop3]{3} = waveTuple[loop3]{4};
        infoArray[1]{1}[loop3]{3} = (confOBCP[loop3 + 1]{2} - confOBCP[loop3 + 1]{1}) / 2;
        //     copy the number of grating steps
        infoArray[1]{1}[loop3]{4} = confOBCP[loop3 + 1]{6};
        //     copy other data from sumUpObsTime
        infoArray[1]{1}[loop3]{5} = sumUpObsTime[loop3][0];
        infoArray[1]{1}[loop3]{6} = sumUpObsTime[loop3][1];
        infoArray[1]{1}[loop3]{7} = sumUpObsTime[loop3][2];
        infoArray[1]{1}[loop3]{8} = sumUpObsTime[loop3][3];
        infoArray[1]{1}[loop3]{9} = sumUpObsTime[loop3][4];
    }
    // Also data from SlewCal to infoArray
    for(int loop4 = 0 .. nbKeyWAVE - 1) {
        //     for some reason it has to be "initialized"
        infoArray[0]{1}[loop4] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the wavelength
        infoArray[0]{1}[loop4]{0} = keyWAVE[loop4];
        //     copy other data from sumUpCalTimeTime
        infoArray[0]{1}[loop4]{5} = sumUpCalTime[loop4][0];
        infoArray[0]{1}[loop4]{6} = sumUpCalTime[loop4][1];
        infoArray[0]{1}[loop4]{7} = sumUpCalTime[loop4][2];
        infoArray[0]{1}[loop4]{8} = sumUpCalTime[loop4][3];
        infoArray[0]{1}[loop4]{9} = sumUpCalTime[loop4][4];
    }
    // Further update of infoArray: add information from AOT_prologue    
    infoArray[0]{1}[nbKeyWAVE] = {0.0,0.0,0,0,0,0,0,0,0,0};
    //   Copy OVR and TOT times
    infoArray[0]{1}[nbKeyWAVE]{9} = calTime[nbKeyWAVE][4];
    infoArray[0]{1}[nbKeyWAVE]{5} = calTime[nbKeyWAVE][4];
    //   Copy the number of lines observed and the number of key waves used
    infoArray[0]{0}{3} = nbKeyWAVE;
    infoArray[1]{0}{3} = nbLines;
    //   Copy the number of nod cycles and the number of raster points visited
    infoArray[1]{0}{4} = nbNods;
    infoArray[1]{0}{5} = m * n;
    // The duration of the OBS phase is given by timeObsEnd - timeSlewCal
    // Now get it from PntReq: timeObsPhase == tobs
    // int timeObsPhase = timeObsEnd - timeSlewCal;
    // Slew time during the OBS phase is then given by
    int timeSlewObs = tobs - nbOBS * timeOBS;
    if(verbose) {
        debug_print("CalSlew phase lasted [sec]: " + timeSlewCal);
        debug_print("The OBS phase lasted [sec]: " + tobs);
        debug_print("Total slew during OBS [sec]: " + timeSlewObs);
    }
    // Fill 3rd dimension of infoArray with global timing and AOT information
    // timeObsEnd is the total duration of the AOT
    // Pass details of AOT
    // We use OBCP27: OBCP_grat_scan_chop2 (unless FreqSwitch)
    string aotName = "GratScanChop2";
    // Special "sky time"  for FreqSwitch and SmallSourceDither. 
    if(switching) {
        aotName = "FreqSwitch";
    }
    // Special "sky time"  for ScanChopNoNod.
    if(pmode == "scan") {
        aotName = "GratScanChop2";
    }
    // Define source to please AOT code
    string source = "point";
    if(source == "dithered") {
        infoArray[1]{0}{0} = "SmSrcDither";
    }
    infoArray[2] = {{aotName,0.0,timeObsEnd,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Use available entries to convey m,n, and nbNods
    infoArray[2]{0}{3} = m;
    infoArray[2]{0}{4} = n;
    infoArray[2]{0}{5} = nbNods;
    // PointSources are also seen with composite_nodding
    if(pointMode == "fine_pointing" || pointMode == "composite_nodding") {
        infoArray[2]{0}{3} = 1;
        infoArray[2]{0}{4} = 1;
    }
    // For scan mode use m & n to convey the area of the mapped area [arcsec**2] and the
    // detecting element area
    if(pmode == "scan") {
        //    Assume detector size is HxW (height,width). The time spent on one sky area is
        //    H/scan, where scan is the scan rate [arcsec/sec]. The repetion factor due to
        //    scan legs is W/step + 1, where step is the scan leg separation. Hence time
        // spent on any scanned sky is (H/scan) * (W/step + 1). Another approximate formula
        // is
        //    timeSKY = tOBS*detAREA/surfSCAN
        //    Detector size (all values here in arcsec)
        double detSIZE = 47.0;
        //      Surface of one of the 5-detector columns	
        double oneCOL = legScanLength * 60.0 * detSIZE;
        double surfSCAN = double(numScanLegs - 1) * legScanLength * 60.0 * separationScanLeg + oneCOL;
        double timeOBS0 = double(numScanLegs) * legScanLength * 60.0 / rateScan;
        double fracDET = detSIZE * detSIZE / surfSCAN;
        double timeSKY = timeOBS0 * fracDET;
        //    Pass timeSKY using infoArray[1]{0}{1}
        infoArray[1]{0}{1} = timeSKY;
        if(verbose) {
            debug_print("Surface oneCOL: " + oneCOL);
            debug_print("Surface Scan: " + surfSCAN);
            debug_print("timeOBS: " + timeOBS0 + "; ratio det/map: " + fracDET);
        }
    }
    // If switching 
    if(switching && source == "Large") {
        infoArray[1]{0}{0} = "RasterOFF";
    } else {
        if(switching && source == "Point") {
            infoArray[1]{0}{0} = "Pointed";
        }
        infoArray[2]{0}{5} = userNODcycles;
    }
    // Process the information contained in infoArray (pass also lines)
    PacsProcessInfoArrayLine(infoArray,lines,confOBCP,obsOverhead,nbOBS,nbOFF,verbose);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    // Compute the total time SRC + REF
    int accumSrceRef = 0;
    for(int loopL = 0 .. nbLines - 1) {
        //   Add up Srce and Ref times (SRC + REF)
        accumSrceRef = accumSrceRef + infoArray[1]{1}[loopL]{6} + infoArray[1]{1}[loopL]{7};
    }
    // Compute overheads as total "sky" time minus SRC+REF time
    int overPACSandSC = fromPntReq[0] - accumSrceRef;
    // Return demanded tuples

    return {accumSrceRef,fromPntReq[1],overPACSandSC};
}

// File          : PACS_DropOut_Diaghk_Setup.cus
// Missionphase  : PACS FM Test
//
// Purpose       : Switch on diagnostic hk relevant to temperature sensor drop outs  
//
// Author        : H. Feuchtgruber
// CUSification  : HF
// Arguments     :
//
// Description   : Diagnostic data relevant to temperature sensor drop outs
//               :
// Comments      : Copied from FW diag hk setup
//                 
//
// Version       : 1.0
// History       : 1.0 / 18-Jun-2009 initial version by HF 
//                 
procedure PACS_DropOut_Diaghk_Setup {
}{
    // diag_hk_period  integer Diagnostic HK period : 4=synch on detect, >4=ms, 0=1KHz (not recommended)
    int diag_hk_period = 100;
    // Default time for one 'standard' command execution (sec)
    // set command_time    0.5
    // DMC_WRT_DIAG_HK_LIST
    // DMC_DATA_LENGTH            PP065420 contains the number of desired HK parameters
    // DMC_4_BYTES_WORDS_DATA     PP067420 contains the desired HK parameters' IDs
    // DMC_CHECKSUM               PP066420
    //
    //     DMC_TS_CHOP_V        622
    //     DMC_TS_FPU_T1_V      623
    //     DMC_TS_FPU_T2_V      624
    //     DMC_T_SE_SRC1_LG     571
    //     DMC_T_SE_SRC1_HG     572
    //     DMC_T_SE_SRC1_V1     573
    //     DMC_T_SE_SRC1_V2     574     
    //     DMC_CHOPPER_TEMP     407
    //     DMC_FPU_T1_T         426
    //     DMC_FPU_T2_T         427
    //     DMC_REF_VOLT_0V      428
    //     DMC_REF_VOLT_5V      430
    //     DMC_FPU_T_SENS_ST    404
    //
    //set hk_list [list {PP067420 622} {PP067420 623} {PP067420 624} {PP067420 571} \
    //                  {PP067420 572} {PP067420 573} {PP067420 574} {PP067420 407} \
    //                  {PP067420 426} {PP067420 427} {PP067420 428} {PP067420 430} \
    //                  {PP067420 404} \
    //            [list PP067420 [expr 0xFFFF]]]
    //
    // set chksum [getChkSum -d -32 $hk_list]
    int nb_words = 14;
    {int}[] list_tuple = [{622},{623},{624},{571},{572},{573},{574},{407},{426},{427},{428},{430},{404},{0xffff}];
    int[] list_int = [622,623,624,571,572,573,574,407,426,427,428,430,404,0xffff];
    int chksum = checksum("int",list_int);
    // eval tcsend PC160420 \{PP065420 14\} $hk_list \{PP066420 $chksum\}
    // waittime $command_time
    // Send the TC
    Pacs_DMC_WRT_DIAG_HK_LIST(nb_words,list_tuple,chksum);
    delay(1);
    //DMC_START_DIAG_HK
    // DIAG_HK_PERIOD             PP076420
    // tcsend PC146420 [list PP076420 $diag_hk_period]
    // waittime $command_time
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    //------------------
    // End of procedure
    //------------------
}

// Missionphase  : PACS AVM ILT Orbit-Operations
//
// Purpose       : OnBoardControlProcedure to perform
//                 staring photometry
//
// OBCP author   : Helmut Feuchtgruber
// CUS script    : Thomas G. Mueller
//
// Arguments: 
// Type  Name                 Description
// int   nb_loops             p01 Number of loops
// int   comp_mode_blu         Compression mode BLUE
// int   comp_mode_red         Ditto RED 
//
//
// Description   : This script mimics the Staring Photometry OBCP
//                 pseudo script, section 3.3 in PACS-ME-LI-005
//                 This CUS version computes the duration of the
//                 observation, as specified by the input parameters.
//                 It will also send the trigger TC to start the OBCP
//
// Dependencies  : DMC_phot_staring
//                 WriteBBID   
// Comments      : 
//
// Version       : 1.0 18-Apr-2005 Creation by TM
// History       : 1.0 18-Apr-2005 Creation by TM
//                 1.1 09-oct-2008 VD&DAC: Add sync()
//
//
int[] block OBCP_phot_staring PACS 7 {
    int nb_loops = 60; // p01 Number of loops
    int comp_mode_blu = 0; // Compression mode BLUE channel
    int comp_mode_red = 0; // Compression mode RED channel
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain system parameter from PACSparams
    // BOL readout frequency [Hz] and readout period [msec]
    double bol_freq = dlookup("PACSparams","bolo_sample","freq_time");
    string bol_unit = slookup("PACSparams","bolo_sample","unit");
    double bol_period = 1000.0 / bol_freq;
    // Obtain duration of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duration of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duration of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duration_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duration_msec [msec] as it goes)
    // OBCP_STARING_PHOTOMETRY(seq, seq_time, P#1, cmp_par_blue, cmp_par_red)
    // Begin
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DEC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) ; (all filled by DPU based on seq parameter)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Call CUS version of DECMEC sequence to obtain duration
    // Returns array with [duration_rdouts,duree_SRC,duree_REF,duree_CAL,duree_OVR]
    int[] duree1 = DMC_phot_staring(nb_loops);
    // Convert duration [readouts] into [msec]; add dmc_margin
    int seq_time = ifloor(double(duree1[0]) * bol_period) + dmc_margin;
    // Convert other times as well into msec
    duree_SRC = ifloor(double(duree1[1]) * bol_period);
    duree_REF = ifloor(double(duree1[2]) * bol_period);
    duree_CAL = ifloor(double(duree1[3]) * bol_period);
    duree_OVR = duree_OVR + ifloor(double(duree1[4]) * bol_period) + dmc_margin;
    // Tally into accumulated duration of OBCP
    duration_msec = duration_msec + seq_time;
    // DMC_SYNCHRONIZE_ON_DET(4)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_START_SEQUENCE
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(seq_time)
    //          ; Check execution status of the sequence and in case of
    //            failure stop OBCP and issue TM(1,8)+event
    // Issue TM(1,7)
    // End
    // Duration: 6 x 200ms + seq_time + 0.5s
    // This procedure calls the sequence described in sec.4.1.3.
    //
    // Now trigger execution of OBCP
    // This OBCP is number 7, requires 5 parameters and lasts seq_time [msec]
    string obcp_ID = "STARING_PHOT";
    int obcp_par_nber = 5;
    int seq_DMC = 3;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_loops},{4,comp_mode_blu},{5,comp_mode_red}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nber,grp);
    // Add the "communication jitter"
    duration_msec = duration_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Return total duration [sec] to calling program
    // Create return time array; convert into [sec]
    int[] time_array = [duration_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // Set delay()
    delay(time_array[0]);
    // Ending time
    int time_elapsed = time() - time_start;
    time_array[0] = time_elapsed;
    // Return
    WriteEndBB();
    // Add  sync
    sync();

    return time_array;
}

// Filename	 : Pacs_Spec_Prepare_EMC
// Purpose       :  EMC preparation
//                  
//                 
//
// TCL author    : HF
// TCL file      : 
// CUS author    : HF 
// Script file   : SPEC_Prepare_EMC.txt 
//
// Input arguments none
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Sets chopper, grating and the SPU
//                            
//                           
//                            
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                             
//                 
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0 29-Mar-2005 creation by HF
// 		  2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
procedure Pacs_Spec_Prepare_EMC {
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp 
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp 
    int nb_raw_spu_blu = 3; // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3; // Nb of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0; // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true; // Start SPU or not [true,false]
    int chop_pos = -21350; // Chopper position
    int grat_pos = 500000; // Grating position
}{
    // Configure and start both SPUs
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Move the Chopper and the Grating to the defined position for "most sensitive" mode
    SPEC_MOV_CHOP_and_GRAT(chop_pos,grat_pos);
}

// Missionphase  : FM
//
// Purpose	:  Setup diagnostic housekeeping for the FM 
//                 detector test PTD 0.7.6 in spectroscopy.
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: Set up  housekeeping parameter for diagnostic housekeeping 
//	  of the detector.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy.
//                 
// Comments	: 
//
// Version	: 3.0	
// 
// History 	: 1.0 27-07-06 creation by HD. script test.
//                2.0 27-07-06 HD. script works.
//		  3.0 20-06-07 HD. Prepare Test for FM-ILT3.
block SPEC_chop_det_dhk_fmilt076spec_V1_bb PACS 385 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //----------------------------------------------------- 
    // Setup and start diagnostic HK for PTD 0.7.6 V1
    //----------------------------------------------------- 
    int diag_hk_length = 16;
    {int}[] parlist = [{209},{244},{245},{246},{290},{291},{298},{324},{325},{332},{358},{359},{366},{392},{393},{0xffff}];
    int[] aux = [209,244,245,246,290,291,298,324,325,332,358,359,366,392,393,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(diag_hk_length,parlist,check_sum);
    int diag_hk_period = 1;
    // Synchronize diagnostic HK on blue spectrometer readouts
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark End of Block
    WriteEndBB();
}

// CVS file      : CONF_spec_fltw_redundant.txt
// Missionphase  : FMILT_3 & Later
//
// Purpose       : CONFigure the spectro filter wheel servo loop
//                  
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 0.1 13-Oct-2004 Creation by DAC
// History       : 0.2  4-jul-2006 Removed "return" statement
//                 1.0 11-Jun-2007 PR New scheme due to new format of configuration command
//                                               (DMC UM v.4.3)
// 1.1 DAC 20-jun-2007 Use _R row
//               :
procedure CONF_spec_fltw_redundant {
}{
    string calUname = "CONFFWSPEC";
    // FWSPEC CALIBRATION TABLE
    string calUrow = "FMILT_R";
    // INSTRUMENT VERSION
    int rate = ilookup(calUname,calUrow,"Rate");
    int current = ilookup(calUname,calUrow,"Drive_current");
    int threshold_A = ilookup(calUname,calUrow,"Threshold_A");
    int threshold_B = ilookup(calUname,calUrow,"Threshold_B");
    int status_A = ilookup(calUname,calUrow,"Status_A");
    int status_B = ilookup(calUname,calUrow,"Status_B");
    {int}[] parlist = [{rate},{current},{threshold_A},{threshold_B},{status_A},{status_B}];
    int[] aux = [rate,current,threshold_A,threshold_B,status_A,status_B];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_FWSPEC_CONF_PAR(parlist,check_sum);
}

// Script file   : PACS_Spec_Gra_IST_PID_Loop_Less_OBS.cus 
//
// Purpose       :  Run a loop of tens of different sets of PID parameters
//
// Description  : For each set, performs a dozen of small and two larger movements
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
//                 1.1  13-Nov-2007 BV: added MOIS comments
//		   2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
procedure Pacs_Spec_Gra_IST_PID_Loop_Less {
}{
    mois_comment("Start of procedure: Run a grid of less daring PID parameters");
    // Register start of OBS
    //
    mois_step("Configure Nominal SPEC_HK");
    debug_print("Configure Nominal SPEC_HK");
    PACS_Spec_HK_Setup();
    //
    debug_print("Configure DIAG_HK");
    mois_step("Configure DIAG_HK");
    int diag_hk_period = 5;
    PACS_Spec_Gra_Diaghk_Setup(diag_hk_period);
    //
    mois_step("Configure Grating");
    debug_print("Configure Grating");
    string calUname = "CONFGrat";
    string calUrow = "IST";
    CONF_grating(calUname,calUrow);
    delay(10);
    //
    mois_step("Loop over PID parameters and perform diagnostic movements");
    debug_print("PID LOOP : PIDs smaller than in FMILT");
    PACS_Spec_Gra_PID_loop_Short_Less();
    //
    mois_step("Reset Diagnostic housekeeping");
    debug_print("Reset DIAG_HK");
    PACS_Diaghk_Reset();
    //
    mois_step("PACS to safe mode");
    debug_print("PACS to SAFE MODE");
    OBCP_SAFE();
    delay(10);
}

// Mission phase : PV Phase
//
// Purpose : PCD req.1.1.1bis for the PV Phase
//           Measure the responsivity with a 4x9 raster on a point source
//           and the noise on a off pointing position. An offset in -Y allows to
//           measure the noise during the last 4 pointings.
//
// Author : Koryo Okumura
//
// Version : Wed Jul 29 04:25:45 EDT 2009
//
// CUS script : procedure Phot_highGainBiasDirect
//
// Argument :
//   string select = "ginit" in ["ginit","g1_0","g1_3","g1_6","g1_7","g1_8","g1_9","g2_0","g2_1","g2_2","g2_3","g2_4","g2_5","g2_6","g2_7","g2_8","g2_9","g3_0","g3_1","g3_3","g3_5","binit","b1_0","b1_3","b1_6","b1_7","b1_8","b1_9","b2_0","b2_1","b2_2","b2_3","b2_4","b2_5","b2_6","b2_7","b2_8","b2_9","b3_0","b3_1","b3_3","b3_5","final"]; // Select a configuration or initialize or finalize
//   string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   According to "select" set the photometer in a configuration before a raster
//   - ginit or binit :
//     + Set a filter corresponding to the given "selection"
//     + Set the biases group by group
//     + Set the chopper on the optical center
//   - in general :
//     + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group corresponding to the selected bias
//     + Do a raster measurement by the calling obs script PacsCal_Phot_highGainBiasDirect_Fix or PacsCal_Phot_highGainBiasDirect
//   - final :
//     + The biases are set following a given bias table
//
// Dependencies : Commissioning and PV data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_highGainBias(1, "HIGH")
//
procedure Phot_highGainBiasDirect {
    string select = "ginit" in ["ginit","g1_0","g1_3","g1_6","g1_7","g1_8","g1_9","g2_0","g2_1","g2_2","g2_3","g2_4","g2_5","g2_6","g2_7","g2_8","g2_9","g3_0","g3_1","g3_3","g3_5","binit","b1_0","b1_3","b1_6","b1_7","b1_8","b1_9","b2_0","b2_1","b2_2","b2_3","b2_4","b2_5","b2_6","b2_7","b2_8","b2_9","b3_0","b3_1","b3_3","b3_5","final"]; // Sequence number to define a configuration
    string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
}{
    if(select == "ginit") {
        //
        //*******************************
        // Select Filter A (100 microns)
        //*******************************
        //
        PHOT_fltw_move("POS A");
        //
        //*************************************************
        // Set the biases and start SPU, then set the gain
        //*************************************************
        //
        PHOT_change_biases(startBiasTable,"DIRECT","HIGH");
        //
        //**********************************************
        // Set the PACS chopper at the position 664
        //**********************************************
        //
        Pacs_DMC_MOVE_CHOP_ABS(664);
        //
        //**********************************************************************
        //                       Measurement
        // Background fluxes 0.90pW on green and 4.00pW on red
        //**********************************************************************
        //
        // sync the bus
        sync();
    }
    if(select == "g1_0") {
        //***********************************************************
        // Bias 1 (Vh-Vl)bleu = 1.0 Volts, (Vh-Vl)rouge = 1.0 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G1(0.99);
        // Set group 1 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G1(-0.01);
        // Set group 1 bol bias 03 (VRL) to 0.31491130488121843 Volts
        Pacs_BOLC_SET_VRL_G1(0.31491130488121843);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.8110596864511221 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.8110596864511221);
        // Set group 2 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G2(0.99);
        // Set group 2 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G2(-0.01);
        // Set group 2 bol bias 03 (VRL) to 0.3215626823200911 Volts
        Pacs_BOLC_SET_VRL_G2(0.3215626823200911);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.8170382701841934 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.8170382701841934);
        // Set group 3 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G3(0.99);
        // Set group 3 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G3(-0.01);
        // Set group 3 bol bias 03 (VRL) to 0.3165614686762489 Volts
        Pacs_BOLC_SET_VRL_G3(0.3165614686762489);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.8126483268747755 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.8126483268747755);
        // Set group 4 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G4(0.99);
        // Set group 4 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G4(-0.01);
        // Set group 4 bol bias 03 (VRL) to 0.3074090931646965 Volts
        Pacs_BOLC_SET_VRL_G4(0.3074090931646965);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.8040091353360972 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.8040091353360972);
        // Set group 5 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G5(0.99);
        // Set group 5 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G5(-0.01);
        // Set group 5 bol bias 03 (VRL) to 0.36201755468700786 Volts
        Pacs_BOLC_SET_VRL_G5(0.36201755468700786);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.9021910348181166 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.9021910348181166);
        // Set group 6 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G6(0.99);
        // Set group 6 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G6(-0.01);
        // Set group 6 bol bias 03 (VRL) to 0.3533438794439342 Volts
        Pacs_BOLC_SET_VRL_G6(0.3533438794439342);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.8633797020856684 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.8633797020856684);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g1_3") {
        //***********************************************************
        // Bias 2 (Vh-Vl)bleu = 1.3 Volts, (Vh-Vl)rouge = 1.1 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.2604418530690626 Volts
        Pacs_BOLC_SET_VH_G1(1.2604418530690626);
        // Set group 1 bol bias 02 (VL) to -0.039558146930937475 Volts
        Pacs_BOLC_SET_VL_G1(-0.039558146930937475);
        // Set group 1 bol bias 03 (VRL) to 0.39289641464607533 Volts
        Pacs_BOLC_SET_VRL_G1(0.39289641464607533);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9766782902708646 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9766782902708646);
        // Set group 2 bol bias 01 (VH) to 1.2498739910541468 Volts
        Pacs_BOLC_SET_VH_G2(1.2498739910541468);
        // Set group 2 bol bias 02 (VL) to -0.05012600894585325 Volts
        Pacs_BOLC_SET_VL_G2(-0.05012600894585325);
        // Set group 2 bol bias 03 (VRL) to 0.38973301197020527 Volts
        Pacs_BOLC_SET_VRL_G2(0.38973301197020527);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9731057042643696 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9731057042643696);
        // Set group 3 bol bias 01 (VH) to 1.2515928357832167 Volts
        Pacs_BOLC_SET_VH_G3(1.2515928357832167);
        // Set group 3 bol bias 02 (VL) to -0.04840716421678328 Volts
        Pacs_BOLC_SET_VL_G3(-0.04840716421678328);
        // Set group 3 bol bias 03 (VRL) to 0.3894785311214204 Volts
        Pacs_BOLC_SET_VRL_G3(0.3894785311214204);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9736637244409159 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9736637244409159);
        // Set group 4 bol bias 01 (VH) to 1.2635401056840647 Volts
        Pacs_BOLC_SET_VH_G4(1.2635401056840647);
        // Set group 4 bol bias 02 (VL) to -0.0364598943159354 Volts
        Pacs_BOLC_SET_VL_G4(-0.0364598943159354);
        // Set group 4 bol bias 03 (VRL) to 0.38594958764314397 Volts
        Pacs_BOLC_SET_VRL_G4(0.38594958764314397);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.992820860208166 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.992820860208166);
        // Set group 5 bol bias 01 (VH) to 1.09 Volts
        Pacs_BOLC_SET_VH_G5(1.09);
        // Set group 5 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G5(-0.01);
        // Set group 5 bol bias 03 (VRL) to 0.3988167414134357 Volts
        Pacs_BOLC_SET_VRL_G5(0.3988167414134357);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.8938178971254427 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.8938178971254427);
        // Set group 6 bol bias 01 (VH) to 1.09 Volts
        Pacs_BOLC_SET_VH_G6(1.09);
        // Set group 6 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G6(-0.01);
        // Set group 6 bol bias 03 (VRL) to 0.38957428152869855 Volts
        Pacs_BOLC_SET_VRL_G6(0.38957428152869855);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.8769480931267648 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.8769480931267648);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g1_6") {
        //***********************************************************
        // Bias 3 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.4466042467331648 Volts
        Pacs_BOLC_SET_VH_G1(1.4466042467331648);
        // Set group 1 bol bias 02 (VL) to -0.1533957532668354 Volts
        Pacs_BOLC_SET_VL_G1(-0.1533957532668354);
        // Set group 1 bol bias 03 (VRL) to 0.3931184799278562 Volts
        Pacs_BOLC_SET_VRL_G1(0.3931184799278562);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9768976175854893 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9768976175854893);
        // Set group 2 bol bias 01 (VH) to 1.4348666737564109 Volts
        Pacs_BOLC_SET_VH_G2(1.4348666737564109);
        // Set group 2 bol bias 02 (VL) to -0.16513332624358923 Volts
        Pacs_BOLC_SET_VL_G2(-0.16513332624358923);
        // Set group 2 bol bias 03 (VRL) to 0.38935224534697577 Volts
        Pacs_BOLC_SET_VRL_G2(0.38935224534697577);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9727293430298154 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9727293430298154);
        // Set group 3 bol bias 01 (VH) to 1.4360911903448164 Volts
        Pacs_BOLC_SET_VH_G3(1.4360911903448164);
        // Set group 3 bol bias 02 (VL) to -0.16390880965518373 Volts
        Pacs_BOLC_SET_VL_G3(-0.16390880965518373);
        // Set group 3 bol bias 03 (VRL) to 0.3896621581853307 Volts
        Pacs_BOLC_SET_VRL_G3(0.3896621581853307);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9738464077847953 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9738464077847953);
        // Set group 4 bol bias 01 (VH) to 1.451604038362524 Volts
        Pacs_BOLC_SET_VH_G4(1.451604038362524);
        // Set group 4 bol bias 02 (VL) to -0.14839596163747615 Volts
        Pacs_BOLC_SET_VL_G4(-0.14839596163747615);
        // Set group 4 bol bias 03 (VRL) to 0.38721550093595813 Volts
        Pacs_BOLC_SET_VRL_G4(0.38721550093595813);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9940809535263424 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9940809535263424);
        // Set group 5 bol bias 01 (VH) to 1.176830084971648 Volts
        Pacs_BOLC_SET_VH_G5(1.176830084971648);
        // Set group 5 bol bias 02 (VL) to -0.023169915028352042 Volts
        Pacs_BOLC_SET_VL_G5(-0.023169915028352042);
        // Set group 5 bol bias 03 (VRL) to 0.423605592820457 Volts
        Pacs_BOLC_SET_VRL_G5(0.423605592820457);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.9186309231847374 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.9186309231847374);
        // Set group 6 bol bias 01 (VH) to 1.19 Volts
        Pacs_BOLC_SET_VH_G6(1.19);
        // Set group 6 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G6(-0.01);
        // Set group 6 bol bias 03 (VRL) to 0.42683111640625715 Volts
        Pacs_BOLC_SET_VRL_G6(0.42683111640625715);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.9139108739371622 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.9139108739371622);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g1_7") {
        //***********************************************************
        // Bias 4 (Vh-Vl)bleu = 1.7 Volts, (Vh-Vl)rouge = 1.3 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.5103025129380314 Volts
        Pacs_BOLC_SET_VH_G1(1.5103025129380314);
        // Set group 1 bol bias 02 (VL) to -0.18969748706196854 Volts
        Pacs_BOLC_SET_VL_G1(-0.18969748706196854);
        // Set group 1 bol bias 03 (VRL) to 0.39334126989340834 Volts
        Pacs_BOLC_SET_VRL_G1(0.39334126989340834);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9771176574542377 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9771176574542377);
        // Set group 2 bol bias 01 (VH) to 1.4981688599762897 Volts
        Pacs_BOLC_SET_VH_G2(1.4981688599762897);
        // Set group 2 bol bias 02 (VL) to -0.20183114002371028 Volts
        Pacs_BOLC_SET_VL_G2(-0.20183114002371028);
        // Set group 2 bol bias 03 (VRL) to 0.3895018797527151 Volts
        Pacs_BOLC_SET_VRL_G2(0.3895018797527151);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9728772469622824 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9728772469622824);
        // Set group 3 bol bias 01 (VH) to 1.4988973586426284 Volts
        Pacs_BOLC_SET_VH_G3(1.4988973586426284);
        // Set group 3 bol bias 02 (VL) to -0.20110264135737144 Volts
        Pacs_BOLC_SET_VL_G3(-0.20110264135737144);
        // Set group 3 bol bias 03 (VRL) to 0.38988321326629705 Volts
        Pacs_BOLC_SET_VRL_G3(0.38988321326629705);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.974066326737784 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.974066326737784);
        // Set group 4 bol bias 01 (VH) to 1.5153710271389698 Volts
        Pacs_BOLC_SET_VH_G4(1.5153710271389698);
        // Set group 4 bol bias 02 (VL) to -0.1846289728610302 Volts
        Pacs_BOLC_SET_VL_G4(-0.1846289728610302);
        // Set group 4 bol bias 03 (VRL) to 0.38759598061305345 Volts
        Pacs_BOLC_SET_VRL_G4(0.38759598061305345);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9944596772055088 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9944596772055088);
        // Set group 5 bol bias 01 (VH) to 1.2373765147884428 Volts
        Pacs_BOLC_SET_VH_G5(1.2373765147884428);
        // Set group 5 bol bias 02 (VL) to -0.06262348521155736 Volts
        Pacs_BOLC_SET_VL_G5(-0.06262348521155736);
        // Set group 5 bol bias 03 (VRL) to 0.4231546601820514 Volts
        Pacs_BOLC_SET_VRL_G5(0.4231546601820514);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0737330353761743 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0737330353761743);
        // Set group 6 bol bias 01 (VH) to 1.2620813870511016 Volts
        Pacs_BOLC_SET_VH_G6(1.2620813870511016);
        // Set group 6 bol bias 02 (VL) to -0.03791861294889845 Volts
        Pacs_BOLC_SET_VL_G6(-0.03791861294889845);
        // Set group 6 bol bias 03 (VRL) to 0.4365536756619326 Volts
        Pacs_BOLC_SET_VRL_G6(0.4365536756619326);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0125308363899257 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0125308363899257);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g1_8") {
        //***********************************************************
        // Bias 5 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.5746054260860674 Volts
        Pacs_BOLC_SET_VH_G1(1.5746054260860674);
        // Set group 1 bol bias 02 (VL) to -0.2253945739139327 Volts
        Pacs_BOLC_SET_VL_G1(-0.2253945739139327);
        // Set group 1 bol bias 03 (VRL) to 0.3932716162847716 Volts
        Pacs_BOLC_SET_VRL_G1(0.3932716162847716);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9770488639865138 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9770488639865138);
        // Set group 2 bol bias 01 (VH) to 1.5618613714796097 Volts
        Pacs_BOLC_SET_VH_G2(1.5618613714796097);
        // Set group 2 bol bias 02 (VL) to -0.23813862852039025 Volts
        Pacs_BOLC_SET_VL_G2(-0.23813862852039025);
        // Set group 2 bol bias 03 (VRL) to 0.38927245764630447 Volts
        Pacs_BOLC_SET_VRL_G2(0.38927245764630447);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9726504776431222 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9726504776431222);
        // Set group 3 bol bias 01 (VH) to 1.5626563338488486 Volts
        Pacs_BOLC_SET_VH_G3(1.5626563338488486);
        // Set group 3 bol bias 02 (VL) to -0.23734366615115154 Volts
        Pacs_BOLC_SET_VL_G3(-0.23734366615115154);
        // Set group 3 bol bias 03 (VRL) to 0.39010656105086017 Volts
        Pacs_BOLC_SET_VRL_G3(0.39010656105086017);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9520663043298032 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9520663043298032);
        // Set group 4 bol bias 01 (VH) to 1.5803345539887472 Volts
        Pacs_BOLC_SET_VH_G4(1.5803345539887472);
        // Set group 4 bol bias 02 (VL) to -0.21966544601125282 Volts
        Pacs_BOLC_SET_VL_G4(-0.21966544601125282);
        // Set group 4 bol bias 03 (VRL) to 0.38802691306918746 Volts
        Pacs_BOLC_SET_VRL_G4(0.38802691306918746);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9948886170390088 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9948886170390088);
        // Set group 5 bol bias 01 (VH) to 1.2990548950746752 Volts
        Pacs_BOLC_SET_VH_G5(1.2990548950746752);
        // Set group 5 bol bias 02 (VL) to -0.1009451049253246 Volts
        Pacs_BOLC_SET_VL_G5(-0.1009451049253246);
        // Set group 5 bol bias 03 (VRL) to 0.42253767898766403 Volts
        Pacs_BOLC_SET_VRL_G5(0.42253767898766403);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.073112590654842 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.073112590654842);
        // Set group 6 bol bias 01 (VH) to 1.3235509250997841 Volts
        Pacs_BOLC_SET_VH_G6(1.3235509250997841);
        // Set group 6 bol bias 02 (VL) to -0.07644907490021571 Volts
        Pacs_BOLC_SET_VL_G6(-0.07644907490021571);
        // Set group 6 bol bias 03 (VRL) to 0.4356120279464395 Volts
        Pacs_BOLC_SET_VRL_G6(0.4356120279464395);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0115879408988957 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0115879408988957);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g1_9") {
        //***********************************************************
        // Bias 6 (Vh-Vl)bleu = 1.9 Volts, (Vh-Vl)rouge = 1.5 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.6402199051027921 Volts
        Pacs_BOLC_SET_VH_G1(1.6402199051027921);
        // Set group 1 bol bias 02 (VL) to -0.25978009489720777 Volts
        Pacs_BOLC_SET_VL_G1(-0.25978009489720777);
        // Set group 1 bol bias 03 (VRL) to 0.3931898746876479 Volts
        Pacs_BOLC_SET_VRL_G1(0.3931898746876479);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9769681314039869 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9769681314039869);
        // Set group 2 bol bias 01 (VH) to 1.6266725708788872 Volts
        Pacs_BOLC_SET_VH_G2(1.6266725708788872);
        // Set group 2 bol bias 02 (VL) to -0.27332742912111274 Volts
        Pacs_BOLC_SET_VL_G2(-0.27332742912111274);
        // Set group 2 bol bias 03 (VRL) to 0.389108175849032 Volts
        Pacs_BOLC_SET_VRL_G2(0.389108175849032);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9724880939910572 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9724880939910572);
        // Set group 3 bol bias 01 (VH) to 1.6383684660823183 Volts
        Pacs_BOLC_SET_VH_G3(1.6383684660823183);
        // Set group 3 bol bias 02 (VL) to -0.2616315339176816 Volts
        Pacs_BOLC_SET_VL_G3(-0.2616315339176816);
        // Set group 3 bol bias 03 (VRL) to 0.40130564291962717 Volts
        Pacs_BOLC_SET_VRL_G3(0.40130564291962717);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.963203735882543 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.963203735882543);
        // Set group 4 bol bias 01 (VH) to 1.6464466803651918 Volts
        Pacs_BOLC_SET_VH_G4(1.6464466803651918);
        // Set group 4 bol bias 02 (VL) to -0.253553319634808 Volts
        Pacs_BOLC_SET_VL_G4(-0.253553319634808);
        // Set group 4 bol bias 03 (VRL) to 0.38846072438079005 Volts
        Pacs_BOLC_SET_VRL_G4(0.38846072438079005);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9953204183673823 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9953204183673823);
        // Set group 5 bol bias 01 (VH) to 1.361967639315405 Volts
        Pacs_BOLC_SET_VH_G5(1.361967639315405);
        // Set group 5 bol bias 02 (VL) to -0.1380323606845949 Volts
        Pacs_BOLC_SET_VL_G5(-0.1380323606845949);
        // Set group 5 bol bias 03 (VRL) to 0.42173840001161234 Volts
        Pacs_BOLC_SET_VRL_G5(0.42173840001161234);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0723087762240313 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0723087762240313);
        // Set group 6 bol bias 01 (VH) to 1.3868176040333537 Volts
        Pacs_BOLC_SET_VH_G6(1.3868176040333537);
        // Set group 6 bol bias 02 (VL) to -0.11318239596664628 Volts
        Pacs_BOLC_SET_VL_G6(-0.11318239596664628);
        // Set group 6 bol bias 03 (VRL) to 0.43419935624396677 Volts
        Pacs_BOLC_SET_VRL_G6(0.43419935624396677);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.010173163758215 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.010173163758215);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_0") {
        //***********************************************************
        // Bias 7 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.7072552504837253 Volts
        Pacs_BOLC_SET_VH_G1(1.7072552504837253);
        // Set group 1 bol bias 02 (VL) to -0.2927447495162747 Volts
        Pacs_BOLC_SET_VL_G1(-0.2927447495162747);
        // Set group 1 bol bias 03 (VRL) to 0.39300694397919855 Volts
        Pacs_BOLC_SET_VRL_G1(0.39300694397919855);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9767874572233488 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9767874572233488);
        // Set group 2 bol bias 01 (VH) to 1.692663076962388 Volts
        Pacs_BOLC_SET_VH_G2(1.692663076962388);
        // Set group 2 bol bias 02 (VL) to -0.30733692303761195 Volts
        Pacs_BOLC_SET_VL_G2(-0.30733692303761195);
        // Set group 2 bol bias 03 (VRL) to 0.3887091184811946 Volts
        Pacs_BOLC_SET_VRL_G2(0.3887091184811946);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9720936424409112 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9720936424409112);
        // Set group 3 bol bias 01 (VH) to 1.704185527633064 Volts
        Pacs_BOLC_SET_VH_G3(1.704185527633064);
        // Set group 3 bol bias 02 (VL) to -0.295814472366936 Volts
        Pacs_BOLC_SET_VL_G3(-0.295814472366936);
        // Set group 3 bol bias 03 (VRL) to 0.4014500719789626 Volts
        Pacs_BOLC_SET_VRL_G3(0.4014500719789626);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9633466285199563 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9633466285199563);
        // Set group 4 bol bias 01 (VH) to 1.7140968369777032 Volts
        Pacs_BOLC_SET_VH_G4(1.7140968369777032);
        // Set group 4 bol bias 02 (VL) to -0.2859031630222967 Volts
        Pacs_BOLC_SET_VL_G4(-0.2859031630222967);
        // Set group 4 bol bias 03 (VRL) to 0.3891942580835225 Volts
        Pacs_BOLC_SET_VRL_G4(0.3891942580835225);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9960505441377652 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9960505441377652);
        // Set group 5 bol bias 01 (VH) to 1.4140772343701025 Volts
        Pacs_BOLC_SET_VH_G5(1.4140772343701025);
        // Set group 5 bol bias 02 (VL) to -0.18592276562989757 Volts
        Pacs_BOLC_SET_VL_G5(-0.18592276562989757);
        // Set group 5 bol bias 03 (VRL) to 0.40997067244647206 Volts
        Pacs_BOLC_SET_VRL_G5(0.40997067244647206);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0604679247843345 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0604679247843345);
        // Set group 6 bol bias 01 (VH) to 1.4508528288233054 Volts
        Pacs_BOLC_SET_VH_G6(1.4508528288233054);
        // Set group 6 bol bias 02 (VL) to -0.14914717117669465 Volts
        Pacs_BOLC_SET_VL_G6(-0.14914717117669465);
        // Set group 6 bol bias 03 (VRL) to 0.43354239736180156 Volts
        Pacs_BOLC_SET_VRL_G6(0.43354239736180156);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.009515130266216 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.009515130266216);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_1") {
        //***********************************************************
        // Bias 8 (Vh-Vl)bleu = 2.1 Volts, (Vh-Vl)rouge = 1.7 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.7763064474811254 Volts
        Pacs_BOLC_SET_VH_G1(1.7763064474811254);
        // Set group 1 bol bias 02 (VL) to -0.32369355251887477 Volts
        Pacs_BOLC_SET_VL_G1(-0.32369355251887477);
        // Set group 1 bol bias 03 (VRL) to 0.3929117872458944 Volts
        Pacs_BOLC_SET_VRL_G1(0.3929117872458944);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9766934734357156 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9766934734357156);
        // Set group 2 bol bias 01 (VH) to 1.760421890972815 Volts
        Pacs_BOLC_SET_VH_G2(1.760421890972815);
        // Set group 2 bol bias 02 (VL) to -0.3395781090271849 Volts
        Pacs_BOLC_SET_VL_G2(-0.3395781090271849);
        // Set group 2 bol bias 03 (VRL) to 0.3885757589950336 Volts
        Pacs_BOLC_SET_VRL_G2(0.3885757589950336);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9719618205852854 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9719618205852854);
        // Set group 3 bol bias 01 (VH) to 1.7720431785316175 Volts
        Pacs_BOLC_SET_VH_G3(1.7720431785316175);
        // Set group 3 bol bias 02 (VL) to -0.3279568214683825 Volts
        Pacs_BOLC_SET_VL_G3(-0.3279568214683825);
        // Set group 3 bol bias 03 (VRL) to 0.4018779497744413 Volts
        Pacs_BOLC_SET_VRL_G3(0.4018779497744413);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9859921836646144 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9859921836646144);
        // Set group 4 bol bias 01 (VH) to 1.7844121897694236 Volts
        Pacs_BOLC_SET_VH_G4(1.7844121897694236);
        // Set group 4 bol bias 02 (VL) to -0.31558781023057647 Volts
        Pacs_BOLC_SET_VL_G4(-0.31558781023057647);
        // Set group 4 bol bias 03 (VRL) to 0.39037916192256217 Volts
        Pacs_BOLC_SET_VRL_G4(0.39037916192256217);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9972299184858024 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9972299184858024);
        // Set group 5 bol bias 01 (VH) to 1.477526658704948 Volts
        Pacs_BOLC_SET_VH_G5(1.477526658704948);
        // Set group 5 bol bias 02 (VL) to -0.22247334129505197 Volts
        Pacs_BOLC_SET_VL_G5(-0.22247334129505197);
        // Set group 5 bol bias 03 (VRL) to 0.40905936069000043 Volts
        Pacs_BOLC_SET_VRL_G5(0.40905936069000043);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.059550453875679 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.059550453875679);
        // Set group 6 bol bias 01 (VH) to 1.5151586609905838 Volts
        Pacs_BOLC_SET_VH_G6(1.5151586609905838);
        // Set group 6 bol bias 02 (VL) to -0.18484133900941616 Volts
        Pacs_BOLC_SET_VL_G6(-0.18484133900941616);
        // Set group 6 bol bias 03 (VRL) to 0.43253382177085165 Volts
        Pacs_BOLC_SET_VRL_G6(0.43253382177085165);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0085060936227923 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0085060936227923);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_2") {
        //***********************************************************
        // Bias 9 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.8 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.8477065354350637 Volts
        Pacs_BOLC_SET_VH_G1(1.8477065354350637);
        // Set group 1 bol bias 02 (VL) to -0.3522934645649365 Volts
        Pacs_BOLC_SET_VL_G1(-0.3522934645649365);
        // Set group 1 bol bias 03 (VRL) to 0.3928551010344241 Volts
        Pacs_BOLC_SET_VRL_G1(0.3928551010344241);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.976637485687116 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.976637485687116);
        // Set group 2 bol bias 01 (VH) to 1.8296090411271155 Volts
        Pacs_BOLC_SET_VH_G2(1.8296090411271155);
        // Set group 2 bol bias 02 (VL) to -0.37039095887288453 Volts
        Pacs_BOLC_SET_VL_G2(-0.37039095887288453);
        // Set group 2 bol bias 03 (VRL) to 0.38775841031856695 Volts
        Pacs_BOLC_SET_VRL_G2(0.38775841031856695);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9711538787251761 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9711538787251761);
        // Set group 3 bol bias 01 (VH) to 1.841519930396799 Volts
        Pacs_BOLC_SET_VH_G3(1.841519930396799);
        // Set group 3 bol bias 02 (VL) to -0.35848006960320106 Volts
        Pacs_BOLC_SET_VL_G3(-0.35848006960320106);
        // Set group 3 bol bias 03 (VRL) to 0.40195292210921824 Volts
        Pacs_BOLC_SET_VRL_G3(0.40195292210921824);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9638441384832317 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9638441384832317);
        // Set group 4 bol bias 01 (VH) to 1.8560275203811134 Volts
        Pacs_BOLC_SET_VH_G4(1.8560275203811134);
        // Set group 4 bol bias 02 (VL) to -0.3439724796188869 Volts
        Pacs_BOLC_SET_VL_G4(-0.3439724796188869);
        // Set group 4 bol bias 03 (VRL) to 0.3911662396825011 Volts
        Pacs_BOLC_SET_VRL_G4(0.3911662396825011);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9980133065056234 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9980133065056234);
        // Set group 5 bol bias 01 (VH) to 1.5419730265537344 Volts
        Pacs_BOLC_SET_VH_G5(1.5419730265537344);
        // Set group 5 bol bias 02 (VL) to -0.25802697344626574 Volts
        Pacs_BOLC_SET_VL_G5(-0.25802697344626574);
        // Set group 5 bol bias 03 (VRL) to 0.407947187499842 Volts
        Pacs_BOLC_SET_VRL_G5(0.407947187499842);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0584306672751223 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0584306672751223);
        // Set group 6 bol bias 01 (VH) to 1.5800659587002086 Volts
        Pacs_BOLC_SET_VH_G6(1.5800659587002086);
        // Set group 6 bol bias 02 (VL) to -0.21993404129979136 Volts
        Pacs_BOLC_SET_VL_G6(-0.21993404129979136);
        // Set group 6 bol bias 03 (VRL) to 0.4311454765153988 Volts
        Pacs_BOLC_SET_VRL_G6(0.4311454765153988);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0071167605145566 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0071167605145566);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_3") {
        //***********************************************************
        // Bias 10 (Vh-Vl)bleu = 2.3 Volts, (Vh-Vl)rouge = 1.9 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.9215770642413583 Volts
        Pacs_BOLC_SET_VH_G1(1.9215770642413583);
        // Set group 1 bol bias 02 (VL) to -0.3784229357586415 Volts
        Pacs_BOLC_SET_VL_G1(-0.3784229357586415);
        // Set group 1 bol bias 03 (VRL) to 0.3926472775679627 Volts
        Pacs_BOLC_SET_VRL_G1(0.3926472775679627);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9764322211591614 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9764322211591614);
        // Set group 2 bol bias 01 (VH) to 1.9015583161672205 Volts
        Pacs_BOLC_SET_VH_G2(1.9015583161672205);
        // Set group 2 bol bias 02 (VL) to -0.39844168383277934 Volts
        Pacs_BOLC_SET_VL_G2(-0.39844168383277934);
        // Set group 2 bol bias 03 (VRL) to 0.3872580365783701 Volts
        Pacs_BOLC_SET_VRL_G2(0.3872580365783701);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9928814713939536 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9928814713939536);
        // Set group 3 bol bias 01 (VH) to 1.924712550703177 Volts
        Pacs_BOLC_SET_VH_G3(1.924712550703177);
        // Set group 3 bol bias 02 (VL) to -0.37528744929682273 Volts
        Pacs_BOLC_SET_VL_G3(-0.37528744929682273);
        // Set group 3 bol bias 03 (VRL) to 0.4133853220168953 Volts
        Pacs_BOLC_SET_VRL_G3(0.4133853220168953);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9751488705414568 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9751488705414568);
        // Set group 4 bol bias 01 (VH) to 1.9295265554899754 Volts
        Pacs_BOLC_SET_VH_G4(1.9295265554899754);
        // Set group 4 bol bias 02 (VL) to -0.3704734445100245 Volts
        Pacs_BOLC_SET_VL_G4(-0.3704734445100245);
        // Set group 4 bol bias 03 (VRL) to 0.3913944030216683 Volts
        Pacs_BOLC_SET_VRL_G4(0.3913944030216683);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9982403977385172 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9982403977385172);
        // Set group 5 bol bias 01 (VH) to 1.619157620345736 Volts
        Pacs_BOLC_SET_VH_G5(1.619157620345736);
        // Set group 5 bol bias 02 (VL) to -0.28084237965426384 Volts
        Pacs_BOLC_SET_VL_G5(-0.28084237965426384);
        // Set group 5 bol bias 03 (VRL) to 0.4181337237404772 Volts
        Pacs_BOLC_SET_VRL_G5(0.4181337237404772);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0686829641920164 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0686829641920164);
        // Set group 6 bol bias 01 (VH) to 1.6464943218684462 Volts
        Pacs_BOLC_SET_VH_G6(1.6464943218684462);
        // Set group 6 bol bias 02 (VL) to -0.25350567813155367 Volts
        Pacs_BOLC_SET_VL_G6(-0.25350567813155367);
        // Set group 6 bol bias 03 (VRL) to 0.42983091508014903 Volts
        Pacs_BOLC_SET_VRL_G6(0.42983091508014903);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0058013261499523 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0058013261499523);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_4") {
        //***********************************************************
        // Bias 11 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.009876475533583 Volts
        Pacs_BOLC_SET_VH_G1(2.009876475533583);
        // Set group 1 bol bias 02 (VL) to -0.3901235244664168 Volts
        Pacs_BOLC_SET_VL_G1(-0.3901235244664168);
        // Set group 1 bol bias 03 (VRL) to 0.40347013530505543 Volts
        Pacs_BOLC_SET_VRL_G1(0.40347013530505543);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9871043914308184 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9871043914308184);
        // Set group 2 bol bias 01 (VH) to 1.9760552142185226 Volts
        Pacs_BOLC_SET_VH_G2(1.9760552142185226);
        // Set group 2 bol bias 02 (VL) to -0.42394478578147743 Volts
        Pacs_BOLC_SET_VL_G2(-0.42394478578147743);
        // Set group 2 bol bias 03 (VRL) to 0.3865563849289725 Volts
        Pacs_BOLC_SET_VRL_G2(0.3865563849289725);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9921878559038309 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9921878559038309);
        // Set group 3 bol bias 01 (VH) to 1.9994179317413638 Volts
        Pacs_BOLC_SET_VH_G3(1.9994179317413638);
        // Set group 3 bol bias 02 (VL) to -0.4005820682586361 Volts
        Pacs_BOLC_SET_VL_G3(-0.4005820682586361);
        // Set group 3 bol bias 03 (VRL) to 0.4134943391290234 Volts
        Pacs_BOLC_SET_VRL_G3(0.4134943391290234);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9974788605748868 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9974788605748868);
        // Set group 4 bol bias 01 (VH) to 2.0063261531952854 Volts
        Pacs_BOLC_SET_VH_G4(2.0063261531952854);
        // Set group 4 bol bias 02 (VL) to -0.3936738468047143 Volts
        Pacs_BOLC_SET_VL_G4(-0.3936738468047143);
        // Set group 4 bol bias 03 (VRL) to 0.3918214571029178 Volts
        Pacs_BOLC_SET_VRL_G4(0.3918214571029178);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9986654421352081 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9986654421352081);
        // Set group 5 bol bias 01 (VH) to 1.6865030568375055 Volts
        Pacs_BOLC_SET_VH_G5(1.6865030568375055);
        // Set group 5 bol bias 02 (VL) to -0.31349694316249443 Volts
        Pacs_BOLC_SET_VL_G5(-0.31349694316249443);
        // Set group 5 bol bias 03 (VRL) to 0.4169290649049042 Volts
        Pacs_BOLC_SET_VRL_G5(0.4169290649049042);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0452487710114853 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0452487710114853);
        // Set group 6 bol bias 01 (VH) to 1.7152182740372384 Volts
        Pacs_BOLC_SET_VH_G6(1.7152182740372384);
        // Set group 6 bol bias 02 (VL) to -0.2847817259627615 Volts
        Pacs_BOLC_SET_VL_G6(-0.2847817259627615);
        // Set group 6 bol bias 03 (VRL) to 0.4289846398856858 Volts
        Pacs_BOLC_SET_VRL_G6(0.4289846398856858);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0049545211149127 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0049545211149127);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_5") {
        //***********************************************************
        // Bias 12 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 2.1 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.1015543913725074 Volts
        Pacs_BOLC_SET_VH_G1(2.1015543913725074);
        // Set group 1 bol bias 02 (VL) to -0.3984456086274925 Volts
        Pacs_BOLC_SET_VL_G1(-0.3984456086274925);
        // Set group 1 bol bias 03 (VRL) to 0.4142917461729985 Volts
        Pacs_BOLC_SET_VRL_G1(0.4142917461729985);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.997826498579354 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.997826498579354);
        // Set group 2 bol bias 01 (VH) to 2.053575158914676 Volts
        Pacs_BOLC_SET_VH_G2(2.053575158914676);
        // Set group 2 bol bias 02 (VL) to -0.446424841085324 Volts
        Pacs_BOLC_SET_VL_G2(-0.446424841085324);
        // Set group 2 bol bias 03 (VRL) to 0.38582156888593877 Volts
        Pacs_BOLC_SET_VRL_G2(0.38582156888593877);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9692392102867975 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9692392102867975);
        // Set group 3 bol bias 01 (VH) to 2.0777255808437647 Volts
        Pacs_BOLC_SET_VH_G3(2.0777255808437647);
        // Set group 3 bol bias 02 (VL) to -0.42227441915623515 Volts
        Pacs_BOLC_SET_VL_G3(-0.42227441915623515);
        // Set group 3 bol bias 03 (VRL) to 0.4135789149134009 Volts
        Pacs_BOLC_SET_VRL_G3(0.4135789149134009);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9975624674721397 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9975624674721397);
        // Set group 4 bol bias 01 (VH) to 2.0862309333440736 Volts
        Pacs_BOLC_SET_VH_G4(2.0862309333440736);
        // Set group 4 bol bias 02 (VL) to -0.4137690666559265 Volts
        Pacs_BOLC_SET_VL_G4(-0.4137690666559265);
        // Set group 4 bol bias 03 (VRL) to 0.39200996131042865 Volts
        Pacs_BOLC_SET_VRL_G4(0.39200996131042865);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9988530580038057 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9988530580038057);
        // Set group 5 bol bias 01 (VH) to 1.7561026148265482 Volts
        Pacs_BOLC_SET_VH_G5(1.7561026148265482);
        // Set group 5 bol bias 02 (VL) to -0.3438973851734519 Volts
        Pacs_BOLC_SET_VL_G5(-0.3438973851734519);
        // Set group 5 bol bias 03 (VRL) to 0.415585005357646 Volts
        Pacs_BOLC_SET_VRL_G5(0.415585005357646);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.043896406112691 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.043896406112691);
        // Set group 6 bol bias 01 (VH) to 1.7857752538780838 Volts
        Pacs_BOLC_SET_VH_G6(1.7857752538780838);
        // Set group 6 bol bias 02 (VL) to -0.3142247461219163 Volts
        Pacs_BOLC_SET_VL_G6(-0.3142247461219163);
        // Set group 6 bol bias 03 (VRL) to 0.4279343882313106 Volts
        Pacs_BOLC_SET_VRL_G6(0.4279343882313106);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0039036469029026 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0039036469029026);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_6") {
        //***********************************************************
        // Bias 13 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.2 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.1861805706356843 Volts
        Pacs_BOLC_SET_VH_G1(2.1861805706356843);
        // Set group 1 bol bias 02 (VL) to -0.413819429364316 Volts
        Pacs_BOLC_SET_VL_G1(-0.413819429364316);
        // Set group 1 bol bias 03 (VRL) to 0.4136977781342747 Volts
        Pacs_BOLC_SET_VRL_G1(0.4136977781342747);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0194569613465028 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.0194569613465028);
        // Set group 2 bol bias 01 (VH) to 2.135466372433529 Volts
        Pacs_BOLC_SET_VH_G2(2.135466372433529);
        // Set group 2 bol bias 02 (VL) to -0.46453362756647104 Volts
        Pacs_BOLC_SET_VL_G2(-0.46453362756647104);
        // Set group 2 bol bias 03 (VRL) to 0.38559250810266327 Volts
        Pacs_BOLC_SET_VRL_G2(0.38559250810266327);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9690127608204688 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9690127608204688);
        // Set group 3 bol bias 01 (VH) to 2.1595315777041786 Volts
        Pacs_BOLC_SET_VH_G3(2.1595315777041786);
        // Set group 3 bol bias 02 (VL) to -0.4404684222958214 Volts
        Pacs_BOLC_SET_VL_G3(-0.4404684222958214);
        // Set group 3 bol bias 03 (VRL) to 0.41334124907167524 Volts
        Pacs_BOLC_SET_VRL_G3(0.41334124907167524);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9973275250137286 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9973275250137286);
        // Set group 4 bol bias 01 (VH) to 2.170304299964091 Volts
        Pacs_BOLC_SET_VH_G4(2.170304299964091);
        // Set group 4 bol bias 02 (VL) to -0.42969570003590896 Volts
        Pacs_BOLC_SET_VL_G4(-0.42969570003590896);
        // Set group 4 bol bias 03 (VRL) to 0.39229709106193544 Volts
        Pacs_BOLC_SET_VRL_G4(0.39229709106193544);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9991388331630189 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9991388331630189);
        // Set group 5 bol bias 01 (VH) to 1.8387544191430765 Volts
        Pacs_BOLC_SET_VH_G5(1.8387544191430765);
        // Set group 5 bol bias 02 (VL) to -0.36124558085692376 Volts
        Pacs_BOLC_SET_VL_G5(-0.36124558085692376);
        // Set group 5 bol bias 03 (VRL) to 0.4248823693610551 Volts
        Pacs_BOLC_SET_VRL_G5(0.4248823693610551);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.053248047331341 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.053248047331341);
        // Set group 6 bol bias 01 (VH) to 1.8592993014606782 Volts
        Pacs_BOLC_SET_VH_G6(1.8592993014606782);
        // Set group 6 bol bias 02 (VL) to -0.34070069853932194 Volts
        Pacs_BOLC_SET_VL_G6(-0.34070069853932194);
        // Set group 6 bol bias 03 (VRL) to 0.4266611014559859 Volts
        Pacs_BOLC_SET_VRL_G6(0.4266611014559859);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.002629657329772 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.002629657329772);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_7") {
        //***********************************************************
        // Bias 14 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.3 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.2753008617761528 Volts
        Pacs_BOLC_SET_VH_G1(2.2753008617761528);
        // Set group 1 bol bias 02 (VL) to -0.42469913822384736 Volts
        Pacs_BOLC_SET_VL_G1(-0.42469913822384736);
        // Set group 1 bol bias 03 (VRL) to 0.41305128775731165 Volts
        Pacs_BOLC_SET_VRL_G1(0.41305128775731165);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0188128839956407 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.0188128839956407);
        // Set group 2 bol bias 01 (VH) to 2.2200540205830306 Volts
        Pacs_BOLC_SET_VH_G2(2.2200540205830306);
        // Set group 2 bol bias 02 (VL) to -0.47994597941696954 Volts
        Pacs_BOLC_SET_VL_G2(-0.47994597941696954);
        // Set group 2 bol bias 03 (VRL) to 0.384046120637867 Volts
        Pacs_BOLC_SET_VRL_G2(0.384046120637867);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9897061638175213 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9897061638175213);
        // Set group 3 bol bias 01 (VH) to 2.245249492019461 Volts
        Pacs_BOLC_SET_VH_G3(2.245249492019461);
        // Set group 3 bol bias 02 (VL) to -0.4547505079805393 Volts
        Pacs_BOLC_SET_VL_G3(-0.4547505079805393);
        // Set group 3 bol bias 03 (VRL) to 0.4125629897111581 Volts
        Pacs_BOLC_SET_VRL_G3(0.4125629897111581);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9965581992791106 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9965581992791106);
        // Set group 4 bol bias 01 (VH) to 2.270618026838391 Volts
        Pacs_BOLC_SET_VH_G4(2.270618026838391);
        // Set group 4 bol bias 02 (VL) to -0.42938197316160936 Volts
        Pacs_BOLC_SET_VL_G4(-0.42938197316160936);
        // Set group 4 bol bias 03 (VRL) to 0.40477056217070767 Volts
        Pacs_BOLC_SET_VRL_G4(0.40477056217070767);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0114969201970143 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.0114969201970143);
        // Set group 5 bol bias 01 (VH) to 1.9023766892145328 Volts
        Pacs_BOLC_SET_VH_G5(1.9023766892145328);
        // Set group 5 bol bias 02 (VL) to -0.3976233107854671 Volts
        Pacs_BOLC_SET_VL_G5(-0.3976233107854671);
        // Set group 5 bol bias 03 (VRL) to 0.4120200100696618 Volts
        Pacs_BOLC_SET_VRL_G5(0.4120200100696618);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0403086300201214 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0403086300201214);
        // Set group 6 bol bias 01 (VH) to 1.9352110902279933 Volts
        Pacs_BOLC_SET_VH_G6(1.9352110902279933);
        // Set group 6 bol bias 02 (VL) to -0.3647889097720066 Volts
        Pacs_BOLC_SET_VL_G6(-0.3647889097720066);
        // Set group 6 bol bias 03 (VRL) to 0.4251544040958699 Volts
        Pacs_BOLC_SET_VRL_G6(0.4251544040958699);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0011222019097725 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0011222019097725);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_8") {
        //***********************************************************
        // Bias 15 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.4 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.3706004267013063 Volts
        Pacs_BOLC_SET_VH_G1(2.3706004267013063);
        // Set group 1 bol bias 02 (VL) to -0.42939957329869366 Volts
        Pacs_BOLC_SET_VL_G1(-0.42939957329869366);
        // Set group 1 bol bias 03 (VRL) to 0.4128233157591776 Volts
        Pacs_BOLC_SET_VRL_G1(0.4128233157591776);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9741413207323013 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9741413207323013);
        // Set group 2 bol bias 01 (VH) to 2.30849650818746 Volts
        Pacs_BOLC_SET_VH_G2(2.30849650818746);
        // Set group 2 bol bias 02 (VL) to -0.49150349181253966 Volts
        Pacs_BOLC_SET_VL_G2(-0.49150349181253966);
        // Set group 2 bol bias 03 (VRL) to 0.3818593817104539 Volts
        Pacs_BOLC_SET_VRL_G2(0.3818593817104539);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.987544087436569 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.987544087436569);
        // Set group 3 bol bias 01 (VH) to 2.3365657260248964 Volts
        Pacs_BOLC_SET_VH_G3(2.3365657260248964);
        // Set group 3 bol bias 02 (VL) to -0.4634342739751033 Volts
        Pacs_BOLC_SET_VL_G3(-0.4634342739751033);
        // Set group 3 bol bias 03 (VRL) to 0.41203384722665815 Volts
        Pacs_BOLC_SET_VRL_G3(0.41203384722665815);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9960351445039464 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9960351445039464);
        // Set group 4 bol bias 01 (VH) to 2.3518733233838134 Volts
        Pacs_BOLC_SET_VH_G4(2.3518733233838134);
        // Set group 4 bol bias 02 (VL) to -0.4481266766161862 Volts
        Pacs_BOLC_SET_VL_G4(-0.4481266766161862);
        // Set group 4 bol bias 03 (VRL) to 0.3934834273661596 Volts
        Pacs_BOLC_SET_VRL_G4(0.3934834273661596);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0003195538237746 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.0003195538237746);
        // Set group 5 bol bias 01 (VH) to 1.9800777632387063 Volts
        Pacs_BOLC_SET_VH_G5(1.9800777632387063);
        // Set group 5 bol bias 02 (VL) to -0.4199222367612936 Volts
        Pacs_BOLC_SET_VL_G5(-0.4199222367612936);
        // Set group 5 bol bias 03 (VRL) to 0.40944012382521133 Volts
        Pacs_BOLC_SET_VRL_G5(0.40944012382521133);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0377115768798726 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0377115768798726);
        // Set group 6 bol bias 01 (VH) to 2.01513172113205 Volts
        Pacs_BOLC_SET_VH_G6(2.01513172113205);
        // Set group 6 bol bias 02 (VL) to -0.38486827886795016 Volts
        Pacs_BOLC_SET_VL_G6(-0.38486827886795016);
        // Set group 6 bol bias 03 (VRL) to 0.4236192556113485 Volts
        Pacs_BOLC_SET_VRL_G6(0.4236192556113485);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.9995863630649058 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.9995863630649058);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_9") {
        //***********************************************************
        // Bias 16 (Vh-Vl)bleu = 2.9 Volts, (Vh-Vl)rouge = 2.5 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.481656607902919 Volts
        Pacs_BOLC_SET_VH_G1(2.481656607902919);
        // Set group 1 bol bias 02 (VL) to -0.4183433920970805 Volts
        Pacs_BOLC_SET_VL_G1(-0.4183433920970805);
        // Set group 1 bol bias 03 (VRL) to 0.42341440262252883 Volts
        Pacs_BOLC_SET_VRL_G1(0.42341440262252883);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9846940225694476 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9846940225694476);
        // Set group 2 bol bias 01 (VH) to 2.414691010796746 Volts
        Pacs_BOLC_SET_VH_G2(2.414691010796746);
        // Set group 2 bol bias 02 (VL) to -0.4853089892032536 Volts
        Pacs_BOLC_SET_VL_G2(-0.4853089892032536);
        // Set group 2 bol bias 03 (VRL) to 0.39253051982236287 Volts
        Pacs_BOLC_SET_VRL_G2(0.39253051982236287);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.975870648916194 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.975870648916194);
        // Set group 3 bol bias 01 (VH) to 2.433226441693846 Volts
        Pacs_BOLC_SET_VH_G3(2.433226441693846);
        // Set group 3 bol bias 02 (VL) to -0.4667735583061541 Volts
        Pacs_BOLC_SET_VL_G3(-0.4667735583061541);
        // Set group 3 bol bias 03 (VRL) to 0.41131230190878887 Volts
        Pacs_BOLC_SET_VRL_G3(0.41131230190878887);
        // Set group 3 bol bias 20 (VH_BLIND) to 2.017544140544661 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(2.017544140544661);
        // Set group 4 bol bias 01 (VH) to 2.4505544534181185 Volts
        Pacs_BOLC_SET_VH_G4(2.4505544534181185);
        // Set group 4 bol bias 02 (VL) to -0.4494455465818812 Volts
        Pacs_BOLC_SET_VL_G4(-0.4494455465818812);
        // Set group 4 bol bias 03 (VRL) to 0.39404533883994697 Volts
        Pacs_BOLC_SET_VRL_G4(0.39404533883994697);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0231010170539365 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.0231010170539365);
        // Set group 5 bol bias 01 (VH) to 2.084532589278408 Volts
        Pacs_BOLC_SET_VH_G5(2.084532589278408);
        // Set group 5 bol bias 02 (VL) to -0.415467410721592 Volts
        Pacs_BOLC_SET_VL_G5(-0.415467410721592);
        // Set group 5 bol bias 03 (VRL) to 0.4287571629467245 Volts
        Pacs_BOLC_SET_VRL_G5(0.4287571629467245);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.012698827468528 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.012698827468528);
        // Set group 6 bol bias 01 (VH) to 2.0995907437397068 Volts
        Pacs_BOLC_SET_VH_G6(2.0995907437397068);
        // Set group 6 bol bias 02 (VL) to -0.4004092562602932 Volts
        Pacs_BOLC_SET_VL_G6(-0.4004092562602932);
        // Set group 6 bol bias 03 (VRL) to 0.42148512746445066 Volts
        Pacs_BOLC_SET_VRL_G6(0.42148512746445066);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.99745141271377 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.99745141271377);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g3_0") {
        //***********************************************************
        // Bias 17 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.6 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.600397057706278 Volts
        Pacs_BOLC_SET_VH_G1(2.600397057706278);
        // Set group 1 bol bias 02 (VL) to -0.3996029422937219 Volts
        Pacs_BOLC_SET_VL_G1(-0.3996029422937219);
        // Set group 1 bol bias 03 (VRL) to 0.4352373155819225 Volts
        Pacs_BOLC_SET_VRL_G1(0.4352373155819225);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.996478815796946 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.996478815796946);
        // Set group 2 bol bias 01 (VH) to 2.514934658647339 Volts
        Pacs_BOLC_SET_VH_G2(2.514934658647339);
        // Set group 2 bol bias 02 (VL) to -0.485065341352661 Volts
        Pacs_BOLC_SET_VL_G2(-0.485065341352661);
        // Set group 2 bol bias 03 (VRL) to 0.39192545859088324 Volts
        Pacs_BOLC_SET_VRL_G2(0.39192545859088324);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9974948822002625 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9974948822002625);
        // Set group 3 bol bias 01 (VH) to 2.537533329053119 Volts
        Pacs_BOLC_SET_VH_G3(2.537533329053119);
        // Set group 3 bol bias 02 (VL) to -0.4624666709468811 Volts
        Pacs_BOLC_SET_VL_G3(-0.4624666709468811);
        // Set group 3 bol bias 03 (VRL) to 0.4110505916239857 Volts
        Pacs_BOLC_SET_VRL_G3(0.4110505916239857);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9950632305477918 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9950632305477918);
        // Set group 4 bol bias 01 (VH) to 2.5528988845382643 Volts
        Pacs_BOLC_SET_VH_G4(2.5528988845382643);
        // Set group 4 bol bias 02 (VL) to -0.4471011154617358 Volts
        Pacs_BOLC_SET_VL_G4(-0.4471011154617358);
        // Set group 4 bol bias 03 (VRL) to 0.39332244377654313 Volts
        Pacs_BOLC_SET_VRL_G4(0.39332244377654313);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.97793711182537 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.97793711182537);
        // Set group 5 bol bias 01 (VH) to 2.172287009978402 Volts
        Pacs_BOLC_SET_VH_G5(2.172287009978402);
        // Set group 5 bol bias 02 (VL) to -0.4277129900215981 Volts
        Pacs_BOLC_SET_VL_G5(-0.4277129900215981);
        // Set group 5 bol bias 03 (VRL) to 0.424805887491143 Volts
        Pacs_BOLC_SET_VRL_G5(0.424805887491143);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.9865044825613933 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.9865044825613933);
        // Set group 6 bol bias 01 (VH) to 2.192498481627701 Volts
        Pacs_BOLC_SET_VH_G6(2.192498481627701);
        // Set group 6 bol bias 02 (VL) to -0.4075015183722993 Volts
        Pacs_BOLC_SET_VL_G6(-0.4075015183722993);
        // Set group 6 bol bias 03 (VRL) to 0.4230819346131489 Volts
        Pacs_BOLC_SET_VRL_G6(0.4230819346131489);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.9990488199887213 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.9990488199887213);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g3_1") {
        //***********************************************************
        // Bias 18 (Vh-Vl)bleu = 3.1 Volts, (Vh-Vl)rouge = 2.7 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.7231858510855047 Volts
        Pacs_BOLC_SET_VH_G1(2.7231858510855047);
        // Set group 1 bol bias 02 (VL) to -0.3768141489144955 Volts
        Pacs_BOLC_SET_VL_G1(-0.3768141489144955);
        // Set group 1 bol bias 03 (VRL) to 0.44566796402443376 Volts
        Pacs_BOLC_SET_VRL_G1(0.44566796402443376);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0068845500748607 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.0068845500748607);
        // Set group 2 bol bias 01 (VH) to 2.6328472848704307 Volts
        Pacs_BOLC_SET_VH_G2(2.6328472848704307);
        // Set group 2 bol bias 02 (VL) to -0.46715271512956946 Volts
        Pacs_BOLC_SET_VL_G2(-0.46715271512956946);
        // Set group 2 bol bias 03 (VRL) to 0.4033574824568482 Volts
        Pacs_BOLC_SET_VRL_G2(0.4033574824568482);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.98654163454466 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.98654163454466);
        // Set group 3 bol bias 01 (VH) to 2.671015555171699 Volts
        Pacs_BOLC_SET_VH_G3(2.671015555171699);
        // Set group 3 bol bias 02 (VL) to -0.4289844448283011 Volts
        Pacs_BOLC_SET_VL_G3(-0.4289844448283011);
        // Set group 3 bol bias 03 (VRL) to 0.4334238579780366 Volts
        Pacs_BOLC_SET_VRL_G3(0.4334238579780366);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9949656787915016 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9949656787915016);
        // Set group 4 bol bias 01 (VH) to 2.683355029655175 Volts
        Pacs_BOLC_SET_VH_G4(2.683355029655175);
        // Set group 4 bol bias 02 (VL) to -0.41664497034482534 Volts
        Pacs_BOLC_SET_VL_G4(-0.41664497034482534);
        // Set group 4 bol bias 03 (VRL) to 0.4148785432313051 Volts
        Pacs_BOLC_SET_VRL_G4(0.4148785432313051);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.021492839689401 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.021492839689401);
        // Set group 5 bol bias 01 (VH) to 2.265458141418861 Volts
        Pacs_BOLC_SET_VH_G5(2.265458141418861);
        // Set group 5 bol bias 02 (VL) to -0.4345418585811395 Volts
        Pacs_BOLC_SET_VL_G5(-0.4345418585811395);
        // Set group 5 bol bias 03 (VRL) to 0.42074010861107924 Volts
        Pacs_BOLC_SET_VRL_G5(0.42074010861107924);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.960193631972712 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.960193631972712);
        // Set group 6 bol bias 01 (VH) to 2.291335406841721 Volts
        Pacs_BOLC_SET_VH_G6(2.291335406841721);
        // Set group 6 bol bias 02 (VL) to -0.4086645931582792 Volts
        Pacs_BOLC_SET_VL_G6(-0.4086645931582792);
        // Set group 6 bol bias 03 (VRL) to 0.42408872519340446 Volts
        Pacs_BOLC_SET_VRL_G6(0.42408872519340446);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0000560349821974 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0000560349821974);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g3_3") {
        //***********************************************************
        // Bias 19 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.8 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.953762912317898 Volts
        Pacs_BOLC_SET_VH_G1(2.953762912317898);
        // Set group 1 bol bias 02 (VL) to -0.34623708768210176 Volts
        Pacs_BOLC_SET_VL_G1(-0.34623708768210176);
        // Set group 1 bol bias 03 (VRL) to 0.4351408430547646 Volts
        Pacs_BOLC_SET_VRL_G1(0.4351408430547646);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.018604765708868 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.018604765708868);
        // Set group 2 bol bias 01 (VH) to 2.8726352179977614 Volts
        Pacs_BOLC_SET_VH_G2(2.8726352179977614);
        // Set group 2 bol bias 02 (VL) to -0.42736478200223854 Volts
        Pacs_BOLC_SET_VL_G2(-0.42736478200223854);
        // Set group 2 bol bias 03 (VRL) to 0.414735933268399 Volts
        Pacs_BOLC_SET_VRL_G2(0.414735933268399);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9977822068595887 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9977822068595887);
        // Set group 3 bol bias 01 (VH) to 2.912560583948949 Volts
        Pacs_BOLC_SET_VH_G3(2.912560583948949);
        // Set group 3 bol bias 02 (VL) to -0.38743941605105087 Volts
        Pacs_BOLC_SET_VL_G3(-0.38743941605105087);
        // Set group 3 bol bias 03 (VRL) to 0.43313062540919095 Volts
        Pacs_BOLC_SET_VRL_G3(0.43313062540919095);
        // Set group 3 bol bias 20 (VH_BLIND) to 2.016897798393872 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(2.016897798393872);
        // Set group 4 bol bias 01 (VH) to 2.9276689529187987 Volts
        Pacs_BOLC_SET_VH_G4(2.9276689529187987);
        // Set group 4 bol bias 02 (VL) to -0.3723310470812009 Volts
        Pacs_BOLC_SET_VL_G4(-0.3723310470812009);
        // Set group 4 bol bias 03 (VRL) to 0.4250104382196459 Volts
        Pacs_BOLC_SET_VRL_G4(0.4250104382196459);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.03153123431831 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.03153123431831);
        // Set group 5 bol bias 01 (VH) to 2.3685426057457377 Volts
        Pacs_BOLC_SET_VH_G5(2.3685426057457377);
        // Set group 5 bol bias 02 (VL) to -0.431457394254262 Volts
        Pacs_BOLC_SET_VL_G5(-0.431457394254262);
        // Set group 5 bol bias 03 (VRL) to 0.4194660339248105 Volts
        Pacs_BOLC_SET_VRL_G5(0.4194660339248105);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.958912105112433 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.958912105112433);
        // Set group 6 bol bias 01 (VH) to 2.387979742674767 Volts
        Pacs_BOLC_SET_VH_G6(2.387979742674767);
        // Set group 6 bol bias 02 (VL) to -0.41202025732523284 Volts
        Pacs_BOLC_SET_VL_G6(-0.41202025732523284);
        // Set group 6 bol bias 03 (VRL) to 0.41583832368330265 Volts
        Pacs_BOLC_SET_VRL_G6(0.41583832368330265);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.9918032048982883 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.9918032048982883);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g3_5") {
        //***********************************************************
        // Bias 20 (Vh-Vl)bleu = 3.5 Volts, (Vh-Vl)rouge = 3.0 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 3.2215792747333167 Volts
        Pacs_BOLC_SET_VH_G1(3.2215792747333167);
        // Set group 1 bol bias 02 (VL) to -0.2784207252666834 Volts
        Pacs_BOLC_SET_VL_G1(-0.2784207252666834);
        // Set group 1 bol bias 03 (VRL) to 0.4417658775487089 Volts
        Pacs_BOLC_SET_VRL_G1(0.4417658775487089);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0029925416622745 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.0029925416622745);
        // Set group 2 bol bias 01 (VH) to 3.125766471402503 Volts
        Pacs_BOLC_SET_VH_G2(3.125766471402503);
        // Set group 2 bol bias 02 (VL) to -0.37423352859749703 Volts
        Pacs_BOLC_SET_VL_G2(-0.37423352859749703);
        // Set group 2 bol bias 03 (VRL) to 0.4173574683012983 Volts
        Pacs_BOLC_SET_VRL_G2(0.4173574683012983);
        // Set group 2 bol bias 20 (VH_BLIND) to 2.022605609147021 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(2.022605609147021);
        // Set group 3 bol bias 01 (VH) to 3.177257384071087 Volts
        Pacs_BOLC_SET_VH_G3(3.177257384071087);
        // Set group 3 bol bias 02 (VL) to -0.322742615928913 Volts
        Pacs_BOLC_SET_VL_G3(-0.322742615928913);
        // Set group 3 bol bias 03 (VRL) to 0.43185016495155787 Volts
        Pacs_BOLC_SET_VRL_G3(0.43185016495155787);
        // Set group 3 bol bias 20 (VH_BLIND) to 2.0156310454329387 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(2.0156310454329387);
        // Set group 4 bol bias 01 (VH) to 3.1731210990369876 Volts
        Pacs_BOLC_SET_VH_G4(3.1731210990369876);
        // Set group 4 bol bias 02 (VL) to -0.3268789009630126 Volts
        Pacs_BOLC_SET_VL_G4(-0.3268789009630126);
        // Set group 4 bol bias 03 (VRL) to 0.41433291143376344 Volts
        Pacs_BOLC_SET_VRL_G4(0.41433291143376344);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0209525376587134 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.0209525376587134);
        // Set group 5 bol bias 01 (VH) to 2.6023262611288924 Volts
        Pacs_BOLC_SET_VH_G5(2.6023262611288924);
        // Set group 5 bol bias 02 (VL) to -0.3976737388711077 Volts
        Pacs_BOLC_SET_VL_G5(-0.3976737388711077);
        // Set group 5 bol bias 03 (VRL) to 0.41713188109460797 Volts
        Pacs_BOLC_SET_VRL_G5(0.41713188109460797);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.9565639381039313 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.9565639381039313);
        // Set group 6 bol bias 01 (VH) to 2.6133778395994915 Volts
        Pacs_BOLC_SET_VH_G6(2.6133778395994915);
        // Set group 6 bol bias 02 (VL) to -0.3866221604005083 Volts
        Pacs_BOLC_SET_VL_G6(-0.3866221604005083);
        // Set group 6 bol bias 03 (VRL) to 0.3988282729535058 Volts
        Pacs_BOLC_SET_VRL_G6(0.3988282729535058);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0194203860131417 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0194203860131417);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "binit") {
        //*******************************
        // Select Filter B (70 microns)
        //*******************************
        //
        PHOT_fltw_move("POS B");
        //
        //*************************************************
        // Set the biases and start SPU, then set the gain
        //*************************************************
        //
        PHOT_change_biases(startBiasTable,"DIRECT","HIGH");
        //
        //**********************************************
        // Set the PACS chopper at the position 664
        //**********************************************
        //
        Pacs_DMC_MOVE_CHOP_ABS(664);
        //
        //**********************************************************************
        //                       Measurement
        // Background fluxes 1.02pW on blue and 4.00pW on red
        //**********************************************************************
        //
        // sync the bus
        sync();
    }
    if(select == "b1_0") {
        //***********************************************************
        // Bias 1 (Vh-Vl)bleu = 1.0 Volts, (Vh-Vl)rouge = 1.0 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G1(0.99);
        // Set group 1 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G1(-0.01);
        // Set group 1 bol bias 03 (VRL) to 0.31491130488121843 Volts
        Pacs_BOLC_SET_VRL_G1(0.31491130488121843);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.8110596864511221 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.8110596864511221);
        // Set group 2 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G2(0.99);
        // Set group 2 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G2(-0.01);
        // Set group 2 bol bias 03 (VRL) to 0.3215626823200911 Volts
        Pacs_BOLC_SET_VRL_G2(0.3215626823200911);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.8170382701841934 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.8170382701841934);
        // Set group 3 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G3(0.99);
        // Set group 3 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G3(-0.01);
        // Set group 3 bol bias 03 (VRL) to 0.3165614686762489 Volts
        Pacs_BOLC_SET_VRL_G3(0.3165614686762489);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.8126483268747755 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.8126483268747755);
        // Set group 4 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G4(0.99);
        // Set group 4 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G4(-0.01);
        // Set group 4 bol bias 03 (VRL) to 0.3074090931646965 Volts
        Pacs_BOLC_SET_VRL_G4(0.3074090931646965);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.8040091353360972 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.8040091353360972);
        // Set group 5 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G5(0.99);
        // Set group 5 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G5(-0.01);
        // Set group 5 bol bias 03 (VRL) to 0.36201755468700786 Volts
        Pacs_BOLC_SET_VRL_G5(0.36201755468700786);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.9021910348181166 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.9021910348181166);
        // Set group 6 bol bias 01 (VH) to 0.99 Volts
        Pacs_BOLC_SET_VH_G6(0.99);
        // Set group 6 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G6(-0.01);
        // Set group 6 bol bias 03 (VRL) to 0.3533438794439342 Volts
        Pacs_BOLC_SET_VRL_G6(0.3533438794439342);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.8633797020856684 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.8633797020856684);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b1_3") {
        //***********************************************************
        // Bias 2 (Vh-Vl)bleu = 1.3 Volts, (Vh-Vl)rouge = 1.1 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.2604418530690626 Volts
        Pacs_BOLC_SET_VH_G1(1.2604418530690626);
        // Set group 1 bol bias 02 (VL) to -0.039558146930937475 Volts
        Pacs_BOLC_SET_VL_G1(-0.039558146930937475);
        // Set group 1 bol bias 03 (VRL) to 0.39289641464607533 Volts
        Pacs_BOLC_SET_VRL_G1(0.39289641464607533);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9766782902708646 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9766782902708646);
        // Set group 2 bol bias 01 (VH) to 1.2498739910541468 Volts
        Pacs_BOLC_SET_VH_G2(1.2498739910541468);
        // Set group 2 bol bias 02 (VL) to -0.05012600894585325 Volts
        Pacs_BOLC_SET_VL_G2(-0.05012600894585325);
        // Set group 2 bol bias 03 (VRL) to 0.38973301197020527 Volts
        Pacs_BOLC_SET_VRL_G2(0.38973301197020527);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9731057042643696 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9731057042643696);
        // Set group 3 bol bias 01 (VH) to 1.2515928357832167 Volts
        Pacs_BOLC_SET_VH_G3(1.2515928357832167);
        // Set group 3 bol bias 02 (VL) to -0.04840716421678328 Volts
        Pacs_BOLC_SET_VL_G3(-0.04840716421678328);
        // Set group 3 bol bias 03 (VRL) to 0.3894785311214204 Volts
        Pacs_BOLC_SET_VRL_G3(0.3894785311214204);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9736637244409159 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9736637244409159);
        // Set group 4 bol bias 01 (VH) to 1.2635401056840647 Volts
        Pacs_BOLC_SET_VH_G4(1.2635401056840647);
        // Set group 4 bol bias 02 (VL) to -0.0364598943159354 Volts
        Pacs_BOLC_SET_VL_G4(-0.0364598943159354);
        // Set group 4 bol bias 03 (VRL) to 0.38594958764314397 Volts
        Pacs_BOLC_SET_VRL_G4(0.38594958764314397);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.992820860208166 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.992820860208166);
        // Set group 5 bol bias 01 (VH) to 1.09 Volts
        Pacs_BOLC_SET_VH_G5(1.09);
        // Set group 5 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G5(-0.01);
        // Set group 5 bol bias 03 (VRL) to 0.3988167414134357 Volts
        Pacs_BOLC_SET_VRL_G5(0.3988167414134357);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.8938178971254427 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.8938178971254427);
        // Set group 6 bol bias 01 (VH) to 1.09 Volts
        Pacs_BOLC_SET_VH_G6(1.09);
        // Set group 6 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G6(-0.01);
        // Set group 6 bol bias 03 (VRL) to 0.38957428152869855 Volts
        Pacs_BOLC_SET_VRL_G6(0.38957428152869855);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.8769480931267648 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.8769480931267648);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b1_6") {
        //***********************************************************
        // Bias 3 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.4466042467331648 Volts
        Pacs_BOLC_SET_VH_G1(1.4466042467331648);
        // Set group 1 bol bias 02 (VL) to -0.1533957532668354 Volts
        Pacs_BOLC_SET_VL_G1(-0.1533957532668354);
        // Set group 1 bol bias 03 (VRL) to 0.3931184799278562 Volts
        Pacs_BOLC_SET_VRL_G1(0.3931184799278562);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9768976175854893 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9768976175854893);
        // Set group 2 bol bias 01 (VH) to 1.4348666737564109 Volts
        Pacs_BOLC_SET_VH_G2(1.4348666737564109);
        // Set group 2 bol bias 02 (VL) to -0.16513332624358923 Volts
        Pacs_BOLC_SET_VL_G2(-0.16513332624358923);
        // Set group 2 bol bias 03 (VRL) to 0.38935224534697577 Volts
        Pacs_BOLC_SET_VRL_G2(0.38935224534697577);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9727293430298154 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9727293430298154);
        // Set group 3 bol bias 01 (VH) to 1.4360911903448164 Volts
        Pacs_BOLC_SET_VH_G3(1.4360911903448164);
        // Set group 3 bol bias 02 (VL) to -0.16390880965518373 Volts
        Pacs_BOLC_SET_VL_G3(-0.16390880965518373);
        // Set group 3 bol bias 03 (VRL) to 0.3896621581853307 Volts
        Pacs_BOLC_SET_VRL_G3(0.3896621581853307);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9738464077847953 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9738464077847953);
        // Set group 4 bol bias 01 (VH) to 1.451604038362524 Volts
        Pacs_BOLC_SET_VH_G4(1.451604038362524);
        // Set group 4 bol bias 02 (VL) to -0.14839596163747615 Volts
        Pacs_BOLC_SET_VL_G4(-0.14839596163747615);
        // Set group 4 bol bias 03 (VRL) to 0.38721550093595813 Volts
        Pacs_BOLC_SET_VRL_G4(0.38721550093595813);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9940809535263424 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9940809535263424);
        // Set group 5 bol bias 01 (VH) to 1.176830084971648 Volts
        Pacs_BOLC_SET_VH_G5(1.176830084971648);
        // Set group 5 bol bias 02 (VL) to -0.023169915028352042 Volts
        Pacs_BOLC_SET_VL_G5(-0.023169915028352042);
        // Set group 5 bol bias 03 (VRL) to 0.423605592820457 Volts
        Pacs_BOLC_SET_VRL_G5(0.423605592820457);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.9186309231847374 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.9186309231847374);
        // Set group 6 bol bias 01 (VH) to 1.19 Volts
        Pacs_BOLC_SET_VH_G6(1.19);
        // Set group 6 bol bias 02 (VL) to -0.01 Volts
        Pacs_BOLC_SET_VL_G6(-0.01);
        // Set group 6 bol bias 03 (VRL) to 0.42683111640625715 Volts
        Pacs_BOLC_SET_VRL_G6(0.42683111640625715);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.9139108739371622 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.9139108739371622);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b1_7") {
        //***********************************************************
        // Bias 4 (Vh-Vl)bleu = 1.7 Volts, (Vh-Vl)rouge = 1.3 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.5103025129380314 Volts
        Pacs_BOLC_SET_VH_G1(1.5103025129380314);
        // Set group 1 bol bias 02 (VL) to -0.18969748706196854 Volts
        Pacs_BOLC_SET_VL_G1(-0.18969748706196854);
        // Set group 1 bol bias 03 (VRL) to 0.39334126989340834 Volts
        Pacs_BOLC_SET_VRL_G1(0.39334126989340834);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9771176574542377 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9771176574542377);
        // Set group 2 bol bias 01 (VH) to 1.4981688599762897 Volts
        Pacs_BOLC_SET_VH_G2(1.4981688599762897);
        // Set group 2 bol bias 02 (VL) to -0.20183114002371028 Volts
        Pacs_BOLC_SET_VL_G2(-0.20183114002371028);
        // Set group 2 bol bias 03 (VRL) to 0.3895018797527151 Volts
        Pacs_BOLC_SET_VRL_G2(0.3895018797527151);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9728772469622824 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9728772469622824);
        // Set group 3 bol bias 01 (VH) to 1.4988973586426284 Volts
        Pacs_BOLC_SET_VH_G3(1.4988973586426284);
        // Set group 3 bol bias 02 (VL) to -0.20110264135737144 Volts
        Pacs_BOLC_SET_VL_G3(-0.20110264135737144);
        // Set group 3 bol bias 03 (VRL) to 0.38988321326629705 Volts
        Pacs_BOLC_SET_VRL_G3(0.38988321326629705);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.974066326737784 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.974066326737784);
        // Set group 4 bol bias 01 (VH) to 1.5153710271389698 Volts
        Pacs_BOLC_SET_VH_G4(1.5153710271389698);
        // Set group 4 bol bias 02 (VL) to -0.1846289728610302 Volts
        Pacs_BOLC_SET_VL_G4(-0.1846289728610302);
        // Set group 4 bol bias 03 (VRL) to 0.38759598061305345 Volts
        Pacs_BOLC_SET_VRL_G4(0.38759598061305345);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9944596772055088 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9944596772055088);
        // Set group 5 bol bias 01 (VH) to 1.2373765147884428 Volts
        Pacs_BOLC_SET_VH_G5(1.2373765147884428);
        // Set group 5 bol bias 02 (VL) to -0.06262348521155736 Volts
        Pacs_BOLC_SET_VL_G5(-0.06262348521155736);
        // Set group 5 bol bias 03 (VRL) to 0.4231546601820514 Volts
        Pacs_BOLC_SET_VRL_G5(0.4231546601820514);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0737330353761743 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0737330353761743);
        // Set group 6 bol bias 01 (VH) to 1.2620813870511016 Volts
        Pacs_BOLC_SET_VH_G6(1.2620813870511016);
        // Set group 6 bol bias 02 (VL) to -0.03791861294889845 Volts
        Pacs_BOLC_SET_VL_G6(-0.03791861294889845);
        // Set group 6 bol bias 03 (VRL) to 0.4365536756619326 Volts
        Pacs_BOLC_SET_VRL_G6(0.4365536756619326);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0125308363899257 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0125308363899257);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b1_8") {
        //***********************************************************
        // Bias 5 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.5746054260860674 Volts
        Pacs_BOLC_SET_VH_G1(1.5746054260860674);
        // Set group 1 bol bias 02 (VL) to -0.2253945739139327 Volts
        Pacs_BOLC_SET_VL_G1(-0.2253945739139327);
        // Set group 1 bol bias 03 (VRL) to 0.3932716162847716 Volts
        Pacs_BOLC_SET_VRL_G1(0.3932716162847716);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9770488639865138 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9770488639865138);
        // Set group 2 bol bias 01 (VH) to 1.5618613714796097 Volts
        Pacs_BOLC_SET_VH_G2(1.5618613714796097);
        // Set group 2 bol bias 02 (VL) to -0.23813862852039025 Volts
        Pacs_BOLC_SET_VL_G2(-0.23813862852039025);
        // Set group 2 bol bias 03 (VRL) to 0.38927245764630447 Volts
        Pacs_BOLC_SET_VRL_G2(0.38927245764630447);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9726504776431222 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9726504776431222);
        // Set group 3 bol bias 01 (VH) to 1.5626563338488486 Volts
        Pacs_BOLC_SET_VH_G3(1.5626563338488486);
        // Set group 3 bol bias 02 (VL) to -0.23734366615115154 Volts
        Pacs_BOLC_SET_VL_G3(-0.23734366615115154);
        // Set group 3 bol bias 03 (VRL) to 0.39010656105086017 Volts
        Pacs_BOLC_SET_VRL_G3(0.39010656105086017);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9520663043298032 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9520663043298032);
        // Set group 4 bol bias 01 (VH) to 1.5803345539887472 Volts
        Pacs_BOLC_SET_VH_G4(1.5803345539887472);
        // Set group 4 bol bias 02 (VL) to -0.21966544601125282 Volts
        Pacs_BOLC_SET_VL_G4(-0.21966544601125282);
        // Set group 4 bol bias 03 (VRL) to 0.38802691306918746 Volts
        Pacs_BOLC_SET_VRL_G4(0.38802691306918746);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9948886170390088 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9948886170390088);
        // Set group 5 bol bias 01 (VH) to 1.2990548950746752 Volts
        Pacs_BOLC_SET_VH_G5(1.2990548950746752);
        // Set group 5 bol bias 02 (VL) to -0.1009451049253246 Volts
        Pacs_BOLC_SET_VL_G5(-0.1009451049253246);
        // Set group 5 bol bias 03 (VRL) to 0.42253767898766403 Volts
        Pacs_BOLC_SET_VRL_G5(0.42253767898766403);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.073112590654842 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.073112590654842);
        // Set group 6 bol bias 01 (VH) to 1.3235509250997841 Volts
        Pacs_BOLC_SET_VH_G6(1.3235509250997841);
        // Set group 6 bol bias 02 (VL) to -0.07644907490021571 Volts
        Pacs_BOLC_SET_VL_G6(-0.07644907490021571);
        // Set group 6 bol bias 03 (VRL) to 0.4356120279464395 Volts
        Pacs_BOLC_SET_VRL_G6(0.4356120279464395);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0115879408988957 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0115879408988957);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b1_9") {
        //***********************************************************
        // Bias 6 (Vh-Vl)bleu = 1.9 Volts, (Vh-Vl)rouge = 1.5 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.6402199051027921 Volts
        Pacs_BOLC_SET_VH_G1(1.6402199051027921);
        // Set group 1 bol bias 02 (VL) to -0.25978009489720777 Volts
        Pacs_BOLC_SET_VL_G1(-0.25978009489720777);
        // Set group 1 bol bias 03 (VRL) to 0.3931898746876479 Volts
        Pacs_BOLC_SET_VRL_G1(0.3931898746876479);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9769681314039869 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9769681314039869);
        // Set group 2 bol bias 01 (VH) to 1.6266725708788872 Volts
        Pacs_BOLC_SET_VH_G2(1.6266725708788872);
        // Set group 2 bol bias 02 (VL) to -0.27332742912111274 Volts
        Pacs_BOLC_SET_VL_G2(-0.27332742912111274);
        // Set group 2 bol bias 03 (VRL) to 0.389108175849032 Volts
        Pacs_BOLC_SET_VRL_G2(0.389108175849032);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9724880939910572 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9724880939910572);
        // Set group 3 bol bias 01 (VH) to 1.6383684660823183 Volts
        Pacs_BOLC_SET_VH_G3(1.6383684660823183);
        // Set group 3 bol bias 02 (VL) to -0.2616315339176816 Volts
        Pacs_BOLC_SET_VL_G3(-0.2616315339176816);
        // Set group 3 bol bias 03 (VRL) to 0.40130564291962717 Volts
        Pacs_BOLC_SET_VRL_G3(0.40130564291962717);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.963203735882543 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.963203735882543);
        // Set group 4 bol bias 01 (VH) to 1.6464466803651918 Volts
        Pacs_BOLC_SET_VH_G4(1.6464466803651918);
        // Set group 4 bol bias 02 (VL) to -0.253553319634808 Volts
        Pacs_BOLC_SET_VL_G4(-0.253553319634808);
        // Set group 4 bol bias 03 (VRL) to 0.38846072438079005 Volts
        Pacs_BOLC_SET_VRL_G4(0.38846072438079005);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9953204183673823 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9953204183673823);
        // Set group 5 bol bias 01 (VH) to 1.361967639315405 Volts
        Pacs_BOLC_SET_VH_G5(1.361967639315405);
        // Set group 5 bol bias 02 (VL) to -0.1380323606845949 Volts
        Pacs_BOLC_SET_VL_G5(-0.1380323606845949);
        // Set group 5 bol bias 03 (VRL) to 0.42173840001161234 Volts
        Pacs_BOLC_SET_VRL_G5(0.42173840001161234);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0723087762240313 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0723087762240313);
        // Set group 6 bol bias 01 (VH) to 1.3868176040333537 Volts
        Pacs_BOLC_SET_VH_G6(1.3868176040333537);
        // Set group 6 bol bias 02 (VL) to -0.11318239596664628 Volts
        Pacs_BOLC_SET_VL_G6(-0.11318239596664628);
        // Set group 6 bol bias 03 (VRL) to 0.43419935624396677 Volts
        Pacs_BOLC_SET_VRL_G6(0.43419935624396677);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.010173163758215 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.010173163758215);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_0") {
        //***********************************************************
        // Bias 7 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.7072552504837253 Volts
        Pacs_BOLC_SET_VH_G1(1.7072552504837253);
        // Set group 1 bol bias 02 (VL) to -0.2927447495162747 Volts
        Pacs_BOLC_SET_VL_G1(-0.2927447495162747);
        // Set group 1 bol bias 03 (VRL) to 0.39300694397919855 Volts
        Pacs_BOLC_SET_VRL_G1(0.39300694397919855);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9767874572233488 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9767874572233488);
        // Set group 2 bol bias 01 (VH) to 1.692663076962388 Volts
        Pacs_BOLC_SET_VH_G2(1.692663076962388);
        // Set group 2 bol bias 02 (VL) to -0.30733692303761195 Volts
        Pacs_BOLC_SET_VL_G2(-0.30733692303761195);
        // Set group 2 bol bias 03 (VRL) to 0.3887091184811946 Volts
        Pacs_BOLC_SET_VRL_G2(0.3887091184811946);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9720936424409112 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9720936424409112);
        // Set group 3 bol bias 01 (VH) to 1.704185527633064 Volts
        Pacs_BOLC_SET_VH_G3(1.704185527633064);
        // Set group 3 bol bias 02 (VL) to -0.295814472366936 Volts
        Pacs_BOLC_SET_VL_G3(-0.295814472366936);
        // Set group 3 bol bias 03 (VRL) to 0.4014500719789626 Volts
        Pacs_BOLC_SET_VRL_G3(0.4014500719789626);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9633466285199563 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9633466285199563);
        // Set group 4 bol bias 01 (VH) to 1.7140968369777032 Volts
        Pacs_BOLC_SET_VH_G4(1.7140968369777032);
        // Set group 4 bol bias 02 (VL) to -0.2859031630222967 Volts
        Pacs_BOLC_SET_VL_G4(-0.2859031630222967);
        // Set group 4 bol bias 03 (VRL) to 0.3891942580835225 Volts
        Pacs_BOLC_SET_VRL_G4(0.3891942580835225);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9960505441377652 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9960505441377652);
        // Set group 5 bol bias 01 (VH) to 1.4140772343701025 Volts
        Pacs_BOLC_SET_VH_G5(1.4140772343701025);
        // Set group 5 bol bias 02 (VL) to -0.18592276562989757 Volts
        Pacs_BOLC_SET_VL_G5(-0.18592276562989757);
        // Set group 5 bol bias 03 (VRL) to 0.40997067244647206 Volts
        Pacs_BOLC_SET_VRL_G5(0.40997067244647206);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0604679247843345 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0604679247843345);
        // Set group 6 bol bias 01 (VH) to 1.4508528288233054 Volts
        Pacs_BOLC_SET_VH_G6(1.4508528288233054);
        // Set group 6 bol bias 02 (VL) to -0.14914717117669465 Volts
        Pacs_BOLC_SET_VL_G6(-0.14914717117669465);
        // Set group 6 bol bias 03 (VRL) to 0.43354239736180156 Volts
        Pacs_BOLC_SET_VRL_G6(0.43354239736180156);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.009515130266216 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.009515130266216);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_1") {
        //***********************************************************
        // Bias 8 (Vh-Vl)bleu = 2.1 Volts, (Vh-Vl)rouge = 1.7 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.7763064474811254 Volts
        Pacs_BOLC_SET_VH_G1(1.7763064474811254);
        // Set group 1 bol bias 02 (VL) to -0.32369355251887477 Volts
        Pacs_BOLC_SET_VL_G1(-0.32369355251887477);
        // Set group 1 bol bias 03 (VRL) to 0.3929117872458944 Volts
        Pacs_BOLC_SET_VRL_G1(0.3929117872458944);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9766934734357156 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9766934734357156);
        // Set group 2 bol bias 01 (VH) to 1.760421890972815 Volts
        Pacs_BOLC_SET_VH_G2(1.760421890972815);
        // Set group 2 bol bias 02 (VL) to -0.3395781090271849 Volts
        Pacs_BOLC_SET_VL_G2(-0.3395781090271849);
        // Set group 2 bol bias 03 (VRL) to 0.3885757589950336 Volts
        Pacs_BOLC_SET_VRL_G2(0.3885757589950336);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9719618205852854 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9719618205852854);
        // Set group 3 bol bias 01 (VH) to 1.7720431785316175 Volts
        Pacs_BOLC_SET_VH_G3(1.7720431785316175);
        // Set group 3 bol bias 02 (VL) to -0.3279568214683825 Volts
        Pacs_BOLC_SET_VL_G3(-0.3279568214683825);
        // Set group 3 bol bias 03 (VRL) to 0.4018779497744413 Volts
        Pacs_BOLC_SET_VRL_G3(0.4018779497744413);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9859921836646144 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9859921836646144);
        // Set group 4 bol bias 01 (VH) to 1.7844121897694236 Volts
        Pacs_BOLC_SET_VH_G4(1.7844121897694236);
        // Set group 4 bol bias 02 (VL) to -0.31558781023057647 Volts
        Pacs_BOLC_SET_VL_G4(-0.31558781023057647);
        // Set group 4 bol bias 03 (VRL) to 0.39037916192256217 Volts
        Pacs_BOLC_SET_VRL_G4(0.39037916192256217);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9972299184858024 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9972299184858024);
        // Set group 5 bol bias 01 (VH) to 1.477526658704948 Volts
        Pacs_BOLC_SET_VH_G5(1.477526658704948);
        // Set group 5 bol bias 02 (VL) to -0.22247334129505197 Volts
        Pacs_BOLC_SET_VL_G5(-0.22247334129505197);
        // Set group 5 bol bias 03 (VRL) to 0.40905936069000043 Volts
        Pacs_BOLC_SET_VRL_G5(0.40905936069000043);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.059550453875679 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.059550453875679);
        // Set group 6 bol bias 01 (VH) to 1.5151586609905838 Volts
        Pacs_BOLC_SET_VH_G6(1.5151586609905838);
        // Set group 6 bol bias 02 (VL) to -0.18484133900941616 Volts
        Pacs_BOLC_SET_VL_G6(-0.18484133900941616);
        // Set group 6 bol bias 03 (VRL) to 0.43253382177085165 Volts
        Pacs_BOLC_SET_VRL_G6(0.43253382177085165);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0085060936227923 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0085060936227923);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_2") {
        //***********************************************************
        // Bias 9 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.8 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.8477065354350637 Volts
        Pacs_BOLC_SET_VH_G1(1.8477065354350637);
        // Set group 1 bol bias 02 (VL) to -0.3522934645649365 Volts
        Pacs_BOLC_SET_VL_G1(-0.3522934645649365);
        // Set group 1 bol bias 03 (VRL) to 0.3928551010344241 Volts
        Pacs_BOLC_SET_VRL_G1(0.3928551010344241);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.976637485687116 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.976637485687116);
        // Set group 2 bol bias 01 (VH) to 1.8296090411271155 Volts
        Pacs_BOLC_SET_VH_G2(1.8296090411271155);
        // Set group 2 bol bias 02 (VL) to -0.37039095887288453 Volts
        Pacs_BOLC_SET_VL_G2(-0.37039095887288453);
        // Set group 2 bol bias 03 (VRL) to 0.38775841031856695 Volts
        Pacs_BOLC_SET_VRL_G2(0.38775841031856695);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9711538787251761 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9711538787251761);
        // Set group 3 bol bias 01 (VH) to 1.841519930396799 Volts
        Pacs_BOLC_SET_VH_G3(1.841519930396799);
        // Set group 3 bol bias 02 (VL) to -0.35848006960320106 Volts
        Pacs_BOLC_SET_VL_G3(-0.35848006960320106);
        // Set group 3 bol bias 03 (VRL) to 0.40195292210921824 Volts
        Pacs_BOLC_SET_VRL_G3(0.40195292210921824);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9638441384832317 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9638441384832317);
        // Set group 4 bol bias 01 (VH) to 1.8560275203811134 Volts
        Pacs_BOLC_SET_VH_G4(1.8560275203811134);
        // Set group 4 bol bias 02 (VL) to -0.3439724796188869 Volts
        Pacs_BOLC_SET_VL_G4(-0.3439724796188869);
        // Set group 4 bol bias 03 (VRL) to 0.3911662396825011 Volts
        Pacs_BOLC_SET_VRL_G4(0.3911662396825011);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9980133065056234 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9980133065056234);
        // Set group 5 bol bias 01 (VH) to 1.5419730265537344 Volts
        Pacs_BOLC_SET_VH_G5(1.5419730265537344);
        // Set group 5 bol bias 02 (VL) to -0.25802697344626574 Volts
        Pacs_BOLC_SET_VL_G5(-0.25802697344626574);
        // Set group 5 bol bias 03 (VRL) to 0.407947187499842 Volts
        Pacs_BOLC_SET_VRL_G5(0.407947187499842);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0584306672751223 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0584306672751223);
        // Set group 6 bol bias 01 (VH) to 1.5800659587002086 Volts
        Pacs_BOLC_SET_VH_G6(1.5800659587002086);
        // Set group 6 bol bias 02 (VL) to -0.21993404129979136 Volts
        Pacs_BOLC_SET_VL_G6(-0.21993404129979136);
        // Set group 6 bol bias 03 (VRL) to 0.4311454765153988 Volts
        Pacs_BOLC_SET_VRL_G6(0.4311454765153988);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0071167605145566 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0071167605145566);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_3") {
        //***********************************************************
        // Bias 10 (Vh-Vl)bleu = 2.3 Volts, (Vh-Vl)rouge = 1.9 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.9215770642413583 Volts
        Pacs_BOLC_SET_VH_G1(1.9215770642413583);
        // Set group 1 bol bias 02 (VL) to -0.3784229357586415 Volts
        Pacs_BOLC_SET_VL_G1(-0.3784229357586415);
        // Set group 1 bol bias 03 (VRL) to 0.3926472775679627 Volts
        Pacs_BOLC_SET_VRL_G1(0.3926472775679627);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9764322211591614 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9764322211591614);
        // Set group 2 bol bias 01 (VH) to 1.9015583161672205 Volts
        Pacs_BOLC_SET_VH_G2(1.9015583161672205);
        // Set group 2 bol bias 02 (VL) to -0.39844168383277934 Volts
        Pacs_BOLC_SET_VL_G2(-0.39844168383277934);
        // Set group 2 bol bias 03 (VRL) to 0.3872580365783701 Volts
        Pacs_BOLC_SET_VRL_G2(0.3872580365783701);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9928814713939536 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9928814713939536);
        // Set group 3 bol bias 01 (VH) to 1.924712550703177 Volts
        Pacs_BOLC_SET_VH_G3(1.924712550703177);
        // Set group 3 bol bias 02 (VL) to -0.37528744929682273 Volts
        Pacs_BOLC_SET_VL_G3(-0.37528744929682273);
        // Set group 3 bol bias 03 (VRL) to 0.4133853220168953 Volts
        Pacs_BOLC_SET_VRL_G3(0.4133853220168953);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9751488705414568 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9751488705414568);
        // Set group 4 bol bias 01 (VH) to 1.9295265554899754 Volts
        Pacs_BOLC_SET_VH_G4(1.9295265554899754);
        // Set group 4 bol bias 02 (VL) to -0.3704734445100245 Volts
        Pacs_BOLC_SET_VL_G4(-0.3704734445100245);
        // Set group 4 bol bias 03 (VRL) to 0.3913944030216683 Volts
        Pacs_BOLC_SET_VRL_G4(0.3913944030216683);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9982403977385172 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9982403977385172);
        // Set group 5 bol bias 01 (VH) to 1.619157620345736 Volts
        Pacs_BOLC_SET_VH_G5(1.619157620345736);
        // Set group 5 bol bias 02 (VL) to -0.28084237965426384 Volts
        Pacs_BOLC_SET_VL_G5(-0.28084237965426384);
        // Set group 5 bol bias 03 (VRL) to 0.4181337237404772 Volts
        Pacs_BOLC_SET_VRL_G5(0.4181337237404772);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0686829641920164 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0686829641920164);
        // Set group 6 bol bias 01 (VH) to 1.6464943218684462 Volts
        Pacs_BOLC_SET_VH_G6(1.6464943218684462);
        // Set group 6 bol bias 02 (VL) to -0.25350567813155367 Volts
        Pacs_BOLC_SET_VL_G6(-0.25350567813155367);
        // Set group 6 bol bias 03 (VRL) to 0.42983091508014903 Volts
        Pacs_BOLC_SET_VRL_G6(0.42983091508014903);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0058013261499523 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0058013261499523);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_4") {
        //***********************************************************
        // Bias 11 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.009876475533583 Volts
        Pacs_BOLC_SET_VH_G1(2.009876475533583);
        // Set group 1 bol bias 02 (VL) to -0.3901235244664168 Volts
        Pacs_BOLC_SET_VL_G1(-0.3901235244664168);
        // Set group 1 bol bias 03 (VRL) to 0.40347013530505543 Volts
        Pacs_BOLC_SET_VRL_G1(0.40347013530505543);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9871043914308184 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9871043914308184);
        // Set group 2 bol bias 01 (VH) to 1.9760552142185226 Volts
        Pacs_BOLC_SET_VH_G2(1.9760552142185226);
        // Set group 2 bol bias 02 (VL) to -0.42394478578147743 Volts
        Pacs_BOLC_SET_VL_G2(-0.42394478578147743);
        // Set group 2 bol bias 03 (VRL) to 0.3865563849289725 Volts
        Pacs_BOLC_SET_VRL_G2(0.3865563849289725);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9921878559038309 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9921878559038309);
        // Set group 3 bol bias 01 (VH) to 1.9994179317413638 Volts
        Pacs_BOLC_SET_VH_G3(1.9994179317413638);
        // Set group 3 bol bias 02 (VL) to -0.4005820682586361 Volts
        Pacs_BOLC_SET_VL_G3(-0.4005820682586361);
        // Set group 3 bol bias 03 (VRL) to 0.4134943391290234 Volts
        Pacs_BOLC_SET_VRL_G3(0.4134943391290234);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9974788605748868 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9974788605748868);
        // Set group 4 bol bias 01 (VH) to 2.0063261531952854 Volts
        Pacs_BOLC_SET_VH_G4(2.0063261531952854);
        // Set group 4 bol bias 02 (VL) to -0.3936738468047143 Volts
        Pacs_BOLC_SET_VL_G4(-0.3936738468047143);
        // Set group 4 bol bias 03 (VRL) to 0.3918214571029178 Volts
        Pacs_BOLC_SET_VRL_G4(0.3918214571029178);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9986654421352081 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9986654421352081);
        // Set group 5 bol bias 01 (VH) to 1.6865030568375055 Volts
        Pacs_BOLC_SET_VH_G5(1.6865030568375055);
        // Set group 5 bol bias 02 (VL) to -0.31349694316249443 Volts
        Pacs_BOLC_SET_VL_G5(-0.31349694316249443);
        // Set group 5 bol bias 03 (VRL) to 0.4169290649049042 Volts
        Pacs_BOLC_SET_VRL_G5(0.4169290649049042);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0452487710114853 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0452487710114853);
        // Set group 6 bol bias 01 (VH) to 1.7152182740372384 Volts
        Pacs_BOLC_SET_VH_G6(1.7152182740372384);
        // Set group 6 bol bias 02 (VL) to -0.2847817259627615 Volts
        Pacs_BOLC_SET_VL_G6(-0.2847817259627615);
        // Set group 6 bol bias 03 (VRL) to 0.4289846398856858 Volts
        Pacs_BOLC_SET_VRL_G6(0.4289846398856858);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0049545211149127 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0049545211149127);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_5") {
        //***********************************************************
        // Bias 12 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 2.1 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.1015543913725074 Volts
        Pacs_BOLC_SET_VH_G1(2.1015543913725074);
        // Set group 1 bol bias 02 (VL) to -0.3984456086274925 Volts
        Pacs_BOLC_SET_VL_G1(-0.3984456086274925);
        // Set group 1 bol bias 03 (VRL) to 0.4142917461729985 Volts
        Pacs_BOLC_SET_VRL_G1(0.4142917461729985);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.997826498579354 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.997826498579354);
        // Set group 2 bol bias 01 (VH) to 2.053575158914676 Volts
        Pacs_BOLC_SET_VH_G2(2.053575158914676);
        // Set group 2 bol bias 02 (VL) to -0.446424841085324 Volts
        Pacs_BOLC_SET_VL_G2(-0.446424841085324);
        // Set group 2 bol bias 03 (VRL) to 0.38582156888593877 Volts
        Pacs_BOLC_SET_VRL_G2(0.38582156888593877);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9692392102867975 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9692392102867975);
        // Set group 3 bol bias 01 (VH) to 2.0777255808437647 Volts
        Pacs_BOLC_SET_VH_G3(2.0777255808437647);
        // Set group 3 bol bias 02 (VL) to -0.42227441915623515 Volts
        Pacs_BOLC_SET_VL_G3(-0.42227441915623515);
        // Set group 3 bol bias 03 (VRL) to 0.4135789149134009 Volts
        Pacs_BOLC_SET_VRL_G3(0.4135789149134009);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9975624674721397 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9975624674721397);
        // Set group 4 bol bias 01 (VH) to 2.0862309333440736 Volts
        Pacs_BOLC_SET_VH_G4(2.0862309333440736);
        // Set group 4 bol bias 02 (VL) to -0.4137690666559265 Volts
        Pacs_BOLC_SET_VL_G4(-0.4137690666559265);
        // Set group 4 bol bias 03 (VRL) to 0.39200996131042865 Volts
        Pacs_BOLC_SET_VRL_G4(0.39200996131042865);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9988530580038057 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9988530580038057);
        // Set group 5 bol bias 01 (VH) to 1.7561026148265482 Volts
        Pacs_BOLC_SET_VH_G5(1.7561026148265482);
        // Set group 5 bol bias 02 (VL) to -0.3438973851734519 Volts
        Pacs_BOLC_SET_VL_G5(-0.3438973851734519);
        // Set group 5 bol bias 03 (VRL) to 0.415585005357646 Volts
        Pacs_BOLC_SET_VRL_G5(0.415585005357646);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.043896406112691 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.043896406112691);
        // Set group 6 bol bias 01 (VH) to 1.7857752538780838 Volts
        Pacs_BOLC_SET_VH_G6(1.7857752538780838);
        // Set group 6 bol bias 02 (VL) to -0.3142247461219163 Volts
        Pacs_BOLC_SET_VL_G6(-0.3142247461219163);
        // Set group 6 bol bias 03 (VRL) to 0.4279343882313106 Volts
        Pacs_BOLC_SET_VRL_G6(0.4279343882313106);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0039036469029026 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0039036469029026);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_6") {
        //***********************************************************
        // Bias 13 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.2 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.1861805706356843 Volts
        Pacs_BOLC_SET_VH_G1(2.1861805706356843);
        // Set group 1 bol bias 02 (VL) to -0.413819429364316 Volts
        Pacs_BOLC_SET_VL_G1(-0.413819429364316);
        // Set group 1 bol bias 03 (VRL) to 0.4136977781342747 Volts
        Pacs_BOLC_SET_VRL_G1(0.4136977781342747);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0194569613465028 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.0194569613465028);
        // Set group 2 bol bias 01 (VH) to 2.135466372433529 Volts
        Pacs_BOLC_SET_VH_G2(2.135466372433529);
        // Set group 2 bol bias 02 (VL) to -0.46453362756647104 Volts
        Pacs_BOLC_SET_VL_G2(-0.46453362756647104);
        // Set group 2 bol bias 03 (VRL) to 0.38559250810266327 Volts
        Pacs_BOLC_SET_VRL_G2(0.38559250810266327);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9690127608204688 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9690127608204688);
        // Set group 3 bol bias 01 (VH) to 2.1595315777041786 Volts
        Pacs_BOLC_SET_VH_G3(2.1595315777041786);
        // Set group 3 bol bias 02 (VL) to -0.4404684222958214 Volts
        Pacs_BOLC_SET_VL_G3(-0.4404684222958214);
        // Set group 3 bol bias 03 (VRL) to 0.41334124907167524 Volts
        Pacs_BOLC_SET_VRL_G3(0.41334124907167524);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9973275250137286 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9973275250137286);
        // Set group 4 bol bias 01 (VH) to 2.170304299964091 Volts
        Pacs_BOLC_SET_VH_G4(2.170304299964091);
        // Set group 4 bol bias 02 (VL) to -0.42969570003590896 Volts
        Pacs_BOLC_SET_VL_G4(-0.42969570003590896);
        // Set group 4 bol bias 03 (VRL) to 0.39229709106193544 Volts
        Pacs_BOLC_SET_VRL_G4(0.39229709106193544);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9991388331630189 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9991388331630189);
        // Set group 5 bol bias 01 (VH) to 1.8387544191430765 Volts
        Pacs_BOLC_SET_VH_G5(1.8387544191430765);
        // Set group 5 bol bias 02 (VL) to -0.36124558085692376 Volts
        Pacs_BOLC_SET_VL_G5(-0.36124558085692376);
        // Set group 5 bol bias 03 (VRL) to 0.4248823693610551 Volts
        Pacs_BOLC_SET_VRL_G5(0.4248823693610551);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.053248047331341 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.053248047331341);
        // Set group 6 bol bias 01 (VH) to 1.8592993014606782 Volts
        Pacs_BOLC_SET_VH_G6(1.8592993014606782);
        // Set group 6 bol bias 02 (VL) to -0.34070069853932194 Volts
        Pacs_BOLC_SET_VL_G6(-0.34070069853932194);
        // Set group 6 bol bias 03 (VRL) to 0.4266611014559859 Volts
        Pacs_BOLC_SET_VRL_G6(0.4266611014559859);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.002629657329772 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.002629657329772);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_7") {
        //***********************************************************
        // Bias 14 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.3 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.2753008617761528 Volts
        Pacs_BOLC_SET_VH_G1(2.2753008617761528);
        // Set group 1 bol bias 02 (VL) to -0.42469913822384736 Volts
        Pacs_BOLC_SET_VL_G1(-0.42469913822384736);
        // Set group 1 bol bias 03 (VRL) to 0.41305128775731165 Volts
        Pacs_BOLC_SET_VRL_G1(0.41305128775731165);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0188128839956407 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.0188128839956407);
        // Set group 2 bol bias 01 (VH) to 2.2200540205830306 Volts
        Pacs_BOLC_SET_VH_G2(2.2200540205830306);
        // Set group 2 bol bias 02 (VL) to -0.47994597941696954 Volts
        Pacs_BOLC_SET_VL_G2(-0.47994597941696954);
        // Set group 2 bol bias 03 (VRL) to 0.384046120637867 Volts
        Pacs_BOLC_SET_VRL_G2(0.384046120637867);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9897061638175213 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9897061638175213);
        // Set group 3 bol bias 01 (VH) to 2.245249492019461 Volts
        Pacs_BOLC_SET_VH_G3(2.245249492019461);
        // Set group 3 bol bias 02 (VL) to -0.4547505079805393 Volts
        Pacs_BOLC_SET_VL_G3(-0.4547505079805393);
        // Set group 3 bol bias 03 (VRL) to 0.4125629897111581 Volts
        Pacs_BOLC_SET_VRL_G3(0.4125629897111581);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9965581992791106 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9965581992791106);
        // Set group 4 bol bias 01 (VH) to 2.270618026838391 Volts
        Pacs_BOLC_SET_VH_G4(2.270618026838391);
        // Set group 4 bol bias 02 (VL) to -0.42938197316160936 Volts
        Pacs_BOLC_SET_VL_G4(-0.42938197316160936);
        // Set group 4 bol bias 03 (VRL) to 0.40477056217070767 Volts
        Pacs_BOLC_SET_VRL_G4(0.40477056217070767);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0114969201970143 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.0114969201970143);
        // Set group 5 bol bias 01 (VH) to 1.9023766892145328 Volts
        Pacs_BOLC_SET_VH_G5(1.9023766892145328);
        // Set group 5 bol bias 02 (VL) to -0.3976233107854671 Volts
        Pacs_BOLC_SET_VL_G5(-0.3976233107854671);
        // Set group 5 bol bias 03 (VRL) to 0.4120200100696618 Volts
        Pacs_BOLC_SET_VRL_G5(0.4120200100696618);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0403086300201214 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0403086300201214);
        // Set group 6 bol bias 01 (VH) to 1.9352110902279933 Volts
        Pacs_BOLC_SET_VH_G6(1.9352110902279933);
        // Set group 6 bol bias 02 (VL) to -0.3647889097720066 Volts
        Pacs_BOLC_SET_VL_G6(-0.3647889097720066);
        // Set group 6 bol bias 03 (VRL) to 0.4251544040958699 Volts
        Pacs_BOLC_SET_VRL_G6(0.4251544040958699);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0011222019097725 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0011222019097725);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_8") {
        //***********************************************************
        // Bias 15 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.4 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.3706004267013063 Volts
        Pacs_BOLC_SET_VH_G1(2.3706004267013063);
        // Set group 1 bol bias 02 (VL) to -0.42939957329869366 Volts
        Pacs_BOLC_SET_VL_G1(-0.42939957329869366);
        // Set group 1 bol bias 03 (VRL) to 0.4128233157591776 Volts
        Pacs_BOLC_SET_VRL_G1(0.4128233157591776);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9741413207323013 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9741413207323013);
        // Set group 2 bol bias 01 (VH) to 2.30849650818746 Volts
        Pacs_BOLC_SET_VH_G2(2.30849650818746);
        // Set group 2 bol bias 02 (VL) to -0.49150349181253966 Volts
        Pacs_BOLC_SET_VL_G2(-0.49150349181253966);
        // Set group 2 bol bias 03 (VRL) to 0.3818593817104539 Volts
        Pacs_BOLC_SET_VRL_G2(0.3818593817104539);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.987544087436569 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.987544087436569);
        // Set group 3 bol bias 01 (VH) to 2.3365657260248964 Volts
        Pacs_BOLC_SET_VH_G3(2.3365657260248964);
        // Set group 3 bol bias 02 (VL) to -0.4634342739751033 Volts
        Pacs_BOLC_SET_VL_G3(-0.4634342739751033);
        // Set group 3 bol bias 03 (VRL) to 0.41203384722665815 Volts
        Pacs_BOLC_SET_VRL_G3(0.41203384722665815);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9960351445039464 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9960351445039464);
        // Set group 4 bol bias 01 (VH) to 2.3518733233838134 Volts
        Pacs_BOLC_SET_VH_G4(2.3518733233838134);
        // Set group 4 bol bias 02 (VL) to -0.4481266766161862 Volts
        Pacs_BOLC_SET_VL_G4(-0.4481266766161862);
        // Set group 4 bol bias 03 (VRL) to 0.3934834273661596 Volts
        Pacs_BOLC_SET_VRL_G4(0.3934834273661596);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0003195538237746 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.0003195538237746);
        // Set group 5 bol bias 01 (VH) to 1.9800777632387063 Volts
        Pacs_BOLC_SET_VH_G5(1.9800777632387063);
        // Set group 5 bol bias 02 (VL) to -0.4199222367612936 Volts
        Pacs_BOLC_SET_VL_G5(-0.4199222367612936);
        // Set group 5 bol bias 03 (VRL) to 0.40944012382521133 Volts
        Pacs_BOLC_SET_VRL_G5(0.40944012382521133);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0377115768798726 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0377115768798726);
        // Set group 6 bol bias 01 (VH) to 2.01513172113205 Volts
        Pacs_BOLC_SET_VH_G6(2.01513172113205);
        // Set group 6 bol bias 02 (VL) to -0.38486827886795016 Volts
        Pacs_BOLC_SET_VL_G6(-0.38486827886795016);
        // Set group 6 bol bias 03 (VRL) to 0.4236192556113485 Volts
        Pacs_BOLC_SET_VRL_G6(0.4236192556113485);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.9995863630649058 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.9995863630649058);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_9") {
        //***********************************************************
        // Bias 16 (Vh-Vl)bleu = 2.9 Volts, (Vh-Vl)rouge = 2.5 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.481656607902919 Volts
        Pacs_BOLC_SET_VH_G1(2.481656607902919);
        // Set group 1 bol bias 02 (VL) to -0.4183433920970805 Volts
        Pacs_BOLC_SET_VL_G1(-0.4183433920970805);
        // Set group 1 bol bias 03 (VRL) to 0.42341440262252883 Volts
        Pacs_BOLC_SET_VRL_G1(0.42341440262252883);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9846940225694476 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9846940225694476);
        // Set group 2 bol bias 01 (VH) to 2.414691010796746 Volts
        Pacs_BOLC_SET_VH_G2(2.414691010796746);
        // Set group 2 bol bias 02 (VL) to -0.4853089892032536 Volts
        Pacs_BOLC_SET_VL_G2(-0.4853089892032536);
        // Set group 2 bol bias 03 (VRL) to 0.39253051982236287 Volts
        Pacs_BOLC_SET_VRL_G2(0.39253051982236287);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.975870648916194 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.975870648916194);
        // Set group 3 bol bias 01 (VH) to 2.433226441693846 Volts
        Pacs_BOLC_SET_VH_G3(2.433226441693846);
        // Set group 3 bol bias 02 (VL) to -0.4667735583061541 Volts
        Pacs_BOLC_SET_VL_G3(-0.4667735583061541);
        // Set group 3 bol bias 03 (VRL) to 0.41131230190878887 Volts
        Pacs_BOLC_SET_VRL_G3(0.41131230190878887);
        // Set group 3 bol bias 20 (VH_BLIND) to 2.017544140544661 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(2.017544140544661);
        // Set group 4 bol bias 01 (VH) to 2.4505544534181185 Volts
        Pacs_BOLC_SET_VH_G4(2.4505544534181185);
        // Set group 4 bol bias 02 (VL) to -0.4494455465818812 Volts
        Pacs_BOLC_SET_VL_G4(-0.4494455465818812);
        // Set group 4 bol bias 03 (VRL) to 0.39404533883994697 Volts
        Pacs_BOLC_SET_VRL_G4(0.39404533883994697);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0231010170539365 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.0231010170539365);
        // Set group 5 bol bias 01 (VH) to 2.084532589278408 Volts
        Pacs_BOLC_SET_VH_G5(2.084532589278408);
        // Set group 5 bol bias 02 (VL) to -0.415467410721592 Volts
        Pacs_BOLC_SET_VL_G5(-0.415467410721592);
        // Set group 5 bol bias 03 (VRL) to 0.4287571629467245 Volts
        Pacs_BOLC_SET_VRL_G5(0.4287571629467245);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.012698827468528 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.012698827468528);
        // Set group 6 bol bias 01 (VH) to 2.0995907437397068 Volts
        Pacs_BOLC_SET_VH_G6(2.0995907437397068);
        // Set group 6 bol bias 02 (VL) to -0.4004092562602932 Volts
        Pacs_BOLC_SET_VL_G6(-0.4004092562602932);
        // Set group 6 bol bias 03 (VRL) to 0.42148512746445066 Volts
        Pacs_BOLC_SET_VRL_G6(0.42148512746445066);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.99745141271377 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.99745141271377);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b3_0") {
        //***********************************************************
        // Bias 17 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.6 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.600397057706278 Volts
        Pacs_BOLC_SET_VH_G1(2.600397057706278);
        // Set group 1 bol bias 02 (VL) to -0.3996029422937219 Volts
        Pacs_BOLC_SET_VL_G1(-0.3996029422937219);
        // Set group 1 bol bias 03 (VRL) to 0.4352373155819225 Volts
        Pacs_BOLC_SET_VRL_G1(0.4352373155819225);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.996478815796946 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.996478815796946);
        // Set group 2 bol bias 01 (VH) to 2.514934658647339 Volts
        Pacs_BOLC_SET_VH_G2(2.514934658647339);
        // Set group 2 bol bias 02 (VL) to -0.485065341352661 Volts
        Pacs_BOLC_SET_VL_G2(-0.485065341352661);
        // Set group 2 bol bias 03 (VRL) to 0.39192545859088324 Volts
        Pacs_BOLC_SET_VRL_G2(0.39192545859088324);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9974948822002625 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9974948822002625);
        // Set group 3 bol bias 01 (VH) to 2.537533329053119 Volts
        Pacs_BOLC_SET_VH_G3(2.537533329053119);
        // Set group 3 bol bias 02 (VL) to -0.4624666709468811 Volts
        Pacs_BOLC_SET_VL_G3(-0.4624666709468811);
        // Set group 3 bol bias 03 (VRL) to 0.4110505916239857 Volts
        Pacs_BOLC_SET_VRL_G3(0.4110505916239857);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9950632305477918 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9950632305477918);
        // Set group 4 bol bias 01 (VH) to 2.5528988845382643 Volts
        Pacs_BOLC_SET_VH_G4(2.5528988845382643);
        // Set group 4 bol bias 02 (VL) to -0.4471011154617358 Volts
        Pacs_BOLC_SET_VL_G4(-0.4471011154617358);
        // Set group 4 bol bias 03 (VRL) to 0.39332244377654313 Volts
        Pacs_BOLC_SET_VRL_G4(0.39332244377654313);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.97793711182537 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.97793711182537);
        // Set group 5 bol bias 01 (VH) to 2.172287009978402 Volts
        Pacs_BOLC_SET_VH_G5(2.172287009978402);
        // Set group 5 bol bias 02 (VL) to -0.4277129900215981 Volts
        Pacs_BOLC_SET_VL_G5(-0.4277129900215981);
        // Set group 5 bol bias 03 (VRL) to 0.424805887491143 Volts
        Pacs_BOLC_SET_VRL_G5(0.424805887491143);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.9865044825613933 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.9865044825613933);
        // Set group 6 bol bias 01 (VH) to 2.192498481627701 Volts
        Pacs_BOLC_SET_VH_G6(2.192498481627701);
        // Set group 6 bol bias 02 (VL) to -0.4075015183722993 Volts
        Pacs_BOLC_SET_VL_G6(-0.4075015183722993);
        // Set group 6 bol bias 03 (VRL) to 0.4230819346131489 Volts
        Pacs_BOLC_SET_VRL_G6(0.4230819346131489);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.9990488199887213 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.9990488199887213);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b3_1") {
        //***********************************************************
        // Bias 18 (Vh-Vl)bleu = 3.1 Volts, (Vh-Vl)rouge = 2.7 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.7231858510855047 Volts
        Pacs_BOLC_SET_VH_G1(2.7231858510855047);
        // Set group 1 bol bias 02 (VL) to -0.3768141489144955 Volts
        Pacs_BOLC_SET_VL_G1(-0.3768141489144955);
        // Set group 1 bol bias 03 (VRL) to 0.44566796402443376 Volts
        Pacs_BOLC_SET_VRL_G1(0.44566796402443376);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0068845500748607 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.0068845500748607);
        // Set group 2 bol bias 01 (VH) to 2.6328472848704307 Volts
        Pacs_BOLC_SET_VH_G2(2.6328472848704307);
        // Set group 2 bol bias 02 (VL) to -0.46715271512956946 Volts
        Pacs_BOLC_SET_VL_G2(-0.46715271512956946);
        // Set group 2 bol bias 03 (VRL) to 0.4033574824568482 Volts
        Pacs_BOLC_SET_VRL_G2(0.4033574824568482);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.98654163454466 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.98654163454466);
        // Set group 3 bol bias 01 (VH) to 2.671015555171699 Volts
        Pacs_BOLC_SET_VH_G3(2.671015555171699);
        // Set group 3 bol bias 02 (VL) to -0.4289844448283011 Volts
        Pacs_BOLC_SET_VL_G3(-0.4289844448283011);
        // Set group 3 bol bias 03 (VRL) to 0.4334238579780366 Volts
        Pacs_BOLC_SET_VRL_G3(0.4334238579780366);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9949656787915016 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9949656787915016);
        // Set group 4 bol bias 01 (VH) to 2.683355029655175 Volts
        Pacs_BOLC_SET_VH_G4(2.683355029655175);
        // Set group 4 bol bias 02 (VL) to -0.41664497034482534 Volts
        Pacs_BOLC_SET_VL_G4(-0.41664497034482534);
        // Set group 4 bol bias 03 (VRL) to 0.4148785432313051 Volts
        Pacs_BOLC_SET_VRL_G4(0.4148785432313051);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.021492839689401 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.021492839689401);
        // Set group 5 bol bias 01 (VH) to 2.265458141418861 Volts
        Pacs_BOLC_SET_VH_G5(2.265458141418861);
        // Set group 5 bol bias 02 (VL) to -0.4345418585811395 Volts
        Pacs_BOLC_SET_VL_G5(-0.4345418585811395);
        // Set group 5 bol bias 03 (VRL) to 0.42074010861107924 Volts
        Pacs_BOLC_SET_VRL_G5(0.42074010861107924);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.960193631972712 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.960193631972712);
        // Set group 6 bol bias 01 (VH) to 2.291335406841721 Volts
        Pacs_BOLC_SET_VH_G6(2.291335406841721);
        // Set group 6 bol bias 02 (VL) to -0.4086645931582792 Volts
        Pacs_BOLC_SET_VL_G6(-0.4086645931582792);
        // Set group 6 bol bias 03 (VRL) to 0.42408872519340446 Volts
        Pacs_BOLC_SET_VRL_G6(0.42408872519340446);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0000560349821974 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0000560349821974);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b3_3") {
        //***********************************************************
        // Bias 19 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.8 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.953762912317898 Volts
        Pacs_BOLC_SET_VH_G1(2.953762912317898);
        // Set group 1 bol bias 02 (VL) to -0.34623708768210176 Volts
        Pacs_BOLC_SET_VL_G1(-0.34623708768210176);
        // Set group 1 bol bias 03 (VRL) to 0.4351408430547646 Volts
        Pacs_BOLC_SET_VRL_G1(0.4351408430547646);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.018604765708868 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.018604765708868);
        // Set group 2 bol bias 01 (VH) to 2.8726352179977614 Volts
        Pacs_BOLC_SET_VH_G2(2.8726352179977614);
        // Set group 2 bol bias 02 (VL) to -0.42736478200223854 Volts
        Pacs_BOLC_SET_VL_G2(-0.42736478200223854);
        // Set group 2 bol bias 03 (VRL) to 0.414735933268399 Volts
        Pacs_BOLC_SET_VRL_G2(0.414735933268399);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9977822068595887 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9977822068595887);
        // Set group 3 bol bias 01 (VH) to 2.912560583948949 Volts
        Pacs_BOLC_SET_VH_G3(2.912560583948949);
        // Set group 3 bol bias 02 (VL) to -0.38743941605105087 Volts
        Pacs_BOLC_SET_VL_G3(-0.38743941605105087);
        // Set group 3 bol bias 03 (VRL) to 0.43313062540919095 Volts
        Pacs_BOLC_SET_VRL_G3(0.43313062540919095);
        // Set group 3 bol bias 20 (VH_BLIND) to 2.016897798393872 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(2.016897798393872);
        // Set group 4 bol bias 01 (VH) to 2.9276689529187987 Volts
        Pacs_BOLC_SET_VH_G4(2.9276689529187987);
        // Set group 4 bol bias 02 (VL) to -0.3723310470812009 Volts
        Pacs_BOLC_SET_VL_G4(-0.3723310470812009);
        // Set group 4 bol bias 03 (VRL) to 0.4250104382196459 Volts
        Pacs_BOLC_SET_VRL_G4(0.4250104382196459);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.03153123431831 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.03153123431831);
        // Set group 5 bol bias 01 (VH) to 2.3685426057457377 Volts
        Pacs_BOLC_SET_VH_G5(2.3685426057457377);
        // Set group 5 bol bias 02 (VL) to -0.431457394254262 Volts
        Pacs_BOLC_SET_VL_G5(-0.431457394254262);
        // Set group 5 bol bias 03 (VRL) to 0.4194660339248105 Volts
        Pacs_BOLC_SET_VRL_G5(0.4194660339248105);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.958912105112433 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.958912105112433);
        // Set group 6 bol bias 01 (VH) to 2.387979742674767 Volts
        Pacs_BOLC_SET_VH_G6(2.387979742674767);
        // Set group 6 bol bias 02 (VL) to -0.41202025732523284 Volts
        Pacs_BOLC_SET_VL_G6(-0.41202025732523284);
        // Set group 6 bol bias 03 (VRL) to 0.41583832368330265 Volts
        Pacs_BOLC_SET_VRL_G6(0.41583832368330265);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.9918032048982883 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.9918032048982883);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b3_5") {
        //***********************************************************
        // Bias 20 (Vh-Vl)bleu = 3.5 Volts, (Vh-Vl)rouge = 3.0 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 3.2215792747333167 Volts
        Pacs_BOLC_SET_VH_G1(3.2215792747333167);
        // Set group 1 bol bias 02 (VL) to -0.2784207252666834 Volts
        Pacs_BOLC_SET_VL_G1(-0.2784207252666834);
        // Set group 1 bol bias 03 (VRL) to 0.4417658775487089 Volts
        Pacs_BOLC_SET_VRL_G1(0.4417658775487089);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0029925416622745 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.0029925416622745);
        // Set group 2 bol bias 01 (VH) to 3.125766471402503 Volts
        Pacs_BOLC_SET_VH_G2(3.125766471402503);
        // Set group 2 bol bias 02 (VL) to -0.37423352859749703 Volts
        Pacs_BOLC_SET_VL_G2(-0.37423352859749703);
        // Set group 2 bol bias 03 (VRL) to 0.4173574683012983 Volts
        Pacs_BOLC_SET_VRL_G2(0.4173574683012983);
        // Set group 2 bol bias 20 (VH_BLIND) to 2.022605609147021 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(2.022605609147021);
        // Set group 3 bol bias 01 (VH) to 3.177257384071087 Volts
        Pacs_BOLC_SET_VH_G3(3.177257384071087);
        // Set group 3 bol bias 02 (VL) to -0.322742615928913 Volts
        Pacs_BOLC_SET_VL_G3(-0.322742615928913);
        // Set group 3 bol bias 03 (VRL) to 0.43185016495155787 Volts
        Pacs_BOLC_SET_VRL_G3(0.43185016495155787);
        // Set group 3 bol bias 20 (VH_BLIND) to 2.0156310454329387 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(2.0156310454329387);
        // Set group 4 bol bias 01 (VH) to 3.1731210990369876 Volts
        Pacs_BOLC_SET_VH_G4(3.1731210990369876);
        // Set group 4 bol bias 02 (VL) to -0.3268789009630126 Volts
        Pacs_BOLC_SET_VL_G4(-0.3268789009630126);
        // Set group 4 bol bias 03 (VRL) to 0.41433291143376344 Volts
        Pacs_BOLC_SET_VRL_G4(0.41433291143376344);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0209525376587134 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(2.0209525376587134);
        // Set group 5 bol bias 01 (VH) to 2.6023262611288924 Volts
        Pacs_BOLC_SET_VH_G5(2.6023262611288924);
        // Set group 5 bol bias 02 (VL) to -0.3976737388711077 Volts
        Pacs_BOLC_SET_VL_G5(-0.3976737388711077);
        // Set group 5 bol bias 03 (VRL) to 0.41713188109460797 Volts
        Pacs_BOLC_SET_VRL_G5(0.41713188109460797);
        // Set group 5 bol bias 20 (VH_BLIND) to 1.9565639381039313 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(1.9565639381039313);
        // Set group 6 bol bias 01 (VH) to 2.6133778395994915 Volts
        Pacs_BOLC_SET_VH_G6(2.6133778395994915);
        // Set group 6 bol bias 02 (VL) to -0.3866221604005083 Volts
        Pacs_BOLC_SET_VL_G6(-0.3866221604005083);
        // Set group 6 bol bias 03 (VRL) to 0.3988282729535058 Volts
        Pacs_BOLC_SET_VRL_G6(0.3988282729535058);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0194203860131417 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0194203860131417);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "final") {
        //********************************
        // Epilogue : Set the end biases
        //********************************
        PHOT_change_biases(endBiasTable,"DIRECT","LOW");
        //
        // sync the bus
        sync();
    }
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req.1.1.1bis for the Commissioning Phase
//           Check the bias/signal relationship using CSs
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowGainBias1_direct
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   + Set the biases group by group
//   + Set the blue filter 100um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 8 sets of 4 baisc biases (VH, VL, VRL, VH-BLIND) are set group by group
//   + Set the blue filter 70um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 8 sets of 4 baisc biases (VH, VL, VRL, VH-BLIND) are set group by group
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_CommPh_lowGainBias1(1, "LOW")
//            New version
//
// Version : Fri Apr 18 18:00:37 CEST 2008
//
procedure Phot_lowGainBias1_direct {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
}{
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //***********************************************
    //***********************************************
    //
    // Bias setting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(startBiasTable,1);
    PHOT_set_bias_volt(startBiasTable,2);
    PHOT_set_bias_volt(startBiasTable,3);
    PHOT_set_bias_volt(startBiasTable,4);
    PHOT_set_bias_volt(startBiasTable,5);
    PHOT_set_bias_volt(startBiasTable,6);
    //
    //********************************************************
    // Sequence mode : blocking on VDEC_X for the direct mode
    //********************************************************
    //
    // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
    // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
    //
    //**************************
    // Sequence mode : Sref_only
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
    //# P 09 01 00 01
    int operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // Set gain low
    Pacs_BOLC_SET_GAIN("LOW");
    //
    //**********************************************
    // Set the PAcS chopper at the position -21350
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(-21350);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS1 at 48.0 K
    // corresponding to 1.20pW on the green and 5.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.457556831416261 Volts
    Pacs_BOLC_SET_VH_G1(1.457556831416261);
    // Set group 1 bol bias 02 (VL) to -0.14244316858373907 Volts
    Pacs_BOLC_SET_VL_G1(-0.14244316858373907);
    // Set group 1 bol bias 03 (VRL) to 0.39289728144635716 Volts
    Pacs_BOLC_SET_VRL_G1(0.39289728144635716);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151471417543995 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151471417543995);
    // Set group 2 bol bias 01 (VH) to 1.444087138537561 Volts
    Pacs_BOLC_SET_VH_G2(1.444087138537561);
    // Set group 2 bol bias 02 (VL) to -0.1559128614624391 Volts
    Pacs_BOLC_SET_VL_G2(-0.1559128614624391);
    // Set group 2 bol bias 03 (VRL) to 0.3888592125442133 Volts
    Pacs_BOLC_SET_VRL_G2(0.3888592125442133);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1467299681244416 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1467299681244416);
    // Set group 3 bol bias 01 (VH) to 1.4461276964721905 Volts
    Pacs_BOLC_SET_VH_G3(1.4461276964721905);
    // Set group 3 bol bias 02 (VL) to -0.15387230352780956 Volts
    Pacs_BOLC_SET_VL_G3(-0.15387230352780956);
    // Set group 3 bol bias 03 (VRL) to 0.389702653261631 Volts
    Pacs_BOLC_SET_VRL_G3(0.389702653261631);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1440068212666743 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1440068212666743);
    // Set group 4 bol bias 01 (VH) to 1.461535092163816 Volts
    Pacs_BOLC_SET_VH_G4(1.461535092163816);
    // Set group 4 bol bias 02 (VL) to -0.13846490783618415 Volts
    Pacs_BOLC_SET_VL_G4(-0.13846490783618415);
    // Set group 4 bol bias 03 (VRL) to 0.38666891513104484 Volts
    Pacs_BOLC_SET_VRL_G4(0.38666891513104484);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1428402830030913 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1428402830030913);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.393205233420548 Volts
    Pacs_BOLC_SET_VRL_G5(0.393205233420548);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.144845482323282 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.144845482323282);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3832953489422562 Volts
    Pacs_BOLC_SET_VRL_G6(0.3832953489422562);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.130607584787264 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.130607584787264);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.585769661368119 Volts
    Pacs_BOLC_SET_VH_G1(1.585769661368119);
    // Set group 1 bol bias 02 (VL) to -0.214230338631881 Volts
    Pacs_BOLC_SET_VL_G1(-0.214230338631881);
    // Set group 1 bol bias 03 (VRL) to 0.39304515064751266 Volts
    Pacs_BOLC_SET_VRL_G1(0.39304515064751266);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151646819089764 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151646819089764);
    // Set group 2 bol bias 01 (VH) to 1.571162518585341 Volts
    Pacs_BOLC_SET_VH_G2(1.571162518585341);
    // Set group 2 bol bias 02 (VL) to -0.22883748141465898 Volts
    Pacs_BOLC_SET_VL_G2(-0.22883748141465898);
    // Set group 2 bol bias 03 (VRL) to 0.3888194923923588 Volts
    Pacs_BOLC_SET_VRL_G2(0.3888194923923588);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1466838588402206 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1466838588402206);
    // Set group 3 bol bias 01 (VH) to 1.5728976206374763 Volts
    Pacs_BOLC_SET_VH_G3(1.5728976206374763);
    // Set group 3 bol bias 02 (VL) to -0.22710237936252387 Volts
    Pacs_BOLC_SET_VL_G3(-0.22710237936252387);
    // Set group 3 bol bias 03 (VRL) to 0.39016220909623334 Volts
    Pacs_BOLC_SET_VRL_G3(0.39016220909623334);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144513683272569 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144513683272569);
    // Set group 4 bol bias 01 (VH) to 1.5905884509492139 Volts
    Pacs_BOLC_SET_VH_G4(1.5905884509492139);
    // Set group 4 bol bias 02 (VL) to -0.2094115490507863 Volts
    Pacs_BOLC_SET_VL_G4(-0.2094115490507863);
    // Set group 4 bol bias 03 (VRL) to 0.38773283476462383 Volts
    Pacs_BOLC_SET_VRL_G4(0.38773283476462383);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440552130411823 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440552130411823);
    // Set group 5 bol bias 01 (VH) to 1.3241923646302258 Volts
    Pacs_BOLC_SET_VH_G5(1.3241923646302258);
    // Set group 5 bol bias 02 (VL) to -0.07580763536977406 Volts
    Pacs_BOLC_SET_VL_G5(-0.07580763536977406);
    // Set group 5 bol bias 03 (VRL) to 0.40046001102514184 Volts
    Pacs_BOLC_SET_VRL_G5(0.40046001102514184);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.153546375049013 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.153546375049013);
    // Set group 6 bol bias 01 (VH) to 1.37098688511416 Volts
    Pacs_BOLC_SET_VH_G6(1.37098688511416);
    // Set group 6 bol bias 02 (VL) to -0.02901311488583999 Volts
    Pacs_BOLC_SET_VL_G6(-0.02901311488583999);
    // Set group 6 bol bias 03 (VRL) to 0.43611847195239406 Volts
    Pacs_BOLC_SET_VRL_G6(0.43611847195239406);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1943115490461103 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1943115490461103);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7183370767248043 Volts
    Pacs_BOLC_SET_VH_G1(1.7183370767248043);
    // Set group 1 bol bias 02 (VL) to -0.2816629232751957 Volts
    Pacs_BOLC_SET_VL_G1(-0.2816629232751957);
    // Set group 1 bol bias 03 (VRL) to 0.39272615099525776 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272615099525776);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151268425592528 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151268425592528);
    // Set group 2 bol bias 01 (VH) to 1.7019559750109217 Volts
    Pacs_BOLC_SET_VH_G2(1.7019559750109217);
    // Set group 2 bol bias 02 (VL) to -0.29804402498907834 Volts
    Pacs_BOLC_SET_VL_G2(-0.29804402498907834);
    // Set group 2 bol bias 03 (VRL) to 0.388357028089395 Volts
    Pacs_BOLC_SET_VRL_G2(0.388357028089395);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461470122884805 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461470122884805);
    // Set group 3 bol bias 01 (VH) to 1.714454188425701 Volts
    Pacs_BOLC_SET_VH_G3(1.714454188425701);
    // Set group 3 bol bias 02 (VL) to -0.2855458115742991 Volts
    Pacs_BOLC_SET_VL_G3(-0.2855458115742991);
    // Set group 3 bol bias 03 (VRL) to 0.401550404399907 Volts
    Pacs_BOLC_SET_VRL_G3(0.401550404399907);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.15707892246005 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.15707892246005);
    // Set group 4 bol bias 01 (VH) to 1.7242793470756728 Volts
    Pacs_BOLC_SET_VH_G4(1.7242793470756728);
    // Set group 4 bol bias 02 (VL) to -0.27572065292432724 Volts
    Pacs_BOLC_SET_VL_G4(-0.27572065292432724);
    // Set group 4 bol bias 03 (VRL) to 0.3889940535267571 Volts
    Pacs_BOLC_SET_VRL_G4(0.3889940535267571);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454955805079967 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454955805079967);
    // Set group 5 bol bias 01 (VH) to 1.4496153041151667 Volts
    Pacs_BOLC_SET_VH_G5(1.4496153041151667);
    // Set group 5 bol bias 02 (VL) to -0.15038469588483347 Volts
    Pacs_BOLC_SET_VL_G5(-0.15038469588483347);
    // Set group 5 bol bias 03 (VRL) to 0.39905723488551603 Volts
    Pacs_BOLC_SET_VRL_G5(0.39905723488551603);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.15186471364944 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.15186471364944);
    // Set group 6 bol bias 01 (VH) to 1.4970241024935167 Volts
    Pacs_BOLC_SET_VH_G6(1.4970241024935167);
    // Set group 6 bol bias 02 (VL) to -0.10297589750648331 Volts
    Pacs_BOLC_SET_VL_G6(-0.10297589750648331);
    // Set group 6 bol bias 03 (VRL) to 0.43401661473441144 Volts
    Pacs_BOLC_SET_VRL_G6(0.43401661473441144);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1918048548715423 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1918048548715423);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8585362347937342 Volts
    Pacs_BOLC_SET_VH_G1(1.8585362347937342);
    // Set group 1 bol bias 02 (VL) to -0.34146376520626587 Volts
    Pacs_BOLC_SET_VL_G1(-0.34146376520626587);
    // Set group 1 bol bias 03 (VRL) to 0.3925990888065586 Volts
    Pacs_BOLC_SET_VRL_G1(0.3925990888065586);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1511177079955788 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1511177079955788);
    // Set group 2 bol bias 01 (VH) to 1.838716500789082 Volts
    Pacs_BOLC_SET_VH_G2(1.838716500789082);
    // Set group 2 bol bias 02 (VL) to -0.3612834992109183 Volts
    Pacs_BOLC_SET_VL_G2(-0.3612834992109183);
    // Set group 2 bol bias 03 (VRL) to 0.38744902130448367 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744902130448367);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1450929993071512 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1450929993071512);
    // Set group 3 bol bias 01 (VH) to 1.85163190367321 Volts
    Pacs_BOLC_SET_VH_G3(1.85163190367321);
    // Set group 3 bol bias 02 (VL) to -0.34836809632679006 Volts
    Pacs_BOLC_SET_VL_G3(-0.34836809632679006);
    // Set group 3 bol bias 03 (VRL) to 0.4020826639883897 Volts
    Pacs_BOLC_SET_VRL_G3(0.4020826639883897);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157667831933953 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157667831933953);
    // Set group 4 bol bias 01 (VH) to 1.8658389594227858 Volts
    Pacs_BOLC_SET_VH_G4(1.8658389594227858);
    // Set group 4 bol bias 02 (VL) to -0.3341610405772144 Volts
    Pacs_BOLC_SET_VL_G4(-0.3341610405772144);
    // Set group 4 bol bias 03 (VRL) to 0.39087822103495706 Volts
    Pacs_BOLC_SET_VRL_G4(0.39087822103495706);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1476476539739764 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1476476539739764);
    // Set group 5 bol bias 01 (VH) to 1.5900913542685013 Volts
    Pacs_BOLC_SET_VH_G5(1.5900913542685013);
    // Set group 5 bol bias 02 (VL) to -0.20990864573149876 Volts
    Pacs_BOLC_SET_VL_G5(-0.20990864573149876);
    // Set group 5 bol bias 03 (VRL) to 0.40844955554354584 Volts
    Pacs_BOLC_SET_VRL_G5(0.40844955554354584);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.163093126853995 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.163093126853995);
    // Set group 6 bol bias 01 (VH) to 1.6276124853923464 Volts
    Pacs_BOLC_SET_VH_G6(1.6276124853923464);
    // Set group 6 bol bias 02 (VL) to -0.17238751460765359 Volts
    Pacs_BOLC_SET_VL_G6(-0.17238751460765359);
    // Set group 6 bol bias 03 (VRL) to 0.43216415132235575 Volts
    Pacs_BOLC_SET_VRL_G6(0.43216415132235575);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1895819441738285 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1895819441738285);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0202028596068895 Volts
    Pacs_BOLC_SET_VH_G1(2.0202028596068895);
    // Set group 1 bol bias 02 (VL) to -0.3797971403931106 Volts
    Pacs_BOLC_SET_VL_G1(-0.3797971403931106);
    // Set group 1 bol bias 03 (VRL) to 0.4031554178502121 Volts
    Pacs_BOLC_SET_VRL_G1(0.4031554178502121);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163634915975391 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163634915975391);
    // Set group 2 bol bias 01 (VH) to 1.9845954458032045 Volts
    Pacs_BOLC_SET_VH_G2(1.9845954458032045);
    // Set group 2 bol bias 02 (VL) to -0.41540455419679545 Volts
    Pacs_BOLC_SET_VL_G2(-0.41540455419679545);
    // Set group 2 bol bias 03 (VRL) to 0.38611513204716796 Volts
    Pacs_BOLC_SET_VRL_G2(0.38611513204716796);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1435447105412555 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1435447105412555);
    // Set group 3 bol bias 01 (VH) to 2.0091673911193446 Volts
    Pacs_BOLC_SET_VH_G3(2.0091673911193446);
    // Set group 3 bol bias 02 (VL) to -0.39083260888065513 Volts
    Pacs_BOLC_SET_VL_G3(-0.39083260888065513);
    // Set group 3 bol bias 03 (VRL) to 0.4135751200095534 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135751200095534);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170378532407885 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170378532407885);
    // Set group 4 bol bias 01 (VH) to 2.0158037297874873 Volts
    Pacs_BOLC_SET_VH_G4(2.0158037297874873);
    // Set group 4 bol bias 02 (VL) to -0.3841962702125128 Volts
    Pacs_BOLC_SET_VL_G4(-0.3841962702125128);
    // Set group 4 bol bias 03 (VRL) to 0.3915724280149063 Volts
    Pacs_BOLC_SET_VRL_G4(0.3915724280149063);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1484406507127387 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1484406507127387);
    // Set group 5 bol bias 01 (VH) to 1.7225616727109463 Volts
    Pacs_BOLC_SET_VH_G5(1.7225616727109463);
    // Set group 5 bol bias 02 (VL) to -0.27743832728905365 Volts
    Pacs_BOLC_SET_VL_G5(-0.27743832728905365);
    // Set group 5 bol bias 03 (VRL) to 0.40580736393386424 Volts
    Pacs_BOLC_SET_VRL_G5(0.40580736393386424);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.159935285624683 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.159935285624683);
    // Set group 6 bol bias 01 (VH) to 1.7622827443723812 Volts
    Pacs_BOLC_SET_VH_G6(1.7622827443723812);
    // Set group 6 bol bias 02 (VL) to -0.23771725562761872 Volts
    Pacs_BOLC_SET_VL_G6(-0.23771725562761872);
    // Set group 6 bol bias 03 (VRL) to 0.4298269773716583 Volts
    Pacs_BOLC_SET_VRL_G6(0.4298269773716583);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1867614355291423 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1867614355291423);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.196006753214598 Volts
    Pacs_BOLC_SET_VH_G1(2.196006753214598);
    // Set group 1 bol bias 02 (VL) to -0.4039932467854021 Volts
    Pacs_BOLC_SET_VL_G1(-0.4039932467854021);
    // Set group 1 bol bias 03 (VRL) to 0.41357184702417576 Volts
    Pacs_BOLC_SET_VRL_G1(0.41357184702417576);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1759648938728384 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1759648938728384);
    // Set group 2 bol bias 01 (VH) to 2.1433243650504217 Volts
    Pacs_BOLC_SET_VH_G2(2.1433243650504217);
    // Set group 2 bol bias 02 (VL) to -0.45667563494957836 Volts
    Pacs_BOLC_SET_VL_G2(-0.45667563494957836);
    // Set group 2 bol bias 03 (VRL) to 0.3850880425693594 Volts
    Pacs_BOLC_SET_VRL_G2(0.3850880425693594);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14235260562423 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14235260562423);
    // Set group 3 bol bias 01 (VH) to 2.1686669393324536 Volts
    Pacs_BOLC_SET_VH_G3(2.1686669393324536);
    // Set group 3 bol bias 02 (VL) to -0.43133306066754634 Volts
    Pacs_BOLC_SET_VL_G3(-0.43133306066754634);
    // Set group 3 bol bias 03 (VRL) to 0.41346974712361556 Volts
    Pacs_BOLC_SET_VRL_G3(0.41346974712361556);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.17026203238048 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.17026203238048);
    // Set group 4 bol bias 01 (VH) to 2.1793962970285237 Volts
    Pacs_BOLC_SET_VH_G4(2.1793962970285237);
    // Set group 4 bol bias 02 (VL) to -0.42060370297147653 Volts
    Pacs_BOLC_SET_VL_G4(-0.42060370297147653);
    // Set group 4 bol bias 03 (VRL) to 0.39239244557899233 Volts
    Pacs_BOLC_SET_VRL_G4(0.39239244557899233);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.149377418431709 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.149377418431709);
    // Set group 5 bol bias 01 (VH) to 1.8624422796333608 Volts
    Pacs_BOLC_SET_VH_G5(1.8624422796333608);
    // Set group 5 bol bias 02 (VL) to -0.3375577203666393 Volts
    Pacs_BOLC_SET_VL_G5(-0.3375577203666393);
    // Set group 5 bol bias 03 (VRL) to 0.4028017551941114 Volts
    Pacs_BOLC_SET_VRL_G5(0.4028017551941114);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.156343875220547 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.156343875220547);
    // Set group 6 bol bias 01 (VH) to 1.9050654119965236 Volts
    Pacs_BOLC_SET_VH_G6(1.9050654119965236);
    // Set group 6 bol bias 02 (VL) to -0.2949345880034766 Volts
    Pacs_BOLC_SET_VL_G6(-0.2949345880034766);
    // Set group 6 bol bias 03 (VRL) to 0.42788441761189455 Volts
    Pacs_BOLC_SET_VRL_G6(0.42788441761189455);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1844170100895375 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1844170100895375);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3796037366573897 Volts
    Pacs_BOLC_SET_VH_G1(2.3796037366573897);
    // Set group 1 bol bias 02 (VL) to -0.4203962633426101 Volts
    Pacs_BOLC_SET_VL_G1(-0.4203962633426101);
    // Set group 1 bol bias 03 (VRL) to 0.4129099400989898 Volts
    Pacs_BOLC_SET_VRL_G1(0.4129099400989898);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175181344026924 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175181344026924);
    // Set group 2 bol bias 01 (VH) to 2.315754480139234 Volts
    Pacs_BOLC_SET_VH_G2(2.315754480139234);
    // Set group 2 bol bias 02 (VL) to -0.4842455198607661 Volts
    Pacs_BOLC_SET_VL_G2(-0.4842455198607661);
    // Set group 2 bol bias 03 (VRL) to 0.38156757008948644 Volts
    Pacs_BOLC_SET_VRL_G2(0.38156757008948644);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.138266993828065 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.138266993828065);
    // Set group 3 bol bias 01 (VH) to 2.3449665772192874 Volts
    Pacs_BOLC_SET_VH_G3(2.3449665772192874);
    // Set group 3 bol bias 02 (VL) to -0.45503342278071257 Volts
    Pacs_BOLC_SET_VL_G3(-0.45503342278071257);
    // Set group 3 bol bias 03 (VRL) to 0.4122322683327103 Volts
    Pacs_BOLC_SET_VRL_G3(0.4122322683327103);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1688938193526224 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1688938193526224);
    // Set group 4 bol bias 01 (VH) to 2.360152158437928 Volts
    Pacs_BOLC_SET_VH_G4(2.360152158437928);
    // Set group 4 bol bias 02 (VL) to -0.4398478415620719 Volts
    Pacs_BOLC_SET_VL_G4(-0.4398478415620719);
    // Set group 4 bol bias 03 (VRL) to 0.39354738531821554 Volts
    Pacs_BOLC_SET_VRL_G4(0.39354738531821554);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150696897295742 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150696897295742);
    // Set group 5 bol bias 01 (VH) to 2.0139550919820626 Volts
    Pacs_BOLC_SET_VH_G5(2.0139550919820626);
    // Set group 5 bol bias 02 (VL) to -0.38604490801793717 Volts
    Pacs_BOLC_SET_VL_G5(-0.38604490801793717);
    // Set group 5 bol bias 03 (VRL) to 0.39874967908065667 Volts
    Pacs_BOLC_SET_VRL_G5(0.39874967908065667);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151495860090233 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151495860090233);
    // Set group 6 bol bias 01 (VH) to 2.0603593375586526 Volts
    Pacs_BOLC_SET_VH_G6(2.0603593375586526);
    // Set group 6 bol bias 02 (VL) to -0.3396406624413473 Volts
    Pacs_BOLC_SET_VL_G6(-0.3396406624413473);
    // Set group 6 bol bias 03 (VRL) to 0.4254561262075288 Volts
    Pacs_BOLC_SET_VRL_G6(0.4254561262075288);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1814861909041072 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1814861909041072);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6080079699591967 Volts
    Pacs_BOLC_SET_VH_G1(2.6080079699591967);
    // Set group 1 bol bias 02 (VL) to -0.39199203004080335 Volts
    Pacs_BOLC_SET_VL_G1(-0.39199203004080335);
    // Set group 1 bol bias 03 (VRL) to 0.4353039674693117 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353039674693117);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2016826896367014 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2016826896367014);
    // Set group 2 bol bias 01 (VH) to 2.5212704911688184 Volts
    Pacs_BOLC_SET_VH_G2(2.5212704911688184);
    // Set group 2 bol bias 02 (VL) to -0.4787295088311815 Volts
    Pacs_BOLC_SET_VL_G2(-0.4787295088311815);
    // Set group 2 bol bias 03 (VRL) to 0.39184175711517744 Volts
    Pacs_BOLC_SET_VRL_G2(0.39184175711517744);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150192531202592 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150192531202592);
    // Set group 3 bol bias 01 (VH) to 2.5446946302676037 Volts
    Pacs_BOLC_SET_VH_G3(2.5446946302676037);
    // Set group 3 bol bias 02 (VL) to -0.4553053697323962 Volts
    Pacs_BOLC_SET_VL_G3(-0.4553053697323962);
    // Set group 3 bol bias 03 (VRL) to 0.41118382754245053 Volts
    Pacs_BOLC_SET_VRL_G3(0.41118382754245053);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1677345299207764 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1677345299207764);
    // Set group 4 bol bias 01 (VH) to 2.582263974911207 Volts
    Pacs_BOLC_SET_VH_G4(2.582263974911207);
    // Set group 4 bol bias 02 (VL) to -0.4177360250887929 Volts
    Pacs_BOLC_SET_VL_G4(-0.4177360250887929);
    // Set group 4 bol bias 03 (VRL) to 0.4155747259799741 Volts
    Pacs_BOLC_SET_VRL_G4(0.4155747259799741);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1758807093660604 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1758807093660604);
    // Set group 5 bol bias 01 (VH) to 2.2123399887514554 Volts
    Pacs_BOLC_SET_VH_G5(2.2123399887514554);
    // Set group 5 bol bias 02 (VL) to -0.38766001124854466 Volts
    Pacs_BOLC_SET_VL_G5(-0.38766001124854466);
    // Set group 5 bol bias 03 (VRL) to 0.4257278403385899 Volts
    Pacs_BOLC_SET_VRL_G5(0.4257278403385899);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1837591130416554 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1837591130416554);
    // Set group 6 bol bias 01 (VH) to 2.2318001783201304 Volts
    Pacs_BOLC_SET_VH_G6(2.2318001783201304);
    // Set group 6 bol bias 02 (VL) to -0.36819982167986975 Volts
    Pacs_BOLC_SET_VL_G6(-0.36819982167986975);
    // Set group 6 bol bias 03 (VRL) to 0.423759377774352 Volts
    Pacs_BOLC_SET_VRL_G6(0.423759377774352);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1794381888209813 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1794381888209813);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //**********************************************
    // Set the PAcS chopper at the position 21200
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(21200);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS2 at 58.0 K
    // corresponding to 1.55pW on the green and 6.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4721285832931112 Volts
    Pacs_BOLC_SET_VH_G1(1.4721285832931112);
    // Set group 1 bol bias 02 (VL) to -0.12787141670688873 Volts
    Pacs_BOLC_SET_VL_G1(-0.12787141670688873);
    // Set group 1 bol bias 03 (VRL) to 0.3926297476827718 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926297476827718);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151154074587398 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151154074587398);
    // Set group 2 bol bias 01 (VH) to 1.4563242224495716 Volts
    Pacs_BOLC_SET_VH_G2(1.4563242224495716);
    // Set group 2 bol bias 02 (VL) to -0.14367577755042849 Volts
    Pacs_BOLC_SET_VL_G2(-0.14367577755042849);
    // Set group 2 bol bias 03 (VRL) to 0.3881765529411487 Volts
    Pacs_BOLC_SET_VRL_G2(0.3881765529411487);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.145937513130471 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.145937513130471);
    // Set group 3 bol bias 01 (VH) to 1.45972772124239 Volts
    Pacs_BOLC_SET_VH_G3(1.45972772124239);
    // Set group 3 bol bias 02 (VL) to -0.14027227875761006 Volts
    Pacs_BOLC_SET_VL_G3(-0.14027227875761006);
    // Set group 3 bol bias 03 (VRL) to 0.38988919840997094 Volts
    Pacs_BOLC_SET_VRL_G3(0.38988919840997094);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1442125685158864 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1442125685158864);
    // Set group 4 bol bias 01 (VH) to 1.4747276174033868 Volts
    Pacs_BOLC_SET_VH_G4(1.4747276174033868);
    // Set group 4 bol bias 02 (VL) to -0.12527238259661322 Volts
    Pacs_BOLC_SET_VL_G4(-0.12527238259661322);
    // Set group 4 bol bias 03 (VRL) to 0.38624222870786595 Volts
    Pacs_BOLC_SET_VRL_G4(0.38624222870786595);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1423530627314813 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1423530627314813);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3734713392363535 Volts
    Pacs_BOLC_SET_VRL_G5(0.3734713392363535);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1211616404276756 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1211616404276756);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3640870527167945 Volts
    Pacs_BOLC_SET_VRL_G6(0.3640870527167945);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1074512769294307 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1074512769294307);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6005646067625168 Volts
    Pacs_BOLC_SET_VH_G1(1.6005646067625168);
    // Set group 1 bol bias 02 (VL) to -0.19943539323748327 Volts
    Pacs_BOLC_SET_VL_G1(-0.19943539323748327);
    // Set group 1 bol bias 03 (VRL) to 0.3927137250656313 Volts
    Pacs_BOLC_SET_VRL_G1(0.3927137250656313);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1512536862532445 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1512536862532445);
    // Set group 2 bol bias 01 (VH) to 1.5835245401299414 Volts
    Pacs_BOLC_SET_VH_G2(1.5835245401299414);
    // Set group 2 bol bias 02 (VL) to -0.21647545987005867 Volts
    Pacs_BOLC_SET_VL_G2(-0.21647545987005867);
    // Set group 2 bol bias 03 (VRL) to 0.3880497715778095 Volts
    Pacs_BOLC_SET_VRL_G2(0.3880497715778095);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1457903439369534 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1457903439369534);
    // Set group 3 bol bias 01 (VH) to 1.5867464604266623 Volts
    Pacs_BOLC_SET_VH_G3(1.5867464604266623);
    // Set group 3 bol bias 02 (VL) to -0.2132535395733377 Volts
    Pacs_BOLC_SET_VL_G3(-0.2132535395733377);
    // Set group 3 bol bias 03 (VRL) to 0.3903025295231384 Volts
    Pacs_BOLC_SET_VRL_G3(0.3903025295231384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144668449205875 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144668449205875);
    // Set group 4 bol bias 01 (VH) to 1.6044364991789073 Volts
    Pacs_BOLC_SET_VH_G4(1.6044364991789073);
    // Set group 4 bol bias 02 (VL) to -0.19556350082109264 Volts
    Pacs_BOLC_SET_VL_G4(-0.19556350082109264);
    // Set group 4 bol bias 03 (VRL) to 0.387662053519384 Volts
    Pacs_BOLC_SET_VRL_G4(0.387662053519384);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1439743820479262 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1439743820479262);
    // Set group 5 bol bias 01 (VH) to 1.3451907640885556 Volts
    Pacs_BOLC_SET_VH_G5(1.3451907640885556);
    // Set group 5 bol bias 02 (VL) to -0.054809235911444244 Volts
    Pacs_BOLC_SET_VL_G5(-0.054809235911444244);
    // Set group 5 bol bias 03 (VRL) to 0.40021084689056974 Volts
    Pacs_BOLC_SET_VRL_G5(0.40021084689056974);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1532482013507512 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1532482013507512);
    // Set group 6 bol bias 01 (VH) to 1.39 Volts
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.4344512926668127 Volts
    Pacs_BOLC_SET_VRL_G6(0.4344512926668127);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.192323231555507 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.192323231555507);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7330644465100378 Volts
    Pacs_BOLC_SET_VH_G1(1.7330644465100378);
    // Set group 1 bol bias 02 (VL) to -0.26693555348996223 Volts
    Pacs_BOLC_SET_VL_G1(-0.26693555348996223);
    // Set group 1 bol bias 03 (VRL) to 0.3923254235050375 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923254235050375);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1507930978184753 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1507930978184753);
    // Set group 2 bol bias 01 (VH) to 1.714453661934205 Volts
    Pacs_BOLC_SET_VH_G2(1.714453661934205);
    // Set group 2 bol bias 02 (VL) to -0.2855463380657951 Volts
    Pacs_BOLC_SET_VL_G2(-0.2855463380657951);
    // Set group 2 bol bias 03 (VRL) to 0.38771628761093724 Volts
    Pacs_BOLC_SET_VRL_G2(0.38771628761093724);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1454032366160996 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1454032366160996);
    // Set group 3 bol bias 01 (VH) to 1.7283831876482196 Volts
    Pacs_BOLC_SET_VH_G3(1.7283831876482196);
    // Set group 3 bol bias 02 (VL) to -0.2716168123517804 Volts
    Pacs_BOLC_SET_VL_G3(-0.2716168123517804);
    // Set group 3 bol bias 03 (VRL) to 0.40171045250948384 Volts
    Pacs_BOLC_SET_VRL_G3(0.40171045250948384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157256007066197 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157256007066197);
    // Set group 4 bol bias 01 (VH) to 1.7381239240265867 Volts
    Pacs_BOLC_SET_VH_G4(1.7381239240265867);
    // Set group 4 bol bias 02 (VL) to -0.26187607597341334 Volts
    Pacs_BOLC_SET_VL_G4(-0.26187607597341334);
    // Set group 4 bol bias 03 (VRL) to 0.38896138623469356 Volts
    Pacs_BOLC_SET_VRL_G4(0.38896138623469356);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454582711839105 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454582711839105);
    // Set group 5 bol bias 01 (VH) to 1.4703496551390403 Volts
    Pacs_BOLC_SET_VH_G5(1.4703496551390403);
    // Set group 5 bol bias 02 (VL) to -0.12965034486095992 Volts
    Pacs_BOLC_SET_VL_G5(-0.12965034486095992);
    // Set group 5 bol bias 03 (VRL) to 0.39904033450461596 Volts
    Pacs_BOLC_SET_VRL_G5(0.39904033450461596);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151844445053932 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151844445053932);
    // Set group 6 bol bias 01 (VH) to 1.5181165758982518 Volts
    Pacs_BOLC_SET_VH_G6(1.5181165758982518);
    // Set group 6 bol bias 02 (VL) to -0.08188342410174834 Volts
    Pacs_BOLC_SET_VL_G6(-0.08188342410174834);
    // Set group 6 bol bias 03 (VRL) to 0.4343226272779045 Volts
    Pacs_BOLC_SET_VRL_G6(0.4343226272779045);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1921697898825356 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1921697898825356);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8730534488812565 Volts
    Pacs_BOLC_SET_VH_G1(1.8730534488812565);
    // Set group 1 bol bias 02 (VL) to -0.3269465511187437 Volts
    Pacs_BOLC_SET_VL_G1(-0.3269465511187437);
    // Set group 1 bol bias 03 (VRL) to 0.3922166883004623 Volts
    Pacs_BOLC_SET_VRL_G1(0.3922166883004623);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1506641222123926 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1506641222123926);
    // Set group 2 bol bias 01 (VH) to 1.8512060220322217 Volts
    Pacs_BOLC_SET_VH_G2(1.8512060220322217);
    // Set group 2 bol bias 02 (VL) to -0.34879397796777845 Volts
    Pacs_BOLC_SET_VL_G2(-0.34879397796777845);
    // Set group 2 bol bias 03 (VRL) to 0.3869592141320811 Volts
    Pacs_BOLC_SET_VRL_G2(0.3869592141320811);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1445244519836626 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1445244519836626);
    // Set group 3 bol bias 01 (VH) to 1.8654619469621685 Volts
    Pacs_BOLC_SET_VH_G3(1.8654619469621685);
    // Set group 3 bol bias 02 (VL) to -0.33453805303783174 Volts
    Pacs_BOLC_SET_VL_G3(-0.33453805303783174);
    // Set group 3 bol bias 03 (VRL) to 0.40224166318840543 Volts
    Pacs_BOLC_SET_VRL_G3(0.40224166318840543);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1578437499437477 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1578437499437477);
    // Set group 4 bol bias 01 (VH) to 1.8790483325189686 Volts
    Pacs_BOLC_SET_VH_G4(1.8790483325189686);
    // Set group 4 bol bias 02 (VL) to -0.32095166748103154 Volts
    Pacs_BOLC_SET_VL_G4(-0.32095166748103154);
    // Set group 4 bol bias 03 (VRL) to 0.39052544771082365 Volts
    Pacs_BOLC_SET_VRL_G4(0.39052544771082365);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1472446958154223 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1472446958154223);
    // Set group 5 bol bias 01 (VH) to 1.5997463742933684 Volts
    Pacs_BOLC_SET_VH_G5(1.5997463742933684);
    // Set group 5 bol bias 02 (VL) to -0.2002536257066316 Volts
    Pacs_BOLC_SET_VL_G5(-0.2002536257066316);
    // Set group 5 bol bias 03 (VRL) to 0.3972802806465645 Volts
    Pacs_BOLC_SET_VRL_G5(0.3972802806465645);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1497335299275955 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1497335299275955);
    // Set group 6 bol bias 01 (VH) to 1.64826517003746 Volts
    Pacs_BOLC_SET_VH_G6(1.64826517003746);
    // Set group 6 bol bias 02 (VL) to -0.1517348299625401 Volts
    Pacs_BOLC_SET_VL_G6(-0.1517348299625401);
    // Set group 6 bol bias 03 (VRL) to 0.43238698345346915 Volts
    Pacs_BOLC_SET_VRL_G6(0.43238698345346915);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.189850849172478 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.189850849172478);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.034145377320728 Volts
    Pacs_BOLC_SET_VH_G1(2.034145377320728);
    // Set group 1 bol bias 02 (VL) to -0.36585462267927166 Volts
    Pacs_BOLC_SET_VL_G1(-0.36585462267927166);
    // Set group 1 bol bias 03 (VRL) to 0.4026842358176688 Volts
    Pacs_BOLC_SET_VRL_G1(0.4026842358176688);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163077213168135 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163077213168135);
    // Set group 2 bol bias 01 (VH) to 1.9964246373780308 Volts
    Pacs_BOLC_SET_VH_G2(1.9964246373780308);
    // Set group 2 bol bias 02 (VL) to -0.40357536262196914 Volts
    Pacs_BOLC_SET_VL_G2(-0.40357536262196914);
    // Set group 2 bol bias 03 (VRL) to 0.38543545754038677 Volts
    Pacs_BOLC_SET_VRL_G2(0.38543545754038677);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1427558304354366 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1427558304354366);
    // Set group 3 bol bias 01 (VH) to 2.0225756539924595 Volts
    Pacs_BOLC_SET_VH_G3(2.0225756539924595);
    // Set group 3 bol bias 02 (VL) to -0.37742434600754043 Volts
    Pacs_BOLC_SET_VL_G3(-0.37742434600754043);
    // Set group 3 bol bias 03 (VRL) to 0.41362905220735763 Volts
    Pacs_BOLC_SET_VRL_G3(0.41362905220735763);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704381594190805 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704381594190805);
    // Set group 4 bol bias 01 (VH) to 2.0286801589025623 Volts
    Pacs_BOLC_SET_VH_G4(2.0286801589025623);
    // Set group 4 bol bias 02 (VL) to -0.37131984109743765 Volts
    Pacs_BOLC_SET_VL_G4(-0.37131984109743765);
    // Set group 4 bol bias 03 (VRL) to 0.39131683434261844 Volts
    Pacs_BOLC_SET_VRL_G4(0.39131683434261844);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.14814867942076 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.14814867942076);
    // Set group 5 bol bias 01 (VH) to 1.7436864671540049 Volts
    Pacs_BOLC_SET_VH_G5(1.7436864671540049);
    // Set group 5 bol bias 02 (VL) to -0.2563135328459952 Volts
    Pacs_BOLC_SET_VL_G5(-0.2563135328459952);
    // Set group 5 bol bias 03 (VRL) to 0.4060804936984878 Volts
    Pacs_BOLC_SET_VRL_G5(0.4060804936984878);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1602616898977316 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1602616898977316);
    // Set group 6 bol bias 01 (VH) to 1.7834132365202005 Volts
    Pacs_BOLC_SET_VH_G6(1.7834132365202005);
    // Set group 6 bol bias 02 (VL) to -0.21658676347979958 Volts
    Pacs_BOLC_SET_VL_G6(-0.21658676347979958);
    // Set group 6 bol bias 03 (VRL) to 0.43021242094743417 Volts
    Pacs_BOLC_SET_VRL_G6(0.43021242094743417);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1872266025341247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1872266025341247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.209416047586087 Volts
    Pacs_BOLC_SET_VH_G1(2.209416047586087);
    // Set group 1 bol bias 02 (VL) to -0.3905839524139128 Volts
    Pacs_BOLC_SET_VL_G1(-0.3905839524139128);
    // Set group 1 bol bias 03 (VRL) to 0.4134679213904496 Volts
    Pacs_BOLC_SET_VRL_G1(0.4134679213904496);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758418687268812 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758418687268812);
    // Set group 2 bol bias 01 (VH) to 2.1541915675147214 Volts
    Pacs_BOLC_SET_VH_G2(2.1541915675147214);
    // Set group 2 bol bias 02 (VL) to -0.44580843248527846 Volts
    Pacs_BOLC_SET_VL_G2(-0.44580843248527846);
    // Set group 2 bol bias 03 (VRL) to 0.38424319746039115 Volts
    Pacs_BOLC_SET_VRL_G2(0.38424319746039115);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1413720715536493 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1413720715536493);
    // Set group 3 bol bias 01 (VH) to 2.1813068162319285 Volts
    Pacs_BOLC_SET_VH_G3(2.1813068162319285);
    // Set group 3 bol bias 02 (VL) to -0.4186931837680716 Volts
    Pacs_BOLC_SET_VL_G3(-0.4186931837680716);
    // Set group 3 bol bias 03 (VRL) to 0.41360319513591143 Volts
    Pacs_BOLC_SET_VRL_G3(0.41360319513591143);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704095720713417 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704095720713417);
    // Set group 4 bol bias 01 (VH) to 2.202944386753124 Volts
    Pacs_BOLC_SET_VH_G4(2.202944386753124);
    // Set group 4 bol bias 02 (VL) to -0.3970556132468757 Volts
    Pacs_BOLC_SET_VL_G4(-0.3970556132468757);
    // Set group 4 bol bias 03 (VRL) to 0.40381007074137704 Volts
    Pacs_BOLC_SET_VRL_G4(0.40381007074137704);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1624292794462514 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1624292794462514);
    // Set group 5 bol bias 01 (VH) to 1.883738472848583 Volts
    Pacs_BOLC_SET_VH_G5(1.883738472848583);
    // Set group 5 bol bias 02 (VL) to -0.31626152715141714 Volts
    Pacs_BOLC_SET_VL_G5(-0.31626152715141714);
    // Set group 5 bol bias 03 (VRL) to 0.4028494691164935 Volts
    Pacs_BOLC_SET_VRL_G5(0.4028494691164935);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.156400882301432 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.156400882301432);
    // Set group 6 bol bias 01 (VH) to 1.9235912310846244 Volts
    Pacs_BOLC_SET_VH_G6(1.9235912310846244);
    // Set group 6 bol bias 02 (VL) to -0.2764087689153759 Volts
    Pacs_BOLC_SET_VL_G6(-0.2764087689153759);
    // Set group 6 bol bias 03 (VRL) to 0.4280070912945936 Volts
    Pacs_BOLC_SET_VRL_G6(0.4280070912945936);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1845650655206446 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1845650655206446);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3806926938420414 Volts
    Pacs_BOLC_SET_VH_G1(2.3806926938420414);
    // Set group 1 bol bias 02 (VL) to -0.41930730615795847 Volts
    Pacs_BOLC_SET_VL_G1(-0.41930730615795847);
    // Set group 1 bol bias 03 (VRL) to 0.4020155079485436 Volts
    Pacs_BOLC_SET_VRL_G1(0.4020155079485436);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162285695776181 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162285695776181);
    // Set group 2 bol bias 01 (VH) to 2.3371282046100963 Volts
    Pacs_BOLC_SET_VH_G2(2.3371282046100963);
    // Set group 2 bol bias 02 (VL) to -0.46287179538990364 Volts
    Pacs_BOLC_SET_VL_G2(-0.46287179538990364);
    // Set group 2 bol bias 03 (VRL) to 0.3923402298587034 Volts
    Pacs_BOLC_SET_VRL_G2(0.3923402298587034);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1507712805161225 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1507712805161225);
    // Set group 3 bol bias 01 (VH) to 2.356604953923699 Volts
    Pacs_BOLC_SET_VH_G3(2.356604953923699);
    // Set group 3 bol bias 02 (VL) to -0.44339504607630065 Volts
    Pacs_BOLC_SET_VL_G3(-0.44339504607630065);
    // Set group 3 bol bias 03 (VRL) to 0.4124662568673877 Volts
    Pacs_BOLC_SET_VRL_G3(0.4124662568673877);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.169152536126319 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.169152536126319);
    // Set group 4 bol bias 01 (VH) to 2.3825039100730487 Volts
    Pacs_BOLC_SET_VH_G4(2.3825039100730487);
    // Set group 4 bol bias 02 (VL) to -0.4174960899269509 Volts
    Pacs_BOLC_SET_VL_G4(-0.4174960899269509);
    // Set group 4 bol bias 03 (VRL) to 0.40493410269973024 Volts
    Pacs_BOLC_SET_VRL_G4(0.40493410269973024);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1637149679245193 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1637149679245193);
    // Set group 5 bol bias 01 (VH) to 2.0340896725156363 Volts
    Pacs_BOLC_SET_VH_G5(2.0340896725156363);
    // Set group 5 bol bias 02 (VL) to -0.3659103274843634 Volts
    Pacs_BOLC_SET_VL_G5(-0.3659103274843634);
    // Set group 5 bol bias 03 (VRL) to 0.3987896988621052 Volts
    Pacs_BOLC_SET_VRL_G5(0.3987896988621052);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1515438563527702 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1515438563527702);
    // Set group 6 bol bias 01 (VH) to 2.080247845760918 Volts
    Pacs_BOLC_SET_VH_G6(2.080247845760918);
    // Set group 6 bol bias 02 (VL) to -0.31975215423908154 Volts
    Pacs_BOLC_SET_VL_G6(-0.31975215423908154);
    // Set group 6 bol bias 03 (VRL) to 0.42577779561759777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42577779561759777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1818744401374954 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1818744401374954);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6181566702818313 Volts
    Pacs_BOLC_SET_VH_G1(2.6181566702818313);
    // Set group 1 bol bias 02 (VL) to -0.38184332971816887 Volts
    Pacs_BOLC_SET_VL_G1(-0.38184332971816887);
    // Set group 1 bol bias 03 (VRL) to 0.43545225816479755 Volts
    Pacs_BOLC_SET_VRL_G1(0.43545225816479755);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2018572484354544 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2018572484354544);
    // Set group 2 bol bias 01 (VH) to 2.5300933623498008 Volts
    Pacs_BOLC_SET_VH_G2(2.5300933623498008);
    // Set group 2 bol bias 02 (VL) to -0.469906637650199 Volts
    Pacs_BOLC_SET_VL_G2(-0.469906637650199);
    // Set group 2 bol bias 03 (VRL) to 0.3917176926734228 Volts
    Pacs_BOLC_SET_VRL_G2(0.3917176926734228);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1500484890692286 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1500484890692286);
    // Set group 3 bol bias 01 (VH) to 2.5545115967606167 Volts
    Pacs_BOLC_SET_VH_G3(2.5545115967606167);
    // Set group 3 bol bias 02 (VL) to -0.4454884032393832 Volts
    Pacs_BOLC_SET_VL_G3(-0.4454884032393832);
    // Set group 3 bol bias 03 (VRL) to 0.41136249367186684 Volts
    Pacs_BOLC_SET_VRL_G3(0.41136249367186684);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1679320914489204 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1679320914489204);
    // Set group 4 bol bias 01 (VH) to 2.591852678092942 Volts
    Pacs_BOLC_SET_VH_G4(2.591852678092942);
    // Set group 4 bol bias 02 (VL) to -0.408147321907058 Volts
    Pacs_BOLC_SET_VL_G4(-0.408147321907058);
    // Set group 4 bol bias 03 (VRL) to 0.4158848845694993 Volts
    Pacs_BOLC_SET_VRL_G4(0.4158848845694993);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176235181901646 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176235181901646);
    // Set group 5 bol bias 01 (VH) to 2.231303538712061 Volts
    Pacs_BOLC_SET_VH_G5(2.231303538712061);
    // Set group 5 bol bias 02 (VL) to -0.36869646128793887 Volts
    Pacs_BOLC_SET_VL_G5(-0.36869646128793887);
    // Set group 5 bol bias 03 (VRL) to 0.4261159129370585 Volts
    Pacs_BOLC_SET_VRL_G5(0.4261159129370585);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1842235863263286 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1842235863263286);
    // Set group 6 bol bias 01 (VH) to 2.2493043049150576 Volts
    Pacs_BOLC_SET_VH_G6(2.2493043049150576);
    // Set group 6 bol bias 02 (VL) to -0.3506956950849426 Volts
    Pacs_BOLC_SET_VL_G6(-0.3506956950849426);
    // Set group 6 bol bias 03 (VRL) to 0.4237159708307814 Volts
    Pacs_BOLC_SET_VRL_G6(0.4237159708307814);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.179385794698645 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.179385794698645);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //*******************************
    // Select Filter B (70 microns)
    //*******************************
    //
    PHOT_fltw_move("POS B");
    //
    //**********************************************
    // Set the PAcS chopper at the position -21350
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(-21350);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS0 at 48.0 K
    // corresponding to 0.90pW on the blue and 5.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4721285832931112 Volts
    Pacs_BOLC_SET_VH_G1(1.4721285832931112);
    // Set group 1 bol bias 02 (VL) to -0.12787141670688873 Volts
    Pacs_BOLC_SET_VL_G1(-0.12787141670688873);
    // Set group 1 bol bias 03 (VRL) to 0.3926297476827718 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926297476827718);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151154074587398 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151154074587398);
    // Set group 2 bol bias 01 (VH) to 1.4563242224495716 Volts
    Pacs_BOLC_SET_VH_G2(1.4563242224495716);
    // Set group 2 bol bias 02 (VL) to -0.14367577755042849 Volts
    Pacs_BOLC_SET_VL_G2(-0.14367577755042849);
    // Set group 2 bol bias 03 (VRL) to 0.3881765529411487 Volts
    Pacs_BOLC_SET_VRL_G2(0.3881765529411487);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.145937513130471 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.145937513130471);
    // Set group 3 bol bias 01 (VH) to 1.45972772124239 Volts
    Pacs_BOLC_SET_VH_G3(1.45972772124239);
    // Set group 3 bol bias 02 (VL) to -0.14027227875761006 Volts
    Pacs_BOLC_SET_VL_G3(-0.14027227875761006);
    // Set group 3 bol bias 03 (VRL) to 0.38988919840997094 Volts
    Pacs_BOLC_SET_VRL_G3(0.38988919840997094);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1442125685158864 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1442125685158864);
    // Set group 4 bol bias 01 (VH) to 1.4747276174033868 Volts
    Pacs_BOLC_SET_VH_G4(1.4747276174033868);
    // Set group 4 bol bias 02 (VL) to -0.12527238259661322 Volts
    Pacs_BOLC_SET_VL_G4(-0.12527238259661322);
    // Set group 4 bol bias 03 (VRL) to 0.38624222870786595 Volts
    Pacs_BOLC_SET_VRL_G4(0.38624222870786595);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1423530627314813 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1423530627314813);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3734713392363535 Volts
    Pacs_BOLC_SET_VRL_G5(0.3734713392363535);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1211616404276756 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1211616404276756);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3640870527167945 Volts
    Pacs_BOLC_SET_VRL_G6(0.3640870527167945);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1074512769294307 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1074512769294307);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6005646067625168 Volts
    Pacs_BOLC_SET_VH_G1(1.6005646067625168);
    // Set group 1 bol bias 02 (VL) to -0.19943539323748327 Volts
    Pacs_BOLC_SET_VL_G1(-0.19943539323748327);
    // Set group 1 bol bias 03 (VRL) to 0.3927137250656313 Volts
    Pacs_BOLC_SET_VRL_G1(0.3927137250656313);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1512536862532445 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1512536862532445);
    // Set group 2 bol bias 01 (VH) to 1.5835245401299414 Volts
    Pacs_BOLC_SET_VH_G2(1.5835245401299414);
    // Set group 2 bol bias 02 (VL) to -0.21647545987005867 Volts
    Pacs_BOLC_SET_VL_G2(-0.21647545987005867);
    // Set group 2 bol bias 03 (VRL) to 0.3880497715778095 Volts
    Pacs_BOLC_SET_VRL_G2(0.3880497715778095);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1457903439369534 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1457903439369534);
    // Set group 3 bol bias 01 (VH) to 1.5867464604266623 Volts
    Pacs_BOLC_SET_VH_G3(1.5867464604266623);
    // Set group 3 bol bias 02 (VL) to -0.2132535395733377 Volts
    Pacs_BOLC_SET_VL_G3(-0.2132535395733377);
    // Set group 3 bol bias 03 (VRL) to 0.3903025295231384 Volts
    Pacs_BOLC_SET_VRL_G3(0.3903025295231384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144668449205875 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144668449205875);
    // Set group 4 bol bias 01 (VH) to 1.6044364991789073 Volts
    Pacs_BOLC_SET_VH_G4(1.6044364991789073);
    // Set group 4 bol bias 02 (VL) to -0.19556350082109264 Volts
    Pacs_BOLC_SET_VL_G4(-0.19556350082109264);
    // Set group 4 bol bias 03 (VRL) to 0.387662053519384 Volts
    Pacs_BOLC_SET_VRL_G4(0.387662053519384);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1439743820479262 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1439743820479262);
    // Set group 5 bol bias 01 (VH) to 1.3451907640885556 Volts
    Pacs_BOLC_SET_VH_G5(1.3451907640885556);
    // Set group 5 bol bias 02 (VL) to -0.054809235911444244 Volts
    Pacs_BOLC_SET_VL_G5(-0.054809235911444244);
    // Set group 5 bol bias 03 (VRL) to 0.40021084689056974 Volts
    Pacs_BOLC_SET_VRL_G5(0.40021084689056974);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1532482013507512 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1532482013507512);
    // Set group 6 bol bias 01 (VH) to 1.39 Volts
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.4344512926668127 Volts
    Pacs_BOLC_SET_VRL_G6(0.4344512926668127);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.192323231555507 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.192323231555507);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7330644465100378 Volts
    Pacs_BOLC_SET_VH_G1(1.7330644465100378);
    // Set group 1 bol bias 02 (VL) to -0.26693555348996223 Volts
    Pacs_BOLC_SET_VL_G1(-0.26693555348996223);
    // Set group 1 bol bias 03 (VRL) to 0.3923254235050375 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923254235050375);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1507930978184753 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1507930978184753);
    // Set group 2 bol bias 01 (VH) to 1.714453661934205 Volts
    Pacs_BOLC_SET_VH_G2(1.714453661934205);
    // Set group 2 bol bias 02 (VL) to -0.2855463380657951 Volts
    Pacs_BOLC_SET_VL_G2(-0.2855463380657951);
    // Set group 2 bol bias 03 (VRL) to 0.38771628761093724 Volts
    Pacs_BOLC_SET_VRL_G2(0.38771628761093724);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1454032366160996 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1454032366160996);
    // Set group 3 bol bias 01 (VH) to 1.7283831876482196 Volts
    Pacs_BOLC_SET_VH_G3(1.7283831876482196);
    // Set group 3 bol bias 02 (VL) to -0.2716168123517804 Volts
    Pacs_BOLC_SET_VL_G3(-0.2716168123517804);
    // Set group 3 bol bias 03 (VRL) to 0.40171045250948384 Volts
    Pacs_BOLC_SET_VRL_G3(0.40171045250948384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157256007066197 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157256007066197);
    // Set group 4 bol bias 01 (VH) to 1.7381239240265867 Volts
    Pacs_BOLC_SET_VH_G4(1.7381239240265867);
    // Set group 4 bol bias 02 (VL) to -0.26187607597341334 Volts
    Pacs_BOLC_SET_VL_G4(-0.26187607597341334);
    // Set group 4 bol bias 03 (VRL) to 0.38896138623469356 Volts
    Pacs_BOLC_SET_VRL_G4(0.38896138623469356);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454582711839105 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454582711839105);
    // Set group 5 bol bias 01 (VH) to 1.4703496551390403 Volts
    Pacs_BOLC_SET_VH_G5(1.4703496551390403);
    // Set group 5 bol bias 02 (VL) to -0.12965034486095992 Volts
    Pacs_BOLC_SET_VL_G5(-0.12965034486095992);
    // Set group 5 bol bias 03 (VRL) to 0.39904033450461596 Volts
    Pacs_BOLC_SET_VRL_G5(0.39904033450461596);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151844445053932 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151844445053932);
    // Set group 6 bol bias 01 (VH) to 1.5181165758982518 Volts
    Pacs_BOLC_SET_VH_G6(1.5181165758982518);
    // Set group 6 bol bias 02 (VL) to -0.08188342410174834 Volts
    Pacs_BOLC_SET_VL_G6(-0.08188342410174834);
    // Set group 6 bol bias 03 (VRL) to 0.4343226272779045 Volts
    Pacs_BOLC_SET_VRL_G6(0.4343226272779045);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1921697898825356 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1921697898825356);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8730534488812565 Volts
    Pacs_BOLC_SET_VH_G1(1.8730534488812565);
    // Set group 1 bol bias 02 (VL) to -0.3269465511187437 Volts
    Pacs_BOLC_SET_VL_G1(-0.3269465511187437);
    // Set group 1 bol bias 03 (VRL) to 0.3922166883004623 Volts
    Pacs_BOLC_SET_VRL_G1(0.3922166883004623);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1506641222123926 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1506641222123926);
    // Set group 2 bol bias 01 (VH) to 1.8512060220322217 Volts
    Pacs_BOLC_SET_VH_G2(1.8512060220322217);
    // Set group 2 bol bias 02 (VL) to -0.34879397796777845 Volts
    Pacs_BOLC_SET_VL_G2(-0.34879397796777845);
    // Set group 2 bol bias 03 (VRL) to 0.3869592141320811 Volts
    Pacs_BOLC_SET_VRL_G2(0.3869592141320811);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1445244519836626 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1445244519836626);
    // Set group 3 bol bias 01 (VH) to 1.8654619469621685 Volts
    Pacs_BOLC_SET_VH_G3(1.8654619469621685);
    // Set group 3 bol bias 02 (VL) to -0.33453805303783174 Volts
    Pacs_BOLC_SET_VL_G3(-0.33453805303783174);
    // Set group 3 bol bias 03 (VRL) to 0.40224166318840543 Volts
    Pacs_BOLC_SET_VRL_G3(0.40224166318840543);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1578437499437477 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1578437499437477);
    // Set group 4 bol bias 01 (VH) to 1.8790483325189686 Volts
    Pacs_BOLC_SET_VH_G4(1.8790483325189686);
    // Set group 4 bol bias 02 (VL) to -0.32095166748103154 Volts
    Pacs_BOLC_SET_VL_G4(-0.32095166748103154);
    // Set group 4 bol bias 03 (VRL) to 0.39052544771082365 Volts
    Pacs_BOLC_SET_VRL_G4(0.39052544771082365);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1472446958154223 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1472446958154223);
    // Set group 5 bol bias 01 (VH) to 1.5997463742933684 Volts
    Pacs_BOLC_SET_VH_G5(1.5997463742933684);
    // Set group 5 bol bias 02 (VL) to -0.2002536257066316 Volts
    Pacs_BOLC_SET_VL_G5(-0.2002536257066316);
    // Set group 5 bol bias 03 (VRL) to 0.3972802806465645 Volts
    Pacs_BOLC_SET_VRL_G5(0.3972802806465645);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1497335299275955 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1497335299275955);
    // Set group 6 bol bias 01 (VH) to 1.64826517003746 Volts
    Pacs_BOLC_SET_VH_G6(1.64826517003746);
    // Set group 6 bol bias 02 (VL) to -0.1517348299625401 Volts
    Pacs_BOLC_SET_VL_G6(-0.1517348299625401);
    // Set group 6 bol bias 03 (VRL) to 0.43238698345346915 Volts
    Pacs_BOLC_SET_VRL_G6(0.43238698345346915);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.189850849172478 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.189850849172478);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.034145377320728 Volts
    Pacs_BOLC_SET_VH_G1(2.034145377320728);
    // Set group 1 bol bias 02 (VL) to -0.36585462267927166 Volts
    Pacs_BOLC_SET_VL_G1(-0.36585462267927166);
    // Set group 1 bol bias 03 (VRL) to 0.4026842358176688 Volts
    Pacs_BOLC_SET_VRL_G1(0.4026842358176688);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163077213168135 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163077213168135);
    // Set group 2 bol bias 01 (VH) to 1.9964246373780308 Volts
    Pacs_BOLC_SET_VH_G2(1.9964246373780308);
    // Set group 2 bol bias 02 (VL) to -0.40357536262196914 Volts
    Pacs_BOLC_SET_VL_G2(-0.40357536262196914);
    // Set group 2 bol bias 03 (VRL) to 0.38543545754038677 Volts
    Pacs_BOLC_SET_VRL_G2(0.38543545754038677);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1427558304354366 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1427558304354366);
    // Set group 3 bol bias 01 (VH) to 2.0225756539924595 Volts
    Pacs_BOLC_SET_VH_G3(2.0225756539924595);
    // Set group 3 bol bias 02 (VL) to -0.37742434600754043 Volts
    Pacs_BOLC_SET_VL_G3(-0.37742434600754043);
    // Set group 3 bol bias 03 (VRL) to 0.41362905220735763 Volts
    Pacs_BOLC_SET_VRL_G3(0.41362905220735763);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704381594190805 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704381594190805);
    // Set group 4 bol bias 01 (VH) to 2.0286801589025623 Volts
    Pacs_BOLC_SET_VH_G4(2.0286801589025623);
    // Set group 4 bol bias 02 (VL) to -0.37131984109743765 Volts
    Pacs_BOLC_SET_VL_G4(-0.37131984109743765);
    // Set group 4 bol bias 03 (VRL) to 0.39131683434261844 Volts
    Pacs_BOLC_SET_VRL_G4(0.39131683434261844);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.14814867942076 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.14814867942076);
    // Set group 5 bol bias 01 (VH) to 1.7436864671540049 Volts
    Pacs_BOLC_SET_VH_G5(1.7436864671540049);
    // Set group 5 bol bias 02 (VL) to -0.2563135328459952 Volts
    Pacs_BOLC_SET_VL_G5(-0.2563135328459952);
    // Set group 5 bol bias 03 (VRL) to 0.4060804936984878 Volts
    Pacs_BOLC_SET_VRL_G5(0.4060804936984878);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1602616898977316 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1602616898977316);
    // Set group 6 bol bias 01 (VH) to 1.7834132365202005 Volts
    Pacs_BOLC_SET_VH_G6(1.7834132365202005);
    // Set group 6 bol bias 02 (VL) to -0.21658676347979958 Volts
    Pacs_BOLC_SET_VL_G6(-0.21658676347979958);
    // Set group 6 bol bias 03 (VRL) to 0.43021242094743417 Volts
    Pacs_BOLC_SET_VRL_G6(0.43021242094743417);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1872266025341247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1872266025341247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.209416047586087 Volts
    Pacs_BOLC_SET_VH_G1(2.209416047586087);
    // Set group 1 bol bias 02 (VL) to -0.3905839524139128 Volts
    Pacs_BOLC_SET_VL_G1(-0.3905839524139128);
    // Set group 1 bol bias 03 (VRL) to 0.4134679213904496 Volts
    Pacs_BOLC_SET_VRL_G1(0.4134679213904496);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758418687268812 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758418687268812);
    // Set group 2 bol bias 01 (VH) to 2.1541915675147214 Volts
    Pacs_BOLC_SET_VH_G2(2.1541915675147214);
    // Set group 2 bol bias 02 (VL) to -0.44580843248527846 Volts
    Pacs_BOLC_SET_VL_G2(-0.44580843248527846);
    // Set group 2 bol bias 03 (VRL) to 0.38424319746039115 Volts
    Pacs_BOLC_SET_VRL_G2(0.38424319746039115);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1413720715536493 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1413720715536493);
    // Set group 3 bol bias 01 (VH) to 2.1813068162319285 Volts
    Pacs_BOLC_SET_VH_G3(2.1813068162319285);
    // Set group 3 bol bias 02 (VL) to -0.4186931837680716 Volts
    Pacs_BOLC_SET_VL_G3(-0.4186931837680716);
    // Set group 3 bol bias 03 (VRL) to 0.41360319513591143 Volts
    Pacs_BOLC_SET_VRL_G3(0.41360319513591143);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704095720713417 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704095720713417);
    // Set group 4 bol bias 01 (VH) to 2.202944386753124 Volts
    Pacs_BOLC_SET_VH_G4(2.202944386753124);
    // Set group 4 bol bias 02 (VL) to -0.3970556132468757 Volts
    Pacs_BOLC_SET_VL_G4(-0.3970556132468757);
    // Set group 4 bol bias 03 (VRL) to 0.40381007074137704 Volts
    Pacs_BOLC_SET_VRL_G4(0.40381007074137704);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1624292794462514 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1624292794462514);
    // Set group 5 bol bias 01 (VH) to 1.883738472848583 Volts
    Pacs_BOLC_SET_VH_G5(1.883738472848583);
    // Set group 5 bol bias 02 (VL) to -0.31626152715141714 Volts
    Pacs_BOLC_SET_VL_G5(-0.31626152715141714);
    // Set group 5 bol bias 03 (VRL) to 0.4028494691164935 Volts
    Pacs_BOLC_SET_VRL_G5(0.4028494691164935);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.156400882301432 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.156400882301432);
    // Set group 6 bol bias 01 (VH) to 1.9235912310846244 Volts
    Pacs_BOLC_SET_VH_G6(1.9235912310846244);
    // Set group 6 bol bias 02 (VL) to -0.2764087689153759 Volts
    Pacs_BOLC_SET_VL_G6(-0.2764087689153759);
    // Set group 6 bol bias 03 (VRL) to 0.4280070912945936 Volts
    Pacs_BOLC_SET_VRL_G6(0.4280070912945936);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1845650655206446 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1845650655206446);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3806926938420414 Volts
    Pacs_BOLC_SET_VH_G1(2.3806926938420414);
    // Set group 1 bol bias 02 (VL) to -0.41930730615795847 Volts
    Pacs_BOLC_SET_VL_G1(-0.41930730615795847);
    // Set group 1 bol bias 03 (VRL) to 0.4020155079485436 Volts
    Pacs_BOLC_SET_VRL_G1(0.4020155079485436);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162285695776181 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162285695776181);
    // Set group 2 bol bias 01 (VH) to 2.3371282046100963 Volts
    Pacs_BOLC_SET_VH_G2(2.3371282046100963);
    // Set group 2 bol bias 02 (VL) to -0.46287179538990364 Volts
    Pacs_BOLC_SET_VL_G2(-0.46287179538990364);
    // Set group 2 bol bias 03 (VRL) to 0.3923402298587034 Volts
    Pacs_BOLC_SET_VRL_G2(0.3923402298587034);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1507712805161225 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1507712805161225);
    // Set group 3 bol bias 01 (VH) to 2.356604953923699 Volts
    Pacs_BOLC_SET_VH_G3(2.356604953923699);
    // Set group 3 bol bias 02 (VL) to -0.44339504607630065 Volts
    Pacs_BOLC_SET_VL_G3(-0.44339504607630065);
    // Set group 3 bol bias 03 (VRL) to 0.4124662568673877 Volts
    Pacs_BOLC_SET_VRL_G3(0.4124662568673877);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.169152536126319 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.169152536126319);
    // Set group 4 bol bias 01 (VH) to 2.3825039100730487 Volts
    Pacs_BOLC_SET_VH_G4(2.3825039100730487);
    // Set group 4 bol bias 02 (VL) to -0.4174960899269509 Volts
    Pacs_BOLC_SET_VL_G4(-0.4174960899269509);
    // Set group 4 bol bias 03 (VRL) to 0.40493410269973024 Volts
    Pacs_BOLC_SET_VRL_G4(0.40493410269973024);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1637149679245193 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1637149679245193);
    // Set group 5 bol bias 01 (VH) to 2.0340896725156363 Volts
    Pacs_BOLC_SET_VH_G5(2.0340896725156363);
    // Set group 5 bol bias 02 (VL) to -0.3659103274843634 Volts
    Pacs_BOLC_SET_VL_G5(-0.3659103274843634);
    // Set group 5 bol bias 03 (VRL) to 0.3987896988621052 Volts
    Pacs_BOLC_SET_VRL_G5(0.3987896988621052);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1515438563527702 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1515438563527702);
    // Set group 6 bol bias 01 (VH) to 2.080247845760918 Volts
    Pacs_BOLC_SET_VH_G6(2.080247845760918);
    // Set group 6 bol bias 02 (VL) to -0.31975215423908154 Volts
    Pacs_BOLC_SET_VL_G6(-0.31975215423908154);
    // Set group 6 bol bias 03 (VRL) to 0.42577779561759777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42577779561759777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1818744401374954 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1818744401374954);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6181566702818313 Volts
    Pacs_BOLC_SET_VH_G1(2.6181566702818313);
    // Set group 1 bol bias 02 (VL) to -0.38184332971816887 Volts
    Pacs_BOLC_SET_VL_G1(-0.38184332971816887);
    // Set group 1 bol bias 03 (VRL) to 0.43545225816479755 Volts
    Pacs_BOLC_SET_VRL_G1(0.43545225816479755);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2018572484354544 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2018572484354544);
    // Set group 2 bol bias 01 (VH) to 2.5300933623498008 Volts
    Pacs_BOLC_SET_VH_G2(2.5300933623498008);
    // Set group 2 bol bias 02 (VL) to -0.469906637650199 Volts
    Pacs_BOLC_SET_VL_G2(-0.469906637650199);
    // Set group 2 bol bias 03 (VRL) to 0.3917176926734228 Volts
    Pacs_BOLC_SET_VRL_G2(0.3917176926734228);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1500484890692286 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1500484890692286);
    // Set group 3 bol bias 01 (VH) to 2.5545115967606167 Volts
    Pacs_BOLC_SET_VH_G3(2.5545115967606167);
    // Set group 3 bol bias 02 (VL) to -0.4454884032393832 Volts
    Pacs_BOLC_SET_VL_G3(-0.4454884032393832);
    // Set group 3 bol bias 03 (VRL) to 0.41136249367186684 Volts
    Pacs_BOLC_SET_VRL_G3(0.41136249367186684);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1679320914489204 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1679320914489204);
    // Set group 4 bol bias 01 (VH) to 2.591852678092942 Volts
    Pacs_BOLC_SET_VH_G4(2.591852678092942);
    // Set group 4 bol bias 02 (VL) to -0.408147321907058 Volts
    Pacs_BOLC_SET_VL_G4(-0.408147321907058);
    // Set group 4 bol bias 03 (VRL) to 0.4158848845694993 Volts
    Pacs_BOLC_SET_VRL_G4(0.4158848845694993);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176235181901646 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176235181901646);
    // Set group 5 bol bias 01 (VH) to 2.231303538712061 Volts
    Pacs_BOLC_SET_VH_G5(2.231303538712061);
    // Set group 5 bol bias 02 (VL) to -0.36869646128793887 Volts
    Pacs_BOLC_SET_VL_G5(-0.36869646128793887);
    // Set group 5 bol bias 03 (VRL) to 0.4261159129370585 Volts
    Pacs_BOLC_SET_VRL_G5(0.4261159129370585);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1842235863263286 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1842235863263286);
    // Set group 6 bol bias 01 (VH) to 2.2493043049150576 Volts
    Pacs_BOLC_SET_VH_G6(2.2493043049150576);
    // Set group 6 bol bias 02 (VL) to -0.3506956950849426 Volts
    Pacs_BOLC_SET_VL_G6(-0.3506956950849426);
    // Set group 6 bol bias 03 (VRL) to 0.4237159708307814 Volts
    Pacs_BOLC_SET_VRL_G6(0.4237159708307814);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.179385794698645 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.179385794698645);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //**********************************************
    // Set the PAcS chopper at the position 21200
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(21200);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS1 at 58.0 K
    // corresponding to 1.25pW on the blue and 6.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4721285832931112 Volts
    Pacs_BOLC_SET_VH_G1(1.4721285832931112);
    // Set group 1 bol bias 02 (VL) to -0.12787141670688873 Volts
    Pacs_BOLC_SET_VL_G1(-0.12787141670688873);
    // Set group 1 bol bias 03 (VRL) to 0.3926297476827718 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926297476827718);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151154074587398 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151154074587398);
    // Set group 2 bol bias 01 (VH) to 1.4563242224495716 Volts
    Pacs_BOLC_SET_VH_G2(1.4563242224495716);
    // Set group 2 bol bias 02 (VL) to -0.14367577755042849 Volts
    Pacs_BOLC_SET_VL_G2(-0.14367577755042849);
    // Set group 2 bol bias 03 (VRL) to 0.3881765529411487 Volts
    Pacs_BOLC_SET_VRL_G2(0.3881765529411487);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.145937513130471 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.145937513130471);
    // Set group 3 bol bias 01 (VH) to 1.45972772124239 Volts
    Pacs_BOLC_SET_VH_G3(1.45972772124239);
    // Set group 3 bol bias 02 (VL) to -0.14027227875761006 Volts
    Pacs_BOLC_SET_VL_G3(-0.14027227875761006);
    // Set group 3 bol bias 03 (VRL) to 0.38988919840997094 Volts
    Pacs_BOLC_SET_VRL_G3(0.38988919840997094);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1442125685158864 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1442125685158864);
    // Set group 4 bol bias 01 (VH) to 1.4747276174033868 Volts
    Pacs_BOLC_SET_VH_G4(1.4747276174033868);
    // Set group 4 bol bias 02 (VL) to -0.12527238259661322 Volts
    Pacs_BOLC_SET_VL_G4(-0.12527238259661322);
    // Set group 4 bol bias 03 (VRL) to 0.38624222870786595 Volts
    Pacs_BOLC_SET_VRL_G4(0.38624222870786595);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1423530627314813 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1423530627314813);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3734713392363535 Volts
    Pacs_BOLC_SET_VRL_G5(0.3734713392363535);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1211616404276756 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1211616404276756);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3640870527167945 Volts
    Pacs_BOLC_SET_VRL_G6(0.3640870527167945);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1074512769294307 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1074512769294307);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6005646067625168 Volts
    Pacs_BOLC_SET_VH_G1(1.6005646067625168);
    // Set group 1 bol bias 02 (VL) to -0.19943539323748327 Volts
    Pacs_BOLC_SET_VL_G1(-0.19943539323748327);
    // Set group 1 bol bias 03 (VRL) to 0.3927137250656313 Volts
    Pacs_BOLC_SET_VRL_G1(0.3927137250656313);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1512536862532445 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1512536862532445);
    // Set group 2 bol bias 01 (VH) to 1.5835245401299414 Volts
    Pacs_BOLC_SET_VH_G2(1.5835245401299414);
    // Set group 2 bol bias 02 (VL) to -0.21647545987005867 Volts
    Pacs_BOLC_SET_VL_G2(-0.21647545987005867);
    // Set group 2 bol bias 03 (VRL) to 0.3880497715778095 Volts
    Pacs_BOLC_SET_VRL_G2(0.3880497715778095);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1457903439369534 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1457903439369534);
    // Set group 3 bol bias 01 (VH) to 1.5867464604266623 Volts
    Pacs_BOLC_SET_VH_G3(1.5867464604266623);
    // Set group 3 bol bias 02 (VL) to -0.2132535395733377 Volts
    Pacs_BOLC_SET_VL_G3(-0.2132535395733377);
    // Set group 3 bol bias 03 (VRL) to 0.3903025295231384 Volts
    Pacs_BOLC_SET_VRL_G3(0.3903025295231384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144668449205875 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144668449205875);
    // Set group 4 bol bias 01 (VH) to 1.6044364991789073 Volts
    Pacs_BOLC_SET_VH_G4(1.6044364991789073);
    // Set group 4 bol bias 02 (VL) to -0.19556350082109264 Volts
    Pacs_BOLC_SET_VL_G4(-0.19556350082109264);
    // Set group 4 bol bias 03 (VRL) to 0.387662053519384 Volts
    Pacs_BOLC_SET_VRL_G4(0.387662053519384);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1439743820479262 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1439743820479262);
    // Set group 5 bol bias 01 (VH) to 1.3451907640885556 Volts
    Pacs_BOLC_SET_VH_G5(1.3451907640885556);
    // Set group 5 bol bias 02 (VL) to -0.054809235911444244 Volts
    Pacs_BOLC_SET_VL_G5(-0.054809235911444244);
    // Set group 5 bol bias 03 (VRL) to 0.40021084689056974 Volts
    Pacs_BOLC_SET_VRL_G5(0.40021084689056974);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1532482013507512 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1532482013507512);
    // Set group 6 bol bias 01 (VH) to 1.39 Volts
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.4344512926668127 Volts
    Pacs_BOLC_SET_VRL_G6(0.4344512926668127);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.192323231555507 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.192323231555507);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7330644465100378 Volts
    Pacs_BOLC_SET_VH_G1(1.7330644465100378);
    // Set group 1 bol bias 02 (VL) to -0.26693555348996223 Volts
    Pacs_BOLC_SET_VL_G1(-0.26693555348996223);
    // Set group 1 bol bias 03 (VRL) to 0.3923254235050375 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923254235050375);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1507930978184753 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1507930978184753);
    // Set group 2 bol bias 01 (VH) to 1.714453661934205 Volts
    Pacs_BOLC_SET_VH_G2(1.714453661934205);
    // Set group 2 bol bias 02 (VL) to -0.2855463380657951 Volts
    Pacs_BOLC_SET_VL_G2(-0.2855463380657951);
    // Set group 2 bol bias 03 (VRL) to 0.38771628761093724 Volts
    Pacs_BOLC_SET_VRL_G2(0.38771628761093724);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1454032366160996 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1454032366160996);
    // Set group 3 bol bias 01 (VH) to 1.7283831876482196 Volts
    Pacs_BOLC_SET_VH_G3(1.7283831876482196);
    // Set group 3 bol bias 02 (VL) to -0.2716168123517804 Volts
    Pacs_BOLC_SET_VL_G3(-0.2716168123517804);
    // Set group 3 bol bias 03 (VRL) to 0.40171045250948384 Volts
    Pacs_BOLC_SET_VRL_G3(0.40171045250948384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157256007066197 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157256007066197);
    // Set group 4 bol bias 01 (VH) to 1.7381239240265867 Volts
    Pacs_BOLC_SET_VH_G4(1.7381239240265867);
    // Set group 4 bol bias 02 (VL) to -0.26187607597341334 Volts
    Pacs_BOLC_SET_VL_G4(-0.26187607597341334);
    // Set group 4 bol bias 03 (VRL) to 0.38896138623469356 Volts
    Pacs_BOLC_SET_VRL_G4(0.38896138623469356);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454582711839105 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454582711839105);
    // Set group 5 bol bias 01 (VH) to 1.4703496551390403 Volts
    Pacs_BOLC_SET_VH_G5(1.4703496551390403);
    // Set group 5 bol bias 02 (VL) to -0.12965034486095992 Volts
    Pacs_BOLC_SET_VL_G5(-0.12965034486095992);
    // Set group 5 bol bias 03 (VRL) to 0.39904033450461596 Volts
    Pacs_BOLC_SET_VRL_G5(0.39904033450461596);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151844445053932 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151844445053932);
    // Set group 6 bol bias 01 (VH) to 1.5181165758982518 Volts
    Pacs_BOLC_SET_VH_G6(1.5181165758982518);
    // Set group 6 bol bias 02 (VL) to -0.08188342410174834 Volts
    Pacs_BOLC_SET_VL_G6(-0.08188342410174834);
    // Set group 6 bol bias 03 (VRL) to 0.4343226272779045 Volts
    Pacs_BOLC_SET_VRL_G6(0.4343226272779045);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1921697898825356 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1921697898825356);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8730534488812565 Volts
    Pacs_BOLC_SET_VH_G1(1.8730534488812565);
    // Set group 1 bol bias 02 (VL) to -0.3269465511187437 Volts
    Pacs_BOLC_SET_VL_G1(-0.3269465511187437);
    // Set group 1 bol bias 03 (VRL) to 0.3922166883004623 Volts
    Pacs_BOLC_SET_VRL_G1(0.3922166883004623);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1506641222123926 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1506641222123926);
    // Set group 2 bol bias 01 (VH) to 1.8512060220322217 Volts
    Pacs_BOLC_SET_VH_G2(1.8512060220322217);
    // Set group 2 bol bias 02 (VL) to -0.34879397796777845 Volts
    Pacs_BOLC_SET_VL_G2(-0.34879397796777845);
    // Set group 2 bol bias 03 (VRL) to 0.3869592141320811 Volts
    Pacs_BOLC_SET_VRL_G2(0.3869592141320811);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1445244519836626 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1445244519836626);
    // Set group 3 bol bias 01 (VH) to 1.8654619469621685 Volts
    Pacs_BOLC_SET_VH_G3(1.8654619469621685);
    // Set group 3 bol bias 02 (VL) to -0.33453805303783174 Volts
    Pacs_BOLC_SET_VL_G3(-0.33453805303783174);
    // Set group 3 bol bias 03 (VRL) to 0.40224166318840543 Volts
    Pacs_BOLC_SET_VRL_G3(0.40224166318840543);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1578437499437477 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1578437499437477);
    // Set group 4 bol bias 01 (VH) to 1.8790483325189686 Volts
    Pacs_BOLC_SET_VH_G4(1.8790483325189686);
    // Set group 4 bol bias 02 (VL) to -0.32095166748103154 Volts
    Pacs_BOLC_SET_VL_G4(-0.32095166748103154);
    // Set group 4 bol bias 03 (VRL) to 0.39052544771082365 Volts
    Pacs_BOLC_SET_VRL_G4(0.39052544771082365);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1472446958154223 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1472446958154223);
    // Set group 5 bol bias 01 (VH) to 1.5997463742933684 Volts
    Pacs_BOLC_SET_VH_G5(1.5997463742933684);
    // Set group 5 bol bias 02 (VL) to -0.2002536257066316 Volts
    Pacs_BOLC_SET_VL_G5(-0.2002536257066316);
    // Set group 5 bol bias 03 (VRL) to 0.3972802806465645 Volts
    Pacs_BOLC_SET_VRL_G5(0.3972802806465645);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1497335299275955 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1497335299275955);
    // Set group 6 bol bias 01 (VH) to 1.64826517003746 Volts
    Pacs_BOLC_SET_VH_G6(1.64826517003746);
    // Set group 6 bol bias 02 (VL) to -0.1517348299625401 Volts
    Pacs_BOLC_SET_VL_G6(-0.1517348299625401);
    // Set group 6 bol bias 03 (VRL) to 0.43238698345346915 Volts
    Pacs_BOLC_SET_VRL_G6(0.43238698345346915);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.189850849172478 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.189850849172478);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.034145377320728 Volts
    Pacs_BOLC_SET_VH_G1(2.034145377320728);
    // Set group 1 bol bias 02 (VL) to -0.36585462267927166 Volts
    Pacs_BOLC_SET_VL_G1(-0.36585462267927166);
    // Set group 1 bol bias 03 (VRL) to 0.4026842358176688 Volts
    Pacs_BOLC_SET_VRL_G1(0.4026842358176688);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163077213168135 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163077213168135);
    // Set group 2 bol bias 01 (VH) to 1.9964246373780308 Volts
    Pacs_BOLC_SET_VH_G2(1.9964246373780308);
    // Set group 2 bol bias 02 (VL) to -0.40357536262196914 Volts
    Pacs_BOLC_SET_VL_G2(-0.40357536262196914);
    // Set group 2 bol bias 03 (VRL) to 0.38543545754038677 Volts
    Pacs_BOLC_SET_VRL_G2(0.38543545754038677);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1427558304354366 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1427558304354366);
    // Set group 3 bol bias 01 (VH) to 2.0225756539924595 Volts
    Pacs_BOLC_SET_VH_G3(2.0225756539924595);
    // Set group 3 bol bias 02 (VL) to -0.37742434600754043 Volts
    Pacs_BOLC_SET_VL_G3(-0.37742434600754043);
    // Set group 3 bol bias 03 (VRL) to 0.41362905220735763 Volts
    Pacs_BOLC_SET_VRL_G3(0.41362905220735763);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704381594190805 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704381594190805);
    // Set group 4 bol bias 01 (VH) to 2.0286801589025623 Volts
    Pacs_BOLC_SET_VH_G4(2.0286801589025623);
    // Set group 4 bol bias 02 (VL) to -0.37131984109743765 Volts
    Pacs_BOLC_SET_VL_G4(-0.37131984109743765);
    // Set group 4 bol bias 03 (VRL) to 0.39131683434261844 Volts
    Pacs_BOLC_SET_VRL_G4(0.39131683434261844);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.14814867942076 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.14814867942076);
    // Set group 5 bol bias 01 (VH) to 1.7436864671540049 Volts
    Pacs_BOLC_SET_VH_G5(1.7436864671540049);
    // Set group 5 bol bias 02 (VL) to -0.2563135328459952 Volts
    Pacs_BOLC_SET_VL_G5(-0.2563135328459952);
    // Set group 5 bol bias 03 (VRL) to 0.4060804936984878 Volts
    Pacs_BOLC_SET_VRL_G5(0.4060804936984878);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1602616898977316 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1602616898977316);
    // Set group 6 bol bias 01 (VH) to 1.7834132365202005 Volts
    Pacs_BOLC_SET_VH_G6(1.7834132365202005);
    // Set group 6 bol bias 02 (VL) to -0.21658676347979958 Volts
    Pacs_BOLC_SET_VL_G6(-0.21658676347979958);
    // Set group 6 bol bias 03 (VRL) to 0.43021242094743417 Volts
    Pacs_BOLC_SET_VRL_G6(0.43021242094743417);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1872266025341247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1872266025341247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.209416047586087 Volts
    Pacs_BOLC_SET_VH_G1(2.209416047586087);
    // Set group 1 bol bias 02 (VL) to -0.3905839524139128 Volts
    Pacs_BOLC_SET_VL_G1(-0.3905839524139128);
    // Set group 1 bol bias 03 (VRL) to 0.4134679213904496 Volts
    Pacs_BOLC_SET_VRL_G1(0.4134679213904496);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758418687268812 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758418687268812);
    // Set group 2 bol bias 01 (VH) to 2.1541915675147214 Volts
    Pacs_BOLC_SET_VH_G2(2.1541915675147214);
    // Set group 2 bol bias 02 (VL) to -0.44580843248527846 Volts
    Pacs_BOLC_SET_VL_G2(-0.44580843248527846);
    // Set group 2 bol bias 03 (VRL) to 0.38424319746039115 Volts
    Pacs_BOLC_SET_VRL_G2(0.38424319746039115);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1413720715536493 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1413720715536493);
    // Set group 3 bol bias 01 (VH) to 2.1813068162319285 Volts
    Pacs_BOLC_SET_VH_G3(2.1813068162319285);
    // Set group 3 bol bias 02 (VL) to -0.4186931837680716 Volts
    Pacs_BOLC_SET_VL_G3(-0.4186931837680716);
    // Set group 3 bol bias 03 (VRL) to 0.41360319513591143 Volts
    Pacs_BOLC_SET_VRL_G3(0.41360319513591143);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704095720713417 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704095720713417);
    // Set group 4 bol bias 01 (VH) to 2.202944386753124 Volts
    Pacs_BOLC_SET_VH_G4(2.202944386753124);
    // Set group 4 bol bias 02 (VL) to -0.3970556132468757 Volts
    Pacs_BOLC_SET_VL_G4(-0.3970556132468757);
    // Set group 4 bol bias 03 (VRL) to 0.40381007074137704 Volts
    Pacs_BOLC_SET_VRL_G4(0.40381007074137704);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1624292794462514 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1624292794462514);
    // Set group 5 bol bias 01 (VH) to 1.883738472848583 Volts
    Pacs_BOLC_SET_VH_G5(1.883738472848583);
    // Set group 5 bol bias 02 (VL) to -0.31626152715141714 Volts
    Pacs_BOLC_SET_VL_G5(-0.31626152715141714);
    // Set group 5 bol bias 03 (VRL) to 0.4028494691164935 Volts
    Pacs_BOLC_SET_VRL_G5(0.4028494691164935);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.156400882301432 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.156400882301432);
    // Set group 6 bol bias 01 (VH) to 1.9235912310846244 Volts
    Pacs_BOLC_SET_VH_G6(1.9235912310846244);
    // Set group 6 bol bias 02 (VL) to -0.2764087689153759 Volts
    Pacs_BOLC_SET_VL_G6(-0.2764087689153759);
    // Set group 6 bol bias 03 (VRL) to 0.4280070912945936 Volts
    Pacs_BOLC_SET_VRL_G6(0.4280070912945936);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1845650655206446 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1845650655206446);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3806926938420414 Volts
    Pacs_BOLC_SET_VH_G1(2.3806926938420414);
    // Set group 1 bol bias 02 (VL) to -0.41930730615795847 Volts
    Pacs_BOLC_SET_VL_G1(-0.41930730615795847);
    // Set group 1 bol bias 03 (VRL) to 0.4020155079485436 Volts
    Pacs_BOLC_SET_VRL_G1(0.4020155079485436);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162285695776181 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162285695776181);
    // Set group 2 bol bias 01 (VH) to 2.3371282046100963 Volts
    Pacs_BOLC_SET_VH_G2(2.3371282046100963);
    // Set group 2 bol bias 02 (VL) to -0.46287179538990364 Volts
    Pacs_BOLC_SET_VL_G2(-0.46287179538990364);
    // Set group 2 bol bias 03 (VRL) to 0.3923402298587034 Volts
    Pacs_BOLC_SET_VRL_G2(0.3923402298587034);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1507712805161225 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1507712805161225);
    // Set group 3 bol bias 01 (VH) to 2.356604953923699 Volts
    Pacs_BOLC_SET_VH_G3(2.356604953923699);
    // Set group 3 bol bias 02 (VL) to -0.44339504607630065 Volts
    Pacs_BOLC_SET_VL_G3(-0.44339504607630065);
    // Set group 3 bol bias 03 (VRL) to 0.4124662568673877 Volts
    Pacs_BOLC_SET_VRL_G3(0.4124662568673877);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.169152536126319 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.169152536126319);
    // Set group 4 bol bias 01 (VH) to 2.3825039100730487 Volts
    Pacs_BOLC_SET_VH_G4(2.3825039100730487);
    // Set group 4 bol bias 02 (VL) to -0.4174960899269509 Volts
    Pacs_BOLC_SET_VL_G4(-0.4174960899269509);
    // Set group 4 bol bias 03 (VRL) to 0.40493410269973024 Volts
    Pacs_BOLC_SET_VRL_G4(0.40493410269973024);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1637149679245193 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1637149679245193);
    // Set group 5 bol bias 01 (VH) to 2.0340896725156363 Volts
    Pacs_BOLC_SET_VH_G5(2.0340896725156363);
    // Set group 5 bol bias 02 (VL) to -0.3659103274843634 Volts
    Pacs_BOLC_SET_VL_G5(-0.3659103274843634);
    // Set group 5 bol bias 03 (VRL) to 0.3987896988621052 Volts
    Pacs_BOLC_SET_VRL_G5(0.3987896988621052);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1515438563527702 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1515438563527702);
    // Set group 6 bol bias 01 (VH) to 2.080247845760918 Volts
    Pacs_BOLC_SET_VH_G6(2.080247845760918);
    // Set group 6 bol bias 02 (VL) to -0.31975215423908154 Volts
    Pacs_BOLC_SET_VL_G6(-0.31975215423908154);
    // Set group 6 bol bias 03 (VRL) to 0.42577779561759777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42577779561759777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1818744401374954 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1818744401374954);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6181566702818313 Volts
    Pacs_BOLC_SET_VH_G1(2.6181566702818313);
    // Set group 1 bol bias 02 (VL) to -0.38184332971816887 Volts
    Pacs_BOLC_SET_VL_G1(-0.38184332971816887);
    // Set group 1 bol bias 03 (VRL) to 0.43545225816479755 Volts
    Pacs_BOLC_SET_VRL_G1(0.43545225816479755);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2018572484354544 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2018572484354544);
    // Set group 2 bol bias 01 (VH) to 2.5300933623498008 Volts
    Pacs_BOLC_SET_VH_G2(2.5300933623498008);
    // Set group 2 bol bias 02 (VL) to -0.469906637650199 Volts
    Pacs_BOLC_SET_VL_G2(-0.469906637650199);
    // Set group 2 bol bias 03 (VRL) to 0.3917176926734228 Volts
    Pacs_BOLC_SET_VRL_G2(0.3917176926734228);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1500484890692286 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1500484890692286);
    // Set group 3 bol bias 01 (VH) to 2.5545115967606167 Volts
    Pacs_BOLC_SET_VH_G3(2.5545115967606167);
    // Set group 3 bol bias 02 (VL) to -0.4454884032393832 Volts
    Pacs_BOLC_SET_VL_G3(-0.4454884032393832);
    // Set group 3 bol bias 03 (VRL) to 0.41136249367186684 Volts
    Pacs_BOLC_SET_VRL_G3(0.41136249367186684);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1679320914489204 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1679320914489204);
    // Set group 4 bol bias 01 (VH) to 2.591852678092942 Volts
    Pacs_BOLC_SET_VH_G4(2.591852678092942);
    // Set group 4 bol bias 02 (VL) to -0.408147321907058 Volts
    Pacs_BOLC_SET_VL_G4(-0.408147321907058);
    // Set group 4 bol bias 03 (VRL) to 0.4158848845694993 Volts
    Pacs_BOLC_SET_VRL_G4(0.4158848845694993);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176235181901646 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176235181901646);
    // Set group 5 bol bias 01 (VH) to 2.231303538712061 Volts
    Pacs_BOLC_SET_VH_G5(2.231303538712061);
    // Set group 5 bol bias 02 (VL) to -0.36869646128793887 Volts
    Pacs_BOLC_SET_VL_G5(-0.36869646128793887);
    // Set group 5 bol bias 03 (VRL) to 0.4261159129370585 Volts
    Pacs_BOLC_SET_VRL_G5(0.4261159129370585);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1842235863263286 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1842235863263286);
    // Set group 6 bol bias 01 (VH) to 2.2493043049150576 Volts
    Pacs_BOLC_SET_VH_G6(2.2493043049150576);
    // Set group 6 bol bias 02 (VL) to -0.3506956950849426 Volts
    Pacs_BOLC_SET_VL_G6(-0.3506956950849426);
    // Set group 6 bol bias 03 (VRL) to 0.4237159708307814 Volts
    Pacs_BOLC_SET_VRL_G6(0.4237159708307814);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.179385794698645 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.179385794698645);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //********************************
    // Epilogue : Set the safe biases
    //********************************
    PHOT_set_bias_volt(endBiasTable,1);
    PHOT_set_bias_volt(endBiasTable,2);
    PHOT_set_bias_volt(endBiasTable,3);
    PHOT_set_bias_volt(endBiasTable,4);
    PHOT_set_bias_volt(endBiasTable,5);
    PHOT_set_bias_volt(endBiasTable,6);
    //
    // sync the bus
    sync();
}

// Script        : PacsEng_Chopper_AutoOptPlateau.txt
// Missionphase  : Commissioning
//
// Purpose	: Check a series of different chopper controller settings.
//                  
// Author	: Markus Nielbock
// CUS author 	: MN
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called.
//                  
// Dependencies : 
//
// Preconditions: PACS switched on and Chopper switched off.
//                 
// Comments	: This script is based on the commanding script
//                PACS_Chopper_uk_move_12000_OBS.cus and
//                PACS_Chopper_AutoOpt_OBS.cus
//
// Version	: 1.0
// 
// History 	: 1.0 09-Jun-2009 (MN) Script to do simple chopper cycle 
//
// Initialise input parameters:
// Defines control parameter range, loops run from k(p,i,c,f)min to
// k(p,i,c,f)max defining the inverse of the ratio of parameter change w.r.t.
// the default value.
obs PacsEng_Chopper_AutoOptPlateau {
    int chop_pos = 12000 in [0,21000]; // Chopper position in raw units
    int cycle = 10 in [1,20]; // Number of on-off chopping cycles
    int plateau_time = 2 in [1,5]; // Plateau time (1 to 5 sec)
    int kpmin = 0 in [-3,3]; // Kp range min
    int kpmax = 0 in [-3,3]; // Kp range max
    int kimin = 0 in [-3,3]; // Ki range min
    int kimax = 0 in [-3,3]; // Ki range max
    int kcmin = 0 in [-3,3]; // KiCurr range min
    int kcmax = 0 in [-3,3]; // KiCurr range max
    int kfmin = 0 in [-3,3]; // Kf range min
    int kfmax = 0 in [-3,3]; // Kf range max
}{
    // duration
    int tOPT = duration(Pacs_Chopper_AutoOptPlateau(chop_pos,cycle,plateau_time,kpmin,kpmax,kimin,kimax,kcmin,kcmax,kfmin,kfmax));
    int tOBSID = duration(WriteOBSID($OBSID));
    int tEndID = duration(WriteEndID());
    int tp = tOPT + tOBSID + tEndID;
    // Issue the pointing request
    int[] fromPntReq = no_pointing(true,0,0,tp);
}{
    // The state machine
    int[] stateVar = [0];
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 3) {
            // Get OBSID from environment
            //Send OBSID to DMC
            WriteOBSID($OBSID);
            data_rate(120.0);
            Pacs_Chopper_AutoOptPlateau(chop_pos,cycle,plateau_time,kpmin,kpmax,kimin,kimax,kcmin,kcmax,kfmin,kfmax);
            // Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Gra_Mec_Setup_Cold {
    /* No variables to call PacsEng_Spec_Gra_Mec_Setup_Cold                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_Mec_Setup_Cold                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_Mec_Setup_Cold()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_Mec_Setup_Cold();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id: PacsEng_Spec_SPU_Reset.txt,v 1.5 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_SPU_Reset_u {
    /* No variables to call PacsEng_Spec_SPU_Reset                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_SPU_Reset                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_SPU_Reset()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_SPU_Reset();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Phot_Sequencer_Setup.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Loading the sequencer to build up the signal (OBMO)
//                 for normal DDCS mode
//
// Author        : T. Mueller
// CUSification  : DAC
// Arguments     : none
//                 
//
// Description   : This script will set the sequencer, which is building
//                 up the final signal and it sets the data mode
//                 to "Bolo & HK".
//                 This script should be executed just after the
//                 switch-on procedure, the BOLC initialisation
//                 and the bias settings (polarizer)
//                              
// Comments      :  Coded based on PhFPU UM, Draft 5, August 10, 2006
//
// Version       : 1.3
// History       : 1.0 / 20-Apr-2004 initial version by TM
//                    1.1    7-mar-2006 SEND_COMMAND_TO_BOLC renamed
//                    1.2   11-aug-2006 TM: updated for PhFPU UM, draft 5, chapter 4.2.2
//                    1.3   26-oct-2006 TM: data mode Bolo & Hk is set in the end
//
procedure PACS_Phot_Sequencer_Setup {
}{
    // ------------------------------------------------------------
    // ------------------------------------------------------------
    // PhFPU UM, draft 5:
    // 4.2.2 Loading the sequencer
    // Programmable Sequencer loading script for "Hacheur" mode
    // ------------------------------------------------------------
    // ------------------------------------------------------------
    // Set clock mux stop
    //# P 09 00 00 00
    int operand = 0x9000000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 0 time 0 clk 20
    //# P 0C 00 0014
    operand = 0xc000014;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 1 time 35 clk 52
    //# P 0C 01 11B4
    operand = 0xc0111b4;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 2 time 144 clk 116
    //# P 0C 02 4874
    operand = 0xc024874;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 3 time 153 clk 100
    //# P 0C 03 4CE4
    operand = 0xc034ce4;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 4 time 159 clk 108
    //# P 0C 04 4FEC
    operand = 0xc044fec;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 5 time 280 clk 44
    //# P 0C 05 8C2C
    operand = 0xc058c2c;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 6 time 290 clk 36
    //# P 0C 06 9124
    operand = 0xc069124;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 7 time 294 clk 52
    //# P 0C 07 9334
    operand = 0xc079334;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 8 time 314 clk 20
    //# P 0C 08 9B14
    operand = 0xc089b14;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 9 time 322 clk 0
    //# P 0C 09 A100
    operand = 0xc09a100;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set clock mux sequencer
    //# P 09 00 00 01
    operand = 0x9000001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set data mode Bolo & HK
    //# P 09 02 00 01
    operand = 0x9020001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    // ---------------------------------------------
    //
    //-----------------
    // End of Procedure
    //-----------------
}

// Missionphase  : FMIST
//
// Purpose       : CONFigure the servo grating loop using parameters read from
//                 a CAL-U file
//                  
// Author        : Pierre Royer
//
// Arguments     : This version reads the ROW calUrow of the -calUname CAL-U file
// string calUname  Name of the CAL-U table
// string calUrow   Name of the ROW containing the desired controler params
//
// Version       : 1.0
// History       : 1.0 20-Jul-2007 PR
//               :
procedure PACS_Spec_Gra_IST_Set_Ctrl_Par {
}{
    // Calibration Table
    string calUname = "CONFGrat";
    // Row in table = Instrument Configuration
    string calUrow = "FMILT";
    // 0 : rate read from calibration table; 1 : rate forced = 3 (homing request)
    int homing_mode_rate = 1;
    //
    // Read the demanded column of the given table.
    // Rows 0 to 8
    int word0 = ilookup(calUname,calUrow,"Kp");
    int word1 = ilookup(calUname,calUrow,"Ki");
    int word2 = ilookup(calUname,calUrow,"Kd");
    int word3 = ilookup(calUname,calUrow,"Kf");
    int word4 = 3;
    if(homing_mode_rate == 0) {
        word4 = ilookup(calUname,calUrow,"Rate");
    }
    int word5 = ilookup(calUname,calUrow,"AccLimit");
    int word6 = ilookup(calUname,calUrow,"OutputLimit");
    int word7 = ilookup(calUname,calUrow,"Scaling");
    int word8 = ilookup(calUname,calUrow,"ErrorLimit");
    // Create the parameter list tuple
    {int}[] params = [{word0},{word1},{word2},{word3},{word4},{word5},{word6},{word7},{word8}];
    // Create the array for the checksum function
    int[] aux = [word0,word1,word2,word3,word4,word5,word6,word7,word8];
    int chksum = checksum("int",aux);
    // Send the TC
    Pacs_DMC_WRT_GRAT_CONF_PAR(params,chksum);
    delay(1);
}

// CVS comments  : $Id: 
// Purpose       : Estimate grating parameters by referring to the U-CAL SPEC_BAND_params and 
//                 grating calibration file mentioned therein
//
// CUS author    : DAC & VD
// Script file   : cloned SPEC_get_grat_info
//
// Input arguments
// type    name         description
// double  waveLen      Desired wavelength [microns]
//
// Return values
// Type                           Description
// tuple  {double,int,int,        {waveLen,order,gratPos,
//         int,int}                nbSteps,stepSize}  
//
// Description   : Access the table SPEC_BAND_params. Verify that the given
// wavelength is within range; obtain order and the name of the GratCal
// grat vs. wavelength table. Get nominal grating position from GratCal table.
// Returns the grating position such that nominal grating position will be
// acchieved after nbSteps/2 steps.
//
// Notes from 18-june-2009 (DAC). Order, which used to be the key to many
// CAL-U tables has been extended into an indicator of wavelength/filter
// combinations. The amended logic defines the following orders for use
// with the KeyWaves:
// - If 1st order and using parallel filter A: order = 12
// - If 1st order and using parallel filter B: order = 13
// - If 2nd order (filter A):                  order =  2
// - If 3rd order (filter B):                  order =  3
// - If 2nd order at 3rd order wavelengths:    order = 23
// 
// For the science lines, Order has its original intrpretation, i.e.
// grating order
// 
//
// Dependencies  :
//
// Preconditions :
//                 
// Comments      : With current version of lookup, first column has to be of
// type string
// 
// History       : 0.1 25-aug-2005 DAC
// 0.2  8-may-2006 Return grating position such that line falls
//                 in the middle of array after n_steps/2
// 0.3 30-may-2006 Access SPEC_BAND_params using module SPEC_BAND_read;
//                 SPEC_BAND_read no longer used (since when?)
//                 Return central pixel gratPos if switching = true
// 0.4 22-nov-2006 "Verbosed" debug_print
// 0.5 14-feb-2007 Verbose in calling argument
// 0.6 14-mar-2007 extraConf in calling argument
// 0.6  7-may-2007 Amended for SCR-3164: introduction of "L" lines in
//                 SPEC_BAND_params
// 0.7  8-may-2007 Case of overlapping bands; orderSel defines the order
// 1.0 10-oct-2007 SCR3632. Dedicated key wave parameters. K lines will
//                 be recognized because "resol" will be KHI, KMED, or KLOW
// 2.0 06-05-2009 VD sort out KeyWL SPR5447 for ALL Ranges inc. SEDs
// 3.0 24-nov-2009 VD PHS-1264 Key Wave @ order 2 if lineLamdba < 103.1
// 4.0 26-nov-2009 VD PHS-1267 wavelength band larger
// 5.0 30-nov-2009 VD SCRs PHS-1272 and PHS-1274
// 6.0 21-apr-2010 VD PHS-1385: cloned form SPEC_get_grat_info: to account for Line un-chopped
//                    Range section NOT removed as this will be used for Range un-chop
//
{double,int,int,int,int} procedure SPEC_get_grat_info_unchop {
    double waveLen = 54.0 in [51.0,220.0]; // Sought wavelength
    string resol = "HI" in ["HI","MED","LOW","KHI","KMED","KLOW"]; // Desired resolution
    /* PHS-1385   bool switching = true; // Return central pixel if true */
    string obsmode = "chopNod";
    string extraConf = "normal" in ["normal","bright"];
    string orderSel = "order2";
    bool verbose = false;
}{
    bool special = false;
    bool switching = false;
    if(obsmode == "switching") {
        switching = true;
    }
    // PacsRangeSpec may call with sedN instead of orderSelN; use
    // "conversion" table for sedN => orderSelN 
    if(orderSel == "sed2" || orderSel == "sedb2b") {
        orderSel = "order2";
    }
    if(orderSel == "sed3" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        orderSel = "order3";
    }
    if(orderSel == "sed4") {
        string save_orderSel = "sed4";
        orderSel = "order2";
        special = true;
    }
    // Open and read SPEC_BAND_params table. Table indexed by ORDER
    // Try two possible ORDERs: order 1 and order indicated by orderSel
    // Start with order = 1
    int order = 1;
    if(special) {
        order = 23;
    }
    bool found = false;
    int nbSRCH = 0;
    while(!found && nbSRCH < 2) {
        //   SCR-3164. Deal with "L" lines
        // PHS-1385
        if(obsmode == "chopNod" || obsmode == "switching") {
            string key = "L" + order;
        } else {
            if(obsmode == "gratScan") {
                key = "UL" + order;
            }
        }
        //   SCR-3632 Deal with key wavelengths
        // Start KeyWave if-endif	
        if(resol == "KHI" || resol == "KMED" || resol == "KLOW") {
            if(orderSel == "order2" && waveLen > 103.1) {
                order = 12;
            }
            if(orderSel == "order2" && waveLen <= 103.1) {
                if(!special) {
                    order = 2;
                } else {
                    if(special) {
                        order = 23;
                    }
                }
            }
            if(verbose) {
                debug_print("SPEC_get_grat: orderSel " + orderSel);
            }
            if(orderSel == "order3" && waveLen >= 100.0) {
                order = 13;
            }
            if(orderSel == "order3" && waveLen <= 99.0) {
                order = 3;
            }
            key = "K" + order;
            if(verbose) {
                debug_print("waveLEN: " + waveLen);
                debug_print("keyW: " + key);
            }
        }
        // End KeyWave if-endif
        //   read BLU and RED edges of the SPEC bands
        double blu = dlookup("SPEC_BAND_params",key,"BLU");
        double red = dlookup("SPEC_BAND_params",key,"RED");
        found = blu <= waveLen && red >= waveLen;
        // Logic to deal with upper/lower half
        if(found) {
            string newKey = "";
            if(key == "L1" && waveLen > 150.0) {
                newKey = "L1R";
            }
            if(key == "L1" && waveLen < 160.0) {
                newKey = "L1B";
            }
            //	       debug_print("#########Newkey: " + newKey);		       
        }
        if(verbose) {
            debug_print("SPEC_get_grat: Switching is " + switching);
            debug_print("SPEC_get_grat: Wave " + waveLen);
            debug_print("SPEC_get_grat: FOUND " + found);
            debug_print("SPEC_get_grat: key " + key);
            debug_print("SPEC_get_grat: nbSRCH " + nbSRCH);
        }
        //   If not yet found search in order indicated by orderSel
        if(!found) {
            if(orderSel == "order2") {
                order = 2;
            } else {
                if(orderSel == "order3") {
                    order = 3;
                }
            }
            nbSRCH = nbSRCH + 1;
        }
    }
    // If given wavelength not found there is a problem
    if(!found) {
        error("Wavelength " + waveLen + " is not within " + orderSel);
    }
    // Found the ORDER. Get now the name of position vs. wavelength gratPosTab
    string gratPosTab = slookup("SPEC_BAND_params",key,"CAL_FILE");
    // Read the step size and the number of steps for this ORDER and resolution
    // Recast "resol" as it was before SCR3632
    if(resol == "KHI") {
        resol = "HI";
    }
    if(resol == "KMED") {
        resol = "MED";
    }
    if(resol == "KLOW") {
        resol = "LOW";
    }
    // Special case for "bright" source
    if(extraConf == "normal") {
        int stepSize = ilookup("SPEC_BAND_params",key,resol);
        int nbSteps = ilookup("SPEC_BAND_params",key,"NSTEPS");
    }
    if(extraConf == "bright") {
        stepSize = ilookup("SPEC_BAND_params",key,resol);
        nbSteps = ilookup("SPEC_BAND_params",key,"FASTSTEP");
    }
    // Get from gratPosTab the grating position corresponding to waveLen
    double gratPosDble = interpolate(gratPosTab,"grat_pos",waveLen);
    // gratPos will place waveLen in the middle of the array
    int gratPos = iround(gratPosDble);
    if(verbose) {
        debug_print("SPEC_get_grat Nominal wavelen: " + waveLen);
        debug_print("SPEC_get_grat Nominal grating: " + gratPos);
    }
    // Grating is scanned with a negative step size (increasing wavelength) 
    // The grating start position should then be such that after nbSteps/2 we
    // are at nominal position: 
    //              gratPos = gratStartPos - stepSize*nbSteps/2
    // hence:
    int gratStartPos = iround(gratPosDble + double(stepSize) * double(nbSteps) / 2.0);
    // and will scan by decreasing grating angle, i.e. negative step size:
    stepSize = -stepSize;
    // If frequency switch return return gratPos (central pixel)
    if(switching) {
        gratStartPos = gratPos;
    }
    if(verbose) {
        debug_print("SPEC_get_grat: reads SPEC_BANDS");
        debug_print("SPEC_get_grat: WAVE/order/gratNOMINAL/gratSTRT: " + waveLen + "/" + order + "/" + gratPos + "/" + gratStartPos);
        debug_print("SPEC_get_grat: nbSteps/stepSize: " + nbSteps + "/" + stepSize);
    }

    return {waveLen,order,gratStartPos,nbSteps,stepSize};
}

// Filename	: Pacs_Spec_dark_current_pv
//
// Purpose	:  Short performance test Dark Current
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do dark current measurements in buffer transmission mode on
//                     both CS positions.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and internal CSs switched off.
//                        CDMS has to be switched to burst mode. After the end of the
//                        test go back to nominal mode.
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 1.1
// 
// History 	: 1.0 04-04-07 HD. IST update.
// 		  2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//                     2.1 08-Apr-2008 HF adapted to in-flight default biases and heater values
//		  based on PacsEng_Spec_dark_current_imt502
//		  1.0 15-07-08 HD. Version now for PV.
//                1.1 27-08-09 MN: changed SPU setup script (PHS-1161)
//              
procedure Pacs_Spec_dark_current_pv {
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    int gratPOS = 500000; // Grating Position
}{
    // Switch to burst mode 
    Burstmode_setup_block();
    //
    // Set-Up definition
    // reset interval in ramps    
    int reset_inter = 512;
    // choose temperature blue det in raw units
    double blue_temp = 0.78;
    // heat-up time for blue detector heater in sec
    int heat_up_time = 900;
    // observing time in sec     
    int obs_time = 420;
    // Move chopper to one CS
    PACS_Chopper_mov_abs_fm_bb(-21350);
    // Move Filter Wheel to Position A
    SPEC_fltw_move(fltPOS);
    // Move grating to a key wavelength
    SPEC_Gra_move_abs_raw(gratPOS);
    delay(15);
    // Set Temperature 
    PACS_Spec_B_Heat_Setup(blue_temp);
    // Wait for stabilization of the temperature 
    delay(heat_up_time);
    // CRE setup
    int ramp_len_red = reset_inter;
    int ramp_len_blu = reset_inter;
    double bias_d_red = 0.03;
    double bias_r_red = 3.0E-4;
    double bias_d_blu = 0.08;
    double bias_r_blu = 3.0E-4;
    int capa_red = 0;
    int capa_blu = 0;
    SPEC_CRE_No_Heater_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // SPU setup   
    int comp_mode_blu = 25;
    int comp_mode_red = 25;
    int nb_samp_subramp_blu = 16;
    int nb_samp_subramp_red = 16;
    int nb_raw_spu_blu = 3;
    int nb_raw_spu_red = 3;
    int glitch_det = 1;
    int ramp_fit_alg = 1;
    bool startSPU = true;
    Pacs_Spec_spu_flex_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Dark Current measurements for 7 minutes at CS1 position
    delay(obs_time);
    // Do SPU reset
    SPEC_spu_reset();
    // Move chopper to default position 
    PACS_Chopper_mov_abs_fm_bb(0);
    // CRE setup to default values
    SPEC_CRE_No_Heater_setup(64,64,bias_d_red,0.01,bias_d_blu,0.01,12,12);
    // reset burst mode profile
    Burstmode_reset_block();
}

// Missionphase  : PACS IST
//
// Purpose       : Spectroscopy to Non-Prime 
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
//
// Arguments     : None
//                 
//
// Description   : This script will disable and switch off mechanisms, 
//                 calibration sources
//                 and detectors to go from spectroscopy to non-prime. 
//                 
//                              
// Comments      :      
//
// Version       : 2.1
// History       : 1.0 /  16-Dec-2002 initial version
//                 1.1 /  02-Jul-2003 added stop compression commands   
//                 1.2 /  09-Oct-2003 Sytnax changes according to new TOPE
//                 1.3 /  26-Mar-2004 Adapted to DMC SUM 2.6
//                 2.0 /  24-Aug-2004 Adapted for CQM and DMC SUM 3.1 
//                 2.1 /  10-Nov-2004 Editorial for IST, removed switch-off of
//                        FPU T-sensors and FW turn
// 2.2  10-apr-2006 Renamed to  SpectroscopytoNonPrime  
procedure SpectroscopytoNonPrime {
}{
    debug_print("Start SpectroscopytoNonprime");
    // DMC_DISABLE_BB1_CONT
    Pacs_DMC_DISABLE_BB_1_CONT();
    delay(1);
    // DMC-SWITCH-OFF-BB-1-CONT" SWITCH OFF BLACK BODY 1 CONTROLLER
    Pacs_DMC_SWOF_BB_1_CONT();
    // DMC_DISABLE_BB2_CONT
    Pacs_DMC_DISABLE_BB_2_CONT();
    delay(1);
    // DMC-SWITCH-OFF-BB-2-CONT" SWITCH OFF BLACK BODY 1 CONTROLLER
    Pacs_DMC_SWOF_BB_2_CONT();
    delay(1);
    // "DMC-DISABLE-CHOPPER-CONT" DISABLE CHOPPER CONTROLLER
    Pacs_DMC_DISABLE_CHOP_CONT();
    delay(1);
    // "DMC-SWITCH-OFF-CHOP-CONT" SWITCH OFF CHOPPER CONTROLLER
    Pacs_DMC_SWOF_CHOP_CONT();
    delay(1);
    // "DMC-DISABLE-GRATING-CONT" DISABLE GRATING CONTROLLER
    Pacs_DMC_DISABLE_GRAT_CONT();
    // "DMC-SWITCH-OFF-GRAT-CONT" SWITCH OFF GRATING CONTROLLER
    Pacs_DMC_SWOF_GRAT_CONT();
    // SPUS-STOP-REDUCT-COMPR
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    // DMC_WRT_B_DEC_OPT(ID,LENGTH,4,CHKSUM)
    int[] argum = [4];
    {int}[] argTuple = [{4}];
    int chksum = checksum("int",argum);
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,chksum);
    delay(1);
    argum = [4];
    argTuple = [{4}];
    chksum = checksum("int",argum);
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,chksum);
    delay(1);
    // "DMC-SWITCH-OFF-RED-SPEC" SWITCH OFF RED SPECTROMETER ARRAY POWER
    Pacs_DMC_SWOF_R_SPEC();
    delay(1);
    // "DMC-SWITCH-OFF-BLUE-SPEC" SWITCH OFF BLUE SPECTROMETER ARRAY POWER
    Pacs_DMC_SWOF_B_SPEC();
    delay(1);
    // "DMC-SWITCH-OFF-RED-DEC" SWITCH OFF RED DEC POWER
    Pacs_DMC_SWOF_R_DEC();
    delay(1);
    // "DMC-SWITCH-OFF-BLUE-DEC" SWITCH OFF BLUE DEC POWER
    Pacs_DMC_SWOF_B_DEC();
    delay(1);
    // DPU-SET-HK-LIST (NonPrime for both channels)
    Pacs_DPU_SET_HK_LIST("NO_PRIME","BOTH Array");
    // End of Procedure
}

// $Id: PacsEng_Spec_GeGa_Loop_Comm.txt,v 1.4 2008/11/12 11:40:20 vanessad Exp $
// Missionphase  : PACS Commissiong Phase
//
//
//
//
// Purpose      : Ge:Ga detector Loop
//
// Author       : Helmut Dannerbauer
// CUS script   : HD
// CVS file     :
//
// Arguments    : bias, integration time, capacity, measurement time, resistor bias
//
//
// Description  : Loop over bias, integration time and capacity.
//
// Dependencies :  - Pacs_Spec_GeGa_Loop_Comm 
//		   - WriteOBSID
//		   - WriteEndID
//
//
// Preconditions : - PACS is switched on
//                 - Setup spectroscopy
//		   - Mechanics and CS controllers are SWON and ENABLED
//
// Comments     : 
//
// Version      : 1.0
//
// History      : 1.0 HD. 14-Apr-2008 initial version by HD.
//	1.1 PR. 17-Apr-2008 See corresponding procedure
//	1.2 PR 06-05-2009 Add parameters for raw ramps & all_slopefit
//
//
obs PacsEng_Spec_GeGa_Loop_Comm {
    /* Needed variables to call PacsEng_Spec_GeGa_Loop_Comm                        */
    int repeat_global = 15; // Global repetition factor (main loop)
    int repeat_intern = 2; // Repetition factor inside the bias loop (ramplen+capa loops)
    double[] bias_blue = [0.06,0.08,0.1,0.12]; //bias blue
    double[] bias_red = [0.03,0.04,0.05,0.06]; //bias red red
    int[] ramp_len_blue = [32,64]; //ramp length blue (set integration time)
    int[] ramp_len_red = [32,64]; //ramp length red (set integration time)
    int[] capa_blue = [8,12]; //capacity blue
    int[] capa_red = [8,12]; //capacity red
    int meas_time = 60; //observing time in seconds per setting
    double bias_res_blue = 0.0101; //resistor bias blue
    double bias_res_red = 0.0101; //resistor bias red
    int chop_pos = 0; //chopper position
    int grat_pos = 535000; // grating position
    string filter_pos = "POS A" in ["POS A","POS B"]; // FW position
    int nb_raw_spu_blu = 3; // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3; // Nb of raw channels transmitted by SPUL
    bool subramps_of_8 = false; // true = subramps of 8 samples, false = slope fit for ramps<1/4s otherwise subramps of 16
    bool all_slopefit = true; // true = SPU forced in in slope fitting for all setups. Does not overrule subramps_of_8
    /* End of needed variables for PacsEng_Spec_GeGa_Loop_Comm  */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_GeGa_Loop_Comm(repeat_global,repeat_intern,bias_blue,bias_red,ramp_len_blue,ramp_len_red,capa_blue,capa_red,meas_time,bias_res_blue,bias_res_red,chop_pos,grat_pos,filter_pos,nb_raw_spu_blu,nb_raw_spu_red,subramps_of_8,all_slopefit)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic.
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_GeGa_Loop_Comm(repeat_global,repeat_intern,bias_blue,bias_red,ramp_len_blue,ramp_len_red,capa_blue,capa_red,meas_time,bias_res_blue,bias_res_red,chop_pos,grat_pos,filter_pos,nb_raw_spu_blu,nb_raw_spu_red,subramps_of_8,all_slopefit);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase     : PV phase
//
// Purpose          : Spatial calibration procedure
//                    
//
// CUS author       : HF, based on WaveCalChop
// Script file      : 
//
//
// Description      : Uses OBCP27 for executing a parameterized scan of any length, stepsize etc.
//                   
//
// Dependencies     : 
//
// Preconditions    : PACS must be on and configured for spectroscopy
//
// Comments         : 
// Version          : 1.1
// History    	   : 1.0 18-Mar-2009 HF adapted from WaveCalChop
// 	     1.1 23-Jul-2009 BV SPR 1798 corrected biases	       
//
procedure SpatialCalChop {
    string fltPOS = "POS A"; // Filter wheel position (0="POS A", 1="POS B")
    int grat_pos = 500000; // grating start position for scan
    int grat_time = 0; // Grating time to move to start [msec]
    int grat_step_up = 200; // grating step size
    int grat_step_dn = 200; // grating steop size down
    int nb_grat_steps = 50; // number of grating steps in one direction
    int nb_CS1_CS2 = 0; // nb of cycles on internal CS
    int nb_rdouts_ramp = 64; // number of readouts per ramp
    int nb_ramps_plateau = 1; //Nb of readouts per chopper position
    int nb_up_down = 1; // number of grating updown scans
    int capa_red = 0; // Red capacitor
    int capa_blu = 0; // Blue capacitor
    double bias_r_blu = 0.01; // Bias "r" blue
    double bias_r_red = 0.01; // Bias "r" red
    double bias_d_blu = 0.1; // Bias "d" blue
    double bias_d_red = 0.042; // Bias "d" red
    int nb_samp_subramp_blu = 16; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 16; // Nb of red samples per sub-ramp
    int nb_SRC_REF = 3; // nb of cycles (ramps) per grating position
    int chop_pos1 = 664; // initial chopper position
    int chop_pos2 = 664; // chopper off position
    int detector = 1; // 1= blue detecor 2=red detector
}{
    // Condition the CREs and detectors
    int ramp_len_blu = nb_rdouts_ramp;
    int ramp_len_red = nb_rdouts_ramp;
    // Set up the blue and red CRE subsystem
    // cre_ctrl is a bit field:
    // 256=sync width=2, 128=T sensor on, 2=enable, 1=power on
    // Do not enable yet
    int cre_ctrl_red = 256 + 128 + 2 + 1;
    int cre_ctrl_blu = 256 + 128 + 2 + 1;
    SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // Set BLUE heater parameters (mA)
    double heater_blu = 0.78;
    SPEC_heater_setup(heater_blu);
    //
    // SPU parameters
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    // Reset SPU
    SPEC_spu_reset();
    // Re-start SPU in default mode
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Move the filter wheel
    SPEC_fltw_move(fltPOS);
    // Get CSn positions from dedicated CAL-U file
    int ref1 = chop_pos1;
    int ref2 = chop_pos2;
    int chop_pos_REF1 = chop_pos1;
    int chop_pos_REF2 = chop_pos2;
    int chop_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    //     int grat_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating"); 
    //     grat_def should be grat_pos in this case
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","SPEC","pos_CS1");
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    int grat_def_time = 0;
    // Time to come back to default position set to 0
    //                           because grating already in position
    //
    // Now trigger execution of OBCP
    // This OBCP is number 27, requires 21 parameters and calls DEC/MEC #12
    // This is done in a raw way to overcome the state machine
    string obcp_ID = "GRAT_SCAN_CHOP2";
    int obcp_par_nb = 21;
    int seq_DMC = 12;
    {int,int}[] grp = [{1,seq_DMC},{2,80000000},{3,nb_up_down},{4,nb_grat_steps},{5,nb_SRC_REF},{6,chop_pos_REF1},{7,nb_ramps_plateau},{8,chop_pos_REF2},{9,nb_CS1_CS2},{10,chop_pos_CS1},{11,chop_pos_CS2},{12,grat_step_up},{13,grat_step_dn},{14,detector},{15,grat_pos},{16,grat_time},{17,comp_mode_blu},{18,comp_mode_red},{19,grat_pos},{20,chop_def},{21,grat_def_time}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    //int[] duree3 = OBCP_grat_scan_chop2(nb_up_down,nb_grat_steps,nb_SRC_REF,chop_pos_REF1,nb_ramps_plateau,chop_pos_REF2,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_up,grat_step_dn,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_pos,chop_def,grat_def_time,nb_rdouts_ramp);
    // Do not Reset the SPU here
    // SPEC_spu_reset();
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : PACS Spectrometer FoV Scan on the cryo cover
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version	: 1.0
// History       : 1.0  15-Apr-2008  Initial version by PR
//
obs PacsEng_Spec_GeGa_Chop_2_3 {
    /* Needed variables to call PacsEng_Spec_FoV_Scan                        */
    int grat_pos = 535000; // Grating position
    string filter_pos = "POS A" in ["POS A","POS B"];
    int nb_rdouts_ramp = 64; // Ramp length used in computation of OBCP duration only
    int nb_samp_subramp_blu = 64; // Red Subramp length  (directly connected to ramp_fit_alg)
    int nb_samp_subramp_red = 64; // Blue Subramp length
    int ramp_fit_alg = 0 in [0,1]; // Ramp fit algorithm [0=LstSq;1=mean value]
    int nb_grat_steps = 1; // Number of grating steps          P#2
    int nb_SRC_OFF = 10; // Nb cycles grating position       P#3
    int nb_ramps_plateau = 2; // Nb of ramps per chopper plateau P#5
    /* End of needed variables for PacsEng_Spec_FoV_Scan                     */
}{
    // Fixed Parameters
    int nb_up_down = 1;
    // Number of sequences: up down up  P#1
    int grat_step_up = 0;
    // Grating step                   P#11
    int grat_step_dn = 0;
    // Grating step                   P#12
    int chop_pos_REF1 = 664;
    // Chopper position 1              P#4
    int chop_pos_CS1 = -21350;
    // Chopper position on CS1       P#9
    int chop_pos_CS2 = 21200;
    // Chopper position on CS2        P#10
    int grat_time = 15000;
    // Grating time
    int grat_def_time = 15000;
    // Grating default time
    int chop_def = 664;
    // Chopper default position
    int detector = 1;
    // Detector to SYNCH on
    int grat_def = 500000;
    // Grating default
    int comp_mode_blu = 16;
    // "Blue" compression
    int comp_mode_red = 16;
    // "Red" compression
    //
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_GeGa_Chop_2_3(nb_samp_subramp_blu,nb_samp_subramp_red,ramp_fit_alg,filter_pos,nb_up_down,nb_grat_steps,nb_SRC_OFF,chop_pos_REF1,nb_ramps_plateau,chop_pos_CS1,chop_pos_CS2,grat_step_up,grat_step_dn,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,nb_rdouts_ramp)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_GeGa_Chop_2_3(nb_samp_subramp_blu,nb_samp_subramp_red,ramp_fit_alg,filter_pos,nb_up_down,nb_grat_steps,nb_SRC_OFF,chop_pos_REF1,nb_ramps_plateau,chop_pos_CS1,chop_pos_CS2,grat_step_up,grat_step_dn,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,nb_rdouts_ramp);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id: PacsEng_PHOT_orbit_epilogue.txt,v 1.4 2008/11/12 11:40:20 vanessad Exp $
// Purpose        : Bring PACS from any state to the standard PHOT configuration
//
// CUS author     : KO modified from PacsEng_PHOT_orbit_prologue
//
// Input arguments: see after module identification
//
// Return values
// N/A
//
// Comments      :
//
// History: 
// 1.0 19-may-2008 KO, Created by modifying PacsEng_PHOT_orbit_prologue
// 1.1 20-may-2008 KO, Debugged for pointing timing logic
//
obs PacsEng_PHOT_orbit_epilogue {
    string calUfile = "BOLObias_preILT_standard_low"; //Bias table
    int tSET = 1; // Settling time for CS
    string fltPOS = "POS A"; // Filter
    double set_CS1 = 48.0; // set CS1 (ohms)
    double set_CS2 = 58.0; // set CS2 (ohms)
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct mode
}{
    bool execute = true;
    // Initial hold
    int tih = imax(1,duration(WriteOBSID($OBSID)));
    // Final hold
    int tfh = imax(1,duration(WriteEndID())) + tSET;
    // Duration of "stable" pointing
    int tp = duration(PHOT_setup(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //     Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //     Call the PHOT setup script
            PHOT_setup(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect);
        }
        if(state[0] == 5) {
            //     Wait for CS to stabilize
            delay(tSET);
            //     Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

//
// Missionphase  : PACS CoP and PV
//
// Purpose       : Condition SPU for SPECtroscopy observations
//                  
// CUS author    : Markus Nielbock
// Script file   : Pacs_Spec_spu_flex_setup.cus
//                 based on SPEC_spu_setup
//
// Input arguments
// Type Name              Default     Description
// int  comp_mode_blu       16        Compression mode Default=16; double=17;
//                                    lossless=20; transp=23; 4sec reset=24; 
//                                    buffer_mode=25, noise=33
// int  comp_mode_red       16        As above for RED
// int  nb_samp_subramp_blu 16        Number of samples per sub-ramp 
//                                    (>=4 and <= readouts per ramp)
// int  nb_samp_subramp_red 16        As above for RED
// int  nb_raw_spu_blu       3        Number of raw channels transmitted by SPU
// int  nb_raw_spu_red       3        As above for RED
// int  glitch_det           1        Glitch detection; 0=on; 1=off
// int  ramp_fit_alg         1        Ramp fit algorithm: 0=LstSq fit,1=mean value
// bool startSPU           true       Start SPU after setting values
//
//
// Description   : Sets values for compression mode,
//                 threshold values (glitch, chopper, grating), raw 
//                 channel transmission, sub-ramp and detector
//                 constants, load DPU time and restart SPU. Script
//                 sets its own delays [sec] and returns the total
//                 duration in milliseconds. This version addresses
//                 BLU and RED; could make a BLU only and RED only version
//                 The call sequence to this module is as follows:
//                  
// Dependencies  : All spectrometer observations that need lossless compression
//                 or buffer transmission mode.
//
// Preconditions :
//                 
// Comments      :
//
// Version         1.0
//
// 1.0   11-Aug-2009 MN  cloned from SPEC_spu_setup and re-established input
//                       parameters
//             
block Pacs_Spec_spu_flex_setup PACS 102 {
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 16; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 16; // Nb of red samples per sub-ramp
    int nb_raw_spu_blu = 3; // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3; // Nb of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1; // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true; // Start SPU or not [true,false]
}{
    // Spectro "Ottensamer" block is now read off CONF_SPEC_param
    string calU = "CONF_SPEC_param";
    string rowName = "Normal0";
    string rowRED = "" + rowName + "RED";
    string rowBLU = "" + rowName + "BLU";
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    // Set the SPU compression modes
    // (TC arguments are defined as type {int}[], cf. definition of
    //  Pacs_DMC_WRT_SPU_TRAN_MODE; hence define comp_par accordingly)
    {int}[] comp_par = [{comp_mode_blu},{comp_mode_red}];
    // The "checksum" function needs an array as argument, hence use elements
    // of comp_par cast as an array:                      
    int[] aux = [comp_mode_blu,comp_mode_red];
    int check_sum = checksum("int",aux);
    // Issue the TC
    Pacs_DMC_WRT_SPU_TRAN_MODE(comp_par,check_sum);
    // Setting of start index of raw channels for SPUS and SPUL
    string spus_obs_mode = "SPEC";
    string spul_obs_mode = "SPEC";
    int spus_startraw = ilookup(calU,rowRED,"st_ind");
    int spul_startraw = ilookup(calU,rowBLU,"st_ind");
    Pacs_SPUS_RAW_CHAN_TRAN_MODE(spus_obs_mode,nb_raw_spu_blu,spus_startraw);
    Pacs_SPUL_RAW_CHAN_TRAN_MODE(spul_obs_mode,nb_raw_spu_red,spul_startraw);
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    int ppf = ilookup(calU,rowBLU,"ppf");
    // PPP: Pre-Processing Parameter
    int ppp = ilookup(calU,rowBLU,"ppp");
    // Threshold for glitch detection in spectroscopy
    int tfs = ilookup(calU,rowBLU,"tfs");
    // Threshold for chopper position deviation in spectroscopy
    int tcs = ilookup(calU,rowBLU,"tcs");
    // Threshold for grating deviation
    int tgd = ilookup(calU,rowBLU,"tgd");
    // Readouts per SubRamp readback
    int rsrr = nb_samp_subramp_blu;
    // Glitch detection for spectroscopy
    int gdfs = glitch_det;
    // Ramp fitting algorithm
    int rfal = ramp_fit_alg;
    // Sorting algorithm
    int soal = ilookup(calU,rowBLU,"soal");
    // lossless compression algorithm (0,1,2,3,4)
    int lcal = ilookup(calU,rowBLU,"lcal");
    // PACS Codec Order (3,4)
    int pcod = ilookup(calU,rowBLU,"pcod");
    // New 13.95a values are
    int rndb = ilookup(calU,rowBLU,"rndb");
    int rnds = ilookup(calU,rowBLU,"rnds");
    int fixrc = ilookup(calU,rowBLU,"fixrc");
    int dpre = ilookup(calU,rowBLU,"dpre");
    int dpost = ilookup(calU,rowBLU,"dpost");
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    {int}[] spu_par = Array2grp_1(aux);
    // and issue TC to "Short" SPU
    Pacs_SPUS_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    // Spectro "Ottensamer" block ("L" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    ppf = ilookup(calU,rowRED,"ppf");
    // PPP: Pre-Processing Parameter
    ppp = ilookup(calU,rowRED,"ppp");
    // Threshold for glitch detection in spectroscopy
    tfs = ilookup(calU,rowRED,"tfs");
    // Threshold for chopper position deviation in spectroscopy
    tcs = ilookup(calU,rowRED,"tcs");
    // Threshold for grating deviation
    tgd = ilookup(calU,rowRED,"tgd");
    // Readouts per SubRamp readback
    rsrr = nb_samp_subramp_red;
    // Glitch detection for spectroscopy
    gdfs = glitch_det;
    // Ramp fitting algorithm
    rfal = ramp_fit_alg;
    // Sorting algorithm
    soal = ilookup(calU,rowRED,"soal");
    // lossless compression algorithm (0,1,2,3,4)
    lcal = ilookup(calU,rowRED,"lcal");
    // PACS Codec Order (3,4)
    pcod = ilookup(calU,rowRED,"pcod");
    // New 13.95a values are
    rndb = ilookup(calU,rowRED,"rndb");
    rnds = ilookup(calU,rowRED,"rnds");
    fixrc = ilookup(calU,rowRED,"fixrc");
    dpre = ilookup(calU,rowRED,"dpre");
    dpost = ilookup(calU,rowRED,"dpost");
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    spu_par = Array2grp_1(aux);
    // and issue TC to "Long" SPU
    Pacs_SPUL_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    // Send time stamps
    // DMC_WRT_TIME: Write the time sent by the DPU into the DMC buffer
    // (No action on this one?)
    // DPU sends the time to DEC/MEC
    Pacs_DPU_SEND_TIME();
    // DMC_SET_TIME: Set the time previously written by the write time command
    Pacs_DMC_SET_TIME();
    // Start reduction/compression if commanded to do so
    if(startSPU) {
        Pacs_SPUS_START_REDUCT_COMPR();
        Pacs_SPUL_START_REDUCT_COMPR();
    }
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose	:  Performance Test of internal PACS calibration sources
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We start with a heat-up of the calibration sources.
//	  After monitoring for some while the behaviour on the desired temperature of
//                     both internal PACS calibration sources, we do a smaller heat-up which is followed 
//                     by a cooling down. The monitoring is based on diag. HK. 
//                     PTD 0.7.11 and 0.7.12 are the basis for this test. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy
//                 
// Comments	: This script is based on the commanding during the CQM ILT. 
//
// Version	: 2.0	
// 
// History 	: 1.0 04-04-06 Refined on IST requirements.
// 		: 2.0 04-mar-2008 translated into PV script VDP
//
obs PacsEng_Spec_CS_imt511 {
    /* Needed variables to call PacsEng_Spec_CS_imt511                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_CS_imt511                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_CS_imt511_bb()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_CS_imt511_bb();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id: PacsEng_Spec_Dark_CS_SequentialWarmUp.txt,v 1.1 2008/11/12 16:46:30 pierre Exp $
// Missionphase  :  PACS FM IST SOVT2 & PV Phase
//
//
// Purpose      : Schedule the associated CUS procedure
//
// Author       : PRoyer
// CUS script   : PR
// CVS file     :
//
// Arguments    : 
//
//
// Description  : 
//
// Dependencies :  
//
// Preconditions: 
//	- PACS is switched on
//	- Setup spectroscopy with cold calibration sources
//
// Comments: 
//
// Version: 1.0
//
// History : 1.0 16-Nov-2008 Created from the corresponding PacsCal
//
//
obs PacsEng_Spec_Dark_CS_SequentialWarmUp {
    /* Needed variables to call PacsEng_Spec_Dark_CS_SequentialWarmUp                        */
    int obs_time = 540; // Observing time per CS/FW/Grating setting
    int chop_time = 180; // Chopper plateau [sec] during CS temp rise time (0 = no chopping)
    /* End of needed variables for PacsEng_Spec_Dark_CS_SequentialWarmUp                     */
}{
    debug_print("obs PacsEng_Spec_Dark_CS_SequentialWarmUp. Version 1.0. 20081112");
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Dark_CS_SequentialWarmUp(obs_time,chop_time)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic.
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Dark_CS_SequentialWarmUp(obs_time,chop_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Spec_Fil_Trapping_DEG_MODE
// Missionphase  : PACS FM ILT
//
// Purpose       : Position sequence test of spectrometer filterwheel, intensively using the relative movements
//
// Author        : PR
//
// Arguments     :
//
// Description   : Operations in 2 phases
//         Phase 1   Open loop movements of increasing size from both FW stop positions
//         Phase 2   Repetition of the same small open loop movements, from positions 45 degrees from the stop positions.
//
// Comments      : Prerequisite : spec_mec_setup has been executed 
//
// Version       : 1.0
// History       : 1.0 / 12-May-2006 Creation
//
block PACS_Spec_Fil_Trapping_DEG_MODE PACS 179 {
    int num_iter = 2; // Number of repetitions of each sub-test block
    int maxkick = 15; // Maximal amplitude of the kicks in each sub-test block (degrees)
}{
    // Register start of BB
    WriteBBID($BBID);
    //
    double deg = 0.0;
    deg = 1536.0 / 360.0;
    // One degree in commanding units of the FW
    num_iter = 2 * num_iter;
    //
    int slew_time = 10;
    // max slew_time for any movement
    int kicktime = 4;
    //
    int fw_start = 0;
    // initial filter wheel position (0=A; 1=B)
    int fw_pos2 = (fw_start + 1) % 2;
    //
    // other filter wheel position
    //
    string[] fltPOS = ["POS A","POS B"];
    // number of iterations in all the test loops
    //
    // SWON FW CONTROLLER
    Pacs_DMC_SWON_FW_SPEC();
    delay(1);
    //
    // STARTING FROM FW STOP POSITION
    // ==============================
    //
    Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    //
    int step = 0;
    double n = 0.0;
    //
    for(int loop0 = 0 .. num_iter - 1) {
        Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[loop0 % 2]);
        delay(slew_time);
        for(int npos = 1 .. maxkick) {
            n = double(npos);
            Pacs_DMC_MOVE_SPEC_FW_STEP(iround(n * deg));
            delay(kicktime);
        }
    }
    //
    Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    //
    for(int loop1 = 0 .. num_iter - 1) {
        Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[loop1 % 2]);
        delay(slew_time);
        for(int nneg = 1 .. maxkick) {
            n = double(nneg);
            Pacs_DMC_MOVE_SPEC_FW_STEP(-1 * iround(n * deg));
            delay(kicktime);
        }
    }
    //
    // 45 DEGREES FROM POSITION
    // ========================
    Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    //
    for(int loop2 = 0 .. num_iter - 1) {
        for(int npos2 = 1 .. maxkick) {
            n = double(npos2);
            Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[loop2 % 2]);
            delay(slew_time + 5);
            Pacs_DMC_MOVE_SPEC_FW_STEP(iround(45.0 * deg));
            delay(slew_time);
            //
            Pacs_DMC_MOVE_SPEC_FW_STEP(iround(n * deg));
            delay(kicktime);
        }
    }
    //
    Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    //
    for(int loop3 = 0 .. num_iter - 1) {
        for(int nneg2 = 1 .. maxkick) {
            n = double(nneg2);
            Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[loop3 % 2]);
            delay(slew_time + 5);
            Pacs_DMC_MOVE_SPEC_FW_STEP(iround(-45.0 * deg));
            delay(slew_time);
            //
            Pacs_DMC_MOVE_SPEC_FW_STEP(-1 * iround(n * deg));
            delay(kicktime);
        }
    }
    //
    Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    //
    // Mark End of Block
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose	: Perform one MOVE_GRATING_ABSOLUTE
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: target_pos : Grating target position
//
// Description	: executes Pacs_DMC_MOVE_GRAT_ABS_RAW
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on
//	    The grating controller is SWON, ENABLED and HOMED
//	    (e.g. SetupSpectroscopyEQMIMT takes care for it)
//
// Comments	: Since the amplitude of the movement cannot be computed, THIS BBlock/COMMAND DOES NOT INCLUDE ANY DELAY!!!
//
// Version	: 2.0
//               
// History	: 1.0 22-Sep-2005 Creation by PR
// History      : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_Gra_move_abs_raw {
    /* Needed variables to call PacsEng_Spec_Gra_move_abs_raw */
    int target_pos = 500000; // Target position
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_move_abs_raw      */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_Gra_move_abs_raw(target_pos)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_Gra_move_abs_raw(target_pos);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Missionphase  : PACS FMILT
//
// Purpose       : Configure the spec filter wheel for Nominal Warm
//
// Author        : PR
//
// Arguments     : 
//
// Description   : 
//                 
// Comments      :      
//
// Version       : 0.1 
// History       : 0.1  04-Jul-2007 Initial version
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//
obs PacsEng_CONF_spec_fltw_Warm {
    /* No variables to call PacsEng_CONF_spec_fltw_Warm                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POSB" */
    /* End of needed variables for PacsEng_CONF_spec_fltw_Warm                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_spec_fltw_Warm()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_spec_fltw_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS script    ; SPEC_init_det_setup.cus
// Missionphase  : PACS AVM ILT
//
// Purpose       : Prepare for Spectroscopy 
//
// Author        : H. Feuchtgruber
//
// Arguments     : none
//
// CRE setup according to the DEC/MEC User's Manual
//
// 1. DMC_SWON_B_DEC to switch on the DEC 
// 2. Wait 8 seconds to get the 1355 connection between DEC and CPU board 
// 3. Send the complete set of default parameters. 
//    First send a DMC_WRT_B_SPEC_PAR command with these values 
//    (in hex: 20-8-18C-0-0-EA60-0-0).    
// 3a. Then, send a DMC_SET_PAR_B_SPEC to really send the parameters to the DEC. 
// 4. DMC_SWON_B_SPEC to switch on the detector array 
// 5. Wait 15 seconds to let the switch on procedure run and all voltages 
//    become stables 
// 6. Then, to activate the CREs (signal SELECT on the CREs), send the first 
//    3 parameters, i.e. DMC_WRT_B_SPEC_PAR command with these 
//    values (length: 3, values in hex : 20- 8-18E). 
// 6a. Then, send a DMC_SET_PAR_B_SPEC to really send the parameters to the DEC. 
//    Note: with this command, we set bit1 to 1 (activate CRE). Bit0 
//    has been set to 1 by the DMC_SWON_B_SPEC command but, 
//    bit0 is not commandable through the DMC_WRT_B_SPEC_PAR. 
//    The only way to switch on/off the detector array is to use the 
//    trigger commands. 
// 7. Then, you should set the bias voltages by writing the first 4 or 5 
//    parameters of the block. Make sure to copy the latest values you use 
//    for the first 3 parameters.
//
// Description   : Sets CRE parameters (see list of arguments).
//                 User specifies cre_ctrl_xx as:
//                 cre_ctrl: 256 to set "sync width=2"
//                           128 to set "T sensor on" 
//                             2 to set "select"
//                             1 power on (not relevant here)
//                 Script adds capa_xx to cre_ctrl_xx
//                     xx_cre_ctrl = capa_xx + cre_ctrl_xx
//                 xx_cre_ctrl gets written to the CRE register
//                 Must be called on a stopped SPU. This procedure will
//                 neither stop nor start SPU (call SPEC_spu_reset and 
//                 SPEC_spu_setup respectively for that)
//// Description   : Section "Initial detector setup" from SetupSpectroscopy.tcl,
//                 v2.8
//
// Comments      :
//
// Version       : 0.4
// History       : 0.1  3-jul-2006 initial version
//               : 0.2 10-nov-2006 TM: inclusion of the CRE selection
//                 0.3 16-nov-2006 Revision for copy to OpDataBase
//                 0.4 11-feb-2008 DAC removed two spurious debug print
//
procedure SPEC_init_det_setup {
}{
    // Switchon B and R DEC power, wait 8 sec
    Pacs_DMC_SWON_B_DEC();
    delay(8);
    Pacs_DMC_SWON_R_DEC();
    delay(8);
    // Wait after DEC switch-on
    delay(5);
    // Now define the startup Ge:Ga detector parameters (to be performed in 3 steps)
    // The 3rd step - setting the bias voltages - is done by SPEC_cre_setup
    // 1st step
    int read_per_ramp_b = 8;
    int cre_ctrl_b = 396;
    double bias_r_b = 0.0;
    double bias_d_b = 0.0;
    int read_per_ramp_r = 8;
    int cre_ctrl_r = 396;
    double bias_r_r = 0.0;
    double bias_d_r = 0.0;
    // Bias values have been given in ENG units. Have to convert to RAW in
    // order to compute check-sums
    // BLUe channel
    int i_blu_bias_r = convert_to_raw("pacs_DMC_BIAS_R",bias_r_b);
    int i_blu_bias_d = convert_to_raw("pacs_DMC_BIAS_D",bias_d_b);
    int clks_rdout = 32;
    int simul_reg = 60000;
    int[] aux = [clks_rdout,read_per_ramp_b,cre_ctrl_b,i_blu_bias_r,i_blu_bias_d,simul_reg];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_B_SPEC_PAR(clks_rdout,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,simul_reg,check_sum);
    // RED channel
    int i_red_bias_r = convert_to_raw("pacs_DMC_BIAS_R",bias_r_r);
    int i_red_bias_d = convert_to_raw("pacs_DMC_BIAS_D",bias_d_r);
    aux = [clks_rdout,read_per_ramp_r,cre_ctrl_r,i_red_bias_r,i_red_bias_d,simul_reg];
    check_sum = checksum("int",aux);
    Pacs_DMC_WRT_R_SPEC_PAR(clks_rdout,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,simul_reg,check_sum);
    // SEND COMPLETE PARAMETERS TABLE TO Blue/RED DEC
    Pacs_DMC_SET_PAR_B_SPEC();
    Pacs_DMC_SET_PAR_R_SPEC();
    // SWITCH ON BLUE/RED SPECTROMETER ARRAY POWER
    Pacs_DMC_SWON_B_SPEC();
    delay(1);
    Pacs_DMC_SWON_R_SPEC();
    delay(1);
    // Wait for CRE HW sequence to finish
    delay(15);
    ////////////////////////////////////////////
    // 2nd step
    cre_ctrl_b = 398;
    cre_ctrl_r = 398;
    // Bias values have been given in ENG units. Have to convert to RAW in
    // order to compute check-sums
    // BLUe channel
    aux = [clks_rdout,read_per_ramp_b,cre_ctrl_b,i_blu_bias_r,i_blu_bias_d,simul_reg];
    check_sum = checksum("int",aux);
    Pacs_DMC_WRT_B_SPEC_PAR(clks_rdout,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,simul_reg,check_sum);
    // RED channel
    aux = [clks_rdout,read_per_ramp_r,cre_ctrl_r,i_red_bias_r,i_red_bias_d,simul_reg];
    check_sum = checksum("int",aux);
    Pacs_DMC_WRT_R_SPEC_PAR(clks_rdout,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,simul_reg,check_sum);
    // SEND COMPLETE PARAMETERS TABLE TO Blue/RED DEC
    Pacs_DMC_SET_PAR_B_SPEC();
    Pacs_DMC_SET_PAR_R_SPEC();
    // End of script
}

// Script file   : OBCP_chop_scan_phot.txt
// Missionphase  :
//
// Purpose       : Chopper Up-Down Scan Photometry (OBCP 14, DMC Seq. 15)
//                 This procedure is required to execute chopper scans across
//                 the PACS field of view. The filter wheel is commanded 
//                 outside this OBCP. This procedure calls the sequence 
//                 described in sec. 4.1.9
//
// OBCP author   : HF
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Chop increasingly away from start position; then increasingly
// closer to start position. Whole operation may be repeated nb_up_down times
//
// Dependencies  :
//
// Preconditions :
//
// Comments      :
//
// Version      : 0.2
// History       : 0.1  6-apr-2006 DAC
// 0.2  9-aug-2006 TM new default values
// 0.3  8-sep-2006 DAC Use OBCP number rather than name
// 0.4 10-oct-2006 DAC Back to OBCP name
//
int[] block OBCP_chop_scan_phot PACS 14 {
    int nb_up_down = 1; // P#1  number of up-down seqs.
    int nb_rdouts = 19; // P#2  number of readouts on step
    int nb_steps_up = 100; // P#3  number of steps up
    int nb_steps_dn = 100; // P#4  number of steps down
    int step_up = 200; // P#5  relative move up
    int step_dn = -200; // P#6  relative move down
    int detector = 4; // Detector to SYNCH on
    int comp_mode_blu = 0; // "Blue" compression
    int comp_mode_red = 0; // "Red" compression
    int chop_start = -10000; // Chopper start position
    int chop_def = 0; // Chopper default position
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain system parameter from PACSparams
    // BOL readout frequency [Hz] and readout period [msec]
    double bol_freq = dlookup("PACSparams","bolo_sample","freq_time");
    string bol_unit = slookup("PACSparams","bolo_sample","unit");
    double bol_period = 1000.0 / bol_freq;
    debug_print("Bolo sample: " + bol_freq + " " + bol_unit);
    debug_print("Bolo period: " + bol_period + "[msec]");
    // Obtain duration of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duration of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duration of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    debug_print("DMC/OBCP margins: " + dmc_margin + "/" + obcp_margin);
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duree_msec [msec] as it goes)
    // Begin
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    // Here and elsewhere it is assumed that OBCP "internal" TCs take t_cmd
    // [msec] to be executed
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_start_pos)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM)
    // (all parameters filled by DPU based on seq parameter)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHKSUM)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_START_SEQUENCE
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Call DEC/MEC sequence just to know the seq time
    int[] duree1 = DMC_chop_scan_phot(nb_up_down,nb_rdouts,nb_steps_up,nb_steps_dn);
    debug_print("Duration DMC_chop_scan_phot [rdouts] " + duree1);
    // Convert duration [readouts] into [msec]; add dmc_margin
    int seq_time = ifloor(double(duree1[0]) * bol_period) + dmc_margin;
    // Convert other times as well into msec
    duree_SRC = ifloor(double(duree1[1]) * bol_period);
    duree_REF = ifloor(double(duree1[2]) * bol_period);
    duree_CAL = ifloor(double(duree1[3]) * bol_period);
    duree_OVR = duree_OVR + ifloor(double(duree1[4]) * bol_period) + dmc_margin;
    // Tally into accumulated duration
    duree_msec = duree_msec + seq_time;
    // WAIT(seq_time)
    // Check execution status of the sequence and in case of
    // failure stop OBCP and issue TM(1,8) + event
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Issue TM(1,7)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // End
    // Duration: 8 x 200ms + seq_time + 0.5s
    // Now trigger execution of OBCP
    // This OBCP is number 14, requires 13 parameters and lasts seq_time [msec]
    // It calls DMC sequence 15
    string obcp_ID = "CHOP_UPDOWN_PHOT";
    int obcp_NB = 14;
    int obcp_par_nber = 13;
    int seq_DMC = 15;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_rdouts},{5,nb_steps_up},{6,nb_steps_dn},{7,step_up},{8,step_dn},{9,detector},{10,comp_mode_blu},{11,comp_mode_red},{12,chop_start},{13,chop_def}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nber,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Return total duration [sec] to calling program
    // Create return time array; convert into [sec]
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // Set delay()
    delay(time_array[0]);
    // Ending time
    int time_elapsed = time() - time_start;
    time_array[0] = time_elapsed;
    // Return

    return time_array;
}

// Filename	 : Pacs_Spec_QuickFullSpectrum
// Purpose       :  Quick full spectral scan in about 1 hour in all bands
//                  
//
// Input arguments  Integrating capacitance blue (0,8,4,12) and red; chopper position
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Uses OBCP28 for executing quick full scans in both filters
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                 
// Comments      : 
// Version	 : 1.1
// History	 : 1.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//                      1.1 08-Apr-2008 HF changed to in-flight defauilt biases
//                      1.2 08-Jun-2009 BV Changed to optimal biases from CoP / extended grating range to CoP results
// 
procedure Pacs_Spec_QuickFullSpectrum {
    int chop_def = 650; // chopper position during grating scan
    int capa_red = 0; // Red capacitor
    int capa_blu = 0; // Blue capacitor
}{
    // Fixed parameters
    int grating_start = 32000;
    // grating start position for scan\
    int grating_stepsize = 1005;
    // grating step size
    int grating_numsteps = 1025;
    // number of grating steps in one direction
    int grating_numramps = 2;
    // number of ramps per grating position
    int readoutsperramp = 64;
    // number of readouts per ramp
    int num_updown = 1;
    // number of grating updown scans
    int grat_def = 496000;
    // position of grating after the scan
    int chop_pos_CS1 = -21350;
    int chop_pos_CS2 = 21200;
    int detector = 1;
    // Synchronize on this detector 1:Blue 2:Red
    int nb_CS1_CS2 = 0;
    // number of cycles on calsources, 0=don't use them
    int nb_ramps_CS = 3;
    // number of ramps on CSs
    int grat_start_time = 15000;
    // time for grating to start [ms]
    int grat_def_time = 15000;
    // time for grating to go to default [ms]  
    //
    // CRE settings
    int ramp_len_blu = readoutsperramp;
    int ramp_len_red = readoutsperramp;
    // Set up the blue and red CRE subsystem
    // cre_ctrl is a bit field:
    // 256=sync width=2, 128=T sensor on, 2=enable, 1=power on
    // Do not enable yet
    int cre_ctrl_red = 256 + 128 + 2 + 1;
    int cre_ctrl_blu = 256 + 128 + 2 + 1;
    // Give ENG values for the bias [v]
    double bias_r_blu = 0.01;
    double bias_r_red = 0.01;
    double bias_d_blu = 0.1;
    double bias_d_red = 0.042;
    // 
    // SPU parameters
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int nb_samp_subramp_blu = 64;
    // Nb of blue samples per sub-ramp 
    int nb_samp_subramp_red = 64;
    // Nb of red samples per sub-ramp 
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    // Reset SPU 
    // Move the filter wheel to Position B 
    SPEC_fltw_move("POS B");
    // internal flux check for filter B
    SPEC_fluxref("CS2","B");
    // Write CRE parameters for scan
    SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // Re-start SPU in default mode
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //
    // Scan in filter B
    OBCP_grat_scan_nochop(num_updown,grating_numsteps,grating_stepsize,-grating_stepsize,grating_numramps,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,nb_ramps_CS,grating_numsteps,chop_def,detector,grating_start,grat_start_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,readoutsperramp);
    //
    // Reset spu 
    SPEC_spu_reset();
    // Move the filter wheel to Position A
    SPEC_fltw_move("POS A");
    // Flux check for filter A
    SPEC_fluxref("CS2","A");
    // Write CRE parameters for scan
    SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // Re-start SPU in default mode
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //
    // Scan in filter A
    OBCP_grat_scan_nochop(num_updown,grating_numsteps,grating_stepsize,-grating_stepsize,grating_numramps,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,nb_ramps_CS,grating_numsteps,chop_def,detector,grating_start,grat_start_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,readoutsperramp);
    //
    // Reset spu 
    SPEC_spu_reset();
}

// File          : PACS_Phot_Sequencer_SetupNew.cus
// Missionphase  : PACS ILT3
//
// Purpose       : Loading the sequencer to build up the signal (OBMO)
//                 for normal DDCS mode
//
// Author        : E.Doumayrou & L.Rodriguez
// CUSification  : K.Okumura
// Arguments     : none
//                 
//
// Description   : This script will set the sequencer, which is building
//                 up the final signal and it sets the data mode
//                 to "Bolo & HK".
//                 This script should be executed just after the
//                 switch-on procedure, the BOLC initialisation
//                 and the bias settings (polarizer)
//                              
// Comments      : New! The values are set to decrease the noise in DDCS mode
//                 1.1 Also switch off VSMS during CKRL/VDECX switching
//
// Version       : 1.0
// History       : 1.0 14-Jun-2007 KO initial version with input from ED & LR
//                 1.1 16-Jun-2007 KO new set of values from ED & LR
//
procedure PACS_Phot_Sequencer_SetupNew {
}{
    // ------------------------------------------------------------
    // ------------------------------------------------------------
    // New sequencer to decrease the noise in DCSS mode
    // ------------------------------------------------------------
    // ------------------------------------------------------------
    // Set clock mux stop
    //# P 09 00 00 00
    int operand = 0x9000000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 0 time 0 clk 20
    //# P 0C 00 0014
    operand = 0xc000014;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 1 time 35 clk 52
    //# P 0C 01 11B4
    operand = 0xc0111b4;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 2
    //# P 0C 02 4174
    operand = 0xc024174;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 3
    //# P 0C 03 4A54
    operand = 0xc034a54;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 4
    //# P 0C 04 4CC4
    operand = 0xc044cc4;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 5
    //# P 0C 05 4FCC
    operand = 0xc054fcc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 6
    //# P 0C 06 526C
    operand = 0xc06526c;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 7
    //# P 0C 07 84AC
    operand = 0xc0784ac;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 8
    //# P 0C 08 8E8C
    operand = 0xc088e8c;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table 9
    //# P 0C 09 9104
    operand = 0xc099104;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table A
    //# P 0C 0A 9314
    operand = 0xc0a9314;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set seq param table B
    //# P 0C 0B A100
    operand = 0xc0ba100;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set clock mux sequencer
    //# P 09 00 00 01
    operand = 0x9000001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

block Pacs_CcuMonitorStartRecycle PACS 2102 {
}{
    PacsCcuMonitorPeriodRecycle();
    sync();
}

// $Id:
// Purpose       : Set BBID to its required value to indicate the end
//                 of current BB execution (see FIRST-FSC-DOC-0200) 
//                 and Delay Science Block afetr Cal block
//
// CUS script    : Vanessa Doublier-Pritchard
//
// Input arguments: delay
//
// Description   : BBID will be set to its specicifc delay
//
// Comments      : Needed for SCR PACS-2039
//
// Version       : 16-sep-2009 1.0 VD Creation
//
block PacsBbDelayScience PACS 1103 {
    int nDelay = 4;
}{
    // Write BBID to DEC/MEC
    Pacs_DMC_SET_BBID($BBID);
    delay(nDelay);
    Pacs_DMC_SET_BBID(0x40000000);
}

// File          : PACS_AF15_Test_Setup.cus
// Missionphase  : PACS PV phase
//
// Purpose       : Enable AF15 to monitor 12 Bolometer VSS currents
//
// Author        : T. Mueller
// CUSification  : TM
// Arguments     :
//
// Description   : Enable AF15 to monitor 12 Bolometer VSS currents
//               
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 07-Jul-2009 initial version by TM
//                 
procedure PACS_AF15_Test_Setup {
}{
    // Pacs_DPU_SET_FUNCT   
    //       DPU_FUNCT_ID  Dec 100
    //       DPU_ACTIVITY_ID  Dec 6
    //       DPU_STRUCTURE_ID Dec 2
    //       DPU_INT_FUNCT_ID Dec 15   (EVENT_BOL_I_RO)
    //       ENABLE_DISABLE   Dec 1    (ENABLE)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","ENABLE");
    delay(300);
    //------------------
    // End of procedure
    //------------------
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req.1.1.1 for the Commissioning Phase
//           Check the bias/signal relationship using telescope background
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_lowGainBias2_direct
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_low_OD46"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_low_OD46"; // Bias table containing the final values
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_lowGainBias2_direct
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_CommPh_lowGainBias2(1, "LOW")
//
// Version : Wed Jun 24 12:56:45 EDT 2009
//
obs PacsCal_Phot_lowGainBias2_direct {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_low_OD46"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_low_OD46"; // Bias table containing the final values
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(endBiasTable,"DIRECT","LOW"));
    int timeCal3CPR1 = duration(Pacs_OBCP_chopped_photometry2(nLoops1,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    //Minimum slew time
    int tslewmin = timeOBSID + timeSetBias + timeCal3CPR1;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeSetBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_lowGainBias2_direct(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops1,664,15,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,15,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            //  Call the Phot_lowGainBias2_direct
            //************************************
            Phot_lowGainBias2_direct(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,15,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
//
// Purpose	: Move chopper to absolute position
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The building block containing the instrumental command 
//                     for move chopper to absolute position is called.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and chopper enabled.
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 2.0
// 
// History 	: 1.0 15-04-05 creation by HD
//                1.1 25-Apr-2005 HF, added OBSID and EndID calls
//                1.2 19-jun-2007 Renamed to xxxx_OBS for naming uniformity
// 		: 2.0  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Chop_mov_abs {
    /* Needed variables to call PacsEng_Chop_mov_abs                        */
    int chop_abs_pos = 0; // chopper absolute position
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Chop_mov_abs                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Chop_mov_abs(chop_abs_pos)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Chop_mov_abs(chop_abs_pos);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       :  EMC reset activities
//                  
//                 
//
// TCL author    : HF
// TCL file      : 
// CUS author    : HF 
// Script file   : ENTER_SAFE_Mode.txt 
//
// Input arguments none
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Transit to SAFE mode
//                            
//                           
//                            
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                             
//                 
// Comments      : 
//
// Version	: 2.0  
// History       : 1.0 29-Mar-2005 creation by HF
//              : 2.0  04-Mar-2008  Converted into Eng OBS by VDP
//
//
obs PacsEng_ENTER_SAFE_Mode {
    /* Needed variables to call PacsEng_ENTER_SAFE_Mode                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_ENTER_SAFE_Mode                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(OBCP_SAFE()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            OBCP_SAFE();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id: PacsEng_Spec_Dark_CS_SimultaneousWarmUp.txt,v 1.1 2008/11/12 16:46:30 pierre Exp $
// Missionphase  :  PACS FM IST SOVT2 & PV Phase
//
//
// Purpose      : Schedule the associated CUS procedure
//
// Author       : PRoyer
// CUS script   : PR
// CVS file     :
//
// Arguments    : 
//
//
// Description  : 
//
// Dependencies :  
//
// Preconditions: 
//	- PACS is switched on
//	- Setup spectroscopy with cold calibration sources
//
// Comments: 
//
// Version: 1.0
//
// History : 1.0 12-Nov-2008 Created from the corresponding PacsCal & from PacsEng_Spec_GeGa_Loop_Comm
//
//
obs PacsEng_Spec_Dark_CS_SimultaneousWarmUp {
    /* Needed variables to call PacsEng_Spec_Dark_CS_SimultaneousWarmUp                        */
    int obs_time = 540; // Observing time per CS/FW/Grating setting
    int chop_time = 180; // Chopper plateau [sec] during CS temp rise time (0 = no chopping)
    /* End of needed variables for PacsEng_Spec_Dark_CS_SimultaneousWarmUp                     */
}{
    debug_print("obs PacsEng_Spec_Dark_CS_SimultaneousWarmUp. Version 1.0. 20081112");
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Dark_CS_SimultaneousWarmUp(obs_time,chop_time)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic.
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Dark_CS_SimultaneousWarmUp(obs_time,chop_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Spec_Gra_Mec_Setup.cus
// Missionphase  : PACS FM ILT
//
// Purpose       : Prepare grating mechanism
//
// Author        : P. Royer
//
// Arguments     :  CALIBRATION TABLE (CONFGrat)
//		    ROW of CALU table (CONFGrat)
//		   	Row of this table = instrument version
//
// Description   : This script will switch on and set all required
//                 parameters for the grating
//                              
// Comments      :      
//
// Version       : 1.0
// History       : 1.0 / 13-Jun-2006 created from a non-calu-using script
//                    1.1 / 08-Nov-2006 Additional delay after setting the inductosyn amplitude
//
procedure PACS_Spec_Gra_Mec_Setup {
    string calUname = "CONFGrat"; // GRATING CALIBRATION TABLE
    string calUrow = "FMILT"; // INSTRUMENT VERSION
}{
    //
    // Grating home mode: 0 = move to neg. positions; 1 = move to pos. positions
    int grat_home_mode = 1;
    // Grating central position (rough)
    int grat_center_pos = 500000;
    //
    //----------------------
    // CONTROLLER PARAMETERS
    //----------------------
    //
    PACS_Spec_Gra_Conf_Calu(calUname,calUrow);
    //
    //----------------------
    // ADDITIONAL PARAMETERS
    //----------------------
    //
    // ADDITIONAL PARAMS : 1. GRATING INDUCTOSYN AMPLITUDE
    //
    int induct_ampl = ilookup(calUname,calUrow,"InductAmpl");
    {int}[] list_tuple = [{induct_ampl}];
    int[] list_int = [induct_ampl];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_INDUC_AMPL(list_tuple,chksum);
    delay(1);
    //
    // ADDITIONAL PARAMS : 2. HALL SENSOR OFFSET
    //
    int hall_offset = ilookup(calUname,calUrow,"HallOffset");
    list_tuple = [{hall_offset}];
    list_int = [hall_offset];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_HALLOFFSET(list_tuple,chksum);
    delay(1);
    //
    // ADDITIONAL PARAMS : 3. GRATING RANGE
    //
    int range = ilookup(calUname,calUrow,"Range");
    list_tuple = [{range}];
    list_int = [range];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_RANGE(list_tuple,chksum);
    delay(1);
    //
    // DELAY NECESSARY FOR FM ILT (CAN BE SUPPRESSED IN FLIGHT, when correct value is defaulted in OBSW)
    // NECESSARY WAIT TIME AFTER SETTING THE AMPLITUDE
    //
    delay(120);
    //
    // ----------------------------
    // SWITCH ON GRATING CONTROLLER
    // ----------------------------
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    //
    // ENABLE GRATING CONTROLLER
    Pacs_DMC_ENABLE_GRAT_CONT();
    delay(1);
    //
    // ----------------
    // HOME THE GRATING
    // ----------------
    // Search for the origin and initialize the position encoder correctly
    // PARAM: 0 = move towards negative positions;
    //        1 = move towards positive positions;
    // Duration: max 70 sec (if the Grating param 'rate' is 3), 
    //           depending on the initial position of the grating.
    // Failure code: 0xAA: Grating controller is not enabled
    //
    string[] homeMode = ["NEGATIVE","POSITIVE"];
    Pacs_DMC_HOME_GRAT(homeMode[grat_home_mode]);
    delay(70);
    //
    // MOVE GRATING TO CENTER
    Pacs_DMC_MOVE_GRAT_ABS(grat_center_pos);
    delay(30);
    //-------------------------
    // End of Procedure
    //-------------------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       : Disable all regular HK for FDIR Test
//                 
//
// Author        : Helmut Feuchtgruber
//
// Arguments     : None
//
// Description   : use Service 14 for nominal HK and a memory load for the essential
//
// Dependencies  : Disable_HK
//
// Comments      : 
//
// Version       : 2.0 
// History       : 1.0 27-Mar-2007 initial Version 
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Disable_HK {
    /* Needed variables to call PacsEng_Disable_HK                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Disable_HK                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Disable_HK()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Disable_HK();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req. None during the Commissioning Phase
//           Short exploration of all the biases used in preview
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_prePreview
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + PHOT_orbit_prologue is executed
//
// Description :
//   + Set the blue filter 100um
//   + Set the biases group by group
//   + Set the chopper on the optical center
//   +   Loop over 1 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   + Set the blue filter 70um
//   +   Loop over 1 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_prePreview(1, "LOW")
//            New version
//
// Version : Sun Jun 07 16:52:52 EDT 2009
//
procedure Phot_prePreview {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
}{
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //*************************************************
    // Set the biases and start SPU, then set the gain
    //*************************************************
    //
    PHOT_set_biases(startBiasTable,"DIRECT","LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position 664
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Fluxes 1.00pW on the green and 1.00pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.188023941895642 Volts
    Pacs_BOLC_SET_VH_G1(2.188023941895642);
    // Set group 1 bol bias 02 (VL) to -0.2119760581043576 Volts
    Pacs_BOLC_SET_VL_G1(-0.2119760581043576);
    // Set group 1 bol bias 03 (VRL) to 0.5792130362737066 Volts
    Pacs_BOLC_SET_VRL_G1(0.5792130362737066);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0118334263256505 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0118334263256505);
    // Set group 2 bol bias 01 (VH) to 2.168140262013536 Volts
    Pacs_BOLC_SET_VH_G2(2.168140262013536);
    // Set group 2 bol bias 02 (VL) to -0.23185973798646387 Volts
    Pacs_BOLC_SET_VL_G2(-0.23185973798646387);
    // Set group 2 bol bias 03 (VRL) to 0.5768079444184409 Volts
    Pacs_BOLC_SET_VRL_G2(0.5768079444184409);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.008992942560805 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.008992942560805);
    // Set group 3 bol bias 01 (VH) to 2.1725277892051422 Volts
    Pacs_BOLC_SET_VH_G3(2.1725277892051422);
    // Set group 3 bol bias 02 (VL) to -0.22747221079485758 Volts
    Pacs_BOLC_SET_VL_G3(-0.22747221079485758);
    // Set group 3 bol bias 03 (VRL) to 0.5845666562137258 Volts
    Pacs_BOLC_SET_VRL_G3(0.5845666562137258);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0169525299193807 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0169525299193807);
    // Set group 4 bol bias 01 (VH) to 2.1563572765727077 Volts
    Pacs_BOLC_SET_VH_G4(2.1563572765727077);
    // Set group 4 bol bias 02 (VL) to -0.24364272342729232 Volts
    Pacs_BOLC_SET_VL_G4(-0.24364272342729232);
    // Set group 4 bol bias 03 (VRL) to 0.5396301176900922 Volts
    Pacs_BOLC_SET_VRL_G4(0.5396301176900922);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9742177344988572 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9742177344988572);
    // Set group 5 bol bias 01 (VH) to 1.773869442864505 Volts
    Pacs_BOLC_SET_VH_G5(1.773869442864505);
    // Set group 5 bol bias 02 (VL) to -0.22613055713549512 Volts
    Pacs_BOLC_SET_VL_G5(-0.22613055713549512);
    // Set group 5 bol bias 03 (VRL) to 0.6038540729107426 Volts
    Pacs_BOLC_SET_VRL_G5(0.6038540729107426);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0302874109443203 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0302874109443203);
    // Set group 6 bol bias 01 (VH) to 1.7657376153832673 Volts
    Pacs_BOLC_SET_VH_G6(1.7657376153832673);
    // Set group 6 bol bias 02 (VL) to -0.23426238461673266 Volts
    Pacs_BOLC_SET_VL_G6(-0.23426238461673266);
    // Set group 6 bol bias 03 (VRL) to 0.5752260745437106 Volts
    Pacs_BOLC_SET_VRL_G6(0.5752260745437106);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0004178568036832 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0004178568036832);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    //**********************************************************************
    //                       Measurement
    // Fluxes 5.00pW on the green and 5.00pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.295828680824288 Volts
    Pacs_BOLC_SET_VH_G1(2.295828680824288);
    // Set group 1 bol bias 02 (VL) to -0.10417131917571198 Volts
    Pacs_BOLC_SET_VL_G1(-0.10417131917571198);
    // Set group 1 bol bias 03 (VRL) to 0.5437536546448385 Volts
    Pacs_BOLC_SET_VRL_G1(0.5437536546448385);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9768671457202651 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9768671457202651);
    // Set group 2 bol bias 01 (VH) to 2.273846430978376 Volts
    Pacs_BOLC_SET_VH_G2(2.273846430978376);
    // Set group 2 bol bias 02 (VL) to -0.126153569021624 Volts
    Pacs_BOLC_SET_VL_G2(-0.126153569021624);
    // Set group 2 bol bias 03 (VRL) to 0.5561901874707269 Volts
    Pacs_BOLC_SET_VRL_G2(0.5561901874707269);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9887928130949397 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9887928130949397);
    // Set group 3 bol bias 01 (VH) to 2.292603255682727 Volts
    Pacs_BOLC_SET_VH_G3(2.292603255682727);
    // Set group 3 bol bias 02 (VL) to -0.10739674431727275 Volts
    Pacs_BOLC_SET_VL_G3(-0.10739674431727275);
    // Set group 3 bol bias 03 (VRL) to 0.5700616894772873 Volts
    Pacs_BOLC_SET_VRL_G3(0.5700616894772873);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.002620856556083 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.002620856556083);
    // Set group 4 bol bias 01 (VH) to 2.2670192431069673 Volts
    Pacs_BOLC_SET_VH_G4(2.2670192431069673);
    // Set group 4 bol bias 02 (VL) to -0.13298075689303268 Volts
    Pacs_BOLC_SET_VL_G4(-0.13298075689303268);
    // Set group 4 bol bias 03 (VRL) to 0.5186000298414586 Volts
    Pacs_BOLC_SET_VRL_G4(0.5186000298414586);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9535197513961629 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9535197513961629);
    // Set group 5 bol bias 01 (VH) to 1.8832354317617566 Volts
    Pacs_BOLC_SET_VH_G5(1.8832354317617566);
    // Set group 5 bol bias 02 (VL) to -0.11676456823824355 Volts
    Pacs_BOLC_SET_VL_G5(-0.11676456823824355);
    // Set group 5 bol bias 03 (VRL) to 0.5884637576607907 Volts
    Pacs_BOLC_SET_VRL_G5(0.5884637576607907);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.015054900093189 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.015054900093189);
    // Set group 6 bol bias 01 (VH) to 1.8648505520676595 Volts
    Pacs_BOLC_SET_VH_G6(1.8648505520676595);
    // Set group 6 bol bias 02 (VL) to -0.13514944793234052 Volts
    Pacs_BOLC_SET_VL_G6(-0.13514944793234052);
    // Set group 6 bol bias 03 (VRL) to 0.5539283480062471 Volts
    Pacs_BOLC_SET_VRL_G6(0.5539283480062471);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9795350841099772 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9795350841099772);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    //**********************************************************************
    //                       Measurement
    // Fluxes 8.00pW on the green and 9.00pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3626748538269005 Volts
    Pacs_BOLC_SET_VH_G1(2.3626748538269005);
    // Set group 1 bol bias 02 (VL) to -0.037325146173099344 Volts
    Pacs_BOLC_SET_VL_G1(-0.037325146173099344);
    // Set group 1 bol bias 03 (VRL) to 0.5303173755517996 Volts
    Pacs_BOLC_SET_VRL_G1(0.5303173755517996);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9636165293117853 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9636165293117853);
    // Set group 2 bol bias 01 (VH) to 2.33787073504465 Volts
    Pacs_BOLC_SET_VH_G2(2.33787073504465);
    // Set group 2 bol bias 02 (VL) to -0.06212926495534987 Volts
    Pacs_BOLC_SET_VL_G2(-0.06212926495534987);
    // Set group 2 bol bias 03 (VRL) to 0.5477127604768299 Volts
    Pacs_BOLC_SET_VRL_G2(0.5477127604768299);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.980497190239408 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.980497190239408);
    // Set group 3 bol bias 01 (VH) to 2.3664037207509665 Volts
    Pacs_BOLC_SET_VH_G3(2.3664037207509665);
    // Set group 3 bol bias 02 (VL) to -0.03359627924903341 Volts
    Pacs_BOLC_SET_VL_G3(-0.03359627924903341);
    // Set group 3 bol bias 03 (VRL) to 0.5660763147370259 Volts
    Pacs_BOLC_SET_VRL_G3(0.5660763147370259);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.998709539255328 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.998709539255328);
    // Set group 4 bol bias 01 (VH) to 2.3339481230796837 Volts
    Pacs_BOLC_SET_VH_G4(2.3339481230796837);
    // Set group 4 bol bias 02 (VL) to -0.066051876920316 Volts
    Pacs_BOLC_SET_VL_G4(-0.066051876920316);
    // Set group 4 bol bias 03 (VRL) to 0.5097094552074399 Volts
    Pacs_BOLC_SET_VRL_G4(0.5097094552074399);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9447624937386496 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9447624937386496);
    // Set group 5 bol bias 01 (VH) to 1.9632137389756883 Volts
    Pacs_BOLC_SET_VH_G5(1.9632137389756883);
    // Set group 5 bol bias 02 (VL) to -0.036786261024311706 Volts
    Pacs_BOLC_SET_VL_G5(-0.036786261024311706);
    // Set group 5 bol bias 03 (VRL) to 0.5794927331333275 Volts
    Pacs_BOLC_SET_VRL_G5(0.5794927331333275);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0061678303155763 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0061678303155763);
    // Set group 6 bol bias 01 (VH) to 1.9404169823203001 Volts
    Pacs_BOLC_SET_VH_G6(1.9404169823203001);
    // Set group 6 bol bias 02 (VL) to -0.05958301767969998 Volts
    Pacs_BOLC_SET_VL_G6(-0.05958301767969998);
    // Set group 6 bol bias 03 (VRL) to 0.5414144672793326 Volts
    Pacs_BOLC_SET_VRL_G6(0.5414144672793326);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.967235044824026 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.967235044824026);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    //**********************************************************************
    //                       Measurement
    // Fluxes 10.00pW on the green and 13.00pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.39 Volts
    Pacs_BOLC_SET_VH_G1(2.39);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.5045999971434033 Volts
    Pacs_BOLC_SET_VRL_G1(0.5045999971434033);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9383191070735781 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9383191070735781);
    // Set group 2 bol bias 01 (VH) to 2.380145605779282 Volts
    Pacs_BOLC_SET_VH_G2(2.380145605779282);
    // Set group 2 bol bias 02 (VL) to -0.019854394220717775 Volts
    Pacs_BOLC_SET_VL_G2(-0.019854394220717775);
    // Set group 2 bol bias 03 (VRL) to 0.5422312335131889 Volts
    Pacs_BOLC_SET_VRL_G2(0.5422312335131889);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9751316950075646 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9751316950075646);
    // Set group 3 bol bias 01 (VH) to 2.39 Volts
    Pacs_BOLC_SET_VH_G3(2.39);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.5381738704293105 Volts
    Pacs_BOLC_SET_VRL_G3(0.5381738704293105);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9713376278036194 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9713376278036194);
    // Set group 4 bol bias 01 (VH) to 2.3785064412620516 Volts
    Pacs_BOLC_SET_VH_G4(2.3785064412620516);
    // Set group 4 bol bias 02 (VL) to -0.021493558737948337 Volts
    Pacs_BOLC_SET_VL_G4(-0.021493558737948337);
    // Set group 4 bol bias 03 (VRL) to 0.5043041147959068 Volts
    Pacs_BOLC_SET_VRL_G4(0.5043041147959068);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9394388995453165 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9394388995453165);
    // Set group 5 bol bias 01 (VH) to 1.99 Volts
    Pacs_BOLC_SET_VH_G5(1.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.5410967021397044 Volts
    Pacs_BOLC_SET_VRL_G5(0.5410967021397044);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.9684017395455966 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.9684017395455966);
    // Set group 6 bol bias 01 (VH) to 1.99 Volts
    Pacs_BOLC_SET_VH_G6(1.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.5259202658431701 Volts
    Pacs_BOLC_SET_VRL_G6(0.5259202658431701);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9520087411615752 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9520087411615752);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //*******************************
    // Select Filter B (70 microns)
    //*******************************
    //
    PHOT_fltw_move("POS B");
    //
    //
    //**********************************************************************
    //                       Measurement
    // Fluxes 2.00pW on the blue and 1.00pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2172657559897315 Volts
    Pacs_BOLC_SET_VH_G1(2.2172657559897315);
    // Set group 1 bol bias 02 (VL) to -0.1827342440102686 Volts
    Pacs_BOLC_SET_VL_G1(-0.1827342440102686);
    // Set group 1 bol bias 03 (VRL) to 0.5672727148127518 Volts
    Pacs_BOLC_SET_VRL_G1(0.5672727148127518);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0000761093305046 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0000761093305046);
    // Set group 2 bol bias 01 (VH) to 2.1974276447987626 Volts
    Pacs_BOLC_SET_VH_G2(2.1974276447987626);
    // Set group 2 bol bias 02 (VL) to -0.2025723552012374 Volts
    Pacs_BOLC_SET_VL_G2(-0.2025723552012374);
    // Set group 2 bol bias 03 (VRL) to 0.5703556371419088 Volts
    Pacs_BOLC_SET_VRL_G2(0.5703556371419088);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.002642426671661 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.002642426671661);
    // Set group 3 bol bias 01 (VH) to 2.205020948730773 Volts
    Pacs_BOLC_SET_VH_G3(2.205020948730773);
    // Set group 3 bol bias 02 (VL) to -0.194979051269227 Volts
    Pacs_BOLC_SET_VL_G3(-0.194979051269227);
    // Set group 3 bol bias 03 (VRL) to 0.5789044932202722 Volts
    Pacs_BOLC_SET_VRL_G3(0.5789044932202722);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.011357576782093 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.011357576782093);
    // Set group 4 bol bias 01 (VH) to 2.186828583150386 Volts
    Pacs_BOLC_SET_VH_G4(2.186828583150386);
    // Set group 4 bol bias 02 (VL) to -0.21317141684961383 Volts
    Pacs_BOLC_SET_VL_G4(-0.21317141684961383);
    // Set group 4 bol bias 03 (VRL) to 0.5325812292924039 Volts
    Pacs_BOLC_SET_VRL_G4(0.5325812292924039);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9672941603403928 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9672941603403928);
    // Set group 5 bol bias 01 (VH) to 1.773869442864505 Volts
    Pacs_BOLC_SET_VH_G5(1.773869442864505);
    // Set group 5 bol bias 02 (VL) to -0.22613055713549512 Volts
    Pacs_BOLC_SET_VL_G5(-0.22613055713549512);
    // Set group 5 bol bias 03 (VRL) to 0.6038540729107426 Volts
    Pacs_BOLC_SET_VRL_G5(0.6038540729107426);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0302874109443203 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0302874109443203);
    // Set group 6 bol bias 01 (VH) to 1.7657376153832673 Volts
    Pacs_BOLC_SET_VH_G6(1.7657376153832673);
    // Set group 6 bol bias 02 (VL) to -0.23426238461673266 Volts
    Pacs_BOLC_SET_VL_G6(-0.23426238461673266);
    // Set group 6 bol bias 03 (VRL) to 0.5752260745437106 Volts
    Pacs_BOLC_SET_VRL_G6(0.5752260745437106);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0004178568036832 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0004178568036832);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    //**********************************************************************
    //                       Measurement
    // Fluxes 6.00pW on the blue and 5.00pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.318146944306358 Volts
    Pacs_BOLC_SET_VH_G1(2.318146944306358);
    // Set group 1 bol bias 02 (VL) to -0.08185305569364176 Volts
    Pacs_BOLC_SET_VL_G1(-0.08185305569364176);
    // Set group 1 bol bias 03 (VRL) to 0.5388320784881557 Volts
    Pacs_BOLC_SET_VRL_G1(0.5388320784881557);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.972009781132206 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.972009781132206);
    // Set group 2 bol bias 01 (VH) to 2.295595789445418 Volts
    Pacs_BOLC_SET_VH_G2(2.295595789445418);
    // Set group 2 bol bias 02 (VL) to -0.10440421055458171 Volts
    Pacs_BOLC_SET_VL_G2(-0.10440421055458171);
    // Set group 2 bol bias 03 (VRL) to 0.5531943186562807 Volts
    Pacs_BOLC_SET_VRL_G2(0.5531943186562807);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.985861519568982 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.985861519568982);
    // Set group 3 bol bias 01 (VH) to 2.3174307976046897 Volts
    Pacs_BOLC_SET_VH_G3(2.3174307976046897);
    // Set group 3 bol bias 02 (VL) to -0.08256920239531018 Volts
    Pacs_BOLC_SET_VL_G3(-0.08256920239531018);
    // Set group 3 bol bias 03 (VRL) to 0.5686021808737526 Volts
    Pacs_BOLC_SET_VRL_G3(0.5686021808737526);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.001182414525746 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.001182414525746);
    // Set group 4 bol bias 01 (VH) to 2.289389793796455 Volts
    Pacs_BOLC_SET_VH_G4(2.289389793796455);
    // Set group 4 bol bias 02 (VL) to -0.11061020620354478 Volts
    Pacs_BOLC_SET_VL_G4(-0.11061020620354478);
    // Set group 4 bol bias 03 (VRL) to 0.5151148914368677 Volts
    Pacs_BOLC_SET_VRL_G4(0.5151148914368677);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9500867051631081 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9500867051631081);
    // Set group 5 bol bias 01 (VH) to 1.8832354317617566 Volts
    Pacs_BOLC_SET_VH_G5(1.8832354317617566);
    // Set group 5 bol bias 02 (VL) to -0.11676456823824355 Volts
    Pacs_BOLC_SET_VL_G5(-0.11676456823824355);
    // Set group 5 bol bias 03 (VRL) to 0.5884637576607907 Volts
    Pacs_BOLC_SET_VRL_G5(0.5884637576607907);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.015054900093189 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.015054900093189);
    // Set group 6 bol bias 01 (VH) to 1.8648505520676595 Volts
    Pacs_BOLC_SET_VH_G6(1.8648505520676595);
    // Set group 6 bol bias 02 (VL) to -0.13514944793234052 Volts
    Pacs_BOLC_SET_VL_G6(-0.13514944793234052);
    // Set group 6 bol bias 03 (VRL) to 0.5539283480062471 Volts
    Pacs_BOLC_SET_VRL_G6(0.5539283480062471);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9795350841099772 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9795350841099772);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    //**********************************************************************
    //                       Measurement
    // Fluxes 9.00pW on the blue and 9.00pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.384938805304766 Volts
    Pacs_BOLC_SET_VH_G1(2.384938805304766);
    // Set group 1 bol bias 02 (VL) to -0.015061194695234037 Volts
    Pacs_BOLC_SET_VL_G1(-0.015061194695234037);
    // Set group 1 bol bias 03 (VRL) to 0.5260600647389171 Volts
    Pacs_BOLC_SET_VRL_G1(0.5260600647389171);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9594273604678216 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9594273604678216);
    // Set group 2 bol bias 01 (VH) to 2.359008170411966 Volts
    Pacs_BOLC_SET_VH_G2(2.359008170411966);
    // Set group 2 bol bias 02 (VL) to -0.04099182958803371 Volts
    Pacs_BOLC_SET_VL_G2(-0.04099182958803371);
    // Set group 2 bol bias 03 (VRL) to 0.5449719969950095 Volts
    Pacs_BOLC_SET_VRL_G2(0.5449719969950095);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9778145922043888 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9778145922043888);
    // Set group 3 bol bias 01 (VH) to 2.39 Volts
    Pacs_BOLC_SET_VH_G3(2.39);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.5639232322076849 Volts
    Pacs_BOLC_SET_VRL_G3(0.5639232322076849);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.996597916290843 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.996597916290843);
    // Set group 4 bol bias 01 (VH) to 2.3562272821708676 Volts
    Pacs_BOLC_SET_VH_G4(2.3562272821708676);
    // Set group 4 bol bias 02 (VL) to -0.04377271782913206 Volts
    Pacs_BOLC_SET_VL_G4(-0.04377271782913206);
    // Set group 4 bol bias 03 (VRL) to 0.5070067850016735 Volts
    Pacs_BOLC_SET_VRL_G4(0.5070067850016735);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9421006312907465 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9421006312907465);
    // Set group 5 bol bias 01 (VH) to 1.9632137389756883 Volts
    Pacs_BOLC_SET_VH_G5(1.9632137389756883);
    // Set group 5 bol bias 02 (VL) to -0.036786261024311706 Volts
    Pacs_BOLC_SET_VL_G5(-0.036786261024311706);
    // Set group 5 bol bias 03 (VRL) to 0.5794927331333275 Volts
    Pacs_BOLC_SET_VRL_G5(0.5794927331333275);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0061678303155763 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0061678303155763);
    // Set group 6 bol bias 01 (VH) to 1.9404169823203001 Volts
    Pacs_BOLC_SET_VH_G6(1.9404169823203001);
    // Set group 6 bol bias 02 (VL) to -0.05958301767969998 Volts
    Pacs_BOLC_SET_VL_G6(-0.05958301767969998);
    // Set group 6 bol bias 03 (VRL) to 0.5414144672793326 Volts
    Pacs_BOLC_SET_VRL_G6(0.5414144672793326);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.967235044824026 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.967235044824026);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    //**********************************************************************
    //                       Measurement
    // Fluxes 11.00pW on the blue and 13.00pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.39 Volts
    Pacs_BOLC_SET_VH_G1(2.39);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.47807873485265556 Volts
    Pacs_BOLC_SET_VRL_G1(0.47807873485265556);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.912151740491099 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.912151740491099);
    // Set group 2 bol bias 01 (VH) to 2.39 Volts
    Pacs_BOLC_SET_VH_G2(2.39);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.5282074288847702 Volts
    Pacs_BOLC_SET_VRL_G2(0.5282074288847702);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9613842491939912 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9613842491939912);
    // Set group 3 bol bias 01 (VH) to 2.39 Volts
    Pacs_BOLC_SET_VH_G3(2.39);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.5124245086509361 Volts
    Pacs_BOLC_SET_VRL_G3(0.5124245086509361);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.945922079810452 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.945922079810452);
    // Set group 4 bol bias 01 (VH) to 2.39 Volts
    Pacs_BOLC_SET_VH_G4(2.39);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.4908158442369046 Volts
    Pacs_BOLC_SET_VRL_G4(0.4908158442369046);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.926219602118351 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.926219602118351);
    // Set group 5 bol bias 01 (VH) to 1.99 Volts
    Pacs_BOLC_SET_VH_G5(1.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.5410967021397044 Volts
    Pacs_BOLC_SET_VRL_G5(0.5410967021397044);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.9684017395455966 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.9684017395455966);
    // Set group 6 bol bias 01 (VH) to 1.99 Volts
    Pacs_BOLC_SET_VH_G6(1.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.5259202658431701 Volts
    Pacs_BOLC_SET_VRL_G6(0.5259202658431701);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9520087411615752 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9520087411615752);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //********************************
    // Epilogue : Set the safe biases
    //********************************
    PHOT_set_bias_volt(endBiasTable,1);
    PHOT_set_bias_volt(endBiasTable,2);
    PHOT_set_bias_volt(endBiasTable,3);
    PHOT_set_bias_volt(endBiasTable,4);
    PHOT_set_bias_volt(endBiasTable,5);
    PHOT_set_bias_volt(endBiasTable,6);
    //
    // sync the bus
    sync();
}

// Missionphase  : 
//
// Purpose       : Set gain "HIGH" or "LOW" for the BOLO electronics
//                  
//                 
//
// TCL author    : 
// TCL file      : tm_phot_set_gain.tcl
// CUS author    : 
// Script file   : PHOT_set_gain.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : This script will activate the LOW or HIGH gain modes
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-apr-2005 DAC.
// 
int[] procedure PHOT_set_gain {
    string set_gain = "LOW" in ["LOW","HIGH"]; // Set electronics gain
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    Pacs_BOLC_SET_GAIN(set_gain);
    // Time spent
    int duree_TCs = time() - time_start;
    duree_OVR = duree_TCs;
    duree_num = duree_OVR;
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    sync();

    return time_array;
}

// Missionphase  : FM
//
// Purpose	:  Setup diagnostic housekeeping for the FM 
//                 chopper tests. Special HKs.
//                  
// Author	: Markus Nielbock
// CUS author 	: MN
//
// Description	: Set up 5 housekeeping parameter for diagnostic housekeeping 
//	  of the chopper for open loop tests.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and SPEC_Chop_fft_eqmimt_obs
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 1.0	
// 
// History 	: 
//	  1.0 29-03-07 MN. Spec. HK for open loop measurements.
//        1.1 21-jan-2008 DAC Added WiteEndBB
//
block SPEC_Chopper_dhk_5hk_1khz_bb PACS 474 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //-------------------------------------------- 
    // Setup and start diagnostic HK for Chopper
    //-------------------------------------------- 
    int chop_diag_hk_length = 6;
    {int}[] parlist = [{209},{244},{245},{258},{561},{0xffff}];
    int[] aux = [209,244,245,258,561,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(chop_diag_hk_length,parlist,check_sum);
    int diag_hk_period = 0;
    // Synchronize diagnostic HK on blue spectrometer readouts
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark end of BB
    WriteEndBB();
    sync();
}

// Mission phase : PV Phase
//
// Purpose : PCD req.1.1.18 for the PV Phase
//           Measure the level of the electronical cross-talk
//
// Author : Koryo Okumura
//
// Version : Fri Aug 28 2009
//
// CUS script : obs PacsCal_Phot_crossTalk
//
// Argument :
//   string select = "ginit" in ["binit","ginit","lowIVSS","nominalIVSS","highIVSS","final"]; // Select an option to define IVSS current
//   int naifid = 2000001; // SSO tracking object number
//   double ra = 0.0; // RA
//   double dec = 0.0; // Dec
//   string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
//   int nLoops1 = 30; // number of CSs cycles during slew
//   int nLoops5 = 30; // number of CSs cycles during final hold
//   int readouts_plateau = 32; // number of readouts per chopper plateau
//   bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + PHOT_orbit_prologue is executed (then more than the minimum requirement below is fullfilled):
//     - Bolometers are biased
//     - Sequencer is activated
//
// Description : PacsCal script of Phot_crossTalk
//   init + During the slew, CSs are measured through 2 filters
//        + Set a filter corresponding to the given seqNum
//        + Set the biases group by group
//        + Set the chopper on the optical center
//        + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//        + VGGs are set for all buffer units corresponding to select
//        + Do a small scan map to cover the whole detector with a point source
//
// Dependencies : Commissioning and PV data for the nominal setting of biases
//
// Update :
//   28-Aug-2009 : KO, Now the calibration block is done through the current
//                     filter and the filter setting in the initialisation is
//                     kept as it is (SPR: PACS-2003)
//   23-Sep-2009 : KO, naifid is set to 0, because otherwise XHSpot can not
//                     handle as non SSO. At the same time, yoffset is also
//                     set to zero. This non zero value came from a cut and
//                     paste of the high gain CUS script.
//
obs PacsCal_Phot_crossTalk {
    string select = "ginit" in ["binit","ginit","lowIVSS","nominalIVSS","highIVSS","final"]; // Select an option to define IVSS current
    string setting = "DIRECT" in ["DIRECT","DDCS"]; // Operating mode
    int naifid = 0; // SSO tracking object number
    double ra = 0.0; // RA
    double dec = 0.0; // Dec
    string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 32; // number of readouts per chopper plateau
    bool verbose = true;
}{
    int nRdts = readouts_plateau - 1;
    bool execute = true;
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeCal3CPR1 = duration(OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644));
    int timeSetup = duration(Phot_crossTalk(select,startBiasTable,endBiasTable,setting));
    int tslewmin = 0;
    int tih = 0;
    int tfh = 0;
    // Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // yoffset [arcsec] (Positive offset to get an empty sky in the last 4 pointings)
    double yoffset = 0.0;
    // zoffset [arcsec]
    double zoffset = 0.0;
    // Duration of "stable" pointing in seconds
    int tp = 0;
    //Issue PointReq
    int[] ts = [0];
    if(select == "ginit" || select == "binit" || select == "final") {
        // Several arguments needed for "basic_fine_pointing"
        // time to set OBSID and biases then PacsPhotSlewCal
        // Minimum slew time
        tslewmin = timeOBSID + timeSetup + timeCal3CPR1;
        if(verbose) {
            debug_print("Tslewmin: " + tslewmin);
        }
        // Initial hold
        tih = 0;
        // Final hold
        tfh = timeEndID;
        // Duration of "stable" pointing in seconds
        tp = 1;
        //Issue PointReq
        ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    } else {
        // Several arguments needed for "basic_line_scan_pointing"
        // time to set OBSID and biases then OBCP_chopped_photometry
        int timeCal3CPR5 = duration(OBCP_chopped_photometry(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,644));
        // Minimum slew time
        tslewmin = timeOBSID + timeSetup + timeCal3CPR1;
        if(verbose) {
            debug_print("Tslewmin: " + tslewmin);
        }
        // Initial hold
        tih = 0;
        // Final hold
        tfh = timeCal3CPR5 + timeEndID;
        // Fixed in the sky coordinates
        bool fixed = false;
        // Orientation angle (degrees)
        double patt = 90.0;
        // Number of scans: additional 8 pixels due to the chopper misalignment
        int nscan = 46;
        // Scan length in arcsec: additional 6 pixels due to chopper misalignment
        double scanLength = 233.0;
        // Angular distance (arcsec) between 2 scans
        double space = 3.0;
        // Scan speed in arcsec/s (about 2 frames per pixel)
        double speed = 16.0;
        // Hold time
        int thold = 0;
        // Number of holds
        int nhold = 0;
        // Number of repetition
        int nrepeat = 1;
        //Issue PointReq
        ts = line_scan_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,nscan,scanLength,space,speed,thold,nhold,nrepeat);
    }
}{
    int tNOW = time();
    int[] state = [0];
    if(select == "ginit" || select == "binit" || select == "final") {
        //  Start the sequence
        while(state[0] >= 0) {
            state = next_state();
            if(state[0] == 1) {
                if(verbose) {
                    tNOW = time();
                    debug_print("SLEW starts at " + tNOW);
                }
                // Set OBSID
                WriteOBSID($OBSID);
                data_rate(120.0);
                //************************************
                //  Call the Phot_crossTalk
                //************************************
                Phot_crossTalk(select,startBiasTable,endBiasTable,setting);
                //
                //************************************************************
                // 3 chopper positions measurement through the current filter
                //************************************************************
                OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                if(verbose) {
                    tNOW = time();
                    debug_print("SLEW ends at   " + tNOW);
                }
            }
            if(state[0] == 2) {
                if(verbose) {
                    tNOW = time();
                    debug_print("INITIAL_HOLD starts at   " + tNOW);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("INITIAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("POINT starts at   " + tNOW);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("POINT ends at     " + tNOW);
                }
            }
            if(state[0] == 5) {
                if(verbose) {
                    tNOW = time();
                    debug_print("FINAL_HOLD starts at   " + tNOW);
                }
                // Write EndID
                data_rate(0.0);
                WriteEndID();
                if(verbose) {
                    tNOW = time();
                    debug_print("FINAL_HOLD ends at     " + tNOW);
                }
            }
        }
    } else {
        int finalChop = 0;
        //  Start the sequence
        while(state[0] >= 0) {
            state = next_state();
            if(state[0] == 1) {
                if(verbose) {
                    tNOW = time();
                    debug_print("SLEW starts at " + tNOW);
                }
                // Set OBSID
                WriteOBSID($OBSID);
                data_rate(120.0);
                //
                //************************************
                //  Call the Phot_crossTalk
                //************************************
                Phot_crossTalk(select,startBiasTable,endBiasTable,setting);
                //
                //************************************************************
                // 3 chopper positions measurement through the current filter
                //************************************************************
                OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                if(verbose) {
                    tNOW = time();
                    debug_print("SLEW ends at   " + tNOW);
                }
            }
            if(state[0] == 2) {
                if(verbose) {
                    tNOW = time();
                    debug_print("INITIAL_HOLD starts at   " + tNOW);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("INITIAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("POINT starts at   " + tNOW);
                }
            }
            if(state[0] == 4) {
                if(verbose) {
                    tNOW = time();
                    debug_print("OFF starts at   " + tNOW);
                }
            }
            if(state[0] == 5) {
                if(verbose) {
                    tNOW = time();
                    debug_print("FINAL_HOLD starts at   " + tNOW);
                }
                //************************************************************
                // 3 chopper positions measurement through the current filter
                //************************************************************
                OBCP_chopped_photometry(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                // Write EndID
                data_rate(0.0);
                WriteEndID();
                if(verbose) {
                    tNOW = time();
                    debug_print("FINAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 8) {
                if(verbose) {
                    tNOW = time();
                    debug_print("LINE starts at   " + tNOW);
                }
                // Nichts zu tun, na ja...
                if(verbose) {
                    tNOW = time();
                    debug_print("LINE ends at   " + tNOW);
                }
            }
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       : Exercise all available OBCPs for SPECtroscopy
//                  
//                 
//
// TCL author    : N/A
// TCL file      : tN/A
// CUS author    : DAC
// Script file   : SPEC_all_aots_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Exercise all available OBCPs for PHOT
//   
// Dependencies  : 
//
// Preconditions : SPEC_setup has been executed
//     
// Comments   : 
// 
// Version      2.0
// History       0.1 25-apr-2005 DAC
// 0.2 26-apr-2005 DAC Added SPEC_spu_setup and PACS_reset
// 0.3 26-apr-2005 DAC SPEC_aot_prologue instead of SPEC_spu_setup 
// 0.4 20-sep-2005 Correcred up/dn grating steps
// 0.5 25-oct-2005 DAC Use fit_alg = 0
// 0.6 09-aug-2006 TM updated for both filters, new OBCP, new default parameters
//                             and SPEC_spu_setup (instead of SPEC_aot_prologue)
// 0.7 10-aug-2006 TM shorten execution length
// 0.8 09-aug-2006 TM synchronisation sources for OBCP27 changed from 2 to 1
// 1.0 17-nov-2006 Reviewed for OpDataBase
// 2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
obs PacsEng_Spec_all_aots {
    /* Needed variables to call PacsEng_Spec_all_aots                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_all_aots                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_all_aots()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_all_aots();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       :  Fully Characterize one set of PID parameters (Healthcheck & slewtime cal)
//
// Description  : 
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0 
// History       : 1.0  12-Jul-2007 PR
//                 1.1  13-Nov-2007 BV Added MOIS comments
//		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
obs PacsEng_Spec_Gra_IST_Full_Charac {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Full_Charac        */
    string calUrowSLOW = "PVSlow";
    string calUrowFAST = "PV";
    /* End of needed variables for PacsEng_Spec_Gra_IST_Full_Charac                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Gra_IST_Full_Charac(calUrowSLOW,calUrowFAST)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Gra_IST_Full_Charac(calUrowSLOW,calUrowFAST);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id: PacsCal_WaveCalRaster.txt,v 1.0 2009/07/10 10:25:00 vanessad Exp $
// Missionphase		: PACS PV Phase
//
// Purpose :		Wavelength calibration and instrumental profile
// 	      	     rater without chopping
// Author		 : HF
//
// Arguments:
//
// Prerequisite 	: PACS does not need to be on nor setup for spectroscopy
//
// Description		: Uses flexible procedure WaveCalNoChop
// 			  
// Comments		:
//
// Version		: 1.0
// 
// History		: 1.0 Copied from PacsCal_WaveCalNoChop and PacsCal_WaveCalRaster Using example from PacsCal_WaveCalNoChop
//                      : 1.1 14-sep-2009 VD PHS-1173
//                      : 2.0 26-nov-2009 PACS-2330: adapted to Burst mode
//                      :                 VD Enable Burst mode and BUS_LIST
// 			
obs PacsCal_WaveCalRaster_Burst {
    /* Spectro definitions */
    string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B"
    int order = 2; // Order selection for Slewcal
    int grat_start = 500000; // grating start position for scan
    int grat_stepsize = 200; // grating step size
    int grat_numsteps = 50; // number of grating steps in one direction
    int grat_numramps = 3; // number of ramps per grating position
    int chop_def = 664; // chopper position during grating scan
    int nb_rdout_ramp = 64; // number of readouts per ramp
    int num_updown = 1; // number of grating updown scans
    int grat_end = 496000; // position of grating after the scan
    int capa_red = 12; // Red capacitor
    int capa_blu = 12; // Blue capacitor
    double bias_r_blu = 0.01; // Bias "r" blue
    double bias_r_red = 0.01; // Bias "r" red
    double bias_d_blu = 0.1; // Bias "d" blue
    double bias_d_red = 0.042; // Bias "d" red
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp    
    int comp_mode_blu = 16; // compression mode for blue detector
    int comp_mode_red = 16; // compression mode for red detector
    int nb_raw_red = 0; // number of raw red pixels
    int nb_raw_blu = 0; // number of raw blue pixels
    /* Pointing parameters */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    double raoff = 0.0 in [0.0,360.0];
    double decoff = 0.0 in [-90.0,90.0];
    bool refSelected = false; // OFF position needed
    /* raster */
    int m = 2 in [2,100]; // Number of points in a raster line
    int n = 1 in [1,100]; // number of raster lines
    int k = 2 in [0,200]; // OFF repetition use (m*n)
    double d1 = 2.0 in [2.0,480.0]; // Raster point separation in a line [arcsec]
    double d2 = 2.0 in [2.0,480.0]; // Raster line separation [arcsec]
    bool fixed = false; // Raster in S/C (=false) or SKY coordinates (=true)
    double patt = 0.0; // Raster pattern orientation
    bool verbose = true;
}{
    // computing time for slew / calibration during slew time and others
    //Execute the pointing request
    busconfig (7);
    bool execute = true;
    // Set OBSID
    int tobsid = duration(WriteOBSID($OBSID));
    // Calibration time during slew
    // SPEC parameters for BLU and RED               
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    string throwUsage = "small";
    string extraConf = "normal";
    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // frstLstGratPos is the last position for the grating after the Cals done
    // during Slew time... must be same as observations start position: grat_pos   
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    // "N/A" in string because of indexing 0,1,2,3
    string[] choix = ["N/A","order1","order2","order3","sed4"];
    string order_str = "order" + order;
    //    if(choix[order] != "order1") {
    //        double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //    double keyWL = PacsSpecKeyWaves(order_str);
    double[] keyWAVE = [150.0];
    if(choix[order] == "order3" && fltPOS == "POS B") {
        error("Filter B and order 3 are not compatible");
    }
    if(choix[order] == "order1" && fltPOS == "POS A") {
        keyWAVE = [180.0];
    }
    if(choix[order] == "order1" && fltPOS == "POS B") {
        keyWAVE = [150.0];
    }
    if(choix[order] == "order2" && fltPOS == "POS B") {
        keyWAVE = [75.0];
    }
    if(choix[order] == "order3" && fltPOS == "POS A") {
        keyWAVE = [60.0];
    }
    // this is for extended Blue
    if(choix[order] == "order2" && fltPOS == "POS A") {
        keyWAVE = [60.0];
        choix[order] = "sed4";
    }
    // no need for SpecKeyWave!
    int tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]));
    //   } else {
    //       keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //       double keyWAVE2 = dlookup("KEY_WAVES",order_str,"KeyWave2");
    //       keyWAVE = [keyWAVE1,keyWAVE2];
    //        tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]));
    //   }
    //Initial hold
    int tih = 0;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int grat_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int tepilog = duration(SPEC_aot_epilogue(grat_start,grat_def,verbose));
    //Duration of "stable" pointing
    int tp = duration(WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_end,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red));
    if(verbose) {
        debug_print("Duration of WaveCalNoChop" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    int t_BUS_LIST_enable = imax(2,duration(Burstmode_setup_block()));
    int t_BUS_LIST_disable = imax(2,duration(Burstmode_reset_block()));
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    int thold = 0;
    int nhold = 0;
    int top = duration(WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_end,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red));
    int nrepeat = 1;
    //Issue PointReq
    int tslewmin = tobsid + t_BUS_LIST_enable + tpacsSlewCal;
    int tfh = tendobsid + t_BUS_LIST_disable + tepilog;
    if(verbose) {
        debug_print("Slewing time is:" + tslewmin + "sec");
    }
    int[] ts = raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            int tNOW = time();
            // slew time calibration
            WriteOBSID($OBSID);
            Burstmode_setup_block();
            if(verbose) {
                debug_print("Slewing starts at :" + tNOW + " sec");
            }
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            if(choix[order] == "order1") {
                PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]);
            } else {
                PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]);
            }
            tNOW = time();
            if(verbose) {
                debug_print("Slewing ends at " + tNOW + " sec");
            }
            data_rate(300.0);
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_end,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red);
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 4) {
                    //       Call the WaveCal procedure
                    tNOW = time();
                    if(verbose) {
                        debug_print("Observation at NOD starts at :" + tNOW + " sec");
                    }
                    WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_end,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red);
                    tNOW = time();
                    if(verbose) {
                        debug_print("Observation at NOD ends at :" + tNOW + " sec");
                    }
                } else {
                    if(state[0] == 5) {
                        tNOW = time();
                        if(verbose) {
                            debug_print("Final Hold starts at :" + tNOW + " sec");
                        }
                        SPEC_aot_epilogue(grat_start,grat_def,verbose);
                        Burstmode_reset_block();
                        data_rate(0.0);
                        WriteEndID();
                        tNOW = time();
                        if(verbose) {
                            debug_print("Final Hold ends at :" + tNOW + " sec");
                        }
                    }
                }
            }
        }
    }
    // End of Observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       : Exercise chopped SED
//                  
//                 
//
// TCL author    : N/A
// TCL file      : tN/A
// CUS author    : TM
// Script file   : 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Exercise all available OBCPs for PHOT
//   
// Dependencies  : 
//
// Preconditions : SPEC_setup has been executed
//     
// Comments   : 
// 
// Version      1.0
// History      0.1 11-apr-2007 TM
// 		1.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
obs PacsEng_Spec_chopped_SED {
    /* Needed variables to call PacsEng_Spec_chopped_SED                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_chopped_SED                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_chopped_SED()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_chopped_SED();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Filename	: Pacs_Spec_Gra_Slew_Time_Cal
// Purpose	: Loops over relative grating movements of various step_size
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: gra_steps_per_block : number of grating steps per step_size
//
// Description	: Loops over relative grating movements
//	  The step sizes are fixed. A block of "gra_steps_per_block" steps is performed for each given step_size
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on
//	    The grating controller is SWON, ENABLED and HOMED
//	    (e.g. SetupSpectroscopyEQMIMT takes care for it)
//
// Comments	: This test only makes sense with appropriate diagnostic HK (e.g. PACS_Spec_Gra_Diaghk_Setup.tcl)
//
// Version	: 2.0
//               
// History	: 1.0 12-Jun-2006 Creation based on SPEC_Gra_slew_time_cal
//			          addition of step sizes typical of AOT
//		  2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
procedure Pacs_Spec_Gra_Slew_Time_Cal {
    int gra_steps_per_block = 3;
}{
    // Fixing the parameters for the blocks of grating movements
    int time_on_pos = 2;
    double atomic_step_pos = 116.505;
    double atomic_step_neg = -116.505;
    double[] steps = [1.0,2.0,3.0,3.43,5.15,7.725,10.3,15.0,20.6,50.0,100.0,200.0,600.0];
    int n_steps = length(steps) - 1;
    int astep = 0;
    // First block : from bottom, upwards 
    SPEC_Gra_move_abs_raw(66000);
    delay(25);
    for(int n1 = 0 .. n_steps) {
        // debug_print("n1 =" + n1 + " steps[n1] = " + steps[n1]);
        astep = iround(steps[n1] * atomic_step_pos);
        SPEC_Gra_move_rel_raw_loop(gra_steps_per_block,astep,time_on_pos);
    }
    // Second block : from center, upwards 
    SPEC_Gra_move_abs_raw(500000);
    delay(25);
    for(int n2 = 0 .. n_steps) {
        astep = iround(steps[n2] * atomic_step_pos);
        SPEC_Gra_move_rel_raw_loop(gra_steps_per_block,astep,time_on_pos);
    }
    // Third block : from top, downwards 
    SPEC_Gra_move_abs_raw(990000);
    delay(25);
    for(int n3 = 0 .. n_steps) {
        astep = iround(steps[n3] * atomic_step_neg);
        SPEC_Gra_move_rel_raw_loop(gra_steps_per_block,astep,time_on_pos);
    }
    // Fourth block : from center, downwards 
    SPEC_Gra_move_abs_raw(500000);
    delay(25);
    for(int n4 = 0 .. n_steps) {
        astep = iround(steps[n4] * atomic_step_neg);
        SPEC_Gra_move_rel_raw_loop(gra_steps_per_block,astep,time_on_pos);
    }
    // End : bring the grating back to central position
    SPEC_Gra_move_abs_raw(500000);
    delay(25);
}

// CVS comments  : $Id: SumFunction.txt,v 1.2 2007/04/25 15:14:05 dcesarsk Exp $ 
// Purpose       : Accumulate OBCP times, sum2 = sum2 + sum1
//
// CUS author    : DAC
// Script file   : SumFunction.txt 
//
// Input arguments
// type     name   description
// int [][] sum1   Vector of times per waveLength
// int [][] sum2   Accumulated vector of times per waveLength
//   
// Return values
// Type            Description
// int [][] sum2   Vector of accumulated times per waveLength
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 11-jan-2006 DAC
//               : 1.0 14-apr-2010 VD PHS-1383 clean way to handle in/out variables
int[][] procedure SumFunction {
    int[][] sum1 = [[0]];
    int[][] sum2 = [[0]];
}{
    // Establish length of sum1
    int nbWave = length(sum1);
    int[][] sum1_tmp = sum1;
    int[][] sum2_tmp = sum2;
    // Sum for all wavelenths represented in sum1
    for(int loop0 = 0 .. nbWave - 1) {
        sum2_tmp[loop0][0] = sum2_tmp[loop0][0] + sum1_tmp[loop0][0];
        sum2_tmp[loop0][1] = sum2_tmp[loop0][1] + sum1_tmp[loop0][1];
        sum2_tmp[loop0][2] = sum2_tmp[loop0][2] + sum1_tmp[loop0][2];
        sum2_tmp[loop0][3] = sum2_tmp[loop0][3] + sum1_tmp[loop0][3];
        sum2_tmp[loop0][4] = sum2_tmp[loop0][4] + sum1_tmp[loop0][4];
    }

    return sum2_tmp;
}

// File          : PACS_Phot_DPU_DMC_Setup.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Prepare DPU and DMC for photometry
//
// Author        : T. Mueller
// CUSification  : DAC
// Arguments     : none
//                 
//
// Description   : This script will set the DPU HK list, write and set the
//                 FPGA timing parameters (if necessary), set the synchronization
//                 source for the sequencer, forward data to the packet encoder
//                 and validate the sciece data
//
//                              
// Comments      :  Coded with respect to DPU and DMC UM
//
// Version       : 1.5
// History       : 1.0 / 23-Apr-2003 initial version by FGB
//               : 1.1 / 25-Nov-2003 update by TM
//               : 1.2 / 20-Apr-2004 modified and renamed
//               : 1.3 / 13-Apr-2006 TM update for FM, adopted from
//                       "PHOT_dpu_dmc_setup.txt"
//                 1.4 / 11-Aug-2006 TM update for FM, delay(1) introduced
//                          between sequential FPGA parameter settings
//                  1.5 23-nov-2006 Updated FPGA parameters
//
// @author Thomas Mueller
// @date today
// @version 1.3
// @purpose Prepare DPU and DMC for photometry
procedure PACS_Phot_DPU_DMC_Setup {
}{
    //-------------------------------
    //  Set HK list
    //-------------------------------
    // DPU_SET_HK_LIST (PHOT HK_PACKT_ID=2;
    //                  SPU_ARRAY: 1 for both channels, 2 for blue chan, 3: for red chan)
    // PC003380 "DPU_SET_HK_LIST" SET THE PREDIFINED LIST OF HK VALUES
    //                            FOR THE HK PACKET
    //         PP005380 "HK_PACKT_ID"
    //         PP025380 "SPU_ARRAY"
    // tcsend PC003380 {PP005380 2} [list PP025380 $phot_hk]
    // waittime 0.5
    Pacs_DPU_SET_HK_LIST("PHOT","BOTH Array");
    delay(1);
    //-------------------------------------------------
    // Stop forwarding data to packet encoder
    //-------------------------------------------------
    // PC169420 "DMC_WRT_BOL_REC_OPT" WRITE THE BOL RECEIVER OPTIONS
    //         Fixed GroupSize: 1, repetition: 1
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // tcsend PC169420 {PP067420 4} \
    //                {PP066420 0xC444 LO}
    // waittime 0.5
    int[] argum = [4];
    {int}[] argTuple = [{4}];
    int chksum = checksum("int",argum);
    Pacs_DMC_WRT_BOL_REC_OPT(argTuple,chksum);
    delay(1);
    // PC170420 "DMC_WRT_B_DEC_REC_OPT" WRITE THE BLUE DEC RECEIVER OPTIONS
    //         Fixed GroupSize: 1, repetition: 1
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // tcsend PC170420 {PP067420 4} \
    //                {PP066420 0xC444 LO}
    // waittime 0.5
    argum = [4];
    argTuple = [{4}];
    chksum = checksum("int",argum);
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,chksum);
    delay(1);
    // PC171420 "DMC_WRT_R_DEC_REC_OPT" WRITE THE RED DEC RECEIVER OPTIONS
    //         Fixed GroupSize: 1, repetition: 1
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // tcsend PC171420 {PP067420 4} \
    //                {PP066420 0xC444 LO}
    // waittime 0.5
    argum = [4];
    argTuple = [{4}];
    chksum = checksum("int",argum);
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,chksum);
    delay(1);
    // Write and set FPGA timing parameters
    // DMC_WRT_TIMING_FPGA_PAR
    int[] aux = [0x0,0x0,0x0,26,0x977dc04,0x32];
    int check_sum = checksum("int",aux);
    {int}[] parlist = Array2grp_1(aux);
    Pacs_DMC_WRT_TIMING_FPGA_PAR(parlist,check_sum);
    // DMC_SET_TIMING_FPGA_PAR: Copy parameters set by WRT_TIMING to registers
    Pacs_DMC_SET_TIMING_FPGA_PAR();
    // SYNCHRONIZE_ON_DETECTOR (synchronize on BOL readouts)
    //     1 = synchronize on blue spectrometer ramps
    //     2 = synchronize on red spectrometer ramps
    //     4 = synchronize on BOL readouts
    Pacs_DMC_SYNCHRONIZE_ON_DET_RAW(4);
    delay(1);
    // Write and set FPGA timing parameters
    // DMC_WRT_TIMING_FPGA_PAR
    aux = [0x0,0x0,0x0,26,0x977dc04,0x22];
    check_sum = checksum("int",aux);
    parlist = Array2grp_1(aux);
    Pacs_DMC_WRT_TIMING_FPGA_PAR(parlist,check_sum);
    // DMC_SET_TIMING_FPGA_PAR: Copy parameters set by WRT_TIMING to registers
    Pacs_DMC_SET_TIMING_FPGA_PAR();
    //------------------------------------------------
    // Forward data to Packet Encoder
    //------------------------------------------------
    // PC169420 "DMC_WRT_BOL_REC_OPT" WRITE THE BOL RECEIVER OPTIONS
    //         Fixed GroupSize: 1, repetition: 1
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // tcsend PC169420 {PP067420 0} {PP066420 0x84C0 LO}
    // waittime 0.5
    argum = [0];
    argTuple = [{0}];
    chksum = checksum("int",argum);
    Pacs_DMC_WRT_BOL_REC_OPT(argTuple,chksum);
    delay(1);
    //------------------------------------------------
    // Validate science data photometry
    //------------------------------------------------
    // PC095420 "DMC_VAL_SCI_DATA_B" VALIDATE SCIENCE DATA FROM THE BLUE CHANNEL
    // 
    // PC096420 "DMC_VAL_SCI_DATA_R" VALIDATE SCIENCE DATA FROM THE RED CHANNEL
    // 
    // PC097420 "DMC_VAL_SCI_DATA_BOTH" VALIDATE SCIENCE DATA FROM BOTH CHANNELS
    // tcsend PC097420
    // waittime 0.5
    Pacs_DMC_VAL_SCI_DATA_BOTH();
    //-----------------
    // End of Procedure
    //-----------------
}

// Preconditions : 
//     
// Comments	: 
//
// Version	: 1.0
//      
// History	: 1.0 05-Apr-2005 Creation by PR
//                1.1 11-apr-2005 DAC. Same correction as 
//                                OBCP_spec_2_3_chop, viz. returned time array
//                1.2 27-apr-2005 DAC Corrected OBCP name after MIB
//                1.3 14-jan-2008 DAC Added WriteEndBB at the end of bld. block
//
int[] block OBCP_grat_scan_nochop PACS 28 {
    int nb_up_dn = 1; // DMC Seq P#1 : Number of sequences: up down up ...
    int nb_grat_steps_up = 20; // DMC Seq P#2 Number of grating steps (up-scan)
    int grat_step_up = 133; // DMC Seq P#3 : Grating step (up-scan)
    int grat_step_dn = -133; // DMC Seq P#4 : Grating step (down-scan)
    int nb_ramps_grat_pos = 3; // DMC Seq P#5 : Nb ramps/grat position
    int nb_CS1_CS2 = 1; // DMC Seq P#6 : Nb of cycles on CS/grat position
    int chop_pos_CS1 = -25000; // DMC Seq P#7 : Chopper position on CS1
    int chop_pos_CS2 = 25000; // DMC Seq P#8 : Chopper position on CS2
    int nb_ramps_cs = 3; // DMC Seq P#9 : Nb ramps plateau on CS
    int nb_grat_steps_dn = 20; // DMC Seq P#10 Number of grating steps (down-scan)
    int chop_def = 0; // DMC Seq P#11 : Chopper default position
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int grat_start_pos = 800000; // Starting grating position
    int grat_start_time = 40000; // Time for grating to move to start position
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int grat_def_time = 20000; // Grating time to move to grat_def [msec]
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Register with environment
    WriteBBID($BBID);
    // Variables for time_array
    int duree_ramps = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    // debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    // debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // duree of this OBCP (computed and returned in [msec])
    int duree_msec = 0;
    // OBCP pseudo code 
    // OBCP_GRAT_LINE_SCAN_NOCHOP(seq, seq_time, P#1,&,P#11,  
    //                          detector, grat_pos, grat_time,
    //                          comp_mode_blu, comp_mode_red, 
    //                          grat_def, grat_def_time) 
    // Begin 
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_start_pos) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // (all parameters filled by DPU based on seq parameter) 
    // DMC_SYNCHRONIZE_ON_DET(detector) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, comp_mode_blu, comp_mode_red, CHHKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT (grat_time) 
    duree_msec = duree_msec + t_cmd + grat_start_time;
    duree_OVR = duree_OVR + t_cmd + grat_start_time;
    // DMC_START_SEQUENCE
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Call DEC/MEC sequence just to know the execution time 
    // (hence not all parameters are relevant)
    int[] duree1 = DMC_grat_scan_nochop(nb_up_dn,nb_grat_steps_up,nb_ramps_grat_pos,nb_CS1_CS2,nb_ramps_cs,nb_grat_steps_dn);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    // WAIT (seq_time)
    duree_msec = duree_msec + t_cmd;
    duree_msec = duree_msec + seq_time;
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT (grat_def_time) 
    duree_msec = duree_msec + t_cmd + grat_def_time;
    duree_OVR = duree_OVR + t_cmd + grat_def_time;
    // Issue TM(1,7)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Now trigger execution of OBCP
    // This OBCP is number 28, requires 20 parameters and calls DEC/MEC Seq #13
    string obcp_ID = "GRAT_SCAN_NOCHOP";
    int obcp_par_nb = 20;
    int seq_DMC = 13;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_dn},{4,nb_grat_steps_up},{5,grat_step_up},{6,grat_step_dn},{7,nb_ramps_grat_pos},{8,nb_CS1_CS2},{9,chop_pos_CS1},{10,chop_pos_CS2},{11,nb_ramps_cs},{12,nb_grat_steps_dn},{13,chop_def},{14,detector},{15,grat_start_pos},{16,grat_start_time},{17,comp_mode_blu},{18,comp_mode_red},{19,grat_def},{20,grat_def_time}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    delay(time_array[0]);
    // Indicate end of BB
    WriteEndBB();
    // Return the array of times

    return time_array;
}

// Missionphase  : 
//
// Purpose       : Set CRE bias, ramps' length and capacitor values
//                  
// Author        : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : SPEC_cre_setup.txt
//
// Arguments     : 
// Type     Name          DefVal   Description
// int      cre_ctrl_red           CRE control register (red)
// int      cre_ctrl_blu           CRE control register (blu)
// int      ramp_len_red     64    Red ramps' length
// int      ramp_len_blu     64    Blue ramps' lengthl
// double   bias_d_red        0    BIAS_D for red spectrometer (1V=4095)
// double   bias_r_red        0    BIAS_R for red spectrometer (1V=4095)
// double   bias_d_blu        0    BIAS_D for blue spectrometer (1V=4095)
// double   bias_r_blu        0    BIAS_R for blue spectrometer (1V=4095)
// int      capa_red          0    Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
// int      capa_blu          0    Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
//
//
// CRE setup according to the DEC/MEC User's Manual
//
// 1. DMC_SWON_B_DEC to switch on the DEC 
// 2. Wait 5 seconds to get the 1355 connection between DEC and CPU board 
// 3. Send the complete set of default parameters. 
//    First send a DMC_WRT_B_SPEC_PAR command with these values 
//    (in hex: 20-8-18C-0-0-EA60-0-0).    
// 3a. Then, send a DMC_SET_PAR_B_SPEC to really send the parameters to the DEC. 
// 4. DMC_SWON_B_SPEC to switch on the detector array 
// 5. Wait 15 seconds to let the switch on procedure run and all voltages 
//    become stables 
// 6. Then, to activate the CREs (signal SELECT on the CREs), send the first 
//    3 parameters, i.e. DMC_WRT_B_SPEC_PAR command with these 
//    values (length: 3, values in hex : 20- 8-18E). 
// 6a. Then, send a DMC_SET_PAR_B_SPEC to really send the parameters to the DEC. 
//    Note: with this command, we set bit1 to 1 (activate CRE). Bit0 
//    has been set to 1 by the DMC_SWON_B_SPEC command but, 
//    bit0 is not commandable through the DMC_WRT_B_SPEC_PAR. 
//    The only way to switch on/off the detector array is to use the 
//    trigger commands. 
// 7. Then, you should set the bias voltages by writing the first 4 or 5 
//    parameters of the block. Make sure to copy the latest values you use 
//    for the first 3 parameters.
//
// Description   : Sets CRE parameters (see list of arguments).
//                 User specifies cre_ctrl_xx as:
//                 cre_ctrl: 256 to set "sync width=2"
//                           128 to set "T sensor on" 
//                             2 to set "select"
//                             1 power on (not relevant here)
//                 Script adds capa_xx to cre_ctrl_xx
//                     xx_cre_ctrl = capa_xx + cre_ctrl_xx
//                 xx_cre_ctrl gets written to the CRE register
//                 Must be called on a stopped SPU. This procedure will
//                 neither stop nor start SPU (call SPEC_spu_reset and 
//                 SPEC_spu_setup respectively for that)
//
//                  
// Dependencies  : 
//                 
// Comments      : Based on V1.3 of FGB's fgb_spec_cre_setup.tcl. Major
//                 change is getting ENG values for the bias voltages
//
// Version       : 0.1  7-Oct-2004 Creation by DAC
// History       : 0.2 12-Oct-2004 Removed "delay" statements
//                 0.3 18-Oct-2004 Normalized variable names
//                 0.4 21-Oct-2004 Added cre_ctrl_xx and heater_on
//                                 arguments to allow calling by
//                                 SPEC_orbit_prologue. 
//                                 Removed heater commands
//                 0.5 27-Oct-2004 Put bck delay statement 
//                 1.0 10-Apr-2006 HF, modified for FM
//                 1.1. 20-oct-2010 PACS-3098 VD & HF HEATER ON (using orbit prologue current value 0.78?)
//                                          Use duration_msec to WAIT...
//                                          
//
int procedure SPEC_cre_setup {
    int cre_ctrl_red = 386; // Red  CRE register (capa_red=0)
    int cre_ctrl_blu = 386; // Blue CRE register (capa_blu=0)
    int ramp_len_red = 64; // Red  ramp length
    int ramp_len_blu = 64; // Blue ramp length
    double bias_d_red = 0.07 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_red = 0.01 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.21 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_r_blu = 0.01 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    int capa_red = 12; // Capacitor red  (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_blu = 12; // Capacitor blue (0=100fF,4=400fF,8=0.2pf,12=1pF)
}{
    // Accumulated duration [milliseconds]
    int duration_msec = 0;
    // Write the blue spectrometer parameters
    int blu_cre_ctrl = capa_blu + cre_ctrl_blu;
    // Bias values have been given in ENG units. Have to convert to RAW in
    // order to compute check-sums
    int i_blu_bias_r = convert_to_raw("pacs_DMC_BIAS_R",bias_r_blu);
    int i_blu_bias_d = convert_to_raw("pacs_DMC_BIAS_D",bias_d_blu);
    int[] aux = [32,ramp_len_blu,blu_cre_ctrl,i_blu_bias_r,i_blu_bias_d,0];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_B_SPEC_PAR(32,ramp_len_blu,blu_cre_ctrl,bias_r_blu,bias_d_blu,0,check_sum);
    // Same for RED parameters
    int red_cre_ctrl = capa_red + cre_ctrl_red;
    int i_bias_r_red = convert_to_raw("pacs_DMC_BIAS_R",bias_r_red);
    int i_bias_d_red = convert_to_raw("pacs_DMC_BIAS_D",bias_d_red);
    aux = [32,ramp_len_red,red_cre_ctrl,i_bias_r_red,i_bias_d_red,0];
    check_sum = checksum("int",aux);
    Pacs_DMC_WRT_R_SPEC_PAR(32,ramp_len_red,red_cre_ctrl,bias_r_red,bias_d_red,0,check_sum);
    // Send complete parameters table to both DECS
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    // Convert duration to [sec] and set delay
    int duration_sec = Msec2sec(duration_msec);
    delay(duration_sec);
    //   Pacs_DMC_SWON_BD_HEATER();
    // careful if this changes!!
    Pacs_DMC_SET_B_SPEC_HEAT_C(0.78);

    return duration_msec;
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Purpose       : PHOT "AOT" with dithered chopping and nodding in raster
//                 OBCP used: OBCP_chopped_photometry_dither (OBCP#5)
//                 Calls nodding_raster_pointing (3.6 in Point document)
// Author        : DAC
//
// Arguments     : See input list below
//
// Prerequisite  : PACS is PHOT configured and SPU is stopped, ready to be
//                 configured.
//
// Description   : Uses OBCP3
// Comments      : Based on PacsCal_PHOT_NodRaster
//
// Version       : 0.1
// History       : 0.1 19-feb-2008 DAC
//                 
obs PacsCal_PHOT_Dither_NodRaster {
    /* Needed variables to call PHOT_NodRaster                               */
    string fltPOS = "POS A"; // Fltw position "POS A" or "POS B"
    double chopthrow = 30.0 in [2.0,960.0]; // Nod/chop throw [arcsec]
    string gain = "LOW" in ["LOW","HIGH"]; // BOLC gain
    /*                                 */
    /* OBCP related parameters         */
    /*                                 */
    /* PHOT compression modes          */
    /* 0x00 BOL0: Default              */
    /* 0x01 BOL1: Double Compression   */
    /* 0x02 BOL2: Half Compression     */
    /* 0x04 BOL4: Lossless Compression */
    /* 0x07 BOL7: Transparent          */
    /* 0x09 BOL9: Buffer Transmission  */
    int comp_mode_blu = 0x0; // Compression mode
    int comp_mode_red = 0x0; // Compression mode
    int nraw_blu = 3; // Number of raw pixels
    int nraw_red = 3; // Number of raw pixels
    int nb_SRC_REF = 2; // Nb of SRC-REF1-SRC-REF2 cycles
    int nb_rd_plateau = 31; // Nb rdouts/plateau (4*nn - 1)
    int nb_cycles_obs_cal = 1; // Outermost DMC loop
    int nb_CS1_CS2 = 0; // Loop on CSs
    int max_dither = 1000; // Maximum dither (chopper engineering units)
    /* Pointing parameters             */
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // zoffset [arcsec]
    double ra = 0.0; // RA (returned by xHPOT pop-up window)
    double dec = 0.0; // DEC (ditto)
    /* Raster parameters               */
    int m = 2 in [2,100]; // Number of raster points       
    int n = 2 in [1,100]; // Number of raster lines
    double d1 = 2.0 in [2.0,480.0]; // Raster point step [arcsec]       
    double d2 = 2.0 in [2.0,480.0]; // Raster line separation [arcsec]
    int nnod = 2; // Number of Aa aA ... nods 
    /* NOTE: raster size shall not be larger than 14880x14880 arcsec */
    /* Overall "verbosity"             */
    bool verbose = true;
}{
    // Compute duration of tasks to be performed during slew to source
    // Set OBSID
    int timeOBSID = duration(WriteOBSID($OBSID));
    // Move filter wheel to intended position
    int timeFLTW = duration(PHOT_fltw_move(fltPOS));
    // Condition BOLC to gain setting. This may change the data rate but SPU
    // is still stopped and a proper comp_mode may be defined
    // Can I set the gain directly (Thomas says "yes")
    //DAC Done by AOT-prologue    int timeGAIN = duration(PHOT_set_gain(gain));
    // Condition SPU to demanded compression mode
    int timePROL = duration(PHOT_aot_prologue(gain,comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,verbose));
    //
    // Before dealing with the OBCP, obtain the chopper position for CS1 and CS2
    // (likely not to be used here, but just for completeness)
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","PHOT","pos_CS1");
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","PHOT","pos_CS2");
    // The chopper moves from -chopthrow/2 to +chopthrow/2 [arcsec]
    string convU = "PHOT_CHOP_sky";
    double auxSRC = -chopthrow / 2.0;
    double auxREF = +chopthrow / 2.0;
    int chop_pos_SRC = PacsReadChopSky(convU,auxSRC);
    int chop_pos_REF = PacsReadChopSky(convU,auxREF);
    // Report settings if verbose
    if(verbose) {
        debug_print("++CHOPPER, SRC: " + auxSRC + " [arcsec] -> " + chop_pos_SRC + " [ENG]");
        debug_print("++CHOPPER, REF: " + auxREF + " [arcsec] -> " + chop_pos_REF + " [ENG]");
    }
    // Default position for chopper
    int chop_def = ilookup("SPEC_MEC_Defaults","Photometry","chopper");
    // Duration of OBCP to be performed ON and NOD
    int tp = duration(OBCP_chopped_photometry_dither(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def,max_dither));
    if(verbose) {
        debug_print("Duration of OBCP " + tp + " [sec]");
    }
    // tp cannot be shorted than 10 sec
    if(tp < 10) {
        error("The OBCP cannot be shorter than 10 sec; adjust your OBCP parameters");
    }
    //
    // Several arguments needed for "nodding_raster_pointing"
    //
    //Execute the pointing request
    bool execute = true;
    //Minimum slew time
    int tslewmin = timeOBSID + timeFLTW + timePROL;
    // Add one second (there is no sinc() in some procedures during slew)
    tslewmin = tslewmin + 1;
    if(verbose) {
        debug_print("Slew MinTime is " + tslewmin + " [sec]");
    }
    //Initial hold
    int tih = 0;
    //Final hold
    // Need 1 sec to WriteEndID() and close OBS
    int tfh = 1;
    //Use PHOT virtual aperture
    string ib = "P01_0";
    //Non-solar source
    int naifid = 0;
    //Issue PointReq
    // Still undefined variables
    // Raster in S/C coordinates
    bool fixed = false;
    // Raster pattern orientation
    double patt = 0.0;
    // Nodding orientation (along y-axis)
    double pattnod = 270.0;
    // Number of points/scan lines before going to OFF
    int k = 0;
    // Number of nods/raster/sacn before performing a hold
    int nhold = 0;
    // Duration of a hold operation
    int thold = 0;
    // Time spent at OFF
    int top = 0;
    // Coordinates of OFF position
    double raoff = 0.0;
    double decoff = 0.0;
    // Repetitions of pattern
    int nrepeat = 1;
    // The minimum duration of return slew between repetitions
    int trepeatmin = 0;
    // Minimum duration of a "load" operation
    int tloadmin = 0;
    // Number of slews before starting a "load" slew
    int nload = 0;
    // Issue de PointReq  
    int[] ts = nodding_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,chopthrow,nnod,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            int tNOW = time();
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            //      Set OBSID, move filter, set gain, perform prologue
            WriteOBSID($OBSID);
            data_rate(120.0);
            PHOT_fltw_move(fltPOS);
            PHOT_aot_prologue(gain,comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,verbose);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //      Call the OBCP with the known parameters
            OBCP_chopped_photometry_dither(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def,max_dither);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            //      Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 7) {
            tNOW = time();
            if(verbose) {
                debug_print("NOD   starts at   " + tNOW);
            }
            //      Call the OBCP with the same parameters as for POINT
            OBCP_chopped_photometry_dither(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def,max_dither);
            tNOW = time();
            if(verbose) {
                debug_print("NOD   ends at     " + tNOW);
            }
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_CS_SFT_Warm {
    /* No variables to call PacsEng_CS_SFT_Warm                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_CS_SFT_Warm                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_CS_SFT_Warm()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_CS_SFT_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_SPU_Buffer_Setup {
    /* No variables to call PacsEng_Spec_SPU_Buffer_Setup                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_SPU_Buffer_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_SPU_Buffer_Setup()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_SPU_Buffer_Setup();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsProcessInfoArrayRange.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $ 
//
// Purpose       : Process the timing information gathered in infoArray
//
// CUS author    : DAC
//
// Input arguments
// type    name        description
//
// tuple sortRanges    HSPOT input
// id, bluEdge, redEdge, repeatFactor, lineFlux, contFlux, lineWidth
//
// tuple sortRangesEXT HSPOT input added later
// fluxUnitSel, widthUnitSel, refWave
// tuple   infoArray
// Slew/Point/AOT       SlewCal or pointing mode or global AOT info
// 0.0                  not in use
// TotDur               duration of the phase Slew/Point/AOT
// nbLines              number of spectral lines observed in phase Slew/point
// nnods                number of nod cycles in phase Point
// m*n                  size of raster when applicable
// wave1                each of the nbLines wavelengths or waveStart
// wave2                each of the nbLines wavelengths or waveEnd
// order                grating order for line wave
// gratStep             grating step (needed to estimate "multiplexing")
// TOT,SRC,REF,CAL,OVR  the canonical OBCP duration (/nod/raster)
//
// Return values
// Type          Description
//
// Description   : Use the information in infoArray to compute several times and
// overheads, as well as the expected RMS fluctuations for each observed line
// infoArray is a three-element tuple:
//    infoArray[0] contains information on the SlewCal phase
//    infoArray[1] contains information on the OBS phase
//    infoArray[2] contains global information on the AOT
//                  
// Dependencies  : 
//
// Comments      : 
// 
// History       : 0.1  6-Sep-2005 DAC
// 0.2 27-sep-2005 Adding elements to compute RMS
// 0.3 28-sep-2005 Add nbGratSteps to infoArray
// 0.4 29-sep-2005 Add confOBCP to input arguments since I need nb_up_dn !!
// 0.5  6-oct-2005 Corrected Raster/Staring logic
// 0.6 14-oct-2005 Text of message
// 1.0 24-oct-2005 Add HTML tags
// 1.1 23-jan-2006 Multiplication by nbNods, mRaster, nRaster no longer needed
//                 since next_state collects time per raster per nod. Also
//                 eliminate "PACS overheads"
// 1.2  1-mar-2006 Use dformat for messages
// 2.0 11-mar-2006 Deal with LINE and CONT RMS values
// 2.1 22-nov-2006 Added "verbose" to input arguments
// 3.0 17-jan-2006 "Improved" messages
// 3.1 12-feb-2007 Accept as input the tuples sortRanges and sortRangesEXT
//                 Renamed to PacsProcessInfoArrayRange; only used
//                 for RANGE due to addition of ranges and rangesEXT
//                 Removed input aotID as only used for PacsRange
// 3.2 26-feb-2007 Added order information from HSPOT: needed by PacsSpecRMS
//                 to deal with "free" grating data
// 4.0 12-mar-2007 Call PacsSpecRMS with "bigTuple" needed to convey graphic
//                 information to main module
//                 Return bigTuple for use by main
// 4.1 12-apr-2007 Add obsOverhead for SCR-2813, implemented SCR-2924
// 4.2 19-apr-2007 Report Best,Worst, etc per "free" range
// 4.4 27-apr-2007 SPR-3147: change km/s into kms
// 4.5 23-may-2007 SPR-3210: return S/N
// 4.5 24-oct-2007 Added nbOBS and nbOFF to input arguments, same to
//                 PacsSpecRMS
// 5.0 01-dec-2009 VD SCR PHS-1272
// 6.0 18-jan-2010 VD PHS-1285 SED only
// 7.0 09-feb-2010 VD PHS-1320
// 8.0 05-may-2010 VD PHS-1385 ripples: gratScanObsTime .. may be used? sometime?
// 9.0 20-may-2010 VD PHS-1433/PHS-1430 gratScanObsTime shoould be filled as fn of range repeat/nb
//                 
{{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] procedure PacsProcessInfoArrayRange_tmp {
    /* infoArray                                                               */
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    /* rangeSPOT (the sorted version)                                             */
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [{"",0.0,0.0,0,0.0,0.0,0.0,"","",0.0}];
    /* infoRangeSed grating */
    {double,double}[] infoRangeSed = [{0.0,0.0}];
    /* confOBCP                                                                */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* order selected by user in HSPOT                                         */
    string orderSel = "order2";
    /* observatory overhead                                                    */
    int obsOverhead = 180;
    /* nbOBS and nbOFF                                                         */
    int nbOBS = 1;
    int nbOFF = 0;
    /* verbose?                                                                */
    bool verbose = true;
}{
    // How am I called?
    if(verbose) {
        debug_print("PROCArray: ranges   : " + rangeSPOT);
    }
    // Number of spectral lines (SlewCal and OBS)
    int nbKeyWaves = infoArray[0]{0}{3};
    if(orderSel == "sedb2b" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        int nbLines = 1;
    } else {
        nbLines = infoArray[1]{0}{3};
    }
    // Number of nods (OBS)
    int nbNodCycles = infoArray[1]{0}{4};
    // Nb of "pointings" for nbNodCycles
    int nbNods = 2 * nbNodCycles;
    if(nbNods == 0) {
        nbNods = 1;
    }
    // Call module to estimate RMS fluctuations; pass information via infoArray
    // and confOBCP (for nb_up_dn)
    // Array noiseWave[nbLines][8] used to contain: 
    //
    //    noiseWave[lineNb][BwlC,BrC,WwlC,WrC,BwlL,BrL,WwlL,WrL]
    //
    // where B: best, W: worst, wl: wavelength, r: RMS, C: continuum, L: line
    // Add three more elements refWave, rmsCont, rmsLine
    // Above is now included in "bigTuple"
    // PHS-1385 ripples!
    // PHS-1433
    int[] gratScanObsTime = [1];
    for(int loop11 = 0 .. nbLines - 1) {
        gratScanObsTime[loop11] = 1;
    }
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = PacsSpecRMS_tmp("RANGE",orderSel,infoArray,rangeSPOT,infoRangeSed,confOBCP,nbOBS,nbOFF,gratScanObsTime,verbose);
    // Define variable to extract info from noiseTuple
    double[][] noiseWave = [[0.0]];
    // Useful variables
    int lineCnt = 0;
    string[] msgLine = ["Line1"];
    // one line of text
    // Report on nodding pattern and pointing details
    msgLine[lineCnt] = "PACS AOT: PacsRangeSpec";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Pointing mode: <B>" + infoArray[1]{0}{0} + "</B> with " + nbNodCycles + " nod cycles</p>";
    lineCnt = lineCnt + 1;
    int mRaster = infoArray[2]{0}{3};
    int nRaster = infoArray[2]{0}{4};
    // When either m or n are >1 then it is raster
    if(mRaster > 1 || nRaster > 1) {
        msgLine[lineCnt] = "<p>Raster size (lines/points):" + mRaster + "/" + nRaster + "</p>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "<p> Nod pattern: nominal position A, or A->B, B->A, etc.</p>";
    lineCnt = lineCnt + 1;
    if(nbNodCycles == 0) {
        msgLine[lineCnt] = "<p>   A </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles == 1) {
        msgLine[lineCnt] = "<p>   A->B </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles == 2) {
        msgLine[lineCnt] = "<p>   A->B B->A </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles > 2) {
        int aux1 = nbNodCycles - 2;
        msgLine[lineCnt] = "<p>   A->B B->A and " + aux1 + " more A<->B leg(s) </p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("AOT, PointMode and Nodding info",lineCnt,msgLine);
    // Global timing information for this AOT
    lineCnt = 0;
    int totAOT = infoArray[2]{0}{2};
    msgLine[lineCnt] = "<p> AOT total duration: " + totAOT + " [sec] </p>";
    lineCnt = lineCnt + 1;
    //  Next is tslew returned by PntReq
    int tslew = infoArray[0]{0}{2};
    msgLine[lineCnt] = "<ul><li> CalSlew (with overheads) " + tslew + " [sec]</li>";
    lineCnt = lineCnt + 1;
    // infoArray[1]{0}{2} is defined as the elementary OBCP duration (per nod
    // and per raster pointing; includes all wavelengths)
    //int totSRCREF = mRaster * nRaster * nbNods * infoArray[1]{0}{2};
    int totSRCREF = infoArray[1]{0}{2};
    msgLine[lineCnt] = "<li> SRC/REF (with overheads) " + totSRCREF + " [sec]</li>";
    lineCnt = lineCnt + 1;
    // 
    //    int slewSRCREF = totAOT - totSRCREF - tslew;
    //    msgLine[lineCnt] = "<li> Overheads in SRC/REF     " + 
    //                       slewSRCREF + " [sec]</li>";
    //    lineCnt = lineCnt + 1;
    int cost = totAOT - tslew;
    // If slewCal takes longer than obsOverhead, then it becomes the overhead
    if(tslew > obsOverhead) {
        obsOverhead = tslew;
    }
    cost = cost + obsOverhead;
    msgLine[lineCnt] = "<li><b>AOT cost</B> (includes time for slewing to source): " + totSRCREF + " + " + obsOverhead + " [sec] = " + cost + " [sec]</li></ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Global AOT durations",lineCnt,msgLine);
    if(verbose) {
        debug_print("++ Start ProcessArray debug info");
        debug_print(" CalSlew: " + infoArray[0]);
        debug_print(" OBS    : " + infoArray[1]);
        debug_print(" TotDur : " + infoArray[2]);
        debug_print("++ End of ProcessArray debug info");
    }
    // Inform the details of SlewCal to HSPOT user
    //   AOT prologue
    lineCnt = 0;
    msgLine[lineCnt] = "<ul><li> AOT prologue duration: " + infoArray[0]{1}[nbKeyWaves]{5} + " [sec]</li>";
    lineCnt = lineCnt + 1;
    //   For each keyWave
    for(int loop0 = 0 .. nbKeyWaves - 1) {
        msgLine[lineCnt] = "<li> KeyWave: " + infoArray[0]{1}[loop0]{0} + " [&micro;m]; CAL duration: " + infoArray[0]{1}[loop0]{5} + " [sec]</li>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    // Display message
    PacsMessageCenter("RANGE setup and CAL summary",lineCnt,msgLine);
    // Re-initialize lineCnt for new series of messages
    lineCnt = 0;
    // Report per LINE
    // Continue defining noiseWave for historical reasons (it used to be returned
    // by PacsSpecRMS, now replaced by bigTuple)
    for(int loop1 = 0 .. nbLines - 1) {
        noiseWave[loop1] = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0];
        //    CONTinuum
        noiseWave[loop1][0] = bigTuple[loop1]{0}{1}[0];
        noiseWave[loop1][1] = bigTuple[loop1]{0}{1}[1];
        noiseWave[loop1][2] = bigTuple[loop1]{0}{1}[2];
        noiseWave[loop1][3] = bigTuple[loop1]{0}{1}[3];
        //    LINE
        noiseWave[loop1][4] = bigTuple[loop1]{0}{1}[4];
        noiseWave[loop1][5] = bigTuple[loop1]{0}{1}[5];
        noiseWave[loop1][6] = bigTuple[loop1]{0}{1}[6];
        noiseWave[loop1][7] = bigTuple[loop1]{0}{1}[7];
        //    CONT and LINE for refWave     
        noiseWave[loop1][8] = bigTuple[loop1]{0}{1}[8];
        noiseWave[loop1][9] = bigTuple[loop1]{0}{1}[9];
        noiseWave[loop1][10] = bigTuple[loop1]{0}{1}[10];
        int trueObsTime = infoArray[1]{1}[loop1]{5};
        //    SrcTime includes REF!
        int trueSrcTime = infoArray[1]{1}[loop1]{6} + infoArray[1]{1}[loop1]{7};
        int lineOver = trueObsTime - trueSrcTime;
        //    Report on "free" ranges, if any...
        //    Up to three ranges: 0,1,2
        //    Tuples can only take literal indexes. Since cannot loop on index,
        //    construct bool "array exists?" of existing ranges
        bool[] good = [bigTuple[loop1]{0}{1}[0] != 0.0,bigTuple[loop1]{1}{1}[0] != 0.0,bigTuple[loop1]{2}{1}[0] != 0.0];
        //    good[0] is the nominal range; reported above
        //    Start with good[1]
        if(good[0]) {
            msgLine[lineCnt] = "<h3>" + rangeSPOT[loop1]{0} + ": " + infoArray[1]{1}[loop1]{0} + "-" + infoArray[1]{1}[loop1]{1} + " [&micro;m]:</h3>";
            lineCnt = lineCnt + 1;
            //        Go ahead and issue messages
            {int,string[]} freeMsg = {0,[""]};
            freeMsg = PacsRangeMessage(bigTuple[loop1]{0});
            //        Add new messages to already stored messages
            for(int loopM0 = 0 .. freeMsg{0} - 1) {
                msgLine[lineCnt] = freeMsg{1}[loopM0];
                lineCnt = lineCnt + 1;
            }
            //        Compute S/N ratios and insert in message stream
            //        NOTE: line in 1E-18; continuum in mJy
            //        Safeguard against division by zero
            if(bigTuple[loop1]{0}{1}[9] > 0.0010) {
                double s2nCONT = 0.0010 * rangeSPOT[loop1]{5} / bigTuple[loop1]{0}{1}[9];
                msgLine[lineCnt] = "<li>S/N continuum (ref. wavelength): " + dformat(s2nCONT,2) + "</li>";
                lineCnt = lineCnt + 1;
            }
            if(bigTuple[loop1]{0}{1}[10] > 1.0E-22) {
                double s2nLINE = 1.0E-18 * rangeSPOT[loop1]{4} / bigTuple[loop1]{0}{1}[10];
                msgLine[lineCnt] = "<li>S/N line (ref. wavelength): " + dformat(s2nLINE,2) + "</li>";
                lineCnt = lineCnt + 1;
            }
            //        Estimate resolution for given wavelength and order
            //        This is done here because the elements needed for the computation
            //        are at this level; i.e. it does not belong to bigTuple
            //        Need order and wavelength
            int order = infoArray[1]{1}[loop1]{2};
            double wave = noiseWave[loop1][8];
            if(verbose) {
                debug_print("wave: " + wave);
            }
            //        Build key to read SPEC_resolution table
            if(wave < 103.1) {
                string keyCOL = "resol" + order;
                if(order == 23) {
                    // see email from BV 2010-05-04
                    keyCOL = "resol2";
                }
            } else {
                keyCOL = "resol1";
            }
            double resolkm = interpolate("SPEC_resolution",keyCOL,wave);
            //        Resolution in microns
            double resolmic = resolkm * wave / 300000.0;
            // Deal with possible loss of resolution
            // Compare instrument resolution with line width
            // User given line width
            double userWidth = rangeSPOT[loop1]{6};
            // User given width units
            string unitWidth = rangeSPOT[loop1]{8};
            // Is there a sensitivity degradation? 
            bool sensitDegrad = false;
            // Assume no degradtaion
            double degrad = 1.0;
            // Avoid divisiob by zero
            if(resolkm > 0.0) {
                // Do not compare torchons et servillettes
                if(unitWidth == "micron" && userWidth > resolmic) {
                    sensitDegrad = true;
                    degrad = sqrt(userWidth / resolmic);
                }
                if(unitWidth == "kms" && userWidth > resolkm) {
                    sensitDegrad = true;
                    degrad = sqrt(userWidth / resolkm);
                }
            }
            if(verbose) {
                debug_print("++line parameters: " + userWidth + " " + unitWidth);
                debug_print("++sensitDegrad: " + sensitDegrad);
                debug_print("++Degrad: " + degrad);
            }
            //        Add the information to current message stream
            msgLine[lineCnt] = "<li>FWHM at reference wavelength: " + dformat(resolkm,1) + " [km/s] or " + dformat(resolmic,3) + " [&micro;m]</li>";
            lineCnt = lineCnt + 1;
            if(sensitDegrad) {
                msgLine[lineCnt] = "<li><b>Warning:</b> the given line width, " + userWidth + " " + unitWidth + ", exceeds the instrumental FWHM; expect a loss of " + dformat(degrad,1) + " times in the LINE Signal-to-Noise ratio</li>";
                lineCnt = lineCnt + 1;
            }
            msgLine[lineCnt] = " <br>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "<li>Total duration (SRC+REF+PACS overheads) : " + trueObsTime + " [sec]</li>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "<li>SRC+REF (no overheads): " + trueSrcTime + " [sec]</li>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "</ul>";
            lineCnt = lineCnt + 1;
        }
        //    Continue with good[1]
        if(good[1]) {
            string assoc = bigTuple[loop1]{1}{0};
            //        Logic to identify LO and HI wavelength in range
            int nElem = length(bigTuple[loop1]{1}{2});
            double waveLO = bigTuple[loop1]{1}{2}[0];
            double waveHI = bigTuple[loop1]{1}{2}[nElem - 1];
            msgLine[lineCnt] = "<h4>" + dformat(waveLO,2) + "-" + dformat(waveHI,2) + " free range1 at " + assoc + "</h4>";
            lineCnt = lineCnt + 1;
            //        Go ahead and issue messages
            freeMsg = PacsRangeMessage(bigTuple[loop1]{1});
            //        Add new messages to already stored messages
            for(int loopM1 = 0 .. freeMsg{0} - 1) {
                msgLine[lineCnt] = freeMsg{1}[loopM1];
                lineCnt = lineCnt + 1;
            }
            //        Estimate resolution for given wavelength and order
            //        Need order and wavelength
            order = 1;
            if(assoc == "order2" || assoc == "order23") {
                order = 2;
            }
            if(assoc == "order3") {
                order = 3;
            }
            wave = bigTuple[loop1]{1}{1}[8];
            //        Build key to read SPEC_resolution table
            keyCOL = "resol" + order;
            resolkm = interpolate("SPEC_resolution",keyCOL,wave);
            //        Resolution in microns
            resolmic = resolkm * wave / 300000.0;
            //        Add the information to current message stream
            msgLine[lineCnt] = "<li>FWHM at reference wavelength: " + dformat(resolkm,1) + " [km/s] or " + dformat(resolmic,3) + " [&micro;m]</li>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "</ul>";
            lineCnt = lineCnt + 1;
        }
        if(good[2]) {
            assoc = bigTuple[loop1]{2}{0};
            //        Logic to identify LO and HI wavelength in range
            nElem = length(bigTuple[loop1]{2}{2});
            waveLO = bigTuple[loop1]{2}{2}[0];
            waveHI = bigTuple[loop1]{2}{2}[nElem - 1];
            msgLine[lineCnt] = "<h4>" + dformat(waveLO,2) + "-" + dformat(waveHI,2) + " free range2 at " + assoc + "</h4>";
            lineCnt = lineCnt + 1;
            //        Go ahead and issue messages
            freeMsg = PacsRangeMessage(bigTuple[loop1]{2});
            //        Add new messages to stored messages
            for(int loopM2 = 0 .. freeMsg{0} - 1) {
                msgLine[lineCnt] = freeMsg{1}[loopM2];
                lineCnt = lineCnt + 1;
            }
            //        Estimate resolution for given wavelength and order
            //        This is done here because the elements needed for the computation
            //        are at this level; i.e. it does not belong to bigTuple
            //        Need order and wavelength
            order = 1;
            if(assoc == "order2" || assoc == "order23") {
                order = 2;
            }
            if(assoc == "order3") {
                order = 3;
            }
            wave = bigTuple[loop1]{2}{1}[8];
            //        Build key to read SPEC_resolution table
            keyCOL = "resol" + order;
            resolkm = interpolate("SPEC_resolution",keyCOL,wave);
            //        Resolution in microns
            resolmic = resolkm * wave / 300000.0;
            //        Add the information to current message stream
            msgLine[lineCnt] = "<li>FWHM at reference wavelength: " + dformat(resolkm,1) + " [km/s] or " + dformat(resolmic,3) + " [&micro;m]</li>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "</ul>";
            lineCnt = lineCnt + 1;
        }
        //  End loop on nbLines
    }
    // Display message
    PacsMessageCenter("SpecRange summary",lineCnt,msgLine);
    // Return with bigTuple

    return bigTuple;
}

// File          : PACS_Spec_HK_Setup.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Prepare for Spectroscopy HK 
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
// Arguments     : none
//                 
//
// Description   : This script will only activate Spectroscopy HK
//                                              
// Comments      :  
//    
//
// Version       : 1.0
// History       : 1.0 / 18-Nov-2004 initial version
//                     
// 
procedure PACS_Spec_HK_Setup {
}{
    //DPU_SET_HK_LIST (SPEC for both channels)
    // tcsend PC003380 {PP005380 1} {PP025380 1}
    // waittime 0.5
    Pacs_DPU_SET_HK_LIST("SPEC","BOTH Array");
    delay(1);
    // putlog "Spec HK set" 
    // ---------------------
    // End of Procedure
    // ---------------------
}

// CVS comments  : $Id: WriteEndID.txt,v 1.9 2007/08/22 10:21:52 dcesarsk Exp $ 
// Purpose       : Set the BBID and OBSID to the predefined values shown
//                 in FIRST-FSC-DOC-0200 
//
// CUS script    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
// Original TCL  : N/A
// CVS file      : WriteEndID.txt
//
// Input arguments 
// Type  Name     DefVal  Description
//
// Description   : Equivalent of WriteOBSID and WriteBBID but using preset
//                 values for $OBSID and $BBID
//
// Dependencies  : Pacs_DMC_SET_BBID and Pacs_DMC_SET_OBSID
//
// Comments      : 
//
// Version       : 0.1 12-Oct-2004 First creation
// History       : 0.2 21-Oct-2004 Added write to CDMS
// 1.0 24-Mar-2005 DAC Removed all writes except to DMC (ASTRIUM environment)
// 1.1 20-oct-2005 BBID and then OBSID; do not sync() before leaving as this
//                 is the last TC ever.
// 1.2 19-apr-2006 Do sync so duration() will give time for next TC
// 1.2.1 22-nov-2006 Removed debug_print
// 2.0 21-aug-2007 According to HERSCHEL SCIENCE GROUND SEGMENT
//                 TO INSTRUMENTS INTERFACE CONTROL DOCUMENT
//                 reference FIRST-FSC-DOC-0200; OBSID should be set
//                 to zero when no observing (in OBS phase)
//                 Removed write to BBID as all blocks now end by setting
//                 their BBIDs to the default value (SCR-3507) 
// 2.1 02-jun-2009 VD SCR 6979: according to an ever changing documentation
//     		      OBSID has to be set to 50000000hex
//
procedure WriteEndID {
}{
    //   int iBBID = 0x40000000;
    //    // Write BBID to DEC/MEC
    //    Pacs_DMC_SET_BBID(iBBID);
    int iOBSID = 0x50000000;
    // Write OBSID to DEC/MEC
    Pacs_DMC_SET_OBSID(iOBSID);
    sync();
}

// File          : PACS_Phot_Switchoff.cus
// Missionphase  : PACS FM Test
//
// Purpose       : BOLC switch-off
//
// Author        : T. Mueller
//
// Arguments     : none
//
//
// Description   : Once we are satisfied with the tests, it is time to switch
//                 off the instrument by setting all biases to zero
//
// Comments      :  Coded based on PhFPU UM, draft 5, chapter 4.2.6
//
// Version       : 1.3
// History       : 1.0 / 02-Jul-2004 initial version by TM
//                 1.1    7-mar-2006 SEND_COMMAND_TO_BOLC renamed
//                 1.2   11-aug-2006 TM: updated for PhFPU UM, draft 5, chapter 4.2.6
//                 1.3   08-nov-2006 TM: groups off in the end
procedure PACS_Phot_Switchoff {
}{
    //***********************************
    //*
    //* Switch-off procedure for BOLC
    //* Part 1: switching off the detectors
    //*
    //* creation date : 15/09/05
    //*
    //*
    //***********************************
    // Switch off of all biases in the correct order
    //
    // Set all groups bol bias 02 (VL) to 0.00000000 Volt (0)
    //# P 00 02 0000
    int operand = 0x20000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 05 (VCH) to 0.00000000 Volt (0)
    //# P 00 05 0000
    operand = 0x50000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 01 (VH) to 0.00000000 Volt (0)
    //# P 00 01 0000
    operand = 0x10000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 03 (VRL) to 0.00000000 Volt (0)
    //# P 00 03 0000
    operand = 0x30000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 04 (VINJ) to 0.00000000 Volt (0)
    //# P 00 04 0000
    operand = 0x40000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 06 (VDL) to 0.00000000 Volt (0)
    //# P 00 06 0000
    operand = 0x60000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 08 (VGL) to 0.00000000 Volt (0)
    //# P 00 08 0000
    operand = 0x80000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 07 (VSS) to 0.00000000 Volt (0)
    //# P 00 07 0000
    operand = 0x70000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 16 (VDD) to 0.00000000 Volt (0)
    //# P 00 10 0000
    operand = 0x100000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 15 (VGG) to 0.00000000 Volt (0)
    //# P 00 0F 0000
    operand = 0xf0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 09 (CKRLH) to 0.00000000 Volt (0)
    //# P 00 09 0000
    operand = 0x90000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 10 (CKRLL) to 0.00000000 Volt (0)
    //# P 00 0A 0000
    operand = 0xa0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 11 (VDECX-H) to 0.00000000 Volt (0)
    //# P 00 0B 0000
    operand = 0xb0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 12 (VDECX-L) to 0.00000000 Volt (0)
    //# P 00 0C 0000
    operand = 0xc0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 13 (VSMS-H) to 0.00000000 Volt (0)
    //# P 00 0D 0000
    operand = 0xd0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 14 (VSMS-L) to 0.00000000 Volt (0)
    //# P 00 0E 0000
    operand = 0xe0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 18 (VDL-BU) to 0.00000000 Volt (0)
    //# P 00 12 0000
    operand = 0x120000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 20 (VH_BLIND) to 0.00000000 Volt (0)
    //# P 00 14 0000
    operand = 0x140000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 19 (VGL-BU) to 0.00000000 Volt (0)
    //# P 00 13 0000
    operand = 0x130000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 17 (VSS-BU) to 0.00000000 Volt (0)
    //# P 00 11 0000
    operand = 0x110000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //
    //
    // Wait 100 ms
    //# S 01 000064
    //
    // Switch-off of the protection biases
    //
    // Set all groups bol bias 21 (VDD-PROT-CL) OFF (0)
    //# P 00 15 0000
    operand = 0x150000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 22 (VDD-PROT-BU) OFF (0)
    //# P 00 16 0000
    operand = 0x160000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 23 (GND-BU) OFF (0)
    //# P 00 17 0000
    operand = 0x170000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //
    //***********************************
    //*
    //* Switch-off procedure for BOLC
    //* Part 2: switching off BOLC groups
    //*
    //* creation date : 15/09/05
    //*
    //*
    //***********************************
    // Switch off all groups
    // Set group on/off 00 hexa
    //# P 0A 00 00 00
    operand = 0xa000000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

// CVS comments  : $Id:
// Purpose       : compute nodThrow and skew angle from RA/DEC for OFF positions
//
// CUS author    : VD
// Script file   : nodOffFunction
//
// Input arguments
// type     name   description
// double   ra
// double   dec
// double   raoff  abs RA for OFF pos
// double   decoff abs DEC for OFF pos
// Return values
// Type            Description
// {double,double} nodOffparams: nodThrow and skew angle
//
// Description   : 
//                  
// Dependencies  : 
// Position source: (ra1, dec1)
// Position off: (ra2, dec2)
//  --> in degrees BUT throw should be in arcsec
// radif  = ra2-ra1
// skewAngle  = atan(sin(radif),cos(dec1)*tan(dec2)-sin(dec1)*cos(radif))
//
// deldec2 = (dec2-dec1)/2.0
// delra2 =  (ra2-ra1)/2.0d
// sindis = sqrt( sin(deldec2)*sin(deldec2) + cos(dec1)*cos(dec2)*sin(delra2)*sin(delra2) )
// throw = 2.0d*asin(sindis) 
//
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-apr-2010 VD creation PHS-1385 (and PHS-1386)
//                 1.0 16-jun-2010 PHS-1467 VD & RV : constrain pattnod to [0,360]
//
{double,double} procedure NodOffFunction {
    double ra = 0.0;
    double dec = 0.0;
    double raoff = 0.0;
    double decoff = 0.0;
}{
    double pi = 3.14159265;
    double ninety = 90.0 * pi / 180.0;
    double ra_on = ra * pi / 180.0;
    double dec_on = dec * pi / 180.0;
    double ra_off = raoff * pi / 180.0;
    double dec_off = decoff * pi / 180.0;
    // Position source: (ra_on, dec_on)
    // Position off: (ra_off, dec_off)
    // 
    // 
    // 
    double radif = ra_off - ra_on;
    double yy = cos(dec_on) * tan(dec_off) - sin(dec_on) * cos(radif);
    double skewAngle_rad = atan2(sin(radif),yy);
    double skewAngle = skewAngle_rad / pi * 180.0;
    double deldec_off = (dec_off - dec_on) / 2.0;
    double delra_off = (ra_off - ra_on) / 2.0;
    double sindis = sqrt(sin(deldec_off) * sin(deldec_off) + cos(dec_on) * cos(dec_off) * sin(delra_off) * sin(delra_off));
    double throw_rad = 2.0 * asin(sindis);
    double throw = 3600.0 * (throw_rad / pi * 180.0);
    // PHS-1467 constrain pattnod to [0,360]
    if(skewAngle < 0.0) {
        skewAngle = 360.0 + skewAngle;
    }
    // RV
    // The "chop throw" angle:
    //   double rv_throw = acos((sin(dec_on) * sin(dec_off)) +(cos(dec_on) * cos(dec_off) * cos(ra_off - ra_on)));
    //The skew angle:
    //  double rv_pattnod = acos((cos(rv_throw) - (cos(ninety-dec_on) * cos(ninety-dec_off))) / (sin(ninety-dec_on) * sin(ninety-dec_off)));
    //  double rv_deg_throw = (rv_throw / pi ) * 180.0;
    //  double rv_deg_pattnod = (rv_pattnod / pi ) * 180.0;
    //  debug_print("rv nodThrow: " +rv_deg_throw);
    //  debug_print("rv pattnod: " +rv_deg_pattnod);
    {double,double} nodOffparams = {skewAngle,throw};

    return nodOffparams;
}

// Missionphase  : PACS AVM ILT Orbit-Operations
//
// Purpose       :  OBCP 11: Photometry Calibration II, calls  DEC seq  6 
//
// OBCP author   : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky & Thomas G. Mueller
// CVS file      : OBCP_phot_cal_I.txt
//
// Arguments: 
// Type  Name                  Description
// int   nb_cal_cycles         p01 Nb of main loops
// int   chop_POS_0            p02 Chopper start position
// int   nb_rdouts_plateau     p03 Nb readouts per chopper plateau
// int   label_1               p04 1st of two labels
// int   label_2               p05 2nd of two labels
// int   chop_POS_1            p06 1st of 5 chopper positions
// int   chop_POS_2            p07 2nd of 5 chopper positions
// int   chop_POS_3            p08 3rd of 5 chopper positions
// int   chop_POS_4            p09 4th of 5 chopper positions
// int   chop_POS_5            p10 5th of 5 chopper positions
//
// Description   : This script mimics the OBCP_PHOT_CAL_II
//                 pseudo script, section 3.11.2 in PACS-ME-LI-005
//                 This CUS version computes the duration of the
//                 observation, as specified by the input parameters.
//                 It will also send the trigger TC to start the OBCP
//
// Dependencies  : DEC_phot_cal_I DECMEC sequence, 4.1.6
//                 WriteBBID to declare its BB identification 
// Comments      : 
//
// Version       : 0.1 29-Oct-2004 DAC
// History       : 
//
int[] block OBCP_phot_cal_II PACS 11 {
    int nb_cal_cycles = 2; // p01 Nb of main loops
    int chop_POS_0 = -22680; // p02 Chopper start position
    int nb_rdouts_plateau = 79; // p03 Nb readouts per chopper plateau
    int label_1 = 65; // p04 1st of two labels
    int label_2 = 129; // p05 2nd of two labels
    int chop_POS_1 = 45270; // p06 1st of 5 chopper positions
    int chop_POS_2 = 45770; // p07 2nd of 5 chopper positions
    int chop_POS_3 = 46270; // p08 3rd of 5 chopper positions
    int chop_POS_4 = 46770; // p09 4th of 5 chopper positions
    int chop_POS_5 = 47270; // p10 5th of 5 chopper positions
    int comp_mode_blu = 0; // Compression mode BLUE channel
    int comp_mode_red = 0; // Compression mode RED channel
    int chop_def = 0; // Chopper default position
}{
    // Starting time
    int time_start = time();
    // Anounce start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Bolo sampling rate (needed to compute readout duration)
    double bol_freq = dlookup("PACSparams","bolo_sample","freq_time");
    string bol_unit = slookup("PACSparams","bolo_sample","unit");
    // BOL readout frequency [Hz] and readout period [msec]
    double bol_period = 1000.0 / bol_freq;
    debug_print("Bolo frequency: " + bol_freq + " " + bol_unit);
    debug_print("Bolo period: " + bol_period + "[msec]");
    // Obtain duration of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duration of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duration of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Accumulated duration of this script [msec]
    int duration_msec = 0;
    // OBCP pseudo-code starts here; accumulate duration as it goes)
    // OBCP_PHOT_CAL_II(seq,seq_time,P#1-P#10,comp_mode_blu,comp_mode_red,chop_def)
    // Begin 
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Call CUS version of DECMEC sequence to obtain duration
    // Returns array with [duration_rdouts,duree_SRC,duree_REF,duree_CAL,duree_OVR]
    int[] duree1 = DMC_phot_cal_II(nb_cal_cycles,nb_rdouts_plateau);
    // Convert duration [readouts] into [msec]; add dmc_margin
    int seq_time = ifloor(double(duree1[0]) * bol_period) + dmc_margin;
    // Convert other times as well into msec
    duree_SRC = ifloor(double(duree1[1]) * bol_period);
    duree_REF = ifloor(double(duree1[2]) * bol_period);
    duree_CAL = ifloor(double(duree1[3]) * bol_period);
    duree_OVR = duree_OVR + ifloor(double(duree1[4]) * bol_period) + dmc_margin;
    // Tally into accumulated duration of OBCP   			 
    duration_msec = duration_msec + seq_time;
    // DMC_SYNCHRONIZE_ON_DETECTOR(4) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, comp_mode_blu, comp_mode_red, CHHKSUM) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_START_SEQUENCE 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT (seq_time)   
    // ; Check execution status of the sequence and in case of failure stop OBCP 
    // DMC_MOVE_CHOP_ABS(chop_def) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Issue TM(1,7) 
    // End
    // Now trigger execution of OBCP
    // This OBCP is number 11, requires 15 parameters, call DEC seq #6
    // which lasts seq_time [msec]
    string obcp_ID = "PHOT_CALIB_II";
    int obcp_par_nb = 15;
    int seq_DMC = 6;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_cal_cycles},{4,chop_POS_0},{5,nb_rdouts_plateau},{6,label_1},{7,label_2},{8,chop_POS_1},{9,chop_POS_2},{10,chop_POS_3},{11,chop_POS_4},{12,chop_POS_5},{13,comp_mode_blu},{14,comp_mode_red},{15,chop_def}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    // Add the OBCP "jitter"
    duration_msec = duration_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Return total duration [sec] to calling program
    // Create return time array; convert into [sec]
    int[] time_array = [duration_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // Set delay()
    delay(time_array[0]);
    // Ending time
    int time_elapsed = time() - time_start;
    time_array[0] = time_elapsed;
    // Return

    return time_array;
}

// CVS comments  : $Id: WriteOBSID.txt,v 1.7 2007/11/06 08:39:25 dcesarsk Exp $ 
// Missionphase  : 
//
// Purpose       : Set the OBSID via DEC/MEC; show decoded OBSID on
//                 user screen 
//
// CUS script    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
// Original TCL  : N/A
// CVS file      : WriteOBSID.txt
//
// Input arguments
// Type  Name     DefVal  Description
// int   iOBSID   N/A     OBSID obtained from environment
//
// Description   : Obtain OBSID from run environment and send TC to DMC
//                 Write decoded OBSID to log file
//
// Dependencies  : Pacs_DMC_SET_OBSID
//                 DecodeOBSID
//                 
// Comments      : 
//
// Version       : 0.1 23-Sep-2004 First creation
// History       : 0.2 28-Sep-2004 Remove set_unset; write
//                                 decoded OBSID to output log
//                 0.3  7-Oct-2004 Renamed to WriteOBSID to match to names of
//                                 related procedures
//                 0.4 12-Oct-2004 Added write to EGSE environment (need
//                                 to add write to IST environment ??)
//                 0.5 21-Oct-2004 Added write to CDMS
//                 1.0  9-May-2005 DAC Removed write to EGSE and CDMS (not
//                                 needed at Astrium)
//                 1.1 20-oct-2005 Added sync() as I will need the "true"
//                                 duration
//                 1.2  5-nov-2007 Added delay(1) before first TC to wait
//                                 for completion of bus_configure
//               :
//
procedure WriteOBSID_hk {
    int iOBSID = 0x20000000; // Observation ID  
}{
    // Wait 1 second to allow for bus_configure
    delay(1);
    // Write OBSID to DEC/MEC and decode to output log
    Pacs_DMC_SET_OBSID(iOBSID);
    // house keeping data rate
    ess_hk_data_rate(0.31);
    non_ess_hk_data_rate(4.0);
    // sync the bus
    sync();
    // Inform CUS debugger
    //   DecodeOBSID(iOBSID);
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// just to call Phot_lowFreq_direct_EMT
//
// Version 	: 1.0
// History	: 0.1 Thu Mar 29 2007
// 		: 1.0 04-mar-2008 translated into PV script VDP
//
obs PacsEng_Phot_low_freq_direct {
    /* Needed variables to call PacsEng_Phot_low_freq_direct                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_low_freq_direct                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Phot_lowFreq_direct_IST("cs2",2000,"BOLObias_ILT_lowFreq_CS2","BOLObias_preILT_standard_low")));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Phot_lowFreq_direct_IST("cs2",2000,"BOLObias_ILT_lowFreq_CS2","BOLObias_preILT_standard_low");
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: Array2grp_1.txt,v 1.2 2007/04/25 15:14:03 dcesarsk Exp $ 
// Missionphase  : 
//
// Purpose       : Utility to create  grp_1 tuples out of 1D arrays.
//                 Many PACS TCs require a grp_1 argument. It appears that grp_1 are
//                 defined as "1 element" tuples, which conceptually is the same as a 1D
//                 array. The checksum function, on the other hand, which is used to checksum
//                 some PACS operands, acts on 1D arrays. So a grp_1 list cannot be checksummed
//                 unless a 1D array is created from the grp_1. This is error prone as the
//                 following construct is needed in many CUS instances:
//
//                 // TC operand    
//                   {int}[] spu_par = [{ppf},{ppp},{tfp},{tcp}];
//
//                 // Check sum argument array
//                    int aux = [ppf,ppp,tfp,tcp];
//                    int check_sum = checksum("int",aux);
//
//                 The utility Array2grp_1 will create "spu_par " given the array aux as
//                 input:
//
//                 {int} [] spu_par = Array2grp_1(aux);
//
// TCL author    : N/A
// TCL file      : N/A
// CUS author    : DAC
// Script file   : Array2grp_1.txt 
//
// Input arguments
// type     name         description
// int[]    array_in     Any 1D array containing elements needed as operand for a TC
//
// Return values
// type      Name     Description
// {int} []           A 1D tuple constructed with all the elements of the input array  
//
// Description   : Extract elements from array_in and insert them as "tuples" in tuple_out
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 creation by XXX
{int}[] procedure Array2grp_1 {
    int[] array_in = [0,1,2,3];
}{
    // Get dimension of array_in
    int nb_elem = length(array_in);
    // Create output tuple
    {int}[] tuple_out = [{0}];
    {int} aux = {0};
    // and fill it with elements from array_in
    for(int loop = 0 .. nb_elem - 1) {
        aux = {array_in[loop]};
        tuple_out[loop] = aux;
    }

    return tuple_out;
}

//
// Purpose	: Record data in BOL-C test pattern mode
//
// Author	: Bart Vandenbussche
// CUS script	: PHOT_TestPattern_obs
// CVS file	: 
//
// Arguments	: time_in_testmode : time to stay in test pattern mode
//
// Description	: Switch to BOL-C HK+test pattern data mode
//                     wait <time_in_testmode> seconds
//                     Switch to BOL-C HK + bolometer data mode 
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on with configured BOLC
//                 
// Comments	: 
//
// Version	: 3.0
//               
// History	: 1.0 13-apr-2005 BV - First version
//                2.0 DAC 19-oct-2005 Added SPU start and stop
//                2.1 BV   11-04-2007  Changed raw channels to 0
//		  3.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
procedure Pacs_Phot_TestPattern {
    int time_in_testmode = 60;
}{
    // Switch ON SPU
    PHOT_spu_setup(0,0,0,0,true);
    // Bulding block containing the mode switch, a delay and a switch back
    PHOT_TestPattern(time_in_testmode);
    // Switch OFF SPU
    PHOT_spu_reset();
    sync();
}

// File          : PACS_Diaghk_Reset.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Switch off diagnostic hk flow  
//
// Author        : B.Vandenbussche
// CUSification  : DAC
// Arguments     :
//
// Description   :
//               :
// Comments      : 
//
// Version       : 1.0
// History       : 1.0 / 07-Jan-2004 initial version by BV 
//
procedure PACS_Diaghk_Reset {
}{
    Pacs_DMC_STOP_DIAG_HK();
    delay(1);
    //------------------
    // End of procedure
    //------------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : TM
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version       : 1.0
// 
// History       : 0.1 22-mar-2006
//                 0.2 09-oct-2006, TM
//		   1.0 04-mar-2008 translated into PV script
//
obs PacsEng_Phot_spu_reset {
    /* Needed variables to call PacsEng_Phot_spu_reset                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_spu_reset                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PHOT_spu_reset()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_spu_reset();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       :  Run a loop of tens of different sets of PID parameters
//
// Description  : For each set, performs a dozen of small and two larger movements
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
// 		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
obs PacsEng_Spec_Gra_IST_PID_Loop {
    /* Needed variables to call PacsEng_Spec_Gra_IST_PID_Loop                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_PID_Loop                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Gra_IST_PID_Loop()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Gra_IST_PID_Loop();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Spec_Gra_SFT_Warm.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Grating short functional test warm
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
// Arguments     : none
//
// Description   : This script will switch on and set all required
//                 parameters for the grating
//                              
// Comments      :      
//
// Version       : 1.0
// History       : 1.0 / 26-Nov-2004 initial version
//                    1.1 / 02-Mar-2007 PR Introduced DEGMODE configuration of the grating
//
procedure PACS_Spec_Gra_SFT_Warm {
}{
    debug_print("Start PACS_Spec_Gra_SFT_Warm");
    //
    // CONFIGURATION
    // HF's approach: everything is hardcoded
    // Default parameters :
    //		Rate = 32 (grating speed ~ 1 deg / sec)
    //		Maximum Output Current = 8192 (138.75 mA)
    //
    {int}[] parlist = [{32},{8192}];
    int[] aux = [32,8192];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_GRAT_DEGMOD_PAR(parlist,check_sum);
    delay(1);
    //
    // PC108420 "DMC_SWON_GRAT_CONT" SWITCH ON GRATING CONTROLLER
    //tcsend PC108420
    //waittime 0.5
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    // PC115420 "DMC_ENTER_GRAT_CONT_DEG,0"
    //tcsend PC115420 {PP092420 0}
    //waittime 0.5
    Pacs_DMC_ENTER_GRAT_CONT_DEG(0);
    delay(1);
    // PC112420 "DMC_MOVE_GRAT_REL" MOVE GRATING relative
    // tcsend PC113420 {PP078420 1280}
    // waittime 15.0
    Pacs_DMC_MOVE_GRAT_REL(1280);
    delay(15);
    // PC112420 "DMC_MOVE_GRAT_REL" MOVE GRATING relative
    //tcsend PC113420 {PP078420 -1280}
    //waittime 15.0
    Pacs_DMC_MOVE_GRAT_REL(-1280);
    delay(15);
    // "DMC_EXIT_GRAT_CONT_DEG" Exit grating open loop mode
    // tcsend PC116420
    // waittime 0.5
    Pacs_DMC_EXIT_GRAT_CONT_DEG();
    delay(1);
    // "DMC-SWITCH-OFF-GRAT-CONT" SWITCH OFF GRATING CONTROLLER
    // tcsend PC109420
    // waittime 0.5
    Pacs_DMC_SWOF_GRAT_CONT();
    delay(1);
    //-------------------------
    // End of Procedure
    //-------------------------
}

// Missionphase  : EQM IMT
//
// Purpose	: Configure the DPU bus list for burst mode
//
// Author	: Bart Vandenbussche	: 
//
// Arguments	: none
//
// Description	: Sets the bus list for burst mode
//                  
// Dependencies : none
//
// Comments	: 
//
// Version	: 1.0
//               
// History	: 1.0 20-04-2005 BV - created base on Thomas' tcl script
// 		  2.0 07-02-1008 VDP - added WriteBBID and WriteEndBB
//		      		 for PV phase
//
block Burstmode_setup_block PACS 307 {
}{
    // Obtain and set Block ID
    WriteBBID($BBID);
    Pacs_DPU_SET_BUS_LIST("ENABLE");
    // Reset Block ID
    WriteEndBB();
}

// Mission phase : Performace Verification Phase
//
// Purpose : PCD req.1.1.10 Explore the time constant after flux change for
//                          a flux levels using a CS and the background
//
// Author : Koryo Okumura
//
// Version : Wed Jul 29 08:48:33 EDT 2009
//
// CUS script : procedure Phot_bandpassDDCS
//
// Argument :
//   string biasTable = "BOLObias_standard_high" : Bias table file name containing the initial values
//   string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
//   int sideField = 7134 : Chopper angle for the FOV next to BB2
//   int chop_pos_CS2 = 21196 : Chopper angle for BB2
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description :
//   + All the biases are set group by group
//     except for VH, VL, VRL and VHBLIND
//   + Loop over 8 PACS chopper frequencies
//   +   Loop over 3 different biases (set group by group)
//   + The 4 biases are set to a safe value for caution
//   Signal plateau length provided by PACS chopper movement : [40, 2, 3, 4, 6, 8, 10, 16] readouts
//
// Dependencies : Previously obtaind data at high gain (PCD req.1.1.1bis)
//
// Comments : generated by IA script : cus_PVph_timeCont(False)
//                     SCR PACS-1873
//
procedure Phot_bandpassDDCS {
    string biasTable = "BOLObias_standard_low"; // Bias table file name containing the initial values
    string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
    int sideField = 7134; // Chopper angle for the FOV next to BB2
    int chop_pos_CS2 = 21196; // Chopper angle for BB2
}{
    //
    //**********************************************
    // Flux is 1.6pW on the bleu
    //     and 7.1pW on the red detector
    //**********************************************
    //
    //*******************************
    // Select Filter A (110 microns)
    //*******************************
    PHOT_fltw_move("POS A");
    //
    //*******************************
    // Bias setting of the detectors
    //*******************************
    //
    PHOT_change_biases(biasTable,"DDCS",gain);
    //
    // Set the PACS chopper at the central position
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //************************
    // Set DPU for Burst mode
    //************************
    Pacs_DPU_SET_BUS_LIST("ENABLE");
    //
    //
    //*****************************************************
    // PACS chopper cycle with 40 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,39,0,0,211,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,39,0,0,211,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,39,0,0,211,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 2 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,1,0,0,4220,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,1,0,0,4220,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,1,0,0,4220,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 3 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,2,0,0,2814,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,2,0,0,2814,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,2,0,0,2814,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 4 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,3,0,0,2110,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,3,0,0,2110,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,3,0,0,2110,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 6 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,5,0,0,1407,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,5,0,0,1407,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,5,0,0,1407,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 8 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,7,0,0,1055,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,7,0,0,1055,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,7,0,0,1055,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 10 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,9,0,0,844,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,9,0,0,844,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,9,0,0,844,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 16 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,15,0,0,528,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,15,0,0,528,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,15,0,0,528,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //************************
    // Set DPU for Burst mode
    //************************
    Pacs_DPU_SET_BUS_LIST("DISABLE");
    //
    //
    // Sychronize
    //
    sync();
}

// $Id: PacsCal_OBCP_chopped_photometry.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $
// Missionphase  : PACS PV Phase
//
// Purpose       : Wavelength calibration and instrumental profile
// Author        : HF
//
// Arguments     :
//
// Prerequisite  : PACS must be on and configured for Photometry
//
// Description   : Uses OBCP4 for executing a parameterized 
//
// Comments      :
//
// Version       : 0.2
// History       : 0.1 29-apr-2008 VDP created
//                 
obs PacsCal_OBCP_chopped_photometry {
    /* Pacs_OBCP_chopped_photometry parameters */
    int nb_SRC_REF = 0; // p01 Number of observations in OBS loop
    int chop_pos_SRC = 0; // p02 Chopper position for SRCE
    int nb_rdouts_plateau = 15; // p03 Number of readouts per chopper position 
    int chop_pos_REF1 = 0; // p04 Chopper position for BKG1
    int chop_pos_REF2 = 0; // p05 Chopper position for BB2
    int nb_cycles_obs_cal = 1; // p06 Number of obs/cal cycles
    int nb_CS1_CS2 = 38; // p07 Number of observations in CAL loop
    int chop_pos_CS1 = -21350; // p08 Chopper position for CS1
    int chop_pos_CS2 = 21200; // p09 Chopper position for CS2
    int comp_mode_blu = 0; // Compression mode BLUE channel 
    int comp_mode_red = 0; // Compression mode RED channel 
    int chop_def = 0; // Chopper default position
    /* Pointing basic parameters */
    int naifid = 0; // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // zoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    //Minimum slew time
    int tslewmin = imax(1,duration(WriteOBSID($OBSID)));
    //Initial hold
    int tih = 0;
    //Final hold
    int tfh = imax(1,duration(WriteEndID()));
    //Duration of "stable" pointing
    int tp = duration(Pacs_OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def));
    debug_print("tp:" + tp);
    //Use SPECTRO virtual aperture
    string ib = "P01_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            WriteOBSID($OBSID);
            data_rate(120.0);
        } else {
            if(state[0] == 3) {
                //     
                Pacs_OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
            } else {
                if(state[0] == 5) {
                    data_rate(0.0);
                    WriteEndID();
                }
            }
        }
    }
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowGainBiasDirect
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   + Set the biases group by group
//   + Set the blue filter 100um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + Set the blue filter 70um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//            New version
//
// Version : Thu Jul 10 21:22:36 CEST 2008
//
procedure Phot_lowGainBiasDirect {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
}{
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //************************************************
    // Set the biases and start SPU, then set the gain
    //************************************************
    //
    PHOT_set_biases(startBiasTable,"DIRECT","LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position -21350
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(-21350);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS1 at 48.0 K
    // corresponding to 1.20pW on the green and 5.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.2387937986138855 Volts
    Pacs_BOLC_SET_VH_G1(1.2387937986138855);
    // Set group 1 bol bias 02 (VL) to -0.01120620138611441 Volts
    Pacs_BOLC_SET_VL_G1(-0.01120620138611441);
    // Set group 1 bol bias 03 (VRL) to 0.39273766758961587 Volts
    Pacs_BOLC_SET_VRL_G1(0.39273766758961587);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1512820863099917 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1512820863099917);
    // Set group 2 bol bias 01 (VH) to 1.2273390654384582 Volts
    Pacs_BOLC_SET_VH_G2(1.2273390654384582);
    // Set group 2 bol bias 02 (VL) to -0.022660934561541744 Volts
    Pacs_BOLC_SET_VL_G2(-0.022660934561541744);
    // Set group 2 bol bias 03 (VRL) to 0.38921788688528014 Volts
    Pacs_BOLC_SET_VRL_G2(0.38921788688528014);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.147146340755748 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.147146340755748);
    // Set group 3 bol bias 01 (VH) to 1.2296951151089281 Volts
    Pacs_BOLC_SET_VH_G3(1.2296951151089281);
    // Set group 3 bol bias 02 (VL) to -0.020304884891071927 Volts
    Pacs_BOLC_SET_VL_G3(-0.020304884891071927);
    // Set group 3 bol bias 03 (VRL) to 0.3894736881379893 Volts
    Pacs_BOLC_SET_VRL_G3(0.3894736881379893);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.143754288741119 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.143754288741119);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.38519980225961764 Volts
    Pacs_BOLC_SET_VRL_G4(0.38519980225961764);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.141162817635055 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.141162817635055);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3228584222642352 Volts
    Pacs_BOLC_SET_VRL_G5(0.3228584222642352);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.067428073283575 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.067428073283575);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3146600782399116 Volts
    Pacs_BOLC_SET_VRL_G6(0.3146600782399116);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.057234963490994 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.057234963490994);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.457556831416261 Volts
    Pacs_BOLC_SET_VH_G1(1.457556831416261);
    // Set group 1 bol bias 02 (VL) to -0.14244316858373907 Volts
    Pacs_BOLC_SET_VL_G1(-0.14244316858373907);
    // Set group 1 bol bias 03 (VRL) to 0.39289728144635716 Volts
    Pacs_BOLC_SET_VRL_G1(0.39289728144635716);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151471417543995 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151471417543995);
    // Set group 2 bol bias 01 (VH) to 1.444087138537561 Volts
    Pacs_BOLC_SET_VH_G2(1.444087138537561);
    // Set group 2 bol bias 02 (VL) to -0.1559128614624391 Volts
    Pacs_BOLC_SET_VL_G2(-0.1559128614624391);
    // Set group 2 bol bias 03 (VRL) to 0.3888592125442133 Volts
    Pacs_BOLC_SET_VRL_G2(0.3888592125442133);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1467299681244416 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1467299681244416);
    // Set group 3 bol bias 01 (VH) to 1.4461276964721905 Volts
    Pacs_BOLC_SET_VH_G3(1.4461276964721905);
    // Set group 3 bol bias 02 (VL) to -0.15387230352780956 Volts
    Pacs_BOLC_SET_VL_G3(-0.15387230352780956);
    // Set group 3 bol bias 03 (VRL) to 0.389702653261631 Volts
    Pacs_BOLC_SET_VRL_G3(0.389702653261631);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1440068212666743 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1440068212666743);
    // Set group 4 bol bias 01 (VH) to 1.461535092163816 Volts
    Pacs_BOLC_SET_VH_G4(1.461535092163816);
    // Set group 4 bol bias 02 (VL) to -0.13846490783618415 Volts
    Pacs_BOLC_SET_VL_G4(-0.13846490783618415);
    // Set group 4 bol bias 03 (VRL) to 0.38666891513104484 Volts
    Pacs_BOLC_SET_VRL_G4(0.38666891513104484);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1428402830030913 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1428402830030913);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.393205233420548 Volts
    Pacs_BOLC_SET_VRL_G5(0.393205233420548);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.144845482323282 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.144845482323282);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3832953489422562 Volts
    Pacs_BOLC_SET_VRL_G6(0.3832953489422562);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.130607584787264 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.130607584787264);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.585769661368119 Volts
    Pacs_BOLC_SET_VH_G1(1.585769661368119);
    // Set group 1 bol bias 02 (VL) to -0.214230338631881 Volts
    Pacs_BOLC_SET_VL_G1(-0.214230338631881);
    // Set group 1 bol bias 03 (VRL) to 0.39304515064751266 Volts
    Pacs_BOLC_SET_VRL_G1(0.39304515064751266);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151646819089764 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151646819089764);
    // Set group 2 bol bias 01 (VH) to 1.571162518585341 Volts
    Pacs_BOLC_SET_VH_G2(1.571162518585341);
    // Set group 2 bol bias 02 (VL) to -0.22883748141465898 Volts
    Pacs_BOLC_SET_VL_G2(-0.22883748141465898);
    // Set group 2 bol bias 03 (VRL) to 0.3888194923923588 Volts
    Pacs_BOLC_SET_VRL_G2(0.3888194923923588);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1466838588402206 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1466838588402206);
    // Set group 3 bol bias 01 (VH) to 1.5728976206374763 Volts
    Pacs_BOLC_SET_VH_G3(1.5728976206374763);
    // Set group 3 bol bias 02 (VL) to -0.22710237936252387 Volts
    Pacs_BOLC_SET_VL_G3(-0.22710237936252387);
    // Set group 3 bol bias 03 (VRL) to 0.39016220909623334 Volts
    Pacs_BOLC_SET_VRL_G3(0.39016220909623334);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144513683272569 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144513683272569);
    // Set group 4 bol bias 01 (VH) to 1.5905884509492139 Volts
    Pacs_BOLC_SET_VH_G4(1.5905884509492139);
    // Set group 4 bol bias 02 (VL) to -0.2094115490507863 Volts
    Pacs_BOLC_SET_VL_G4(-0.2094115490507863);
    // Set group 4 bol bias 03 (VRL) to 0.38773283476462383 Volts
    Pacs_BOLC_SET_VRL_G4(0.38773283476462383);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440552130411823 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440552130411823);
    // Set group 5 bol bias 01 (VH) to 1.3241923646302258 Volts
    Pacs_BOLC_SET_VH_G5(1.3241923646302258);
    // Set group 5 bol bias 02 (VL) to -0.07580763536977406 Volts
    Pacs_BOLC_SET_VL_G5(-0.07580763536977406);
    // Set group 5 bol bias 03 (VRL) to 0.40046001102514184 Volts
    Pacs_BOLC_SET_VRL_G5(0.40046001102514184);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.153546375049013 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.153546375049013);
    // Set group 6 bol bias 01 (VH) to 1.37098688511416 Volts
    Pacs_BOLC_SET_VH_G6(1.37098688511416);
    // Set group 6 bol bias 02 (VL) to -0.02901311488583999 Volts
    Pacs_BOLC_SET_VL_G6(-0.02901311488583999);
    // Set group 6 bol bias 03 (VRL) to 0.43611847195239406 Volts
    Pacs_BOLC_SET_VRL_G6(0.43611847195239406);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1943115490461103 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1943115490461103);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7183370767248043 Volts
    Pacs_BOLC_SET_VH_G1(1.7183370767248043);
    // Set group 1 bol bias 02 (VL) to -0.2816629232751957 Volts
    Pacs_BOLC_SET_VL_G1(-0.2816629232751957);
    // Set group 1 bol bias 03 (VRL) to 0.39272615099525776 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272615099525776);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151268425592528 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151268425592528);
    // Set group 2 bol bias 01 (VH) to 1.7019559750109217 Volts
    Pacs_BOLC_SET_VH_G2(1.7019559750109217);
    // Set group 2 bol bias 02 (VL) to -0.29804402498907834 Volts
    Pacs_BOLC_SET_VL_G2(-0.29804402498907834);
    // Set group 2 bol bias 03 (VRL) to 0.388357028089395 Volts
    Pacs_BOLC_SET_VRL_G2(0.388357028089395);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461470122884805 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461470122884805);
    // Set group 3 bol bias 01 (VH) to 1.714454188425701 Volts
    Pacs_BOLC_SET_VH_G3(1.714454188425701);
    // Set group 3 bol bias 02 (VL) to -0.2855458115742991 Volts
    Pacs_BOLC_SET_VL_G3(-0.2855458115742991);
    // Set group 3 bol bias 03 (VRL) to 0.401550404399907 Volts
    Pacs_BOLC_SET_VRL_G3(0.401550404399907);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.15707892246005 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.15707892246005);
    // Set group 4 bol bias 01 (VH) to 1.7242793470756728 Volts
    Pacs_BOLC_SET_VH_G4(1.7242793470756728);
    // Set group 4 bol bias 02 (VL) to -0.27572065292432724 Volts
    Pacs_BOLC_SET_VL_G4(-0.27572065292432724);
    // Set group 4 bol bias 03 (VRL) to 0.3889940535267571 Volts
    Pacs_BOLC_SET_VRL_G4(0.3889940535267571);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454955805079967 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454955805079967);
    // Set group 5 bol bias 01 (VH) to 1.4496153041151667 Volts
    Pacs_BOLC_SET_VH_G5(1.4496153041151667);
    // Set group 5 bol bias 02 (VL) to -0.15038469588483347 Volts
    Pacs_BOLC_SET_VL_G5(-0.15038469588483347);
    // Set group 5 bol bias 03 (VRL) to 0.39905723488551603 Volts
    Pacs_BOLC_SET_VRL_G5(0.39905723488551603);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.15186471364944 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.15186471364944);
    // Set group 6 bol bias 01 (VH) to 1.4970241024935167 Volts
    Pacs_BOLC_SET_VH_G6(1.4970241024935167);
    // Set group 6 bol bias 02 (VL) to -0.10297589750648331 Volts
    Pacs_BOLC_SET_VL_G6(-0.10297589750648331);
    // Set group 6 bol bias 03 (VRL) to 0.43401661473441144 Volts
    Pacs_BOLC_SET_VRL_G6(0.43401661473441144);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1918048548715423 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1918048548715423);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8585362347937342 Volts
    Pacs_BOLC_SET_VH_G1(1.8585362347937342);
    // Set group 1 bol bias 02 (VL) to -0.34146376520626587 Volts
    Pacs_BOLC_SET_VL_G1(-0.34146376520626587);
    // Set group 1 bol bias 03 (VRL) to 0.3925990888065586 Volts
    Pacs_BOLC_SET_VRL_G1(0.3925990888065586);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1511177079955788 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1511177079955788);
    // Set group 2 bol bias 01 (VH) to 1.838716500789082 Volts
    Pacs_BOLC_SET_VH_G2(1.838716500789082);
    // Set group 2 bol bias 02 (VL) to -0.3612834992109183 Volts
    Pacs_BOLC_SET_VL_G2(-0.3612834992109183);
    // Set group 2 bol bias 03 (VRL) to 0.38744902130448367 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744902130448367);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1450929993071512 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1450929993071512);
    // Set group 3 bol bias 01 (VH) to 1.85163190367321 Volts
    Pacs_BOLC_SET_VH_G3(1.85163190367321);
    // Set group 3 bol bias 02 (VL) to -0.34836809632679006 Volts
    Pacs_BOLC_SET_VL_G3(-0.34836809632679006);
    // Set group 3 bol bias 03 (VRL) to 0.4020826639883897 Volts
    Pacs_BOLC_SET_VRL_G3(0.4020826639883897);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157667831933953 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157667831933953);
    // Set group 4 bol bias 01 (VH) to 1.8658389594227858 Volts
    Pacs_BOLC_SET_VH_G4(1.8658389594227858);
    // Set group 4 bol bias 02 (VL) to -0.3341610405772144 Volts
    Pacs_BOLC_SET_VL_G4(-0.3341610405772144);
    // Set group 4 bol bias 03 (VRL) to 0.39087822103495706 Volts
    Pacs_BOLC_SET_VRL_G4(0.39087822103495706);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1476476539739764 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1476476539739764);
    // Set group 5 bol bias 01 (VH) to 1.5144117466818523 Volts
    Pacs_BOLC_SET_VH_G5(1.5144117466818523);
    // Set group 5 bol bias 02 (VL) to -0.18558825331814774 Volts
    Pacs_BOLC_SET_VL_G5(-0.18558825331814774);
    // Set group 5 bol bias 03 (VRL) to 0.39841417525779244 Volts
    Pacs_BOLC_SET_VRL_G5(0.39841417525779244);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151093482383656 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151093482383656);
    // Set group 6 bol bias 01 (VH) to 1.5622243148794812 Volts
    Pacs_BOLC_SET_VH_G6(1.5622243148794812);
    // Set group 6 bol bias 02 (VL) to -0.13777568512051877 Volts
    Pacs_BOLC_SET_VL_G6(-0.13777568512051877);
    // Set group 6 bol bias 03 (VRL) to 0.43327546525989336 Volts
    Pacs_BOLC_SET_VRL_G6(0.43327546525989336);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1909210235812204 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1909210235812204);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0202028596068895 Volts
    Pacs_BOLC_SET_VH_G1(2.0202028596068895);
    // Set group 1 bol bias 02 (VL) to -0.3797971403931106 Volts
    Pacs_BOLC_SET_VL_G1(-0.3797971403931106);
    // Set group 1 bol bias 03 (VRL) to 0.4031554178502121 Volts
    Pacs_BOLC_SET_VRL_G1(0.4031554178502121);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163634915975391 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163634915975391);
    // Set group 2 bol bias 01 (VH) to 1.9845954458032045 Volts
    Pacs_BOLC_SET_VH_G2(1.9845954458032045);
    // Set group 2 bol bias 02 (VL) to -0.41540455419679545 Volts
    Pacs_BOLC_SET_VL_G2(-0.41540455419679545);
    // Set group 2 bol bias 03 (VRL) to 0.38611513204716796 Volts
    Pacs_BOLC_SET_VRL_G2(0.38611513204716796);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1435447105412555 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1435447105412555);
    // Set group 3 bol bias 01 (VH) to 2.0091673911193446 Volts
    Pacs_BOLC_SET_VH_G3(2.0091673911193446);
    // Set group 3 bol bias 02 (VL) to -0.39083260888065513 Volts
    Pacs_BOLC_SET_VL_G3(-0.39083260888065513);
    // Set group 3 bol bias 03 (VRL) to 0.4135751200095534 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135751200095534);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170378532407885 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170378532407885);
    // Set group 4 bol bias 01 (VH) to 2.0158037297874873 Volts
    Pacs_BOLC_SET_VH_G4(2.0158037297874873);
    // Set group 4 bol bias 02 (VL) to -0.3841962702125128 Volts
    Pacs_BOLC_SET_VL_G4(-0.3841962702125128);
    // Set group 4 bol bias 03 (VRL) to 0.3915724280149063 Volts
    Pacs_BOLC_SET_VRL_G4(0.3915724280149063);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1484406507127387 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1484406507127387);
    // Set group 5 bol bias 01 (VH) to 1.5900913542685013 Volts
    Pacs_BOLC_SET_VH_G5(1.5900913542685013);
    // Set group 5 bol bias 02 (VL) to -0.20990864573149876 Volts
    Pacs_BOLC_SET_VL_G5(-0.20990864573149876);
    // Set group 5 bol bias 03 (VRL) to 0.40844955554354584 Volts
    Pacs_BOLC_SET_VRL_G5(0.40844955554354584);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.163093126853995 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.163093126853995);
    // Set group 6 bol bias 01 (VH) to 1.6276124853923464 Volts
    Pacs_BOLC_SET_VH_G6(1.6276124853923464);
    // Set group 6 bol bias 02 (VL) to -0.17238751460765359 Volts
    Pacs_BOLC_SET_VL_G6(-0.17238751460765359);
    // Set group 6 bol bias 03 (VRL) to 0.43216415132235575 Volts
    Pacs_BOLC_SET_VRL_G6(0.43216415132235575);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1895819441738285 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1895819441738285);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.1116098904579044 Volts
    Pacs_BOLC_SET_VH_G1(2.1116098904579044);
    // Set group 1 bol bias 02 (VL) to -0.3883901095420957 Volts
    Pacs_BOLC_SET_VL_G1(-0.3883901095420957);
    // Set group 1 bol bias 03 (VRL) to 0.4140062165204889 Volts
    Pacs_BOLC_SET_VRL_G1(0.4140062165204889);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764790937594767 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764790937594767);
    // Set group 2 bol bias 01 (VH) to 2.0619437696054 Volts
    Pacs_BOLC_SET_VH_G2(2.0619437696054);
    // Set group 2 bol bias 02 (VL) to -0.43805623039459973 Volts
    Pacs_BOLC_SET_VL_G2(-0.43805623039459973);
    // Set group 2 bol bias 03 (VRL) to 0.38550512685952865 Volts
    Pacs_BOLC_SET_VRL_G2(0.38550512685952865);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1428366925092326 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1428366925092326);
    // Set group 3 bol bias 01 (VH) to 2.0871836925661524 Volts
    Pacs_BOLC_SET_VH_G3(2.0871836925661524);
    // Set group 3 bol bias 02 (VL) to -0.4128163074338474 Volts
    Pacs_BOLC_SET_VL_G3(-0.4128163074338474);
    // Set group 3 bol bias 03 (VRL) to 0.41367957243777737 Volts
    Pacs_BOLC_SET_VRL_G3(0.41367957243777737);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704940139980216 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704940139980216);
    // Set group 4 bol bias 01 (VH) to 2.095481525504912 Volts
    Pacs_BOLC_SET_VH_G4(2.095481525504912);
    // Set group 4 bol bias 02 (VL) to -0.40451847449508793 Volts
    Pacs_BOLC_SET_VL_G4(-0.40451847449508793);
    // Set group 4 bol bias 03 (VRL) to 0.3918611768543646 Volts
    Pacs_BOLC_SET_VRL_G4(0.3918611768543646);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.148770503204217 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.148770503204217);
    // Set group 5 bol bias 01 (VH) to 1.6549108970361488 Volts
    Pacs_BOLC_SET_VH_G5(1.6549108970361488);
    // Set group 5 bol bias 02 (VL) to -0.24508910296385117 Volts
    Pacs_BOLC_SET_VL_G5(-0.24508910296385117);
    // Set group 5 bol bias 03 (VRL) to 0.4072430925044988 Volts
    Pacs_BOLC_SET_VRL_G5(0.4072430925044988);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161651131887083 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161651131887083);
    // Set group 6 bol bias 01 (VH) to 1.6931168196610022 Volts
    Pacs_BOLC_SET_VH_G6(1.6931168196610022);
    // Set group 6 bol bias 02 (VL) to -0.20688318033899758 Volts
    Pacs_BOLC_SET_VL_G6(-0.20688318033899758);
    // Set group 6 bol bias 03 (VRL) to 0.4307551048853343 Volts
    Pacs_BOLC_SET_VRL_G6(0.4307551048853343);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187881524411063 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187881524411063);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.196006753214598 Volts
    Pacs_BOLC_SET_VH_G1(2.196006753214598);
    // Set group 1 bol bias 02 (VL) to -0.4039932467854021 Volts
    Pacs_BOLC_SET_VL_G1(-0.4039932467854021);
    // Set group 1 bol bias 03 (VRL) to 0.41357184702417576 Volts
    Pacs_BOLC_SET_VRL_G1(0.41357184702417576);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1759648938728384 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1759648938728384);
    // Set group 2 bol bias 01 (VH) to 2.1433243650504217 Volts
    Pacs_BOLC_SET_VH_G2(2.1433243650504217);
    // Set group 2 bol bias 02 (VL) to -0.45667563494957836 Volts
    Pacs_BOLC_SET_VL_G2(-0.45667563494957836);
    // Set group 2 bol bias 03 (VRL) to 0.3850880425693594 Volts
    Pacs_BOLC_SET_VRL_G2(0.3850880425693594);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14235260562423 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14235260562423);
    // Set group 3 bol bias 01 (VH) to 2.1686669393324536 Volts
    Pacs_BOLC_SET_VH_G3(2.1686669393324536);
    // Set group 3 bol bias 02 (VL) to -0.43133306066754634 Volts
    Pacs_BOLC_SET_VL_G3(-0.43133306066754634);
    // Set group 3 bol bias 03 (VRL) to 0.41346974712361556 Volts
    Pacs_BOLC_SET_VRL_G3(0.41346974712361556);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.17026203238048 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.17026203238048);
    // Set group 4 bol bias 01 (VH) to 2.1793962970285237 Volts
    Pacs_BOLC_SET_VH_G4(2.1793962970285237);
    // Set group 4 bol bias 02 (VL) to -0.42060370297147653 Volts
    Pacs_BOLC_SET_VL_G4(-0.42060370297147653);
    // Set group 4 bol bias 03 (VRL) to 0.39239244557899233 Volts
    Pacs_BOLC_SET_VRL_G4(0.39239244557899233);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.149377418431709 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.149377418431709);
    // Set group 5 bol bias 01 (VH) to 1.7225616727109463 Volts
    Pacs_BOLC_SET_VH_G5(1.7225616727109463);
    // Set group 5 bol bias 02 (VL) to -0.27743832728905365 Volts
    Pacs_BOLC_SET_VL_G5(-0.27743832728905365);
    // Set group 5 bol bias 03 (VRL) to 0.40580736393386424 Volts
    Pacs_BOLC_SET_VRL_G5(0.40580736393386424);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.159935285624683 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.159935285624683);
    // Set group 6 bol bias 01 (VH) to 1.7622827443723812 Volts
    Pacs_BOLC_SET_VH_G6(1.7622827443723812);
    // Set group 6 bol bias 02 (VL) to -0.23771725562761872 Volts
    Pacs_BOLC_SET_VL_G6(-0.23771725562761872);
    // Set group 6 bol bias 03 (VRL) to 0.4298269773716583 Volts
    Pacs_BOLC_SET_VRL_G6(0.4298269773716583);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1867614355291423 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1867614355291423);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2848572542958143 Volts
    Pacs_BOLC_SET_VH_G1(2.2848572542958143);
    // Set group 1 bol bias 02 (VL) to -0.4151427457041857 Volts
    Pacs_BOLC_SET_VL_G1(-0.4151427457041857);
    // Set group 1 bol bias 03 (VRL) to 0.4131612503913013 Volts
    Pacs_BOLC_SET_VRL_G1(0.4131612503913013);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175478838481054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175478838481054);
    // Set group 2 bol bias 01 (VH) to 2.227445675456437 Volts
    Pacs_BOLC_SET_VH_G2(2.227445675456437);
    // Set group 2 bol bias 02 (VL) to -0.47255432454356333 Volts
    Pacs_BOLC_SET_VL_G2(-0.47255432454356333);
    // Set group 2 bol bias 03 (VRL) to 0.38358395077791313 Volts
    Pacs_BOLC_SET_VRL_G2(0.38358395077791313);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1406069736852453 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1406069736852453);
    // Set group 3 bol bias 01 (VH) to 2.2541010275551834 Volts
    Pacs_BOLC_SET_VH_G3(2.2541010275551834);
    // Set group 3 bol bias 02 (VL) to -0.4458989724448167 Volts
    Pacs_BOLC_SET_VL_G3(-0.4458989724448167);
    // Set group 3 bol bias 03 (VRL) to 0.4127976284436742 Volts
    Pacs_BOLC_SET_VRL_G3(0.4127976284436742);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1695189208400576 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1695189208400576);
    // Set group 4 bol bias 01 (VH) to 2.2792127013060117 Volts
    Pacs_BOLC_SET_VH_G4(2.2792127013060117);
    // Set group 4 bol bias 02 (VL) to -0.4207872986939883 Volts
    Pacs_BOLC_SET_VL_G4(-0.4207872986939883);
    // Set group 4 bol bias 03 (VRL) to 0.4047407291500576 Volts
    Pacs_BOLC_SET_VRL_G4(0.4047407291500576);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1634937911711 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1634937911711);
    // Set group 5 bol bias 01 (VH) to 1.8021521044604545 Volts
    Pacs_BOLC_SET_VH_G5(1.8021521044604545);
    // Set group 5 bol bias 02 (VL) to -0.2978478955395457 Volts
    Pacs_BOLC_SET_VL_G5(-0.2978478955395457);
    // Set group 5 bol bias 03 (VRL) to 0.4159065601971136 Volts
    Pacs_BOLC_SET_VRL_G5(0.4159065601971136);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.17200886747967 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.17200886747967);
    // Set group 6 bol bias 01 (VH) to 1.8316635864270032 Volts
    Pacs_BOLC_SET_VH_G6(1.8316635864270032);
    // Set group 6 bol bias 02 (VL) to -0.26833641357299687 Volts
    Pacs_BOLC_SET_VL_G6(-0.26833641357299687);
    // Set group 6 bol bias 03 (VRL) to 0.4288145963722081 Volts
    Pacs_BOLC_SET_VRL_G6(0.4288145963722081);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.185539634602432 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.185539634602432);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3796037366573897 Volts
    Pacs_BOLC_SET_VH_G1(2.3796037366573897);
    // Set group 1 bol bias 02 (VL) to -0.4203962633426101 Volts
    Pacs_BOLC_SET_VL_G1(-0.4203962633426101);
    // Set group 1 bol bias 03 (VRL) to 0.4129099400989898 Volts
    Pacs_BOLC_SET_VRL_G1(0.4129099400989898);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175181344026924 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175181344026924);
    // Set group 2 bol bias 01 (VH) to 2.315754480139234 Volts
    Pacs_BOLC_SET_VH_G2(2.315754480139234);
    // Set group 2 bol bias 02 (VL) to -0.4842455198607661 Volts
    Pacs_BOLC_SET_VL_G2(-0.4842455198607661);
    // Set group 2 bol bias 03 (VRL) to 0.38156757008948644 Volts
    Pacs_BOLC_SET_VRL_G2(0.38156757008948644);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.138266993828065 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.138266993828065);
    // Set group 3 bol bias 01 (VH) to 2.3449665772192874 Volts
    Pacs_BOLC_SET_VH_G3(2.3449665772192874);
    // Set group 3 bol bias 02 (VL) to -0.45503342278071257 Volts
    Pacs_BOLC_SET_VL_G3(-0.45503342278071257);
    // Set group 3 bol bias 03 (VRL) to 0.4122322683327103 Volts
    Pacs_BOLC_SET_VRL_G3(0.4122322683327103);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1688938193526224 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1688938193526224);
    // Set group 4 bol bias 01 (VH) to 2.360152158437928 Volts
    Pacs_BOLC_SET_VH_G4(2.360152158437928);
    // Set group 4 bol bias 02 (VL) to -0.4398478415620719 Volts
    Pacs_BOLC_SET_VL_G4(-0.4398478415620719);
    // Set group 4 bol bias 03 (VRL) to 0.39354738531821554 Volts
    Pacs_BOLC_SET_VRL_G4(0.39354738531821554);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150696897295742 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150696897295742);
    // Set group 5 bol bias 01 (VH) to 1.8624422796333608 Volts
    Pacs_BOLC_SET_VH_G5(1.8624422796333608);
    // Set group 5 bol bias 02 (VL) to -0.3375577203666393 Volts
    Pacs_BOLC_SET_VL_G5(-0.3375577203666393);
    // Set group 5 bol bias 03 (VRL) to 0.4028017551941114 Volts
    Pacs_BOLC_SET_VRL_G5(0.4028017551941114);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.156343875220547 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.156343875220547);
    // Set group 6 bol bias 01 (VH) to 1.9050654119965236 Volts
    Pacs_BOLC_SET_VH_G6(1.9050654119965236);
    // Set group 6 bol bias 02 (VL) to -0.2949345880034766 Volts
    Pacs_BOLC_SET_VL_G6(-0.2949345880034766);
    // Set group 6 bol bias 03 (VRL) to 0.42788441761189455 Volts
    Pacs_BOLC_SET_VRL_G6(0.42788441761189455);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1844170100895375 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1844170100895375);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6080079699591967 Volts
    Pacs_BOLC_SET_VH_G1(2.6080079699591967);
    // Set group 1 bol bias 02 (VL) to -0.39199203004080335 Volts
    Pacs_BOLC_SET_VL_G1(-0.39199203004080335);
    // Set group 1 bol bias 03 (VRL) to 0.4353039674693117 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353039674693117);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2016826896367014 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2016826896367014);
    // Set group 2 bol bias 01 (VH) to 2.5212704911688184 Volts
    Pacs_BOLC_SET_VH_G2(2.5212704911688184);
    // Set group 2 bol bias 02 (VL) to -0.4787295088311815 Volts
    Pacs_BOLC_SET_VL_G2(-0.4787295088311815);
    // Set group 2 bol bias 03 (VRL) to 0.39184175711517744 Volts
    Pacs_BOLC_SET_VRL_G2(0.39184175711517744);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150192531202592 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150192531202592);
    // Set group 3 bol bias 01 (VH) to 2.5446946302676037 Volts
    Pacs_BOLC_SET_VH_G3(2.5446946302676037);
    // Set group 3 bol bias 02 (VL) to -0.4553053697323962 Volts
    Pacs_BOLC_SET_VL_G3(-0.4553053697323962);
    // Set group 3 bol bias 03 (VRL) to 0.41118382754245053 Volts
    Pacs_BOLC_SET_VRL_G3(0.41118382754245053);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1677345299207764 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1677345299207764);
    // Set group 4 bol bias 01 (VH) to 2.582263974911207 Volts
    Pacs_BOLC_SET_VH_G4(2.582263974911207);
    // Set group 4 bol bias 02 (VL) to -0.4177360250887929 Volts
    Pacs_BOLC_SET_VL_G4(-0.4177360250887929);
    // Set group 4 bol bias 03 (VRL) to 0.4155747259799741 Volts
    Pacs_BOLC_SET_VRL_G4(0.4155747259799741);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1758807093660604 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1758807093660604);
    // Set group 5 bol bias 01 (VH) to 2.0139550919820626 Volts
    Pacs_BOLC_SET_VH_G5(2.0139550919820626);
    // Set group 5 bol bias 02 (VL) to -0.38604490801793717 Volts
    Pacs_BOLC_SET_VL_G5(-0.38604490801793717);
    // Set group 5 bol bias 03 (VRL) to 0.39874967908065667 Volts
    Pacs_BOLC_SET_VRL_G5(0.39874967908065667);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151495860090233 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151495860090233);
    // Set group 6 bol bias 01 (VH) to 2.0603593375586526 Volts
    Pacs_BOLC_SET_VH_G6(2.0603593375586526);
    // Set group 6 bol bias 02 (VL) to -0.3396406624413473 Volts
    Pacs_BOLC_SET_VL_G6(-0.3396406624413473);
    // Set group 6 bol bias 03 (VRL) to 0.4254561262075288 Volts
    Pacs_BOLC_SET_VRL_G6(0.4254561262075288);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1814861909041072 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1814861909041072);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.958669888952511 Volts
    Pacs_BOLC_SET_VH_G1(2.958669888952511);
    // Set group 1 bol bias 02 (VL) to -0.3413301110474886 Volts
    Pacs_BOLC_SET_VL_G1(-0.3413301110474886);
    // Set group 1 bol bias 03 (VRL) to 0.43496400697889964 Volts
    Pacs_BOLC_SET_VRL_G1(0.43496400697889964);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201282516353445 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201282516353445);
    // Set group 2 bol bias 01 (VH) to 2.877259199990068 Volts
    Pacs_BOLC_SET_VH_G2(2.877259199990068);
    // Set group 2 bol bias 02 (VL) to -0.4227408000099317 Volts
    Pacs_BOLC_SET_VL_G2(-0.4227408000099317);
    // Set group 2 bol bias 03 (VRL) to 0.41471523343174815 Volts
    Pacs_BOLC_SET_VRL_G2(0.41471523343174815);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1767077990321737 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1767077990321737);
    // Set group 3 bol bias 01 (VH) to 2.917604872367548 Volts
    Pacs_BOLC_SET_VH_G3(2.917604872367548);
    // Set group 3 bol bias 02 (VL) to -0.38239512763245215 Volts
    Pacs_BOLC_SET_VL_G3(-0.38239512763245215);
    // Set group 3 bol bias 03 (VRL) to 0.43322793583509106 Volts
    Pacs_BOLC_SET_VRL_G3(0.43322793583509106);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1920928084003948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1920928084003948);
    // Set group 4 bol bias 01 (VH) to 2.9326607124177055 Volts
    Pacs_BOLC_SET_VH_G4(2.9326607124177055);
    // Set group 4 bol bias 02 (VL) to -0.36733928758229417 Volts
    Pacs_BOLC_SET_VL_G4(-0.36733928758229417);
    // Set group 4 bol bias 03 (VRL) to 0.4248388375312061 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248388375312061);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.186464990521523 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.186464990521523);
    // Set group 5 bol bias 01 (VH) to 2.2123399887514554 Volts
    Pacs_BOLC_SET_VH_G5(2.2123399887514554);
    // Set group 5 bol bias 02 (VL) to -0.38766001124854466 Volts
    Pacs_BOLC_SET_VL_G5(-0.38766001124854466);
    // Set group 5 bol bias 03 (VRL) to 0.4257278403385899 Volts
    Pacs_BOLC_SET_VRL_G5(0.4257278403385899);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1837591130416554 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1837591130416554);
    // Set group 6 bol bias 01 (VH) to 2.2318001783201304 Volts
    Pacs_BOLC_SET_VH_G6(2.2318001783201304);
    // Set group 6 bol bias 02 (VL) to -0.36819982167986975 Volts
    Pacs_BOLC_SET_VL_G6(-0.36819982167986975);
    // Set group 6 bol bias 03 (VRL) to 0.423759377774352 Volts
    Pacs_BOLC_SET_VRL_G6(0.423759377774352);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1794381888209813 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1794381888209813);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //**********************************************
    // Set the PACS chopper at the position 21200
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(21200);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS2 at 58.0 K
    // corresponding to 1.55pW on the green and 6.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38123347242944194 Volts
    Pacs_BOLC_SET_VRL_G1(0.38123347242944194);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1376407910122737 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1376407910122737);
    // Set group 2 bol bias 01 (VH) to 1.2387003199108486 Volts
    Pacs_BOLC_SET_VH_G2(1.2387003199108486);
    // Set group 2 bol bias 02 (VL) to -0.011299680089151297 Volts
    Pacs_BOLC_SET_VL_G2(-0.011299680089151297);
    // Set group 2 bol bias 03 (VRL) to 0.3885454558920056 Volts
    Pacs_BOLC_SET_VRL_G2(0.3885454558920056);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146365745091845 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146365745091845);
    // Set group 3 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G3(1.24);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.38773615773066705 Volts
    Pacs_BOLC_SET_VRL_G3(0.38773615773066705);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.141837957849939 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.141837957849939);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3746747870084728 Volts
    Pacs_BOLC_SET_VRL_G4(0.3746747870084728);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1291508925975227 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1291508925975227);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.30644740182478597 Volts
    Pacs_BOLC_SET_VRL_G5(0.30644740182478597);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051135159732571 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051135159732571);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.29823090263814045 Volts
    Pacs_BOLC_SET_VRL_G6(0.29823090263814045);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0409569182979173 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0409569182979173);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4721285832931112 Volts
    Pacs_BOLC_SET_VH_G1(1.4721285832931112);
    // Set group 1 bol bias 02 (VL) to -0.12787141670688873 Volts
    Pacs_BOLC_SET_VL_G1(-0.12787141670688873);
    // Set group 1 bol bias 03 (VRL) to 0.3926297476827718 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926297476827718);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151154074587398 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151154074587398);
    // Set group 2 bol bias 01 (VH) to 1.4563242224495716 Volts
    Pacs_BOLC_SET_VH_G2(1.4563242224495716);
    // Set group 2 bol bias 02 (VL) to -0.14367577755042849 Volts
    Pacs_BOLC_SET_VL_G2(-0.14367577755042849);
    // Set group 2 bol bias 03 (VRL) to 0.3881765529411487 Volts
    Pacs_BOLC_SET_VRL_G2(0.3881765529411487);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.145937513130471 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.145937513130471);
    // Set group 3 bol bias 01 (VH) to 1.45972772124239 Volts
    Pacs_BOLC_SET_VH_G3(1.45972772124239);
    // Set group 3 bol bias 02 (VL) to -0.14027227875761006 Volts
    Pacs_BOLC_SET_VL_G3(-0.14027227875761006);
    // Set group 3 bol bias 03 (VRL) to 0.38988919840997094 Volts
    Pacs_BOLC_SET_VRL_G3(0.38988919840997094);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1442125685158864 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1442125685158864);
    // Set group 4 bol bias 01 (VH) to 1.4747276174033868 Volts
    Pacs_BOLC_SET_VH_G4(1.4747276174033868);
    // Set group 4 bol bias 02 (VL) to -0.12527238259661322 Volts
    Pacs_BOLC_SET_VL_G4(-0.12527238259661322);
    // Set group 4 bol bias 03 (VRL) to 0.38624222870786595 Volts
    Pacs_BOLC_SET_VRL_G4(0.38624222870786595);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1423530627314813 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1423530627314813);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3734713392363535 Volts
    Pacs_BOLC_SET_VRL_G5(0.3734713392363535);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1211616404276756 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1211616404276756);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3640870527167945 Volts
    Pacs_BOLC_SET_VRL_G6(0.3640870527167945);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1074512769294307 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1074512769294307);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6005646067625168 Volts
    Pacs_BOLC_SET_VH_G1(1.6005646067625168);
    // Set group 1 bol bias 02 (VL) to -0.19943539323748327 Volts
    Pacs_BOLC_SET_VL_G1(-0.19943539323748327);
    // Set group 1 bol bias 03 (VRL) to 0.3927137250656313 Volts
    Pacs_BOLC_SET_VRL_G1(0.3927137250656313);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1512536862532445 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1512536862532445);
    // Set group 2 bol bias 01 (VH) to 1.5835245401299414 Volts
    Pacs_BOLC_SET_VH_G2(1.5835245401299414);
    // Set group 2 bol bias 02 (VL) to -0.21647545987005867 Volts
    Pacs_BOLC_SET_VL_G2(-0.21647545987005867);
    // Set group 2 bol bias 03 (VRL) to 0.3880497715778095 Volts
    Pacs_BOLC_SET_VRL_G2(0.3880497715778095);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1457903439369534 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1457903439369534);
    // Set group 3 bol bias 01 (VH) to 1.5867464604266623 Volts
    Pacs_BOLC_SET_VH_G3(1.5867464604266623);
    // Set group 3 bol bias 02 (VL) to -0.2132535395733377 Volts
    Pacs_BOLC_SET_VL_G3(-0.2132535395733377);
    // Set group 3 bol bias 03 (VRL) to 0.3903025295231384 Volts
    Pacs_BOLC_SET_VRL_G3(0.3903025295231384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144668449205875 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144668449205875);
    // Set group 4 bol bias 01 (VH) to 1.6044364991789073 Volts
    Pacs_BOLC_SET_VH_G4(1.6044364991789073);
    // Set group 4 bol bias 02 (VL) to -0.19556350082109264 Volts
    Pacs_BOLC_SET_VL_G4(-0.19556350082109264);
    // Set group 4 bol bias 03 (VRL) to 0.387662053519384 Volts
    Pacs_BOLC_SET_VRL_G4(0.387662053519384);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1439743820479262 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1439743820479262);
    // Set group 5 bol bias 01 (VH) to 1.3451907640885556 Volts
    Pacs_BOLC_SET_VH_G5(1.3451907640885556);
    // Set group 5 bol bias 02 (VL) to -0.054809235911444244 Volts
    Pacs_BOLC_SET_VL_G5(-0.054809235911444244);
    // Set group 5 bol bias 03 (VRL) to 0.40021084689056974 Volts
    Pacs_BOLC_SET_VRL_G5(0.40021084689056974);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1532482013507512 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1532482013507512);
    // Set group 6 bol bias 01 (VH) to 1.39 Volts
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.4344512926668127 Volts
    Pacs_BOLC_SET_VRL_G6(0.4344512926668127);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.192323231555507 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.192323231555507);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7330644465100378 Volts
    Pacs_BOLC_SET_VH_G1(1.7330644465100378);
    // Set group 1 bol bias 02 (VL) to -0.26693555348996223 Volts
    Pacs_BOLC_SET_VL_G1(-0.26693555348996223);
    // Set group 1 bol bias 03 (VRL) to 0.3923254235050375 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923254235050375);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1507930978184753 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1507930978184753);
    // Set group 2 bol bias 01 (VH) to 1.714453661934205 Volts
    Pacs_BOLC_SET_VH_G2(1.714453661934205);
    // Set group 2 bol bias 02 (VL) to -0.2855463380657951 Volts
    Pacs_BOLC_SET_VL_G2(-0.2855463380657951);
    // Set group 2 bol bias 03 (VRL) to 0.38771628761093724 Volts
    Pacs_BOLC_SET_VRL_G2(0.38771628761093724);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1454032366160996 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1454032366160996);
    // Set group 3 bol bias 01 (VH) to 1.7283831876482196 Volts
    Pacs_BOLC_SET_VH_G3(1.7283831876482196);
    // Set group 3 bol bias 02 (VL) to -0.2716168123517804 Volts
    Pacs_BOLC_SET_VL_G3(-0.2716168123517804);
    // Set group 3 bol bias 03 (VRL) to 0.40171045250948384 Volts
    Pacs_BOLC_SET_VRL_G3(0.40171045250948384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157256007066197 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157256007066197);
    // Set group 4 bol bias 01 (VH) to 1.7381239240265867 Volts
    Pacs_BOLC_SET_VH_G4(1.7381239240265867);
    // Set group 4 bol bias 02 (VL) to -0.26187607597341334 Volts
    Pacs_BOLC_SET_VL_G4(-0.26187607597341334);
    // Set group 4 bol bias 03 (VRL) to 0.38896138623469356 Volts
    Pacs_BOLC_SET_VRL_G4(0.38896138623469356);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454582711839105 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454582711839105);
    // Set group 5 bol bias 01 (VH) to 1.4703496551390403 Volts
    Pacs_BOLC_SET_VH_G5(1.4703496551390403);
    // Set group 5 bol bias 02 (VL) to -0.12965034486095992 Volts
    Pacs_BOLC_SET_VL_G5(-0.12965034486095992);
    // Set group 5 bol bias 03 (VRL) to 0.39904033450461596 Volts
    Pacs_BOLC_SET_VRL_G5(0.39904033450461596);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151844445053932 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151844445053932);
    // Set group 6 bol bias 01 (VH) to 1.5181165758982518 Volts
    Pacs_BOLC_SET_VH_G6(1.5181165758982518);
    // Set group 6 bol bias 02 (VL) to -0.08188342410174834 Volts
    Pacs_BOLC_SET_VL_G6(-0.08188342410174834);
    // Set group 6 bol bias 03 (VRL) to 0.4343226272779045 Volts
    Pacs_BOLC_SET_VRL_G6(0.4343226272779045);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1921697898825356 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1921697898825356);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8730534488812565 Volts
    Pacs_BOLC_SET_VH_G1(1.8730534488812565);
    // Set group 1 bol bias 02 (VL) to -0.3269465511187437 Volts
    Pacs_BOLC_SET_VL_G1(-0.3269465511187437);
    // Set group 1 bol bias 03 (VRL) to 0.3922166883004623 Volts
    Pacs_BOLC_SET_VRL_G1(0.3922166883004623);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1506641222123926 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1506641222123926);
    // Set group 2 bol bias 01 (VH) to 1.8512060220322217 Volts
    Pacs_BOLC_SET_VH_G2(1.8512060220322217);
    // Set group 2 bol bias 02 (VL) to -0.34879397796777845 Volts
    Pacs_BOLC_SET_VL_G2(-0.34879397796777845);
    // Set group 2 bol bias 03 (VRL) to 0.3869592141320811 Volts
    Pacs_BOLC_SET_VRL_G2(0.3869592141320811);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1445244519836626 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1445244519836626);
    // Set group 3 bol bias 01 (VH) to 1.8654619469621685 Volts
    Pacs_BOLC_SET_VH_G3(1.8654619469621685);
    // Set group 3 bol bias 02 (VL) to -0.33453805303783174 Volts
    Pacs_BOLC_SET_VL_G3(-0.33453805303783174);
    // Set group 3 bol bias 03 (VRL) to 0.40224166318840543 Volts
    Pacs_BOLC_SET_VRL_G3(0.40224166318840543);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1578437499437477 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1578437499437477);
    // Set group 4 bol bias 01 (VH) to 1.8790483325189686 Volts
    Pacs_BOLC_SET_VH_G4(1.8790483325189686);
    // Set group 4 bol bias 02 (VL) to -0.32095166748103154 Volts
    Pacs_BOLC_SET_VL_G4(-0.32095166748103154);
    // Set group 4 bol bias 03 (VRL) to 0.39052544771082365 Volts
    Pacs_BOLC_SET_VRL_G4(0.39052544771082365);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1472446958154223 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1472446958154223);
    // Set group 5 bol bias 01 (VH) to 1.5346700184984832 Volts
    Pacs_BOLC_SET_VH_G5(1.5346700184984832);
    // Set group 5 bol bias 02 (VL) to -0.16532998150151687 Volts
    Pacs_BOLC_SET_VL_G5(-0.16532998150151687);
    // Set group 5 bol bias 03 (VRL) to 0.39828926215052507 Volts
    Pacs_BOLC_SET_VRL_G5(0.39828926215052507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1509436695484125 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1509436695484125);
    // Set group 6 bol bias 01 (VH) to 1.5825303056022821 Volts
    Pacs_BOLC_SET_VH_G6(1.5825303056022821);
    // Set group 6 bol bias 02 (VL) to -0.11746969439771773 Volts
    Pacs_BOLC_SET_VL_G6(-0.11746969439771773);
    // Set group 6 bol bias 03 (VRL) to 0.43350337388623417 Volts
    Pacs_BOLC_SET_VRL_G6(0.43350337388623417);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191192803954044 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191192803954044);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.034145377320728 Volts
    Pacs_BOLC_SET_VH_G1(2.034145377320728);
    // Set group 1 bol bias 02 (VL) to -0.36585462267927166 Volts
    Pacs_BOLC_SET_VL_G1(-0.36585462267927166);
    // Set group 1 bol bias 03 (VRL) to 0.4026842358176688 Volts
    Pacs_BOLC_SET_VRL_G1(0.4026842358176688);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163077213168135 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163077213168135);
    // Set group 2 bol bias 01 (VH) to 1.9964246373780308 Volts
    Pacs_BOLC_SET_VH_G2(1.9964246373780308);
    // Set group 2 bol bias 02 (VL) to -0.40357536262196914 Volts
    Pacs_BOLC_SET_VL_G2(-0.40357536262196914);
    // Set group 2 bol bias 03 (VRL) to 0.38543545754038677 Volts
    Pacs_BOLC_SET_VRL_G2(0.38543545754038677);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1427558304354366 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1427558304354366);
    // Set group 3 bol bias 01 (VH) to 2.0225756539924595 Volts
    Pacs_BOLC_SET_VH_G3(2.0225756539924595);
    // Set group 3 bol bias 02 (VL) to -0.37742434600754043 Volts
    Pacs_BOLC_SET_VL_G3(-0.37742434600754043);
    // Set group 3 bol bias 03 (VRL) to 0.41362905220735763 Volts
    Pacs_BOLC_SET_VRL_G3(0.41362905220735763);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704381594190805 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704381594190805);
    // Set group 4 bol bias 01 (VH) to 2.0286801589025623 Volts
    Pacs_BOLC_SET_VH_G4(2.0286801589025623);
    // Set group 4 bol bias 02 (VL) to -0.37131984109743765 Volts
    Pacs_BOLC_SET_VL_G4(-0.37131984109743765);
    // Set group 4 bol bias 03 (VRL) to 0.39131683434261844 Volts
    Pacs_BOLC_SET_VRL_G4(0.39131683434261844);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.14814867942076 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.14814867942076);
    // Set group 5 bol bias 01 (VH) to 1.5997463742933684 Volts
    Pacs_BOLC_SET_VH_G5(1.5997463742933684);
    // Set group 5 bol bias 02 (VL) to -0.2002536257066316 Volts
    Pacs_BOLC_SET_VL_G5(-0.2002536257066316);
    // Set group 5 bol bias 03 (VRL) to 0.3972802806465645 Volts
    Pacs_BOLC_SET_VRL_G5(0.3972802806465645);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1497335299275955 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1497335299275955);
    // Set group 6 bol bias 01 (VH) to 1.64826517003746 Volts
    Pacs_BOLC_SET_VH_G6(1.64826517003746);
    // Set group 6 bol bias 02 (VL) to -0.1517348299625401 Volts
    Pacs_BOLC_SET_VL_G6(-0.1517348299625401);
    // Set group 6 bol bias 03 (VRL) to 0.43238698345346915 Volts
    Pacs_BOLC_SET_VRL_G6(0.43238698345346915);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.189850849172478 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.189850849172478);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.1252730205231707 Volts
    Pacs_BOLC_SET_VH_G1(2.1252730205231707);
    // Set group 1 bol bias 02 (VL) to -0.3747269794768295 Volts
    Pacs_BOLC_SET_VL_G1(-0.3747269794768295);
    // Set group 1 bol bias 03 (VRL) to 0.4136487083795371 Volts
    Pacs_BOLC_SET_VRL_G1(0.4136487083795371);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.176055880953933 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.176055880953933);
    // Set group 2 bol bias 01 (VH) to 2.0735703522054516 Volts
    Pacs_BOLC_SET_VH_G2(2.0735703522054516);
    // Set group 2 bol bias 02 (VL) to -0.4264296477945484 Volts
    Pacs_BOLC_SET_VL_G2(-0.4264296477945484);
    // Set group 2 bol bias 03 (VRL) to 0.38501518126647505 Volts
    Pacs_BOLC_SET_VRL_G2(0.38501518126647505);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1422680405518997 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1422680405518997);
    // Set group 3 bol bias 01 (VH) to 2.1002048058798914 Volts
    Pacs_BOLC_SET_VH_G3(2.1002048058798914);
    // Set group 3 bol bias 02 (VL) to -0.3997951941201084 Volts
    Pacs_BOLC_SET_VL_G3(-0.3997951941201084);
    // Set group 3 bol bias 03 (VRL) to 0.41374892649754597 Volts
    Pacs_BOLC_SET_VRL_G3(0.41374892649754597);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170570690743195 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170570690743195);
    // Set group 4 bol bias 01 (VH) to 2.1080881836667413 Volts
    Pacs_BOLC_SET_VH_G4(2.1080881836667413);
    // Set group 4 bol bias 02 (VL) to -0.39191181633325867 Volts
    Pacs_BOLC_SET_VL_G4(-0.39191181633325867);
    // Set group 4 bol bias 03 (VRL) to 0.39179349399255325 Volts
    Pacs_BOLC_SET_VRL_G4(0.39179349399255325);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1486931849427977 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1486931849427977);
    // Set group 5 bol bias 01 (VH) to 1.6757782637240437 Volts
    Pacs_BOLC_SET_VH_G5(1.6757782637240437);
    // Set group 5 bol bias 02 (VL) to -0.22422173627595626 Volts
    Pacs_BOLC_SET_VL_G5(-0.22422173627595626);
    // Set group 5 bol bias 03 (VRL) to 0.40729645571050493 Volts
    Pacs_BOLC_SET_VRL_G5(0.40729645571050493);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1617149101325723 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1617149101325723);
    // Set group 6 bol bias 01 (VH) to 1.7136503402053438 Volts
    Pacs_BOLC_SET_VH_G6(1.7136503402053438);
    // Set group 6 bol bias 02 (VL) to -0.18634965979465615 Volts
    Pacs_BOLC_SET_VL_G6(-0.18634965979465615);
    // Set group 6 bol bias 03 (VRL) to 0.43098263818668947 Volts
    Pacs_BOLC_SET_VRL_G6(0.43098263818668947);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1881561132520857 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1881561132520857);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.209416047586087 Volts
    Pacs_BOLC_SET_VH_G1(2.209416047586087);
    // Set group 1 bol bias 02 (VL) to -0.3905839524139128 Volts
    Pacs_BOLC_SET_VL_G1(-0.3905839524139128);
    // Set group 1 bol bias 03 (VRL) to 0.4134679213904496 Volts
    Pacs_BOLC_SET_VRL_G1(0.4134679213904496);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758418687268812 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758418687268812);
    // Set group 2 bol bias 01 (VH) to 2.1541915675147214 Volts
    Pacs_BOLC_SET_VH_G2(2.1541915675147214);
    // Set group 2 bol bias 02 (VL) to -0.44580843248527846 Volts
    Pacs_BOLC_SET_VL_G2(-0.44580843248527846);
    // Set group 2 bol bias 03 (VRL) to 0.38424319746039115 Volts
    Pacs_BOLC_SET_VRL_G2(0.38424319746039115);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1413720715536493 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1413720715536493);
    // Set group 3 bol bias 01 (VH) to 2.1813068162319285 Volts
    Pacs_BOLC_SET_VH_G3(2.1813068162319285);
    // Set group 3 bol bias 02 (VL) to -0.4186931837680716 Volts
    Pacs_BOLC_SET_VL_G3(-0.4186931837680716);
    // Set group 3 bol bias 03 (VRL) to 0.41360319513591143 Volts
    Pacs_BOLC_SET_VRL_G3(0.41360319513591143);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704095720713417 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704095720713417);
    // Set group 4 bol bias 01 (VH) to 2.202944386753124 Volts
    Pacs_BOLC_SET_VH_G4(2.202944386753124);
    // Set group 4 bol bias 02 (VL) to -0.3970556132468757 Volts
    Pacs_BOLC_SET_VL_G4(-0.3970556132468757);
    // Set group 4 bol bias 03 (VRL) to 0.40381007074137704 Volts
    Pacs_BOLC_SET_VRL_G4(0.40381007074137704);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1624292794462514 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1624292794462514);
    // Set group 5 bol bias 01 (VH) to 1.7436864671540049 Volts
    Pacs_BOLC_SET_VH_G5(1.7436864671540049);
    // Set group 5 bol bias 02 (VL) to -0.2563135328459952 Volts
    Pacs_BOLC_SET_VL_G5(-0.2563135328459952);
    // Set group 5 bol bias 03 (VRL) to 0.4060804936984878 Volts
    Pacs_BOLC_SET_VRL_G5(0.4060804936984878);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1602616898977316 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1602616898977316);
    // Set group 6 bol bias 01 (VH) to 1.7834132365202005 Volts
    Pacs_BOLC_SET_VH_G6(1.7834132365202005);
    // Set group 6 bol bias 02 (VL) to -0.21658676347979958 Volts
    Pacs_BOLC_SET_VL_G6(-0.21658676347979958);
    // Set group 6 bol bias 03 (VRL) to 0.43021242094743417 Volts
    Pacs_BOLC_SET_VRL_G6(0.43021242094743417);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1872266025341247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1872266025341247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.297951276717203 Volts
    Pacs_BOLC_SET_VH_G1(2.297951276717203);
    // Set group 1 bol bias 02 (VL) to -0.4020487232827972 Volts
    Pacs_BOLC_SET_VL_G1(-0.4020487232827972);
    // Set group 1 bol bias 03 (VRL) to 0.41346783054780994 Volts
    Pacs_BOLC_SET_VRL_G1(0.41346783054780994);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175841761189199 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175841761189199);
    // Set group 2 bol bias 01 (VH) to 2.237764444765691 Volts
    Pacs_BOLC_SET_VH_G2(2.237764444765691);
    // Set group 2 bol bias 02 (VL) to -0.46223555523430954 Volts
    Pacs_BOLC_SET_VL_G2(-0.46223555523430954);
    // Set group 2 bol bias 03 (VRL) to 0.3829355076340157 Volts
    Pacs_BOLC_SET_VRL_G2(0.3829355076340157);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.13985443895415 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.13985443895415);
    // Set group 3 bol bias 01 (VH) to 2.2663898962449944 Volts
    Pacs_BOLC_SET_VH_G3(2.2663898962449944);
    // Set group 3 bol bias 02 (VL) to -0.43361010375500575 Volts
    Pacs_BOLC_SET_VL_G3(-0.43361010375500575);
    // Set group 3 bol bias 03 (VRL) to 0.4131238530516411 Volts
    Pacs_BOLC_SET_VRL_G3(0.4131238530516411);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1698796071025357 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1698796071025357);
    // Set group 4 bol bias 01 (VH) to 2.279673221041111 Volts
    Pacs_BOLC_SET_VH_G4(2.279673221041111);
    // Set group 4 bol bias 02 (VL) to -0.42032677895888915 Volts
    Pacs_BOLC_SET_VL_G4(-0.42032677895888915);
    // Set group 4 bol bias 03 (VRL) to 0.39361613583982535 Volts
    Pacs_BOLC_SET_VRL_G4(0.39361613583982535);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.15077544624775 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.15077544624775);
    // Set group 5 bol bias 01 (VH) to 1.809656711096493 Volts
    Pacs_BOLC_SET_VH_G5(1.809656711096493);
    // Set group 5 bol bias 02 (VL) to -0.2903432889035071 Volts
    Pacs_BOLC_SET_VL_G5(-0.2903432889035071);
    // Set group 5 bol bias 03 (VRL) to 0.4049518544441218 Volts
    Pacs_BOLC_SET_VRL_G5(0.4049518544441218);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1589129512261658 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1589129512261658);
    // Set group 6 bol bias 01 (VH) to 1.852468907894238 Volts
    Pacs_BOLC_SET_VH_G6(1.852468907894238);
    // Set group 6 bol bias 02 (VL) to -0.247531092105762 Volts
    Pacs_BOLC_SET_VL_G6(-0.247531092105762);
    // Set group 6 bol bias 03 (VRL) to 0.4292993417752352 Volts
    Pacs_BOLC_SET_VRL_G6(0.4292993417752352);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1861246581200136 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1861246581200136);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3806926938420414 Volts
    Pacs_BOLC_SET_VH_G1(2.3806926938420414);
    // Set group 1 bol bias 02 (VL) to -0.41930730615795847 Volts
    Pacs_BOLC_SET_VL_G1(-0.41930730615795847);
    // Set group 1 bol bias 03 (VRL) to 0.4020155079485436 Volts
    Pacs_BOLC_SET_VRL_G1(0.4020155079485436);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162285695776181 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162285695776181);
    // Set group 2 bol bias 01 (VH) to 2.3371282046100963 Volts
    Pacs_BOLC_SET_VH_G2(2.3371282046100963);
    // Set group 2 bol bias 02 (VL) to -0.46287179538990364 Volts
    Pacs_BOLC_SET_VL_G2(-0.46287179538990364);
    // Set group 2 bol bias 03 (VRL) to 0.3923402298587034 Volts
    Pacs_BOLC_SET_VRL_G2(0.3923402298587034);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1507712805161225 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1507712805161225);
    // Set group 3 bol bias 01 (VH) to 2.356604953923699 Volts
    Pacs_BOLC_SET_VH_G3(2.356604953923699);
    // Set group 3 bol bias 02 (VL) to -0.44339504607630065 Volts
    Pacs_BOLC_SET_VL_G3(-0.44339504607630065);
    // Set group 3 bol bias 03 (VRL) to 0.4124662568673877 Volts
    Pacs_BOLC_SET_VRL_G3(0.4124662568673877);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.169152536126319 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.169152536126319);
    // Set group 4 bol bias 01 (VH) to 2.3825039100730487 Volts
    Pacs_BOLC_SET_VH_G4(2.3825039100730487);
    // Set group 4 bol bias 02 (VL) to -0.4174960899269509 Volts
    Pacs_BOLC_SET_VL_G4(-0.4174960899269509);
    // Set group 4 bol bias 03 (VRL) to 0.40493410269973024 Volts
    Pacs_BOLC_SET_VRL_G4(0.40493410269973024);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1637149679245193 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1637149679245193);
    // Set group 5 bol bias 01 (VH) to 1.883738472848583 Volts
    Pacs_BOLC_SET_VH_G5(1.883738472848583);
    // Set group 5 bol bias 02 (VL) to -0.31626152715141714 Volts
    Pacs_BOLC_SET_VL_G5(-0.31626152715141714);
    // Set group 5 bol bias 03 (VRL) to 0.4028494691164935 Volts
    Pacs_BOLC_SET_VRL_G5(0.4028494691164935);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.156400882301432 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.156400882301432);
    // Set group 6 bol bias 01 (VH) to 1.9235912310846244 Volts
    Pacs_BOLC_SET_VH_G6(1.9235912310846244);
    // Set group 6 bol bias 02 (VL) to -0.2764087689153759 Volts
    Pacs_BOLC_SET_VL_G6(-0.2764087689153759);
    // Set group 6 bol bias 03 (VRL) to 0.4280070912945936 Volts
    Pacs_BOLC_SET_VRL_G6(0.4280070912945936);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1845650655206446 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1845650655206446);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6181566702818313 Volts
    Pacs_BOLC_SET_VH_G1(2.6181566702818313);
    // Set group 1 bol bias 02 (VL) to -0.38184332971816887 Volts
    Pacs_BOLC_SET_VL_G1(-0.38184332971816887);
    // Set group 1 bol bias 03 (VRL) to 0.43545225816479755 Volts
    Pacs_BOLC_SET_VRL_G1(0.43545225816479755);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2018572484354544 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2018572484354544);
    // Set group 2 bol bias 01 (VH) to 2.5300933623498008 Volts
    Pacs_BOLC_SET_VH_G2(2.5300933623498008);
    // Set group 2 bol bias 02 (VL) to -0.469906637650199 Volts
    Pacs_BOLC_SET_VL_G2(-0.469906637650199);
    // Set group 2 bol bias 03 (VRL) to 0.3917176926734228 Volts
    Pacs_BOLC_SET_VRL_G2(0.3917176926734228);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1500484890692286 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1500484890692286);
    // Set group 3 bol bias 01 (VH) to 2.5545115967606167 Volts
    Pacs_BOLC_SET_VH_G3(2.5545115967606167);
    // Set group 3 bol bias 02 (VL) to -0.4454884032393832 Volts
    Pacs_BOLC_SET_VL_G3(-0.4454884032393832);
    // Set group 3 bol bias 03 (VRL) to 0.41136249367186684 Volts
    Pacs_BOLC_SET_VRL_G3(0.41136249367186684);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1679320914489204 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1679320914489204);
    // Set group 4 bol bias 01 (VH) to 2.591852678092942 Volts
    Pacs_BOLC_SET_VH_G4(2.591852678092942);
    // Set group 4 bol bias 02 (VL) to -0.408147321907058 Volts
    Pacs_BOLC_SET_VL_G4(-0.408147321907058);
    // Set group 4 bol bias 03 (VRL) to 0.4158848845694993 Volts
    Pacs_BOLC_SET_VRL_G4(0.4158848845694993);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176235181901646 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176235181901646);
    // Set group 5 bol bias 01 (VH) to 2.0340896725156363 Volts
    Pacs_BOLC_SET_VH_G5(2.0340896725156363);
    // Set group 5 bol bias 02 (VL) to -0.3659103274843634 Volts
    Pacs_BOLC_SET_VL_G5(-0.3659103274843634);
    // Set group 5 bol bias 03 (VRL) to 0.3987896988621052 Volts
    Pacs_BOLC_SET_VRL_G5(0.3987896988621052);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1515438563527702 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1515438563527702);
    // Set group 6 bol bias 01 (VH) to 2.080247845760918 Volts
    Pacs_BOLC_SET_VH_G6(2.080247845760918);
    // Set group 6 bol bias 02 (VL) to -0.31975215423908154 Volts
    Pacs_BOLC_SET_VL_G6(-0.31975215423908154);
    // Set group 6 bol bias 03 (VRL) to 0.42577779561759777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42577779561759777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1818744401374954 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1818744401374954);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.9648806825465286 Volts
    Pacs_BOLC_SET_VH_G1(2.9648806825465286);
    // Set group 1 bol bias 02 (VL) to -0.3351193174534714 Volts
    Pacs_BOLC_SET_VL_G1(-0.3351193174534714);
    // Set group 1 bol bias 03 (VRL) to 0.4345971818834749 Volts
    Pacs_BOLC_SET_VRL_G1(0.4345971818834749);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2008507320864905 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2008507320864905);
    // Set group 2 bol bias 01 (VH) to 2.8835722707263107 Volts
    Pacs_BOLC_SET_VH_G2(2.8835722707263107);
    // Set group 2 bol bias 02 (VL) to -0.4164277292736889 Volts
    Pacs_BOLC_SET_VL_G2(-0.4164277292736889);
    // Set group 2 bol bias 03 (VRL) to 0.4147637133976726 Volts
    Pacs_BOLC_SET_VRL_G2(0.4147637133976726);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176763943185141 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176763943185141);
    // Set group 3 bol bias 01 (VH) to 2.924290179534832 Volts
    Pacs_BOLC_SET_VH_G3(2.924290179534832);
    // Set group 3 bol bias 02 (VL) to -0.37570982046516804 Volts
    Pacs_BOLC_SET_VL_G3(-0.37570982046516804);
    // Set group 3 bol bias 03 (VRL) to 0.4333518026225201 Volts
    Pacs_BOLC_SET_VRL_G3(0.4333518026225201);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.19222958084261 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.19222958084261);
    // Set group 4 bol bias 01 (VH) to 2.938948180111503 Volts
    Pacs_BOLC_SET_VH_G4(2.938948180111503);
    // Set group 4 bol bias 02 (VL) to -0.3610518198884969 Volts
    Pacs_BOLC_SET_VL_G4(-0.3610518198884969);
    // Set group 4 bol bias 03 (VRL) to 0.4248831336064878 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248831336064878);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1865155818476714 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1865155818476714);
    // Set group 5 bol bias 01 (VH) to 2.231303538712061 Volts
    Pacs_BOLC_SET_VH_G5(2.231303538712061);
    // Set group 5 bol bias 02 (VL) to -0.36869646128793887 Volts
    Pacs_BOLC_SET_VL_G5(-0.36869646128793887);
    // Set group 5 bol bias 03 (VRL) to 0.4261159129370585 Volts
    Pacs_BOLC_SET_VRL_G5(0.4261159129370585);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1842235863263286 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1842235863263286);
    // Set group 6 bol bias 01 (VH) to 2.2493043049150576 Volts
    Pacs_BOLC_SET_VH_G6(2.2493043049150576);
    // Set group 6 bol bias 02 (VL) to -0.3506956950849426 Volts
    Pacs_BOLC_SET_VL_G6(-0.3506956950849426);
    // Set group 6 bol bias 03 (VRL) to 0.4237159708307814 Volts
    Pacs_BOLC_SET_VRL_G6(0.4237159708307814);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.179385794698645 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.179385794698645);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //**********************************************
    // Set the PACS chopper at the position 664
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //
    //**********************************************************************
    //                       Measurement
    // PACS photometer central field-of-view
    // corresponding to 1.42pW on the green and 2.30pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //*******************************
    // Select Filter B (70 microns)
    //*******************************
    //
    PHOT_fltw_move("POS B");
    //
    //**********************************************
    // Set the PACS chopper at the position -21350
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(-21350);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS1 at 48.0 K
    // corresponding to 0.90pW on the blue and 5.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //**********************************************
    // Set the PACS chopper at the position 21200
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(21200);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS2 at 58.0 K
    // corresponding to 1.25pW on the blue and 6.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker602();
    delay(measure_time);
    TMMarker600();
    //**********************************************
    // Set the PACS chopper at the position 664
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //
    //**********************************************************************
    //                       Measurement
    // PACS photometer central field-of-view
    // corresponding to 2.53pW on the blue and 2.30pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker603();
    delay(measure_time);
    TMMarker600();
    //********************************
    // Epilogue : Set the safe biases
    //********************************
    PHOT_set_bias_volt(endBiasTable,1);
    PHOT_set_bias_volt(endBiasTable,2);
    PHOT_set_bias_volt(endBiasTable,3);
    PHOT_set_bias_volt(endBiasTable,4);
    PHOT_set_bias_volt(endBiasTable,5);
    PHOT_set_bias_volt(endBiasTable,6);
    //
    // sync the bus
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version       : 0.2
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//                 0.2 11-aug-2006 TM: update of procedure checked
obs PacsEng_Phot_Warm_Startinputsignal {
    /* No variables to call PacsEng_Phot_Warm_Startinputsignal                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_Warm_Startinputsignal                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_Warm_Startinputsignal()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_Warm_Startinputsignal();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Close_Launch_Lock {
    /* No variables to call PacsEng_Close_Launch_Lock                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Close_Launch_Lock                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Close_Launch_Lock()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Close_Launch_Lock();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: Msec2sec.txt,v 1.2 2007/04/25 15:14:03 dcesarsk Exp $ 
// Missionphase  : 
//
// Purpose       : Convert [msec] into [sec]. This is needed since CUS
//                 granularity is the second. 
//
// Author CUS    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
//
// Author TCL    : N/A
//
// Original TCL  : N/A
//
// Input arguments
// Type  Name      DefVal  Description
// int   milisec   N/A     A duration [msec] to be converted into [sec]
//
// Description   : Convert int msec into float sec (for instance 1230 msec
//                 gets converted to 1.230 [sec] and take next closest integer
//                 (2 in this example)
//
// Dependencies  : None
//                 
// Comments      : 
//
// Version       : 0.1 13-Aug-2004 First creation
// History       : 
//               :
//
int procedure Msec2sec {
    int milisec = 0;
}{
    double fwait = double(milisec) / 1000.0;
    int secnds = iceil(fwait);

    return secnds;
}

// CVS comments  : $Id $
// Description :
//
// Dependencies  : 
//
// Comments      : Follows verbatim paragraph 4.2.10 in PACS-ME-LI-005
//                 version 1.6
//         Actual values of input parameters, except values for the
//         various loop counters, are completely irrelevant and so
//         are not used.
//         Loop counters are used to estimate the duree of the
//         sequence
//
// Version       : 0.1
// History       : 0.1 18-sep-2009 PHS-1119 Cloned from wave_switch.. for unChopped
//               : 0.2 21-sep-2009 VD updates on Parameters combination
//               : 0.3 22-sep-2009 updated PHS-1119
//
// This debugging DEC/MEC computes grating positions
procedure PacsDebug_wave_switch_unChop {
    int pos = 1000; // Grating start position
    int nb_dither_steps = 1; // P2 number of dithering steps
    int param1 = 2; // P1
    int ditherSize = 0; // dither size P3
    int param4 = 12; // dummy
    int param6 = 2; // dummy
    int param7 = 188; // Amplitude of A->B jump
    int param8 = 188; // P#8
}{
    // To achieve ABBA
    int param5 = param7;
    int param9 = param5;
    int param11 = -ditherSize;
    // OBCP moves grating to
    int grat = pos;
    debug_print("----unChopped starts at: " + grat);
    // Pseudo code from PACS OBCPs and DMC Sequences (4.2.10)
    // There is the outermost nb_up_down loop not considered here
    // WAIT 1 ; have a defined start
    // LABEL 0 ; set Label to 0
    // LOOP P1                           main loop for nb_up_dn
    for(int mainLoop = 1 .. param1) {
        // LOOP P2                       number of shifts up
        for(int outLOOP = 1 .. nb_dither_steps) {
            //   WAIT 1                         sync. for chopper
            //   MOVE_GRATING_RELATIVE P2       move grating by P3 (dither size)
            grat = grat + ditherSize;
            debug_print("UpDither loop: " + outLOOP + "; grating at: " + grat);
            //   LOOP P4                        nbABBA times core loop
            for(int inLOOP = 1 .. param4) {
                //        MOVE_GRATING_RELATIVE P5    move grating by P5
                grat = grat + param5;
                debug_print("----A (up): " + grat);
                //        MOVE_GRATING_RELATIVE P7    move grating by P7
                grat = grat + param7;
                debug_print("----B (up): " + grat);
                //        MOVE_GRATING_RELATIVE P8    move grating by P8
                grat = grat + param8;
                debug_print("----C (up): " + grat);
                //        MOVE_GRATING_RELATIVE P9    move grating by P9 (-P7)
                grat = grat + param9;
                debug_print("----D (up): " + grat);
                //   END_LOOP nbABBA
            }
            // END_LOOP P2
        }
        // LOOP P10                number of shifts down
        for(int outLOOPdn = 1 .. nb_dither_steps) {
            //   WAIT 1                         sync. for chopper
            debug_print("DnDither loop: " + outLOOPdn + "; grating at: " + grat);
            //   LOOP P4                        nbABBA times core loop
            for(int inLOOPdn = 1 .. param4) {
                //        MOVE_GRATING_RELATIVE P12    move grating by -P5
                grat = grat - param5;
                debug_print("----A (down): " + grat);
                //        MOVE_GRATING_RELATIVE P13   move grating by -P7
                grat = grat - param7;
                debug_print("----B (down): " + grat);
                //        MOVE_GRATING_RELATIVE P14   move grating by -P8
                grat = grat - param8;
                debug_print("----C (down): " + grat);
                //        MOVE_GRATING_RELATIVE P15   move grating by -P9
                grat = grat - param9;
                debug_print("----D (down): " + grat);
                //   END_LOOP nbABBA
            }
            //   MOVE_GRATING_RELATIVE P11
            // move grating by -P3 (-dither size)
            grat = grat - ditherSize;
            // END_LOOP P2
        }
        // END_LOOP P1
    }
    // WAIT 1                            complete last plateau
    // LABEL 0                           no sequence anymore
    // END_SEQUENCE
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : PACS Spectrometer Staring observation in Buffer Transmission Mode
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version	: 1.0
// History       : 1.0  11-Mar-2008  Initial version by PR
//
obs PacsEng_Spec_BufferTransmission {
    /* Needed variables to call PacsEng_Spec_BufferTransmission                        */
    int ramp_len_red = 64; // Red ramps length
    int ramp_len_blu = 64; // Blue ramps length
    double bias_d_red = 0.0401 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_d_blu = 0.0801 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    int capa_red = 8; // Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
    int capa_blu = 8; // Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
    int grat_pos = 500000; // Grating position during the observation (fixed)
    string filter_pos = "POS B" in ["POS A","POS B"]; // FW position during the observation (fixed)
    int chop_pos = 21200; // Chopper Position (default 21200 = CS2)
    int stare_time = 7200; // Idle time in buffer transmission mode
    /* End of needed variables for PacsEng_Spec_BufferTransmission                     */
}{
    //
    busconfig (7);
    // BURST MODE :     4:PACS PRIME  -  7:BURST MODE  - 8:PARALLEL MODE
    //
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_BufferTransmission_Stare(ramp_len_red,ramp_len_blu,bias_d_red,bias_d_blu,capa_red,capa_blu,grat_pos,filter_pos,chop_pos,stare_time)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(300.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_BufferTransmission_Stare(ramp_len_red,ramp_len_blu,bias_d_red,bias_d_blu,capa_red,capa_blu,grat_pos,filter_pos,chop_pos,stare_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_CS_SFT_Warm.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : VERIFY FUNCTION of INTERNAL CALIBRATION SOURCES
//
// Author        : H. Dannerbauer
//                 R. Vavrek
//                 H. Feuchtgruber
// CUSification  : DAC
//               
// Arguments     : BB1 & BB2 temperature [muOhms & Volts]
//          	  
//
// Called        : WaitForGo   
//                 waittime
//                 tcsend
//
// Dependences   : tm_switchon
//                 tm_spec_det_setup
//                 tm_spec_spu_setup
//                 tm_spec_mec_setup
//                 
//
// Description   : This script assumes an already set-up PACS instrument. 
//                 This test is based on functional test 0.7.11 and PTD 0.7.12.
// 
// Comments :      None of the detector systems are involved in the BB's
//                 functional check. Nevertheless, in order to generate HK data, 
//                 the DPU-SET-HK-LIST command is set and parametrised for 
//                 spectroscopy and spectrometer setup needed inorder to 
//                 synchronize diagnostic HK on readouts.  
//                 Commanding unit conversions: 1 setpoint unit = 100 micro
//                 Ohms, max temperature ~ 100 K, max setpoint = 32767 
//                 In case if temperature set directly: -32767 = -10 Volts, 
//                 +32767 = +10 Volts.
//                 
// Version       : 1.0
// History       : This script is based on the commanding during
//                 the CQM ILT Test. 15-11-2004.      
procedure PACS_CS_SFT_Warm {
}{
    debug_print("Start PACS_CS_SFT_Warm");
    // Diagnostic HK period (in milliseconds)
    int diag_hk_period = 300;
    // PC160420 "DMC_WRT_DIAG_HK_LIST" WRITE THE LIST OF DIAGNOSTIC HK INTO DMC MEMORY
    // DMC_DATA_LENGTH            PP065420 contains the number of desired HK parameters
    // DMC_4_BYTES_WORDS_DATA     PP067420 contains the desired HK parameters' IDs
    // DMC_CHECKSUM               PP066420
    //
    // Max number of requested diag HK parameters = 16
    // (including the last one, which is always forced to the same value)
    // Chopper specific measures are:
    // 214 DMC_CS2_CTRL_STA  -  CS2 controller status
    // 445 DMC_CS1_RES_VALUE -  CS1 current resistor value
    // 446 DMC_CS1_OUTPUT    -  CS1 controller output voltage
    // 447 DMC_CS2_RES_VALUE -  CS2 current resistor value
    // 448 DMC_CS1_OUTPUT    -  CS2 controller output voltage
    // 459 DMC_CS1_TARGET    -  CS1 target resistor value
    // 460 DMC_CS2_TARGET    -  CS2 target resistor value
    // 526 DMC_CS1_VOLT_SG   -  CS1 small gain sensor voltage
    // 527 DMC_CS1_VOLT_BG   -  CS1 big gain sensor voltage
    // 528 DMC_CS1_CUR_SG    -  CS1 small gain sensor current
    // 529 DMC_CS1_CUR_BG    -  CS1 big gain sensor current
    // 542 DMC_CS2_VOLT_SG   -  CS2 small gain sensor voltage
    // 543 DMC_CS2_VOLT_BG   -  CS2 big gain sensor voltage
    // 544 DMC_CS2_CUR_SG    -  CS2 small gain sensor current
    // 545 DMC_CS2_CUR_BG    -  CS2 big gain sensor current
    int nb_words = 16;
    {int}[] list_tuple = [{214},{445},{446},{447},{448},{459},{460},{526},{527},{528},{529},{542},{543},{544},{545},{0xffff}];
    int[] list_int = [214,445,446,447,448,459,460,526,527,528,529,542,543,544,545,0xffff];
    int chksum = checksum("int",list_int);
    // Send the TC
    Pacs_DMC_WRT_DIAG_HK_LIST(nb_words,list_tuple,chksum);
    delay(1);
    // 
    // PC161420 "DMC_WRT_DIAG_HK_CONF_TAB" WRITE THE CUSTOM HK CONFIGURATION TABLE
    //         PP065420 "DMC_DATA_LENGTH", GroupSize: 1
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // PC146420 "DMC_START_DIAG_HK" START THE ACQUISITION OF THE DIAGNOSTIC HK
    //         PP076420 "DIAG_HK_PERIOD"
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    //
    // Write calibration source controller parameters
    //
    // DMC_WRT_CS1_CONF_PAR
    list_tuple = [{1000000},{5000},{3277},{1857},{327},{0x7fff},{0}];
    list_int = [1000000,5000,3277,1857,327,0x7fff,0];
    chksum = checksum("int",list_int);
    // Send the TC
    Pacs_DMC_WRT_CS1_CONF_PAR(list_tuple,chksum);
    delay(1);
    // DMC_WRT_CS2_CONF_PAR
    //set params [list {PP067420 1000000} {PP067420 5000} {PP067420 3277} \
    //                 {PP067420 1857} {PP067420 327} \
    //                 [list PP067420 [expr 0x7FFF]] {PP067420 0}]
    list_tuple = [{1000000},{5000},{3277},{1857},{327},{0x7fff},{0}];
    list_int = [1000000,5000,3277,1857,327,0x7fff,0];
    chksum = checksum("int",list_int);
    // Send the TC
    Pacs_DMC_WRT_CS2_CONF_PAR(list_tuple,chksum);
    delay(1);
    //
    // Calibration source controller parameters are set
    //
    // Heat-up the CS sources up to 800000 (70.5K;CS1)
    // and 920000 (76.0K;CS2) --- big step
    // Switchon, enable and set CS1 to 800000 (~70.5K)
    // PC138420 "DMC_SWON_BB_1_CONT" SWITCH ON BLACK BODY 1 CONTROLLER
    Pacs_DMC_SWON_BB_1_CONT();
    delay(1);
    // PC206420 "DMC_ENABLE_BB_1_CONT" ENABLE BB1 CONTROLLER
    Pacs_DMC_ENABLE_BB_1_CONT();
    // PC140420 "DMC_SET_TEMP_BB_1" SET THE TEMPERATURE OF THE BLACK BODY 1
    // PP094420 "DMC_BB_TEMP"
    double temp = 80.0;
    Pacs_DMC_SET_TEMP_BB_1(temp);
    delay(1);
    // Switchon, enable and set CS2 to 920000 (~76.0K)
    // PC142420 "DMC_SWON_BB_2_CONT" SWITCH ON BLACK BODY 2 CONTROLLER
    Pacs_DMC_SWON_BB_2_CONT();
    delay(1);
    // PC208420 "DMC_ENABLE_BB_2_CONT" ENABLE BB2 CONTROLLER
    Pacs_DMC_ENABLE_BB_2_CONT();
    delay(1);
    // PC144420 "DMC_SET_TEMP_BB_2" SET THE TEMPERATURE OF THE BLACK BODY 2
    //	PP094420 "DMC_BB_TEMP"
    temp = 92.0;
    Pacs_DMC_SET_TEMP_BB_2(temp);
    // wait a while to allow for HK checking and sufficient diag data collection
    delay(300);
    // PC147420 "DMC_STOP_DIAG_HK" STOP THE ACQUISITION OF THE DIAGNOSTIC HK
    Pacs_DMC_STOP_DIAG_HK();
    delay(1);
    // End of Procedure
}

// CVS comments  : $Id: SPEC_BAND_read.txt,v 1.3 2007/05/07 13:48:17 dcesarsk Exp $ 
// Purpose       : Return the BAND limits (from SPEC_BAND) for a given order
// CUS author    : DAC
// Script file   : SPEC_BAND_read.txt 
//
// Input arguments
// type    name         description
// int     order        Grating order
//
// Return values
// Type          Description
// double []     LO and HI wavelengths
//
// Description   : Access the table SPEC_BAND_params. Read and return the
//                 band limits for a given order
//
// Dependencies  :
//
// Preconditions :
//                 
// Comments      : 
// type string
// 
// History       : 0.1 23-may-2006 DAC
// 0.2  7-may-2007 Make input argument string to be able to read "L" lines
double[] procedure SPEC_BAND_read {
    string order = "1"; // Give order
}{
    // Open and read SPEC_BAND_params table. Table indexed by ORDER
    // read BLU and RED edges of the SPEC bands
    double blu = dlookup("SPEC_BAND_params",order,"BLU");
    double red = dlookup("SPEC_BAND_params",order,"RED");

    return [blu,red];
}

// CVS comments  : $Id: PacsProcessInfoArrayLine.txt,v 1.13 2007/10/25 12:15:42 dcesarsk Exp $ 
//
// Purpose       : Process the timing information gathered in infoArray
//
// CUS author    : DAC
//
// Input arguments
// type    name        description
// tuple   infoArray
// Slew/Point/AOT       SlewCal or pointing mode or global AOT info
// 0.0                  not in use
// TotDur               duration of the phase Slew/Point/AOT
// nbLines              number of spectral lines observed in phase Slew/point
// nnods                number of nod cycles in phase Point
// m*n                  size of raster when applicable
// wave1                each of the nbLines wavelengths or waveStart
// wave2                each of the nbLines wavelengths or waveEnd
// order                grating order for line wave
// gratStep             grating step (needed to estimate "multiplexing")
// TOT,SRC,REF,CAL,OVR  the canonical OBCP duration (/nod/raster)
//
// Return values
// Type          Description
//
// Description   : Use the information in infoArray to compute several times and
// overheads, as well as the expected RMS fluctuations for each observed line
// infoArray is a three-element tuple:
//    infoArray[0] contains information on the SlewCal phase
//    infoArray[1] contains information on the OBS phase
//    infoArray[2] contains global information on the AOT
//                  
// Dependencies  : 
//
// Comments      : 
// 
// History       : 0.1  6-Sep-2005 DAC
// 0.2 27-sep-2005 Adding elements to compute RMS
// 0.3 28-sep-2005 Add nbGratSteps to infoArray
// 0.4 29-sep-2005 Add confOBCP to input arguments since I need nb_up_dn !!
// 0.5  6-oct-2005 Corrected Raster/Staring logic
// 0.6 14-oct-2005 Text of message
// 1.0 24-oct-2005 Add HTML tags
// 1.1 23-jan-2006 Multiplication by nbNods, mRaster, nRaster no longer needed
//                 since next_state collects time per raster per nod. Also
//                 eliminate "PACS overheads"
// 1.2  1-mar-2006 Use dformat for messages
// 2.0 11-mar-2006 Deal with LINE and CONT RMS values
// 2.1 22-nov-2006 Added "verbose" to input arguments
// 3.0 17-jan-2006 "Improved" messages
// 3.1 12-feb-2007 Accept as input the tuples lines
// 3.2 14-feb-2007 Adapted to amended PacsSpecRMS, simplified code as now
//                 used only with LINE
// 3.3 12-apr-2007 Add obsOverhead for SCR-2813
// 3.4 27-apr-2007 SPR-3147: change km/s into kms
// 3.5 29-may-2007 SPR-3243 Continuum S/N: mJy/mJy
// 3.6 13-jun-2007 SPR-3307 Fewer digits in messages
// 3.7 24-oct-2007 Added nbOBS and nbOFF to input arguments; same to
//                 PacsSpecRMS
// 4.0 08-feb-2010 VD PHS-1308 chnaged to _tmp so that other dependencies are not broken                
// 4.1 08-feb-2010 VD PHS-1308 WS to take into account Nod cycles repeats in SN and RMS
// 5.0 21-apr-2010 VD PHS-1385 un-chop
// 6.0 05-may-2010 VD PHS-1385 cont's RMS simulation from freqSwitch
//                 
procedure PacsProcessInfoArrayLine_4unchop {
    /* infoArray                                                               */
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    /* lines                                                                  */
    /* {id,redshifted wavelength,repeat factor,line flux,continuum flux,      */
    /*  line width,line flux unit,line width unit}                            */
    {string,double,int,double,double,double,string,string}[] lines = [];
    /* confOBCP                                                               */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* observatory overhead                                                    */
    int obsOverhead = 180;
    /* nbOBS and nbOFF                                                         */
    int nbOBS = 1;
    int nbOFF = 0;
    int[] gratScanObsTime = [1];
    /* verbose?                                                                */
    bool verbose = true;
}{
    // Data used here is to be found in
    // infoArray[0]{0}{2}   : tslew from PointReq
    // infoArray[0]{0}{3}   : Number of key waves in AOT
    // infoArray[0]{1}[]{0} : keyWAVE[]
    // infoArray[0]{1}[]{5} : sumCalTime[][0]
    // infoArray[0]{1}[]{6} : sumCalTime[][1]
    // infoArray[0]{1}[]{7} : sumCalTime[][2]
    // infoArray[0]{1}[]{8} : sumCalTime[][3]
    // infoArray[0]{1}[]{9} : sumCalTime[][4]
    // infoArray[1]{0}{0}   : PointReq information (ex. SmSrcDither)
    // infoArray[1]{0}{1}   : Integration time per plateau
    // infoArray[1]{0}{2}   : OBCP duration *per pointing*
    // infoArray[1]{0}{3}   : Number of lines/ranges
    // infoArray[1]{0}{4}   : Number of nod cycles
    // infoArray[1]{0}{5}   : Raster m*n
    // infoArray[1]{1}[]{0} : Starting wave for line []
    // infoArray[1]{1}[]{1} : Ending wave for line []
    // infoArray[1]{1}[]{2} : Grating order for line []
    // infoArray[1]{1}[]{3} : Grating step for line []
    // infoArray[1]{1}[]{4} : Number of grating steps for line []
    // infoArray[2]{0}{0}   : OBCP information (ex. FreqSwitch)
    // infoArray[2]{0}{2}   : Total duration of AOR (SLEW+OBS)
    // infoArray[2]{0}{3}   : Raster "m" size
    // infoArray[2]{0}{4}   : Raster "n" size
    // infoArray[2]{0}{5}   : Nb of nods (does not seem to be used anywhere)
    // Number of spectral lines (SlewCal and OBS)
    int nbKeyWaves = infoArray[0]{0}{3};
    int nbLines = infoArray[1]{0}{3};
    // Number of nods (OBS)
    int nbNodCycles = infoArray[1]{0}{4};
    // Nb of "pointings" for nbNodCycles
    int nbNods = 2 * nbNodCycles;
    if(nbNods == 0) {
        nbNods = 1;
    }
    // Call module to estimate RMS fluctuations; pass information via infoArray
    // and confOBCP (for nb_up_dn)
    // To conform with PacsRangeSpec code, define dummy rangeSPOT tuple (needed
    // by new RMS module)
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [];
    // Ditto for "orderSel"
    // add Fake infoRangeSed PHS-1308 sorry !
    {double,double}[] infoRangeSed = [{0.0,0.0}];
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = PacsSpecRMS_4unchop("LINE","orderSel",infoArray,rangeSPOT,infoRangeSed,confOBCP,nbOBS,nbOFF,gratScanObsTime,verbose);
    // Define variable to extract info from noiseTuple
    double[][] noiseWave = [[0.0]];
    // Useful variables
    int lineCnt = 0;
    string[] msgLine = ["Line1"];
    // one line of text
    // Report on nodding pattern and pointing details
    msgLine[lineCnt] = "PACS AOT: PacsLineSpec";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Pointing mode: <B>" + infoArray[1]{0}{0} + "</B> with " + nbNodCycles + " nod cycles</p>";
    lineCnt = lineCnt + 1;
    int mRaster = infoArray[2]{0}{3};
    int nRaster = infoArray[2]{0}{4};
    // When either m or n are >1 then it is raster
    if(mRaster > 1 || nRaster > 1) {
        msgLine[lineCnt] = "<p>Raster size (lines/points):" + mRaster + "/" + nRaster + "</p>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "<p> Nod pattern: nominal position A, or A->B, B->A, etc.</p>";
    lineCnt = lineCnt + 1;
    if(nbNodCycles == 0) {
        msgLine[lineCnt] = "<p>   A </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles == 1) {
        msgLine[lineCnt] = "<p>   A->B </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles == 2) {
        msgLine[lineCnt] = "<p>   A->B B->A </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles > 2) {
        int aux1 = nbNodCycles - 2;
        msgLine[lineCnt] = "<p>   A->B B->A and " + aux1 + " more A<->B leg(s) </p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("AOT, PointMode and Nodding info",lineCnt,msgLine);
    // Global timing information for this AOT
    lineCnt = 0;
    int totAOT = infoArray[2]{0}{2};
    msgLine[lineCnt] = "<p> AOT total duration: " + totAOT + " [sec] </p>";
    lineCnt = lineCnt + 1;
    //  Next is tslew returned by PntReq
    int tslew = infoArray[0]{0}{2};
    msgLine[lineCnt] = "<ul><li> CalSlew (with overheads) " + tslew + " [sec]</li>";
    lineCnt = lineCnt + 1;
    // infoArray[1]{0}{2} is defined as the elementary OBCP duration (per nod
    // and per raster pointing; includes all wavelengths)
    //int totSRCREF = mRaster * nRaster * nbNods * infoArray[1]{0}{2};
    int totSRCREF = infoArray[1]{0}{2};
    msgLine[lineCnt] = "<li> SRC+REF (with overheads) " + totSRCREF + " [sec]</li>";
    lineCnt = lineCnt + 1;
    //  Logic from RV... If tslew takes shorter than obsOverhead, we keep
    //  obsOverhead
    int cost = totAOT - tslew;
    //  But if tlsew takes longer, it becomes the new obsOverhead
    if(tslew > obsOverhead) {
        obsOverhead = tslew;
    }
    cost = cost + obsOverhead;
    msgLine[lineCnt] = "<li><b>AOT cost</b> (includes time for slewing to source): " + totSRCREF + " + " + obsOverhead + " [sec] = " + cost + " [sec]</li></ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Global AOT durations",lineCnt,msgLine);
    if(verbose) {
        debug_print("++ Start ProcessArray debug info");
        debug_print(" CalSlew: " + infoArray[0]);
        debug_print(" OBS    : " + infoArray[1]);
        debug_print(" TotDur : " + infoArray[2]);
        debug_print("++ End of ProcessArray debug info");
    }
    // Inform the details of SlewCal to HSPOT user
    //   AOT prologue
    lineCnt = 0;
    msgLine[lineCnt] = "<ul><li> AOT prologue duration: " + infoArray[0]{1}[nbKeyWaves]{5} + " [sec]</li>";
    lineCnt = lineCnt + 1;
    //  For each keyWave
    for(int loop0 = 0 .. nbKeyWaves - 1) {
        msgLine[lineCnt] = "<li> KeyWave: " + infoArray[0]{1}[loop0]{0} + " [&micro;m]; CAL duration: " + infoArray[0]{1}[loop0]{5} + " [sec]</li>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    // Display message
    PacsMessageCenter("LINE setup and CAL summary",lineCnt,msgLine);
    // Re-initialize lineCnt for new series of messages
    lineCnt = 0;
    // Continue defining noiseWave for historical reasons (it used to be returned
    // by PacsSpecRMS, now replaced by bigTuple)
    for(int loop1 = 0 .. nbLines - 1) {
        int trueObsTime = infoArray[1]{1}[loop1]{5};
        noiseWave[loop1] = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0];
        //      CONTinuum
        noiseWave[loop1][0] = bigTuple[loop1]{0}{1}[0];
        noiseWave[loop1][1] = bigTuple[loop1]{0}{1}[1];
        noiseWave[loop1][2] = bigTuple[loop1]{0}{1}[2];
        noiseWave[loop1][3] = bigTuple[loop1]{0}{1}[3];
        //      LINE
        noiseWave[loop1][4] = bigTuple[loop1]{0}{1}[4];
        noiseWave[loop1][5] = bigTuple[loop1]{0}{1}[5];
        noiseWave[loop1][6] = bigTuple[loop1]{0}{1}[6];
        noiseWave[loop1][7] = bigTuple[loop1]{0}{1}[7];
        //      CONT and LINE for refWave     
        noiseWave[loop1][8] = bigTuple[loop1]{0}{1}[8];
        noiseWave[loop1][9] = bigTuple[loop1]{0}{1}[9];
        noiseWave[loop1][10] = bigTuple[loop1]{0}{1}[10];
        //      Estimate resolution for given wavelength and order
        //      Need order and wavelength
        int order = infoArray[1]{1}[loop1]{2};
        double wave = infoArray[1]{1}[loop1]{0};
        //      Build key to read SPEC_resolution table
        string keyCOL = "resol" + order;
        double resolkm = interpolate("SPEC_resolution",keyCOL,wave);
        //      Resolution in microns
        double resolmic = resolkm * wave / 300000.0;
        // Compare instrument resolution with line width
        // User given line width
        double userWidth = lines[loop1]{5};
        // User given width units
        string unitWidth = lines[loop1]{7};
        // Is there a sensitivity degradation? 
        bool sensitDegrad = false;
        // Assume no degradation
        double degrad = 1.0;
        // Avoid division by zero
        if(resolkm > 0.0) {
            // Do not compare torchons et servillettes
            if(unitWidth == "micron" && userWidth > resolmic) {
                sensitDegrad = true;
                degrad = sqrt(userWidth / resolmic);
            }
            if(unitWidth == "kms" && userWidth > resolkm) {
                sensitDegrad = true;
                degrad = sqrt(userWidth / resolkm);
            }
        }
        if(verbose) {
            debug_print("++line parameters: " + userWidth + " " + unitWidth);
            debug_print("++sensitDegrad: " + sensitDegrad);
            debug_print("++Degrad: " + degrad);
        }
        // SrcTime includes REF!
        int trueSrcTime = infoArray[1]{1}[loop1]{6} + infoArray[1]{1}[loop1]{7};
        int lineOver = trueObsTime - trueSrcTime;
        msgLine[lineCnt] = "<h3>" + lines[loop1]{0} + ": " + dformat(infoArray[1]{1}[loop1]{0},2) + " [&micro;m]:</h3>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<ul>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<li>FWHM at current wavelength: " + dformat(resolkm,1) + " [km/s] or " + dformat(resolmic,3) + " [&micro;m]";
        lineCnt = lineCnt + 1;
        int noiseMjy = ifloor(1000.0 * noiseWave[loop1][1]);
        msgLine[lineCnt] = "<li>   Continuum RMS: " + noiseMjy + " [mJy]";
        lineCnt = lineCnt + 1;
        // SPR-3243 Wrong S/N ratio. Use the occasion to avoid divide-by-zero
        if(noiseWave[loop1][1] > 1.0E-30) {
            double s2nCONT = lines[loop1]{4} / noiseWave[loop1][1];
            s2nCONT = s2nCONT / 1000.0;
            msgLine[lineCnt] = "<li>   Continuum S/N: " + dformat(s2nCONT,2);
            lineCnt = lineCnt + 1;
        }
        double lineNoise = noiseWave[loop1][5] * 1.0E18;
        msgLine[lineCnt] = "<li>Line RMS: " + dformat(lineNoise,2) + "E-18 [w/m2]</li>";
        lineCnt = lineCnt + 1;
        double s2nLINE = lines[loop1]{3} / lineNoise;
        msgLine[lineCnt] = "<li>Line S/N: " + dformat(s2nLINE,2);
        lineCnt = lineCnt + 1;
        if(sensitDegrad) {
            msgLine[lineCnt] = "<li><b>Warning:</b> the given line width, " + userWidth + " " + unitWidth + ", exceeds the instrumental FWHM; expect a loss of " + dformat(degrad,1) + " times in the LINE Signal-to-Noise ratio</li>";
            lineCnt = lineCnt + 1;
        }
        msgLine[lineCnt] = "<li>Total duration (SRC+REF+PACS overheads): " + trueObsTime + " [sec]";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<li>SRC+REF (no overheads): " + trueSrcTime + " [sec]";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "</ul>";
        lineCnt = lineCnt + 1;
    }
    // Display message
    PacsMessageCenter("SpecLine summary",lineCnt,msgLine);
}

// Mission phase : Performance Verification Phase
//
// Purpose : Explore the time constant after flux change for a flux levels using the low gain
//
// Author : Koryo Okumura
//
// Version : Wed Jul 29 08:49:18 EDT 2009
//
// CUS script : mode PacsCal_Phot_bandpassDDCS
//
// Argument :
//   int sideField = 7134; // Chopper angle for the FOV next to BB2
//   int chop_pos_CS2 = 21196; // Chopper angle for BB2
//   string biasTable = "BOLObias_standard_low"; // Bias table
//   string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//   string calBiasTable = "BOLObias_standard_low"; // Bias table used during calibration blocks
//   string calGain = "LOW" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "DIRECT" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//   int nLoops1 = 30; // number of CSs cycles during slew
//   int nLoops2 = 30; // number of CSs cycles during initial hold
//   int nLoops5 = 30; // number of CSs cycles during final hold
//   int nReadout_plateau = 16; // number of readouts per plateau
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description : OBS script to execute PacsCal_Phot_bandpassDDCS
//
// Dependencies : Previously obtaind data at high gain (PCD req.1.1.1bis)
//
// Comments : generated by IA script : cus_PVph_timeCont(False)
//                     SCR PACS-1873
//
obs PacsCal_Phot_bandpassDDCS {
    int sideField = 7134; // Chopper angle for the FOV next to BB2
    int chop_pos_CS2 = 21196; // Chopper angle for BB2
    string biasTable = "BOLObias_standard_low"; // Bias table
    string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    string calBiasTable = "BOLObias_standard_low"; // Bias table used during calibration blocks
    string calGain = "LOW" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "DIRECT" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 16; // number of readouts per plateau
    bool verbose = true;
}{
    // Bus configuration for the Burst mode (7)
    busconfig (7);
    int nRdts = readouts_plateau - 1;
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = 0;
    int timeChgBias0 = duration(PHOT_change_biases(biasTable,"NO_CHANGE","NO_CHANGE"));
    int timeCal3CPR1 = duration(Pacs_OBCP_chopped_photometry2(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    //Minimum slew time
    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DDCS","LOW"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DDCS",calGain));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"LOW"));
    }
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
    }
    int tslewmin = timeOBSID + timeChgBias + timeCal3CPR1;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeChgBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_bandpassDDCS(biasTable,gain,sideField,chop_pos_CS2));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DDCS","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DDCS",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            // No biases setting here because nothing changes
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            //  Call the Phot_bandpassDDCS
            //************************************
            Phot_bandpassDDCS(biasTable,gain,sideField,chop_pos_CS2);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DDCS","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DDCS",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// CVS comments  : $Id: PacsPhotEstimatorOBCPn.txt,v 1.9 2007/04/25 15:14:04 dcesarsk Exp $ 
// Missionphase  : Operations
//
// Purpose       : Estimate OBCP parameters for the PointMode and filter
//                 specified by the HSPOT user
//
// CUS author    : DAC
// Script file   : PacsPhotEstimatorOBCPn_PV.txt 
//
// Input arguments
// type           name       Description
//
// Return values
// Type    Description
// tuple  {confPHOTblu,confPHOTred,confOBCP,{extension}}
//
// Description   : 
//
// Dependencies  : 
//
// Preconditions :
//
// Comments      : 
// 
// History       : 0.1  19-may-2008 DAC Based on PacsPhotEstimatorOBCPn
//                      added CAL file name to input list
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsPhotEstimatorOBCPn_PV {
    int pointCase = 11; // Internal code for the pointing mode (see main)
    string filter = "blue1" in ["blue1","blue2"]; // filter from HSPOT
    string obcpparams = "OBCP3params"; //Name of the OBCP3params cal file
    int repFactor = 1; //Repeat factor, i.e. number of nod cycles
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOTdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; // Default values
    bool noddingSel = false; // Nodding allowed or not
    bool dither = true; // With/without dithering
    bool verbose = true; // Print bla-bla
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confPHOTblu = clone(paramsPHOTdef{0});
    {int,int,int,int,int,int,int,int,int} confPHOTred = clone(paramsPHOTdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsPHOTdef{2});
    // OBCP tuples use several variables, some of them are dedicated to one or
    // another OBCP. Here define all the tuple variables. Later, they may be 
    // updated according to used OBCP
    int nb_main_loops = 0;
    int nb_cycles_obs_cal = 0;
    int nb_rdouts_plateau = 0;
    int nb_chop_cycle = 0;
    int max_dither = 0;
    int nhold = 0;
    int nb_SRC_OFF = 0;
    int nb_CS1_CS2 = 0;
    int pos_CS1 = 0;
    int pos_CS2 = 0;
    // Update corresponding elements of confOBCP
    // Get "duration related" parameters from corresponding OBCPnparams U-CAL table
    if(pointCase == 11 || pointCase == 12) {
        string calNAME = obcpparams;
        //  The acces key is the chosen filter: blue1 or blue2
        //  There is a row per filter; it lists main OBCP parameters
        nb_main_loops = ilookup(calNAME,filter,"nb_main_loops");
        //  OBCPconf uses nb_cycles_obs_cal as variable name
        nb_cycles_obs_cal = nb_main_loops;
        nb_rdouts_plateau = ilookup(calNAME,filter,"nb_rdouts_plateau");
        nb_chop_cycle = ilookup(calNAME,filter,"nb_chop_cycle");
        max_dither = ilookup(calNAME,filter,"max_dither");
        nhold = ilookup(calNAME,filter,"nhold");
    }
    if(pointCase == 22 || pointCase == 31) {
        calNAME = obcpparams;
        nb_cycles_obs_cal = ilookup(calNAME,filter,"nb_cycles_obs_cal");
        nb_SRC_OFF = ilookup(calNAME,filter,"nb_SRC_REF");
        nb_rdouts_plateau = ilookup(calNAME,filter,"nb_rdouts_plateau");
        nb_CS1_CS2 = ilookup(calNAME,filter,"nb_CS1_CS2");
        nhold = ilookup(calNAME,filter,"nhold");
        //      CS1 and CS2 from dedicated CAL-U file
        pos_CS1 = ilookup("CHOPPERCSparams","PHOT","pos_CS1");
        pos_CS2 = ilookup("CHOPPERCSparams","PHOT","pos_CS2");
    }
    if(pointCase == 33) {
        calNAME = "No CAL file yet";
    }
    if(verbose) {
        debug_print("++PhotEstimator reads CAL-U: " + calNAME);
    }
    // Compute the OBS time for this pointCase and filter
    // Line Scan is not associated to an OBCP yet
    if(pointCase == 33) {
        int[] dureeOBCPn = [1,1,0,0,0];
    }
    // Point source
    if(pointCase == 11 || pointCase == 12) {
        dureeOBCPn = PacsDureeOBCP3(nb_main_loops,nb_rdouts_plateau,nb_chop_cycle);
    }
    // For small and large source use OBCP4
    if(pointCase == 22 || pointCase == 31) {
        dureeOBCPn = PacsDureeOBCP4(nb_SRC_OFF,nb_rdouts_plateau,nb_cycles_obs_cal,nb_CS1_CS2);
    }
    if(verbose) {
        debug_print("++PhotEstimator: dureeOBCP4: " + dureeOBCPn);
    }
    double quantumOBStime = double(dureeOBCPn[1] + dureeOBCPn[2]);
    // Get the "quantum" OBS time for the current order. U-CAL time doubles if 
    // nodding is allowed
    double nodFactor = 1.0;
    if(noddingSel) {
        nodFactor = 2.0;
    } else {
        int nb_nods = 0;
    }
    quantumOBStime = nodFactor * quantumOBStime;
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    if(noddingSel) {
        msgLine[lineCnt] = "<p>Shortest SKY time (no overheads) for filter " + filter + ": " + quantumOBStime + " [sec], includes an A=>B nod cycle</p>";
    } else {
        msgLine[lineCnt] = "<p>Shortest SKY time (no overheads) for filter " + filter + ": " + quantumOBStime + " [sec], no nodding demanded</p>";
    }
    lineCnt = lineCnt + 1;
    // Deal with repFactor. In case of noddingSel = false, the repFactor
    // gives the PointReq nrepeat count
    //
    // Re-use the previous logic based on userOBStime...
    // Repeat factor given for current filter.
    // Observing time can be increased by (integer) factor:
    int obsFactor = repFactor;
    double newOBStime = double(obsFactor) * quantumOBStime;
    if(verbose) {
        debug_print("++PhotEstimator: obsFactor: " + obsFactor + "; filter: " + filter);
    }
    // Common part of nodding/no nodding message
    if(repFactor == 1) {
        msgLine[lineCnt] = "<p>You may increase the sensitivity for the current filter by setting";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = " the RepetitionFactor = 2,3,.. to obtain OBStime = repFactor*" + quantumOBStime + "</p>";
        lineCnt = lineCnt + 1;
    }
    // If no nodding then we repeat the raster pattern
    if(!noddingSel) {
        int repeat_factor = 1;
        nb_nods = 0;
        if(obsFactor > 1) {
            msgLine[lineCnt] = "<p>You entered repFactor > 1 </p>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "Since no nodding was requested, we shall repeat";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "the raster pattern " + obsFactor + " times, leading to a total dwell time of " + newOBStime + " [sec]</p>";
            lineCnt = lineCnt + 1;
            repeat_factor = obsFactor;
        }
    } else {
        //    Nodding selected, here we increase newOBStime by increasing the
        //    number of nod cycles
        repeat_factor = 1;
        nb_nods = obsFactor;
        if(obsFactor > 1) {
            msgLine[lineCnt] = "<p>You entered repFactor > 1 </p>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "Since nodding is allowed, we set the number";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = " of nods to " + obsFactor + " cycles; leading to an accumulated dwell time of " + newOBStime + " [sec]</p>";
            lineCnt = lineCnt + 1;
        }
    }
    // Some more Pointing parameters (auxN just in case I need more...)
    int aux2 = 0;
    int aux3 = 0;
    // Pack information into proper tuples
    confOBCP{0} = nb_cycles_obs_cal;
    confOBCP{1} = max_dither;
    if(!dither) {
        confOBCP{1} = 0;
    }
    // Use confOBCP{2} to convey nb_chop_cycle
    confOBCP{2} = nb_chop_cycle;
    confOBCP{3} = nb_SRC_OFF;
    confOBCP{4} = nb_rdouts_plateau;
    confOBCP{5} = nb_CS1_CS2;
    confOBCP{15} = pos_CS1;
    confOBCP{16} = pos_CS2;
    // All these leftovers from SPECTRO code
    //   confOBCP { 6}  =   nb_grat_step_up  ;
    //   confOBCP { 7}  =   nb_grat_step_dn  ;
    //   confOBCP { 8}  =   grat_start_pos   ;
    //   confOBCP { 9}  =   grat_start_time  ;
    //   confOBCP {10}  =   grat_def_pos     ;
    //   confOBCP {11}  =   grat_def_time    ;
    //   confOBCP {12}  =   chop_pos_SRC     ;
    //   confOBCP {13}  =   chop_pos_REF1    ;
    //   confOBCP {14}  =   chop_pos_REF2    ;
    //   confOBCP {17}  =   chop_def         ;
    //   confOBCP {19}  =   order ;
    //   confPHOTred{ 0} =  capa_red;
    //   confPHOTred{ 1} =  nb_rdouts_ramp_red;
    //   confPHOTred{ 2} =  nb_rdouts_subramp_red;
    //   confPHOTred{ 3} =  comp_mode_red;
    //   confPHOTred{ 4} =  glitch_det_red;
    //   confPHOTred{ 5} =  ramp_fit_alg_red;
    //   confPHOTred{ 6  =  nb_raw_red;
    //   confPHOTred{ 7} =  bias_r_red;
    //   confPHOTred{ 8} =  bias_d_red;
    //   confPHOTblu{ 0} =  capa_blu;
    //   confPHOTblu{ 1} =  nb_rdouts_ramp_blu;
    //   confPHOTblu{ 2} =  nb_rdouts_subramp_blu;
    //   confPHOTblu{ 3} =  comp_mode_blu;
    //   confPHOTblu{ 4} =  glitch_det_blu;
    //   confPHOTblu{ 5} =  ramp_fit_alg_blu;
    //   confPHOTblu{ 6  =  nb_raw_blu;
    //   confPHOTblu{ 7} =  bias_r_blu;
    //   confPHOTblu{ 8} =  bias_d_blu;
    if(verbose) {
        debug_print("++PhotEstimator: OBCP: " + confOBCP);
    }
    // Pass messages to user (not in scan mode)
    if(pointCase != 33) {
        PacsMessageCenter("Observing time information",lineCnt,msgLine);
    }

    return {confPHOTblu,confPHOTred,confOBCP,{nb_nods,repeat_factor,nhold,0}};
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.11
//           Low frequency noise measurement (3 hours each mode)
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_PVph_lowFreq
//
// Argument :
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//
// Description : 
//
// Dependencies : None
//
// Comments :
//
// Version : Jul 1 2008
//
procedure Phot_PVph_lowFreq {
    int measureTime = 10800; // Noise measurement time in seconds
    string filter = "blue70um" in ["blue70um","green100um"]; // Filter
    string setting = "DIRECT" in ["DIRECT","DDCS"]; // Mode
    string biasTable = "BOLObias_standard_high"; // Bias table
}{
    //
    //***************
    // Select Filter
    //***************
    //
    if(filter == "blue70um") {
        PHOT_fltw_move("POS B");
    } else {
        PHOT_fltw_move("POS A");
    }
    //
    //***********************************************
    //	Bias setting of the detectors
    //***********************************************
    //
    PHOT_set_biases(biasTable,setting,"HIGH");
    //
    //********************
    // Let all stabilized
    //********************
    delay(60);
    //
    //**************************************
    // Noise measurement during measureTime
    //**************************************
    TMMarker602();
    delay(measureTime);
    TMMarker600();
}

// Filename	: Pacs_Spec_dark_current_imt502
//
// Purpose	:  Short performance test Dark Current
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do dark current measurements in buffer transmission mode on
//                     both CS positions.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and internal CSs switched off.
//                        CDMS has to be switched to burst mode. After the end of the
//                        test go back to nominal mode.
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 2.1
// 
// History 	: 1.0 04-04-07 HD. IST update.
// 		  2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//                     2.1 08-Apr-2008 HF adapted to in-flight default biases and heater values
//              
procedure Pacs_Spec_dark_current_imt502 {
}{
    // Switch to burst mode 
    Burstmode_setup_block();
    //
    // Set-Up definition
    // reset interval in ramps    
    int reset_inter = 512;
    // choose temperature blue det in raw units
    double blue_temp = 0.78;
    // heat-up time for blue detector heater in sec
    int heat_up_time = 900;
    // observing time in sec     
    int obs_time = 420;
    // Move chopper to one CS
    PACS_Chopper_mov_abs_fm_bb(-21350);
    // Set Temperature 
    PACS_Spec_B_Heat_Setup(blue_temp);
    // Wait for stabilization of the temperature 
    delay(heat_up_time);
    // CRE setup
    int ramp_len_red = reset_inter;
    int ramp_len_blu = reset_inter;
    double bias_d_red = 0.03;
    double bias_r_red = 3.0E-4;
    double bias_d_blu = 0.08;
    double bias_r_blu = 3.0E-4;
    int capa_red = 0;
    int capa_blu = 0;
    SPEC_CRE_No_Heater_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // SPU setup   
    int comp_mode_blu = 25;
    int comp_mode_red = 25;
    int nb_samp_subramp_blu = 16;
    int nb_samp_subramp_red = 16;
    int nb_raw_spu_blu = 3;
    int nb_raw_spu_red = 3;
    int glitch_det = 1;
    int ramp_fit_alg = 1;
    bool startSPU = true;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Dark Current measurements for 7 minutes at CS1 position
    delay(obs_time);
    // Do SPU reset
    SPEC_spu_reset();
    // Move chopper to default position 
    PACS_Chopper_mov_abs_fm_bb(0);
    // CRE setup to default values
    SPEC_CRE_No_Heater_setup(64,64,bias_d_red,0.01,bias_d_blu,0.01,12,12);
    // reset burst mode profile
    Burstmode_reset_block();
}

// $Id: WriteEndBB.txt,v 1.2 2007/08/22 10:21:52 dcesarsk Exp $ 
// Purpose       : Set BBID to its default value to indicate the end
//                 of current BB execution (see FIRST-FSC-DOC-0200) 
//
// CUS script    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
//
// Input arguments N/A
//
// Description   : BBID will be set to its default value
//
// Comments      : Needed for SCR-3507
//
// Version       : 0.1 21-aug-2007 First creation
//
procedure WriteEndBB {
}{
    int iBBID = 0x40000000;
    // Write BBID to DEC/MEC
    Pacs_DMC_SET_BBID(iBBID);
}

// Missionphase  : 
//
// Purpose       : 
//                  
//                 
//
// OBCP author   : HF
// TCL file      : N/A
// CUS author    : VD (based on DAC)
// Script file   : OBCP_grat_line_scan_chopped_3.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Belongs to Section 3.7: Grating Spectral Line Scan 
//                 of PACS-ME-LI-005
//                 Consists mainly of a sequence with repetitive up- and
//                 down-scans with the grating around a given center position,
//                 while the chopper is operating on ABBA pattern: section
//		   3.7.6 (ABBA chopping OBCP 35, DMC 19)
//
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : This is a COPY of OBCP_grat_line_scan_chop_3. 
//                 The goal is to dispose of a copy of the standard ABBA 
//                 chopping OBCP 35, to be used to perform the calibration
//                 block in the AOTs using the ABBA chopping scheme
//		   with another building block number
// 
// History       : 1 02-Apr-2009 PR COPY of OBCP_grat_line_scan_chop_3
// 		   2 24-Jul-2009 PR COPY of OBCP_grat_line_scan_chop_3_cal version from 20090616 & change BBID from 350 to 351
//		                    Caused by undocumented update of OBCP_grat_line_scan_chop_3_cal on 20090624 (PACS-SPR 1860)
//
int[] block OBCP_grat_line_scan_chop_3_cal_unfckdup_yet PACS 351 {
    int nb_up_down = 1; // Nb of "up-down" sequences (P#1); 
    int nb_grat_steps = 16; // Nb of grating steps (P#2)
    int grat_step_up = 168; // Grating step up (P#3) 
    int nb_cycles_grat_pos = 2; // Nb of cycles per grating position (P#4); 
    int chop_pos_REF1 = -1000; // Chopper position 1 SRC (P#5) 
    int nb_ramps_plateau = 3; // Nb of readouts per chopper position (P#6); 
    int chop_pos_REF2 = 2000; // Chopper position 2 REF (P#7)
    int nb_CS1_CS2 = 0; // Nb of cycles on the internal CSs (P#8); 
    int chop_pos_CS1 = -21350; // Chopper position on CS1 (P#9)
    int chop_pos_CS2 = 21200; // Chopper position on CS2 (P#10)
    int grat_step_dn = -168; // Grating step down (P#11) 
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 445000; // Starting grating position
    int grat_time = 40000; // Grating time to move to start [msec]
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopper default position
    int grat_def_time = 20000; // Time to come back to default position
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duree_msec [msec] as it goes)
    // Begin 
    // OBCP_GRATING_LINE_SCAN_CHOPPED_3(seq, seq_time,
    //   P#1,&,P#11, detector, grat_def, grat_time,
    //   cmp_par_blue, cmp_par_red, grat_def, chop_def, grat_time)
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(P#5)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) ; (all parameters filled 
    // by DPU based on seq parameter) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_time) 
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    // DMC_START_SEQUENCE
    //////////////////////////////////////////////////////////////////////////
    // Call DC/MEC code to estimate its duration
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    int[] duree1 = DMC_19_grat_line_scan(nb_up_down,nb_grat_steps,nb_ramps_plateau,nb_CS1_CS2,nb_cycles_grat_pos);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    debug_print("Execution time [msec] from DMC: " + seq_time);
    // duree_msec(seq_time) 
    duree_msec = duree_msec + t_cmd + seq_time;
    // WAIT(seq_time) ; Check execution status of the sequence and in case of 
    // failure stop OBCP and issue TM(1,8)+event 
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_def_time) 
    duree_msec = duree_msec + grat_def_time;
    duree_OVR = duree_OVR + grat_def_time;
    // Issue TM(1,7)
    // End 
    // Now trigger execution of OBCP
    // This OBCP is number 35, requires 21 parameters and calls DEC/MEC #19
    // PENDING!!!    string obcp_ID = "GRAT_SCAN_CHOP2";
    //    string obcp_ID = "GRAT_SCAN_CHOP3";
    int obcp_ID = 35;
    int obcp_par_nb = 21;
    int seq_DMC = 19;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_grat_steps},{5,grat_step_up},{6,nb_cycles_grat_pos},{7,chop_pos_REF1},{8,nb_ramps_plateau},{9,chop_pos_REF2},{10,nb_CS1_CS2},{11,chop_pos_CS1},{12,chop_pos_CS2},{13,grat_step_dn},{14,detector},{15,grat_pos},{16,grat_time},{17,comp_mode_blu},{18,comp_mode_red},{19,grat_def},{20,chop_def},{21,grat_def_time}];
    //     Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp); Mnemonic not impl. use RAW
    Pacs_DPU_START_OBCP_RAW(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    //    debug_print(obcp_ID + ": " + time_array);
    delay(time_array[0]);
    // Return the array of times

    return time_array;
}

// File          : PACS_Spec_Fil_Diaghk_Setup.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Switch on diagnostic hk relevant to spectrometer filterwheel  
//
// Author        : P.Royer, B.Vandenbussche
// CUSification  : DAC
// Arguments     :
//
// Description   : Spectrometer filter wheel diagnostic housekeeping ON
//               :
// Comments      : Code of this building block has been taken out of PTP 0.7.7
//                 by PR.
//                 
//                 Inclusion of hall sensor voltage as housekeeping parameter
//                 is pending - should be included here as well.
//
// Version       : 1.6
// History       : 1.0 / 25-Nov-2003 initial version by BV 
//                 1.1 / 06-Jan-2004 syntax checked 
//                 1.2 / 12-Jan-2003 checksum on actual parameters only - BV
//                 1.3 / 13-Jan-2003 bug fix in list syntax
//                 1.4 / 31-May-2004 Added hall sensor readouts
//                 1.5 / 07-Jul-2004 Added DMC_FPU_T_SENS_ST by TM
//                 1.6 / 19-Jul-2004 Added IMOTA and IMOTB [BV]
//                 1.7 / 12-May-2006 change to block + simplify comments + diaghk+period as argument
//
block PACS_Spec_Fil_Diaghk_Setup PACS 158 {
    int diag_hk_period = 5; // 1: synch w/ BLUE DET  2: synch w/ RED DET  >4: period in ms   0: 1KHz (not to use w/ science)
}{
    // Register start of BB
    WriteBBID($BBID);
    //
    debug_print("Start PACS_Spec_Fil_Diaghk_Setup");
    //
    // Max number of requested diag HK parameters = 16
    // (including the last one, which is always forced to the same value)
    //     DMC_FW_SPEC_CTRL        210
    //     DMC_FWSP_CUR_POS        255
    //     DMC_FWGRAT_HALL_A      256
    //     DMC_FWGRAT_HALL_B      257
    //     DMC_FPU_T_SEN_ST         404
    //     DMC_FW_SPEC_TEMP       405
    //     DMC_FWSPEC_POS_A        555
    //     DMC_FWSPEC_POS_B        559
    //     DMC_FW_GR_IMOTA        560
    //     DMC_FW_GR_IMOTB        567
    //     DMC_FW_GR_VMOTA       556
    //     DMC_FW_GR_VMOTB       564
    //
    int nb_words = 13;
    {int}[] list_tuple = [{210},{255},{256},{257},{404},{405},{555},{559},{560},{567},{556},{564},{0xffff}];
    int[] list_int = [210,255,256,257,404,405,555,559,560,567,556,564,0xffff];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_DIAG_HK_LIST(nb_words,list_tuple,chksum);
    delay(1);
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    //------------------
    // End of procedure
    //------------------
}

// CVS comments  : $Id: SPEC_fltw_move.txt,v 1.3 2007/04/25 15:14:05 dcesarsk Exp $ 
// Missionphase  : 
//
// Purpose       : Change filter wheel in spectroscopy
//                 Attention: there is only one controller for
//                 the filter wheels and the grating, but different
//                 sets of controller parameters!                 
//
// Author        : Thomas Mueller
// CUS script    : Diego A. Cesarsky
// CVS file      : SPEC_fltw_move.txt
//
// Arguments     : 
//
// Description   : 
//                 This script will perform a relative movement of 90degrees of the spectrometer filter
//
//                 This script performs the following operations (section
//                 4.4.8 of the DEC/MEC User's Manual):
//		  "Consider that the grating is powered on and that an
//		   acquisition sequence has ended. To change the filter wheel
//		   position now: 
//		 1. Disable the grating controller (DMC_DISABLE_GRAT_CONT) 
//               2. Switch-on the spectro filter wheel controller 
//		    (DMC_SWON_FW_SPEC). Note : this will switch-off the
//		    grating controller and the photo filter wheel controller 
//		    but the grating position encoder will remain powered-on
//		    and will then continue reading the position. 
//               3. Any of the 2 move commands can be sent 
//               4. Switch-on the grating controller (DMC_SWON_GRAT_CONT) 
//               5. Enable the grating controller (DMC_ENABLE_GRAT_CONT) 
//               6. Start the new acquisition sequence."
//
//                 NOTE: THIS SCRIPT IGNORES REL MODES
//
// Dependencies  : 
//                 
// Comments      : This script should be executed after the
//                        switch-on procedure and the MEC setup
//
// Version       : 1.0 
//
// History	: 1.0  22-Oct-2008 PR First version, based on SPEC_fltw_move
//               :
int procedure SPEC_fltw_move_90degrees {
}{
    // 90 degrees in commanding units of the FW = (1536 / 360) * 90.
    int deg90 = iround(1536.0 / 4.0);
    // Accumulated duration [milliseconds]
    int duration_msec = 0;
    // Disable grating controller
    Pacs_DMC_DISABLE_GRAT_CONT();
    // Switch on power supply of SPEC filter wheel
    Pacs_DMC_SWON_FW_SPEC();
    // Move filterwheel to the predefined position 
    Pacs_DMC_MOVE_SPEC_FW_STEP_RAW(deg90);
    // Get the duration of the move
    int move_time = iceil(dlookup("PACSparams","fltw_time","freq_time"));
    // Same in [sec]
    int move_time_sec = Msec2sec(move_time);
    delay(move_time_sec);
    duration_msec = duration_msec + move_time;
    // Switch on grating controller
    Pacs_DMC_SWON_GRAT_CONT();
    // Enable grating controller
    Pacs_DMC_ENABLE_GRAT_CONT();

    return duration_msec;
}

// Missionphase  : FM
//
// Purpose	:  Setup diagnostic housekeeping for  
//                 CRE check-voltage test PTD1.2.4
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: Set up  housekeeping parameter for diagnostic housekeeping 
//	  of the detector, especially for check-out voltage
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and SPEC_Chop_fft_eqmimt_obs
//                 
// Comments	: 
//
// Version	: 3.0	
// 
// History 	: 1.0 17-08-06 creation by HD. script test.
//		  2.0 22-08-06 HD. error in number of diag. HKs.
//		  3.0 22-08-06 HD. script works.
block SPEC_detector_dhk_fmilt124_bb PACS 361 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //----------------------------------------------------- 
    // Setup and start diagnostic HK for detector PTD 0.7.3
    //----------------------------------------------------- 
    int chop_diag_hk_length = 13;
    {int}[] parlist = [{270},{271},{293},{304},{305},{327},{338},{339},{361},{372},{373},{395},{0xffff}];
    int[] aux = [270,271,293,304,305,327,338,339,361,372,373,395,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(chop_diag_hk_length,parlist,check_sum);
    int diag_hk_period = 1;
    // Synchronize diagnostic HK on blue spectrometer readouts
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark End of Block
    WriteEndBB();
}

// Mission phase : IST level
//
// Purpose : EMC preparation in direct mode
//
// Author : Koryo Okumura / Thomas Mueller
//
// CUS script : procedure Phot_prepareEMC_direct
//
// Argument : None
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + CSs are cold 
//
// Description :
//
// Dependencies : None
//
// Comments : 
//
// Version : Mon Jun 18 2007
//
procedure Phot_prepareEMC_direct {
}{
    string biasFile = "BOLObias_ILT_dark_high";
    // Bias table file containing the initial values
    //
    //***********************************************
    //***********************************************
    //
    //	Bias setting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(biasFile,1);
    PHOT_set_bias_volt(biasFile,2);
    PHOT_set_bias_volt(biasFile,3);
    PHOT_set_bias_volt(biasFile,4);
    PHOT_set_bias_volt(biasFile,5);
    PHOT_set_bias_volt(biasFile,6);
    //
    //
    //********************************************************
    // Sequence mode : blocking on VDEC_X for the direct mode
    //********************************************************
    //
    // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
    // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
    //
    //**************************
    // Sequence mode : Sref_only
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
    //# P 09 01 00 01
    int operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // Set gain high
    Pacs_BOLC_SET_GAIN("HIGH");
    //
    //**********************************************
    // Set the PACS chopper at the CS1
    //**********************************************
    Pacs_DMC_MOVE_CHOP_ABS(-21350);
    //
    //*******************************
    // Select Filter A (110 microns)
    //*******************************
    PHOT_fltw_move("POS A");
    //
}

// File          : PACS_Spec_Dark_SOVT2
// Missionphase  : PACS FM IST   SOVT2
//
// Purpose       : Dark Current Measurement / Assessment of straylight, PACS Spectro.
//
// Author        : Pierre Royer
// CUS script	 : PR
// CVS file	 :
//
// Arguments     : 
//
// Description   :   Visit grating positions of Low RSRF for the dark
//	     Estimate Straylight contribution from visiting High RSRF positions & placing the FW outside of any regular filter position.
//	     Do it for both filters
//	Specific to the SOVT2 version of this test:     
//	     Warm up the CSs (both simultaneously) and chop between them every 3 minutes 
//	     There should be transients > 3 minutes at the beginning (low flux), but this should at least give an idea, and several samples over the warm up time
//
// Dependencies  :
//
// Comments      : !!! It is supposed that PacsEng_Spec_setup has been run before this script, with current to both CSs == 0. !!!
//
// Version       : 1.0
// History       : 1.0 / 22-Oct-2008 
//
procedure PACS_Spec_Dark_SOVT2 {
    int obs_time = 540; // observing time in seconds per CS/FW/Grat setting
    int chop_time = 180; // duration of chopper plateau during rise of CS temp (0 = no chopping)
}{
    //
    // Declare the set of variables specific to this test
    // ===========================
    //
    string[] chopPos = ["pos_CS1","pos_CS2"];
    int choppos = 0;
    //
    // Define the combinations of Grating & FW positions to be tested on each CS
    string[] filterPos = ["POS B","POS B","POS A","POS A"];
    int[] gratingPos = [50000,740000,675000,800000];
    int n_settings = length(gratingPos);
    if(length(filterPos) != n_settings) {
        debug_print("Inconsistent number of grating and filter wheel positions specified");
    }
    //
    // Declare the CS Temps (48, 58 Ohms, copied from the SPEC_setup block (in 
    // ============= 
    double temp_CS1 = 48.0;
    //  Temperature 55K for the PACS calibration source 1 
    double temp_CS2 = 58.0;
    //  Temperature 60K for the PACS calibration source 2
    //
    // Declare the set of CRE variables
    // ===================
    double bias_d_blue = 0.17;
    double bias_d_red = 0.07;
    double bias_res_blue = 0.01;
    double bias_res_red = 0.01;
    int ramp_blue = 64;
    int ramp_red = 64;
    int capacity_blue = 0;
    int capacity_red = 0;
    // 
    // Declare the set of SPU variables
    // ===================
    //
    // Compression mode blue channel : Nominal
    int comp_mode_blu = 16;
    // Compression mode red channel : Nominal
    int comp_mode_red = 16;
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_blu = 16;
    // Nb of red samples per sub-ramp
    int nb_samp_subramp_red = 16;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUL
    int nb_raw_spu_red = 3;
    // Glitch detection; 0=on; 1=off
    int glitch_det = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    int ramp_fit_alg = 1;
    // Start SPU or not [true,false]
    bool startSPU = true;
    //
    // SETUP CRE & SPU
    // ==========
    // Setup CREs
    SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red);
    //
    // Setup SPU
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //
    // PART 1 : CS OFF, VISIT LOW & HIGH RSRF POSITIONS IN BOTH FILTERS
    //
    for(int cs = 0 .. length(chopPos) - 1) {
        //
        // Position the chopper
        // ============
        choppos = ilookup("CHOPPERCSparams","SPEC",chopPos[cs]);
        PACS_Chop_Move_Abs(choppos);
        //
        for(int n = 0 .. n_settings - 1) {
            debug_print("choppos " + choppos + " n " + n + " filterPos[n] " + filterPos[n] + " gratingPos[n] " + gratingPos[n]);
            //
            // ==FW POS ==
            SPEC_fltw_move(filterPos[n]);
            //
            // ==GRAT POS ==
            Pacs_DMC_MOVE_GRAT_ABS(gratingPos[n]);
            //
            // == OBS TIME ==
            delay(obs_time);
            //
            // == FW --> 90 DEGREES == 
            SPEC_fltw_move_90degrees();
            //
            // == OBS TIME ==
            delay(obs_time);
            //
        }
    }
    //
    // PART 2 :  RISING CS TEMPs, CHOP SLOWLY BETWEEN BOTH CS
    //
    // ==GRAT POS ==
    Pacs_DMC_MOVE_GRAT_ABS(50000);
    //
    // ==FW POS ==
    SPEC_fltw_move("POS B");
    //
    debug_print("Grating reset to 50000, FW set to POS B, CS switched on and warmed up");
    //
    // PACS CALIBRATION SOURCES
    CONF_cs("Both");
    CS_on_off("CS1","ON");
    CS_temp("CS1",temp_CS1);
    CS_on_off("CS2","ON");
    CS_temp("CS2",temp_CS2);
    //
    delay(chop_time);
    if(chop_time > 0) {
        //
        int nchop = iround(2200.0 / double(chop_time));
        debug_print("Chopping every " + chop_time + " seconds");
        debug_print("nchop x chop_time = " + nchop + " x " + chop_time + " = " + nchop * chop_time);
        //
        if(nchop >= 2) {
            //
            for(int i = 0 .. nchop - 2) {
                choppos = ilookup("CHOPPERCSparams","SPEC",chopPos[i % 2]);
                PACS_Chop_Move_Abs(choppos);
                debug_print("choppos " + choppos);
                delay(chop_time);
            }
        }
    } else {
        choppos = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
        PACS_Chop_Move_Abs(choppos);
        debug_print("No chopping: chopper position " + choppos);
        delay(2100);
    }
    //
    // FINALISATION
    //
    // Return Chopper & grating to default
    // ===================================
    Pacs_DMC_MOVE_GRAT_ABS(500000);
    delay(1);
    PACS_Chop_Move_Abs(0);
    delay(10);
    //
    // SYNC
    //= = =
    sync();
    //
    // End of Script
}

// Missionphase  :  FM-ILT
//
// Purpose       : Perform Setup Spectroscopy
//
// CUS author    : TM, DAC
// Script file   : SPEC_setup.cus
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Calls the following "elementary" scripts:
//                 - SPEC_dpu_dmc_setup
//                 - SPEC_init_det_setup
//                 - SPEC_CRE_setup
//                 - SPEC_dmc_setup
//                 - SPEC_spu_setup
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 0.6
// History       : 0.1 TM 10-nov-2006
//                 0.2 17-nov-2006 DAC&TM Completed script
//                 0.2.1 17-nov-2006 Renamed SPEC_cre_setup to SPEC_CRE_setup
//                                   to spare changes to modules using
//                                   the original SPEC_cre_setup
//                 0.2.1 17-nov-2006 blue_hetear_current as input argument
//                 0.3   18-dec-2006 Exchange red/blue detectors
//                 0.4   19-feb-2007 Exchange red/blue detectors back to nominal
//                 0.5   02-mar-2007 update for FM
//                 0.6  07-Apr-2008 set lower bias values for in flight radiation environment
//                 0.7  27-jul-2009 BV corrected biases SPR 1798
//                 1.0 21-Oct-2010 PACS-3099 VD & HF comment out autonomy function 20 EVENT_DEC_SPC 
block SPEC_setup PACS 100 {
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double temp_CS1 = 48.0;
    double temp_CS2 = 58.0;
    double blu_heater_curr = 0.78; // Nominal current [mA]
}{
    // Register BBID with environment
    WriteBBID($BBID);
    // Start "elementary" scripts
    SPEC_dpu_dmc_setup();
    // Configure initial configuration for CREs
    SPEC_init_det_setup();
    // Default CRE configuration (set default bias, ramp length, and capacitor)
    // Red  ramp length
    int ramp_len_red = 64;
    // Blue ramp length
    int ramp_len_blu = 64;
    // BIAS_D for red spectro  (0-1V)
    double bias_d_red = 0.042;
    // BIAS_R for red spectro  (0-1V)
    double bias_r_red = 0.01;
    // BIAS_D for blue spectro (0-1V)
    double bias_d_blu = 0.1;
    // BIAS_R for blue spectro (0-1V)
    double bias_r_blu = 0.01;
    // Capacitor red  (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_red = 0;
    // Capacitor blue (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_blu = 0;
    SPEC_CRE_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,blu_heater_curr);
    // Configure all used controllers
    int chopper_def = 0;
    SPEC_dmc_setup(fltPOS,chopper_def,temp_CS1,temp_CS2);
    // configure SPU
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    int nb_samp_subramp_blu = 64;
    int nb_samp_subramp_red = 64;
    int nb_raw_spu_blu = 3;
    int nb_raw_spu_red = 3;
    int glitch_det = 1;
    int ramp_fit_alg = 0;
    bool startSPU = false;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Last! Enable autonomy function 5
    Pacs_DPU_SET_FUNCT("COUNTER_SPEC","ENABLE");
    // Last! Enable autonomy function 20
    //    Pacs_DPU_SET_FUNCT("EVENT_DEC_SPC","ENABLE");
    // Mark End of Block
    WriteEndBB();
    sync();
}

// Missionphase  : 
//
// Purpose       : DMC sequence 5 for OBCP 10: Photometry Calibration I
//
//
// DMC author    : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : DMC_phot_cal_I.txt
//
// Arguments used by the calling OBCP                        
// Type  Name               DefVal  Description   : 
// int   nb_main_loop               number of times main loop is repeated
// int   nb_CS1_CS2_cycles          nb cycles alternating CS1-CS2
// int   nb_rdouts_plateau          number of readouts per chopper plateau
// int   chop_pos_CS1               chopper position on CS1
// int   chop_step_CS1_CS2          Step to go from CS1 to CS2
// int   chop_step_CS2_CS1          Step to go from CS2 to CS1
//
// NOTE: For CUS scripts, only the loop parameters are relevant since they 
//       determine the DMC duration
//
// Description :
//       CUS transcription of 4.1.5 "Chopping on Internal Calibration
//       Sources (variable-variable)" Detailed calibration sequence on 
//       the internal sources, version I. Chopping is done to both internal
//       calibration sources (CS1 and CS2) and the positions on each source 
//       may be incremented by a few small steps.
//       Note: nb_rdouts_plateau must be defined such that: 
//              (nb_rdouts_plateau + 1) mod 4 = 0. 
//       Set nb_CS1_CS2_cycles=1 and chop_step_CS2_CS1=chop_step_CS1_CS2
//       to obtain a sequence which just chops CS1-center to CS2-center.
//       This procedure returns its duration in number of readouts
//       It is up to the calling program to convert number of readouts into 
//       [sec] (this procedure does not know the duration of each readout)
//
//       This procedure generates no TC; its only purpose is to illustrate
//       inner works of the DMC sequence and to compute its duration. Hence
//       it is called with only the duration relevant parameters
//
int[] procedure DMC_phot_cal_I {
    int nb_main_loop = 2; // p01 Number of times main loop is repeated
    int nb_rdouts_plateau = 39; // p03 Number readouts/plateau (4*n-1)
    int nb_CS1_CS2_cycles = 8; // p04 Number of cycles alternating CS1-CS2
}{
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Start tallying the duration (measured in number of readouts)
    int duration_rdouts = 0;
    //
    // WAIT 1 ; have a defined start
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; set Label to 0 
    // WAIT 1 ; have a defined start 
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LOOP nb_main_loop ; main loop measurement 
    for(int main_loop = 1 .. nb_main_loop) {
        //  WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //  MOVE_CHOPPER_ABSOLUTE chop_pos_CS1 ; start pos. chopper CS1 
        //  LABEL 65 ; start quadruple on CS1 
        //  WAIT nb_rdouts_plateau ; take nb_rdouts_plateau images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        //  LOOP nb_CS1_CS2_cycles ; do nb_CS1_CS2_cycles steps on BBs 
        for(int inner_loop = 1 .. nb_CS1_CS2_cycles) {
            //  WAIT 1 ; sync. for chopper
            duration_rdouts = duration_rdouts + 1;
            duree_OVR = duree_OVR + 1;
            //  MOVE_CHOPPER_RELATIVE chop_step_CS1_CS2_cycles ; go to CS2 
            //  LABEL 129 ; start quadruple on CS2 
            //  WAIT nb_rdouts_plateau ; take nb_rdouts_plateau images
            duration_rdouts = duration_rdouts + nb_rdouts_plateau;
            duree_CAL = duree_CAL + nb_rdouts_plateau;
            //  WAIT 1 ; sync. for chopper
            duration_rdouts = duration_rdouts + 1;
            duree_OVR = duree_OVR + 1;
            //  MOVE_CHOPPER_RELATIVE chop_step_CS2_CS1 ; go back to CS1 
            //  LABEL 65 ; start quadruple on CS1 
            //  WAIT nb_rdouts_plateau ; take nb_rdouts_plateau images
            duration_rdouts = duration_rdouts + nb_rdouts_plateau;
            duree_CAL = duree_CAL + nb_rdouts_plateau;
        }
        //  END_LOOP ; end of a saw tooth
    }
    // END_LOOP ; end main loop
    // WAIT 1 ; complete last plateau
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; no sequence anymore 
    // END_SEQUENCE
    // Define return array
    int[] time_array = [duration_rdouts,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    debug_print("DMC_phot_cal_I duration [readouts]: " + duration_rdouts);
    // Return the array of times

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Deep staring observations for GeGa ramp linearization
//                  
// Author	 : Helmut Dannerbauer, Jeroen Bouwman, Ulrich Klaas,
//                      Markus Nielbock
// CUS author    : HD, MN
//
// Input arguments 
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Deep staring observations for GeGa Ramp linearization
//		    on astronomical Sources.
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                 
// Comments      : 
// Version	 : 3.2
// History	 : 2.0 11-dec-2008 HD
//		   including PR comments
//                 2.1 02-Feb-2009 MN: included overhead of buffer transmission mode into observing time calculation
//                 3.0 10-Feb-2009 MN: - included detector selection tables
//                                       prepared by J. Bouwman
//                 3.1 08-Jul-2009 MN: - adjusted default detector bias settings
//                                       blue: 42 mV, red: 100mV
//                                     - killed bugs and defused traps
//                 3.2 11-Aug-2009 MN: SPR PHS-1144
//                                     - replaced SPEC_spu_setup by flexible configuration
//                                       Pacs_Spec_spu_flex_setup
//                                     - set # of raw pixels to 0 (btm/llc use DetSelTable
//                                       to select raw ramp pixels)
// 
procedure Pacs_Spec_Star_Lin_Source {
    /* Needed variables to call PacsCal_Spec_Star_Lin_Source */
    string filter_pos = "POS B" in ["POS A","POS B"]; // Filter (A: 3rd order, B: 2nd order)
    int chopposition = 664 in [-21350,+21200]; // Chopper position (opt. zero: 664)
    int[] gratingposition = [335000,535000,730000,794000,900000]; // List of grating positions
    int[] ramp_len = [32,64]; // List of number of readouts per ramp (blue and red)
    string observing_mode = "llc" in ["llc","btm"]; // Lossless compression or buffer transmission
    string detsel_table = "PACSDetSel_10000" in ["PACSDetSel_10000","PACSDetSel_20001","PACSDetSel_20002","PACSDetSel_20003","PACSDetSel_20004","PACSDetSel_20005","PACSDetSel_20006","PACSDetSel_20007","PACSDetSel_20008","PACSDetSel_20009","PACSDetSel_20010","PACSDetSel_20011","PACSDetSel_20012","PACSDetSel_20013","PACSDetSel_20014","PACSDetSel_20015","PACSDetSel_20016","PACSDetSel_20017","PACSDetSel_20018","PACSDetSel_20019","PACSDetSel_20020","PACSDetSel_20021","PACSDetSel_20022","PACSDetSel_20023","PACSDetSel_20024","PACSDetSel_20025"]; // Detector selection table (default: 10000, module of pixel xx: 200xx)
    int ramps = 80; // Number of ramps per observation
    int[] capa_list = [0,8,4,12]; // Blue and red capacitances (0: 0.14pF, 4:0.45pF, 8: 0.24pF, 12:1.15pF) 
    double bias_d_red = 0.042 in [0.02,0.06]; // BIAS_D for red spectro  (0.02-0.06 V, default: 0.042 V)
    double bias_r_red = 0.01 in [0.0,1.0]; // BIAS_R for red spectro  (0-1 V, default: 0.01 V)
    double bias_d_blu = 0.1 in [0.06,0.12]; // BIAS_D for blue spectro (0.06-0.12 V, default: 0.100 V)
    double bias_r_blu = 0.01 in [0.0,1.0]; // BIAS_R for blue spectro (0-1 V, default: 0.01 V)
    int stab_time = 420; // Stabilisation time in seconds for the CRE setup
}{
    // Switch to burst mode
    Burstmode_setup_block();
    // SPU RESET
    SPEC_spu_reset();
    delay(1);
    //
    if(observing_mode == "llc") {
        int obs_mode = 20;
    } else {
        obs_mode = 25;
    }
    // Assume SPU is stopped, load needed
    PACS_Det_Sel(detsel_table);
    // Position the chopper in the center
    // ====================
    PACS_Chop_Move_Abs(chopposition);
    delay(1);
    // Position the filter wheel
    // =========================
    SPEC_fltw_move(filter_pos);
    // delay is contained in the procedure
    //
    // Declare the set of CRE variables
    // ================================
    int ramp_blue = ramp_len[0];
    int ramp_red = ramp_len[0];
    int capacity_blue = capa_list[0];
    int capacity_red = capa_list[0];
    // SetUp SPU
    //==========
    // Compression mode blue channel : to select
    int comp_mode_blu = obs_mode;
    // Compression mode red channel : to select
    int comp_mode_red = obs_mode;
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_blu = 8;
    // Nb of red samples per sub-ramp
    int nb_samp_subramp_red = 8;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_blu = 0;
    // Nb of raw channels transmitted by SPUL
    int nb_raw_spu_red = 0;
    // Glitch detection; 0=on; 1=off
    int glitch_det = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    int ramp_fit_alg = 1;
    // Start SPU or not [true,false]
    bool startSPU = true;
    //
    // determine length of arrays
    //length of grating position
    int gpl = length(gratingposition);
    //length of readoutsperramp
    int rbl = length(ramp_len);
    //length capa_blue
    int cbl = length(capa_list);
    // MAIN LOOP 
    // GRATING LOOP
    int glc = 0;
    while(glc < gpl) {
        Pacs_DMC_MOVE_GRAT_ABS(gratingposition[glc]);
        delay(10);
        // RAMP LENGTH LOOP
        //
        int rlc = 0;
        while(rlc < rbl) {
            ramp_blue = ramp_len[rlc];
            ramp_red = ramp_len[rlc];
            // CAPACITY LOOP 
            //
            int clc = 0;
            while(clc < cbl) {
                capacity_blue = capa_list[clc];
                capacity_red = capa_list[clc];
                //
                // Setup CREs
                SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capacity_blue,capacity_red);
                //
                // Setup SPU
                Pacs_Spec_spu_flex_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
                //
                // if this is the first measurement with this bias -> delay
                if(glc == 0 && rlc == 0 && clc == 0) {
                    delay(stab_time);
                }
                //
                // OBSERVING TIME CALCULATION depending on read-out mode
                int meas_time = ramps / (256 / ramp_len[rlc]);
                if(observing_mode == "llc") {
                    int obs_time = meas_time + 1;
                } else {
                    int nb_buffer_periods = meas_time / 10;
                    obs_time = nb_buffer_periods * (10 + 160) + 1;
                }
                delay(obs_time);
                //
                // SPU RESET
                SPEC_spu_reset();
                delay(1);
                //
                clc = clc + 1;
            }
            rlc = rlc + 1;
        }
        glc = glc + 1;
    }
    // CRE setup to default values
    SPEC_CRE_No_Heater_setup(64,64,bias_d_red,0.011,bias_d_blu,0.011,12,12);
    // SPU RESET
    SPEC_spu_reset();
    delay(1);
    //SPU is stopped, load default DetSel Table
    PACS_Det_Sel("PACSDetSel_10000");
    // Return Chopper & grating to default
    // ===================================
    Pacs_DMC_MOVE_GRAT_ABS(500000);
    delay(1);
    PACS_Chop_Move_Abs(0);
    delay(15);
    // reset burst mode profile
    Burstmode_reset_block();
    // SYNC
    sync();
}

// CVS comments  : $Id:
// Missionphase  : 
// Purpose       : Stop PHOTOmeter observations at end of AOT
//                : and DUMP the buffer
//                  
// TCL author    : 
// TCL file      : 
// CUS author    : Vanessa Doublier_pritchard & Diego Cesarsky
// Script file   : PacsBbPhot_aot_epilogue.txt 
//
// Input arguments
// Type Name           Default   Description
//
// Description   : Not much for now (just STOP SPU)
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      :
//
// History       : 0.1 19-apr-2006 First creation
// 		   1.0 23-sep-2008 SCR 4431 data_rate
// 		   1.1 21-sep-2009 SCR PHS-1181
// 		   
block PacsBbPhot_aot_epilogue PACS 1104 {
}{
    Pacs_DMC_SET_BBID($BBID);
    // Stop the Long and Short SPUs
    int comp_mode_red = 2;
    int comp_mode_blu = 2;
    {int}[] comp_par = [{comp_mode_blu},{comp_mode_red}];
    int[] aux = [comp_mode_blu,comp_mode_red];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_SPU_TRAN_MODE(comp_par,check_sum);
    // to switch to half compression mode
    //    Pacs_DMC_FUNCT_ID 103 RAW
    //    Pacs_DMC_ACTIVITY_ID 156 RAW
    //    Pacs_DMC_STRUCTURE_ID 4 RAW
    //    Pacs_DMC_MEMORY_BLOCK_ID 28 RAW
    //    Pacs_DMC_DATA_LENGTH 2 RAW
    //     Pacs_DMC_4_BYTES_WORDS_DATA 0x2 RAW
    //     Pacs_DMC_4_BYTES_WORDS_DATA 0x2 RAW
    //     Pacs_DMC_CHECKSUM 0x55ff RAW
    delay(2);
    Pacs_SPUS_STOP_REDUCT_COMPR();
    // stop blue SPU
    Pacs_SPUL_STOP_REDUCT_COMPR();
    // stop red SPU
    //     Pacs_DMC_SET_OBSID ; // reset OBSID
    data_rate(0.0);
    // Sync the bus (function duration will get the "true" duration)
    sync();
    // end of procedure
}

// File          : PACS_Spec_CRE_Setup_Warm.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Configure CRE bias, reset interval and capacitor for 
//                 testing at room temperature
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
// Comments      : Intermediate version
//
// 
// Version       : 1.0
// History       : 1.0 / 16-Nov-2004 Initial version
//                 1.1    7-mar-2006 SPEC_HEAT_1_C renamed
// 1.2  6-apr-2006 DMC v6.0.1
// 1.3 27-nov-2006 changed bias_d to 1mV according to LB input
//                 
procedure PACS_Spec_CRE_Setup_Warm {
}{
    //                  
    // red_reset integer 64 Enter red reset interval
    // blue_reset integer 64 Enter blue reset interval
    // red_bias_d integer 287 Enter BIAS_D for red spectrometer (1V=4095)
    // red_bias_r integer 0 Enter BIAS_R for red spectrometer (1V=4095)
    // blue_bias_d integer 860 Enter BIAS_D for blue spectrometer (1V=4095)
    // blue_bias_r integer 0 Enter BIAS_R for blue spectrometer (1V=4095)
    // red_capacitor integer 8 Enter Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
    // blue_capacitor integer 8 Enter Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
    // heater_blue_1c integer 4095 Enter blue HEATER_1C value (0=0mA, 4095=0.2mA)
    // heater_blue_2c integer 0 Enter blue HEATER_2C value (0=0mA, 4095=0.2mA)
    int red_reset = 64;
    int blue_reset = 64;
    int red_bias_d = 4;
    int red_bias_r = 12;
    int blue_bias_d = 4;
    int blue_bias_r = 12;
    int red_capacitor = 0;
    int blue_capacitor = 0;
    int heater_blue_1c = 0;
    int heater_blue_2c = 0;
    // PC174420 "DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    //         Fixed GroupSize: 1, repetition: 8
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // cre_ctrl: 256=sync width=2, 128=T sensor on, 2=select, 1=power on
    int blue_cre_ctrl = blue_capacitor + 256 + 128 + 2 + 1;
    int[] list_int = [32,blue_reset,blue_cre_ctrl,blue_bias_r,blue_bias_d,0];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,blue_reset,blue_cre_ctrl,blue_bias_r,blue_bias_d,0,chksum);
    delay(1);
    // PC173420 "DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    //         Fixed GroupSize: 1, repetition: 8
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // cre_ctrl: 256=sync width=2, 128=T sensor on, 2=select, 1=power on
    // set red_cre_ctrl [expr $red_capacitor+256+128+2+1]
    // set spec_par_r [list {PP095420 32} \
    //         [list PP096420 $red_reset] \
    //         [list PP097420 $red_cre_ctrl] \
    //         [list PP098420 $red_bias_r] \
    //         [list PP099420 $red_bias_d] {PP100420 0}]
    // set chksum [getChkSum -d -32 $spec_par_r]
    // putlog "ChkSum for spec_par_r: $spec_par_r"
    int red_cre_ctrl = red_capacitor + 256 + 128 + 2 + 1;
    list_int = [32,red_reset,red_cre_ctrl,red_bias_r,red_bias_d,0];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,red_reset,red_cre_ctrl,red_bias_r,red_bias_d,0,chksum);
    delay(1);
    // PC094420 "DMC_SET_PAR_BOTH_SPEC" SEND COMPLETE PARAMETERS TABLE TO BOTH DECS
    // tcsend PC094420 
    // waittime 0.5
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    delay(1);
    // PC094420 "DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    //tcsend PC086420 
    //waittime 0.5
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // PC094420 "DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    //tcsend PC093420 
    //waittime 0.5
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    //  DMC_SET_B_SPE_HEAT_1C(0)
    // eval tcsend PC087420 [list [list PP073420 $heater_blue_1c]]
    // waittime 0.5
    Pacs_DMC_SET_B_SPEC_HEAT_C_RAW(heater_blue_1c);
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 07-Jul-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_FlashHeat_Diaghk_Setup {
    /* No variables to call PacsEng_Spec_FlashHeat_Diaghk_Setup                        */
    int diag_hk_period = 100; // 1: synch w/ BLUE DET  2: synch w/ RED DET  >4: period in ms   0: 1KHz (not to use w/ science)
    /* End of needed variables for PacsEng_Spec_FlashHeat_Diaghk_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_FlashHeat_Diaghk_Setup(diag_hk_period)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_FlashHeat_Diaghk_Setup(diag_hk_period);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : EQM IMT
//
// Purpose	: Loops over relative grating movements
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: n_moves	: Number of relative grating movements in the loop
//	  step_size	: Step size for the relative grating movements
//	  time_on_pos	: idle time spent on each grating position
//
// Description	: Loops over relative grating movements
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on
//	    The grating controller is SWON, ENABLED and HOMED
//	    (e.g. SetupSpectroscopyEQMIMT takes care for it)
//
// Comments	:
//
// Version	: 1.0
//               
// History	: 1.0 30-Mar-2004 Creation by PR
//
block SPEC_Gra_move_rel_raw_loop PACS 104 {
    int n_moves = 3; // Number of relative grating movements in the loop
    int step_size = 133; // Step size for the relative grating movements (raw)
    int time_on_pos = 1; // Idle time spent on each grating position (seconds)
}{
    // Register start of BB
    WriteBBID($BBID);
    // Duration of grating step_size (1 degree/second = actually ~5% margin already)
    // clear "grating plateau", also == additional margin
    double inter = abs(double(step_size)) / 23301.0;
    int step_time = iceil(inter) + time_on_pos;
    for(int i = 1 .. n_moves) {
        Pacs_DMC_MOVE_GRAT_REL_RAW(step_size);
        delay(step_time);
    }
    // Mark End of Block
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       :  Close the Grating Launch Lock
//                  
//                 
//
// TCL author    : HF
// TCL file      : 
// CUS author    : HF
// Script file   : LLock_Close.txt 
//
// Input arguments none
// type    name         description
//
// Return values none
// Type    Name      Default      Description
//
// Description   : Calls only CloseLLock
//	You can use the same parameters with both redundant and nominal electronics and command both motors separetely.
// 	Let's name "Motor N" the motor connected to nominal electronics and "Motor R" the motor connected to redundant electronics.
// 	Then the different parameters have the following effects :
//
// 	- When using nominal electronics :
// 	DMC_LOCK_GRAT + 0x12 = Lock Motor N + Motor R
// 	DMC_LOCK_GRAT + 0x2 = Lock Motor N
// 	DMC_LOCK_GRAT + 0x10 = Lock Motor R
// 	DMC_UNLOCK_GRAT + 0x28 = Unlock Motor N + Motor R
// 	DMC_UNLOCK_GRAT + 0x8 = Unlock Motor N
// 	DMC_UNLOCK_GRAT + 0x20 = Unlock Motor R
//
//	- When using redundant electronics :
// 	DMC_LOCK_GRAT + 0x12 = Lock Motor R + Motor N
// 	DMC_LOCK_GRAT + 0x2 = Lock Motor R
// 	DMC_LOCK_GRAT + 0x10 = Lock Motor N
// 	DMC_UNLOCK_GRAT + 0x28 = Unlock Motor R + Motor N
// 	DMC_UNLOCK_GRAT + 0x8 = Unlock Motor R
// 	DMC_UNLOCK_GRAT + 0x20 = Unlock Motor N
//
//                  
// Dependencies  : CloseLLock
//
// Preconditions : PACS must be switched-on and in the equivalent of the SAFE mode
// 
// Version	: 2.0 
// History       : 1.0 30-Mar-2005  creation by HF
//                 1.1 12-Apr-2006 HF, include degraded modes operation
//		   4.0 04-Mar-2008 Translated into PV script VDP
//                 
obs PacsEng_LLock_Close {
    /* Needed variables to call PacsEng_LLock_Close                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_LLock_Close                     */
}{
    int lock_mode = 18;
    // use motors: 2=motor 1, 16 =motor 2, 12 = both motors
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CloseLLock(lock_mode)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CloseLLock(lock_mode);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Burstmode_Reset.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Reset of PACS burst mode
//
// Author        : T.Mueller, H. Feuchtgruber
// CUSification  : DAC
// Arguments     :
//
// Description   :
//               :
// Comments      : Needs manual interactions
//
//
// Version       : 1.0
// History       : 1.0 / 16-Nov-2004 initial version
//                 
procedure PACS_Burstmode_Reset {
}{
    // PC009380 "DPU_SET_BUS_LIST" SWITCH THE DPU FROM NOMINAL TO BURST MODE
    //                             AND VICEVERSA
    //         PP006380 "ENABLE_DISABLE"
    // tcsend PC009380 {PP006380 0}
    // Switch CDMU to Burst profile
    Pacs_DPU_SET_BUS_LIST("DISABLE");
    delay(1);
    debug_print("Switch CDMU to Nominal Bus Profile");
    debug_print("CDMU is switched to nominal profile now");
    //------------------
    // End of procedure
    //------------------
}

// Mission phase : Performance Verification Phase
//
// Purpose : Low Frequency Noise measurement in orbit
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_PVph_lowFreq
//
// Argument :
//   int measure_time = 10800; // Noise measurement time in seconds
//   string filter = "blue70um" in ["blue70um", "green100um"]; // Filter
//   string setting = "DIRECT" in ["DIRECT", "DDCS"]; // Mode
//   string biasTable = "BOLObias_standard_high"; // Bias table
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_telescBack
//
// Dependencies : PCD req.1.1.1bis ILT data for bias computation
//
// Comments : None
//
// Version :
//   2008-07-11 KO, First try
//
obs PacsCal_Phot_PVph_lowFreq {
    int measure_time = 10800; // Noise measurement time in seconds
    string filter = "blue70um" in ["blue70um","green100um"]; // Filter
    string setting = "DIRECT" in ["DIRECT","DDCS"]; // Mode
    string biasTable = "BOLObias_standard_high"; // Bias table
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(biasTable,"DIRECT","LOW"));
    int timeCal3CPR1 = duration(Pacs_OBCP_chopped_photometry2(nLoops1,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false));
    //Minimum slew time
    int tslewmin = timeOBSID + timeSetBias + timeCal3CPR1;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeEndID + timeSetBias + timeCal3CPR5;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_PVph_lowFreq(measure_time,filter,setting,biasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("SLEW/CAL starts at " + tNOW);
            }
            //     Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            // Set biases and start SPU
            PHOT_set_biases(biasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops1,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false);
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW/CAL ends at: " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            //PHOT_set_biases(biasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //      Call the Phot_telescBack
            Phot_PVph_lowFreq(measure_time,filter,setting,biasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(biasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// Missionphase  :  FM-ILT
//
// Purpose       : Perform Setup Spectroscopy with redundant control parameters
//
// CUS author    : BV
//
// Input arguments
// type     name         description
// string   fltPOS         Initial filter wheel position
// double temp_CS1  Calibration source 1 temperature (resistance value)
// double temp_CS2  Calibration source 2 temperature (resistance value)
// double blu_heater_curr  Blue heater current
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform PACS setup for spectroscopy with redundant control parameters
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.1
// 
// History       : 1.0 BV 10-04-2007 Initial version based on SPEC_setup
//                    1.1 HF 20-06-2007 modified default blue heater setting
//
block SPEC_setup_redundant PACS 1100 {
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double temp_CS1 = 48.0;
    double temp_CS2 = 58.0;
    double blu_heater_curr = 0.78; // Nominal current [mA]
}{
    // Register BBID with environment
    WriteBBID($BBID);
    // Start "elementary" scripts
    SPEC_dpu_dmc_setup();
    // Configure initial configuration for CREs
    SPEC_init_det_setup();
    // Default CRE configuration (set default bias, ramp length, and capacitor)
    // Red  ramp length
    int ramp_len_red = 64;
    // Blue ramp length
    int ramp_len_blu = 64;
    // BIAS_D for red spectro  (0-1V)
    double bias_d_red = 0.069;
    // BIAS_R for red spectro  (0-1V)
    double bias_r_red = 0.01;
    // BIAS_D for blue spectro (0-1V)
    double bias_d_blu = 0.198;
    // BIAS_R for blue spectro (0-1V)
    double bias_r_blu = 0.01;
    // Capacitor red  (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_red = 12;
    // Capacitor blue (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_blu = 12;
    SPEC_CRE_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,blu_heater_curr);
    // Configure all used controllers
    int chopper_def = 0;
    SPEC_dmc_setup_redundant(fltPOS,chopper_def,temp_CS1,temp_CS2);
    // configure SPU
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    int nb_samp_subramp_blu = 64;
    int nb_samp_subramp_red = 64;
    int nb_raw_spu_blu = 3;
    int nb_raw_spu_red = 3;
    int glitch_det = 1;
    int ramp_fit_alg = 0;
    bool startSPU = false;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Last! Enable autonomy function 5
    Pacs_DPU_SET_FUNCT("COUNTER_SPEC","ENABLE");
    // Last! Enable autonomy function 20
    Pacs_DPU_SET_FUNCT("EVENT_DEC_SPC","ENABLE");
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose : just to execute Phot_prepareEMC_DDCS
//
// Author : Koryo Okumura / Thomas Mueller
//
// CUS script : procedure Phot_prepareEMC_DDCS_OBS
//
// Argument : None
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + CSs are cold (connected to slowly drifting satellite L1-level)
//
// Description :
//
// Dependencies : None
//
// Comments : 
//
// Version 	: 1.0
// History	: 0.1 Mon Jun 18 2007
// 		: 1.0 translated into PV scipt VDP
//
obs PacsEng_Phot_prepareEMC_DDCS {
    /* Needed variables to call PacsEng_Phot_prepareEMC_DDCS                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_prepareEMC_DDCS                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Phot_prepareEMC_DDCS()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Phot_prepareEMC_DDCS();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_lowGainBias_direct
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//   double ra = 232.436; // RA : 15h29m44.65s
//   double dec = 48.3645; // DEC : 48d21m52.30
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_lowGainBias_direct
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//
// Version : Mon Jun 30 21:44:42 CEST 2008
//
obs PacsCal_Phot_lowGainBias_direct {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
    double ra = 232.436; // RA : 15h29m44.65s
    double dec = 48.3645; // DEC : 48d21m52.30
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    //Minimum slew time
    int tslewmin = 0;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeOBSID;
    //Final hold
    int tfh = timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_lowGainBias_direct(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            //      Set OBSID
            WriteOBSID($OBSID);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //      Call the Phot_lowGainBias_direct
            Phot_lowGainBias_direct(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            //      Write EndID
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_Switchoff {
    /* No variables to call PacsEng_Phot_Switchoff                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_Switchoff                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_Switchoff()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_Switchoff();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : Set values for the BLUE detector heaters
//                  
//                 
//
// Author        : Diego A. Cesarsky
// CUS script    : Diego A. Cesarsky
// CVS file      : 
//
// Arguments     : 
//                 
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 0.1 21-Oct-2004 Creation by DAC
//                     0.2 10-Apr-2006 Modified for FM
// History       : 
//               :
int procedure SPEC_heater {
    double heater_blu = 0.0; //Blue HEATER value (0:0mA, 4095:20mA)
}{
    // Define duration (always in msec]
    int duration_msec = 0;
    // Send the telecommand to DEC/MEC
    Pacs_DMC_SET_B_SPEC_HEAT_C(heater_blu);
    // Convert to [sec], set delay and return  
    int duration_sec = Msec2sec(duration_msec);
    delay(duration_sec);

    return duration_sec;
}

// Purpose       : 
//
// OBCP author   : HF
// TCL file      : N/A
// CUS author    : DAC
// Script file   : OBCP_27_grat_line_scan_chopped_2.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Belongs to Section 3.8: Grating Spectral Line Scan 
//                 of PACS-ME-LI-005
//                 Consists mainly of a sequence with repetitive up- and
//                 down-scans with the grating around a given center position,
//                 while the chopper is operating as well on either two- or
//                 three-positions. This is OBCP 3.8.2, calling DMC sequence
//                 12 (in 4.2.2)
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-apr-2005 DAC
//                 0.2 22-apr-2005 Rearranged arguments P#1 P#2 etc.
//                 0.3 25-apr-2005 DAC Use same defaults as TM's scripts
//                 0.4 27-apr-2005 DAC MIB name is GRAT_SCAN_CHOP2 (not _2)
//                 1.0 26-aug-2005 Renamed to MIB name (but lower case);
//                                 corresponding DMC is also renamed
//                 1.1 28-mar-2007 Add stateMachine as input variable;
//                                 put stateMachine in 4 upper bits of counter
//
int[] block OBCP_grat_scan_chop_2 PACS 29 {
    int nb_up_down = 1; // Nb of "up-down" sequences (P#1); 
    int nb_grat_steps = 100; // Nb of grating steps (P#2)
    int nb_SRC_REF = 1; // Nb of cycles per grating position (P#3); 
    int chop_pos_REF1 = 1000; // Chopper position 1 (P#4) 
    int nb_ramps_plateau = 1; // Nb of readouts per chopper position (P#5); 
    int chop_pos_REF2 = 3000; // Chopper position 2 (P#6)
    int nb_CS1_CS2 = 0; // Nb of cycles on the internal CSs (P#7); 
    int chop_pos_CS1 = -25000; // Chopper position on CS1 (P#8)
    int chop_pos_CS2 = 25000; // Chopper position on CS2 (P#9)
    int grat_step_up = 1600; // Grating step up (P#10) 
    int grat_step_dn = 1600; // Grating step down (P#11) 
    int detector = 2; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 445000; // Starting grating position
    int grat_time = 0; // Grating time to move to start [msec]
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopper default position
    int grat_def_time = 0; // Time to come back to default position
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
    int stateMachine = 0;
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    // Add stateMachine (shifted 8 bits)to BBID
    WriteBBID($BBID + 4096 * stateMachine);
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    //debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    //debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duree_msec [msec] as it goes)
    // Begin 
    // OBCP_GRATING_LINE_SCAN_CHOPPED_2(seq, seq_time,
    //   P#1,&,P#11, detector, grat_def, grat_time,
    //   cmp_par_blue, cmp_par_red, grat_def, chop_def, grat_time)
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_pos) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) ; (all parameters filled 
    // by DPU based on seq parameter) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_time) 
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    // DMC_START_SEQUENCE
    //////////////////////////////////////////////////////////////////////////
    // Call DEC/MEC code to estimate its duration
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    int[] duree1 = DMC_grat_scan_chop2(nb_up_down,nb_grat_steps,nb_ramps_plateau,nb_CS1_CS2,nb_SRC_REF);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    //  debug_print("Execution time [msec] from DMC: " + seq_time);
    // duree_msec(seq_time) 
    duree_msec = duree_msec + t_cmd + seq_time;
    // WAIT(seq_time) ; Check execution status of the sequence and in case of 
    // failure stop OBCP and issue TM(1,8)+event 
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_def_time) 
    duree_msec = duree_msec + grat_def_time;
    duree_OVR = duree_OVR + grat_def_time;
    // Issue TM(1,7)
    // End 
    // Now trigger execution of OBCP
    // This OBCP is number 27, requires 21 parameters and calls DEC/MEC #12
    string obcp_ID = "GRAT_SCAN_CHOP2";
    int obcp_par_nb = 21;
    int seq_DMC = 12;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_grat_steps},{5,nb_SRC_REF},{6,chop_pos_REF1},{7,nb_ramps_plateau},{8,chop_pos_REF2},{9,nb_CS1_CS2},{10,chop_pos_CS1},{11,chop_pos_CS2},{12,grat_step_up},{13,grat_step_dn},{14,detector},{15,grat_pos},{16,grat_time},{17,comp_mode_blu},{18,comp_mode_red},{19,grat_def},{20,chop_def},{21,grat_def_time}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // debug_print(obcp_ID + ": " + time_array);
    delay(time_array[0]);
    // Return the array of times
    //Reset Block ID
    WriteEndBB();
    //Return time_array

    return time_array;
}

// CVS comments  : $Id: PacsSpecConfSet.txt,v 1.2 2007/05/07 13:48:17 dcesarsk Exp $ 
// Missionphase  : PACS ILT
//
// Purpose       : Apply parameters from confSPEC
//                  
// CUS author    : Diego Cesarsky
//
// Input arguments
// Type Name           Default   Description
//
// Description   : CRE: updates bias voltages
//                 SPU: Sets values for compression mode,
//                 threshold values (glitch, chopper, grating), raw 
//                 channel transmission, sub-ramp and detector
//                 constants, load DPU time and restart SPU. Script
//                 sets its own delays [sec] and returns the total
//                 duration in milliseconds. This version addresses
//                 BLU or RED (except for comp_mode write to DMC)
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      : Based on SPEC_spu_setup and SPEC_cre_setup CUS scripts
//
// History       : 0.1 31-May-2005 First creation
// 0.2 10-apr-2006 Adapted for SPU V12.1
// 1.0  2-may-2007 Renamed to PacsSpecConfSet to follow naming convention
//
int procedure PacsSpecConfSet {
    string color = "BLU" in ["BLU","RED"];
    {int,int,int,int,int,int,int,int,int} confSPEC = {0,0,0,0,0,0,0,0,0}; // SPEC parameters
}{
    // Expand elements of confSPEC
    int capa = confSPEC{0};
    int nb_rdouts_ramp = confSPEC{1};
    int nb_rdouts_subramp = confSPEC{2};
    int comp_mode = confSPEC{3};
    int glitch_det = confSPEC{4};
    int ramp_fit_alg = confSPEC{5};
    int nb_raw = confSPEC{6};
    int bias_r_mV = confSPEC{7};
    int bias_d_mV = confSPEC{8};
    // Duration (accumulated time expressed in milliseconds)
    int duration_msec = 0;
    // Stop the "color" SPUs
    if(color == "BLU") {
        Pacs_SPUS_STOP_REDUCT_COMPR();
    } else {
        Pacs_SPUL_STOP_REDUCT_COMPR();
    }
    // Set the CRE
    int cre_ctrl = 386;
    cre_ctrl = cre_ctrl + capa;
    // Convert bias from mV to volts
    double bias_r = double(bias_r_mV) / 1000.0;
    double bias_d = double(bias_d_mV) / 1000.0;
    // Bias values are given in ENG units. Have to convert to RAW in
    // order to compute check-sums
    int i_bias_r = convert_to_raw("pacs_DMC_BIAS_R",bias_r);
    int i_bias_d = convert_to_raw("pacs_DMC_BIAS_D",bias_d);
    int[] aux = [32,nb_rdouts_ramp,cre_ctrl,i_bias_r,i_bias_d,0];
    int check_sum = checksum("int",aux);
    if(color == "BLU") {
        Pacs_DMC_WRT_B_SPEC_PAR(32,nb_rdouts_ramp,cre_ctrl,bias_r,bias_d,0,check_sum);
    } else {
        Pacs_DMC_WRT_R_SPEC_PAR(32,nb_rdouts_ramp,cre_ctrl,bias_r,bias_d,0,check_sum);
    }
    // Send the parameters to both receivers
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    // Set the SPU compression modes; identical for both SPUs
    {int}[] comp_par = [{comp_mode},{comp_mode}];
    aux = [comp_mode,comp_mode];
    check_sum = checksum("int",aux);
    // Issue the TC to DEC/MEC
    Pacs_DMC_WRT_SPU_TRAN_MODE(comp_par,check_sum);
    // Setting of start index of raw channels for SPUS and SPUL
    string spu_obs_mode = "SPEC";
    int spu_startraw = 1;
    // Sub-ramp and detector const. setting to SPU
    // No preprocessing
    int ppf = 0;
    int ppp = 0;
    // Threshold for glitch
    int tfs = 1000;
    // Threshold for chopper
    int tcs = 100;
    // Threshold for grating
    int tgd = 100;
    // Reordering algorithm 0=no reordering on 1= 2=reorder 3= 4=resort
    int reor = 4;
    // Lossless compression algorithm for spec 0=pacs_codec 1=Rzip+ pacs_codec
    // 2=RZIp only 3= arithmetic coder
    int llcs = 0;
    // Range for the pacs codec 3= low CPU low compression, 4= high CPU and
    // high compression
    int ords = 4;
    // Write detector constants for blue spectrometer array
    {int}[] spu_par = [{ppf},{ppp},{tfs},{tcs},{tgd},{nb_rdouts_subramp},{glitch_det},{ramp_fit_alg},{reor},{llcs},{ords},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}];
    aux = [ppf,ppp,tfs,tcs,tgd,nb_rdouts_subramp,glitch_det,ramp_fit_alg,reor,llcs,ords,0,0,0,0,0,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Send TC to proper SPU
    if(color == "BLU") {
        Pacs_SPUS_RAW_CHAN_TRAN_MODE(spu_obs_mode,nb_raw,spu_startraw);
        Pacs_SPUS_WRT_DET_CST_SPEC(spu_par,check_sum);
        Pacs_SPUS_START_REDUCT_COMPR();
    } else {
        Pacs_SPUL_RAW_CHAN_TRAN_MODE(spu_obs_mode,nb_raw,spu_startraw);
        Pacs_SPUL_WRT_DET_CST_SPEC(spu_par,check_sum);
        Pacs_SPUL_START_REDUCT_COMPR();
    }
    // Set delay [sec]
    int duration_sec = Msec2sec(duration_msec);
    delay(duration_sec);
    // That's it. Return duration [msec]

    return duration_msec;
}

// Missionphase  : FM ILT
//
// Purpose	:  Performance Test of internal PACS calibration sources
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description  : We start with a heat-up of the calibration sources. 
//                After monitoring for some while the behaviour on the desired temperature of
//                both internal PACS calibration sources, we do a smaller heat-up which is followed 
//                by a cooling down. The monitoring is based on diag. HK. 
//                PTD 0.7.11 and 0.7.12 are the basis for this test. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy 
//                 
// Comments	: This script is based on the commanding during the CQM ILT Tests. 
//
// Version	: 1.0	
// 
// History      : 
//		  1.0 09-11-06 HD. Adapted on FM ILT requirements.
block SPEC_CS_fmilt071112_swon_cs_perf_bb PACS 396 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //Switchon and enabling CSs
    Pacs_DMC_SWON_BB_1_CONT();
    Pacs_DMC_ENABLE_BB_1_CONT();
    Pacs_DMC_SWON_BB_2_CONT();
    Pacs_DMC_ENABLE_BB_2_CONT();
    //------------------------------------------------------------------------------
    // Heat the calibration sources up to 70 (XX.XK;CS1) and 80 
    // (70.5K;CS2) Ohm --- big step
    //------------------------------------------------------------------------------
    // start temperature CS1 in Ohm
    double cs1_temp = 70.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // start temperature CS2 in Ohm 	
    double cs2_temp = 80.0;
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    //After 60 minutes of heating-up and stay on the desired temperatures do another heat-up 
    delay(3600);
    // Assume that CSs are on since long and already stabilized, monitor them for 20 minutes only
    delay(1200);
    //--------------------------------------------------------------------------------
    // Heat the calibration sources up to 85 (72.8K;CS1) and 97 (78.4K;CS2) Ohm --- small step
    //--------------------------------------------------------------------------------
    cs1_temp = 85.0;
    cs2_temp = 97.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    //After 60 minutes of heating-up and stay on the desired temperatures do cooling-down
    delay(3600);
    //------------------------------------------
    // Cool both calibration sources down to 10 (X.XXK) 
    //------------------------------------------
    cs1_temp = 10.0;
    cs2_temp = 10.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    // Cool down for about 60 seconds
    delay(60);
    // Mark End of Block
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS Commissiong Phase
//
//
//
//
// Purpose      : Ge:Ga detector Loop
//
// Author       : Pierre Royer
// CUS script   : PR
// CVS file     :
//
// Arguments    : bias, integration time, capacity, measurement time, resistor bias
//
//
// Description  : Loop over bias, integration time and capacity.
//
// Dependencies :  - Pacs_Spec_GeGa_Loop_Comm 
//		   - WriteOBSID
//		   - WriteEndID
//
//
// Preconditions : - PACS is switched on
//                 - Setup spectroscopy
//		   - Mechanics and CS controllers are SWON and ENABLED
//
// Comments     : 
//
// Version      : 1.0
//
// History      : 1.0 04-Jul-2008 PR
//
obs PacsEng_Spec_Curing_Concept_Loop {
    /* Needed variables to call Pacs_Spec_Curing_Concept_Loop                        */
    int repeat_intern = 10; // Repetition factor inside the bias loop (ramplen+capa loops)
    double[] bias_blue = [0.08,0.1,0.125,0.15,0.175,0.2]; //bias blue
    double[] bias_red = [0.02,0.03,0.04,0.05,0.06,0.07]; //bias red red
    int[] ramp_len_blue = [32,64]; //ramp length blue (set integration time)
    int[] ramp_len_red = [32,64]; //ramp length red (set integration time)
    int[] capa_blue = [8,12]; //capacity blue
    int[] capa_red = [8,12]; //capacity red
    int meas_time = 60; //observing time in seconds per setting
    double bias_res_blue = 0.0101; //resistor bias blue
    double bias_res_red = 0.0101; //resistor bias red
    int chop_pos = 21200; // chopper position
    int grat_pos = 535000; // grating position
    string filter_pos = "POS A" in ["POS A","POS B"]; // FW position
    int blue_flasher_current = 819 in [0,820]; //4mA. [0,4095] = [0,20 mA]
    int red_flasher_current = 819 in [0,820]; //4mA. [0,4095] = [0,20 mA]
    int nflash = 1; // Number of flashes
    int flash_time = 60; // Duration of each flash
    int interflash_time = 30; // Idle time between the flashes
    /* End of needed variables for PacsEng_Spec_Curing_Concept_Loop                */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Curing_Concept_Loop(repeat_intern,bias_blue,bias_red,ramp_len_blue,ramp_len_red,capa_blue,capa_red,meas_time,bias_res_blue,bias_res_red,chop_pos,grat_pos,filter_pos,blue_flasher_current,red_flasher_current,nflash,flash_time,interflash_time)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic.
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Curing_Concept_Loop(repeat_intern,bias_blue,bias_red,ramp_len_blue,ramp_len_red,capa_blue,capa_red,meas_time,bias_res_blue,bias_res_red,chop_pos,grat_pos,filter_pos,blue_flasher_current,red_flasher_current,nflash,flash_time,interflash_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Script	 : PACS_Chopper_uk_move_12000_ast_OBS.cus
//
// Missionphase  : IST Chopper Day
//
// Purpose	: Move chopper to absolute position  
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-12000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched on and Chopper switched on.
//                 
// Comments	: This script is based on the commanding during the CQM/FM ILT.
//
// Version	: 4.0	
// 
// History 	: 1.0 02-03-07 HD. Script to do simple chopper cycle 
//
//		  2.0 05-07-07 HD. IST Chopper Day
//		  3.0 05-07-07 MN. edited for SVT/PV conformance
//		  4.0 05-03-2008 translated in PV phase script VDP
obs PacsEng_Chopper_uk_move_12000_ast {
    /* Needed variables to call PacsEng_Chopper_uk_move_12000_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Chopper_uk_move_12000_ast                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Chopper_uk_move_12000_NoConf_ast()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Chopper_uk_move_12000_NoConf_ast();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// copy of SPEC_CRE_No_Heater_setup, adapted for the curing -> allowing for an extra parameter being the 'curing mode'
//
// History : 1.0 25-09-2008 PR
//              1.1 27-07-2009 BV SPR 1798 corrected biases
procedure SPEC_CRE_Curing_setup {
    int ramp_len_red = 64; // Red  ramp length
    int ramp_len_blu = 64; // Blue ramp length
    double bias_d_red = 0.042 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_red = 0.01 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.1 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_r_blu = 0.01 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    int capa_red = 0; // Capacitor red  (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_blu = 0; // Capacitor blue (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int curing_mode = 0 in [0,1]; // Bit 4 of the CRE register : 0 for not in curing mode, 1 for curing mode (CREs in reset mode, while bias on).
}{
    int curing_ctrl = 0;
    if(curing_mode == 1) {
        curing_ctrl = 16;
    } else {
        curing_ctrl = 0;
    }
    // Red  CRE register (capa_red=0)
    int cre_ctrl_red = 386;
    // Blue CRE register (capa_blu=0)
    int cre_ctrl_blu = 386;
    // Blue CRE register (capa_blu=0)
    // Write the blue spectrometer parameters
    int blu_cre_ctrl = capa_blu + cre_ctrl_blu + curing_ctrl;
    // Bias values have been given in ENG units. Have to convert to RAW in
    // order to compute check-sums
    int i_blu_bias_r = convert_to_raw("pacs_DMC_BIAS_R",bias_r_blu);
    int i_blu_bias_d = convert_to_raw("pacs_DMC_BIAS_D",bias_d_blu);
    int clks_rdout = 32;
    int simul_reg = 60000;
    int[] aux = [clks_rdout,ramp_len_blu,blu_cre_ctrl,i_blu_bias_r,i_blu_bias_d,simul_reg];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_B_SPEC_PAR(clks_rdout,ramp_len_blu,blu_cre_ctrl,bias_r_blu,bias_d_blu,simul_reg,check_sum);
    // Same for RED parameters
    int red_cre_ctrl = capa_red + cre_ctrl_red + curing_ctrl;
    int i_bias_r_red = convert_to_raw("pacs_DMC_BIAS_R",bias_r_red);
    int i_bias_d_red = convert_to_raw("pacs_DMC_BIAS_D",bias_d_red);
    aux = [clks_rdout,ramp_len_red,red_cre_ctrl,i_bias_r_red,i_bias_d_red,simul_reg];
    check_sum = checksum("int",aux);
    Pacs_DMC_WRT_R_SPEC_PAR(clks_rdout,ramp_len_red,red_cre_ctrl,bias_r_red,bias_d_red,simul_reg,check_sum);
    // Send complete parameters table to both DECS
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    // Switchon and set blue detector heater
    // Pacs_DMC_SWON_BD_HEATER();
    // Pacs_DMC_SET_B_SPEC_HEAT_C(blue_heat_current);
    // DMC_SYNCHRONIZE_ON_DET(1)
    Pacs_DMC_SYNCHRONIZE_ON_DET(1);
    // DMC_WRT_B_DEC_REC_OPT" WRITE THE BLUE DEC RECEIVER OPTIONS
    {int}[] argTuple = [{0}];
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,0x84c0);
    // DMC_WRT_R_DEC_REC_OPT" WRITE THE RED DEC RECEIVER OPTIONS
    argTuple = [{0}];
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,0x84c0);
    // DMC_VAL_SCI_DATA_BOTH" VALIDATE SCIENCE DATA FROM BOTH CHANNELS
    Pacs_DMC_VAL_SCI_DATA_BOTH();
}

// Mission phase : Commissioning Phase or later
//
// Purpose : PCD req.1.1.9 Measure time constants after cosmic ray impact
//
// Author : Koryo Okumura
//
// Version : May 27 2009
//
// CUS script : procedure Phot_VrlGlitch
//
// Argument :
//   string biasTable = "BOLObias_standard_high" : Bias table file name containing the initial values
//   string gain = "HIGH" in ["LOW","HIGH"] : gain used during the measurements
//   int mesureTime = 1200 : Measurement duration in seconds
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description :
//   + All the biases are set group by group
//   + Set the direct mode
//   + Data acquisition in buffer transmission mode and in burst mode
//
// Dependencies : None
//
// Comments : None
// Update :
//   2009-05-27 : Modified from Phot_glitch
//   2009-06-17 : PHOT_change_biases replaced by PHOT_set_biases
//
procedure Phot_VrlGlitch {
    string biasTable = "BOLObias_standard_high"; // Bias table file name containing the initial values
    string gain = "HIGH" in ["LOW","HIGH"]; // gain used during the measurements
    int measureTime = 1200; // Measurement duration in seconds
}{
    //*******************************
    // Bias setting of the detectors
    //*******************************
    //
    PHOT_change_biases(biasTable,"NO_CHANGE",gain);
    //
    //************
    // Set on VRL
    //************
    // Set all groups bol bias 09 (CKRLH) to 2.0 volts
    Pacs_BOLC_SET_CKRLH_ALL(2.0);
    // Set all groups bol bias 10 (CKRLL) to 2.0 volts
    Pacs_BOLC_SET_CKRLL_ALL(2.0);
    // Set all groups bol bias 12 (VDECX-L) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc0000);
    // Set all groups bol bias 11 (VDECX-H) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0xb0000);
    //
    //***************************
    // Sequence mode : Sb_only
    //***************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    // Set seq mode Sb_only (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sb_only");
    //# P 09 01 00 02
    int operand = 0x9010002;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //
    //************************
    // Set DPU for Burst mode
    //************************
    Pacs_DPU_SET_BUS_LIST("ENABLE");
    //
    // Set SPU to the buffer transmission mode
    PHOT_spu_setup(9,9,0,0,true);
    TMMarker601();
    delay(measureTime);
    TMMarker600();
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*********************************
    // Bias resetting of the detectors
    //*********************************
    //
    PHOT_set_biases(biasTable,"DIRECT",gain);
    //
    //************************
    // Set DPU for Burst mode
    //************************
    Pacs_DPU_SET_BUS_LIST("DISABLE");
    //
    // Sychronize
    //
    sync();
}

procedure Spr {
    string whatIS = "1.2micron" in ["1.2micron","1.4","your.guess"];
}{
    if(whatIS == "1.2micron") {
        message("WhatIS: " + whatIS);
    }
    if(whatIS == "1.4") {
        message("WhatIS: " + whatIS);
    }
    if(whatIS == "your.guess") {
        message("WhatIS: " + whatIS);
    }
    message("WhatIS: " + whatIS);
}

// CVS comments  : $Id: 
// Purpose       : Invoke a PACS calibration OBCP during slew to source
// 		   using ABBA chopper scheme;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsSpecSlewCal_override.txt 
//
// Input arguments
// Type                     Name          Description
// bool                     verbose       Debug_print or not 
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECblu   BLUE SPU parameters
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECred   RED  SPU parameters
// {int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int}[]  confOBCP      OBCP parameters
//  bool                    doPROLOG      Perform/don't AOT prologue
//  double []               keyWAVE       One or several key wavelengths
//  int                     filter        Where to move FltW (as order)
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per key line
//
// Description   : Perform AOT prologue and then OBCP #35.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 0.1 DAC 10-may-2006 
// 		 : 1.0 13-mar-2009 VD OBCP35
//                 1.1  3-jun-2009 DAC Original PacsPacsSpecSlewCal35 from
//                                 VD renamed PacsSpecSlewCal
//                 1.2 18-jun-2009 DAC Enter into OBCP35params with K-orders
//                                 to schedule KeyWave calibrations
//                 1.3 20-jul-2009 VD introduces the faintLines (extraConf == bright for calU CAL block
//                 2.0 introduce override cal_block
//                 2.1 03-aug-2009 VD introduce debug PHS-1133
//                                 
//
int[][] procedure PacsSpecSlewCal_override {
    /* verbose debug print                          */
    bool verbose = false;
    /* SPEC parameters for BLU and RED              */
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,64,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,64,0,0,0,0,0,0,0}];
    /* OBCP parameters                               */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* Perform/don't AOT prologue                    */
    bool doPROLOG = true;
    /* One or several key wavelengths                */
    double[] keyWAVE = [62.5];
    /* Where to leave FltW (as order)                */
    int filter = 2;
    /* Where to leave grating at end of CAL          */
    int frstLstGratPos = 535000;
    /* User defined grating order                    */
    string orderSel = "order3";
    bool overrideCalBlockOBCP35params = false;
}{
    // Debug only
    if(verbose) {
        debug_print("PacsSpecSlew called with:");
        debug_print("confSPECblu: " + confSPECblu[0]);
        debug_print("confOBCP: " + confOBCP[0]);
        debug_print("doPROLOG: " + doPROLOG);
        debug_print("keyWAVE: " + keyWAVE);
        debug_print("filter: " + filter);
        debug_print("frstLstGrat: " + frstLstGratPos);
        debug_print("orderSel: " + orderSel);
    }
    // Array to collect OBCP times per line
    // NOTE: time variables in units of either number of ramps (SPEC) or
    // number of readouts (BOLO) or plain seconds. The calling program 
    // must convert, if applicable, this information into actual duration 
    // in true time units [seconds].
    // SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky), CAL source, 
    // and overheads (wait for something). Total duration is given by duree_num. 
    // If no error, this duration must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    int[][] dureeCalKey = [[0,0,0,0,0]];
    // Long sequence to "unpack" default values from tuples
    int capa_blu = confSPECblu[0]{0};
    int nb_rdouts_ramp_blu = confSPECblu[0]{1};
    int nb_rdouts_subramp_blu = confSPECblu[0]{2};
    int comp_mode_blu = confSPECblu[0]{3};
    int glitch_det_blu = confSPECblu[0]{4};
    int ramp_fit_alg_blu = confSPECblu[0]{5};
    int nb_raw_blu = confSPECblu[0]{6};
    int bias_r_blu_mV = confSPECblu[0]{7};
    int bias_d_blu_mV = confSPECblu[0]{8};
    int capa_red = confSPECred[0]{0};
    int nb_rdouts_ramp_red = confSPECred[0]{1};
    int nb_rdouts_subramp_red = confSPECred[0]{2};
    int comp_mode_red = confSPECred[0]{3};
    int glitch_det_red = confSPECred[0]{4};
    int ramp_fit_alg_red = confSPECred[0]{5};
    int nb_raw_red = confSPECred[0]{6};
    int bias_r_red_mV = confSPECred[0]{7};
    int bias_d_red_mV = confSPECred[0]{8};
    int nb_up_down = confOBCP[0]{0};
    int grat_step_up = confOBCP[0]{1};
    int grat_step_dn = confOBCP[0]{2};
    int nb_SRC_OFF = confOBCP[0]{3};
    int nb_ramps_plateau = confOBCP[0]{4};
    int nb_CS1_CS2 = confOBCP[0]{5};
    int nb_grat_step_up = confOBCP[0]{6};
    int nb_grat_step_dn = confOBCP[0]{7};
    int grat_start_pos = confOBCP[0]{8};
    int grat_start_time = confOBCP[0]{9};
    int grat_def_pos = confOBCP[0]{10};
    int grat_def_time = confOBCP[0]{11};
    int chop_pos_SRC = confOBCP[0]{12};
    int chop_pos_REF1 = confOBCP[0]{13};
    int chop_pos_REF2 = confOBCP[0]{14};
    int chop_pos_CS1 = confOBCP[0]{15};
    int chop_pos_CS2 = confOBCP[0]{16};
    int chop_def = confOBCP[0]{17};
    int detector = confOBCP[0]{18};
    int filterPOS = confOBCP[0]{19};
    // Bias voltages (needed by SPEC_aot_prologue) are commanded in (double) volts
    double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
    double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
    double bias_r_red = double(bias_r_red_mV) / 1000.0;
    double bias_d_red = double(bias_d_red_mV) / 1000.0;
    if(verbose) {
        debug_print("confSPEC: capa_blu: " + capa_blu);
        debug_print("confSPEC: nb_rdouts_ramp_blu: " + nb_rdouts_ramp_blu);
        debug_print("confSPEC: nb_rdouts_subramp_blu: " + nb_rdouts_subramp_blu);
        debug_print("confSPEC: comp_mode_blu: " + comp_mode_blu);
        debug_print("confSPEC: glitch_det_blu: " + glitch_det_blu);
        debug_print("confSPEC: ramp_fit_alg_blu: " + ramp_fit_alg_blu);
        debug_print("confSPEC: nb_raw_blu: " + nb_raw_blu);
        debug_print("confSPEC: bias_r_blu_mV: " + bias_r_blu_mV);
        debug_print("confSPEC: bias_d_blu_mV: " + bias_d_blu_mV);
    }
    // Issue SPEC_aot_prologue if demanded
    if(doPROLOG) {
        totalDUREE = SPEC_aot_prologue(nb_rdouts_ramp_red,nb_rdouts_ramp_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,comp_mode_blu,comp_mode_red,nb_rdouts_subramp_blu,nb_rdouts_subramp_red,nb_raw_blu,nb_raw_red,glitch_det_red,ramp_fit_alg_red,filter,verbose);
    }
    // NOTE: Grating starts at grat_start_pos determined by SPEC_get_grat. At end of
    // SlewCal grating should park. Park position is generally grat_def_pos:
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // AOT_prologue is supposed to have left grating at park position
    grat_def_pos = grat_park;
    // NOTE for version 1.0 and later. Upon execution of SpecSlew, grating is
    //      indeed where SPEC_orbit_prologue left it (the default park position);
    //      this fact remains unchanged. What is new is that SpecSlew will leave
    //      the grating not at the default park position but already at the
    //      position needed by the 1st line that will be observed. There are two
    //      advantages:
    //      1- the new logic in the OBCP incurs in less grating movements when
    //         the OBCP is repeated within a NOD or the next raster point, and
    //      2- the detector will see the illumination corresponding to the line
    //         wavelength before the actual observation starts.
    // Observe now each key wavelength
    int nbKEY = length(keyWAVE);
    {double,int,int,int,int}[] gratTuple = [{0.0,0,0,0,0}];
    for(int loopKEY = 0 .. nbKEY - 1) {
        //     We may perform the loop starting with high ORDER
        int keyWaveLoop1 = nbKEY - 1 - loopKEY;
        // or not....
        keyWaveLoop1 = loopKEY;
        //       
        //     Get grating start position (CAL is performeed with HI resolution)
        //     (frequency switch boolean is set to false)
        bool switching = false;
        // dirty trick to get extraConf bright or normal back!!!
        if(nb_rdouts_ramp_blu != 64) {
            string extraConf = "bright";
        } else {
            extraConf = "normal";
        }
        //        string extraConf = "normal";
        //      Seek K rows in CAL-U, i.e. key wavelength parameters	
        gratTuple[keyWaveLoop1] = SPEC_get_grat_info(keyWAVE[keyWaveLoop1],"KHI",switching,extraConf,orderSel,verbose);
        //      Issue now OBCP#35 for each of the given key wavelengths
        int order = gratTuple[keyWaveLoop1]{1};
        grat_start_pos = gratTuple[keyWaveLoop1]{2};
        if(!overrideCalBlockOBCP35params) {
            debug_print("Using calU file values");
            int nb_grat_steps = gratTuple[keyWaveLoop1]{3};
            nb_grat_step_up = nb_grat_steps;
            nb_grat_step_dn = nb_grat_steps;
            int grat_step_up_fine = gratTuple[keyWaveLoop1]{4};
            int grat_step_dn_fine = -grat_step_up_fine;
            //
        } else {
            grat_step_up_fine = grat_step_up;
            grat_step_dn_fine = grat_step_dn;
        }
        // Read K-lines of table OBCP35params
        // add B if bright mode
        if(extraConf == "bright") {
            string key = "BK" + order;
        } else {
            key = "K" + order;
        }
        if(verbose) {
            debug_print("PacsSlewCal: key " + key);
        }
        string calU = "OBCP35params";
        if(!overrideCalBlockOBCP35params) {
            debug_print("Using calU file values");
            nb_up_down = ilookup(calU,key,"nb_up_down");
            nb_CS1_CS2 = ilookup(calU,key,"nb_CS1_CS2");
            // SRC_OFF == 0;
            nb_SRC_OFF = 0;
            nb_ramps_plateau = ilookup(calU,key,"nb_ramps_plateau");
        }
        int chop_pos_OFF = chop_pos_REF2;
        int grat_step_coarse = 0;
        //      Lookup chopper CS1 and CS2 positions
        calU = "CHOPPERCSparams";
        chop_pos_CS1 = ilookup(calU,"SPEC","pos_CS1");
        chop_pos_CS2 = ilookup(calU,"SPEC","pos_CS2");
        int nb_rdouts_ramp = nb_rdouts_ramp_red;
        //     Grating logic (OBCP is up/down ==> grating ends where it started)
        //     Leave the grating where it is, i.e. end-of-DMC value
        int new_grat_def_pos = grat_start_pos;
        //     But the last line should leave grating at frstLstGratPos
        if(keyWaveLoop1 == nbKEY - 1) {
            new_grat_def_pos = frstLstGratPos;
        }
        //     Number of steps to start position for current line
        int steps_start = grat_def_pos - grat_start_pos;
        int grat_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("OBCPcal:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + ";  time: " + grat_time);
        }
        //
        int steps_end = grat_start_pos - new_grat_def_pos;
        grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("OBCPcal:GratEnd from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
        }
        int[] dureeOBCP = OBCP_grat_line_scan_chop_3_cal(nb_up_down,nb_grat_step_up,grat_step_up_fine,nb_SRC_OFF,chop_pos_SRC,nb_ramps_plateau,chop_pos_OFF,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_dn_fine,detector,grat_start_pos,grat_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
        if(verbose) {
            debug_print("SlewCal performed KeyWave: " + keyWAVE[keyWaveLoop1] + " [mic] requires " + dureeOBCP[0] + " [sec]");
        }
        //     Update dureeCalKey
        dureeCalKey[keyWaveLoop1] = [0,0,0,0,0];
        for(int loop1 = 0 .. 4) {
            dureeCalKey[keyWaveLoop1][loop1] = dureeOBCP[loop1];
        }
        //     Prepare the grating to be ready for the next wavelength
        grat_def_pos = new_grat_def_pos;
    }
    // Add after the KeyWaves in dureeCalKey the duration from AOT_prologue
    dureeCalKey[nbKEY] = [0,0,0,0,0];
    dureeCalKey[nbKEY][4] = totalDUREE[4];
    if(verbose) {
        debug_print("End SlewCal with dureeCalKey: " + dureeCalKey);
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return dureeCalKey;
}

// CVS file      : DMC_chop_scan_spec.txt
// Missionphase  :
//
// Purpose       : Chop increasingly away from start position; then increasingly
//                 closer to start position. Whole operation may be repeated
//                 nb_up_down times
//
// Author        : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
//
// Arguments     : (only timing parameters are used in actual call)
//  int nb_up_down  P#1  number of up-down seqs.
//  int nb_ramps   P#2  number of readouts on step
//  int nb_steps_up P#3  number of steps up
//  int nb_steps_dn P#4  number of steps down
//  int step_up     P#5  relative move up 
//  int step_dn     P#6  relative move down 
//
// Description : Chop increasing distance from start, then revert
//               and chop closer and closer to initial position
//
// Dependencies  : Stand alone DEC/MEC sequence
//
// Comments      : Follows line by line 4.2.9 in PACS-ME-LI-005
//                 Tally all readouts as REF
//
// Version       : 0.1  6-apr-2006 Creation by DAC
// History       : 
int[] procedure DMC_chop_scan_spec {
    int nb_up_dn = 1; // P#1  number of up-down seqs.
    int nb_ramps = 1; // P#2  number of ramps on step
    int nb_steps_up = 1; // P#3  number of steps up
    int nb_steps_dn = 1; // P#4  number of steps down
}{
    // Time keeping variables [readouts]
    int duree_ramps = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Parameterized up and down scan with the PACS chopper.
    // WAIT 1 ; have a defined start
    duree_ramps = duree_ramps + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; ensure LABEL 0
    // WAIT 1
    duree_ramps = duree_ramps + 1;
    duree_OVR = duree_OVR + 1;
    // LOOP P#1 ; number of up-down seqs.
    for(int loop1 = 1 .. nb_up_dn) {
        //    LABEL 193 ; special LABEL up
        //    LOOP P#3 ; number of steps up
        for(int loop3 = 1 .. nb_steps_up) {
            //       WAIT P#2 ; number of readouts on step
            duree_ramps = duree_ramps + nb_ramps;
            duree_SRC = duree_SRC + nb_ramps;
            //       MOVE_CHOPPER_RELATIVE P#5 ; relative move up
        }
        //    END_LOOP
        //    LOOP P#4 ; number of steps down
        for(int loop4 = 1 .. nb_steps_dn) {
            //       WAIT P#2 ; number of readouts on step
            duree_ramps = duree_ramps + nb_ramps;
            duree_SRC = duree_SRC + nb_ramps;
            //       MOVE_CHOPPER_RELATIVE P#6 ; relative move down
            //       LABEL 225 ; special LABEL down
        }
        //    END_LOOP
    }
    // END_LOOP
    // WAIT P#2 ; integrate on last step
    duree_ramps = duree_ramps + nb_ramps;
    duree_SRC = duree_SRC + nb_ramps;
    // WAIT 1
    duree_ramps = duree_ramps + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0
    // END_SEQUENCE
    // Return durations
    // Expected duration
    int duree_theor = 3 + nb_up_dn * (nb_steps_up * nb_ramps + nb_steps_dn * nb_ramps) + nb_ramps;
    debug_print("DMC_chop_scan_spec: " + duree_theor);

    return [duree_ramps,duree_SRC,duree_REF,duree_CAL,duree_OVR];
}

// Missionphase  : 
//
// Purpose       : Two or three position chopping followed by calibration
//         readouts chopping between CS1 and CS2 
//   
// DMC author    : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : DMC_spec_2_3_chop.txt 
//
// Arguments used by the calling OBCP                        
// 
// Type  Name               DefVal  Description   : 
// int   nb_up_down                 number of up-down sequences
// int   nb_grat_steps              number of grating steps
// int   nb_SRC_OFF                 nb cycles on/off source per grating positn
// int   chop_pos_REF1:             chopper position 1
// int   nb_ramps_plateau           number of ramps per chopper plateau
// int   chop_pos_REF2              chopper position 2 
// int   chop_pos_REF3              chopper position 3 
// int   nb_CS1_CS2                 number of cycles on the calibration sources
//                          per grating positn
// int   chop_pos_CS1               chopper position on CS1
// int   chop_pos_CS2               chopper position on CS2
// int   grat_step_up               step size of relative grating move up 
// int   grat_step_dn               step size of relative grating move down 
//
// Description :
//   Default sequence for spectral line observations. The 
//   chopping pattern is identical to the analogous photometry 
//   case, however the number of chopper/readout cycles per 
//   grating step can be given as a parameter. Currently it is 
//   assumed that we do internal calibration measurements inside
//   this sequence on every grating step. "Up" and "Down" scans will 
//   cover the same absolute grating positions in equidistant steps, 
//   commanded by MOVE_GRATING_RELATIVE. The initial absolute start
//   position of the grating will be commanded before, from 
//   within the OBCP (3.9). The number of grating steps for a
//   line scan is determined by nb_grat_steps. The sequence may
//   consist of at least 7 LOOPs.
//   Explicitly: 
//   For the number of UP/DOWN sequences
//  For each of the P#2 grating positions going up
//      Repeat P#3 times
//         SRC P#4
//         OFF P#6
//         SRC P#4
//         OFF P#7
//      End repeat P#3 times
//      Repeat P#8 times
//         CS1 P#9
//         CS2 P#10
//      End repeat P#8 times
//  End of for each of the P#2 grating positions going up
//  For each of the P#2 grating positions going down
//      Repeat P#3 times
//         SRC P#4
//         OFF P#6
//         SRC P#4
//         OFF P#7
//      End repeat P#3 times
//      Repeat P#8 times
//         CS1 P#9
//         CS2 P#10
//      End repeat P#8 times
//  End of for each of the P#2 grating positions going down
//   End for the number of UP/DOWN sequences
//   This procedure returns its duree
//   in number_of_ramps. It is up to the calling program to
//   convert number_of_ramps into [sec] (this procedure does
//   not know the duree of each ramp)
//
//
// Dependencies  : Stand alone DEC/MEC sequence
//   
// Comments      : Follows verbatim paragraph 4.2.1 in PACS-ME-LI-005
//         Actual values of input parameters, except values for the
//         various loop counters, are completely irrelevant and so
//         are not used. 
//         Loop counters are used to estimate the duree of the
//         sequence
//
// Version       : 0.1 19-Aug-2004 Creation by DAC
// History       : 0.2 18-Oct-2004 Normalized variable names
//                 0.3 12-Nov-2004 Introduce time_array 
//                 0.4 14-mar-2007 WAIT=1 for chopper is now useful data
//
// This "dummy" DEC/MEC sequence needs only the loop parameters from the
// complete list above
//
int[] procedure DMC_spec_2_3_chop {
    int nb_up_down = 1; // Number of sequences: up down up ...
    int nb_grat_steps = 10; // Number of grating steps
    int nb_SRC_OFF = 10; // Nb cycles on/off source/grating position
    int nb_ramps_plateau = 10; // Number of ramps per chopper plateau
    int nb_CS1_CS2 = 10; // Nbr cycles on cal src per grating position
}{
    // Define variables for time_array
    int duree_ramps = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Pseudo code from PACS OBCPs and DMC Sequences (4.1.2)
    //
    // WAIT 1 ; have a defined start
    // Accumulated duree_ramps in number of ramps
    duree_ramps = duree_ramps + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; set Label to 0 
    // LOOP P#1 ; main loop measurement
    for(int outloop = 1 .. nb_up_down) {
        //   LOOP P#2 ; grating loop up
        for(int gratUPloop = 1 .. nb_grat_steps) {
            //  WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            //  MOVE_GRATING_RELATIVE P#11 ; increment grating position
            //  LOOP P#3 ; chop readout cycle 
            for(int onoffUPloop = 1 .. nb_SRC_OFF) {
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_SRC = duree_SRC + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#4 ; chopper to P#4 (SRC) 
                //  LABEL 3 ; first chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_SRC = duree_SRC + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_SRC = duree_SRC + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#6 ; chopper to P#6 (REF1)
                //  LABEL 5 ; next chopper pos. 
                //  WAIT P#5 ; take P#5 ramps 
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_REF = duree_REF + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_SRC = duree_SRC + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#4 ; chopper to P#4 (SRC)
                //  LABEL 3 ; first chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_SRC = duree_SRC + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_SRC = duree_SRC + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#7 ; chopper to P#7 (REF2)
                //  LABEL 7 ; last chopper pos. 
                //  WAIT P#5 ; take P#5 ramps 
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_REF = duree_REF + nb_ramps_plateau;
            }
            //  END_LOOP ; chop readout cycle
            //  LOOP P#8 ; calibration loop
            for(int csUPloop = 1 .. nb_CS1_CS2) {
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_CAL = duree_CAL + 1;
                //  MOVE_CHOPPER_ABSOLUTE chop_pos_CS1; chop to CS1 
                //  LABEL 65 ; CS1 
                //  WAIT P#5 ; take nb_ramps_plateau 
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_CAL = duree_CAL + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_CAL = duree_CAL + 1;
                //  MOVE_CHOPPER_ABSOLUTE chop_pos_CS2 ; chop to CS2 
                //  LABEL 129 ; CS2 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_CAL = duree_CAL + nb_ramps_plateau;
            }
            //  END_LOOP ; calibration done
        }
        //   END_LOOP ; grating scan up done
        //   LOOP P#2 ; grating loop down
        for(int gratDNloop = 1 .. nb_grat_steps) {
            //  WAIT 1 ; sync. for grating 
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            //  MOVE_GRATING_RELATIVE grat_step_dn ;decrement grating position 
            //  LOOP P#3 ; chop readout cycle
            for(int onoffDNloop = 1 .. nb_SRC_OFF) {
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_SRC = duree_SRC + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#4 ; chopper to P#4 (SRC)
                //  LABEL 3 ; first chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau 
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_SRC = duree_SRC + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_SRC = duree_SRC + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#6 ; chopper to P#6 (REF1) 
                //  LABEL 5 ; next chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau 
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_REF = duree_REF + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_SRC = duree_SRC + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#4 ; chopper to P#4 (SRC)
                //  LABEL 3 ; first chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_SRC = duree_SRC + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_SRC = duree_SRC + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#7 ; chopper to P#7 (REF2)
                //  LABEL 7 ; last chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_REF = duree_REF + nb_ramps_plateau;
            }
            //  END_LOOP ; chop readout cycle done 
            //  LOOP P#8 ; calibration loop
            for(int csDNloop = 1 .. nb_CS1_CS2) {
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_CAL = duree_CAL + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#9 ; chop to P#9 (CS1) 
                //  LABEL 65 ; CS1 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_CAL = duree_CAL + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_CAL = duree_CAL + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#10 ; chop to P#10 (CS2)
                //  LABEL 129 ; CS2 
                //  WAIT P#5 ; take P#5 ramps
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_CAL = duree_CAL + nb_ramps_plateau;
            }
            //   END_LOOP ; calibration done
        }
        //   END_LOOP ; grating scan up done
    }
    // END_LOOP ; main loop done
    // WAIT 1 ; complete last plateau 
    duree_ramps = duree_ramps + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; reset LABEL to 0 
    // END_SEQUENCE
    // Create time_array
    int[] time_array = [duree_ramps,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    debug_print("DMC_spec_2_3_chop duree: " + time_array);

    return time_array;
}

// $Id: PacsEng_SPEC_orbit_prologue.txt,v 1.8 2008/11/12 11:40:20 vanessad Exp $
// Purpose        : Bring PACS from switched off condition to standby
//                  for PHOT observations
//
// CUS author     : Composed from various ILT modules
//
// Input arguments: see after module identification
//
// Return values
// N/A
//
// Comments      :
//
// History: 
// 1.0  21-aug-2007  Renamed from PACS_SPEC_orbit_prologue
//                                Use new "no_pointing" pointing request and
//                                StateMachine logic
// 2.0  12-nov-2008  Helmut Dannerbauer changed the setup time for CSs from
//		     1800 to 2100 seconds.
obs PacsEng_SPEC_orbit_prologue {
}{
    // Settling time for CS
    int tSET = 2100;
    string fltPOS = "POS A";
    double temp_CS1 = 48.0;
    double temp_CS2 = 58.0;
    double blu_heater_curr = 0.78;
    // Get duration 
    int tp = duration(SPEC_setup(fltPOS,temp_CS1,temp_CS2,blu_heater_curr));
    bool execute = true;
    // Add needed time to set/unset OBSID
    int tset = duration(WriteOBSID($OBSID));
    int tunset = duration(WriteEndID());
    tp = tp + tset + tunset + tSET;
    // Issue PointReq       
    int[] ts = no_pointing(execute,0,0,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 3) {
            //     Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            //     Call the SPEC setup script
            SPEC_setup(fltPOS,temp_CS1,temp_CS2,blu_heater_curr);
            //     Wait for CS to stabilize
            delay(tSET);
            //     Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// Missionphase  : EQM IMT
//
// Purpose	: Configure the DPU bus list for nominal bus list after burst mode
//
// Author	: Bart Vandenbussche	: 
//
// Arguments	: none
//
// Description	: Sets the nominal bus list on the DPU
//                  
// Dependencies : none
//
// Comments	: 
//
// Version	: 1.0
//               
// History	: 1.0 20-04-2005 BV - created base on Thomas' tcl script
// 		  2.0 07-02-2008 VDP - Added WriteBBID and WriteEndBB
//		      		 modified for PV phase		  
//
block Burstmode_reset_block PACS 308 {
}{
    // Obtain and set Block ID
    WriteBBID($BBID);
    Pacs_DPU_SET_BUS_LIST("DISABLE");
    // reset Block ID
    WriteEndBB();
}

// CVS comments  : $Id: SPEC_get_grat_info.txt,v 1.6 2008/05/28 13:53:57 vanessad Exp $ 
// Purpose       : Estimate grating parameters by referring to the U-CAL SPEC_BAND_params and 
//                 grating calibration file mentioned therein
//
// CUS author    : DAC
// Script file   : SPEC_get_grat_info.txt 
//
// Input arguments
// type    name         description
// double  waveLen      Desired wavelength [microns]
//
// Return values
// Type                           Description
// tuple  {double,int,int,        {waveLen,order,gratPos,
//         int,int}                nbSteps,stepSize}  
//
// Description   : Access the table SPEC_BAND_params. Verify that the given
// wavelength is within range; obtain order and the name of the GratCal
// grat vs. wavelength table. Get nominal grating position from GratCal table.
// Returns the grating position such that nominal grating position will be
// acchieved after nbSteps/2 steps.
//
// Notes from 18-june-2009 (DAC). Order, which used to be the key to many
// CAL-U tables has been extended into an indicator of wavelength/filter
// combinations. The amended logic defines the following orders for use
// with the KeyWaves:
// - If 1st order and using parallel filter A: order = 12
// - If 1st order and using parallel filter B: order = 13
// - If 2nd order (filter A):                  order =  2
// - If 3rd order (filter B):                  order =  3
// - If 2nd order at 3rd order wavelengths:    order = 23
// 
// For the science lines, Order has its original intrpretation, i.e.
// grating order
// 
//
// Dependencies  :
//
// Preconditions :
//                 
// Comments      : With current version of lookup, first column has to be of
// type string
// 
// History       : 0.1 25-aug-2005 DAC
// 0.2  8-may-2006 Return grating position such that line falls
//                 in the middle of array after n_steps/2
// 0.3 30-may-2006 Access SPEC_BAND_params using module SPEC_BAND_read;
//                 SPEC_BAND_read no longer used (since when?)
//                 Return central pixel gratPos if switching = true
// 0.4 22-nov-2006 "Verbosed" debug_print
// 0.5 14-feb-2007 Verbose in calling argument
// 0.6 14-mar-2007 extraConf in calling argument
// 0.6  7-may-2007 Amended for SCR-3164: introduction of "L" lines in
//                 SPEC_BAND_params
// 0.7  8-may-2007 Case of overlapping bands; orderSel defines the order
// 1.0 10-oct-2007 SCR3632. Dedicated key wave parameters. K lines will
//                 be recognized because "resol" will be KHI, KMED, or KLOW
// 2.0 06-05-2009 VD sort out KeyWL SPR5447 for ALL Ranges inc. SEDs
// 3.0 24-nov-2009 VD PHS-1264 Key Wave @ order 2 if lineLamdba < 103.1
// 4.0 26-nov-2009 VD PHS-1267 wavelength band larger
// 5.0 30-nov-2009 VD SCRs PHS-1272 and PHS-1274
//
{double,int,int,int,int} procedure SPEC_get_grat_info {
    double waveLen = 54.0 in [51.0,220.0]; // Sought wavelength
    string resol = "HI" in ["HI","MED","LOW","KHI","KMED","KLOW"]; // Desired resolution
    bool switching = true; // Return central pixel if true
    string extraConf = "normal" in ["normal","bright"];
    string orderSel = "order2";
    bool verbose = false;
}{
    bool special = false;
    // PacsRangeSpec may call with sedN instead of orderSelN; use
    // "conversion" table for sedN => orderSelN 
    if(orderSel == "sed2" || orderSel == "sedb2b") {
        orderSel = "order2";
    }
    if(orderSel == "sed3" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        orderSel = "order3";
    }
    if(orderSel == "sed4" || orderSel == "order23") {
        string save_orderSel = "sed4";
        orderSel = "order2";
        special = true;
    }
    // Open and read SPEC_BAND_params table. Table indexed by ORDER
    // Try two possible ORDERs: order 1 and order indicated by orderSel
    // Start with order = 1
    int order = 1;
    if(special) {
        order = 23;
    }
    bool found = false;
    int nbSRCH = 0;
    while(!found && nbSRCH < 2) {
        //   SCR-3164. Deal with "L" lines
        string key = "L" + order;
        //   SCR-3632 Deal with key wavelengths
        // Start KeyWave if-endif	
        if(resol == "KHI" || resol == "KMED" || resol == "KLOW") {
            if(orderSel == "order2" && waveLen > 103.1) {
                order = 12;
            }
            if(orderSel == "order2" && waveLen <= 103.1) {
                if(!special) {
                    order = 2;
                } else {
                    if(special) {
                        order = 23;
                    }
                }
            }
            if(verbose) {
                debug_print("SPEC_get_grat: orderSel " + orderSel);
            }
            if(orderSel == "order3" && waveLen >= 100.0) {
                order = 13;
            }
            if(orderSel == "order3" && waveLen <= 99.0) {
                order = 3;
            }
            key = "K" + order;
            if(verbose) {
                debug_print("waveLEN: " + waveLen);
                debug_print("keyW: " + key);
            }
        }
        // End KeyWave if-endif
        //   read BLU and RED edges of the SPEC bands
        double blu = dlookup("SPEC_BAND_params",key,"BLU");
        double red = dlookup("SPEC_BAND_params",key,"RED");
        found = blu <= waveLen && red >= waveLen;
        // Logic to deal with upper/lower half
        if(found) {
            string newKey = "";
            if(key == "L1" && waveLen > 150.0) {
                newKey = "L1R";
            }
            if(key == "L1" && waveLen < 160.0) {
                newKey = "L1B";
            }
            //	       debug_print("#########Newkey: " + newKey);		       
        }
        if(verbose) {
            debug_print("SPEC_get_grat: Switching is " + switching);
            debug_print("SPEC_get_grat: Wave " + waveLen);
            debug_print("SPEC_get_grat: FOUND " + found);
            debug_print("SPEC_get_grat: key " + key);
            debug_print("SPEC_get_grat: nbSRCH " + nbSRCH);
        }
        //   If not yet found search in order indicated by orderSel
        if(!found) {
            if(orderSel == "order2") {
                order = 2;
            } else {
                if(orderSel == "order3") {
                    order = 3;
                }
            }
            nbSRCH = nbSRCH + 1;
        }
    }
    // If given wavelength not found there is a problem
    if(!found) {
        error("Wavelength " + waveLen + " is not within " + orderSel);
    }
    // Found the ORDER. Get now the name of position vs. wavelength gratPosTab
    string gratPosTab = slookup("SPEC_BAND_params",key,"CAL_FILE");
    // Read the step size and the number of steps for this ORDER and resolution
    // Recast "resol" as it was before SCR3632
    if(resol == "KHI") {
        resol = "HI";
    }
    if(resol == "KMED") {
        resol = "MED";
    }
    if(resol == "KLOW") {
        resol = "LOW";
    }
    // Special case for "bright" source
    if(extraConf == "normal") {
        int stepSize = ilookup("SPEC_BAND_params",key,resol);
        int nbSteps = ilookup("SPEC_BAND_params",key,"NSTEPS");
    }
    if(extraConf == "bright") {
        stepSize = ilookup("SPEC_BAND_params",key,resol);
        nbSteps = ilookup("SPEC_BAND_params",key,"FASTSTEP");
    }
    // Get from gratPosTab the grating position corresponding to waveLen
    double gratPosDble = interpolate(gratPosTab,"grat_pos",waveLen);
    // gratPos will place waveLen in the middle of the array
    int gratPos = iround(gratPosDble);
    if(verbose) {
        debug_print("SPEC_get_grat Nominal wavelen: " + waveLen);
        debug_print("SPEC_get_grat Nominal grating: " + gratPos);
    }
    // Grating is scanned with a negative step size (increasing wavelength) 
    // The grating start position should then be such that after nbSteps/2 we
    // are at nominal position: 
    //              gratPos = gratStartPos - stepSize*nbSteps/2
    // hence:
    int gratStartPos = iround(gratPosDble + double(stepSize) * double(nbSteps) / 2.0);
    // and will scan by decreasing grating angle, i.e. negative step size:
    stepSize = -stepSize;
    // If frequency switch return return gratPos (central pixel)
    if(switching) {
        gratStartPos = gratPos;
    }
    if(verbose) {
        debug_print("SPEC_get_grat: reads SPEC_BANDS");
        debug_print("SPEC_get_grat: WAVE/order/gratNOMINAL/gratSTRT: " + waveLen + "/" + order + "/" + gratPos + "/" + gratStartPos);
        debug_print("SPEC_get_grat: nbSteps/stepSize: " + nbSteps + "/" + stepSize);
    }

    return {waveLen,order,gratStartPos,nbSteps,stepSize};
}

// CVS comments  : $Id: PacsRangeSpecCheckFillRange.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $
// Missionphase  : Operations
//
// Purpose       : Check that HSPOT given ranges agree with U-CAL values,
//                 return corresponding grating positions or null values if
//                 range exceeds U-CAL specifications. Special logic for "SED"
//                 observations
//
// CUS author    : DAC
// Script file   : PacsRangeSpecRangeCheck.txt 
//
// Input arguments
// type                                         name      description
// {string,double,double,double,double,double,  ranges    Variable from HSPOT
// Returns "rangeInfo":  {string,int,int,int,double,double}   
// {ObsType,ORDER,grat_pos_blue,grat_pos_red,grat_step,wave_blu,wave_red}
//                     returns [0,0,0] when rangeWave is invalid
// Description   : Compares HSPOT ranges with limits defined in SPEC_BAND_params
//                 CAL file. Returns grating start/stop positions for all
//                 complying ranges; grating positions are obtained from 
//                 dedicated CAL files (file names found in SPEC_BAND_params)
// Dependencies  : low level CUS functions
//
// Preconditions :
//
// Comments      : 
// 
// History       : 0.1 21-Jun-2005 DAC
// 1.0 15-sep-2005 Adapted for "OBS" CUS script, call argument is "ranges"
// 1.1 16-sep-2005 Add gratStep element to rangeInfo; renamed to 
//                 PacsRangeSpecCheckFillRange since now it adds gratStep
// 1.2 11-may-2006 Element {3} of ranges is now an integer
// 1.3 22-jun-2006 ranges now contains lineWidth. grating and density variables
//                 have changed possible values. Call them xxxNEW and use
//                 "conversion" tables not to change the logic of module
// 1.4 22-nov-2006 Move verbose into call list
// 1.5 25-jan-2007 Read CAL-U using new xcolumn function
// 2.0 12-apr-2007 Several changes for SCR-3050. For RANGE find order given
//                 BLU and RED wavelengths; for SED read directly the relevant
//                 CAL-U row based on HSPOT input
// 2.1 18-apr-2007 Now keeping user defined rangeID; change some logic to
//                 recognize RANGE and SED
// 3.0 27-apr-2007 Define rangeWave as rangeSPOT
// 4.0 11-jun-2007 SPR-3281 Change logic: now checks ORDER rather than finding
//                 ORDER. Added orderSel to input list
// 5.0 01-dec-2009 VD SCR PHS-1272
// 6.0 12-jan-2010 VD PHS-1285: SED dither... override grat_info use infoRangeSed instead
// 7.0 03-may-2010 VD PHS-1393 B2A order23
//
{string,int,int,int,int,double,double}[] procedure PacsRangeSpecCheckFillRange_tmp {
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [{"SED",55.0,70.0,0,0.0,0.0,0.0,"","",0.0}];
    /* PHS-1285 */
    {double,double}[] infoRangeSed = [{0.0,0.0}];
    string densityNEW = "high" in ["nyquist","high"];
    string gratingNEW = "nyquist" in ["nyquist","nyquist"];
    string orderSel = "order3";
    bool verbose = false;
}{
    // Old values of density and grating
    // string density = "high" in ["high","medium","low"];
    // string grating = "medium" in ["fast","low","medium"];
    // "Conversion" tables for new nomenclature
    string density = "high";
    if(densityNEW == "nyquist") {
        density = "low";
    }
    string grating = "medium";
    // Variable to map SPEC_BAND_params file in memory
    string calU = "SPEC_BAND_params";
    {string,double,double,int,int,int,string}[] file_map = [{"",0.0,0.0,0,0,0,""}];
    // Map the whole SPEC_BANDS_params table in memory and create file_map tuple
    string[] keyCol = scolumn(calU,"ORDER");
    double[] lo = dcolumn(calU,"BLU");
    double[] hi = dcolumn(calU,"RED");
    int[] lowStep = icolumn(calU,"LOW");
    int[] medStep = icolumn(calU,"MED");
    int[] hiStep = icolumn(calU,"HI");
    string[] name = scolumn(calU,"CAL_FILE");
    // Currently SPEC_BAND_params has nrows
    int nrows = table_size(calU);
    // Map it to "file_map"
    for(int order = 0 .. nrows - 1) {
        file_map[order] = {keyCol[order],lo[order],hi[order],lowStep[order],medStep[order],hiStep[order],name[order]};
    }
    // Number of input range tuples
    int nbrangeSPOT = length(rangeSPOT);
    // Review each input range for conformity with SPEC_BAND_params; if OK get 
    // the grating positions for the red and blue edges
    // Procedure returns tuple rangeInfo: 
    // {typeOBS,ORDER,bluGRAT,redGRAT,stepGRAT,bluWAVE,redWAVE}
    {string,int,int,int,int,double,double}[] rangeInfo = [{"SED",0,0,0,0,0.0,0.0}];
    // Start loop per HSPOT range (in SED mode the range tuple is furnished by
    // PacsRangeSpecSed)
    for(int loop0 = 0 .. nbrangeSPOT - 1) {
        string typeOBS = rangeSPOT[loop0]{0};
        double bluHSPOT = rangeSPOT[loop0]{1};
        double redHSPOT = rangeSPOT[loop0]{2};
        // An all [0,0,0] rangeInfo means contents of rangeSPOT not found
        rangeInfo[loop0] = {"NONE",0,0,0,0,bluHSPOT,redHSPOT};
        bool found = false;
        // If SED observations, search SPEC_BANDS_params past the
        // three canonical rows (i.e. ORDER=1, 2, and 3)
        // In RANGE mode there is no ORDER=1 specification (ORDER can be 2 or 3)
        // Always check for ORDER=1 and then for given order
        // Hence, check order from first column and then from ORDERth column
        // First index into SPEC_BAND_params
        int index0 = 0;
        //  Establish next index
        if(orderSel == "order2") {
            int index1 = 1;
        }
        if(orderSel == "order3") {
            index1 = 2;
        }
        if(orderSel == "order23") {
            index1 = 6;
        }
        bool isRange = orderSel == "order2" || orderSel == "order3" || orderSel == "order23";
        if(isRange) {
            int count = 1;
            int index = index0;
            while(!found && count < 3) {
                if(verbose) {
                    debug_print("CheckRange: using index: " + index);
                }
                found = bluHSPOT >= file_map[index]{1} && redHSPOT <= file_map[index]{2};
                //        Found the relevant row in SPEC_BAND_params!
                if(found) {
                    // Read associated CAL file; obtain grating positions
                    string file_name = file_map[index]{6};
                    // "Canonical" ORDER 1, 2, or 3, i.e. "RANGE" observations
                    if(verbose) {
                        debug_print("CheckRange found RANGE OBS at index: " + index);
                    }
                    double grat_lo = interpolate(file_name,"grat_pos",bluHSPOT);
                    double grat_hi = interpolate(file_name,"grat_pos",redHSPOT);
                    rangeInfo[loop0]{0} = typeOBS;
                    order = index + 1;
                    if(orderSel == "order23" && order == 7) {
                        order = 23;
                    }
                    rangeInfo[loop0]{1} = order;
                    rangeInfo[loop0]{2} = iround(grat_lo);
                    rangeInfo[loop0]{3} = iround(grat_hi);
                    rangeInfo[loop0]{5} = bluHSPOT;
                    rangeInfo[loop0]{6} = redHSPOT;
                    // Get the gratStep (defined by "density")
                    if(density == "high") {
                        rangeInfo[loop0]{4} = file_map[index]{5};
                    }
                    if(density == "medium") {
                        rangeInfo[loop0]{4} = file_map[index]{4};
                    }
                    if(density == "low") {
                        rangeInfo[loop0]{4} = file_map[index]{3};
                    }
                    //           Found
                }
                //           Not yet found
                index = index1;
                count = count + 1;
            }
            // Enter error if RANGE not found
            if(!found) {
                error("Range " + bluHSPOT + "-" + redHSPOT + " is off allowed bounds");
            }
            // SED observations
        } else {
            if(orderSel == "sed2" || orderSel == "sed3" || orderSel == "sed4") {
                // Read relevant line according to "sedX"
                //     Entry key to SPEC_BANDS_params          
                int keyINT = 4;
                ///Now as input argument:  orderSel = typeOBS;
                if(orderSel == "sed3") {
                    keyINT = 5;
                }
                if(orderSel == "sed4") {
                    keyINT = 6;
                }
                string key = "" + keyINT;
                // Associated CAL file to obtain grating positions
                //     Update index0
                index0 = keyINT - 1;
                file_name = file_map[index0]{6};
                // Entry key to SPEC_SED
                keyINT = keyINT - 3;
                key = "" + keyINT;
                grat_lo = dlookup(file_name,key,"BLU");
                grat_hi = dlookup(file_name,key,"RED");
                order = ilookup(file_name,key,"ORDER");
                rangeInfo[loop0]{0} = typeOBS;
                rangeInfo[loop0]{1} = order;
                rangeInfo[loop0]{2} = iround(grat_lo);
                rangeInfo[loop0]{3} = iround(grat_hi);
                rangeInfo[loop0]{5} = bluHSPOT;
                rangeInfo[loop0]{6} = redHSPOT;
                //     Get the gratStep (defined by "grating")
                if(grating == "low") {
                    rangeInfo[loop0]{4} = file_map[index0]{5};
                }
                if(grating == "medium") {
                    rangeInfo[loop0]{4} = file_map[index0]{4};
                }
                if(grating == "fast") {
                    rangeInfo[loop0]{4} = file_map[index0]{3};
                }
            } else {
                // need logic for getting the grat_positions if dithering .. aaahhh yes
                if(orderSel == "sedb2b") {
                    index0 = 7;
                }
                if(orderSel == "sedb2a") {
                    index0 = 8;
                }
                if(orderSel == "sedb3a") {
                    index0 = 9;
                }
                key = "" + orderSel;
                debug_print("real: key: " + key);
                file_name = file_map[7]{6};
                grat_lo = dlookup(file_name,key,"BLU");
                grat_hi = dlookup(file_name,key,"RED");
                order = ilookup(file_name,key,"ORDER");
                rangeInfo[loop0]{0} = typeOBS;
                rangeInfo[loop0]{1} = order;
                //     Get the gratStep (defined by "grating")
                if(grating == "low") {
                    rangeInfo[loop0]{4} = file_map[index0]{5};
                }
                if(grating == "medium") {
                    rangeInfo[loop0]{4} = file_map[index0]{4};
                }
                if(grating == "fast") {
                    rangeInfo[loop0]{4} = file_map[index0]{3};
                }
                rangeInfo[loop0]{2} = iround(infoRangeSed[loop0]{0});
                rangeInfo[loop0]{3} = iround(infoRangeSed[loop0]{1});
                rangeInfo[loop0]{5} = bluHSPOT;
                rangeInfo[loop0]{6} = redHSPOT;
                //	       rangeInfo[loop0]{2} = iround(grat_lo + double(loop0)*(double(rangeInfo[loop0]{4})/ double(nbrangeSPOT)));
                //	       rangeInfo[loop0]{3} = iround(grat_hi);
                debug_print("CheckFillRangeSED: rangeInfo(grat_lo)" + rangeInfo[loop0]{2} + "/ bluWL: " + rangeInfo[loop0]{5});
                debug_print("From SpecSed Modified: " + infoRangeSed[loop0]{0});
            }
            // SED mode ends here
        }
        if(verbose) {
            debug_print("###CheckFill used table " + file_name);
            debug_print("###CheckFill grat lo/hi/order: " + grat_lo + "/" + grat_hi + "/" + order);
        }
        // End loop on nbRanges
    }
    if(verbose) {
        debug_print("## PacsRangeSpecCheckFillRange reads SPEC_BAND; returns: " + rangeInfo);
    }

    return rangeInfo;
}

// $Id
// Missionphase		: PACS PV Phase
//
// Purpose       : Invoke a PACS calibration OBCP during slew to source;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsPhotSlewCal.txt 
//
// Input arguments
// Type                      Description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform AOT prologue and then OBCP #13.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 DAC  30-Nov-2005 (inspired by PacsSpecSlewCal)
// 0.2 DAC 20-sep-2006 Clean up leftovers from SPEC script 
// 0.3 DAC  6-dec-2006 Adapted to simpler PHOT_fltw_move
// 0.4 DAC 27-jun-2007 SPR-3339 Always move filter wheel
// 1.0 DAC 10-oct-2007 SCR-3628 Added arguments to call aot_prologue 
// 1.5 VD  08-jan-2009 missing call for Default values
//                 
obs PacsCal_PacsPhotSlewCal {
    /* Needed variables to call PacsPhotSlewCal */
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int comp_mode_blu = 0;
    int nb_raw_blu = 3;
    int comp_mode_red = 0;
    int nb_raw_red = 3;
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    double chopthrow = 30.0;
    bool verbose = true;
}{
    // compiting time for slw / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Set OBSID
    int tobsid = duration(WriteOBSID($OBSID));
    // Calibration time during slew
    if(fltPOS == "POS A") {
        string filter = "blue2";
    } else {
        if(fltPOS == "POS B") {
            filter = "blue1";
        }
    }
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsPhotSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // including a new section for Low Gain implementation SCR4196
    bool isBrightPacs = false;
    string srcID = "pointSRC";
    // Obtain default values for "Prime" mode
    paramsPHOT = PacsPhotDefaults(srcID,"Prime",isBrightPacs,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    confPHOTblu[0]{3} = comp_mode_blu;
    confPHOTblu[0]{6} = nb_raw_blu;
    confPHOTred[0] = paramsPHOT{1};
    confPHOTred[0]{3} = comp_mode_red;
    confPHOTred[0]{6} = nb_raw_red;
    confOBCP[0] = paramsPHOT{2};
    bool doProlog = true;
    //Initial hold
    int tih = duration(WriteOBSID($OBSID));
    int tslewmin = 0;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int tepilog = duration(PHOT_aot_epilogue());
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,filter));
    if(verbose) {
        debug_print("Duration of WaveCalChop" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //Photometry
    string ib = "P01_0";
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            int tNOW = time();
            // 
            WriteOBSID($OBSID);
            if(verbose) {
                debug_print("WriteOBSID at :" + tNOW + " sec");
            }
            tNOW = time();
            if(verbose) {
                debug_print("WriteOBSID ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,filter);
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 5) {
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold starts at :" + tNOW + " sec");
                    }
                    PHOT_aot_epilogue();
                    WriteEndID();
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold ends at :" + tNOW + " sec");
                    }
                }
            }
        }
    }
    // End of Observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_Fil_Testseq {
    /* No variables to call PacsEng_Phot_Fil_Testseq                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_Fil_Testseq                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_Fil_Testseq()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_Fil_Testseq();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsDureeOBCP32.txt,v 1.1 2007/10/25 12:16:47 dcesarsk Exp $ 
// Purpose       : Estimate duration of OBCP32 with input parameters
//
// CUS author    : 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : Based on PacsDureeOBCP22
// Version       : 0.1
// History       : 0.1  18-oct-2007 DAC
//                 1.0   3-jun-2009 DAC Rewritten for new OBCP32
//                 1.1 22-sep-2009 VD rewrite logic ofr unchopped OBCP32
//
int[] procedure PacsDureeOBCP32_unChop {
    int ditherCount = 11; // P2 Number of dither cycles
    int nb_up_dn = 1; // P1 Number of up/down cycles
    int nbABBA = 3; // P4 Number ABBA cycles
    int nb_ramps_grat = 1; // P6 Number of ramps per grating positiom
    int nb_rdouts_ramp = 64; // Number of rdouts per ramp
}{
    // Use "theoretical formula
    int dureeUpDn = ditherCount * (nbABBA * 4 * nb_ramps_grat + 1);
    int duree = nb_up_dn * 2 * dureeUpDn;
    //  Create duree array the usual DMC way
    int[] duree_array = [duree,duree / 2,duree / 2,0,0];
    // Use classical method
    int[] classic = DMC_wave_switch(ditherCount,ditherCount,nbABBA,nb_ramps_grat,nb_up_dn);
    // Convert number of ramps into seconds
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    // Convert duration [ramps] into [msec]
    // Create return time array; convert into [sec]
    int[] time_array = [0,0,0,0,0];
    for(int aux = 0 .. 4) {
        time_array[aux] = ifloor(double(duree_array[aux]) * ramp_time);
        time_array[aux] = Msec2sec(time_array[aux]);
        classic[aux] = ifloor(double(classic[aux]) * ramp_time);
        classic[aux] = Msec2sec(classic[aux]);
    }
    //
    // Return total duration [sec] to calling program
    //   return time_array;

    return classic;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_SFT_Cooler_Warm {
    /* No variables to call PacsEng_Phot_SFT_Cooler_Warm                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_SFT_Cooler_Warm                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_SFT_Cooler_Warm()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_SFT_Cooler_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// version 1.0
// History 1.0 05-dec-2008 VD Change call of CONFGrat with ISTSafe
//
procedure PACS_Spec_Gra_PID_loop_Short {
}{
    int[] kp = [2000,2500,3000,3500,4000];
    int[] ki = [50000,75000,100000,125000,150000];
    int[] kd = [20,22,25,27];
    int nsteps_kp = length(kp) - 1;
    int nsteps_ki = length(ki) - 1;
    int nsteps_kd = length(kd) - 1;
    string calUname = "CONFGrat";
    // GRATING CALIBRATION TABLE
    string calUrow = "ISTSafe";
    // INSTRUMENT VERSION
    //
    // ----------------------------
    // SWITCH ON GRATING CONTROLLER
    // ----------------------------
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    //
    int word0 = ilookup(calUname,calUrow,"Kp");
    int word1 = ilookup(calUname,calUrow,"Ki");
    int word2 = ilookup(calUname,calUrow,"Kd");
    int word3 = ilookup(calUname,calUrow,"Kf");
    int word4 = ilookup(calUname,calUrow,"Rate");
    int word5 = ilookup(calUname,calUrow,"AccLimit");
    int word6 = ilookup(calUname,calUrow,"OutputLimit");
    int word7 = ilookup(calUname,calUrow,"Scaling");
    int word8 = ilookup(calUname,calUrow,"ErrorLimit");
    {int}[] params = [];
    int[] aux = [];
    int chksum = 0;
    //
    for(int np = 0 .. nsteps_kp) {
        for(int ni = 0 .. nsteps_ki) {
            for(int nd = 0 .. nsteps_kd) {
                // DISABLE GRATING CONTROLLER
                Pacs_DMC_DISABLE_GRAT_CONT();
                delay(1);
                //
                word0 = kp[np];
                word1 = ki[ni];
                word2 = kd[nd];
                // Create the parameter list tuple
                params = [{word0},{word1},{word2},{word3},{word4},{word5},{word6},{word7},{word8}];
                // Create the array for the checksum function
                aux = [word0,word1,word2,word3,word4,word5,word6,word7,word8];
                chksum = checksum("int",aux);
                // Send the TC
                Pacs_DMC_WRT_GRAT_CONF_PAR(params,chksum);
                delay(1);
                // ENABLE GRATING CONTROLLER
                Pacs_DMC_ENABLE_GRAT_CONT();
                delay(3);
                for(int m = 0 .. 5) {
                    Pacs_DMC_MOVE_GRAT_REL_RAW(117);
                    delay(1);
                }
                for(int j = 0 .. 5) {
                    Pacs_DMC_MOVE_GRAT_REL_RAW(-117);
                    delay(1);
                }
                Pacs_DMC_MOVE_GRAT_REL_RAW(233010);
                delay(10);
                Pacs_DMC_MOVE_GRAT_REL_RAW(-233010);
                delay(10);
            }
        }
    }
    // DISABLE GRATING CONTROLLER
    Pacs_DMC_DISABLE_GRAT_CONT();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	: SPU nominal data rate check (photometry)
//
// Author	: Roland Vavrek
// CUS script	: RV
// CVS file	: 
//
// Arguments	: No interactive parameters
//                         
//                 
//		   
// Description	: Photometry, staring 7 min on CS2/CS1 and chopper zero position in default/double compression SPU setup.
//  
//                  
// Dependencies :  - Chop_mov_abs
//                          - PHOT_spu_reset
//                          - PHOT_spu_setup
//
//
// Preconditions : - PACS is switched on
//                         - Setup photometry with nominal parameters 
//	      - Mechanics and CS controllers are SWON and ENABLED
//                         - CS2/CS1 temperature is raising but not yet stabilized
//
// Comments	: The default detector selection table is assumed to be used before executing this script.
//
// Version	: 2.0
//               
// History	: 2.0 25-mar-2008 Translated from IST to PV phase syntax
// 		 1.3 09-Apr-2007 Use PHOT_spu_reset and PHOT_spu_setup
//               1.2 05-Apr-2007 Chopper positions on CS1 and zero added, double compression mode 
//                                added on CS2, unit time is reduced to 2 min. Constants updated for FM/ILT
//               1.1 27-Apr-2005 SPU reset attached to the end
//               1.0 21-Apr-2005 Creation by RV
//
obs PacsEng_Phot_spu_data_rate {
    /* Needed variables to call PacsEng_Phot_spu_data_rate                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_spu_data_rate                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Phot_spu_data_rate()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Phot_spu_data_rate();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	: Loops over relative grating movements of various step_size
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: gra_steps_per_block : number of grating steps per step_size
//
// Description	: Loops over relative grating movements
//	  The step sizes are fixed. A block of "gra_steps_per_block" steps is performed for each given step_size
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on
//	    The grating controller is SWON, ENABLED and HOMED
//	    (e.g. SetupSpectroscopyEQMIMT takes care for it)
//
// Comments	: This test only makes sense with appropriate diagnostic HK (e.g. PACS_Spec_Gra_Diaghk_Setup.tcl)
//
// Version	: 2.0
//               
// History	: 1.0 12-Jun-2006 Creation based on SPEC_Gra_slew_time_cal
//			          addition of step sizes typical of AOT
//		  2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
obs PacsEng_Spec_Gra_Slew_Time_Cal {
    /* Needed variables to call PacsEng_Spec_Gra_Slew_Time_Cal                        */
    int gra_steps_per_block = 3;
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_Slew_Time_Cal                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Gra_Slew_Time_Cal(gra_steps_per_block)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Gra_Slew_Time_Cal(gra_steps_per_block);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : PACS EQM Test
//
// Purpose       : Open the launch lock
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
// Arguments     : none
//                 
//
// Description   : This script will do what's necessary to open the launch lock
//                              
// Comments      :      
//
// Version       : 1.0
// History       : 1.0 / 17-Nov-2004 initial version
// 1.1  4-apr-2006 Unlock grating with 0x28
//                 
procedure PACS_Open_Launch_Lock {
}{
    // DPU_SET_HK_LIST (SPEC for both channels)
    Pacs_DPU_SET_HK_LIST("SPEC","BOTH Array");
    delay(1);
    // Set the mechanisms
    // "DMC_SWON_GRAT_CONT" SWITCH ON GRATING CONTROLLER
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    // DMC_UNLOCK_GRATING" Unlock the Grating launch lock
    // in open loop mode
    Pacs_DMC_UNLOCK_GRAT(0x28);
    delay(10);
    // DMC_SWOF_GRAT_CONT" Switch off grating controller
    Pacs_DMC_SWOF_GRAT_CONT();
    // ---------------------
    // End of Procedure
    // ---------------------
}

// CVS comments  : $Id: SPEC_grat_time.txt,v 1.4 2007/04/25 15:14:05 dcesarsk Exp $ 
// Purpose       : Provide an estimate of the time it takes the grating to
//                 move nb_steps. NOTE: units are [msec]
//
// CUS author    : DAC
// Script file   : SPEC_grat_time.txt 
//
// Input arguments
// type    name         Description
// int     nb_steps     Desired relative movement of grating
// 
// Return values
// Type    Description
// int     Expected time [msec] to move the grating by nb_steps
//
// Description   : Straitghtforward computation based on a stepping speed of
// 1 degree/sec, equivalent to 23.301 steps per milisecond
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.2 DAC
//  3-may-2006 0.1 Added 200 msec margin for settling  time
// 15-feb-2007 0.2 Read parameters from PACSparams
int procedure SPEC_grat_time {
    int nb_steps = 23301; // Number of grating steps (relative move)
}{
    // Get speed and settling time
    double grat_speed = dlookup("PACSparams","grat_speed","freq_time");
    double grat_settle = dlookup("PACSparams","grat_settle","freq_time");
    if(nb_steps == 0) {
        int needed_time = 0;
    } else {
        needed_time = iceil(abs(double(nb_steps)) / grat_speed + grat_settle);
    }
    // Return [msec]!!

    return needed_time;
}

// Missionphase  : 
//
// Purpose       : Compute execution time of DMC #19: 
//                 Grating Line Scan with ABBA chopping
//
// TCL author    : N/A Pseudo code by HF
// TCL file      : N/A
// CUS author    : VDP (based on DAC)
// Script file   : DMC_19_grat_line_scan.txt
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Similar to 4.2.1 but with 3-2 chopping positions. 
//                 it is meant to reduce glitch, cosmic hits etc ...
//                 Of the 11 Parameters: 
//                    # of "up-down" sequences (P#1); 
//		      # grating step size up (P#3)
//                    # A-B chopper positions (P#5, P#7); 
//                    # of readouts per chopper position (P#6); 
//                    # of cycles per grating position (P#4); 
//                    size of relative grating move up-down (P#2); 
//                    # of cycles on the internal calibration sources (P#8); 
//                    position of CS1 (P#9); 
//                    position of CS2 (P#10);
//		      grating step size down (P#11)
//                  only those involved in time estimation are used here.
//                  
// Dependencies  : 
//
// Preconditions : None.
//                 
// Comments      : No TC are generated; only times are computed
// 
// History       : 0.1 09-feb-2009 VD (based on DAC)
// NOTE: See OBCP_grat_line_chop3 for modification information
//
// 
int[] procedure DMC_19_grat_line_scan {
    int nb_up_down = 1; // Seq P#1 : Nb of sequences: up down up ...
    int nb_grat_steps = 1; // Seq P#2 : Nb of grating steps (up/down scans)
    int nb_ramps_plateau = 1; // Seq P#6 : Nb of ramps per chopper position
    int nb_CS1_CS2 = 1; // Seq P#8 Nb of cycles on CS, per grating position
    int nb_ABBA = 1; // Seq P#4 : Nb of cycles per grating position
}{
    // NOTE: Logic to remove when the DMC will be recoded for ABBA in the CAL part
    // Logic to perform CAL using the science part of the OBCP
    // Is it CAL?
    if(nb_CS1_CS2 >= 1) {
        //      debug_print ("========= DMC_19 called for CAL");
        //    Set nb_ABBA_sci equal to nb_CS1_CS2; set nb_CS1_CS2 to zero
        nb_ABBA = nb_CS1_CS2;
        nb_CS1_CS2 = 0;
    }
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    // WAIT 1                                             ; have a defined start
    duree_OVR = duree_OVR + 1;
    duree_num = duree_num + 1;
    // LABEL 0                                            ; set Label to 0 
    // LOOP P#1            				  ; main loop measurement
    for(int up_down = 1 .. nb_up_down) {
        //LOOP P#3 ; grating loop up
        for(int up = 1 .. nb_grat_steps) {
            // MOVE_GRATING_RELATIVE P#10                  ; increment grating position 
            // WAIT 1                                      ; sync. for grating 
            duree_OVR = duree_OVR + 1;
            duree_num = duree_num + 1;
            // LOOP P#4 ; chop readout cycle
            for(int chop_cycle_1 = 1 .. nb_ABBA) {
                // MOVE_CHOPPER_ABSOLUTE P#5                ; chopper to P#5
                // LABEL 3                                  ; first chopper pos. 
                // WAIT P#6                                 ; take P#6 ramps 
                // *Assume* P#6 is the SRC position... 
                duree_SRC = duree_SRC + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // MOVE_CHOPPER_ABSOLUTE P#7                ; chopper to P#7
                // LABEL 5                                  ; next chopper pos. 
                // WAIT P#6                                 ; take P#6 ramps 
                // *Assume* P#6 is the REF position... 
                duree_REF = duree_REF + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // WAIT P#6                                 ; take P#6 ramps 
                // *Assume* P#6 is the REF position... 
                duree_REF = duree_REF + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // MOVE_CHOPPER_ABSOLUTE P#5                ; chopper to P#5
                // LABEL 3                                  ; first chopper pos. 
                // WAIT P#6                                 ; take P#6 ramps 
                // *Assume* P#6 is the SRC position... 
                duree_SRC = duree_SRC + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                 ; chop readout cycle done
            }
            // LOOP P#8                                    ; calibration loop
            for(int cal_loop_1 = 1 .. nb_CS1_CS2) {
                // MOVE_CHOPPER_ABSOLUTE P#9                ; chop to CS1
                // LABEL 65                                 ; CS1
                // WAIT P#6                                 ; take P#6 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // MOVE_CHOPPER_ABSOLUTE P#10                ; chop to CS2
                // LABEL 129                                ; CS1
                // WAIT P#6                                 ; take P#6 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                    ; calibration done
            }
            // END_LOOP                                      ; grating scan up done
        }
        // LOOP P#2                                      ; grating loop down
        for(int down = 1 .. nb_grat_steps) {
            // WAIT 1 ; sync. for grating 
            duree_OVR = duree_OVR + 1;
            duree_num = duree_num + 1;
            // MOVE_GRATING_RELATIVE P#11                 ; decrement grating position 
            // LOOP P#3 ; chop readout cycle
            for(int chop_cycle_2 = 1 .. nb_ABBA) {
                // MOVE_CHOPPER_ABSOLUTE P#5               ; chopper to P#5
                // LABEL 19                                ; first chopper pos. 
                // WAIT P#6                                ; take P#6 ramps 
                duree_SRC = duree_SRC + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // MOVE_CHOPPER_ABSOLUTE P#7               ; chopper to P#7 
                // LABEL 21                                ; next chopper pos. 
                // WAIT P#6                                ; take P#6 ramps
                duree_REF = duree_REF + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // WAIT P#6 	      			 	; second 
                duree_REF = duree_REF + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // MOVE_CHOPPER_ABSOLUTE P#5               ; chopper to P#5
                // LABEL 19                                ; first chopper pos. 
                // WAIT P#6                                ; take P#6 ramps 
                duree_SRC = duree_SRC + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                   ; chop readout cycle done
            }
            // LOOP P#8                                    ; calibration loop
            for(int cal_loop_2 = 1 .. nb_CS1_CS2) {
                // MOVE_CHOPPER_ABSOLUTE P#9                ; chop to CS1
                // LABEL 81                                 ; CS1
                // WAIT P#6                                 ; take P#6 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // MOVE_CHOPPER_ABSOLUTE P#10               ; chop to CS2
                // LABEL 145                                ; CS2
                // WAIT P#6                                 ; take P#6 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                    ; calibration done
            }
            // END_LOOP                                      ; grating scan down done
        }
        // END_LOOP                                        ; main loop done
    }
    // LABEL 0                                            ; reset LABEL to 0 
    // END_SEQUENCE 
    // duration, in ramps : 1 + P#1 * 2 * P#2 * {1 + (P#4 * P#6 * 4) + (P#8 * P#6 * 2)})}
    int duree = 1 + nb_up_down * 2 * nb_grat_steps * (1 + nb_ABBA * nb_ramps_plateau * 4 + nb_CS1_CS2 * nb_ramps_plateau * 2);
    //  debug_print("Formula  duration DMC: " + duree + " [ramps]");
    //  debug_print("Computed duration DMC: " + duree_num + " [ramps]");
    // Time spent
    int duree_TCs = time() - time_start;
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// File          : PACS_Spec_Heat_SWON.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : SWOF Heaters
//
// Author        : P. Royer
//
// Arguments     : blue & red Heater currents
//
// Description   : SWOF Heaters
//               :
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 07-Jun-2006 initial version by PR
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose SWOF Heaters
// @comment - 
//
block PACS_Spec_Heat_SWOF PACS 164 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //
    // SWON HEATERS
    //
    Pacs_DMC_SWOF_BD_HEATER();
    Pacs_DMC_SWOF_RD_HEATER();
    //
    // End of procedure
    //------------------
}

// Missionphase  : FM ILT
//
// Purpose	 : Switch on/off diagnostic HK
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : This building block switches on/off diagnaostic HK.
//                 Receiving signals:
//                   ON: switch on diagnostic HK
//                   OFF: switch off diagnostic HK
//                  
// Dependencies  :  
//
// Preconditions : PACS switched-on, chopper is switched on
//                 
// Comments	 :
//
// Version	 : 1.1
// 
// History 	 : 1.0 29-03-07 creation by MN
// Begin Mode description
procedure PACS_Chopper_EnDis_Test_dhk {
    string onoff = "OFF" in ["ON","OFF"];
}{
    // For housekeeping using the chopper in open-loop mode, we need the
    // following parameters:
    // 209  DMC_CHOP_CTRL_ST
    // 242  DMC_IRS_CNT
    // 244	DMC_CHOP_CUR_POS
    // 245	DMC_CHOP_SETPOIN
    // 258	DMC_CHOP_OUTPUT
    // 561  DMC_CHOP_IA
    // IF-statement for switching on
    if(onoff == "ON") {
        // Readout period set to 1kHz
        int diag_hk_period = 0;
        // Create list of HK parameters
        {int}[] parlist = [{209},{244},{245},{258},{561},{0xffff}];
        int hk_len = length(parlist);
        // Calculate check sum
        int[] aux = [209,244,245,258,561,0xffff];
        int check_sum = checksum("int",aux);
        // Write HK parameters and start HK
        debug_print("Starting chopper diagnostics with " + hk_len + " parameters:");
        Pacs_DMC_WRT_DIAG_HK_LIST(hk_len,parlist,check_sum);
        Pacs_DMC_START_DIAG_HK(diag_hk_period);
    }
    // End IF
    // IF-statement for switching off
    if(onoff == "OFF") {
        debug_print("Stopping diagnostic HK");
        Pacs_DMC_STOP_DIAG_HK();
    }
    // End IF
}

// CVS comments  : $Id: PacsPhotSlewCal.txt,v 1.10 2008/05/06 13:34:53 vanessa Exp $ 
// Purpose       : Invoke a PACS calibration OBCP during slew to source;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsPhotSlewCal.txt 
//
// Input arguments
// Type                      Description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform AOT prologue and then OBCP #13.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 DAC  30-Nov-2005 (inspired by PacsSpecSlewCal)
// 0.2 DAC 20-sep-2006 Clean up leftovers from SPEC script 
// 0.3 DAC  6-dec-2006 Adapted to simpler PHOT_fltw_move
// 0.4 DAC 27-jun-2007 SPR-3339 Always move filter wheel
// 1.0 DAC 10-oct-2007 SCR-3628 Added arguments to call aot_prologue
// 1.1 JVP 28-apr-2008 ERROR in filter_id assignation: POS A is LW for the
//     	   	       photometer (remind POS A = SW for spectro)
// 1.2 DAC 20-may-2008 Moved FLTW move into DO_PROLOGUE section                
// 2.0 SCR 4431 VDO: implemetation of data_rates
// 2.1 16-sep-2009 VD implementation 5sec delay post-cal: PACS-2039
// 2.2 08-spe-2010 VD PHS-1164 PHOT_fltw_move needs -> BB
// 
int[] procedure PacsPhotSlewCal_PHS1164 {
    bool verbose = true; // Debug_print or not 
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,64,0,0,0,0,0,0,0}]; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,64,0,0,0,0,0,0,0}]; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]; // OBCP parameters
    bool doPROLOG = true; // Perform/don't AOT prologue
    string filter = "blue2"; // PHOT filter
}{
    // Array to collect OBCP times per line
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    // Table of filter wheel positions as per MIB
    // Actually originally not blue1 = SW = POS B, and blue2 = LW = POS A for
    // the photmeter
    if(filter == "blue1") {
        string filterID = "POS B";
    }
    if(filter == "blue2") {
        filterID = "POS A";
    }
    // Long sequence to "unpack" default values from tuples
    int gain_blu = confPHOTblu[0]{0};
    int comp_mode_blu = confPHOTblu[0]{3};
    int glitch_det_blu = confPHOTblu[0]{4};
    int nb_raw_blu = confPHOTblu[0]{6};
    int gain_red = confPHOTred[0]{0};
    int comp_mode_red = confPHOTred[0]{3};
    int glitch_det_red = confPHOTred[0]{4};
    int nb_raw_red = confPHOTred[0]{6};
    int nb_cycles_obs_cal = confOBCP[0]{0};
    int nb_SRC_REF = confOBCP[0]{3};
    int nb_rdouts_plateau = confOBCP[0]{4};
    int nb_CS1_CS2 = confOBCP[0]{5};
    int chop_pos_SRC = confOBCP[0]{12};
    int chop_pos_REF1 = confOBCP[0]{13};
    int chop_pos_REF2 = confOBCP[0]{14};
    int chop_def = confOBCP[0]{17};
    int detector = confOBCP[0]{18};
    int filterPOS = confOBCP[0]{19};
    if(gain_blu == 1 && gain_red == 1) {
        string set_gain = "LOW";
    } else {
        if(gain_blu == 0 || gain_red == 0) {
            set_gain = "HIGH";
        }
    }
    // Issue PHOT_aot_prologue if demanded
    if(doPROLOG) {
        totalDUREE = PHOT_aot_prologue(set_gain,comp_mode_blu,comp_mode_red,nb_raw_blu,nb_raw_red,verbose);
        // Turn the filter wheel
        int timeFLTW = Pacs_PHOT_fltw_move(filterID);
        //  increment total duration and overheads
        totalDUREE[0] = totalDUREE[0] + timeFLTW;
        totalDUREE[4] = totalDUREE[4] + timeFLTW;
    }
    // Issue now OBCP4 for demanded filter
    // Table OBCP4params has parameter values for CAL using blue1 or blue2
    // Get params for demanded filter from OBCP4params
    string calNAME = "OBCP4params";
    // Table acces key is "cal1" or "cal2", corresponding to blue1 and blue2
    // respectively.
    string key = "cal1";
    if(filter == "blue2") {
        key = "cal2";
    }
    nb_cycles_obs_cal = ilookup(calNAME,key,"nb_cycles_obs_cal");
    nb_SRC_REF = ilookup(calNAME,key,"nb_SRC_REF");
    nb_rdouts_plateau = ilookup(calNAME,key,"nb_rdouts_plateau");
    nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    // Read CS positions from CHOPPERCSparams
    int pos_CS1 = ilookup("CHOPPERCSparams","PHOT","pos_CS1");
    int pos_CS2 = ilookup("CHOPPERCSparams","PHOT","pos_CS2");
    // Update OBCP[0] tuple with CAL-U values
    confOBCP[0]{0} = nb_cycles_obs_cal;
    confOBCP[0]{3} = nb_SRC_REF;
    confOBCP[0]{4} = nb_rdouts_plateau;
    confOBCP[0]{5} = nb_CS1_CS2;
    confOBCP[0]{15} = pos_CS1;
    confOBCP[0]{16} = pos_CS2;
    // Call now OBCP with derived parameters
    int[] dureeOBCP = OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,pos_CS1,pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
    if(verbose) {
        debug_print("*** SlewCal OBCP: " + confOBCP[0]);
        debug_print("*** SlewCal OBCP returns: " + dureeOBCP);
    }
    // Tally total durations
    for(int loop0 = 0 .. 4) {
        totalDUREE[loop0] = totalDUREE[loop0] + dureeOBCP[loop0];
    }
    if(verbose) {
        debug_print("***** SlewCal performed CAL: " + key + " requires " + totalDUREE[0] + " [sec]");
    }
    // here we have to add 5sec delay
    // this 5 sec MUST be labeled soooooo 
    PacsBbDelayScience(4);
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return totalDUREE;
}

/////////////////////////////////////////////////////////////////////////////
/// $Id: PacsPhoto.def,v 1.69 2008/05/14 11:10:32 vanessa Exp $ 
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsPhoto AOT
// CUS author    : DAC
// Script file   : PacsPhoto.def
// Return values
// Description   : 
// This AOT has to cater to three different source morphologies:
// "point", "small", and "large". Each mode requires its own pointing modes.
// Available pointing modes (reference is to JBr's document):
// NOTE: All modes include operations during SLEW and operations at end of OBS.
// NOTE: Updated based on e-mail from MS dated 3-Dec-2005 (denoted UPDATE)
// NOTE: Updated after Saclay meeting
// ==== "point"
// no nodding                         2.1  fine_pointing
// nodding (includes "hold" periods)  3.4  nodding_pointing
// UPDATE: Nodding is always needed ==> eliminate fine_pointing
//
// ==== "small"
// (raster dimensions and steps TBD; expect 2x2 or 3x3)
// no nodding ("hold" periods and repetition) 2.13 repeated_raster_with_hold
// nodding ("hold" periods and no repetition) 2.12 nodding_in_raster
// UPDATE: Nodding always used ==> nodding_in_raster
//
// ==== "large"
// Can be RASTER or SCAN (freeze mode is based upon a SCANning PointMode)
// RASTER
// no nodding ("hold" periods and repetition) 2.13 repeated_raster_with_hold
// nodding ("hold" periods and no repetition) 2.12 nodding_in_raster
// UPDATE: Nodding not used ==> raster_pointing
//
// SCAN
// There is no nodding and no chopping. "Hold" periods are allowed (mode 2.14) 
// Leg length is restricted to 20 degrees. Logic will start OBCP7 as early as
// possible (in the INIT_HOLD state). The actual duration of OBCP7 is set as
// short as possible to prevent the CAL phase to interrupt a running DEC/MEC
// sequence.
//
//
// Dependencies  : 
//
// Preconditions : 
//
// Comments      : 
// 
// History       : 0.1  2-Sep-2005 DAC
// 4.5  2-may-2007 For history before today see CVS
//                 Fixed SPR-3160 as tih = duration(OBCP7)
// 4.6 22-may-2007 SPR-3211 Include overheads in Calibration time
// 4.6.1 31-may-2007 Renamed patt to pattnod in "nodding_pointing"
// 4.6.2 27-jun-2007 SPR-3339 Correct SlewCal module    
// 4.7   20-sep-2007 SCR-3552 Add skewCorrec (in PACSyzoffsets) to pattnod
// 4.8   10-oct-2007 SCR-3628 Add Prime/Parallel to PacsPhotDefaults
// 5.0   14-jan-2008 DAC Use standard names for RA,DEC
// 6.0	 28-apr-2008 VDP SPR3689: fixed mapScanLegLength to be decimal
// ..... SCR 4196: implement Low Gain for Bright sources
// 6.1   24-jun-2008 DAC MapScanLength back to integer
// 6.2   17-jul-2008 DAC Inserted TMMarker600 at begin of each scan leg
// 7.0 	 15-sep-2008 VDP implement data_rates and HK rates SCR 4431
// 7.1	 26-sep-2008 VDP remove data_rate (already in WriteOBSID and
// 	 	     	 PHOT_aot_proplogue/epilogue
//			 Merged with DAC on the fly  modif
// 7.2	 30-sep-2008 VDP MapScanLegLength back to double
{int,int,int,double,{string,double,double,double,double,double,double}[]} obs PacsPhoto_complete {
    string blue = "blue1" in ["blue1","blue2"];
    int repFactor = 1 in [1,1500]; // Hard limit for source = "point"
    string source = "point" in ["point","small","largeRaster","largeScan","none"]; // SrceSize
    string mapScanSpeed = "high" in ["high","medium","low"]; // Scan rate
    double mapScanLegLength = 30.0 in [1.0,1200.0]; //Scan leg [arcmin]
    int mapScanNumLegs = 2 in [1,1500]; //Number of scan legs
    string mapScanAngleRef = "inst" in ["sky","inst","i+c","s+c"];
    double mapScanConstrFrom = 0.0 in [0.0,360.0];
    double mapScanConstrTo = 0.0 in [0.0,360.0];
    double mapScanAngle = 0.0 in [0.0,360.0];
    double mapScanCrossScan = 2.0 in [2.0,480.0]; // Scan separation [arcsec]
    bool mapScanHomCoverage = true;
    bool mapScanSquare = false;
    double pointStep = 2.0 in [2.0,480.0];
    double lineStep = 2.0 in [2.0,480.0];
    string mapRasterAngleRef = "inst" in ["inst","i+c"];
    double mapRasterConstrFrom = 0.0 in [0.0,360.0];
    double mapRasterConstrTo = 0.0 in [0.0,360.0];
    int m = 2 in [2,100];
    int n = 1 in [1,100];
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    bool dither = false;
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    int naifid = 0; //RA,DEC or SSO
    double fluxPntBlu = 116.0 in [0.0,2.0E7]; // Flux density in blue band mJy
    double fluxPntRed = 150.0 in [0.0,2.0E7]; // Flux density in red band mJy
    double fluxExtBlu = 116.0 in [0.0,2.0E7]; // Flux in blue band MJy/sr
    double fluxExtRed = 40.0 in [0.0,2.0E7]; // Flux in red band MJy/sr
    int obsOverhead = 180; // Slew overhead
    /* End of input section */
}{
    // Begin "pointing" section
    // Overall "verbosity"
    bool verbose = false;
    // New nodding_pointing variable
    bool startAtOFF = false;
    // Conversion to deprecated variables
    bool noddingSel = true;
    if(source == "largeRaster") {
        string largeOptions = "raster";
        bool mapRasterSel = true;
        noddingSel = false;
    }
    if(source == "largeScan") {
        largeOptions = "scan";
        mapRasterSel = false;
        noddingSel = false;
    }
    int mapRasterNumCycles = repFactor;
    // Useful variables
    // Bolo size: Short Size, i.e. 32 pixels and Long Size [arcsec]
    double boloSSize = 1.75 * 60.0;
    double boloLSize = 3.5 * 60.0;
    double boloArea = boloSSize * boloLSize;
    // 
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // Pointing mode has not been established yet
    int pointCase = 0;
    // Determine the pointing mode
    if(source == "point") {
        //     Variable needed to obtain choper throw from CAl-U
        string srcID = "pointSRC";
        //     Just for completiness, define a 1x1 raster
        m = 1;
        n = 1;
        //     Fine pointing without nodding is disallowed (pointCase remain null)
        if(!noddingSel) {
            string pointMode = "basic_fine_pointing";
            string shortDesc = "Point source (no nodding)";
            // not allowed           pointCase        = 11;
        } else {
            pointMode = "nodding_pointing";
            shortDesc = "Point source (nodding and chopping)";
            pointCase = 12;
            string yzoffsetROW = "P" + pointCase;
        }
    }
    if(source == "small") {
        srcID = "smallSRC";
        //   Obtain the size of the raster from CAL-U "SMALL_SRC_params"
        m = ilookup("SMALL_SRC_params","PHOT","mRast");
        n = ilookup("SMALL_SRC_params","PHOT","nRast");
        pointStep = dlookup("SMALL_SRC_params","PHOT","pointStep");
        lineStep = dlookup("SMALL_SRC_params","PHOT","lineStep");
        if(!noddingSel) {
            pointMode = "raster_pointing";
            shortDesc = " Small source (no nodding)";
            //         not allowed
            //           pointCase = 21;
        } else {
            pointMode = "nodding_raster_pointing";
            shortDesc = "Small source (nodding and chopping)";
            pointCase = 22;
            yzoffsetROW = "P" + pointCase;
        }
    }
    // Large source in Raster Mode
    if(source == "largeRaster") {
        srcID = "largeSRC";
        if(!noddingSel) {
            pointMode = "raster_pointing";
            shortDesc = "Large source, raster mode (chopping and no nodding)";
            pointCase = 31;
            yzoffsetROW = "P" + pointCase;
        } else {
            pointMode = "nodding_in_raster";
            shortDesc = "Large source, raster mode (chopping and nodding)";
            //         not allowed
            //           pointCase = 32;
        }
    }
    // Large source in Scan Mode
    if(source == "largeScan") {
        srcID = "largeSRC";
        pointMode = "line_scan_pointing";
        shortDesc = "Large source, line scan mode (no chopping)";
        //     For consistency
        m = 1;
        n = mapScanNumLegs;
        pointCase = 33;
        yzoffsetROW = "P" + pointCase;
    }
    // If pointCase is still 0, then something went wrong with the PointMode logic...
    if(pointCase == 0) {
        error("NODDING is incompatible with source: " + source);
    }
    // The pointing mode has been established. Continue with other input data
    // from HSPOT
    if(verbose) {
        debug_print("================> PointMode: " + pointMode);
    }
    //
    // confPHOT arrays (red and blu) compared to confSPEC
    //                       PHOT name         SPEC name
    // confPHOTred{ 0}       gain              capa_red;
    // confPHOTred{ 1}       N/A               nb_rdouts_ramp_red;
    // confPHOTred{ 2}       N/A               nb_rdouts_subramp_red;
    // confPHOTred{ 3}       same              comp_mode_red;
    // confPHOTred{ 4}       same              glitch_det_red;
    // confPHOTred{ 5}       ??                ramp_fit_alg_red;
    // confPHOTred{ 6        ??                nb_raw_red;
    // confPHOTred{ 7}       N/A               bias_r_red;
    // confPHOTred{ 8}       N/A               bias_d_red;
    //
    // Define confOBCP array.
    // NOTE: the conf arrays are inherited from PacsSpec, where the [0] element
    // represented the default values, and the [n] element represented values
    // to be used with the n-th wavelength. Here - PHOT - [0] still represents
    // the default values and [1] values corresponding to the chosen filter.
    // Could even use [1] and [2] for blue1 and blue2.... but will not!
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confPHOTblu and confPHOTred
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,0,0,0,0,0,0,0,0}];
    // Define paramsPHOT, a "tuple of tuples"
    // Estimator module returns {confPHOTblu,confPHOTred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // including a new section for Low Gain implementation SCR4196
    bool isBrightPacs = false;
    string calUFile = "isBrightPacsTrigger";
    // section defining triggering Fluxes (to be read in CALU table)
    double fluxPntRedTriggerLowGain = dlookup(calUFile,"Red","fluxPntTrigger");
    if(blue == "blue1") {
        double fluxPntBluTriggerLowGain = dlookup(calUFile,"Blue","fluxPntTrigger");
    } else {
        if(blue == "blue2") {
            fluxPntBluTriggerLowGain = dlookup(calUFile,"Green","fluxPntTrigger");
        }
    }
    double fluxExtRedTriggerLowGain = dlookup(calUFile,"Red","fluxExtTrigger");
    if(blue == "blue1") {
        double fluxExtBluTriggerLowGain = dlookup(calUFile,"Blue","fluxExtTrigger");
    } else {
        if(blue == "blue2") {
            fluxExtBluTriggerLowGain = dlookup(calUFile,"Green","fluxExtTrigger");
        }
    }
    // section test 
    if(fluxPntRedTriggerLowGain <= fluxPntRed || fluxPntBluTriggerLowGain <= fluxPntBlu || fluxExtRedTriggerLowGain <= fluxExtRed || fluxExtBluTriggerLowGain <= fluxExtBlu) {
        isBrightPacs = true;
    }
    // Obtain default values for "Prime" mode
    paramsPHOT = PacsPhotDefaults(srcID,"Prime",isBrightPacs,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    confPHOTred[0] = paramsPHOT{1};
    confOBCP[0] = paramsPHOT{2};
    // Now comes the module to estimate PACS parameters as a function of the
    // exposure time given by the user.
    // paramsPHOText (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,repeat_factor,nhold,dummy2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsPHOText = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for given HSPOT input. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("++Photo: confOBCP[0]: " + confOBCP[0]);
    }
    paramsPHOText = PacsPhotEstimatorOBCPn(pointCase,blue,repFactor,paramsPHOT,noddingSel,dither,verbose);
    // Copy estimates to respective tuples
    confPHOTblu[1] = paramsPHOText{0};
    confPHOTred[1] = paramsPHOText{1};
    confOBCP[1] = paramsPHOText{2};
    int nb_nods = paramsPHOText{3}{0};
    int repeat_factor = paramsPHOText{3}{1};
    int nhold = paramsPHOText{3}{2};
    /////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source.
    // We have to collect the duration of all TCs that will be released after the
    // PointingRequest 
    // First TC is associated with setting OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // Will call PacsPhotSlewCal to perform AOT prologue and CAL during
    // The time needed to perform these activities during slew is
    // with no prologue:
    bool doProlog = false;
    int timeSlewCal = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue));
    if(verbose) {
        debug_print("Duration of SlewCal: " + timeSlewCal);
    }
    // With prologue
    doProlog = true;
    int timeSlewCalProlog = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue));
    if(verbose) {
        debug_print("Duration of SlewCalProlog: " + timeSlewCalProlog);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsPhotCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsPhotCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // Duration of any nod leg or staring observation
    // Use OBCP3 for point source
    // Use OBCP4 for all others, except scan mode
    if(pointCase == 11 || pointCase == 12) {
        int timeOBS = duration(PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        if(verbose) {
            debug_print("TimeOBS OBCP3: " + timeOBS);
        }
    }
    if(pointCase == 22 || pointCase == 31) {
        timeOBS = duration(PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        if(verbose) {
            debug_print("TimeOBS OBCP4: " + timeOBS);
        }
    }
    if(pointCase == 33) {
        //    Estimate how long OBCP7 has to run to cover a scan leg
        //    Scan speed (CAL-U FILE in new version??). Default is "low": 10 arcsec/sec
        double rate = 10.0;
        if(mapScanSpeed == "medium") {
            rate = 20.0;
        }
        if(mapScanSpeed == "high") {
            rate = 60.0;
        }
        double timeLEG = mapScanLegLength * 60.0 / rate;
        //    Duration of OBCP7
        //    For one readout
        int nb_SRC = 1;
        confOBCP[1]{3} = nb_SRC;
        int timeOBS1 = duration(PacsPhotCommandOBCP7(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        //    For 20 readouts
        nb_SRC = 20;
        confOBCP[1]{3} = nb_SRC;
        int timeOBS2 = duration(PacsPhotCommandOBCP7(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        //    Slope per unit nb_SRC_REF, offset  
        double slope = double(timeOBS2 - timeOBS1) / 19.0;
        double offset = double(timeOBS1) - slope;
        //   Compute nb_SRC so that OBCP runs during the whole scan leg
        nb_SRC = iceil((timeLEG - offset) / slope);
        if(verbose) {
            debug_print("Needed nb_SRC to fill scan leg: " + nb_SRC);
        }
        confOBCP[1]{3} = nb_SRC;
        timeOBS = duration(PacsPhotCommandOBCP7(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
    }
    if(verbose) {
        debug_print("confOBCP[1]: " + confOBCP[1]);
        debug_print("==> Duration OBCP: " + timeOBS + " [sec] per nod; pointCase: " + pointCase);
    }
    // Finally deal with PHOT_aot_epilogue and WriteEndID
    int timeEpilogue = duration(PHOT_aot_epilogue());
    int timeEndID = duration(WriteEndID());
    timeEpilogue = timeEpilogue + timeEndID;
    if(verbose) {
        debug_print("Duration aot_epilogue: " + timeEpilogue);
    }
    // We have all elements to issue a Pointing Request and generate TCs
    // - duration of SlewCAL
    // - duration of OBS (one pointing)
    // - nb of nods or nb of raster points
    // - nhold
    ///DAC
    nhold = 0;
    ///DAC
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    //  The nodding step has been estimated already (PacsPhotDefaults). However,
    //  there are no provisions to carry that information here. Easiest is to
    //  read again the relevant CAL-U table
    //  Read nod amplitude [arcsec]
    double nodThrow = dlookup("PHOT_CHOP_params",srcID,"NOD");
    int max_dither = confOBCP[1]{1};
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("TimeSlewCal   : " + timeSlewCal);
        debug_print("TimeOBS       : " + timeOBS);
        debug_print("m/n           : " + m + "/" + n);
        debug_print("nb_nods/repeat_factor/nhold: " + nb_nods + "/" + repeat_factor + "/" + nhold);
        debug_print("NOD amplitude for " + srcID + ": " + nodThrow + " [arcsec]");
        int chpSRC = confOBCP[1]{12};
        int chpREF1 = confOBCP[1]{13};
        int chpREF2 = confOBCP[1]{14};
        debug_print("#### CHOP SRC/REF1/REF2: " + chpSRC + "/" + chpREF1 + "/" + chpREF2);
        debug_print("CHOP dither: " + max_dither);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Issue pointing request
    // Virtual aperture
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("##Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("##skewCorrec : " + skewCorrec);
    }
    // SCAN/RASTER orientation for "scan map" and "chopped raster"
    // RASTER defines mapRasterAngleRef   = "inst" in ["inst", "i+c"];
    // SCAN defines   mapScanAngleRef = "sky" in ["sky", "inst", "s+c", "i+c"]; 
    // By default S/C moves in instrument coordinates
    bool useINST = true;
    if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
        useINST = false;
    }
    // Act according to pointCase
    // POINT source, i.e. 3.4 nodding_pointing
    if(pointCase == 12) {
        //  Issue pointing request (when possible use JBr's variable names for clarity)
        //  SlewCal during slew
        string ib = "P01_0";
        int tslewmin = timeSetOBSID + timeSlewCalProlog;
        int tih = 0;
        int tfh = timeEpilogue;
        bool fixed = false;
        double pattnod = 0.0 + skewCorrec;
        int nnods = nb_nods;
        int tp = timeOBS;
        int tloadslewmin = 0;
        int nload = 0;
        int thold = timeSlewCal;
        //  int nhold        Already defined
        //  Do not start at nod position
        startAtOFF = false;
        int[] fromPntReq = nodding_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nnods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
        if(verbose) {
            debug_print("##### nodding_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tss = fromPntReq[2];
        tload = fromPntReq[3];
    }
    // SMALL source or LARGE raster with nodding
    if(pointCase == 22 || pointCase == 32) {
        //  "nodding_raster_pointing" (3.6 in Pointing document)
        ib = "P01_0";
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        tih = 0;
        tfh = timeEpilogue;
        double patt = 0.0;
        //  Chopper moves along -Y-axis
        pattnod = 270.0 + skewCorrec;
        //  Chop nodThrow was already established
        //  nodThrow = From CAL-U table
        int k = 0;
        fixed = false;
        int nrepeat = repeat_factor;
        double d1 = pointStep;
        double d2 = lineStep;
        thold = timeSlewCal;
        tp = timeOBS;
        nnods = nb_nods;
        //  New arguments for pointing request; will be dealt with next iteration
        int top = 0;
        double raoff = 0.0;
        double decoff = 0.0;
        nrepeat = repeat_factor;
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nnods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
        if(verbose) {
            debug_print("##### nodding_in_raster_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
    }
    // SMALL or LARGE source with no nodding 
    if(pointCase == 21 || pointCase == 31) {
        //  raster_pointing (mode 3.5)
        ib = "P01_0";
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        tih = 0;
        tfh = timeEpilogue;
        //  Perform raster in instrument coordinates
        fixed = false;
        //SPR-2431 Raster lines along y-axis
        patt = 90.0;
        d1 = pointStep;
        d2 = lineStep;
        tp = timeOBS;
        nrepeat = repeat_factor;
        thold = timeSlewCal;
        nhold = 0;
        k = 0;
        top = 0;
        raoff = 0.0;
        decoff = 0.0;
        fromPntReq = raster_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
        if(verbose) {
            debug_print("##### raster_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        trep = fromPntReq[4];
        tsop = fromPntReq[5];
    }
    if(pointCase == 33) {
        //   line_scan_pointing. Keep (most of) JBr's variable names
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        //  Case of homogeneous coverage
        double pi = 3.1415926535;
        //  degrees to radians    
        double dtor = 0.0;
        double rtod = 0.0;
        double halfDiag = 0.0;
        double halfDiagAngle = 0.0;
        dtor = 2.0 * pi / 360.0;
        rtod = 1.0 / dtor;
        halfDiag = sqrt(boloSSize * boloSSize + boloLSize * boloLSize) / 2.0;
        halfDiagAngle = atan(boloSSize / boloLSize) * rtod;
        // Add further constraint from RV (SPR-2889)
        // Add SPR-2699 further logic: mapScanAngleRef overrides ScanHom and ScanSquare
        if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
            mapScanHomCoverage = false;
            mapScanSquare = false;
        }
        //  Could simplify logic after SPR-2699 (mapScanHomCoverage cannot be true
        //  unless inst or i+c have been specified)
        if(mapScanHomCoverage == true && (mapScanAngleRef == "inst" || mapScanAngleRef == "i+c")) {
            mapScanCrossScan = halfDiag * (abs(sin(dtor * (mapScanAngle + 90.0 - halfDiagAngle))) + abs(cos(dtor * (90.0 - halfDiagAngle - mapScanAngle + 90.0))));
            if(verbose) {
                debug_print("New mapScancCross: " + mapScanCrossScan);
            }
        }
        // Case of square map request
        if(mapScanSquare == true && mapScanHomCoverage == true) {
            mapScanNumLegs = iceil(60.0 * mapScanLegLength / mapScanCrossScan);
            if(verbose) {
                debug_print("New mapScanNumLegs: " + mapScanNumLegs);
            }
        }
        //   OBCP7 duration with computed nb_SRC
        int startOBCP7 = 2;
        //   Use "true" duration of OBCP7
        startOBCP7 = duration(PacsPhotCommandOBCP7(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        ib = "P01_0";
        tih = 0;
        tfh = timeEpilogue;
        //   Use instrument coordinates unless HSPOT says otherwise
        fixed = false;
        if(useINST == false) {
            fixed = true;
        }
        patt = mapScanAngle;
        n = mapScanNumLegs;
        d1 = 60.0 * mapScanLegLength;
        d2 = mapScanCrossScan;
        thold = timeSlewCal;
        nhold = 0;
        nrepeat = repFactor;
        if(verbose) {
            debug_print("Map reference: " + mapScanAngleRef + "=" + fixed);
        }
        //   In this version we start OBCP7 with the state=INIT_HOLD. We set
        //   a duration of a few seconds, shorter than the shortest SCAN length.
        //   We also restart OBCP7 at the beginning of each SCAN, just to set the BBID
        //   If there are intervening HOLD states, we restart OBCP7 as soon as the 
        //   CAL is over, else data will be collected till the end of the scans
        fromPntReq = line_scan_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,n,d1,d2,rate,thold,nhold,nrepeat);
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tacc = fromPntReq[2];
        tdec = fromPntReq[3];
        tl = fromPntReq[4];
        tll = fromPntReq[5];
        trep = fromPntReq[6];
        if(verbose) {
            debug_print("##### line_scan_with_hold");
        }
        if(verbose) {
            debug_print("##### rate: " + rate + " arcsec/sec");
        }
        //   Here we record how long it takes to scan a line [sec]
        int scanTime = tl;
        //   Gather the overheads
        int scanOVER = tacc + tdec;
    }
    if(verbose) {
        debug_print("PointReq:  " + fromPntReq + " for pointCase: " + pointCase);
        debug_print("PointMode: " + pointMode);
    }
    // End of "pointing" section
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
        debug_print("++++++++++++++++++++++++ State Machine");
    }
    // Initialize some "global" variables
    int totalOBStime = 0;
    int totalOBSover = 0;
    int totalCALtime = 0;
    int totalCALover = 0;
    int nbSCANlegs = 0;
    // Issue TCs
    int[] state = [0];
    int nbOBS = 0;
    while(state[0] >= 0) {
        state = next_state();
        //// STATE = SLEW
        if(state[0] == 1) {
            if(verbose) {
                int tNOW = time();
                debug_print("=== SLEW/CAL starts at: " + tNOW);
            }
            //     Set OBSID
            WriteOBSID($OBSID);
            doProlog = true;
            int[] calTime = PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue);
            totalCALtime = totalCALtime + calTime[3];
            totalCALover = totalCALover + calTime[0];
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW/CAL ends at: " + tNOW);
                debug_print("    TotalCalTime: " + totalCALtime);
            }
        } else {
            //// STATE = INIT_HOLD
            if(state[0] == 2) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== INIT_HOLD starts at: " + tNOW);
                }
                // do nothing (OBCP7 is now entirely within the LINE state
                if(verbose) {
                    tNOW = time();
                    debug_print("=== INIT_HOLD ends at: " + tNOW);
                }
            } else {
                //// STATE = POINT
                if(state[0] == 3) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== POINT starts at: " + tNOW);
                    }
                    if(pointCase == 12) {
                        //       Observation includes chopping
                        int[] obsTime = PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                    } else {
                        //       Observation does includes chopping
                        obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                    }
                    totalOBStime = totalOBStime + obsTime[1] + obsTime[2];
                    totalOBSover = totalOBSover + obsTime[0];
                    nbOBS = nbOBS + 1;
                    if(verbose) {
                        debug_print("POINT: POINTobs: " + nbOBS);
                    }
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== POINT ends at: " + tNOW);
                    }
                } else {
                    //// STATE = CAL_HOLD
                    if(state[0] == 6) {
                        doProlog = false;
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== CAL-HOLD starts at: " + tNOW);
                        }
                        calTime = PacsPhotSlewCal(false,confPHOTblu,confPHOTred,confOBCP,doProlog,blue);
                        totalCALtime = totalCALtime + calTime[3];
                        totalCALover = totalCALover + calTime[0];
                        if(verbose) {
                            debug_print("Accumulated CALtime: " + totalCALtime);
                        }
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== CAL-HOLD ends at: " + tNOW);
                        }
                    } else {
                        //// STATE = NOD
                        if(state[0] == 7) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== NOD starts at: " + tNOW);
                            }
                            if(pointCase == 12) {
                                //       Observation includes chopping
                                obsTime = PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                            } else {
                                //       Observation does includes chopping
                                obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                            }
                            totalOBStime = totalOBStime + obsTime[1] + obsTime[2];
                            totalOBSover = totalOBSover + obsTime[0];
                            nbOBS = nbOBS + 1;
                            if(verbose) {
                                debug_print("NOD: NODobs: " + nbOBS);
                            }
                        } else {
                            //// STATE = LINE
                            if(state[0] == 8) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== SCAN starts at: " + tNOW);
                                }
                                //    Do we need code to set BBID??
                                //  Yes, use TMMarker600
                                TMMarker600();
                                // Issue OBCP7 for the duration of the scan leg
                                obsTime = PacsPhotCommandOBCP7(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                                totalOBStime = totalOBStime + scanTime;
                                totalOBSover = totalOBSover + scanTime + scanOVER;
                                nbSCANlegs = nbSCANlegs + 1;
                                // Wait scanTime and mark end of BB
                                delay(scanTime);
                                WriteEndBB();
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== SCAN mode, leg: " + nbSCANlegs);
                                    debug_print("    TotalOBSTime: " + totalOBStime);
                                    debug_print("    tacctdec    : " + scanOVER);
                                    debug_print("=== SCAN ends at: " + tNOW);
                                }
                            } else {
                                //// STATE = FINAL_HOLD
                                if(state[0] == 5) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== FinalHOLD starts at: " + tNOW);
                                    }
                                    PHOT_aot_epilogue();
                                    WriteEndID();
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== FinalHOLD ends at: " + tNOW);
                                    }
                                } else {
                                    //// STATE = END
                                    if(state[0] == -1) {
                                        tNOW = time();
                                        if(verbose) {
                                            debug_print("=== END state; time now: " + tNOW);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    int overOBS = totalOBSover - totalOBStime;
    int overCAL = totalCALover - totalCALtime;
    if(verbose) {
        debug_print("+++ OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("    totalOBStime :" + totalOBStime);
        debug_print("    totalOBSover :" + overOBS);
        debug_print("    totalCALtime :" + totalCALtime);
        debug_print("    totalCALover :" + overCAL);
    }
    // Time considerations
    // The "science" part of the observations lasts tobs seconds (tobs from
    // PointReq[0])
    // Time on source is totalOBStime. Hence
    int instrumentAndObservationOverhead = tobs - totalOBStime;
    // Begin "calculation" and report section
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "ObsMode: <B>" + shortDesc + "</B>";
    lineCnt = lineCnt + 1;
    // More pointing information
    if(pointCase == 12) {
        msgLine[lineCnt] = "<p>Chopper throw: " + nodThrow + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        double mapArea = boloArea;
        msgLine[lineCnt] = "<p>PHOTO footprint: " + dformat(boloLSize,2) + " x " + dformat(boloSSize,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>PHOTO area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    if(pointCase == 21 || pointCase == 31 || pointCase == 22) {
        msgLine[lineCnt] = "<p>Raster points/lines: " + m + "/" + n + "</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Step size: " + d1 + " x " + d2 + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        //   Mapped region
        double sizeL = boloLSize + double(m - 1) * d1;
        double sizeS = boloSSize + double(n - 1) * d2;
        mapArea = sizeL * sizeS;
        msgLine[lineCnt] = "<p>PHOTO observed size: " + dformat(sizeL,2) + " x " + dformat(sizeS,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>PHOTO observed area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    if(pointCase == 33) {
        msgLine[lineCnt] = "<p>ScanLeg: " + d1 + " [arcsec]; number of legs: " + n + "; leg separation: " + dformat(d2,1) + " [arcsec], scan speed: " + dformat(rate,2) + " [arcsec/sec]</p>";
        lineCnt = lineCnt + 1;
        //  For the mapped area assume that we scan along the Large side of bolo
        //  Size along scan line
        sizeL = d1 + boloSSize;
        //  Size covered by successive legs
        sizeS = boloLSize + double(n - 1) * d2;
        msgLine[lineCnt] = "<p>PHOTO observed size: " + dformat(sizeL,2) + " x " + dformat(sizeS,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        mapArea = sizeL * sizeS;
        msgLine[lineCnt] = "<p>PHOTO observed area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    // Nodding pattern
    msgLine[lineCnt] = "<h3> Nod pattern (as applicable)</h3>";
    lineCnt = lineCnt + 1;
    if(nb_nods == 0) {
        if(pointCase != 33) {
            msgLine[lineCnt] = " No nodding, S/C stays at nominal position<";
        } else {
            msgLine[lineCnt] = " No nodding, S/C is in line scan mode<";
        }
        lineCnt = lineCnt + 1;
    }
    if(nb_nods == 1) {
        msgLine[lineCnt] = "   A->B ";
        lineCnt = lineCnt + 1;
    }
    if(nb_nods == 2) {
        msgLine[lineCnt] = "   A->B B->A ";
        lineCnt = lineCnt + 1;
    }
    if(nb_nods > 2) {
        int aux1 = nb_nods - 2;
        msgLine[lineCnt] = "   A->B B->A and " + aux1 + " more A->B or B->A leg(s) ";
        lineCnt = lineCnt + 1;
    }
    // Add dithering bla-bla
    msgLine[lineCnt] = "<h3> Dithering information</h3>";
    lineCnt = lineCnt + 1;
    if(dither && pointCase == 12) {
        int half_dither = max_dither / 2;
        msgLine[lineCnt] = "<p> Three position spatial dithering performed with the chopper (" + max_dither + " and " + half_dither + " chopper engineering units)</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Dithering information is not applicable.</p>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "<h3> Duration information</h3>";
    lineCnt = lineCnt + 1;
    tNOW = time();
    msgLine[lineCnt] = "<p>AOT duration (w/overheads): " + tNOW + " [sec]</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p><I>(AOT duration comprises 'on-sky' plus setup and CAL during slew)</I></p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Breakdown of AOT duration:</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul><li>On-sky time (w/overheads): " + tobs + " [sec]</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>(actual on-sky time: " + totalOBStime + " [sec])</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Setup and CAL during slew (w/overheads): " + tslew + " [sec]</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>(actual calibration time: " + totalCALtime + " [sec])</li></ul>";
    lineCnt = lineCnt + 1;
    // The charged obsOverhead is the MAX between tslew, nominalOverhead 
    if(tslew > obsOverhead) {
        obsOverhead = tslew;
    }
    int tcharged = tobs + obsOverhead;
    msgLine[lineCnt] = "<p><b>AOT cost</b> (includes time to slew to source): " + tobs + " + " + obsOverhead + " = " + tcharged + " [sec]</p>";
    lineCnt = lineCnt + 1;
    // On-SRC time calculations start here
    // Uses new algorithm: on-SRC = totalOBStime*boloArea/mapArea
    // OBS times above is for all pointings. For a raster, have to divide
    // by number of raster positions, i.e. m*n
    if(pointCase != 33) {
        //   If steps are smaller than boloXSize, same sky will be seen several times
        //   Compute Short and Long dimension number of sightings (assume source is
        //   placed to maximize number of sightings, i.e. at the proper edge of bolo)
        // NOTE: exchanged pointStep and lineStep as suggested by Roland V.
        int nbShort = iceil(boloSSize / lineStep);
        //   Cannot be larger than m
        if(nbShort > m) {
            nbShort = m;
        }
        int nbLong = iceil(boloLSize / pointStep);
        //   Cannot be larger than n
        if(nbLong > n) {
            nbLong = n;
        }
        if(verbose) {
            debug_print("nbShort/nbLong: " + nbShort + "/" + nbLong);
        }
        //   Time per raster point
        double auxTIMEold = double(totalOBStime * nbShort * nbLong) / double(m * n);
        double auxTIME = double(totalOBStime) * boloArea / mapArea;
        //   Small source is a special case where by design the SRC is always in view
        if(pointCase == 22) {
            auxTIME = auxTIMEold;
        }
    } else {
        //   elementary integration time [sec] will be computed as "transit" time
        //   of the source across the BOLO detector
        //   Case of scan leg size smaller than boloSize
        double sizeAux = boloSSize;
        if(d1 <= boloSSize) {
            sizeAux = d1;
        }
        //   Assume source is 1st seen on row=1; each successive scan may see again
        //   the same sky region if mapScanCrossScan is smaller than bolo width.
        //   The number of times the same sky is scanned again:
        if(mapScanCrossScan != 0.0) {
            int nbCross = iceil(boloLSize / mapScanCrossScan);
            if(verbose) {
                debug_print("nbCross: " + nbCross);
            }
        } else {
            nbCross = repFactor;
        }
        //   nbCross cannot be larger than mapScanNumLegs
        if(nbCross > mapScanNumLegs) {
            nbCross = mapScanNumLegs;
        }
        if(verbose) {
            debug_print("nbCross: " + nbCross);
        }
        //   The "crossing time"
        double crossTime = sizeAux / rate;
        if(verbose) {
            debug_print("crossTime: " + crossTime);
        }
        //   AuxTime is "crossing time" * number of crossings * repFactor
        auxTIMEold = double(repFactor * nbCross) * crossTime;
        // New way of estimating the "observing" time     
        auxTIME = double(totalOBStime) * boloArea / mapArea;
    }
    if(verbose) {
        debug_print("AuxTIMEold: " + auxTIMEold + " [sec]");
        debug_print("AuxTIME   : " + auxTIME + " [sec]");
    }
    // Pass the pointing mode to RMS (may need it for SRC,REF considerations)
    double[] pixRMS = PacsPhotNoiseRMS(pointCase,blue,auxTIME);
    msgLine[lineCnt] = "<h3> Sensitivity information </h3>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Effective on-sky time (one spatial resolution element) : " + dformat(auxTIME,1) + " [sec]</p>";
    lineCnt = lineCnt + 1;
    // Point source or extended source
    if(pointCase == 11 || pointCase == 12) {
        msgLine[lineCnt] = "<p>Point RMS (red): " + dformat(pixRMS[0],1) + " [mJy]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Point RMS (blu): " + dformat(pixRMS[1],1) + " [mJy]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Point RMS (red): " + dformat(pixRMS[0],1) + " [mJy]; extended RMS " + dformat(pixRMS[2],2) + " [MJy/sr]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Point RMS (blu): " + dformat(pixRMS[1],1) + " [mJy]; extended RMS " + dformat(pixRMS[3],2) + " [MJy/sr]</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("PACS Photometer AOT",lineCnt,msgLine);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    // Everything below is new request from RV. Use variable names consistent
    // with input variables in PacsPhoto.def
    // Return demanded tuples
    // ID for band blue1 
    string bandBlue = "60-85";
    if(blue == "blue2") {
        bandBlue = "85-130";
    }
    double pntRMSBlue = pixRMS[1];
    // Watch out for infinite division!!
    // Better watch out for silly limits (SPR-2627)
    if(pntRMSBlue > 0.0010) {
        double pntSNBlu = fluxPntBlu / pntRMSBlue;
    } else {
        pntSNBlu = 0.0;
    }
    string bandRed = "130-210";
    double pntRMSRed = pixRMS[0];
    if(pntRMSRed > 0.0010) {
        double pntSNRed = fluxPntRed / pntRMSRed;
    } else {
        pntSNRed = 0.0;
    }
    double extRMSBlue = pixRMS[3];
    // Watch out for infinite division!!
    if(extRMSBlue > 0.0010) {
        double extSNBlu = fluxExtBlu / extRMSBlue;
    } else {
        extSNBlu = 0.0;
    }
    double extRMSRed = pixRMS[2];
    if(extRMSRed > 0.0010) {
        double extSNRed = fluxExtRed / extRMSRed;
    } else {
        extSNRed = 0.0;
    }
    {string,double,double,double,double,double,double}[] noiseSummary = [{bandBlue,fluxPntBlu,pntSNBlu,pntRMSBlue,fluxExtBlu,extSNBlu,extRMSBlue},{bandRed,fluxPntRed,pntSNRed,pntRMSRed,fluxExtRed,extSNRed,extRMSRed}];
    if(verbose) {
        debug_print("NoiseSumm: " + noiseSummary);
        debug_print("OBStime/CALtime/Overhead/chopthrow: " + totalOBStime + "/" + totalCALtime + "/" + instrumentAndObservationOverhead + "/" + nodThrow);
    }
    //  return {totalOBStime,totalCALtime,instrumentAndObservationOverhead,

    return {totalOBStime,fromPntReq[1],instrumentAndObservationOverhead,nodThrow,noiseSummary};
}

// File          : PACS_Spec_Heat_SWON.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : SWON Heaters
//
// Author        : P. Royer
//
// Arguments     : blue & red Heater currents
//
// Description   : SWON Heaters
//               :
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 07-Jun-2006 initial version by PR
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose SWON Heaters
// @comment - 
//
block PACS_Spec_Heat_SWON PACS 162 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //
    // SWON HEATERS
    //
    Pacs_DMC_SWON_BD_HEATER();
    Pacs_DMC_SWON_RD_HEATER();
    //
    // End of procedure
    //------------------
}

// $Id: PacsEng_orbit_epilogue.E2E,v 1.1 2007/08/24 08:28:44 dcesarsk Exp $
//
// Missionphase  : FM RMS
//
// Purpose       : Leave PACS in switched off mode
//
// Author        : Diego A. Cesarsky
//
// Arguments     : None
//
// Description   : Calls OBCP_safe
//
// Dependencies  : OBCP_SAFE
//
// Comments      : Use new "no_pointing" request
//
// Version       : 0.1
// History       : 0.1 14-feb-2008 Based on AOT's PacsEng_orbit_epilogue
//
obs PacsEng_orbit_epilogue {
}{
    bool execute = true;
    int tih = 0;
    int tfh = 0;
    int tp = duration(OBCP_SAFE());
    // Add needed time to set/unset OBSID
    int tset = duration(WriteOBSID($OBSID));
    int tunset = duration(WriteEndID());
    tp = tp + tset + tunset;
    // Issue PointReq
    int[] ts = no_pointing(execute,0,0,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 3) {
            //     Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            //     Call OBCP_SAFE
            OBCP_SAFE();
            //     Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// CVS comments  : $Id: PHOT_aot_prologue.txt,v 1.8 2008/05/06 13:34:53 vanessa Exp $ 
// Purpose       : SetUp of BOLO preceding AOT (but after orbit_prologue)
//
// CUS author    : DAC
// Script file   : PHOT_aot_prologue.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : Conditions and starts SPU
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 18-jan-2006 DAC
//                 0.2 21-aug-2007 SRC-3507 Indicate end of BB
//                 1.0 10-oct-2007 Added input variables after SCR-3628
//		   2.0 06-may-2008 Added Gain setup: LOW/HIGH gain obs.
int[] block PHOT_aot_prologue_DataRates PACS 212 {
    string set_gain = "LOW";
    int comp_mode_blu = 0;
    int comp_mode_red = 0;
    int nraw_blu = 3;
    int nraw_red = 3;
    bool verbose = true;
}{
    int timeStart = time();
    // Register start of BB
    WriteBBID($BBID);
    // before SPU started: set the data rate
    data_rate(120.0);
    // Define the elements of time_array
    int duree_sec = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Setup SPU
    bool startSPU = true;
    PHOT_spu_gain_setup(set_gain,comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,startSPU);
    // Mark end of BB
    WriteEndBB();
    // Synch bus
    sync();
    // Accumulated duree [milliseconds]
    int duree_msec = 0;
    duree_sec = time() - timeStart;
    // Do nothing for time being
    if(verbose) {
        debug_print("PHOT_aot_prologue: " + duree_sec + " [sec]");
    }

    return [duree_sec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
}

// CVS comments  : $Id: PacsSpecDefaults.txt,v 1.12 2007/10/25 12:15:42 dcesarsk Exp $
// Purpose       : Fill index=0 of OBCP and SPECxxx tuples with known
//                 sensible default values
//                 Starting with version 2.0, "sensible" values will be read
//                 from CAL-U files
//
// CUS author    : DAC
// Script file   : PacsSpecDefaults.txt 
//
// Input arguments
// type           name     Description
// string         throw    HSPOT defined chopper amplitude
//
// Return values
// Type    Name                  Description
// tuple   confSPECx & confOBCP  electronics and OBCP default parameters
//
// Description   : Give default values to tuples OBCP and SPEC. May
// use more information from yet to be created CAL-U files. So far
// only "throw" (HSPOT defined) appears necessary as a call argument
// Getting more SPU-like information from CAL-U is hampered by the "finite"
// size of the confSPEC tuples. May have to read CAL-U elsewhere to get
// more SPU information (SPEC_spu_setup perhaps?)
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Returns       : {{confSPECblu},{confSPECred},{confOBCP}}  
//
// confSPEC{0 -> 8} contains:
//   capa       nb_rdouts_ramp nb_rdouts_subramp  comp_mode
//   glitch_det ramp_fit_alg   nb_raw             bias_r      bias_d
//
// confOBCP{0 -> 19} contains:
// nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
// nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
// grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
// chop_pos_SRC     chop_pos_REF1    chop_pos_REF2
// chop_pos_CS1     chop_pos_CS2     chop_def
// detector         order
//
// version       : 2.0
// History       : 
// 0.1 19-may-2005 First coding
// 1.0 31-May-2005 All elements of confSPEC are now "int"
// 1.1  7-Jun-2005 Ditto for confOBCP
// 1.2 14-jun-2005 Added chopper throw in calling list
// 1.3 21-jun-2005 Renamed PacsSpecDefaults from PacsLineSpecDefaults (no
//                 difference whether LineSpec or RangeSpec)
// 1.4 24-jan-2006 Read CHOP parameters in [arcsec]; convert to ENG
// 1.5 12-apr-2006 No longer FLTW default position; new code for confOBCP{19}:
//       1=don't care/don't know; 1, 2, 3 : grating order. NOTE: no filter is
//       necessary for order = 1
// 1.6 25-apr-2006 Added comp_mode defaults
// 2.0 16-feb-2007 Access CAL-U files
//                 Moved verbose into call arguments
//                 Added yetTBD argument for future choice of CAL-U entries
// 2.1  4-mar-2007 Use special "throw" for raster w/OFF
// 2.2 14-mar-2007 Use extraConf for bright lines
// 2.3 26-mar-2007 Read most parameters from CONF_SPEC_params CAL-U file
// 2.4  4-oct-2007 SPR-3619 Missing chopper throws for CS1 and CS2
// 2.5 20-mar-2009 SCR 6353 de-hardcode nb_SRC_OFF et ...
// 3.0 17-jun-2009 DAC Adapted for new CONF_SPEC_param (without s!) table
//                 - remove "normal/bright" constraints in extraConf
//                 - new logic to read "row" table CONF_SPEC_param 
// 3.1 06-jul-2009 VD add scenario in CONF_SPEC_param
// 3.2 10-jul-2009 VD add detector sync as funct of ramp_len                
// 4.0 20-oct-2009 VD: PHS-1226 no detector sync
//
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} procedure PacsSpecDefaultsSPU {
    /* Chopper throw; needed for OBCP                                       */
    string throw = "large" in ["large","medium","small","offraster"];
    /* Spectro configuration scheme; needed for confSPEC tuple              */
    /* May take TBD values other than normal/bright                         */
    string extraConf = "normal";
    /*    int detector = 1; */
    /*    bool stopUnUsedChannelSPU = true; */
    string scenario = "none";
    /* bla bla                                                              */
    bool verbose = false;
}{
    // Define variables to be used here
    {int,int,int,int,int,int,int,int,int} confSPECblu = {0,0,0,0,0,0,0,0,0};
    {int,int,int,int,int,int,int,int,int} confSPECred = {0,0,0,0,0,0,0,0,0};
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    // Fill confSPECxxx from CAL-U file
    // NOTE: The new file CONF_SPEC_param (no final s!) is indexed by row name
    // Apart from several extra elements, its contents is that of CONF_SPEC_params
    string calU = "CONF_SPEC_param";
    // Which row of the CAL-U file?
    string confROW = "Normal0";
    if(extraConf == "bright" && scenario == "none") {
        confROW = "Fast0";
    }
    // Identify RED and BLU rows    
    if(scenario == "none") {
        string rowRED = "" + confROW + "RED";
        string rowBLU = "" + confROW + "BLU";
    } else {
        rowRED = "" + scenario + "RED";
        rowBLU = "" + scenario + "BLU";
    }
    if(verbose) {
        debug_print("SpecDef reads Table/ROWs: " + calU + " / " + rowRED + " and " + rowBLU);
    }
    // for the momewnt order is NOT passed on:
    string order = "2";
    // Read all red and blu rows
    int capa_red = ilookup(calU,rowRED,"capa");
    confSPECred{0} = capa_red;
    int capa_blu = ilookup(calU,rowBLU,"capa");
    confSPECblu{0} = capa_blu;
    int nb_rdouts_ramp_red = ilookup(calU,rowRED,"nb_rd");
    confSPECred{1} = nb_rdouts_ramp_red;
    int nb_rdouts_ramp_blu = ilookup(calU,rowBLU,"nb_rd");
    confSPECblu{1} = nb_rdouts_ramp_blu;
    int nb_rd_sub_red = ilookup(calU,rowRED,"nb_sub");
    confSPECred{2} = nb_rd_sub_red;
    int nb_rd_sub_blu = ilookup(calU,rowBLU,"nb_sub");
    confSPECblu{2} = nb_rd_sub_blu;
    int comp_mode_red = ilookup(calU,rowRED,"cmp_mde");
    confSPECred{3} = comp_mode_red;
    int comp_mode_blu = ilookup(calU,rowBLU,"cmp_mde");
    confSPECblu{3} = comp_mode_blu;
    int glitch_det_red = ilookup(calU,rowRED,"gltch_d");
    confSPECred{4} = glitch_det_red;
    int glitch_det_blu = ilookup(calU,rowBLU,"gltch_d");
    confSPECblu{4} = glitch_det_red;
    int ramp_fit_red = ilookup(calU,rowRED,"rmp_f");
    confSPECred{5} = ramp_fit_red;
    int ramp_fit_blu = ilookup(calU,rowBLU,"rmp_f");
    confSPECblu{5} = ramp_fit_red;
    int nb_raw_red = ilookup(calU,rowRED,"nb_r");
    confSPECred{6} = nb_raw_red;
    int nb_raw_blu = ilookup(calU,rowBLU,"nb_r");
    confSPECblu{6} = nb_raw_blu;
    int bias_r_red_mV = ilookup(calU,rowRED,"bias_r");
    confSPECred{7} = bias_r_red_mV;
    int bias_r_blu_mV = ilookup(calU,rowBLU,"bias_r");
    confSPECblu{7} = bias_r_blu_mV;
    int bias_d_red_mV = ilookup(calU,rowRED,"bias_d");
    confSPECred{8} = bias_d_red_mV;
    int bias_d_blu_mV = ilookup(calU,rowBLU,"bias_d");
    confSPECblu{8} = bias_d_blu_mV;
    // Fill now confOBCP tuple
    int grat_start_pos = 500000;
    confOBCP{8} = grat_start_pos;
    // Chopper and grating expected at their default positions
    int chop_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    int grat_def_pos = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    confOBCP{10} = grat_def_pos;
    confOBCP{17} = chop_def;
    // Position filter wheel at default position
    //   int fw_pos       = ilookup("SPEC_MEC_Defaults","Spectroscopy","FW");
    // Initialize to don't care/don't know
    int fw_pos = 1;
    confOBCP{19} = fw_pos;
    // initialise defaults OBCPs parameters
    calU = "OBCPDefault";
    int nb_up_down = ilookup(calU,order,"nb_up_down");
    confOBCP{0} = nb_up_down;
    int nb_SRC_OFF = ilookup(calU,order,"nb_SRC_OFF");
    confOBCP{3} = nb_SRC_OFF;
    int nb_ramps_plateau = ilookup(calU,order,"nb_ramps_plateau");
    confOBCP{4} = nb_ramps_plateau;
    int nb_CS1_CS2 = ilookup(calU,order,"nb_CS1_CS2");
    confOBCP{5} = nb_CS1_CS2;
    // Read chopper positions [arcsec] and convert to ENG units
    // Chopper angles
    calU = "SPEC_CHOP_params";
    // Read angles
    double auxSRC = dlookup(calU,throw,"SRC");
    double auxREF1 = dlookup(calU,throw,"REF1");
    double auxREF2 = dlookup(calU,throw,"REF2");
    // Convert into ENG values
    string convU = "SPEC_CHOP_sky";
    int onSRC = PacsReadChopSky(convU,auxSRC);
    int onREF1 = PacsReadChopSky(convU,auxREF1);
    int onREF2 = PacsReadChopSky(convU,auxREF2);
    // Special logic for raster with OFF: we chop between SRC and CS1   
    if(throw == "offraster") {
        // If raster w/OFF, lookup chopper CS1 position (already in ENG)
        calU = "CHOPPERCSparams";
        onREF1 = ilookup(calU,"SPEC","pos_CS1");
        onREF2 = onREF1;
    }
    if(verbose) {
        debug_print("SpecDef:chopSRC  " + auxSRC + " [arcsec] -> " + onSRC + " [ENG]");
        debug_print("SpecDef:chopREF1 " + auxREF1 + " [arcsec] -> " + onREF1 + " [ENG]");
        debug_print("SpecDef:chopREF2 " + auxREF2 + " [arcsec] -> " + onREF2 + " [ENG]");
    }
    confOBCP{12} = onSRC;
    confOBCP{13} = onREF1;
    confOBCP{14} = onREF2;
    // SPR-3619. Chopper position for CS1 and CS2
    // Read table CHOPPERCSparams
    calU = "CHOPPERCSparams";
    int chop_pos_CS1 = ilookup(calU,"SPEC","pos_CS1");
    int chop_pos_CS2 = ilookup(calU,"SPEC","pos_CS2");
    confOBCP{15} = chop_pos_CS1;
    confOBCP{16} = chop_pos_CS2;
    //  if(stopUnUsedChannelSPU) {
    //       confOBCP{18} = detector;
    // } else {
    int detector = 1;
    if(nb_rdouts_ramp_blu >= nb_rdouts_ramp_red) {
        detector = 1;
        confOBCP{18} = detector;
    }
    if(nb_rdouts_ramp_blu < nb_rdouts_ramp_red) {
        detector = 2;
        confOBCP{18} = detector;
    }
    //    }

    return {confSPECblu,confSPECred,confOBCP};
}

// Mission phase : Performace Verification Phase
//
// Purpose : PCD req.1.1.10 Explore the time constant after flux change for
//                          a flux levels using a CS and the background
//
// Author : Koryo Okumura
//
// Version : Wed Jul 29 08:47:30 EDT 2009
//
// CUS script : procedure Phot_bandpassDirect
//
// Argument :
//   string biasTable = "BOLObias_standard_high" : Bias table file name containing the initial values
//   string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
//   int sideField = 7134 : Chopper angle for the FOV next to BB2
//   int chop_pos_CS2 = 21196 : Chopper angle for BB2
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description :
//   + All the biases are set group by group
//     except for VH, VL, VRL and VHBLIND
//   + Loop over 8 PACS chopper frequencies
//   +   Loop over 3 different biases (set group by group)
//   + The 4 biases are set to a safe value for caution
//   Signal plateau length provided by PACS chopper movement : [40, 2, 3, 4, 6, 8, 10, 16] readouts
//
// Dependencies : Previously obtaind data at high gain (PCD req.1.1.1bis)
//
// Comments : generated by IA script : cus_PVph_timeCont()
//                     SCR PACS-1873
//
procedure Phot_bandpassDirect {
    string biasTable = "BOLObias_standard_low"; // Bias table file name containing the initial values
    string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
    int sideField = 7134; // Chopper angle for the FOV next to BB2
    int chop_pos_CS2 = 21196; // Chopper angle for BB2
}{
    //
    //**********************************************
    // Flux is 1.6pW on the bleu
    //     and 7.1pW on the red detector
    //**********************************************
    //
    //*******************************
    // Select Filter A (110 microns)
    //*******************************
    PHOT_fltw_move("POS A");
    //
    //*******************************
    // Bias setting of the detectors
    //*******************************
    //
    PHOT_change_biases(biasTable,"DIRECT",gain);
    //
    // Set the PACS chopper at the central position
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //************************
    // Set DPU for Burst mode
    //************************
    Pacs_DPU_SET_BUS_LIST("ENABLE");
    //
    //
    //*****************************************************
    // PACS chopper cycle with 40 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,39,0,0,211,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,39,0,0,211,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,39,0,0,211,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 2 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,1,0,0,4220,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,1,0,0,4220,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,1,0,0,4220,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 3 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,2,0,0,2814,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,2,0,0,2814,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,2,0,0,2814,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 4 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,3,0,0,2110,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,3,0,0,2110,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,3,0,0,2110,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 6 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,5,0,0,1407,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,5,0,0,1407,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,5,0,0,1407,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 8 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,7,0,0,1055,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,7,0,0,1055,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,7,0,0,1055,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 10 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,9,0,0,844,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,9,0,0,844,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,9,0,0,844,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 16 readouts per plateau
    //*****************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6026781703902877 volts)
    Pacs_BOLC_SET_VH_G1(1.6026781703902877);
    // Set group 1 bol bias 02 (VL) to -0.19732182960971223 volts)
    Pacs_BOLC_SET_VL_G1(-0.19732182960971223);
    // Set group 1 bol bias 03 (VRL) to 0.39266637855393405 volts)
    Pacs_BOLC_SET_VRL_G1(0.39266637855393405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151740948533162 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.151740948533162);
    // Set group 2 bol bias 01 (VH) to 1.5852905432077415 volts)
    Pacs_BOLC_SET_VH_G2(1.5852905432077415);
    // Set group 2 bol bias 02 (VL) to -0.2147094567922586 volts)
    Pacs_BOLC_SET_VL_G2(-0.2147094567922586);
    // Set group 2 bol bias 03 (VRL) to 0.3879398114614454 volts)
    Pacs_BOLC_SET_VRL_G2(0.3879398114614454);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1441453531989163 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1441453531989163);
    // Set group 3 bol bias 01 (VH) to 1.5887248661108317 volts)
    Pacs_BOLC_SET_VH_G3(1.5887248661108317);
    // Set group 3 bol bias 02 (VL) to -0.2112751338891683 volts)
    Pacs_BOLC_SET_VL_G3(-0.2112751338891683);
    // Set group 3 bol bias 03 (VRL) to 0.3903225752984104 volts)
    Pacs_BOLC_SET_VRL_G3(0.3903225752984104);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1475905080892783 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1475905080892783);
    // Set group 4 bol bias 01 (VH) to 1.6064147917831493 volts)
    Pacs_BOLC_SET_VH_G4(1.6064147917831493);
    // Set group 4 bol bias 02 (VL) to -0.19358520821685066 volts)
    Pacs_BOLC_SET_VL_G4(-0.19358520821685066);
    // Set group 4 bol bias 03 (VRL) to 0.38765194191292107 volts)
    Pacs_BOLC_SET_VRL_G4(0.38765194191292107);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1456475032522273 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.1456475032522273);
    // Set group 5 bol bias 01 (VH) to 1.3491824972844575 volts)
    Pacs_BOLC_SET_VH_G5(1.3491824972844575);
    // Set group 5 bol bias 02 (VL) to -0.05081750271554245 volts)
    Pacs_BOLC_SET_VL_G5(-0.05081750271554245);
    // Set group 5 bol bias 03 (VRL) to 0.4000270638803278 volts)
    Pacs_BOLC_SET_VRL_G5(0.4000270638803278);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1557215990346634 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1557215990346634);
    // Set group 6 bol bias 01 (VH) to 1.39 volts)
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 volts)
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.43018350836441854 volts)
    Pacs_BOLC_SET_VRL_G6(0.43018350836441854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1871917099730656 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.1871917099730656);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,15,0,0,528,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2113316610677285 volts)
    Pacs_BOLC_SET_VH_G1(2.2113316610677285);
    // Set group 1 bol bias 02 (VL) to -0.38866833893227165 volts)
    Pacs_BOLC_SET_VL_G1(-0.38866833893227165);
    // Set group 1 bol bias 03 (VRL) to 0.4134530748713457 volts)
    Pacs_BOLC_SET_VRL_G1(0.4134530748713457);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764551556834357 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764551556834357);
    // Set group 2 bol bias 01 (VH) to 2.1557440250096214 volts)
    Pacs_BOLC_SET_VH_G2(2.1557440250096214);
    // Set group 2 bol bias 02 (VL) to -0.4442559749903786 volts)
    Pacs_BOLC_SET_VL_G2(-0.4442559749903786);
    // Set group 2 bol bias 03 (VRL) to 0.3841225053019669 volts)
    Pacs_BOLC_SET_VRL_G2(0.3841225053019669);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.139664720483517 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.139664720483517);
    // Set group 3 bol bias 01 (VH) to 2.1831125129318534 volts)
    Pacs_BOLC_SET_VH_G3(2.1831125129318534);
    // Set group 3 bol bias 02 (VL) to -0.41688748706814654 volts)
    Pacs_BOLC_SET_VL_G3(-0.41688748706814654);
    // Set group 3 bol bias 03 (VRL) to 0.4136222591376682 volts)
    Pacs_BOLC_SET_VRL_G3(0.4136222591376682);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1747183617625896 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.1747183617625896);
    // Set group 4 bol bias 01 (VH) to 2.204721097983623 volts)
    Pacs_BOLC_SET_VH_G4(2.204721097983623);
    // Set group 4 bol bias 02 (VL) to -0.3952789020163771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3952789020163771);
    // Set group 4 bol bias 03 (VRL) to 0.40385385846298777 volts)
    Pacs_BOLC_SET_VRL_G4(0.40385385846298777);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.164627075646312 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.164627075646312);
    // Set group 5 bol bias 01 (VH) to 1.7480584064745956 volts)
    Pacs_BOLC_SET_VH_G5(1.7480584064745956);
    // Set group 5 bol bias 02 (VL) to -0.2519415935254043 volts)
    Pacs_BOLC_SET_VL_G5(-0.2519415935254043);
    // Set group 5 bol bias 03 (VRL) to 0.40609166274161507 volts)
    Pacs_BOLC_SET_VRL_G5(0.40609166274161507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1624006074623914 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1624006074623914);
    // Set group 6 bol bias 01 (VH) to 1.7877339612777292 volts)
    Pacs_BOLC_SET_VH_G6(1.7877339612777292);
    // Set group 6 bol bias 02 (VL) to -0.2122660387222707 volts)
    Pacs_BOLC_SET_VL_G6(-0.2122660387222707);
    // Set group 6 bol bias 03 (VRL) to 0.4301966495677909 volts)
    Pacs_BOLC_SET_VRL_G6(0.4301966495677909);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187207569169754 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.187207569169754);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,15,0,0,528,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.844996919299442 volts)
    Pacs_BOLC_SET_VH_G1(2.844996919299442);
    // Set group 1 bol bias 02 (VL) to -0.35500308070055836 volts)
    Pacs_BOLC_SET_VL_G1(-0.35500308070055836);
    // Set group 1 bol bias 03 (VRL) to 0.4348086376160705 volts)
    Pacs_BOLC_SET_VRL_G1(0.4348086376160705);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017906545811523 volts)
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017906545811523);
    // Set group 2 bol bias 01 (VH) to 2.7581844653962597 volts)
    Pacs_BOLC_SET_VH_G2(2.7581844653962597);
    // Set group 2 bol bias 02 (VL) to -0.44181553460374057 volts)
    Pacs_BOLC_SET_VL_G2(-0.44181553460374057);
    // Set group 2 bol bias 03 (VRL) to 0.4036324915495193 volts)
    Pacs_BOLC_SET_VRL_G2(0.4036324915495193);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1625774473144768 volts)
    Pacs_BOLC_SET_VH_BLIND_G2(2.1625774473144768);
    // Set group 3 bol bias 01 (VH) to 2.8034523711849157 volts)
    Pacs_BOLC_SET_VH_G3(2.8034523711849157);
    // Set group 3 bol bias 02 (VL) to -0.39654762881508426 volts)
    Pacs_BOLC_SET_VL_G3(-0.39654762881508426);
    // Set group 3 bol bias 03 (VRL) to 0.43384893950380693 volts)
    Pacs_BOLC_SET_VRL_G3(0.43384893950380693);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.198219723636212 volts)
    Pacs_BOLC_SET_VH_BLIND_G3(2.198219723636212);
    // Set group 4 bol bias 01 (VH) to 2.811057942433223 volts)
    Pacs_BOLC_SET_VH_G4(2.811057942433223);
    // Set group 4 bol bias 02 (VL) to -0.3889420575667771 volts)
    Pacs_BOLC_SET_VL_G4(-0.3889420575667771);
    // Set group 4 bol bias 03 (VRL) to 0.414060863208262 volts)
    Pacs_BOLC_SET_VRL_G4(0.414060863208262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176561910315575 volts)
    Pacs_BOLC_SET_VH_BLIND_G4(2.176561910315575);
    // Set group 5 bol bias 01 (VH) to 2.1180579801045787 volts)
    Pacs_BOLC_SET_VH_G5(2.1180579801045787);
    // Set group 5 bol bias 02 (VL) to -0.38194201989542126 volts)
    Pacs_BOLC_SET_VL_G5(-0.38194201989542126);
    // Set group 5 bol bias 03 (VRL) to 0.39661860678274014 volts)
    Pacs_BOLC_SET_VRL_G5(0.39661860678274014);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1519623677622284 volts)
    Pacs_BOLC_SET_VH_BLIND_G5(2.1519623677622284);
    // Set group 6 bol bias 01 (VH) to 2.1666545724294903 volts)
    Pacs_BOLC_SET_VH_G6(2.1666545724294903);
    // Set group 6 bol bias 02 (VL) to -0.3333454275705098 volts)
    Pacs_BOLC_SET_VL_G6(-0.3333454275705098);
    // Set group 6 bol bias 03 (VRL) to 0.4246325535210651 volts)
    Pacs_BOLC_SET_VRL_G6(0.4246325535210651);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.18049213767443 volts)
    Pacs_BOLC_SET_VH_BLIND_G6(2.18049213767443);
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,15,0,0,528,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //************************
    // Set DPU for Burst mode
    //************************
    Pacs_DPU_SET_BUS_LIST("DISABLE");
    //
    //
    // Sychronize
    //
    sync();
}

block Pacs_CcuMonitorDefaultRecycle PACS 2101 {
}{
    PacsCcuMonitorPeriodDefault();
    sync();
}

// Missionphase  : FMIST
//
// Purpose       : Enable Grat
//
// Author        : PR
// Arguments     : 
//
// Version       : 1.0 
// History       : 1.0 29-Jul-2007 PR
//
procedure PACS_Spec_Gra_IST_Enable {
}{
    Pacs_DMC_ENABLE_GRAT_CONT();
    delay(1);
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	:  Short performance test of Chopper in IMT
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do rectangular chopping for four frequencies with OBCP27 and its
//                corresponding DMC-sequence 12.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 2.0	
// 
// History 	: 1.0 04-04-07 HD. IST tuned.
// 		 2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
obs PacsEng_Spec_Chopper_imt504 {
    /* Needed variables to call PacsEng_Spec_Chopper_imt504                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Chopper_imt504                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Chopper_imt504()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Chopper_imt504();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: SPEC_MOV_CHOP_and_GRAT.txt,v 1.2 2007/04/25 15:14:04 dcesarsk Exp $ 
// Missionphase  : EQM IMT 
//
// Purpose       :  Move chopper and Grating
//                  
// TCL author    : HF
// TCL file      : 
// CUS author    : HF 
// Script file   : SPEC_MOV_CHOP_andGRAT.txt 
//
// Input arguments none
// type    name         description
// int     chop_pos     Chopper default position
// int     grat_pos     Grating default position
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Abolute moves
//
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//
// Comments      : 
// 
// History       : 1.0 24-Mar-2005 creation by HF
//                 1.1 26-apr-2005 DAC Read grat_time from PACSParams table
//
int[] procedure SPEC_MOV_CHOP_and_GRAT {
    int chop_pos = 25000; // Chopper position
    int grat_pos = 500000; // Grating position
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: time variables may be units of number of ramps (SPEC),
    //       readouts (BOLO) or just [msec]. The calling program must 
    //       convert this count into actual duration in true time units [sec]
    //       as/when applicable.
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    // Total duration (expressed in milliseconds)
    int duration_msec = 0;
    // Assume chopper moves very fast => no influence in total duration
    Pacs_DMC_MOVE_CHOP_ABS(chop_pos);
    // For grating read positioning time from PACSparams
    int move_time = iceil(dlookup("PACSparams","grat_time","freq_time"));
    // Same in [sec]
    int move_time_sec = Msec2sec(move_time);
    //   debug_print("GRAT moves to " + grat_pos + " in " + move_time_sec + " [sec]");
    Pacs_DMC_MOVE_GRAT_ABS(grat_pos);
    duration_msec = duration_msec + move_time;
    delay(move_time_sec);
    // Time spent (not used here)
    int duree_TCs = time() - time_start;
    // All time spent here is OVR time
    duree_num = duration_msec;
    duree_OVR = duration_msec;
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

/////////////////////////////////////////////////////////////////////////////
/// $Id
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsRangeSpec AOT
//
// CUS author    : DAC
// Script file   : PacsRangeSpec.def
//
// Input arguments
// type    name         description
//
// Return values
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : If the file is called PacsRangeSpecObs.def, it is the 
//                 CUSGUI version. To use with HSPOT:
//                 - copy and rename PacsRangeSpec.def
//                 - rename module to PacsRangeSpec
//                 - remove extra code for CUSGUI
//                 - do not forget to set verbose = false
//
// History: 
// For history before 24-apr-2007 see v1.42 in CVS
// 25-apr-2007 14.4 Suppressed history before today (kept in CVS though)
//                  Use rangeSPOT throughtout (i.e. merged ranges & rangeEXT)
//  9-may-2007 14.5 SPR-3186 Use userNODcycles as map repetion for OFF
// 22-may-2007 14.6 SPR-3199 Return SRC time without overheads
// 29-may-2007 14.7 SPR-3237
// 11-jun-2007 14.8 SPR-3277 Use referenceWave (rangeSPOT{9}) for SED mode
// 20-sep-2007 14.9 SPR-3570 RA,DEC offsets may be negative
//                  SCR-3552 Read skewCorrec from PACSyzoffsets; add to pattnod
// 24-sep-2007 15.0 SPR-3581 S/N is not computed in SED mode
// 28-mar-2008 16.0 remove mapRasterRefXXX replaced by raoff,
// 	       	    decoff and refSelected (refSelected is complement to
//		    chopNod hence not used in our logics)
// 29-mar-2008 17.0 Removed section computing ABS or REL offsets: now an HSPOT
//   	       	    functionality
// 28-apr-2008 18.0 raoff and decoff had the wrong range: in dgrees now
// 22-apr-2009 19.0 SPR5447: added keyWL as fnct of order+filter comb.
// 23-apr-2009 20.0 VD SPR 6482
// 12-may-2009 21.0 VD SED setup bug fix
// 29-jul-2009 22.0 VD: implement ABBA chop (OBCP35), for sci block, and  Cal block (BBID 350)
// 20-oct-2009 23.0 VD: PHS-1225 
// 04-dec-2009 24.0 VD PHS-1272 PHS1274
// 07-dec-2009 25.0 PHS-1282
// 09-dec-2009 26.0 VD adapeted to PHS-1285
//
{int,int,int,{string,double[],double[],double[],string,double[],double[],double[],string,double[],double[],double[]}[]} obs PacsCal_PacsRangeSpec {
    /* "rangeSPOT" is a tuple defined by HSPOT                                 */
    /*  It contains                                                            */
    /* {id, bluEdge, redEdge, repeatFactor, lineFlux, contFlux, lineWidth,     */
    /*  fluxUnitSel, widthUnitSel, refWave}                                    */
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [];
    /*------------- following only to use CUS interface -------------------------*/
    string[] rangeId = ["Interesting range"];
    double[] bluWave = [55.0]; // blue limit in [55.0,220.0]
    double[] redWave = [60.0]; // red limit in [55.0,220.0]
    int repeatLine = 1 in [0,10];
    double[] lineFlux = [111.0]; // Line Flux in [0.0,10000.0]
    double[] lineWidth = [400.0]; // line width in [0.0,1000.0]
    string[] widthUnit = ["kms"]; // width unit in ["kms","micron"]
    double[] lcontFlux = [111.11]; // continuum flux in [0.0,10000.0]
    double[] refWave = [60.0];
    /*------------- above only to use CUS interface -------------------------*/
    int userNODcycles = 1 in [1,100];
    string orderSel = "order3" in ["order2","order3","sed2","sed3","sed4","sedb2a","sedb2b","sedb3a"];
    bool chopNod = true;
    string density = "nyquist" in ["nyquist","high"];
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    string throw = "large" in ["large","medium","small"];
    string source = "point" in ["point","dithered","large"];
    double mapRasterAngle = 0.0 in [0.0,360.0];
    int m = 2 in [2,32];
    int n = 1 in [1,32];
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    int naifid = 0; // RA,DEC or SSO
    double pointStep = 2.0 in [0.0,480.0];
    double lineStep = 2.0 in [0.0,480.0];
    bool refSelected = false; // OFF position Needed
    double raoff = 0.0 in [0.0,360.0]; // units in degrees
    double decoff = 0.0 in [-90.0,90.0]; // units in degrees
    int obsOverhead = 180; // Slew overhead
    bool verbose = true;
}{
    //*--------- following only when using CUS interface -------------------*/
    int rangeIdLength = length(rangeId);
    int rangeLength = length(rangeSPOT);
    if(rangeLength == 0) {
        for(int rloop00 = 0 .. rangeIdLength - 1) {
            // checking order's relevance for SED
            if(orderSel == "sed3" || orderSel == "sed4") {
                if(bluWave[rloop00] == 55.0 && redWave[rloop00] == 60.0) {
                    error("Reference wavelength should be comprised between 55.0 and 73.0");
                }
            } else {
                rangeSPOT[rloop00] = {rangeId[rloop00],bluWave[rloop00],redWave[rloop00],repeatLine,lineFlux[rloop00],lcontFlux[rloop00],lineWidth[rloop00],"",widthUnit[rloop00],refWave[rloop00]};
            }
        }
    }
    //*--------- above only when using CUS interface -------------------*/
    // Boolean variables "range" and "sedXXX" are mutually exclusive for HSPOT. For 
    // time being I will use them independently of each other
    // Specifying bool sed = true is a special case of predefined ranges.
    // 30-oct-2006
    // Variables "sed" or "range" have disappeared from front end. Define as
    bool range = true;
    bool sed = false;
    if(orderSel == "sed2" || orderSel == "sed3" || orderSel == "sed4" || orderSel == "sedb2a" || orderSel == "sedb2b" || orderSel == "sedb3a") {
        range = false;
        sed = true;
    }
    // Yet to be defined symbol to access CAL-U file info for detector setup
    // May come from HSPOT front-end in the future
    // The future has come!!!
    string confTable = "normal";
    // In SED or nyquist sample, we use the option "bright"   
    if(sed || density == "nyquist") {
        confTable = "bright";
    }
    // mapOff no longer an input variable but still used elsewhere 
    bool mapOff = !chopNod;
    // to make sure that noone gets funny idea about refSelected
    refSelected = !chopNod;
    // New parameter for nodding_pointing
    bool startAtOFF = false;
    // Variable "grating" has disapeared from the front end. Since it's used by
    // several modules, I keep it with its new (default) definition
    string grating = "nyquist";
    // OFF pointing only when in raster mode
    if(mapOff && source != "large") {
        error("NOD = false only allowed for large sources");
    }
    // Start of "Pointing" section
    // 
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // In "sed" mode, rangeSPOT is filled by module PacsRangeSpecSed
    if(!range) {
        //   Define the RefWave as the mean value of bluWave and redWave
        //   double meanRef = (rangeSPOT[0]{1} + rangeSPOT[0]{2})/2.0;
        // SPR-3277  Save waveRef first!
        // Catch case of rangeSPOT not being defined
        int theLength = length(rangeSPOT);
        if(theLength == 0) {
            error("ERROR! Need a reference wavelength for the SED observation (see UM)");
        }
        // caught! Now extract wavelength
        double waveRef = rangeSPOT[0]{9};
        // SPR-3581. Save information to compute S/N 
        double contFlux = rangeSPOT[0]{5};
        //    Fill rangeSPOT with SED information
        int repeatSed = 0;
        rangeSPOT = PacsRangeSpecSed(orderSel,repeatSed);
        // Insure that user given reference is within order range
        // 
        double redRangeBluEdge = 0.0;
        double redRangeRedEdge = 0.0;
        if(orderSel == "sedb2a") {
            redRangeBluEdge = dlookup("SPEC_BAND_params","b2aSR1","BLU");
            redRangeRedEdge = dlookup("SPEC_BAND_params","b2aSR1","RED");
        }
        if(orderSel == "sedb2b") {
            redRangeBluEdge = dlookup("SPEC_BAND_params","b2bLR1","BLU");
            redRangeRedEdge = dlookup("SPEC_BAND_params","b2bLR1","RED");
        }
        if(orderSel == "sedb3a") {
            redRangeBluEdge = dlookup("SPEC_BAND_params","b3aLR1","BLU");
            redRangeRedEdge = dlookup("SPEC_BAND_params","b3aLR1","RED");
        }
        // Insure that user given reference is within order range
        //         if(waveRef < rangeSPOT[0]{1} || waveRef > rangeSPOT[0]{2}) {
        //            error("Reference wave must be comprised between " + rangeSPOT[0]{1} + " and " + rangeSPOT[0]{2} + " for " + orderSel);
        //        }
        debug_print("2 waveRef: " + waveRef);
        if(waveRef < rangeSPOT[0]{1} || waveRef > redRangeRedEdge) {
            error(" OutSide: Reference wave must be comprised between  [" + rangeSPOT[0]{1} + "," + rangeSPOT[0]{2} + "] and [" + redRangeBluEdge + "," + redRangeRedEdge + "] for " + orderSel);
        } else {
            if(waveRef > rangeSPOT[0]{2} && waveRef < redRangeBluEdge) {
                error(" Inside: Reference wave must be comprised between  [" + rangeSPOT[0]{1} + "," + rangeSPOT[0]{2} + "] and [" + redRangeBluEdge + "," + redRangeRedEdge + "] for " + orderSel);
            }
        }
        // Reference within limits
        rangeSPOT[0]{9} = waveRef;
        // SPR-3581. Add information to compute S/N 
        rangeSPOT[0]{5} = contFlux;
    }
    // Cannot call with empty "rangeSPOT"
    int nbRanges = length(rangeSPOT);
    int nbRanges1 = nbRanges - 1;
    if(nbRanges == 0) {
        error("STOP!! There are no spectral ranges defined!");
    }
    // No more than 10 ranges or repetitions
    int nbRangesRep = 0;
    for(int loop00 = 0 .. nbRanges - 1) {
        //  Default repetion factor is 1
        int repFactor = rangeSPOT[loop00]{3};
        if(repFactor == 0) {
            repFactor = 1;
        }
        nbRangesRep = nbRangesRep + repFactor;
    }
    if(verbose) {
        debug_print("Total ranges/repeat: " + nbRangesRep);
    }
    if(nbRangesRep > 10) {
        error("STOP!! The number of ranges/repetitions exceeds 10");
    }
    // Decode "rangeSPOT" (only if verbose mode)
    if(verbose) {
        for(int iiii = 0 .. nbRanges1) {
            debug_print("RANGE or SED: " + orderSel);
            debug_print("Wave from/to : " + rangeSPOT[iiii]{1} + "/" + rangeSPOT[iiii]{2});
            debug_print("RefWave      : " + rangeSPOT[iiii]{9});
            debug_print("repeat factor: " + rangeSPOT[iiii]{3});
        }
    }
    // Establish now the applicable Pointing Mode (use same pointCase convention
    // used in PacsPhoto and PacsLineSpec)
    // Pointing mode is still undefined
    int pointCase = 0;
    // FinePointingMode with setup time
    if(source == "point") {
        //    For completiness define a 1x1 raster
        m = 1;
        n = 1;
        //    without nodding
        if(!chopNod) {
            string pointMode = "fine_pointing";
            string userMode = "Point source (no nodding";
            pointCase = 11;
            string yzoffsetROW = "S" + pointCase;
        } else {
            //    with nodding      
            pointMode = "composite_nodding";
            userMode = "Point source (nodding)";
            pointCase = 12;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For source "dithered" use predetermined raster parameters
    if(source == "dithered") {
        m = ilookup("SMALL_SRC_params","SPEC","mRast");
        n = ilookup("SMALL_SRC_params","SPEC","nRast");
        pointStep = dlookup("SMALL_SRC_params","SPEC","pointStep");
        lineStep = dlookup("SMALL_SRC_params","SPEC","lineStep");
        //    Raster mode without noding
        if(!chopNod) {
            pointMode = "repeated_raster_with_hold";
            userMode = "Small source (dithering and no nodding)";
            pointCase = 21;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Small source (dithering and nodding)";
            pointCase = 22;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For source "large" user given raster parameters
    if(source == "large") {
        //    Raster mode without noding
        if(mapOff) {
            chopNod = false;
            pointMode = "raster_pointing";
            userMode = "Large source (raster w/OFF, no nodding)";
            pointCase = 30;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Large source (nodding)";
            pointCase = 32;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For symmetrical chopping, virtual apertures are dependent on the chopper
    // throw. 
    // Use special throw value in case of raster w/OFF as we chop between SRC and 
    // CS1
    if(mapOff) {
        throw = "offraster";
    }
    // Add this information to the CALU key entry
    yzoffsetROW = throw + "" + yzoffsetROW;
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("     PointCase ID: " + pointCase);
        debug_print("     PointMode   : " + pointMode);
        debug_print("     CALU entry  : " + yzoffsetROW);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Check that rangeSPOT is commensurate with U-CAL SPEC_BAND_params; get
    // grating positions on the fly
    // NOTE: rangeInfo is defined as 
    //       {typeOBS,order,blu_grat,red_grat,gratStep,bluWave,redWave}
    {string,int,int,int,int,double,double}[] rangeInfo = PacsRangeSpecCheckFillRange(rangeSPOT,density,grating,orderSel,verbose);
    if(verbose) {
        for(int loopA = 0 .. nbRanges1) {
            debug_print("++RangeInfo: " + rangeInfo[loopA]);
        }
    }
    // Reject invalid ranges; abort CUS if invalid ranges are present
    for(int loop000 = 0 .. nbRanges1) {
        if(rangeInfo[loop00]{1} == 0) {
            error("Demanded range " + rangeInfo[loop000]{5} + "-" + rangeInfo[loop000]{6} + " [microns] is out of allowed boundaries");
        }
    }
    // rangeInfo contains all the relevant information. We can sort here, either
    // by wavelength or by start grating position. Create arrays to be sorted
    // Define array of wavelengths and start grating positions; create "order" array
    // in case we want to enforce the no order mixing rule
    double[] rangeWave = [0.0];
    double[] rangeGrat = [0.0];
    int[] orders = [0];
    // order array as float for sort algorithm
    double[] dorder = [0.0];
    // Populate the arrays
    for(int loop0 = 0 .. nbRanges1) {
        rangeWave[loop0] = rangeInfo[loop0]{5};
        //   SORT algorithm requires float input!
        rangeGrat[loop0] = double(rangeInfo[loop0]{2});
        orders[loop0] = rangeInfo[loop0]{1};
        dorder[loop0] = double(rangeInfo[loop0]{1});
    }
    // To reject forbidden order combination, count how many orders
    int nORDER1 = 0;
    int nORDER2 = 0;
    int nORDER3 = 0;
    for(int loop2 = 0 .. nbRanges1) {
        if(orders[loop2] == 1) {
            nORDER1 = nORDER1 + 1;
        }
        if(orders[loop2] == 2) {
            nORDER2 = nORDER2 + 1;
        }
        if(orders[loop2] == 3) {
            nORDER3 = nORDER3 + 1;
        }
    }
    if(nORDER2 != 0 && nORDER3 != 0) {
        //     Report band limits
        double[] band2 = SPEC_BAND_read("2");
        double[] band3 = SPEC_BAND_read("3");
        error("Combination of 2nd (" + band2[0] + "-" + band2[1] + " mic) and 3rd (" + band3[0] + "-" + band3[1] + " mic) grating orders is not allowed");
    }
    // Reject lines not belonging to authorized order
    if(nORDER2 != 0 && orderSel == "order3") {
        error("You have chosen " + orderSel + " but have specified one/several order2 lines");
    }
    if(nORDER3 != 0 && orderSel == "order2") {
        error("You have chosen " + orderSel + " but have specified one/several order3 lines");
    }
    // Determine the filter needed with given lines
    // No filter needed, i.e. ORDER=1
    // This case is history: 
    // HSPOT proposes order 1&2 or 1&3, reported as 2 or 3; filter=1 is no
    // longer possible
    int filter = 1;
    // Determine filter based on HSPUT input
    if(orderSel == "order2" || orderSel == "sed2" || orderSel == "sed4" || orderSel == "sedb2b") {
        filter = 2;
    }
    if(orderSel == "order3" || orderSel == "sed3" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        filter = 3;
    }
    if(verbose) {
        debug_print("ORDER array: " + orders + "; FILTER: " + filter);
        debug_print("The whole OBS will be performed with filter " + filter);
    }
    // Sort by order
    //   int [] sortIndex = SortProc(verbose,dorder);
    // Sort grat_pos from smallest to largest
    int[] sortIndex = SortProc(verbose,rangeGrat);
    // Sort by wavelengths (from blue to red)
    // int sortIndex = SortProc(verbose,rangeWave);
    // Recast "rangeSPOT" and rangeInfo according to the ordered grating 
    // positions
    {string,double,double,int,double,double,double,string,string,double}[] sortRanges = clone(rangeSPOT);
    {string,int,int,int,int,double,double}[] sortRangeInfo = clone(rangeInfo);
    for(int reSORT = 0 .. nbRanges1) {
        //    Reversed sort
        // No reverse SORT (start observations with filter A)
        //    int revSORT           = nbRanges1 - reSORT;
        int revSORT = reSORT;
        int sortedIndex = sortIndex[revSORT];
        sortRanges[reSORT] = rangeSPOT[sortedIndex];
        sortRangeInfo[reSORT] = rangeInfo[sortedIndex];
    }
    // The tuple arrays confOBCP, confSPECred, and confSPECblu play a major
    // role. They contain the parameters related to commanding different PACS
    // subsystems. They are susceptible of changing with the observing conditions.
    // Hence, they have to be watched for changes since these imply sending one or
    // more TCs (usually invoking a building block)
    // Define confOBCP array
    // confOBCP{0 -> 19} contains:
    // nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
    // nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
    // grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
    // chop_pos_SRC     chop_pos_REF1    chop_pos_REF2
    // chop_pos_CS1     chop_pos_CS2     chop_def
    // detector         order
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confSPECblu and confSPECred
    // confSPEC{0 -> 8} contains:
    //   capa       nb_rdouts_ramp nb_rdouts_subramp  comp_mode
    //   glitch_det ramp_fit_alg   nb_raw             bias_r      bias_d
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // Estimator module returns {confSPECblu,confSPECred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    // Obtain default values
    // NEW. Saturation and capacitor/samples choice
    // Most SPEC configuration values are obtained from CONF_SPEC_params (read
    // in PacsSpecDefaults). Have to analyze given fluxes for each reference
    // wavelength. It may happen that a saturation situation will be found
    // Review the reference wavelengths, obtain telescope background, and PSF
    // fraction
    for(int rangeLOOP0 = 1 .. nbRanges) {
        int range1 = rangeLOOP0 - 1;
        waveRef = sortRanges[range1]{9};
        contFlux = sortRanges[range1]{5};
        //    Obtain background and PSF fraction from CALU
        double telBckg = interpolate("SPEC_BCKG_FRAC","BackG",waveRef);
        double psfFrac = interpolate("SPEC_BCKG_FRAC","FracPnt",waveRef);
        debug_print("SATUR. Wave  " + waveRef);
        debug_print("SATUR. Flux  " + contFlux);
        debug_print("SATUR. Backg " + telBckg);
        debug_print("SATUR. PSF   " + psfFrac);
        debug_print("SATUR. Order " + sortRangeInfo[range1]{1});
    }
    paramsSPECdef = PacsSpecDefaults(throw,confTable,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // Here comes the module to estimate PACS parameters as a function of the
    // exposure time given by the user. This is the pilar of the
    // whole AOT logic.
    //Define tuple to contain the "variable" parameters
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPEC = clone(paramsSPECdef);
    // paramsSPECext (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,nb_up_dn,aux1,aux2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for each wavelength. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("confOBCP[0]: " + confOBCP[0]);
    }
    int nbNods = 0;
    double waveMAXnods = 0.0;
    // Accumulated total OBS time
    int totalOBS = 0;
    for(int rangeLOOP = 1 .. nbRanges) {
        range1 = rangeLOOP - 1;
        // OBCP 35
        //        paramsSPECext = PacsRangeSpecEstimatorOBCP27(sortRanges[range1],sortRangeInfo[range1],paramsSPEC,chopNod,verbose);
        paramsSPECext = PacsRangeSpecEstimatorOBCP35(sortRanges[range1],sortRangeInfo[range1],paramsSPEC,chopNod,verbose);
        //    Copy estimates to respective tuples
        confSPECblu[rangeLOOP] = paramsSPECext{0};
        confSPECred[rangeLOOP] = paramsSPECext{1};
        confOBCP[rangeLOOP] = paramsSPECext{2};
        //    nb_nods below is the quantity used by Estimator to compute its duration
        int nb_nods = paramsSPECext{3}{0};
        //     
        if(verbose) {
            debug_print("confOBCP[" + rangeLOOP + "]: " + confOBCP[rangeLOOP]);
        }
        //    Accumulated time
        totalOBS = totalOBS + paramsSPECext{3}{2};
    }
    if(verbose) {
        debug_print("Minimum required time: " + totalOBS + " [sec] for " + nb_nods + " nod cycles");
    }
    if(chopNod) {
        nbNods = userNODcycles;
        if(verbose) {
            debug_print("The PointReq will contain " + nbNods + " nod cycles");
        }
    } else {
        nbNods = 0;
    }
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Estimated total OBStime (SRC+REF) for requested ranges: " + totalOBS + "[sec]</p>";
    lineCnt = lineCnt + 1;
    int nodTotal = nbNods * totalOBS;
    if(chopNod) {
        msgLine[lineCnt] = "<p>With the specified NOD count, " + nbNods + ", the total OBS time amounts to " + nodTotal + "[sec]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Since no NOD was specified the total OBS time is equal" + " to the estimated SRC+REF time. OBS times can be changed" + " by specifying the line(s) repeat factor</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("Accumulated SRC+REF time estimation",lineCnt,msgLine);
    // Messages on general Detector/SPU parameters
    lineCnt = 0;
    msgLine[lineCnt] = "<p>Red channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECred[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    int subRamps = confSPECred[0]{1} / confSPECred[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECred[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECred[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Blue channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECblu[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    subRamps = confSPECblu[0]{1} / confSPECblu[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECblu[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECblu[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Selected PACS setup parameters",lineCnt,msgLine);
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source
    // First operation is to set the OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    if(verbose) {
        debug_print("Duration WriteOBSID: " + timeSetOBSID);
    }
    // Will call PacsSpecSlewCal to perform AOT prologue and CAL during
    // slew to source. Establish an array of key wavelengths, one per order,
    // commensurate with user given wavelengths
    double keyWL = PacsSpecKeyWaves(orderSel,refWave);
    double[] keyWAVE = [keyWL];
    //   double [] keyWAVE = PacsRangeSpecKeyWaves(sortRangeInfo);
    int nbKeyWAVE = 1;
    //   int nbKeyWAVE = length(keyWAVE);
    if(verbose) {
        debug_print("keyWAVES " + keyWAVE);
    }
    // With latest versions of CommandOBCP35 the grating is
    // supposed to be left by SlewCal at the position needed for the 1st line
    // The OBCPs will leave the grating at that same position
    int frstLstGratPos = confOBCP[1]{8};
    if(verbose) {
        debug_print("MAIN:keyWAVES " + keyWAVE);
        debug_print("MAIN:SlewCal should leave grating at: " + frstLstGratPos);
    }
    // Time needed to perform these activities during slew (includes AOTprologue)
    bool doAOTprologue = true;
    int timeSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel));
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during slew: " + timeSlewCal);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsSpecCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsSpecCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // IMPORTANT NOTE: the duration may be different for the first cycle through 
    // all wavelengths than for the following ones owing to differing initial state.
    // However, all steps have been taken so that PACS starts the actual observation
    // in the same state as it would be left at the end of any wavelength cycle
    // Duration of any nod leg or staring observation
    // OBCP 35
    //    int timeOBS = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
    int timeOBS = duration(PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,verbose));
    if(verbose) {
        debug_print("Duration OBCP35: " + timeOBS + " [sec] per nod;  nb_nods: " + nb_nods);
    }
    // Get duration of module to close AOT operations
    // This includes parking the grating
    // Park position
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // The grating was left by OBCPs at frstLstGratPos
    int timeEpilogue = duration(SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose));
    // WriteEndID will be the last TC; get its duration
    int timeEndID = duration(WriteEndID());
    if(verbose) {
        debug_print("Duration WriteEndID: " + timeEndID);
    }
    // Summary of relevant data collected so far
    // timeSlewCal: duration of the leading CAL, including AOT_prologue
    // timeOBS    : duration of a single pointed OBS
    // nb_nods    : number of nods for staring mode or per raster position
    // chopNod : invoke nodding or not (nb_nods = 0 is equivalent to no nod)
    // m, n       : raster nb_points/line, nbRanges per RREQ
    // pointStep,lineStep: more raster parameters
    // ra,dec: more pointing parameters
    //
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Ready to issue a FinePointing mode with/without nodding or
    // a RasterReq with/without nodding. Either one needs some time during
    // slew to perform leading CAL.
    // Make sure that the Preq is possible (possible reason for failure: too short
    // dwell time - currently 10 sec
    int minTdwell = 10;
    if(timeOBS < minTdwell) {
        error("Estimated dwell time is too short. Perhaps your range span is too small");
    }
    //
    // The chopper throws have been read already (PacsSpecDefaults) and angles
    // have been converted into ENG units (OBCPconf). Here,angles are needed in 
    // [arcsec]; easiest is to read again the relevant CAL-U table. 
    // Read chopper position SRC and REF1 [arcsec]
    // 
    // PHS-1225
    double chopAngleSrc = dlookup("SPEC_CHOP_params",throw,"SRC");
    double chopAngleRef = dlookup("SPEC_CHOP_params",throw,"REF1");
    double nodAngleSrc = dlookup("SPEC_NOD_params",throw,"SRC");
    double nodAngleRef = dlookup("SPEC_NOD_params",throw,"REF1");
    // The total nodThrow = chopperTotalThrow
    double nodThrow = abs(nodAngleSrc - nodAngleRef);
    if(verbose) {
        debug_print("PacsSpecDef: CHOP/NOD params SRC/REF/NOD: " + chopAngleSrc + "/" + chopAngleRef + "/" + nodThrow);
    }
    // Issue pointing request (when possible use JBr's variable names for clarity)
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    // Virtual aperture
    string ib = "P02_0";
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("#### skewCorrec : " + skewCorrec);
    }
    int tslewmin = timeSetOBSID + timeSlewCal;
    int tinithold = 0;
    int tfinalhold = timeEndID + timeEpilogue;
    int tp = timeOBS;
    double patt = 0.0;
    double pattnod = 270.0 + skewCorrec;
    int k = 0;
    int thold = 0;
    int nhold = 0;
    int nload = 0;
    int tloadslewmin = 0;
    bool fixed = true;
    if(pointCase == 11) {
        //   FinePointingMode without nodding
        int[] fromPntReq = basic_fine_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,yoffset,zoffset,tp);
    }
    if(pointCase == 12) {
        //   FinePointingMode with nodding, section 3.4
        ib = "P02_0";
        //   Nodding angle is specified wrt spacecraft
        fixed = false;
        //   Nodding is along y axis, opposite chop
        pattnod = 270.0 + skewCorrec;
        fromPntReq = nodding_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nbNods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
    }
    if(pointCase == 21 || pointCase == 31) {
        //   RasterMode without nodding, section 3.5
        ib = "P02_0";
        //   Raster in instrument coordinates
        fixed = false;
        double d1 = pointStep;
        double d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        k = 0;
        int ncover = 1;
        //   New arguments for pointing request; will be dealt with next iteration
        int top = 0;
        raoff = 0.0;
        decoff = 0.0;
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,ncover,thold,nhold,k,top,raoff,decoff);
    }
    if(pointCase == 30) {
        //   RasterMode with no nodding and OFF, section 3.5
        ib = "P02_0";
        //   SPR-3237: fix is true, patt is inherited from HSPOT
        fixed = true;
        patt = mapRasterAngle;
        //   Raster steps
        d1 = pointStep;
        d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        // OFF periodicity (here at beginning and at end of raster)
        k = m * n;
        //   The number of repetions is given in this case by the NOD count SPR-3186
        int nrepeat = userNODcycles;
        if(nrepeat == 0) {
            nrepeat = 1;
        }
        //   Same Tobs during OFF that during "SRC"
        top = tp;
        trepeatmin = 0;
        tloadmin = 0;
        nload = 0;
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
    }
    if(pointCase == 22 || pointCase == 32) {
        //   RasterMode with nodding, section 3.6
        ib = "P02_0";
        //   Raster in instrument coordinates
        fixed = false;
        //   Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        //   Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        k = 0;
        nrepeat = 1;
        //   New arguments for pointing request; will be dealt with next iteration
        top = 0;
        raoff = 0.0;
        decoff = 0.0;
        trepeatmin = 0;
        tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nbNods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
    }
    // Parameters returned by PointReq
    if(verbose) {
        debug_print("=====> Return from " + pointMode + ": " + fromPntReq);
    }
    //Info from API (nomenclature from Jon Br)
    tobs = fromPntReq[0];
    tslew = fromPntReq[1];
    ///////////////////////// end of "timing" section //////////////////////////
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
    }
    if(verbose) {
        int tNOW = time();
        debug_print("=== Issued PointReq Time_now: " + tNOW);
    }
    // Issue TCs
    int[] stateVar = [0];
    int nbOBS = 0;
    int nbOFF = 0;
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            //       Write OBSID (logical part of SlewCal)
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            int[][] calTime = PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel);
            //       Define accumulated Cal time
            int[][] sumUpCalTime = calTime;
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW ends at: " + tNOW);
                debug_print("    SumUpCalTime: " + sumUpCalTime);
            }
        } else {
            if(stateVar[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== POINT starts at: " + tNOW);
                }
                //                int[][] obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);	       
                int[][] obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                nbOBS = nbOBS + 1;
                //       Logic to sum up obsTime
                if(nbOBS == 1) {
                    int[][] sumUpObsTime = obsTime;
                }
                if(nbOBS > 1) {
                    sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("    SumUpObsTime: " + sumUpObsTime);
                    debug_print("=== POINT ends at: " + tNOW);
                }
            } else {
                if(stateVar[0] == 4) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF starts at: " + tNOW);
                    }
                    //                    obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);		   
                    obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                    nbOFF = nbOFF + 1;
                    //       Logic to sum up obsTime
                    if(nbOFF == 1) {
                        int[][] sumUpOffTime = obsTime;
                    }
                    if(nbOFF > 1) {
                        sumUpOffTime = SumFunction(obsTime,sumUpOffTime);
                    }
                    if(verbose) {
                        tNOW = time();
                        debug_print("    SumUpOffTime: " + sumUpOffTime);
                        debug_print("=== OFF ends at: " + tNOW);
                    }
                } else {
                    if(stateVar[0] == 7) {
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== NOD started at: " + tNOW);
                        }
                        //                        obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);		       
                        obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                        nbOBS = nbOBS + 1;
                        //       Logic to sum up obsTime
                        if(nbOBS == 1) {
                            sumUpObsTime = obsTime;
                        }
                        if(nbOBS > 1) {
                            sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                        }
                        if(verbose) {
                            tNOW = time();
                            debug_print("    SumUpObsTime: " + sumUpObsTime);
                            debug_print("=== NOD ends at: " + tNOW);
                        }
                    } else {
                        if(stateVar[0] == 6) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== HOLD starts at: " + tNOW);
                            }
                            calTime = PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel);
                            sumUpCalTime = SumFunction(calTime,sumUpCalTime);
                            if(verbose) {
                                tNOW = time();
                                debug_print("    SumUpCalTime: " + sumUpCalTime);
                                debug_print("=== HOLD ends at: " + tNOW);
                            }
                        } else {
                            if(stateVar[0] == 5) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== FinalHOLD  starts at: " + tNOW);
                                }
                                SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose);
                                WriteEndID();
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== FinalHOLD  ends at: " + tNOW);
                                }
                            } else {
                                if(stateVar[0] == -1) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== AOT ends at: " + tNOW);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    if(verbose) {
        debug_print("OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
    }
    // The original concept of returning durations did not take into 
    // account the bandwidth of the TC bus (2 TCs/sec). The "real" 
    // duration is given by the result from the "duration()" function. Hence
    // the true total duration of the SlewCal phase is given by
    ///   calTime[0] = timeSlewCal;
    // as a result, the overheads are now
    ///   calTime[4] = calTime[0]-(calTime[1]+calTime[2]+calTime[3]); 
    if(verbose) {
        debug_print("Slew & HOLD Cal return: " + sumUpCalTime);
    }
    //original comments for OBCP27 - modified OBCP35 
    // The same holds true for the OBCP35 phase. However, I cannot make the
    // break-down by wavelength (the OBCP35 duration is given for ALL ranges).
    // We may add up the SRC, CAL, and OVR components of OBCP35 duration. For
    // this we need a tuple so we can add the wavelength and other relevant
    // information to the (per wave) duration arrays.
    //
    //    infoArray[] contains a "fixed" global information part
    //    infoArray[0]: {Slew,   intTime,TotDur,nbRanges,nnods,m*n}
    //    infoArray[1]: {Point,  intTime,TotDur,nbRanges,nnods,m*n}
    //    infoArray[2]: {AOTinfo,intTime,TotDur,nbRanges,nnods,m*n}
    // and per wavelength array(s):
    //    [waveSTART,waveEND,order,gratStep,nbGratSteps,TOT,SRC,REF,CAL,OVR]
    // TotDur as given by duration(); TOT,SRC,REF,CAL,OVR are also in [sec]
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    // Fill infoArray with data from SlewCal
    // Instead of using timeSlewCal, use tslew time returned by PointReq
    // infoArray[0] = {{"SlewCal",0.0,timeSlewCal,0,0,0},[{0.,0.,0,0,0,0,0,0,0,0}]};
    infoArray[0] = {{"SlewCal",0.0,tslew,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Fill infoArray with data from OBCP35
    // Compute integration time per chopper plateau
    // intTime = nbRamps/plateau x nbRdouts/ramp x sampleInterval 
    // Sampling frequency
    double specSample = dlookup("PACSparams","spec_sample","freq_time");
    // Number of readouts per ramp
    int nbRdoutRamp = confSPECblu[1]{1};
    // NOTE: WAIT=1 are now counted as useful ramps; hence
    int nbRampPlateau = confOBCP[1]{4} + 1;
    // 
    double intTime = double(nbRampPlateau * nbRdoutRamp) / specSample;
    if(verbose) {
        debug_print("MAIN:AOT          : " + userMode);
        debug_print("MAIN:Rdouts/ramp  : " + nbRdoutRamp);
        debug_print("MAIN:Ramps/plateau: " + nbRampPlateau);
        debug_print("MAIN:IntTime (incl. WAIT=1): " + intTime);
    }
    // Replace timeOBS (per raster and per nod) with tobs from PntReq (matching
    // change in PacsProcessInfoArray)   
    // infoArray[1] = {{userMode,intTime,timeOBS,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    infoArray[1] = {{userMode,intTime,tobs,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    for(int loop3 = 0 .. nbRanges1) {
        //     Create element [loop3]
        infoArray[1]{1}[loop3] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy from/to wavelengths
        infoArray[1]{1}[loop3]{0} = sortRanges[loop3]{1};
        infoArray[1]{1}[loop3]{1} = sortRanges[loop3]{2};
        //     copy the grating order
        infoArray[1]{1}[loop3]{2} = sortRangeInfo[loop3]{1};
        //     copy the grating step
        infoArray[1]{1}[loop3]{3} = sortRangeInfo[loop3]{4};
        //     copy the number of grating step
        infoArray[1]{1}[loop3]{4} = confOBCP[loop3 + 1]{6};
        //     copy other data from obsTime
        infoArray[1]{1}[loop3]{5} = sumUpObsTime[loop3][0];
        infoArray[1]{1}[loop3]{6} = sumUpObsTime[loop3][1];
        infoArray[1]{1}[loop3]{7} = sumUpObsTime[loop3][2];
        infoArray[1]{1}[loop3]{8} = sumUpObsTime[loop3][3];
        infoArray[1]{1}[loop3]{9} = sumUpObsTime[loop3][4];
    }
    // Add more data from SlewCal to infoArray
    for(int loop4 = 0 .. nbKeyWAVE - 1) {
        //     for some reason it has to be "initialized"
        infoArray[0]{1}[loop4] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the wavelength
        infoArray[0]{1}[loop4]{0} = keyWAVE[loop4];
        //     copy other data from sumUpCalTime
        infoArray[0]{1}[loop4]{5} = sumUpCalTime[loop4][0];
        infoArray[0]{1}[loop4]{6} = sumUpCalTime[loop4][1];
        infoArray[0]{1}[loop4]{7} = sumUpCalTime[loop4][2];
        infoArray[0]{1}[loop4]{8} = sumUpCalTime[loop4][3];
        infoArray[0]{1}[loop4]{9} = sumUpCalTime[loop4][4];
    }
    // Further update of infoArray: add information from AOT_prologue    
    infoArray[0]{1}[nbKeyWAVE] = {0.0,0.0,0,0,0,0,0,0,0,0};
    // Copy OVR and TOT times
    infoArray[0]{1}[nbKeyWAVE]{9} = calTime[nbKeyWAVE][4];
    infoArray[0]{1}[nbKeyWAVE]{5} = calTime[nbKeyWAVE][4];
    // Copy the number of ranges observed and the number of key waves used
    infoArray[0]{0}{3} = nbKeyWAVE;
    infoArray[1]{0}{3} = nbRanges;
    // Copy the number of nod cycles and the number of raster points visited
    infoArray[1]{0}{4} = nbNods;
    infoArray[1]{0}{5} = m * n;
    // The duration of the OBS phase is given by timeObsEnd - timeSlewCal
    // Now get it from PntReq: timeObsPhase == tobs
    // int timeObsPhase = timeObsEnd - timeSlewCal - 1 - timeSetOBSID;
    if(verbose) {
        debug_print("CalSlew phase lasted [sec]: " + timeSlewCal);
        debug_print("The OBS phase lasted [sec]: " + tobs);
    }
    // Slew time during the OBS phase is then given by
    int timeSlewObs = tobs - nbOBS * timeOBS;
    if(verbose) {
        debug_print("Total slew during OBS [sec]: " + timeSlewObs);
    }
    // Populate the 3rd dimension of infoArray: global timing and AOT information
    // timeObsEnd is the total duration of the AOT
    infoArray[2] = {{"RangeSpec",0.0,timeObsEnd,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Case of SmallSrc with dithering
    if(source == "dithered") {
        infoArray[1]{0}{0} = "SmSrcDither";
    }
    // Use available entries to convey m,n, and nbNods
    infoArray[2]{0}{3} = m;
    infoArray[2]{0}{4} = n;
    // PointSources are also seen with composite_nodding
    if(pointMode == "fine_pointing" || pointMode == "composite_nodding") {
        infoArray[2]{0}{3} = 1;
        infoArray[2]{0}{4} = 1;
    }
    infoArray[2]{0}{5} = nbNods;
    // Case of raster/w OFF, repeated map
    if(source == "large" && mapOff) {
        infoArray[1]{0}{0} = "RasterOFF";
        infoArray[2]{0}{5} = nrepeat;
    }
    // Process the information contained in infoArray
    // NOTE: since implementing waveRef and fluxes, have to pass also 
    //       sortRanges and sortRangesExt data to ProcessInfoArray
    // aotID is no longer needed as only used for Range
    // but orderSel is needed by PacsSpecRMS
    // SPR-2927 Return bigTuple with information for plotting
    // Add nbOBS and nbOFF to ProcessInfoArray
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = PacsProcessInfoArrayRange(infoArray,sortRanges,confOBCP,orderSel,obsOverhead,nbOBS,nbOFF,verbose);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    //////// Silly code to convert bigTuple into smallTuple ////////////////////
    // bigTuple is too big for HSPOT. I have to remove the 1st double[] to
    // please HSPOT. Create smallTupleN
    {string,double[],double[],double[],string,double[],double[],double[],string,double[],double[],double[]}[] smallTuple = [{"1",[0.0],[0.0],[0.0],"2",[0.0],[0.0],[0.0],"3",[0.0],[0.0],[0.0]}];
    // Old returned tuples
    {int,int,{{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[]} returnTuple = {fromPntReq[0],fromPntReq[1],bigTuple};
    // Copy returnTuple onto smallTuple
    nbRanges = length(bigTuple);
    // The accumulated SRC+REF time
    int accumSrceRef = 0;
    for(int loopR = 0 .. nbRanges - 1) {
        //  Use the nbRanges loop to add up SrceRef times (SRC + REF)
        accumSrceRef = accumSrceRef + infoArray[1]{1}[loopR]{6} + infoArray[1]{1}[loopR]{7};
        //  Define smallTuple
        smallTuple[loopR] = {"1",[0.0],[0.0],[0.0],"2",[0.0],[0.0],[0.0],"3",[0.0],[0.0],[0.0]};
        //   Extract vectors; retrun CONT noise in mJy
        //   First tuple is always the nominal range. Label it as RangeID + "Nominal"
        string id = sortRanges[loopR]{0} + "-nominal";
        smallTuple[loopR]{0} = id;
        double[] wave = returnTuple{2}[loopR]{0}{2};
        double[] cont = returnTuple{2}[loopR]{0}{3};
        double[] line = returnTuple{2}[loopR]{0}{4};
        int nbElem = length(wave);
        for(int loopT1 = 0 .. nbElem - 1) {
            smallTuple[loopR]{1}[loopT1] = wave[loopT1];
            smallTuple[loopR]{2}[loopT1] = 1000.0 * cont[loopT1];
            smallTuple[loopR]{3}[loopT1] = line[loopT1];
        }
        wave = returnTuple{2}[loopR]{1}{2};
        cont = returnTuple{2}[loopR]{1}{3};
        line = returnTuple{2}[loopR]{1}{4};
        nbElem = length(wave);
        //   If there is no "free" data
        id = "undefined";
        //   Else label second tuple as RangeID + "-free1"
        if(nbElem > 1) {
            id = sortRanges[loopR]{0} + "-free1";
        }
        smallTuple[loopR]{4} = id;
        for(int loopT2 = 0 .. nbElem - 1) {
            smallTuple[loopR]{5}[loopT2] = wave[loopT2];
            smallTuple[loopR]{6}[loopT2] = 1000.0 * cont[loopT2];
            smallTuple[loopR]{7}[loopT2] = line[loopT2];
        }
        wave = returnTuple{2}[loopR]{2}{2};
        cont = returnTuple{2}[loopR]{2}{3};
        line = returnTuple{2}[loopR]{2}{4};
        nbElem = length(wave);
        //   If existing, label third tuple as RangeID + "-free2"
        id = "undefined";
        if(nbElem > 1) {
            id = sortRanges[loopR]{0} + "-free2";
        }
        smallTuple[loopR]{8} = id;
        for(int loopT3 = 0 .. nbElem - 1) {
            smallTuple[loopR]{9}[loopT3] = wave[loopT3];
            smallTuple[loopR]{10}[loopT3] = 1000.0 * cont[loopT3];
            smallTuple[loopR]{11}[loopT3] = line[loopT3];
        }
        //  End loop on nbRanges
    }
    // Compute overheads as total "sky" time minus SRC+REF time
    int overPACSandSC = fromPntReq[0] - accumSrceRef;

    return {accumSrceRef,fromPntReq[1],overPACSandSC,smallTuple};
}

// Missionphase  : FM ILT
//
// Purpose	:  Performance Test of internal PACS calibration sources
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description  : We start with a heat-up of the calibration sources. 
//                After monitoring for some while the behaviour on the desired temperature of
//                both internal PACS calibration sources, we do a smaller heat-up which is followed 
//                by a cooling down. The monitoring is based on diag. HK. 
//                PTD 0.7.11 and 0.7.12 are the basis for this test. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy 
//                 
// Comments	: This script is based on the commanding during the CQM ILT Tests. 
//
// Version	: 2.0	
// 
// History      : 0.1 21-07-06 creation by HD based 
//                             on FM IMT script "SPEC_CS_fmilt071112_bb"	
//                             cool-down different then to IMT
//                0.2 24-07-06 HD. correct Missionphase.
//                0.3 24-07-06 HD. delay time adopted for testing.
//                0.4 24-07-06 HD. script works.		
//                0.5 24-07-06 HD. version number updated. 
//                0.6 24-07-06 HD. history formatted.      		       		  
//                0.7 24-07-06 HD. history formatted.
//                0.8 24-07-06 HD. description formatted.
//		  1.0 23-08-06 HD. SwOn/Enabling of CSs added.
//		  2.0 23-08-06 HD. script works.
//		  3.0 07-11-06 HD. Updated on requests by UK.
block SPEC_CS_fmilt071112_swon_cs_bb PACS 365 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //Switchon and enabling CSs
    Pacs_DMC_SWON_BB_1_CONT();
    Pacs_DMC_ENABLE_BB_1_CONT();
    Pacs_DMC_SWON_BB_2_CONT();
    Pacs_DMC_ENABLE_BB_2_CONT();
    //-------------------------------------------- 
    // Setup and start diagnostic HK for calibration sources
    //-------------------------------------------- 
    int cs_diag_hk_length = 16;
    {int}[] parlist = [{214},{445},{446},{447},{448},{459},{460},{526},{527},{528},{529},{542},{543},{544},{545},{0xffff}];
    int[] aux = [214,445,446,447,448,459,460,526,527,528,529,542,543,544,545,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(cs_diag_hk_length,parlist,check_sum);
    int diag_hk_period = 300;
    // Diagnostic HK period (in milliseconds)
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    //------------------------------------------------------------------------------
    // Heat the calibration sources up to 80 (70.5K;CS1) and 92 
    // (76.0K;CS2) Ohm --- big step
    //------------------------------------------------------------------------------
    // start temperature CS1 in Ohm
    double cs1_temp = 80.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // start temperature CS2 in Ohm 	
    double cs2_temp = 92.0;
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    //After 50 minutes of heating-up and stay on the desired temperatures do another heat-up 
    delay(3600);
    // Assume that CSs are on since long and already stabilized, monitor them for 5 minutes only
    delay(1200);
    //--------------------------------------------------------------------------------
    // Heat the calibration sources up to 85 (72.8K;CS1) and 97 (78.4K;CS2) Ohm --- small step
    //--------------------------------------------------------------------------------
    cs1_temp = 85.0;
    cs2_temp = 97.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    //After 30 minutes of heating-up and stay on the desired temperatures do cooling-down
    delay(1800);
    //------------------------------------------
    // Cool both calibration sources down to 39 (50.5K) 
    //------------------------------------------
    cs1_temp = 39.0;
    cs2_temp = 39.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    // Cool down for about 60 minutes
    delay(60);
    Pacs_DMC_STOP_DIAG_HK();
    // Mark End of Block
    WriteEndBB();
}

// $Id: 
// Purpose        : Dump memory about FPGA fixes
//                 
//
// CUS author     : VD + HF
//
// Input arguments: see after module identification
//
// Return values: none
// N/A
//
// Comments      : this has to be run once and done!
//
// History: 1.0 created
//          21-oct-2010 created VD 
//
//
block PacsFPGAMemoryDump PACS 1108 {
    /* no need for inputs this Eng will only be done once!! */
}{
    Pacs_DMC_SET_BBID($BBID);
    // Memory dump
    int mem_dumpId = 0x1100;
    int mem_dump_addr = 0xbf2;
    int dump_dataLength = 0x1053;
    Pacs_DPU_MEMORY_DUMP(mem_dumpId,mem_dump_addr,dump_dataLength);
    int iBBID = 0x40000000;
    // Write BBID to DEC/MEC
    Pacs_DMC_SET_BBID(iBBID);
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Gra_Diaghk_Setup {
    /* No variables to call PacsEng_Spec_Gra_Diaghk_Setup                        */
    int diag_hk_period = 5; // 5 msec diag hk period 
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_Diaghk_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_Diaghk_Setup(diag_hk_period)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_Diaghk_Setup(diag_hk_period);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : Pierre Royer
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 1.0 24-Nov-2008 Copy of PacsEng_CONF_grating_SFTHeII & changed default parameters -> FFT (TP-021 section 11.4.4, CONF_grating_slow_OBS)
//
//
obs PacsEng_CONF_grating {
    /* No variables to call PacsEng_CONF_grating        */
    string calUrow = "ISTSafe"; // INSTRUMENT VERSION
    string calUname = "CONFGrat";
    /* End of needed variables for PacsEng_CONF_grating */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_grating(calUname,calUrow)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_grating(calUname,calUrow);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
// File          : PACS_SwOff_chopper_ast_OBS.cus//
//
// Purpose       : Switch on chopper 
//
// Author        : HD
// CUSification  : HD
// Arguments     : 
//
// Description   : Switch off chopper
//                              
// Comments      :      
//
// Version       : 2.0 
// History       : 0.1  05-jul-2007 Initial version
// History       : 0.2  12-nov-2007 edited for SVT/PV conformance (MN)
// 		   2.0 04-mar-2008 translated into PV script VDP
//
obs PacsEng_SwOff_chopper_ast {
    /* Needed variables to call PacsEng_SwOff_chopper_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_SwOff_chopper_ast                     */
}{
    string on_off = "OFF";
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Chopper_SWON_SWOF_only(on_off)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Chopper_SWON_SWOF_only(on_off);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id: PacsEng_Phot_SPU_Setup.txt,v 1.5 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_SPU_Setup_u {
    /* No variables to call PacsEng_Phot_SPU_Setup_u                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_SPU_Setup_u                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_SPU_Setup()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_SPU_Setup();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: 
// Script file   : PacsLineSpecEstimatorOBCP28.txt 
// Purpose       : Estimate several PACS parameters for each spectral
//                 line specified by the HSPOT user
//
// CUS author    : DAC
//
// Input arguments
// type           name          Description
// tuple          lines         spectral line info from HSPOT
// tuple          waveTuple     grating info associated to "lines"
// tuple          paramsSPECdef confSPECblu & confSPECred & confOBCP
// bool           noddingSel    nodding demanded?
//
// Return values
// Type             Description
// tuple            Derived values for paramsSPECdef
//
// Description   : Fill the PACS state descriptors confSPECx & confOBCP, per
// HSPOT defined wavelength, with values obtained from several CAL-U files.
// This procedure is called once per spectral line. For each line - identified
// here by its order since this is the index into the durations CAL-U file -
// the user gives a desired observing time. The OBCP28params table lists the
// minimum duration per order, without nodding. If nodding is requested, the
// tabulated duration is increased by a factor two; this new duration becomes
// the "observing quantum". Any longer time is accomodated by increasing the
// number of nods. If no nodding is desired, a longer OBS time is accomodated
// by increasing the number of up/down cycles. NO- CHOOPER
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-may-2005 DAC OBCP27
// 		 : 1.0 11-mar-2009 VD created OBCP35
// 		 : 1.2 20-jul-2009 introduce NEW bright mode in OBCP28params
// 		 : 2.0 23-mar-2010 VD clone from 35 for 28 (unchopped grat scan)
// 		                   added OFF position logic
// 		 
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsLineSpecEstimatorOBCP28 {
    {string,double,int,double,double,double,string,string} lines = {"NONE",60.2,0,0.0,0.0,0.0,"bla","bla"}; // linesTuple HSPOT
    {double,int,int,int,int} waveTuple = {0.0,0,0,0,0}; // waveTuple          
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; // Default values
    bool noddingSel = false; // Nodding requested?
    bool faintLines = true; // Fast OBCP if false 
    bool gratScanOff = false; // use OFF params
    bool verbose = false; // print debug information
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    //////////////// Logic to obtain desired OBS time ///////////////////////////
    //
    // ORDER of the current line
    int order = waveTuple{1};
    double waveLEN = waveTuple{0};
    // User desired repetition factor for current line
    int userREPfactor = lines{2};
    // Get the "quantum" OBS time for the current order. U-CAL time doubles if 
    // nodding is allowed
    int nodFactor = 1;
    if(noddingSel) {
        nodFactor = 2;
        int nb_nods = 1;
    } else {
        nb_nods = 0;
    }
    // Grating info pertaining to the current wavelength is in waveTuple
    int nb_grat_step_up = waveTuple{3};
    int nb_grat_step_dn = waveTuple{3};
    int grat_step_up = waveTuple{4};
    int grat_step_dn = -grat_step_up;
    int grat_start_pos = waveTuple{2};
    // Get "duration related" parameters from OBCP28params U-CAL table
    string calNAME = "OBCP28params";
    // The acces key is the grating order
    // if faintline is false then NEW Keys
    if(!faintLines) {
        string key = "B" + order;
    } else {
        key = "" + order;
    }
    if(verbose) {
        debug_print("OBCP28params key: " + key);
    }
    // There is a row per order; it lists main OBCP parameters
    //Now user input int nb_up_down = ilookup(calNAME,key,"nb_up_down");
    int def_up_down = ilookup(calNAME,key,"nb_up_down");
    int nb_up_down = userREPfactor * def_up_down;
    if(gratScanOff) {
        nb_up_down = ilookup(calNAME,key,"up_dn_OFFsrce");
    }
    //    int nb_SRC_OFF = ilookup(calNAME,key,"nb_SRC_OFF");
    int nb_ramps_grat_pos = ilookup(calNAME,key,"nb_ramps_grat_pos");
    int nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    int nb_ramps_cs = ilookup(calNAME,key,"nb_ramps_cs");
    // Estimate the OBS time for this rangeInfo; estimation is for ONE nod only.
    int nb_rdouts_ramp = confSPECred{1};
    // here is 28
    int[] dureeOBCP28 = PacsDureeOBCP28(nb_up_down,nb_grat_step_up,nb_ramps_grat_pos,nb_CS1_CS2,nb_ramps_cs,nb_rdouts_ramp);
    // Use SRC/REF time alone (used to be total duration)
    int quantumOBStime = nodFactor * (dureeOBCP28[1] + dureeOBCP28[2]);
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    if(!gratScanOff) {
        // no need to repeat the message for the OFF position
        msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + waveLEN + " [&micro;m] with line repeated " + userREPfactor + " time(s)</p>";
        lineCnt = lineCnt + 1;
    }
    // This is complete fantasy; just to check the code
    //============== React on LINE/CONT fluxes ========================
    // Line and continuum flux from HSPOT
    double lineFLUX = lines{3};
    double contFLUX = lines{4};
    // Pack information into proper tuples
    confOBCP{0} = nb_up_down;
    confOBCP{1} = grat_step_up;
    confOBCP{2} = grat_step_dn;
    confOBCP{3} = 0;
    confOBCP{4} = nb_ramps_grat_pos;
    confOBCP{5} = nb_CS1_CS2;
    confOBCP{6} = nb_grat_step_up;
    confOBCP{7} = nb_grat_step_dn;
    confOBCP{8} = grat_start_pos;
    //    confOBCP { 9}  =   grat_start_time  ;
    //    confOBCP {10}  =   grat_def_pos     ;
    //    confOBCP {11}  =   grat_def_time    ;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    //  confSPECred{0} = capa_red;
    //   confSPECred{ 1} =  nb_rdouts_ramp_red;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    //int comp_mode_red = 16;
    //confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    // confSPECblu{0} = capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts_ramp_blu;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    //int comp_mode_blu = 16;
    //confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    string msgLabel = "Observing time for un-chop mode " + lines{0};
    if(!gratScanOff) {
        PacsMessageCenter(msgLabel,lineCnt,msgLine);
    }
    // Debug info
    if(verbose) {
        debug_print("EstimatorOBCP28 duration*nod: " + quantumOBStime);
    }
    int aux3 = 0;

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,nb_up_down,quantumOBStime,aux3}};
}

// CVS comments  : $Id: PacsLineSpecEstimatorOBCP27.txt,v 1.16 2007/04/25 15:14:04 dcesarsk Exp $ 
// Script file   : PacsLineSpecEstimatorOBCP27.txt 
// Purpose       : Estimate several PACS parameters for each spectral
//                 line specified by the HSPOT user
//
// CUS author    : DAC
//
// Input arguments
// type           name          Description
// tuple          lines         spectral line info from HSPOT
// tuple          waveTuple     grating info associated to "lines"
// tuple          paramsSPECdef confSPECblu & confSPECred & confOBCP
// bool           noddingSel    nodding demanded?
//
// Return values
// Type             Description
// tuple            Derived values for paramsSPECdef
//
// Description   : Fill the PACS state descriptors confSPECx & confOBCP, per
// HSPOT defined wavelength, with values obtained from several CAL-U files.
// This procedure is called once per spectral line. For each line - identified
// here by its order since this is the index into the durations CAL-U file -
// the user gives a desired observing time. The OBCP27params table lists the
// minimum duration per order, without nodding. If nodding is requested, the
// tabulated duration is increased by a factor two; this new duration becomes
// the "observing quantum". Any longer time is accomodated by increasing the
// number of nods. If no nodding is desired, a longer OBS time is accomodated
// by increasing the number of up/down cycles
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-may-2005 DAC
// 1.0 22-May-2005 DAC Input argument is just lines; tuples
//                 confXXX are now initialized by calling program
// 1.1 22-may-2005 Had to pass "index" to get waveLENGTH
// 1.2 25-may-2005 Back to original architecture using "clone"
// 1.3 31-May-2005 All elements of confSPEC are now "int"
// 1.4  2-Jun-2005 Added TotalTime as input key to OBCPparams look-up table
// 1.5  7-Jun-2005 confOBCP is all {int} now
// 1.6  9-Jun-2005 CAL file OBCPparams renamed to OBCP27params
// 2.0 16-jun-2005 Major change: scale OBS time according to number of grating
//                 steps (durations are computed for grat_steps = 35)
// 2.1 17-jun-2005 Allow integration time to be expressed
//                 per wavelength (passed in "lines")
// 2.2 26-aug-2005 Added waveTuple as input argument, suppress
//                 totalTime since now in "sortLines"
// 3.0 29-aug-2005 Renamed to PacsLineEstimatorOBCP27 since now we use OBCP#27
//                 Added noddingSel to input arguments, call lines as scalar
//                 (index nolonger needed)
// 3.1  2-sep-2005 Added verbose
// 3.2 14-sep-2005 Changed definition of "lines" (bool is the last item)
// 3.3  6-oct-2005 Duration is now computed by PacsDuree
// 3.4 11-oct-2005 Set "lines" as defined in HSPOT
// 3.5 13-oct-2005 Correct treatment of nb_nods
// 3.6 14-oct-2005 Bettering format of messages
// 3.7 11-apr-2006 Define comp_mode_xxx here (since != for SPEC and PHOT)
// 4.0 25-apr-2006 Major overhaul after Leuven
// 4.1 22-jun-2006 Variable "lines" contains width
// 4.2  8-sep-2006 Variable lines contains unit names
// 4.3 17-jan-2007 "Improved" messages
// 4.4 14-feb-2007 Use SRC/REF time only to compute quantumOBS
// 4.5 14-mar-2007 SCR-2942: bright lines
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsLineSpecEstimatorOBCP27 {
    {string,double,int,double,double,double,string,string} lines = {"NONE",60.2,0,0.0,0.0,0.0,"bla","bla"}; // linesTuple HSPOT
    {double,int,int,int,int} waveTuple = {0.0,0,0,0,0}; // waveTuple          
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; // Default values
    bool noddingSel = false; // Nodding requested?
    bool faintLines = true; // Fast OBCP if false 
    bool verbose = false; // print debug information
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    //////////////// Logic to obtain desired OBS time ///////////////////////////
    //
    // ORDER of the current line
    int order = waveTuple{1};
    double waveLEN = waveTuple{0};
    // User desired repetition factor for current line
    int userREPfactor = lines{2};
    // Get the "quantum" OBS time for the current order. U-CAL time doubles if 
    // nodding is allowed
    int nodFactor = 1;
    if(noddingSel) {
        nodFactor = 2;
        int nb_nods = 1;
    } else {
        nb_nods = 0;
    }
    // Grating info pertaining to the current wavelength is in waveTuple
    int nb_grat_step_up = waveTuple{3};
    int nb_grat_step_dn = waveTuple{3};
    int grat_step_up = waveTuple{4};
    int grat_step_dn = -grat_step_up;
    int grat_start_pos = waveTuple{2};
    // Get "duration related" parameters from OBCP27params U-CAL table
    string calNAME = "OBCP27params";
    // The acces key is the grating order
    string key = "" + order;
    // There is a row per order; it lists main OBCP parameters
    //Now user input int nb_up_down = ilookup(calNAME,key,"nb_up_down");
    int nb_up_down = userREPfactor;
    int nb_SRC_OFF = ilookup(calNAME,key,"nb_SRC_OFF");
    int nb_ramps_plateau = ilookup(calNAME,key,"nb_ramps_plateau");
    int nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    // Estimate the OBS time for this rangeInfo; estimation is for ONE nod only.
    int nb_rdouts_ramp = confSPECred{1};
    int[] dureeOBCP27 = PacsDureeOBCP27(nb_up_down,nb_grat_step_up,nb_ramps_plateau,nb_CS1_CS2,nb_SRC_OFF,nb_rdouts_ramp);
    // Use SRC/REF time alone (used to be total duration)
    int quantumOBStime = nodFactor * (dureeOBCP27[1] + dureeOBCP27[2]);
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + waveLEN + " [&micro;m] with line repeated " + userREPfactor + " time(s)</p>";
    lineCnt = lineCnt + 1;
    // This is complete fantasy; just to check the code
    //============== React on LINE/CONT fluxes ========================
    // Line and continuum flux from HSPOT
    double lineFLUX = lines{3};
    double contFLUX = lines{4};
    // Low flux use large integrating capacitor
    //    int capa_red = 0;
    //    int capa_blu = 0;
    //    if(lineFLUX <= 400.0) {
    //       capa_red = 4;
    //       capa_blu = 8;
    //   }
    //    if(lineFLUX <= 100.0) {
    //        capa_red = 12;
    //        capa_blu = 4;
    //    }
    // Pack information into proper tuples
    confOBCP{0} = nb_up_down;
    confOBCP{1} = grat_step_up;
    confOBCP{2} = grat_step_dn;
    confOBCP{3} = nb_SRC_OFF;
    confOBCP{4} = nb_ramps_plateau;
    confOBCP{5} = nb_CS1_CS2;
    confOBCP{6} = nb_grat_step_up;
    confOBCP{7} = nb_grat_step_dn;
    confOBCP{8} = grat_start_pos;
    //    confOBCP { 9}  =   grat_start_time  ;
    //    confOBCP {10}  =   grat_def_pos     ;
    //    confOBCP {11}  =   grat_def_time    ;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    // confSPECred{0} = capa_red;
    //   confSPECred{ 1} =  nb_rdouts_ramp_red;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    // int comp_mode_red = 16;
    // confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    // confSPECblu{0} = capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts_ramp_blu;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    // int comp_mode_blu = 16;
    // confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    string msgLabel = "Observing time for " + lines{0};
    PacsMessageCenter(msgLabel,lineCnt,msgLine);
    // Debug info
    if(verbose) {
        debug_print("LineEstimatorOBCP27 duration: " + quantumOBStime);
    }
    int aux3 = 0;

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,nb_up_down,quantumOBStime,aux3}};
}

// Missionphase  : FMIST
//
// Purpose       : Home Grat
//
// Author        : PR
// Arguments     : 
//
// Version       : 1.0 
// History       : 1.0 29-Jul-2007 PR
//
procedure PACS_Spec_Gra_IST_Home {
}{
    // ----------------
    // HOME THE GRATING
    // ----------------
    // Search for the origin and initialize the position encoder correctly
    // PARAM: 0 = move towards negative positions;
    //        1 = move towards positive positions;
    // Duration: max 70 sec (if the Grating param 'rate' is 3), 
    //           depending on the initial position of the grating.
    // Failure code: 0xAA: Grating controller is not enabled
    //
    int grat_home_mode = 0;
    string[] homeMode = ["NEGATIVE","POSITIVE"];
    Pacs_DMC_HOME_GRAT(homeMode[grat_home_mode]);
    delay(70);
    //
}

// $Id: PacsCal_WaveCalRaster.txt,v 1.0 2009/07/10 10:25:00 vanessad Exp $
// Missionphase		: PACS PV Phase
//
// Purpose :		Wavelength calibration and instrumental profile
// 	      	     rater without chopping
// Author		 : HF
//
// Arguments:
//
// Prerequisite 	: PACS does not need to be on nor setup for spectroscopy
//
// Description		: Uses flexible procedure WaveCalNoChop
// 			  
// Comments		:
//
// Version		: 1.0
// 
// History		: 1.0 Copied from PacsCal_WaveCalNoChop and PacsCal_WaveCalRaster Using example from PacsCal_WaveCalNoChop
//                      : 1.1 14-sep-2009 VD PHS-1173
// 			
obs PacsCal_WaveCalRaster {
    /* Spectro definitions */
    string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B"
    int order = 2; // Order selection for Slewcal
    int grat_start = 500000; // grating start position for scan
    int grat_stepsize = 200; // grating step size
    int grat_numsteps = 50; // number of grating steps in one direction
    int grat_numramps = 3; // number of ramps per grating position
    int chop_def = 664; // chopper position during grating scan
    int nb_rdout_ramp = 64; // number of readouts per ramp
    int num_updown = 1; // number of grating updown scans
    int grat_end = 496000; // position of grating after the scan
    int capa_red = 12; // Red capacitor
    int capa_blu = 12; // Blue capacitor
    double bias_r_blu = 0.01; // Bias "r" blue
    double bias_r_red = 0.01; // Bias "r" red
    double bias_d_blu = 0.1; // Bias "d" blue
    double bias_d_red = 0.042; // Bias "d" red
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp    
    int comp_mode_blu = 16; // compression mode for blue detector
    int comp_mode_red = 16; // compression mode for red detector
    int nb_raw_red = 0; // number of raw red pixels
    int nb_raw_blu = 0; // number of raw blue pixels
    /* Pointing parameters */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    double raoff = 0.0 in [0.0,360.0];
    double decoff = 0.0 in [-90.0,90.0];
    bool refSelected = false; // OFF position needed
    /* raster */
    int m = 2 in [2,100]; // Number of points in a raster line
    int n = 1 in [1,100]; // number of raster lines
    int k = 2 in [0,200]; // OFF repetition use (m*n)
    double d1 = 2.0 in [2.0,480.0]; // Raster point separation in a line [arcsec]
    double d2 = 2.0 in [2.0,480.0]; // Raster line separation [arcsec]
    bool fixed = false; // Raster in S/C (=false) or SKY coordinates (=true)
    double patt = 0.0; // Raster pattern orientation
    bool verbose = true;
}{
    // computing time for slew / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Set OBSID
    int tobsid = duration(WriteOBSID($OBSID));
    // Calibration time during slew
    // SPEC parameters for BLU and RED               
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    string throwUsage = "small";
    string extraConf = "normal";
    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // frstLstGratPos is the last position for the grating after the Cals done
    // during Slew time... must be same as observations start position: grat_pos   
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    // "N/A" in string because of indexing 0,1,2,3
    string[] choix = ["N/A","order1","order2","order3","sed4"];
    string order_str = "order" + order;
    //    if(choix[order] != "order1") {
    //        double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //    double keyWL = PacsSpecKeyWaves(order_str);
    double[] keyWAVE = [150.0];
    if(choix[order] == "order3" && fltPOS == "POS B") {
        error("Filter B and order 3 are not compatible");
    }
    if(choix[order] == "order1" && fltPOS == "POS A") {
        keyWAVE = [180.0];
    }
    if(choix[order] == "order1" && fltPOS == "POS B") {
        keyWAVE = [150.0];
    }
    if(choix[order] == "order2" && fltPOS == "POS B") {
        keyWAVE = [75.0];
    }
    if(choix[order] == "order3" && fltPOS == "POS A") {
        keyWAVE = [60.0];
    }
    // this is for extended Blue
    if(choix[order] == "order2" && fltPOS == "POS A") {
        keyWAVE = [60.0];
        choix[order] = "sed4";
    }
    // no need for SpecKeyWave!
    int tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]));
    //   } else {
    //       keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //       double keyWAVE2 = dlookup("KEY_WAVES",order_str,"KeyWave2");
    //       keyWAVE = [keyWAVE1,keyWAVE2];
    //        tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]));
    //   }
    //Initial hold
    int tih = 0;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int grat_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int tepilog = duration(SPEC_aot_epilogue(grat_start,grat_def,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of "stable" pointing
    int tp = duration(WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_end,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red));
    if(verbose) {
        debug_print("Duration of WaveCalNoChop" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    int thold = 0;
    int nhold = 0;
    int top = duration(WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_end,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red));
    int nrepeat = 1;
    //Issue PointReq
    int tslewmin = tobsid + tpacsSlewCal;
    if(verbose) {
        debug_print("Slewing time is:" + tslewmin + "sec");
    }
    int[] ts = raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            int tNOW = time();
            // slew time calibration
            WriteOBSID($OBSID);
            if(verbose) {
                debug_print("Slewing starts at :" + tNOW + " sec");
            }
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            if(choix[order] == "order1") {
                PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]);
            } else {
                PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]);
            }
            tNOW = time();
            if(verbose) {
                debug_print("Slewing ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_end,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red);
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 4) {
                    //       Call the WaveCal procedure
                    tNOW = time();
                    if(verbose) {
                        debug_print("Observation at NOD starts at :" + tNOW + " sec");
                    }
                    WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_end,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red);
                    tNOW = time();
                    if(verbose) {
                        debug_print("Observation at NOD ends at :" + tNOW + " sec");
                    }
                } else {
                    if(state[0] == 5) {
                        tNOW = time();
                        if(verbose) {
                            debug_print("Final Hold starts at :" + tNOW + " sec");
                        }
                        SPEC_aot_epilogue(grat_start,grat_def,verbose);
                        WriteEndID();
                        tNOW = time();
                        if(verbose) {
                            debug_print("Final Hold ends at :" + tNOW + " sec");
                        }
                    }
                }
            }
        }
    }
    // End of Observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose	: Condition SPU for SPECtroscopy observations
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: none
//
// Description	: Simply calling procedure "SPEC_spu_setup". See there for details.
//                  
// Dependencies : Only low level PACS TCs 
//
// Comments	: 
//
// Version	: 2.0
//               
// History	: 1.0 30-Mar-2004 Creation by PR
// 		1.1 25-oct-2005 DAC Use fit_alg = 0
// 		1.2 18-apr-2006 DAC Back to default fit_alg = 1
//                     Renamed to SPEC_xxxxx_OBS
// 		1.3 28-aug-2006 TM: clean way of calling SPEC_spu_setup, new default parameter
// 		1.4 20-nov-2006 Modified defaults for nb_ramp_subramp and ramp_fit_alg
//		2.0 04-mar-2008 translated into PV script VDp
//
obs PacsEng_Spec_spu_setup {
    /* Needed variables to call PacsEng_Spec_spu_setup                        */
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp 
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp 
    int nb_raw_spu_blu = 3; // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3; // Nb of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0; // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true; // Start SPU or not [true,false]
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_spu_setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : ILT at Garching
//
// Purpose :
//   Reduced NEP measurements for the new sequencer test
//
// Author : Koryo Okumura
//
// CUS script : procedure PHOT_redArray_DDCS_IST
//
// Argument :
//    int response_measure_time = 60; // response measure time in seconds
//    int noise_measure_time = 120; // noise measure time in seconds
//    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//
// Description :
//   + First, all 24 biases are set group by group
//   + Loop over 11 sets of 4 baisc biases (VH, VL, VRL, VH-BLIND) are set group by group
//   + Set PACS chopper on CS1 to measure the noise
//   + Loop over 11 sets of 4 baisc biases (VH, VL, VRL, VH-BLIND) are set group by group
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_oldSeq_IST(0)
//
// Version : Thu Oct 04 20:12:46 CEST 2007
//
procedure PHOT_redArray_DDCS_IST {
    int response_measure_time = 60; // response measure time in seconds
    int noise_measure_time = 120; // noise measure time in seconds
    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
}{
    int operand = 0;
    int posCS1 = -21500;
    int posCS2 = 21500;
    //*********************************
    // Apply the old sequencer setting
    //*********************************
    //
    PACS_Phot_Sequencer_Setup();
    //
    //*******************************
    // Select Filter A (110 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //***********************************************
    //***********************************************
    //
    //	Bias setting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(biasFile,1);
    PHOT_set_bias_volt(biasFile,2);
    PHOT_set_bias_volt(biasFile,3);
    PHOT_set_bias_volt(biasFile,4);
    PHOT_set_bias_volt(biasFile,5);
    PHOT_set_bias_volt(biasFile,6);
    //
    //**************************
    // Sequence mode : Sb_Sref
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sb_Sref (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sb_Sref");
    //# P 09 01 00 00
    operand = 0x9010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // Set gain high
    Pacs_BOLC_SET_GAIN("HIGH");
    //
    //**********************************************
    // Set the PACS chopper at the central position
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(0);
    //
    //**********************************************************************
    //                       Response Measurement
    // Expected fluxes : 1.7 and 2.0pW on the blue
    //               and 5.3 and 6.2pW on the red
    //**********************************************************************
    //
    TMMarker600();
    //***********************************************************
    // Bias 1 (Vh-Vl)blue = 1.0 Volts, (Vh-Vl)red = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G1(0.99);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.2875928897414196 Volts
    Pacs_BOLC_SET_VRL_G1(0.2875928897414196);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.78435816010763 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.78435816010763);
    // Set group 2 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G2(0.99);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.2976890643549285 Volts
    Pacs_BOLC_SET_VRL_G2(0.2976890643549285);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.7946385038224304 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.7946385038224304);
    // Set group 3 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G3(0.99);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.2921869021406959 Volts
    Pacs_BOLC_SET_VRL_G3(0.2921869021406959);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.8111181679623898 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.8111181679623898);
    // Set group 4 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G4(0.99);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.2833032550752384 Volts
    Pacs_BOLC_SET_VRL_G4(0.2833032550752384);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.8038951101792082 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.8038951101792082);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3346340277410602 Volts
    Pacs_BOLC_SET_VRL_G5(0.3346340277410602);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8466792279676985 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8466792279676985);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.32636237036822335 Volts
    Pacs_BOLC_SET_VRL_G6(0.32636237036822335);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8367532617835844 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8367532617835844);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)blue = 1.2 Volts, (Vh-Vl)red = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G1(1.19);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.3577080013822565 Volts
    Pacs_BOLC_SET_VRL_G1(0.3577080013822565);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9420622421434064 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9420622421434064);
    // Set group 2 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G2(1.19);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.36696811904468774 Volts
    Pacs_BOLC_SET_VRL_G2(0.36696811904468774);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9515329512935697 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9515329512935697);
    // Set group 3 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G3(1.19);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.3640303856110917 Volts
    Pacs_BOLC_SET_VRL_G3(0.3640303856110917);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9482056457093682 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9482056457093682);
    // Set group 4 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G4(1.19);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3523579205628669 Volts
    Pacs_BOLC_SET_VRL_G4(0.3523579205628669);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9603646239045185 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9603646239045185);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4064368830411808 Volts
    Pacs_BOLC_SET_VRL_G5(0.4064368830411808);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8950576820742784 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8950576820742784);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.39643145192214363 Volts
    Pacs_BOLC_SET_VRL_G6(0.39643145192214363);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8837201139355604 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8837201139355604);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)blue = 1.4 Volts, (Vh-Vl)red = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.3525857926230986 Volts
    Pacs_BOLC_SET_VH_G1(1.3525857926230986);
    // Set group 1 bol bias 02 (VL) to -0.047414207376901184 Volts
    Pacs_BOLC_SET_VL_G1(-0.047414207376901184);
    // Set group 1 bol bias 03 (VRL) to 0.3926244201072773 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926244201072773);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.976547929868054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.976547929868054);
    // Set group 2 bol bias 01 (VH) to 1.3374255283716547 Volts
    Pacs_BOLC_SET_VH_G2(1.3374255283716547);
    // Set group 2 bol bias 02 (VL) to -0.06257447162834509 Volts
    Pacs_BOLC_SET_VL_G2(-0.06257447162834509);
    // Set group 2 bol bias 03 (VRL) to 0.38802799053825054 Volts
    Pacs_BOLC_SET_VRL_G2(0.38802799053825054);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9723540060682856 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9723540060682856);
    // Set group 3 bol bias 01 (VH) to 1.341267296137658 Volts
    Pacs_BOLC_SET_VH_G3(1.341267296137658);
    // Set group 3 bol bias 02 (VL) to -0.058732703862341994 Volts
    Pacs_BOLC_SET_VL_G3(-0.058732703862341994);
    // Set group 3 bol bias 03 (VRL) to 0.38970189090896923 Volts
    Pacs_BOLC_SET_VRL_G3(0.38970189090896923);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9735810667835696 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9735810667835696);
    // Set group 4 bol bias 01 (VH) to 1.352746675150765 Volts
    Pacs_BOLC_SET_VH_G4(1.352746675150765);
    // Set group 4 bol bias 02 (VL) to -0.04725332484923491 Volts
    Pacs_BOLC_SET_VL_G4(-0.04725332484923491);
    // Set group 4 bol bias 03 (VRL) to 0.3856108728986011 Volts
    Pacs_BOLC_SET_VRL_G4(0.3856108728986011);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9932003720526934 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9932003720526934);
    // Set group 5 bol bias 01 (VH) to 1.320583197395035 Volts
    Pacs_BOLC_SET_VH_G5(1.320583197395035);
    // Set group 5 bol bias 02 (VL) to -0.07941680260496485 Volts
    Pacs_BOLC_SET_VL_G5(-0.07941680260496485);
    // Set group 5 bol bias 03 (VRL) to 0.4116095244710064 Volts
    Pacs_BOLC_SET_VRL_G5(0.4116095244710064);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055742088043621 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055742088043621);
    // Set group 6 bol bias 01 (VH) to 1.3562697990163495 Volts
    Pacs_BOLC_SET_VH_G6(1.3562697990163495);
    // Set group 6 bol bias 02 (VL) to -0.04373020098365052 Volts
    Pacs_BOLC_SET_VL_G6(-0.04373020098365052);
    // Set group 6 bol bias 03 (VRL) to 0.43594530124025854 Volts
    Pacs_BOLC_SET_VRL_G6(0.43594530124025854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.011921670046162 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.011921670046162);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)blue = 1.6 Volts, (Vh-Vl)red = 1.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4783736198117614 Volts
    Pacs_BOLC_SET_VH_G1(1.4783736198117614);
    // Set group 1 bol bias 02 (VL) to -0.12162638018823857 Volts
    Pacs_BOLC_SET_VL_G1(-0.12162638018823857);
    // Set group 1 bol bias 03 (VRL) to 0.392515090355521 Volts
    Pacs_BOLC_SET_VRL_G1(0.392515090355521);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9764399412468519 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9764399412468519);
    // Set group 2 bol bias 01 (VH) to 1.4615686869832905 Volts
    Pacs_BOLC_SET_VH_G2(1.4615686869832905);
    // Set group 2 bol bias 02 (VL) to -0.13843131301670974 Volts
    Pacs_BOLC_SET_VL_G2(-0.13843131301670974);
    // Set group 2 bol bias 03 (VRL) to 0.3878839845398352 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878839845398352);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9722117106846373 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9722117106846373);
    // Set group 3 bol bias 01 (VH) to 1.4655563032867613 Volts
    Pacs_BOLC_SET_VH_G3(1.4655563032867613);
    // Set group 3 bol bias 02 (VL) to -0.13444369671323875 Volts
    Pacs_BOLC_SET_VL_G3(-0.13444369671323875);
    // Set group 3 bol bias 03 (VRL) to 0.38996914633068824 Volts
    Pacs_BOLC_SET_VRL_G3(0.38996914633068824);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9738455591218464 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9738455591218464);
    // Set group 4 bol bias 01 (VH) to 1.4803815567917744 Volts
    Pacs_BOLC_SET_VH_G4(1.4803815567917744);
    // Set group 4 bol bias 02 (VL) to -0.11961844320822568 Volts
    Pacs_BOLC_SET_VL_G4(-0.11961844320822568);
    // Set group 4 bol bias 03 (VRL) to 0.3860593630979322 Volts
    Pacs_BOLC_SET_VRL_G4(0.3860593630979322);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9936441996882226 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9936441996882226);
    // Set group 5 bol bias 01 (VH) to 1.3828510880972673 Volts
    Pacs_BOLC_SET_VH_G5(1.3828510880972673);
    // Set group 5 bol bias 02 (VL) to -0.11714891190273273 Volts
    Pacs_BOLC_SET_VL_G5(-0.11714891190273273);
    // Set group 5 bol bias 03 (VRL) to 0.4109562973201683 Volts
    Pacs_BOLC_SET_VRL_G5(0.4109562973201683);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055094312734005 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055094312734005);
    // Set group 6 bol bias 01 (VH) to 1.4187389541758537 Volts
    Pacs_BOLC_SET_VH_G6(1.4187389541758537);
    // Set group 6 bol bias 02 (VL) to -0.08126104582414631 Volts
    Pacs_BOLC_SET_VL_G6(-0.08126104582414631);
    // Set group 6 bol bias 03 (VRL) to 0.4349651037009118 Volts
    Pacs_BOLC_SET_VRL_G6(0.4349651037009118);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0109400872654906 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0109400872654906);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)blue = 1.7 Volts, (Vh-Vl)red = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.542293926761549 Volts
    Pacs_BOLC_SET_VH_G1(1.542293926761549);
    // Set group 1 bol bias 02 (VL) to -0.15770607323845098 Volts
    Pacs_BOLC_SET_VL_G1(-0.15770607323845098);
    // Set group 1 bol bias 03 (VRL) to 0.3926294451860477 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926294451860477);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9765528932845227 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9765528932845227);
    // Set group 2 bol bias 01 (VH) to 1.5247596019367946 Volts
    Pacs_BOLC_SET_VH_G2(1.5247596019367946);
    // Set group 2 bol bias 02 (VL) to -0.17524039806320546 Volts
    Pacs_BOLC_SET_VL_G2(-0.17524039806320546);
    // Set group 2 bol bias 03 (VRL) to 0.3878550325870832 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878550325870832);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9721831025166574 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9721831025166574);
    // Set group 3 bol bias 01 (VH) to 1.5286400044176514 Volts
    Pacs_BOLC_SET_VH_G3(1.5286400044176514);
    // Set group 3 bol bias 02 (VL) to -0.1713599955823485 Volts
    Pacs_BOLC_SET_VL_G3(-0.1713599955823485);
    // Set group 3 bol bias 03 (VRL) to 0.3901485670988867 Volts
    Pacs_BOLC_SET_VRL_G3(0.3901485670988867);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9740231261405279 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9740231261405279);
    // Set group 4 bol bias 01 (VH) to 1.5451742923820575 Volts
    Pacs_BOLC_SET_VH_G4(1.5451742923820575);
    // Set group 4 bol bias 02 (VL) to -0.15482570761794245 Volts
    Pacs_BOLC_SET_VL_G4(-0.15482570761794245);
    // Set group 4 bol bias 03 (VRL) to 0.3871858356177216 Volts
    Pacs_BOLC_SET_VRL_G4(0.3871858356177216);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9947589297629622 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9947589297629622);
    // Set group 5 bol bias 01 (VH) to 1.4463934011524333 Volts
    Pacs_BOLC_SET_VH_G5(1.4463934011524333);
    // Set group 5 bol bias 02 (VL) to -0.15360659884756683 Volts
    Pacs_BOLC_SET_VL_G5(-0.15360659884756683);
    // Set group 5 bol bias 03 (VRL) to 0.4101701125060366 Volts
    Pacs_BOLC_SET_VRL_G5(0.4101701125060366);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.054314719447538 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.054314719447538);
    // Set group 6 bol bias 01 (VH) to 1.4826068632993925 Volts
    Pacs_BOLC_SET_VH_G6(1.4826068632993925);
    // Set group 6 bol bias 02 (VL) to -0.11739313670060761 Volts
    Pacs_BOLC_SET_VL_G6(-0.11739313670060761);
    // Set group 6 bol bias 03 (VRL) to 0.4338779750444286 Volts
    Pacs_BOLC_SET_VRL_G6(0.4338779750444286);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.009851264439135 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.009851264439135);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)blue = 1.8 Volts, (Vh-Vl)red = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.60690529764583 Volts
    Pacs_BOLC_SET_VH_G1(1.60690529764583);
    // Set group 1 bol bias 02 (VL) to -0.19309470235416992 Volts
    Pacs_BOLC_SET_VL_G1(-0.19309470235416992);
    // Set group 1 bol bias 03 (VRL) to 0.39257168553053945 Volts
    Pacs_BOLC_SET_VRL_G1(0.39257168553053945);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9987180645064364 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9987180645064364);
    // Set group 2 bol bias 01 (VH) to 1.5888225493633414 Volts
    Pacs_BOLC_SET_VH_G2(1.5888225493633414);
    // Set group 2 bol bias 02 (VL) to -0.2111774506366586 Volts
    Pacs_BOLC_SET_VL_G2(-0.2111774506366586);
    // Set group 2 bol bias 03 (VRL) to 0.387719891228717 Volts
    Pacs_BOLC_SET_VRL_G2(0.387719891228717);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9720495652990864 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9720495652990864);
    // Set group 3 bol bias 01 (VH) to 1.5926816774791708 Volts
    Pacs_BOLC_SET_VH_G3(1.5926816774791708);
    // Set group 3 bol bias 02 (VL) to -0.20731832252082927 Volts
    Pacs_BOLC_SET_VL_G3(-0.20731832252082927);
    // Set group 3 bol bias 03 (VRL) to 0.39036266684895493 Volts
    Pacs_BOLC_SET_VRL_G3(0.39036266684895493);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.974235015140725 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.974235015140725);
    // Set group 4 bol bias 01 (VH) to 1.6103713769916332 Volts
    Pacs_BOLC_SET_VH_G4(1.6103713769916332);
    // Set group 4 bol bias 02 (VL) to -0.1896286230083667 Volts
    Pacs_BOLC_SET_VL_G4(-0.1896286230083667);
    // Set group 4 bol bias 03 (VRL) to 0.38763171869999546 Volts
    Pacs_BOLC_SET_VRL_G4(0.38763171869999546);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9952001524800798 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9952001524800798);
    // Set group 5 bol bias 01 (VH) to 1.575230733402161 Volts
    Pacs_BOLC_SET_VH_G5(1.575230733402161);
    // Set group 5 bol bias 02 (VL) to -0.22476926659783908 Volts
    Pacs_BOLC_SET_VL_G5(-0.22476926659783908);
    // Set group 5 bol bias 03 (VRL) to 0.40838061675412257 Volts
    Pacs_BOLC_SET_VRL_G5(0.40838061675412257);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.052540349440553 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.052540349440553);
    // Set group 6 bol bias 01 (VH) to 1.6128643450774607 Volts
    Pacs_BOLC_SET_VH_G6(1.6128643450774607);
    // Set group 6 bol bias 02 (VL) to -0.1871356549225394 Volts
    Pacs_BOLC_SET_VL_G6(-0.1871356549225394);
    // Set group 6 bol bias 03 (VRL) to 0.4319097861053989 Volts
    Pacs_BOLC_SET_VRL_G6(0.4319097861053989);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.007881605555887 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.007881605555887);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)blue = 2.0 Volts, (Vh-Vl)red = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.739376176417995 Volts
    Pacs_BOLC_SET_VH_G1(1.739376176417995);
    // Set group 1 bol bias 02 (VL) to -0.2606238235820051 Volts
    Pacs_BOLC_SET_VL_G1(-0.2606238235820051);
    // Set group 1 bol bias 03 (VRL) to 0.3921536831520859 Volts
    Pacs_BOLC_SET_VRL_G1(0.3921536831520859);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9760829613086472 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9760829613086472);
    // Set group 2 bol bias 01 (VH) to 1.719809813472755 Volts
    Pacs_BOLC_SET_VH_G2(1.719809813472755);
    // Set group 2 bol bias 02 (VL) to -0.28019018652724503 Volts
    Pacs_BOLC_SET_VL_G2(-0.28019018652724503);
    // Set group 2 bol bias 03 (VRL) to 0.38744168454874117 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744168454874117);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9717746579976725 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9717746579976725);
    // Set group 3 bol bias 01 (VH) to 1.7343527587435847 Volts
    Pacs_BOLC_SET_VH_G3(1.7343527587435847);
    // Set group 3 bol bias 02 (VL) to -0.2656472412564153 Volts
    Pacs_BOLC_SET_VL_G3(-0.2656472412564153);
    // Set group 3 bol bias 03 (VRL) to 0.4017790445564455 Volts
    Pacs_BOLC_SET_VRL_G3(0.4017790445564455);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9855314406558735 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9855314406558735);
    // Set group 4 bol bias 01 (VH) to 1.7440573141484068 Volts
    Pacs_BOLC_SET_VH_G4(1.7440573141484068);
    // Set group 4 bol bias 02 (VL) to -0.2559426858515932 Volts
    Pacs_BOLC_SET_VL_G4(-0.2559426858515932);
    // Set group 4 bol bias 03 (VRL) to 0.38894738596666634 Volts
    Pacs_BOLC_SET_VRL_G4(0.38894738596666634);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.996502027278406 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.996502027278406);
    // Set group 5 bol bias 01 (VH) to 1.6403549621270441 Volts
    Pacs_BOLC_SET_VH_G5(1.6403549621270441);
    // Set group 5 bol bias 02 (VL) to -0.25964503787295584 Volts
    Pacs_BOLC_SET_VL_G5(-0.25964503787295584);
    // Set group 5 bol bias 03 (VRL) to 0.4071234038646236 Volts
    Pacs_BOLC_SET_VRL_G5(0.4071234038646236);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051293864758269 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051293864758269);
    // Set group 6 bol bias 01 (VH) to 1.6787311020540112 Volts
    Pacs_BOLC_SET_VH_G6(1.6787311020540112);
    // Set group 6 bol bias 02 (VL) to -0.22126889794598872 Volts
    Pacs_BOLC_SET_VL_G6(-0.22126889794598872);
    // Set group 6 bol bias 03 (VRL) to 0.4305158637367362 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305158637367362);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0064867220677454 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0064867220677454);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)blue = 2.3 Volts, (Vh-Vl)red = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.9636608873020274 Volts
    Pacs_BOLC_SET_VH_G1(1.9636608873020274);
    // Set group 1 bol bias 02 (VL) to -0.3363391126979725 Volts
    Pacs_BOLC_SET_VL_G1(-0.3363391126979725);
    // Set group 1 bol bias 03 (VRL) to 0.40278769107629514 Volts
    Pacs_BOLC_SET_VRL_G1(0.40278769107629514);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9865763456310306 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9865763456310306);
    // Set group 2 bol bias 01 (VH) to 1.927696912686972 Volts
    Pacs_BOLC_SET_VH_G2(1.927696912686972);
    // Set group 2 bol bias 02 (VL) to -0.37230308731302775 Volts
    Pacs_BOLC_SET_VL_G2(-0.37230308731302775);
    // Set group 2 bol bias 03 (VRL) to 0.3858403551587576 Volts
    Pacs_BOLC_SET_VRL_G2(0.3858403551587576);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9924144642105024 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9924144642105024);
    // Set group 3 bol bias 01 (VH) to 1.9431226670014545 Volts
    Pacs_BOLC_SET_VH_G3(1.9431226670014545);
    // Set group 3 bol bias 02 (VL) to -0.35687733299854535 Volts
    Pacs_BOLC_SET_VL_G3(-0.35687733299854535);
    // Set group 3 bol bias 03 (VRL) to 0.4024839037666154 Volts
    Pacs_BOLC_SET_VRL_G3(0.4024839037666154);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9862268670149914 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9862268670149914);
    // Set group 4 bol bias 01 (VH) to 1.9579270398291708 Volts
    Pacs_BOLC_SET_VH_G4(1.9579270398291708);
    // Set group 4 bol bias 02 (VL) to -0.3420729601708289 Volts
    Pacs_BOLC_SET_VL_G4(-0.3420729601708289);
    // Set group 4 bol bias 03 (VRL) to 0.3906771012878555 Volts
    Pacs_BOLC_SET_VRL_G4(0.3906771012878555);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.99821351608857 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.99821351608857);
    // Set group 5 bol bias 01 (VH) to 1.7079035410760286 Volts
    Pacs_BOLC_SET_VH_G5(1.7079035410760286);
    // Set group 5 bol bias 02 (VL) to -0.29209645892397146 Volts
    Pacs_BOLC_SET_VL_G5(-0.29209645892397146);
    // Set group 5 bol bias 03 (VRL) to 0.405804322083024 Volts
    Pacs_BOLC_SET_VRL_G5(0.405804322083024);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0499861292550787 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0499861292550787);
    // Set group 6 bol bias 01 (VH) to 1.7476622867412348 Volts
    Pacs_BOLC_SET_VH_G6(1.7476622867412348);
    // Set group 6 bol bias 02 (VL) to -0.2523377132587652 Volts
    Pacs_BOLC_SET_VL_G6(-0.2523377132587652);
    // Set group 6 bol bias 03 (VRL) to 0.429562228366719 Volts
    Pacs_BOLC_SET_VRL_G6(0.429562228366719);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.005532468489443 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.005532468489443);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)blue = 2.6 Volts, (Vh-Vl)red = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2151628880310112 Volts
    Pacs_BOLC_SET_VH_G1(2.2151628880310112);
    // Set group 1 bol bias 02 (VL) to -0.3848371119689889 Volts
    Pacs_BOLC_SET_VL_G1(-0.3848371119689889);
    // Set group 1 bol bias 03 (VRL) to 0.41342338183313837 Volts
    Pacs_BOLC_SET_VRL_G1(0.41342338183313837);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0193446104924915 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0193446104924915);
    // Set group 2 bol bias 01 (VH) to 2.1588489399994213 Volts
    Pacs_BOLC_SET_VH_G2(2.1588489399994213);
    // Set group 2 bol bias 02 (VL) to -0.4411510600005787 Volts
    Pacs_BOLC_SET_VL_G2(-0.4411510600005787);
    // Set group 2 bol bias 03 (VRL) to 0.3838811209851186 Volts
    Pacs_BOLC_SET_VRL_G2(0.3838811209851186);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9682559687629309 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9682559687629309);
    // Set group 3 bol bias 01 (VH) to 2.1867239063317037 Volts
    Pacs_BOLC_SET_VH_G3(2.1867239063317037);
    // Set group 3 bol bias 02 (VL) to -0.4132760936682966 Volts
    Pacs_BOLC_SET_VL_G3(-0.4132760936682966);
    // Set group 3 bol bias 03 (VRL) to 0.4136603871411812 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136603871411812);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9973179392427267 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9973179392427267);
    // Set group 4 bol bias 01 (VH) to 2.20827452044462 Volts
    Pacs_BOLC_SET_VH_G4(2.20827452044462);
    // Set group 4 bol bias 02 (VL) to -0.39172547955538 Volts
    Pacs_BOLC_SET_VL_G4(-0.39172547955538);
    // Set group 4 bol bias 03 (VRL) to 0.4039414339062088 Volts
    Pacs_BOLC_SET_VRL_G4(0.4039414339062088);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.011301244644244 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.011301244644244);
    // Set group 5 bol bias 01 (VH) to 1.7875017871866707 Volts
    Pacs_BOLC_SET_VH_G5(1.7875017871866707);
    // Set group 5 bol bias 02 (VL) to -0.31249821281332946 Volts
    Pacs_BOLC_SET_VL_G5(-0.31249821281332946);
    // Set group 5 bol bias 03 (VRL) to 0.41576367399178094 Volts
    Pacs_BOLC_SET_VRL_G5(0.41576367399178094);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.037668873916454 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.037668873916454);
    // Set group 6 bol bias 01 (VH) to 1.8172008318899895 Volts
    Pacs_BOLC_SET_VH_G6(1.8172008318899895);
    // Set group 6 bol bias 02 (VL) to -0.2827991681100106 Volts
    Pacs_BOLC_SET_VL_G6(-0.2827991681100106);
    // Set group 6 bol bias 03 (VRL) to 0.42845474144203777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42845474144203777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.004424303719793 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.004424303719793);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)blue = 2.9 Volts, (Vh-Vl)red = 2.3 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.517666343337925 Volts
    Pacs_BOLC_SET_VH_G1(2.517666343337925);
    // Set group 1 bol bias 02 (VL) to -0.382333656662075 Volts
    Pacs_BOLC_SET_VL_G1(-0.382333656662075);
    // Set group 1 bol bias 03 (VRL) to 0.4351367995957048 Volts
    Pacs_BOLC_SET_VRL_G1(0.4351367995957048);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9965703186107444 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9965703186107444);
    // Set group 2 bol bias 01 (VH) to 2.4353683146246183 Volts
    Pacs_BOLC_SET_VH_G2(2.4353683146246183);
    // Set group 2 bol bias 02 (VL) to -0.4646316853753816 Volts
    Pacs_BOLC_SET_VL_G2(-0.4646316853753816);
    // Set group 2 bol bias 03 (VRL) to 0.39230855172448975 Volts
    Pacs_BOLC_SET_VRL_G2(0.39230855172448975);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9765832317921543 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9765832317921543);
    // Set group 3 bol bias 01 (VH) to 2.4565430314555052 Volts
    Pacs_BOLC_SET_VH_G3(2.4565430314555052);
    // Set group 3 bol bias 02 (VL) to -0.4434569685444947 Volts
    Pacs_BOLC_SET_VL_G3(-0.4434569685444947);
    // Set group 3 bol bias 03 (VRL) to 0.4116559215687209 Volts
    Pacs_BOLC_SET_VRL_G3(0.4116559215687209);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175436768747823 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175436768747823);
    // Set group 4 bol bias 01 (VH) to 2.4726040303622487 Volts
    Pacs_BOLC_SET_VH_G4(2.4726040303622487);
    // Set group 4 bol bias 02 (VL) to -0.4273959696377513 Volts
    Pacs_BOLC_SET_VL_G4(-0.4273959696377513);
    // Set group 4 bol bias 03 (VRL) to 0.3940712295914811 Volts
    Pacs_BOLC_SET_VRL_G4(0.3940712295914811);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.023793793137234 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.023793793137234);
    // Set group 5 bol bias 01 (VH) to 1.9226793871045598 Volts
    Pacs_BOLC_SET_VH_G5(1.9226793871045598);
    // Set group 5 bol bias 02 (VL) to -0.37732061289544 Volts
    Pacs_BOLC_SET_VL_G5(-0.37732061289544);
    // Set group 5 bol bias 03 (VRL) to 0.40093587460771146 Volts
    Pacs_BOLC_SET_VRL_G5(0.40093587460771146);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.022938134951507 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.022938134951507);
    // Set group 6 bol bias 01 (VH) to 1.9672658597937258 Volts
    Pacs_BOLC_SET_VH_G6(1.9672658597937258);
    // Set group 6 bol bias 02 (VL) to -0.332734140206274 Volts
    Pacs_BOLC_SET_VL_G6(-0.332734140206274);
    // Set group 6 bol bias 03 (VRL) to 0.4263945599495246 Volts
    Pacs_BOLC_SET_VRL_G6(0.4263945599495246);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.002362975913312 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.002362975913312);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)blue = 3.2 Volts, (Vh-Vl)red = 2.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.847199981495237 Volts
    Pacs_BOLC_SET_VH_G1(2.847199981495237);
    // Set group 1 bol bias 02 (VL) to -0.3528000185047631 Volts
    Pacs_BOLC_SET_VL_G1(-0.3528000185047631);
    // Set group 1 bol bias 03 (VRL) to 0.4347941377293029 Volts
    Pacs_BOLC_SET_VRL_G1(0.4347941377293029);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.018449774761696 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.018449774761696);
    // Set group 2 bol bias 01 (VH) to 2.7602559944480873 Volts
    Pacs_BOLC_SET_VH_G2(2.7602559944480873);
    // Set group 2 bol bias 02 (VL) to -0.43974400555191273 Volts
    Pacs_BOLC_SET_VL_G2(-0.43974400555191273);
    // Set group 2 bol bias 03 (VRL) to 0.4036708891743245 Volts
    Pacs_BOLC_SET_VRL_G2(0.4036708891743245);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.0099936291338243 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.0099936291338243);
    // Set group 3 bol bias 01 (VH) to 2.805732095961401 Volts
    Pacs_BOLC_SET_VH_G3(2.805732095961401);
    // Set group 3 bol bias 02 (VL) to -0.3942679040385992 Volts
    Pacs_BOLC_SET_VL_G3(-0.3942679040385992);
    // Set group 3 bol bias 03 (VRL) to 0.4339248022480186 Volts
    Pacs_BOLC_SET_VRL_G3(0.4339248022480186);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175166229478236 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175166229478236);
    // Set group 4 bol bias 01 (VH) to 2.8132260321912117 Volts
    Pacs_BOLC_SET_VH_G4(2.8132260321912117);
    // Set group 4 bol bias 02 (VL) to -0.3867739678087883 Volts
    Pacs_BOLC_SET_VL_G4(-0.3867739678087883);
    // Set group 4 bol bias 03 (VRL) to 0.4141623922109569 Volts
    Pacs_BOLC_SET_VRL_G4(0.4141623922109569);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.0213933637092976 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.0213933637092976);
    // Set group 5 bol bias 01 (VH) to 2.1145200531318697 Volts
    Pacs_BOLC_SET_VH_G5(2.1145200531318697);
    // Set group 5 bol bias 02 (VL) to -0.38547994686813014 Volts
    Pacs_BOLC_SET_VL_G5(-0.38547994686813014);
    // Set group 5 bol bias 03 (VRL) to 0.4292977832137159 Volts
    Pacs_BOLC_SET_VRL_G5(0.4292977832137159);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.006817368773259 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.006817368773259);
    // Set group 6 bol bias 01 (VH) to 2.1293608950052523 Volts
    Pacs_BOLC_SET_VH_G6(2.1293608950052523);
    // Set group 6 bol bias 02 (VL) to -0.3706391049947475 Volts
    Pacs_BOLC_SET_VL_G6(-0.3706391049947475);
    // Set group 6 bol bias 03 (VRL) to 0.4231555942593115 Volts
    Pacs_BOLC_SET_VRL_G6(0.4231555942593115);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9769002872568586 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9769002872568586);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //
    //
    //************************************************************************
    //                           Noise Measurement
    // Expected fluxes : 1.7pW on the blue and 5.3pW on the red detector
    //************************************************************************
    //
    //*****************************
    // Set the PACS chopper on CS1
    //*****************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(posCS1);
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)blue = 1.0 Volts, (Vh-Vl)red = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G1(0.99);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.2875928897414196 Volts
    Pacs_BOLC_SET_VRL_G1(0.2875928897414196);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.78435816010763 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.78435816010763);
    // Set group 2 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G2(0.99);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.2976890643549285 Volts
    Pacs_BOLC_SET_VRL_G2(0.2976890643549285);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.7946385038224304 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.7946385038224304);
    // Set group 3 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G3(0.99);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.2921869021406959 Volts
    Pacs_BOLC_SET_VRL_G3(0.2921869021406959);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.8111181679623898 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.8111181679623898);
    // Set group 4 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G4(0.99);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.2833032550752384 Volts
    Pacs_BOLC_SET_VRL_G4(0.2833032550752384);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.8038951101792082 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.8038951101792082);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3346340277410602 Volts
    Pacs_BOLC_SET_VRL_G5(0.3346340277410602);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8466792279676985 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8466792279676985);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.32636237036822335 Volts
    Pacs_BOLC_SET_VRL_G6(0.32636237036822335);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8367532617835844 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8367532617835844);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)blue = 1.2 Volts, (Vh-Vl)red = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G1(1.19);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.3577080013822565 Volts
    Pacs_BOLC_SET_VRL_G1(0.3577080013822565);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9420622421434064 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9420622421434064);
    // Set group 2 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G2(1.19);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.36696811904468774 Volts
    Pacs_BOLC_SET_VRL_G2(0.36696811904468774);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9515329512935697 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9515329512935697);
    // Set group 3 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G3(1.19);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.3640303856110917 Volts
    Pacs_BOLC_SET_VRL_G3(0.3640303856110917);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9482056457093682 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9482056457093682);
    // Set group 4 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G4(1.19);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3523579205628669 Volts
    Pacs_BOLC_SET_VRL_G4(0.3523579205628669);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9603646239045185 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9603646239045185);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4064368830411808 Volts
    Pacs_BOLC_SET_VRL_G5(0.4064368830411808);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8950576820742784 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8950576820742784);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.39643145192214363 Volts
    Pacs_BOLC_SET_VRL_G6(0.39643145192214363);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8837201139355604 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8837201139355604);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)blue = 1.4 Volts, (Vh-Vl)red = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.3525857926230986 Volts
    Pacs_BOLC_SET_VH_G1(1.3525857926230986);
    // Set group 1 bol bias 02 (VL) to -0.047414207376901184 Volts
    Pacs_BOLC_SET_VL_G1(-0.047414207376901184);
    // Set group 1 bol bias 03 (VRL) to 0.3926244201072773 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926244201072773);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.976547929868054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.976547929868054);
    // Set group 2 bol bias 01 (VH) to 1.3374255283716547 Volts
    Pacs_BOLC_SET_VH_G2(1.3374255283716547);
    // Set group 2 bol bias 02 (VL) to -0.06257447162834509 Volts
    Pacs_BOLC_SET_VL_G2(-0.06257447162834509);
    // Set group 2 bol bias 03 (VRL) to 0.38802799053825054 Volts
    Pacs_BOLC_SET_VRL_G2(0.38802799053825054);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9723540060682856 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9723540060682856);
    // Set group 3 bol bias 01 (VH) to 1.341267296137658 Volts
    Pacs_BOLC_SET_VH_G3(1.341267296137658);
    // Set group 3 bol bias 02 (VL) to -0.058732703862341994 Volts
    Pacs_BOLC_SET_VL_G3(-0.058732703862341994);
    // Set group 3 bol bias 03 (VRL) to 0.38970189090896923 Volts
    Pacs_BOLC_SET_VRL_G3(0.38970189090896923);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9735810667835696 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9735810667835696);
    // Set group 4 bol bias 01 (VH) to 1.352746675150765 Volts
    Pacs_BOLC_SET_VH_G4(1.352746675150765);
    // Set group 4 bol bias 02 (VL) to -0.04725332484923491 Volts
    Pacs_BOLC_SET_VL_G4(-0.04725332484923491);
    // Set group 4 bol bias 03 (VRL) to 0.3856108728986011 Volts
    Pacs_BOLC_SET_VRL_G4(0.3856108728986011);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9932003720526934 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9932003720526934);
    // Set group 5 bol bias 01 (VH) to 1.320583197395035 Volts
    Pacs_BOLC_SET_VH_G5(1.320583197395035);
    // Set group 5 bol bias 02 (VL) to -0.07941680260496485 Volts
    Pacs_BOLC_SET_VL_G5(-0.07941680260496485);
    // Set group 5 bol bias 03 (VRL) to 0.4116095244710064 Volts
    Pacs_BOLC_SET_VRL_G5(0.4116095244710064);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055742088043621 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055742088043621);
    // Set group 6 bol bias 01 (VH) to 1.3562697990163495 Volts
    Pacs_BOLC_SET_VH_G6(1.3562697990163495);
    // Set group 6 bol bias 02 (VL) to -0.04373020098365052 Volts
    Pacs_BOLC_SET_VL_G6(-0.04373020098365052);
    // Set group 6 bol bias 03 (VRL) to 0.43594530124025854 Volts
    Pacs_BOLC_SET_VRL_G6(0.43594530124025854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.011921670046162 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.011921670046162);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)blue = 1.6 Volts, (Vh-Vl)red = 1.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4783736198117614 Volts
    Pacs_BOLC_SET_VH_G1(1.4783736198117614);
    // Set group 1 bol bias 02 (VL) to -0.12162638018823857 Volts
    Pacs_BOLC_SET_VL_G1(-0.12162638018823857);
    // Set group 1 bol bias 03 (VRL) to 0.392515090355521 Volts
    Pacs_BOLC_SET_VRL_G1(0.392515090355521);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9764399412468519 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9764399412468519);
    // Set group 2 bol bias 01 (VH) to 1.4615686869832905 Volts
    Pacs_BOLC_SET_VH_G2(1.4615686869832905);
    // Set group 2 bol bias 02 (VL) to -0.13843131301670974 Volts
    Pacs_BOLC_SET_VL_G2(-0.13843131301670974);
    // Set group 2 bol bias 03 (VRL) to 0.3878839845398352 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878839845398352);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9722117106846373 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9722117106846373);
    // Set group 3 bol bias 01 (VH) to 1.4655563032867613 Volts
    Pacs_BOLC_SET_VH_G3(1.4655563032867613);
    // Set group 3 bol bias 02 (VL) to -0.13444369671323875 Volts
    Pacs_BOLC_SET_VL_G3(-0.13444369671323875);
    // Set group 3 bol bias 03 (VRL) to 0.38996914633068824 Volts
    Pacs_BOLC_SET_VRL_G3(0.38996914633068824);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9738455591218464 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9738455591218464);
    // Set group 4 bol bias 01 (VH) to 1.4803815567917744 Volts
    Pacs_BOLC_SET_VH_G4(1.4803815567917744);
    // Set group 4 bol bias 02 (VL) to -0.11961844320822568 Volts
    Pacs_BOLC_SET_VL_G4(-0.11961844320822568);
    // Set group 4 bol bias 03 (VRL) to 0.3860593630979322 Volts
    Pacs_BOLC_SET_VRL_G4(0.3860593630979322);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9936441996882226 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9936441996882226);
    // Set group 5 bol bias 01 (VH) to 1.3828510880972673 Volts
    Pacs_BOLC_SET_VH_G5(1.3828510880972673);
    // Set group 5 bol bias 02 (VL) to -0.11714891190273273 Volts
    Pacs_BOLC_SET_VL_G5(-0.11714891190273273);
    // Set group 5 bol bias 03 (VRL) to 0.4109562973201683 Volts
    Pacs_BOLC_SET_VRL_G5(0.4109562973201683);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055094312734005 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055094312734005);
    // Set group 6 bol bias 01 (VH) to 1.4187389541758537 Volts
    Pacs_BOLC_SET_VH_G6(1.4187389541758537);
    // Set group 6 bol bias 02 (VL) to -0.08126104582414631 Volts
    Pacs_BOLC_SET_VL_G6(-0.08126104582414631);
    // Set group 6 bol bias 03 (VRL) to 0.4349651037009118 Volts
    Pacs_BOLC_SET_VRL_G6(0.4349651037009118);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0109400872654906 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0109400872654906);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)blue = 1.7 Volts, (Vh-Vl)red = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.542293926761549 Volts
    Pacs_BOLC_SET_VH_G1(1.542293926761549);
    // Set group 1 bol bias 02 (VL) to -0.15770607323845098 Volts
    Pacs_BOLC_SET_VL_G1(-0.15770607323845098);
    // Set group 1 bol bias 03 (VRL) to 0.3926294451860477 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926294451860477);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9765528932845227 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9765528932845227);
    // Set group 2 bol bias 01 (VH) to 1.5247596019367946 Volts
    Pacs_BOLC_SET_VH_G2(1.5247596019367946);
    // Set group 2 bol bias 02 (VL) to -0.17524039806320546 Volts
    Pacs_BOLC_SET_VL_G2(-0.17524039806320546);
    // Set group 2 bol bias 03 (VRL) to 0.3878550325870832 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878550325870832);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9721831025166574 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9721831025166574);
    // Set group 3 bol bias 01 (VH) to 1.5286400044176514 Volts
    Pacs_BOLC_SET_VH_G3(1.5286400044176514);
    // Set group 3 bol bias 02 (VL) to -0.1713599955823485 Volts
    Pacs_BOLC_SET_VL_G3(-0.1713599955823485);
    // Set group 3 bol bias 03 (VRL) to 0.3901485670988867 Volts
    Pacs_BOLC_SET_VRL_G3(0.3901485670988867);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9740231261405279 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9740231261405279);
    // Set group 4 bol bias 01 (VH) to 1.5451742923820575 Volts
    Pacs_BOLC_SET_VH_G4(1.5451742923820575);
    // Set group 4 bol bias 02 (VL) to -0.15482570761794245 Volts
    Pacs_BOLC_SET_VL_G4(-0.15482570761794245);
    // Set group 4 bol bias 03 (VRL) to 0.3871858356177216 Volts
    Pacs_BOLC_SET_VRL_G4(0.3871858356177216);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9947589297629622 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9947589297629622);
    // Set group 5 bol bias 01 (VH) to 1.4463934011524333 Volts
    Pacs_BOLC_SET_VH_G5(1.4463934011524333);
    // Set group 5 bol bias 02 (VL) to -0.15360659884756683 Volts
    Pacs_BOLC_SET_VL_G5(-0.15360659884756683);
    // Set group 5 bol bias 03 (VRL) to 0.4101701125060366 Volts
    Pacs_BOLC_SET_VRL_G5(0.4101701125060366);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.054314719447538 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.054314719447538);
    // Set group 6 bol bias 01 (VH) to 1.4826068632993925 Volts
    Pacs_BOLC_SET_VH_G6(1.4826068632993925);
    // Set group 6 bol bias 02 (VL) to -0.11739313670060761 Volts
    Pacs_BOLC_SET_VL_G6(-0.11739313670060761);
    // Set group 6 bol bias 03 (VRL) to 0.4338779750444286 Volts
    Pacs_BOLC_SET_VRL_G6(0.4338779750444286);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.009851264439135 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.009851264439135);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)blue = 1.8 Volts, (Vh-Vl)red = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.60690529764583 Volts
    Pacs_BOLC_SET_VH_G1(1.60690529764583);
    // Set group 1 bol bias 02 (VL) to -0.19309470235416992 Volts
    Pacs_BOLC_SET_VL_G1(-0.19309470235416992);
    // Set group 1 bol bias 03 (VRL) to 0.39257168553053945 Volts
    Pacs_BOLC_SET_VRL_G1(0.39257168553053945);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9987180645064364 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9987180645064364);
    // Set group 2 bol bias 01 (VH) to 1.5888225493633414 Volts
    Pacs_BOLC_SET_VH_G2(1.5888225493633414);
    // Set group 2 bol bias 02 (VL) to -0.2111774506366586 Volts
    Pacs_BOLC_SET_VL_G2(-0.2111774506366586);
    // Set group 2 bol bias 03 (VRL) to 0.387719891228717 Volts
    Pacs_BOLC_SET_VRL_G2(0.387719891228717);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9720495652990864 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9720495652990864);
    // Set group 3 bol bias 01 (VH) to 1.5926816774791708 Volts
    Pacs_BOLC_SET_VH_G3(1.5926816774791708);
    // Set group 3 bol bias 02 (VL) to -0.20731832252082927 Volts
    Pacs_BOLC_SET_VL_G3(-0.20731832252082927);
    // Set group 3 bol bias 03 (VRL) to 0.39036266684895493 Volts
    Pacs_BOLC_SET_VRL_G3(0.39036266684895493);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.974235015140725 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.974235015140725);
    // Set group 4 bol bias 01 (VH) to 1.6103713769916332 Volts
    Pacs_BOLC_SET_VH_G4(1.6103713769916332);
    // Set group 4 bol bias 02 (VL) to -0.1896286230083667 Volts
    Pacs_BOLC_SET_VL_G4(-0.1896286230083667);
    // Set group 4 bol bias 03 (VRL) to 0.38763171869999546 Volts
    Pacs_BOLC_SET_VRL_G4(0.38763171869999546);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9952001524800798 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9952001524800798);
    // Set group 5 bol bias 01 (VH) to 1.575230733402161 Volts
    Pacs_BOLC_SET_VH_G5(1.575230733402161);
    // Set group 5 bol bias 02 (VL) to -0.22476926659783908 Volts
    Pacs_BOLC_SET_VL_G5(-0.22476926659783908);
    // Set group 5 bol bias 03 (VRL) to 0.40838061675412257 Volts
    Pacs_BOLC_SET_VRL_G5(0.40838061675412257);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.052540349440553 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.052540349440553);
    // Set group 6 bol bias 01 (VH) to 1.6128643450774607 Volts
    Pacs_BOLC_SET_VH_G6(1.6128643450774607);
    // Set group 6 bol bias 02 (VL) to -0.1871356549225394 Volts
    Pacs_BOLC_SET_VL_G6(-0.1871356549225394);
    // Set group 6 bol bias 03 (VRL) to 0.4319097861053989 Volts
    Pacs_BOLC_SET_VRL_G6(0.4319097861053989);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.007881605555887 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.007881605555887);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)blue = 2.0 Volts, (Vh-Vl)red = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.739376176417995 Volts
    Pacs_BOLC_SET_VH_G1(1.739376176417995);
    // Set group 1 bol bias 02 (VL) to -0.2606238235820051 Volts
    Pacs_BOLC_SET_VL_G1(-0.2606238235820051);
    // Set group 1 bol bias 03 (VRL) to 0.3921536831520859 Volts
    Pacs_BOLC_SET_VRL_G1(0.3921536831520859);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9760829613086472 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9760829613086472);
    // Set group 2 bol bias 01 (VH) to 1.719809813472755 Volts
    Pacs_BOLC_SET_VH_G2(1.719809813472755);
    // Set group 2 bol bias 02 (VL) to -0.28019018652724503 Volts
    Pacs_BOLC_SET_VL_G2(-0.28019018652724503);
    // Set group 2 bol bias 03 (VRL) to 0.38744168454874117 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744168454874117);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9717746579976725 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9717746579976725);
    // Set group 3 bol bias 01 (VH) to 1.7343527587435847 Volts
    Pacs_BOLC_SET_VH_G3(1.7343527587435847);
    // Set group 3 bol bias 02 (VL) to -0.2656472412564153 Volts
    Pacs_BOLC_SET_VL_G3(-0.2656472412564153);
    // Set group 3 bol bias 03 (VRL) to 0.4017790445564455 Volts
    Pacs_BOLC_SET_VRL_G3(0.4017790445564455);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9855314406558735 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9855314406558735);
    // Set group 4 bol bias 01 (VH) to 1.7440573141484068 Volts
    Pacs_BOLC_SET_VH_G4(1.7440573141484068);
    // Set group 4 bol bias 02 (VL) to -0.2559426858515932 Volts
    Pacs_BOLC_SET_VL_G4(-0.2559426858515932);
    // Set group 4 bol bias 03 (VRL) to 0.38894738596666634 Volts
    Pacs_BOLC_SET_VRL_G4(0.38894738596666634);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.996502027278406 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.996502027278406);
    // Set group 5 bol bias 01 (VH) to 1.6403549621270441 Volts
    Pacs_BOLC_SET_VH_G5(1.6403549621270441);
    // Set group 5 bol bias 02 (VL) to -0.25964503787295584 Volts
    Pacs_BOLC_SET_VL_G5(-0.25964503787295584);
    // Set group 5 bol bias 03 (VRL) to 0.4071234038646236 Volts
    Pacs_BOLC_SET_VRL_G5(0.4071234038646236);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051293864758269 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051293864758269);
    // Set group 6 bol bias 01 (VH) to 1.6787311020540112 Volts
    Pacs_BOLC_SET_VH_G6(1.6787311020540112);
    // Set group 6 bol bias 02 (VL) to -0.22126889794598872 Volts
    Pacs_BOLC_SET_VL_G6(-0.22126889794598872);
    // Set group 6 bol bias 03 (VRL) to 0.4305158637367362 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305158637367362);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0064867220677454 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0064867220677454);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)blue = 2.3 Volts, (Vh-Vl)red = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.9636608873020274 Volts
    Pacs_BOLC_SET_VH_G1(1.9636608873020274);
    // Set group 1 bol bias 02 (VL) to -0.3363391126979725 Volts
    Pacs_BOLC_SET_VL_G1(-0.3363391126979725);
    // Set group 1 bol bias 03 (VRL) to 0.40278769107629514 Volts
    Pacs_BOLC_SET_VRL_G1(0.40278769107629514);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9865763456310306 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9865763456310306);
    // Set group 2 bol bias 01 (VH) to 1.927696912686972 Volts
    Pacs_BOLC_SET_VH_G2(1.927696912686972);
    // Set group 2 bol bias 02 (VL) to -0.37230308731302775 Volts
    Pacs_BOLC_SET_VL_G2(-0.37230308731302775);
    // Set group 2 bol bias 03 (VRL) to 0.3858403551587576 Volts
    Pacs_BOLC_SET_VRL_G2(0.3858403551587576);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9924144642105024 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9924144642105024);
    // Set group 3 bol bias 01 (VH) to 1.9431226670014545 Volts
    Pacs_BOLC_SET_VH_G3(1.9431226670014545);
    // Set group 3 bol bias 02 (VL) to -0.35687733299854535 Volts
    Pacs_BOLC_SET_VL_G3(-0.35687733299854535);
    // Set group 3 bol bias 03 (VRL) to 0.4024839037666154 Volts
    Pacs_BOLC_SET_VRL_G3(0.4024839037666154);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9862268670149914 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9862268670149914);
    // Set group 4 bol bias 01 (VH) to 1.9579270398291708 Volts
    Pacs_BOLC_SET_VH_G4(1.9579270398291708);
    // Set group 4 bol bias 02 (VL) to -0.3420729601708289 Volts
    Pacs_BOLC_SET_VL_G4(-0.3420729601708289);
    // Set group 4 bol bias 03 (VRL) to 0.3906771012878555 Volts
    Pacs_BOLC_SET_VRL_G4(0.3906771012878555);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.99821351608857 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.99821351608857);
    // Set group 5 bol bias 01 (VH) to 1.7079035410760286 Volts
    Pacs_BOLC_SET_VH_G5(1.7079035410760286);
    // Set group 5 bol bias 02 (VL) to -0.29209645892397146 Volts
    Pacs_BOLC_SET_VL_G5(-0.29209645892397146);
    // Set group 5 bol bias 03 (VRL) to 0.405804322083024 Volts
    Pacs_BOLC_SET_VRL_G5(0.405804322083024);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0499861292550787 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0499861292550787);
    // Set group 6 bol bias 01 (VH) to 1.7476622867412348 Volts
    Pacs_BOLC_SET_VH_G6(1.7476622867412348);
    // Set group 6 bol bias 02 (VL) to -0.2523377132587652 Volts
    Pacs_BOLC_SET_VL_G6(-0.2523377132587652);
    // Set group 6 bol bias 03 (VRL) to 0.429562228366719 Volts
    Pacs_BOLC_SET_VRL_G6(0.429562228366719);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.005532468489443 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.005532468489443);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)blue = 2.6 Volts, (Vh-Vl)red = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2151628880310112 Volts
    Pacs_BOLC_SET_VH_G1(2.2151628880310112);
    // Set group 1 bol bias 02 (VL) to -0.3848371119689889 Volts
    Pacs_BOLC_SET_VL_G1(-0.3848371119689889);
    // Set group 1 bol bias 03 (VRL) to 0.41342338183313837 Volts
    Pacs_BOLC_SET_VRL_G1(0.41342338183313837);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0193446104924915 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0193446104924915);
    // Set group 2 bol bias 01 (VH) to 2.1588489399994213 Volts
    Pacs_BOLC_SET_VH_G2(2.1588489399994213);
    // Set group 2 bol bias 02 (VL) to -0.4411510600005787 Volts
    Pacs_BOLC_SET_VL_G2(-0.4411510600005787);
    // Set group 2 bol bias 03 (VRL) to 0.3838811209851186 Volts
    Pacs_BOLC_SET_VRL_G2(0.3838811209851186);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9682559687629309 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9682559687629309);
    // Set group 3 bol bias 01 (VH) to 2.1867239063317037 Volts
    Pacs_BOLC_SET_VH_G3(2.1867239063317037);
    // Set group 3 bol bias 02 (VL) to -0.4132760936682966 Volts
    Pacs_BOLC_SET_VL_G3(-0.4132760936682966);
    // Set group 3 bol bias 03 (VRL) to 0.4136603871411812 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136603871411812);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9973179392427267 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9973179392427267);
    // Set group 4 bol bias 01 (VH) to 2.20827452044462 Volts
    Pacs_BOLC_SET_VH_G4(2.20827452044462);
    // Set group 4 bol bias 02 (VL) to -0.39172547955538 Volts
    Pacs_BOLC_SET_VL_G4(-0.39172547955538);
    // Set group 4 bol bias 03 (VRL) to 0.4039414339062088 Volts
    Pacs_BOLC_SET_VRL_G4(0.4039414339062088);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.011301244644244 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.011301244644244);
    // Set group 5 bol bias 01 (VH) to 1.7875017871866707 Volts
    Pacs_BOLC_SET_VH_G5(1.7875017871866707);
    // Set group 5 bol bias 02 (VL) to -0.31249821281332946 Volts
    Pacs_BOLC_SET_VL_G5(-0.31249821281332946);
    // Set group 5 bol bias 03 (VRL) to 0.41576367399178094 Volts
    Pacs_BOLC_SET_VRL_G5(0.41576367399178094);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.037668873916454 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.037668873916454);
    // Set group 6 bol bias 01 (VH) to 1.8172008318899895 Volts
    Pacs_BOLC_SET_VH_G6(1.8172008318899895);
    // Set group 6 bol bias 02 (VL) to -0.2827991681100106 Volts
    Pacs_BOLC_SET_VL_G6(-0.2827991681100106);
    // Set group 6 bol bias 03 (VRL) to 0.42845474144203777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42845474144203777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.004424303719793 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.004424303719793);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)blue = 2.9 Volts, (Vh-Vl)red = 2.3 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.517666343337925 Volts
    Pacs_BOLC_SET_VH_G1(2.517666343337925);
    // Set group 1 bol bias 02 (VL) to -0.382333656662075 Volts
    Pacs_BOLC_SET_VL_G1(-0.382333656662075);
    // Set group 1 bol bias 03 (VRL) to 0.4351367995957048 Volts
    Pacs_BOLC_SET_VRL_G1(0.4351367995957048);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9965703186107444 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9965703186107444);
    // Set group 2 bol bias 01 (VH) to 2.4353683146246183 Volts
    Pacs_BOLC_SET_VH_G2(2.4353683146246183);
    // Set group 2 bol bias 02 (VL) to -0.4646316853753816 Volts
    Pacs_BOLC_SET_VL_G2(-0.4646316853753816);
    // Set group 2 bol bias 03 (VRL) to 0.39230855172448975 Volts
    Pacs_BOLC_SET_VRL_G2(0.39230855172448975);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9765832317921543 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9765832317921543);
    // Set group 3 bol bias 01 (VH) to 2.4565430314555052 Volts
    Pacs_BOLC_SET_VH_G3(2.4565430314555052);
    // Set group 3 bol bias 02 (VL) to -0.4434569685444947 Volts
    Pacs_BOLC_SET_VL_G3(-0.4434569685444947);
    // Set group 3 bol bias 03 (VRL) to 0.4116559215687209 Volts
    Pacs_BOLC_SET_VRL_G3(0.4116559215687209);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175436768747823 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175436768747823);
    // Set group 4 bol bias 01 (VH) to 2.4726040303622487 Volts
    Pacs_BOLC_SET_VH_G4(2.4726040303622487);
    // Set group 4 bol bias 02 (VL) to -0.4273959696377513 Volts
    Pacs_BOLC_SET_VL_G4(-0.4273959696377513);
    // Set group 4 bol bias 03 (VRL) to 0.3940712295914811 Volts
    Pacs_BOLC_SET_VRL_G4(0.3940712295914811);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.023793793137234 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.023793793137234);
    // Set group 5 bol bias 01 (VH) to 1.9226793871045598 Volts
    Pacs_BOLC_SET_VH_G5(1.9226793871045598);
    // Set group 5 bol bias 02 (VL) to -0.37732061289544 Volts
    Pacs_BOLC_SET_VL_G5(-0.37732061289544);
    // Set group 5 bol bias 03 (VRL) to 0.40093587460771146 Volts
    Pacs_BOLC_SET_VRL_G5(0.40093587460771146);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.022938134951507 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.022938134951507);
    // Set group 6 bol bias 01 (VH) to 1.9672658597937258 Volts
    Pacs_BOLC_SET_VH_G6(1.9672658597937258);
    // Set group 6 bol bias 02 (VL) to -0.332734140206274 Volts
    Pacs_BOLC_SET_VL_G6(-0.332734140206274);
    // Set group 6 bol bias 03 (VRL) to 0.4263945599495246 Volts
    Pacs_BOLC_SET_VRL_G6(0.4263945599495246);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.002362975913312 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.002362975913312);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)blue = 3.2 Volts, (Vh-Vl)red = 2.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.847199981495237 Volts
    Pacs_BOLC_SET_VH_G1(2.847199981495237);
    // Set group 1 bol bias 02 (VL) to -0.3528000185047631 Volts
    Pacs_BOLC_SET_VL_G1(-0.3528000185047631);
    // Set group 1 bol bias 03 (VRL) to 0.4347941377293029 Volts
    Pacs_BOLC_SET_VRL_G1(0.4347941377293029);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.018449774761696 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.018449774761696);
    // Set group 2 bol bias 01 (VH) to 2.7602559944480873 Volts
    Pacs_BOLC_SET_VH_G2(2.7602559944480873);
    // Set group 2 bol bias 02 (VL) to -0.43974400555191273 Volts
    Pacs_BOLC_SET_VL_G2(-0.43974400555191273);
    // Set group 2 bol bias 03 (VRL) to 0.4036708891743245 Volts
    Pacs_BOLC_SET_VRL_G2(0.4036708891743245);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.0099936291338243 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.0099936291338243);
    // Set group 3 bol bias 01 (VH) to 2.805732095961401 Volts
    Pacs_BOLC_SET_VH_G3(2.805732095961401);
    // Set group 3 bol bias 02 (VL) to -0.3942679040385992 Volts
    Pacs_BOLC_SET_VL_G3(-0.3942679040385992);
    // Set group 3 bol bias 03 (VRL) to 0.4339248022480186 Volts
    Pacs_BOLC_SET_VRL_G3(0.4339248022480186);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175166229478236 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175166229478236);
    // Set group 4 bol bias 01 (VH) to 2.8132260321912117 Volts
    Pacs_BOLC_SET_VH_G4(2.8132260321912117);
    // Set group 4 bol bias 02 (VL) to -0.3867739678087883 Volts
    Pacs_BOLC_SET_VL_G4(-0.3867739678087883);
    // Set group 4 bol bias 03 (VRL) to 0.4141623922109569 Volts
    Pacs_BOLC_SET_VRL_G4(0.4141623922109569);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.0213933637092976 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.0213933637092976);
    // Set group 5 bol bias 01 (VH) to 2.1145200531318697 Volts
    Pacs_BOLC_SET_VH_G5(2.1145200531318697);
    // Set group 5 bol bias 02 (VL) to -0.38547994686813014 Volts
    Pacs_BOLC_SET_VL_G5(-0.38547994686813014);
    // Set group 5 bol bias 03 (VRL) to 0.4292977832137159 Volts
    Pacs_BOLC_SET_VRL_G5(0.4292977832137159);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.006817368773259 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.006817368773259);
    // Set group 6 bol bias 01 (VH) to 2.1293608950052523 Volts
    Pacs_BOLC_SET_VH_G6(2.1293608950052523);
    // Set group 6 bol bias 02 (VL) to -0.3706391049947475 Volts
    Pacs_BOLC_SET_VL_G6(-0.3706391049947475);
    // Set group 6 bol bias 03 (VRL) to 0.4231555942593115 Volts
    Pacs_BOLC_SET_VRL_G6(0.4231555942593115);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9769002872568586 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9769002872568586);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	:  Short performance test Dark Current
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do dark current measurements in buffer transmission mode on
//                     both CS positions.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and internal CSs switched off.
//                        CDMS has to be switched to burst mode. After the end of the
//                        test go back to nominal mode.
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 2.0
// 
// History 	: 1.0 04-04-07 HD. IST update.
// 		  2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//	: 2.1 9-nov-2008 HD includes busconfig(7) for Burstmode
//
//              
obs PacsEng_Spec_dark_current_imt502 {
    /* Needed variables to call PacsEng_Spec_dark_current_imt502                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_dark_current_imt502                     */
}{
    //
    busconfig (7);
    // BURST MODE :     4:PACS PRIME  -  7:BURST MODE  - 8:PARALLEL MODE    
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_dark_current_imt502()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(300.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_dark_current_imt502();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  :  PACS FM IST SOVT2 & PV Phase
//
//
// Purpose      : Schedule the associated CUS procedure
//
// Author       : PRoyer
// CUS script   : PR
// CVS file     :
//
// Arguments    : 
//
//
// Description  : 
//
// Dependencies :  
//
// Preconditions: 
//	- PACS is switched on
//	- Setup spectroscopy with cold calibration sources
//
// Comments: 
//
// Version: 1.0
//
// History : 1.0 04-Nov-2008 Created from the corresponding PacsCal & from PacsEng_Spec_GeGa_Loop_Comm
//
//
obs PacsEng_Spec_Dark_SOVT2 {
    /* Needed variables to call PacsEng_Spec_Dark_SOVT2                        */
    int obs_time = 540; // Observing time per CS/FW/Grating setting
    int chop_time = 180; // Chopper plateau [sec] during CS temp rise time (0 = no chopping)
    /* End of needed variables for PacsEng_Spec_Dark_SOVT2                     */
}{
    debug_print("obs PacsEng_Spec_Dark_SOVT2. Version 1.0. 20081104");
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Dark_SOVT2(obs_time,chop_time)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic.
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Dark_SOVT2(obs_time,chop_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Spec_Gra_Diaghk_Setup.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Switch on diagnostic hk relevant to the driving SIN & COS signals of the grating 
//
// Author        : P. Royer
// CUSification  : DAC
// Arguments     :
//
// Description   : Grating diagnostic housekeeping ON
//               :
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 18-Apr-2006 initial version by PR
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose Switch on diagnostic housekeeping relevant to grating (driving SIN & COS)
// @comment - 
block PACS_Spec_Gra_Diaghk_SINCOS_Setup PACS 155 {
    int diag_hk_period = 5; // 5 msec diag hk period 
}{
    // Register start of BB
    WriteBBID($BBID);
    // Max number of requested diag HK parameters = 16
    // (including the last one, which is always forced to the same value)
    //
    //     DMC_GR_IND_SINE        539      
    //     DMC_GR_IND_COS         540      
    //     DMC_FWGRAT_HALLA       256
    //     DMC_FWGRAT_HALLB       257
    //     DMC_FW_GR_VMOTA        556
    //     DMC_FW_GR_VMOTB        564
    //     DMC_FW_GR_IMOTA        560
    //     DMC_FW_GR_IMOTB        567
    //     DMC_GRAT_CTRL_ST       208
    //     DMC_GRAT_CUR_POS       250
    //     DMC_GRAT_SETPOIN       251
    //     DMC_GRAT_TARGET        252
    //     DMC_GRAT_PID_ERR       253
    //     DMC_GRAT_OUTPUT        452
    //     DMC_GRAT_IND_READ      512
    {int}[] list_tuple = [{539},{540},{256},{257},{556},{564},{560},{567},{208},{250},{251},{252},{253},{452},{512},{0xffff}];
    int[] list_int = [539,540,256,257,556,564,560,567,208,250,251,252,253,452,512,0xffff];
    int chksum = checksum("int",list_int);
    int nbParams = length(list_int);
    Pacs_DMC_WRT_DIAG_HK_LIST(nbParams,list_tuple,chksum);
    delay(1);
    // DMC_START_DIAG_HK
    // DIAG_HK_PERIOD             PP076420
    // tcsend PC146420 [list PP076420 $diag_hk_period]
    // waittime $command_time
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    // End of procedure
    //------------------
    // Mark End of Block
    WriteEndBB();
}

// CVSscript   : DMC_spec_freq_switch.txt
// Description :
// Wavelength switching will be required on extended sources. No chopping
// will be done. Instead, the grating will be moved in a 2 or 3 position
// pattern around the spectral line to be observed. The frequency of
// internal calibrations is adjusted by the top loop around observation
// and calibration loops.
// It is of course possible to have also calibrations outside the
// sequence, just before and/or after.
//
//
// Dependencies  : Stand alone DEC/MEC sequence
//   
// Comments      : Follows verbatim paragraph 4.2.7 in PACS-ME-LI-005
//                 version 1.0
//         Actual values of input parameters, except values for the
//         various loop counters, are completely irrelevant and so
//         are not used. 
//         Loop counters are used to estimate the duree of the
//         sequence
//
// Version       : 0.1 22-Apr-2005 Creation by TM
// History       : 
//
// This "dummy" DEC/MEC sequence needs only the loop parameters from the
// complete list above
//
int[] procedure DMC_spec_freq_switch {
    int nb_full_seq = 1; // number of full sequences
    int nb_cycles = 8; // nb of grating/readout cycles on the line
    int nb_ramps_grat = 3; // number of ramps per grating position
    int nb_CS1 = 1; // number of cycles on CS1
    int nb_CS2 = 1; // number of cycles on CS2
}{
    // Define variables for time_array
    int duree_ramps = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Pseudo code from PACS OBCPs and DMC Sequences (4.1.7)
    // WAIT 1 ; have a defined start
    duree_ramps = duree_ramps + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; set Label to 0
    // LOOP P#1 ; main loop obs. + cal.
    for(int outloop = 1 .. nb_full_seq) {
        // WAIT 1 ; sync. for chopper
        duree_ramps = duree_ramps + 1;
        duree_OVR = duree_OVR + 1;
        // MOVE_CHOPPER_ABSOLUTE P#2 ; chopper to "on"
        // LOOP P#3 ; do it P#3 times
        for(int inloop1 = 1 .. nb_cycles) {
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#4 ; move grating to P#4
            // LABEL 33 ; wavelength switching
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_SRC = duree_SRC + nb_ramps_grat;
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#6 ; move grating to P#6
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_SRC = duree_SRC + nb_ramps_grat;
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#4 ; move grating to P#4
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_SRC = duree_SRC + nb_ramps_grat;
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#7 ; move grating to P#7
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_SRC = duree_SRC + nb_ramps_grat;
        }
        // END_LOOP ; end loop measurement
        // LOOP P#8 ; calibration loop1
        for(int inloop2 = 1 .. nb_CS1) {
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#4 ; move grating to P#4
            // MOVE_CHOPPER_ABSOLUTE P#9 ; chop to BB1
            // LABEL 97 ; indicate BB1
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_CAL = duree_CAL + nb_ramps_grat;
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#6 ; move grating to P#6
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_CAL = duree_CAL + nb_ramps_grat;
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#4 ; move grating to P#4
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_CAL = duree_CAL + nb_ramps_grat;
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#7 ; move grating to P#7
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_CAL = duree_CAL + nb_ramps_grat;
        }
        // END_LOOP ; end loop calibration1
        // LOOP P#10 ; calibration loop2
        for(int inloop3 = 1 .. nb_CS2) {
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#4 ; move grating to P#4
            // MOVE_CHOPPER_ABSOLUTE P#11 ; chop to BB2
            // LABEL 161 ; indicate BB2
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_CAL = duree_CAL + nb_ramps_grat;
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#6 ; move grating to P#6
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_CAL = duree_CAL + nb_ramps_grat;
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#4 ; move grating to P#4
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_CAL = duree_CAL + nb_ramps_grat;
            // WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_ABSOLUTE P#7 ; move grating to P#7
            // WAIT P#5 ; take P#5 ramps
            duree_ramps = duree_ramps + nb_ramps_grat;
            duree_CAL = duree_CAL + nb_ramps_grat;
        }
        // END_LOOP ; end loop calibration2
    }
    // END_LOOP ; end main loop
    // WAIT 1 ; complete last plateau
    duree_ramps = duree_ramps + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; no sequence anymore
    // END_SEQUENCE
    // Create time_array
    int[] time_array = [duree_ramps,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       :  Near real time adjustment of LHe flow for cryocover mirror 
//                  
//                 
//
// TCL author    : HF
// TCL file      : 
// CUS author    : HF 
// Script file   : Background_Radiance_Adjustment.txt 
//
// Input arguments none
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Uses OBCP 8 to interactively adjust the LHe flow through the
//                            cryocover mirror for telescope background simulation. Chops between
//                            CS1 - 0 - CS2 for a number of specified loops at a given capacitor and
//                            otherwise default detector settings. 
//                  
// Dependencies  : OBCP_spec_2_3_chop, SPEC_heater, SPEC_cre_setup
//
// Preconditions : PACS must be on and configured for spectroscopy
//                             nominal detector settings and reset interval = 64, default C=0.1pF 
//                 
// Comments      : Can be run with different capacitors for EQM IMT purposes
// 
// Version: 2.0
// History
// 1.0 24-Mar-2005 creation by HF
// 1.1 25-apr-2005 DAC Corrected for amended OBCP_spec_2_3_chop
// 1.2 23-jun-2005 HF, added SPU setup and reset
// 1.3 10-Apr-2006 HF, adapted for FM
// 1.4 26-Apr-2006 HF, added move to FW position B 
// 2.0 25-Mar-2008 VDP translated from IST to PV phase syntax
//
obs PacsEng_Background_Adjustment {
    /* Needed variables to call PacsEng_Background_Adjustment                        */
    int nb_up_down = 3; // Number of sequences: up down up ...
    int nb_grat_steps = 5; // Number of grating steps
    int nb_SRC_OFF = 5; // Nb cycles on/off source/grating position
    int nb_CS1_CS2 = 0; // Nbr cycles on cal src per grating position
    int grat_step = 0; // Grating step size
    int capa_blu = 0; // 0=0.1pf 8=0.2pf 4=0.4pF 12=1pF
    int capa_red = 0; // 0=0.1pf 8=0.2pf 4=0.4pF 12=1pF
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Background_Adjustment                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Background_Adjustment(nb_up_down,nb_grat_steps,nb_SRC_OFF,nb_CS1_CS2,grat_step,capa_blu,capa_red)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Background_Adjustment(nb_up_down,nb_grat_steps,nb_SRC_OFF,nb_CS1_CS2,grat_step,capa_blu,capa_red);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose	: Start Diag. HK
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do a chopper full field of view scan from -25000 cu to
//                + 25000 cu and vice versa with steps of 500. The grating is on a position
//		  such that in the blue we are at 87 microns and in the red at
//		  174 microns.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 7.0	
// 
// History 	: 1.0 21-07-06 creation by HD. Based on EQM IMT script "SPEC_Chop_fft_eqmimt_obs.txt"
//			       final chopper poistion (TBC).
//                3.0 26-07-06 HD. Incremental throw included.
//		  5.0 26-07-06 HD. script works.
//		  6.0 07-11-06 HD. Update.
//		  7.0 05-mar-2008 translated  into PV script VDP
obs PacsEng_Spec_Chopper_dhk_imt {
    /* Needed variables to call PacsEng_Spec_Chopper_dhk_imt                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Chopper_dhk_imt                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_Chopper_dhk_imt_bb()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_Chopper_dhk_imt_bb();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : FM ILT
//
// Purpose	:  Performance Test of internal PACS calibration sources
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description  : We start with a heat-up of the calibration sources. 
//                After monitoring for some while the behaviour on the desired temperature of
//                both internal PACS calibration sources, we do a smaller heat-up which is followed 
//                by a cooling down. The monitoring is based on diag. HK. 
//                PTD 0.7.11 and 0.7.12 are the basis for this test. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy 
//                 
// Comments	: This script is based on the commanding during the CQM ILT Tests. 
//
// Version	: 1.0	
// 
// History      : 
//		  1.0 09-11-06 HD. Adapted on FM ILT requirements.
//		  2.0 24-02-07 HD. Adapted for FM ILT.
block SPEC_CS_fmilt071112_heatup_cs_bb PACS 476 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //Switchon and enabling CSs
    Pacs_DMC_SWON_BB_1_CONT();
    Pacs_DMC_ENABLE_BB_1_CONT();
    Pacs_DMC_SWON_BB_2_CONT();
    Pacs_DMC_ENABLE_BB_2_CONT();
    //------------------------------------------------------------------------------
    // Heat the calibration sources up to 70 (XX.XK;CS1) and 80 
    // (70.5K;CS2) Ohm --- big step
    //------------------------------------------------------------------------------
    // start temperature CS1 in Ohm
    double cs1_temp = 70.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // start temperature CS2 in Ohm 	
    double cs2_temp = 80.0;
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    //After 60 minutes of heating-up and stay on the desired temperatures do another heat-up 
    delay(3600);
    // Mark End of Block
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       : Check performance of flashers under various low power regimes
//		   
//
// Author        : P. Royer
//
// Arguments     : 
//
// Prerequisite  : Flashers on
//
// Description   : Loops over low, but increasing currents sent to the flashers
//               :
// Comments      : 
//                 
//
// Version       : 2.0
// History       : 1.0 / 11-Aug-2006 initial version by PR
//                 1.1 / 05-Apr-2007 Update position of BB
//                       Include SWON/SWOF Flashers
//		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.1
// @purpose Check performance of flashers under low power regimes
// @comment - 
//
obs PacsEng_Spec_Flash_IST {
    /* Needed variables to call PacsEng_Spec_Flash_IST                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Flash_IST                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Flash_IST()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Flash_IST();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req.1.1.9 Measure time constants after cosmic ray impact
//
// Author : Koryo Okumura
//
// Version : May 27 2009
//
// CUS script : mode PacsCal_Phot_VrlGlitch
//
// Argument :
//   string biasTable = "BOLObias_standard_high"; // Bias table
//   string gain = "HIGH" in ["LOW","HIGH"]; // gain used during the measurements
//   int measureTime = 1200; // Measurement duration in seconds
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//   string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
//   string calGain = "NO_CHANGE" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description : OBS script to execute Phot_VrlGlitch
//
// Dependencies : None
//
// Comments : None
// Update :
//   2009-05-27 : Modified from PacsCal_Phot_glitch
//
obs PacsCal_Phot_VrlGlitch {
    string biasTable = "BOLObias_standard_low"; // Bias table
    string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
    int measureTime = 1400; // Measurement duration in seconds
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    string calBiasTable = "BOLObias_standard_low"; // Bias table used during calibration blocks
    string calGain = "NO_CHANGE" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 16; // number of readouts per plateau
    bool verbose = true;
}{
    // Bus configuration for the Burst mode (7)
    busconfig (7);
    // Several arguments needed for "basic_fine_pointing"
    int nRdts = readouts_plateau - 1;
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    //int timeOBSID = imax(1, duration(WriteOBSID($OBSID))+ duration(data_rate(300.0)));
    //int timeEndID = imax(1, duration(data_rate(0.0))+ duration(WriteEndID()));
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = 0;
    int timeChgBias0 = duration(PHOT_change_biases(biasTable,"NO_CHANGE","NO_CHANGE"));
    int timeCal3CPR1 = duration(Pacs_OBCP_chopped_photometry2(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    //Minimum slew time
    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT","LOW"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT",calGain));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"LOW"));
    }
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
    }
    int tslewmin = timeOBSID + timeChgBias + timeCal3CPR1;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeChgBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_VrlGlitch(biasTable,gain,measureTime));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(300.0);
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            // No biases setting here because nothing changes
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //**********************
            //  Call Phot_VrlGlitch
            //**********************
            Phot_VrlGlitch(biasTable,gain,measureTime);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// Script file   : OBCP_grat_scan_chop2_fast.txt 
// Purpose       : 
// OBCP author   : HF
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Belongs to Section 3.7: Grating Spectral Line Scan 
//                 of PACS-ME-LI-005, issue 1.4
//                 Consists mainly of a sequence with repetitive up- and
//                 down-scans with the grating around a given center position,
//                 while the chopper is operating as well on either two- or
//                 three-positions. This is OBCP 3.7.3, calling DMC sequence
//                 17 (in 4.2.2)
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : WARNING!! This version uses RAW version of START_OBCP 
// 
// History       : 0.1 26-jun-2006 DAC
// 0.2 27-nov-2006 Made grat_step_dn a negative number
//                
int[] block OBCP_grat_scan_chop2_fast PACS 23 {
    int nb_up_down = 1; // Nb of "up-down" sequences (P#1); 
    int nb_grat_steps = 20; // Nb of grating steps (P#2)
    int nb_cycles_grat_pos = 2; // Nb of cycles per grating position (P#3); 
    int chop_pos_REF1 = 1000; // Chopper position 1 (P#4) 
    int nb_ramps_plateau = 3; // Nb of readouts per chopper position (P#5); 
    int chop_pos_REF2 = 3000; // Chopper position 2 (P#6)
    int nb_CS1_CS2 = 1; // Nb of cycles on the internal CSs (P#7); 
    int chop_pos_CS1 = -25000; // Chopper position on CS1 (P#8)
    int chop_pos_CS2 = 25000; // Chopper position on CS2 (P#9)
    int grat_step_up = 1600; // Grating step up (P#10) 
    int grat_step_dn = -1600; // Grating step down (P#11) 
    int detector = 2; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 445000; // Starting grating position
    int grat_time = 40000; // Grating time to move to start [msec]
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopper default position
    int grat_def_time = 20000; // Time to come back to default position
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    //debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    //debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duree_msec [msec] as it goes)
    // Begin 
    // OBCP_GRATING_LINE_SCAN_CHOPPED_2(seq, seq_time,
    //   P#1,&,P#11, detector, grat_def, grat_time,
    //   cmp_par_blue, cmp_par_red, grat_def, chop_def, grat_time)
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_pos) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) ; (all parameters filled 
    // by DPU based on seq parameter) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_time) 
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    // DMC_START_SEQUENCE
    //////////////////////////////////////////////////////////////////////////
    // Call DEC/MEC code to estimate its duration
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    int[] duree1 = DMC_grat_scan_chop2_fast(nb_up_down,nb_grat_steps,nb_ramps_plateau,nb_CS1_CS2,nb_cycles_grat_pos);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    //  debug_print("Execution time [msec] from DMC: " + seq_time);
    // duree_msec(seq_time) 
    duree_msec = duree_msec + t_cmd + seq_time;
    // WAIT(seq_time) ; Check execution status of the sequence and in case of 
    // failure stop OBCP and issue TM(1,8)+event 
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_def_time) 
    duree_msec = duree_msec + grat_def_time;
    duree_OVR = duree_OVR + grat_def_time;
    // Issue TM(1,7)
    // End 
    // Now trigger execution of OBCP
    // This OBCP is number 23, requires 21 parameters and calls DEC/MEC #17
    string obcp_ID = "GRAT_SCAN_CHOP2_FAST";
    int obcp_NB = 23;
    int obcp_par_nb = 21;
    int seq_DMC = 17;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_grat_steps},{5,nb_cycles_grat_pos},{6,chop_pos_REF1},{7,nb_ramps_plateau},{8,chop_pos_REF2},{9,nb_CS1_CS2},{10,chop_pos_CS1},{11,chop_pos_CS2},{12,grat_step_up},{13,grat_step_dn},{14,detector},{15,grat_pos},{16,grat_time},{17,comp_mode_blu},{18,comp_mode_red},{19,grat_def},{20,chop_def},{21,grat_def_time}];
    Pacs_DPU_START_OBCP_RAW(obcp_NB,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // debug_print(obcp_ID + ": " + time_array);
    delay(time_array[0]);
    // Return the array of times

    return time_array;
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Move Grat Abs
//
// CUS author    : Pierre Royer
//
// Version       : 2.0
//
// History       : 1.0 29-Jul-2007
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_Gra_IST_Disable {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Disable                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_Disable                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_IST_Disable()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_IST_Disable();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : PACS FM Test
//
// Purpose       : Switch on of bolometer groups
//
// Author        : T. Mueller
//
// File          : PHOT_switchon_groups
// Arguments     : none
//                 
//
// Description   : This script will switch on the different groups
//                 of the instrument. BOLC will start in "HK only" mode.
//                              
// Comments      :  Coded based on PhFPU UM, Draft 5
//
// Version       : 1.1
// History       : 1.0 / 08-Nov-2006 initial version by TM
//                    1.1 / 08-Nov-2006 TM: autonomy function 17 added
//                    1.1.1 14-nov-2006 Disable autonomy function for time being
//                    1.2 17-nov-2006 Enable AF with delay after switchon
//                    1.3 09-apr-2007 disable AFs before starting
// 
procedure PHOT_switchon_groups {
}{
    // disable AF 12, AF 15, AF 17
    // disable AF 12 (to check for the protection biases)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_BIAS","DISABLE");
    // disable AF 15 (to check for the VSS currents of groups and BUs)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","DISABLE");
    // disable AF 17 (to check for group power)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_V_PWR","DISABLE");
    //
    delay(2);
    // PC103420 "DMC_SEND_COMMAND_BOLC" SEND COMMAND TO BOL CONTROLLER
    //         PP071420 "BOLOMETER_COMMAND"
    //
    // # Execute BOLC initialisation
    // # for CQM we switched on everything at once, now group by
    // # group starting with 1
    // 
    // # Switch-on group 1 The corresponding bits
    // # are (2^0)=1, which is 1 in hex.
    // tcsend PC103420 {PP071420 0x0A000001 LO}
    // waittime 1.0
    int operand = 0xa000001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2. The corresponding bits
    // # are (2^0+2^1)=3, which is 3 in hex.
    // tcsend PC103420 {PP071420 0x0A000003 LO}
    // waittime 1.0
    operand = 0xa000003;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3. The corresponding bits
    // # are (2^0+2^2+2^3)=7, which is 7 in hex.
    // tcsend PC103420 {PP071420 0x0A000007 LO}
    // waittime 1.0
    operand = 0xa000007;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4. The corresponding bits
    // # are (2^0+2^1+2^2+2^3)=15, which is F in hex.
    // tcsend PC103420 {PP071420 0x0A00000F LO}
    // waittime 1.0
    operand = 0xa00000f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4,5. The corresponding bits
    // # are (2^0+2^1+2^2+2^3+2^4)=31, which is 1F in hex.
    // tcsend PC103420 {PP071420 0x0A00001F LO}
    // waittime 1.0
    operand = 0xa00001f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4,5,6. The corresponding bits
    // # are (2^0+2^1+2^2+2^3+2^4+2^5)=63, which is 3F in hex.
    // tcsend PC103420 {PP071420 0x0A00003F LO}
    // waittime 1.0
    operand = 0xa00003f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(8);
    //------------------------------------
    // autonomy function
    //------------------------------------
    // autonomy function 17 "generate_event_pwr" checks the
    // HK entries: PC_PWR_ANA_P_#, PC_PWR_ANA_N_# and PC_PWR_DIG_#,
    // with # = [1,2,3,4,5,6,7]
    Pacs_DPU_SET_FUNCT("EVENT_BOL_V_PWR","ENABLE");
    // Wait another 2 sec
    delay(2);
    //
    //-----------------
    // End of Procedure
    //-----------------
}

// Mission phase : Commissioning phase and later
//
// Purpose       : Read a BOLObias calibration table and command bias
//                 voltages for all the groups
//                 and then set direct or DDCS mode and gain
//
// Author        : Koryo Okumura
// CUS script    : Koryo Okumura
//
// Arguments     : 
// string  biasTable    The bias table name
// string  gain         The gain "LOW" or "HIGH"
//
// Description   : Read a bias table in volts and set the direct mode
//                  
// Dependencies  : None
//
// Preconditions : Photometer is on and the sequencer is set
//
// Comments      :
//
// Version       : 0.1
// History       : 02-Jul-2008, KO: First version
//
procedure PHOT_set_biases {
    string biasTable = "BOLObias_ILT_standard_low"; // Bias table [volts]
    string setting = "DIRECT" in ["DIRECT","DDCS"]; // Readout mode
    string gain = "LOW" in ["LOW","HIGH"]; // Gain
}{
    int operand = 0;
    //
    //***********************************************
    // Bias setting of the detectors
    //***********************************************
    //
    PHOT_set_bias_volt(biasTable,1);
    PHOT_set_bias_volt(biasTable,2);
    PHOT_set_bias_volt(biasTable,3);
    PHOT_set_bias_volt(biasTable,4);
    PHOT_set_bias_volt(biasTable,5);
    PHOT_set_bias_volt(biasTable,6);
    //
    if(setting == "DIRECT") {
        //********************************************************
        // Sequence mode : blocking on VDEC_X for the direct mode
        //********************************************************
        //
        // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
        Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
        // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
        Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
        //
        //**********************************************************
        // Sequence mode : Sref_only (meaning set for the bolometer)
        //**********************************************************
        //
        // Stop SPU
        PACS_Phot_SPU_Reset();
        delay(1);
        // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
        //# P 09 01 00 01
        operand = 0x9010001;
    } else {
        // Stop SPU
        PACS_Phot_SPU_Reset();
        delay(1);
        // Set seq mode Sbolo-Sref (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sbolo-Sref");
        //# P 09 01 00 00
        operand = 0x9010000;
    }
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //**************************************
    // Start SPU in the appropriate setting
    // including bits rounding for high gain
    //**************************************
    PHOT_spu_gain_setup(gain,0,0,3,3,true);
    delay(1);
    // to sync the bus
    sync();
}

// $Id
// Missionphase		: PACS PV Phase
//
// Purpose :		Fully flexible spectrometer calibration block during PacsSlew
// Author		 : P Royer
//
// Arguments		:
//
// Prerequisite 	: PACS does not need to be on nor setup for spectroscopy
//
// Description		: Uses OBCP 35 and performs AOT prologue and epilogue
// 
// Comments		:
//
// Dependencies		: CONF_SPEC_params : The detector biases are read from column "Normal0"
//
// Version		: 1.2
// 
// History		:  1.0 11-Feb-2009 PR Creation from PacsCal_PacsSpecSlewCal_Flex
// 		   1.1 07-May-2009 PR Upgrade ramp_fit_alg (match FS database) & nb_raw as parameters
//			                      Add parameter no_gratmove
//		   1.2  23-Jul-2009 PR add parameter initial_delay (see also PacsSpecSlewCal35_Flex). SPR PACS-1857
//                                                   29-Jul-2009 PR update history : last change referred to SPR PACS-1857 (SCR PHS-1128)
//
obs PacsCal_PacsSpecSlewCal35_Flex {
    /* Needed variables to call PacsSpecSlewCal */
    /* FW, WAVELENGTH & OBCP parameters */
    double[] waves = [60.0]; // Wavelengths
    int order = 2;
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int nb_up_dn = 1; //       	     nb_up_down  	   	 	  	OBCP 19 DMCSeq. P#1
    int nb_grat_steps = 16; //	     nb_grating_steps  	   	   	OBCP 19 DMCSeq. P#2
    int nb_cycles_grat = 2; //	     nb_chop_cycles_per_gratpos  	OBCP 19 DMCSeq. P#4
    int nb_ramps_grat_pos = 1; //nb_ramps_per_gratpos  		OBCP 19 DMCSeq. P#6
    int initial_delay = 30; // Fixed delay (for drifts) at the start of the OBCP (added to grat_(start)_time)
    bool no_gratmove = false; // false: gratstep read from CALU. True: gratstep forced to 0
    /* CRE & SPU PARAMETERS */
    int capa_blu = 12;
    int capa_red = 12;
    int nb_rdouts_ramp_blu = 64;
    int nb_rdouts_ramp_red = 64;
    int nb_rdouts_subramp_blu = 16;
    int nb_rdouts_subramp_red = 16;
    int ramp_fit_alg_blu = 1;
    int ramp_fit_alg_red = 1;
    int nb_raw_blu = 3;
    int nb_raw_red = 3;
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    /* POINTING PARAMETERS */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    bool verbose = true;
}{
    // FIXED CRE & SPU Parameters
    int glitch_det_blu = 1;
    int glitch_det_red = 1;
    int bias_d_blu_mV = ilookup("CONF_SPEC_params","bias_d_blu","Normal0");
    int bias_d_red_mV = ilookup("CONF_SPEC_params","bias_d_red","Normal0");
    int bias_r_blu_mV = ilookup("CONF_SPEC_params","bias_r_blu","Normal0");
    int bias_r_red_mV = ilookup("CONF_SPEC_params","bias_r_red","Normal0");
    // FIXED OBCP Parameters
    // OBCP 19 DMCSeq. P#3
    string order_str = "" + order;
    int grat_step_up = ilookup("SPEC_BAND_params",order_str,"HI");
    if(no_gratmove) {
        grat_step_up = 0;
    }
    // OBCP 19 DMCSeq. P#11
    int grat_step_dn = -1 * grat_step_up;
    // OBCP 19 DMCSeq. P#5 == P#9
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","SPEC","pos_CS1");
    // OBCP 19 DMCSeq. P#7 == P#10
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    // OBCP 19 DMCSeq. P#8
    int nb_cycles_cal = 0;
    // Synchronize on this detector 1:Blue 2:Red
    int detector = 1;
    // Chopped default position
    int chop_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int grat_pos = grat_park;
    // PacsSpecSlewCal_Flex parks the grating already
    //
    // compiting time for slw / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Verification for grating and chopper hard limits
    //double chopthrow = 30.0;
    //int[] gratpos = [0];
    //Pacs_HardLimitsCheck(gratpos,chopthrow);
    // Calibration time during slew
    // SPEC parameters for BLU and RED    
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{capa_blu,nb_rdouts_ramp_blu,nb_rdouts_subramp_blu,comp_mode_blu,glitch_det_blu,ramp_fit_alg_blu,nb_raw_blu,bias_r_blu_mV,bias_d_blu_mV}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{capa_red,nb_rdouts_ramp_red,nb_rdouts_subramp_red,comp_mode_red,glitch_det_red,ramp_fit_alg_red,nb_raw_red,bias_r_red_mV,bias_d_red_mV}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{nb_up_dn,nb_grat_steps,grat_step_up,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,nb_cycles_cal,detector,chop_def}];
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    //
    //
    //Initial hold
    int tih = duration(WriteOBSID($OBSID));
    int tslewmin = 0;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int tepilog = duration(SPEC_aot_epilogue(grat_pos,grat_park,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(PacsSpecSlewCal35_Flex(verbose,confSPECblu,confSPECred,confOBCP,initial_delay,doPROLOG,waves,fltPOS,order));
    if(verbose) {
        debug_print("Duration of PacsSpecSlewCal_Flex" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    debug_print("ts: " + ts);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            int tNOW = time();
            // 
            WriteOBSID($OBSID);
            data_rate(120.0);
            if(verbose) {
                debug_print("WriteOBSID at :" + tNOW + " sec");
            }
            tNOW = time();
            if(verbose) {
                debug_print("WriteOBSID ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                tNOW = time();
                PacsSpecSlewCal35_Flex(verbose,confSPECblu,confSPECred,confOBCP,initial_delay,doPROLOG,waves,fltPOS,order);
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 5) {
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold starts at :" + tNOW + " sec");
                    }
                    SPEC_aot_epilogue(grat_pos,grat_park,verbose);
                    data_rate(0.0);
                    WriteEndID();
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold ends at :" + tNOW + " sec");
                    }
                }
            }
        }
    }
    // End of Observation
}

// Missionphase  :  FM-ILT
//
// Purpose       : Perform Spectroscopy thermal behaviour
//
// CUS author    : TM, DAC
// Script file   : SPEC_thermal.cus
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 0.1 TM 10-nov-2006
//                 0.2 17-nov-2006 DAC&TM Completed script
//                 0.3 17-nov-2006 TM Completed script
//                 0.4 02-mar-2007 TM updated for FM, incl. diagHK
//                 0.5 05-mar-2007 TM updated for chopper and diagHK
//                 0.6 14-mar-2007 TM updated for OBCPs and diagHK
//                 0.7 07-apr-2007 new chopper controller parameters,
//                                            filter movements after all configurations
//                 0.8 07-Apr-2008 Changed bias values to in-flight default 30mV/80mV
//		   1.0 05-dec-2008 VD changed call for CONFGrat with ISTSafe
//
procedure SPEC_thermal {
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double temp_CS1 = 48.0;
    double temp_CS2 = 58.0;
}{
    // wait for a clean start
    delay(60);
    // Start "elementary" scripts
    SPEC_dpu_dmc_setup();
    // wait 
    delay(30);
    // Configure initial configuration for CREs
    SPEC_init_det_setup();
    delay(300);
    // Default CRE configuration (set default bias, ramp length, and capacitor)
    // Red  ramp length
    int ramp_len_red = 64;
    // Blue ramp length
    int ramp_len_blu = 64;
    // BIAS_D for red spectro  (0-1V)
    double bias_d_red = 0.03;
    // BIAS_R for red spectro  (0-1V)
    double bias_r_red = 0.01;
    // BIAS_D for blue spectro (0-1V)
    double bias_d_blu = 0.08;
    // BIAS_R for blue spectro (0-1V)
    double bias_r_blu = 0.01;
    // Capacitor red  (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_red = 12;
    // Capacitor blue (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_blu = 12;
    double blu_heater_curr = 0.0;
    SPEC_CRE_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,blu_heater_curr);
    // wait
    delay(300);
    // command the blue detector heater to its operational
    // temperature
    SPEC_heater_setup(1.5);
    delay(300);
    //
    //  configure diag HK for filterwheel, grating, chopper
    int diag_hk_period = 5;
    //     DMC_CHOP_CUR_POS       244
    //     DMC_CHOP_SETPOINT      245
    //     DMC_CHOP_TARGET        246
    //     DMC_GRAT_CUR_POS       250
    //     DMC_GRAT_SETPOIN       251
    //     DMC_GRAT_TARGET        252
    //     DMC_FWSP_CUR_POS       255
    //     DMC_FWGRAT_HALL_A      256
    //     DMC_FWGRAT_HALL_B      257
    //     DMC_CHOP_OUTPUT        258
    //     DMC_GRAT_OUTPUT        452
    //     DMC_FWSPEC_POS_A       555
    //     DMC_FWSPEC_POS_A       559
    //     DMC_CHOP_IA            561
    {int}[] list_tuple = [{244},{245},{246},{250},{251},{252},{255},{256},{257},{258},{452},{555},{559},{561},{0xffff}];
    int[] list_int = [244,245,246,250,251,252,255,256,257,258,452,555,559,561,0xffff];
    int chksum = checksum("int",list_int);
    int nbParams = length(list_int);
    Pacs_DMC_WRT_DIAG_HK_LIST(nbParams,list_tuple,chksum);
    delay(1);
    // DMC_START_DIAG_HK
    // DIAG_HK_PERIOD             PP076420
    // tcsend PC146420 [list PP076420 $diag_hk_period]
    // waittime $command_time
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    // CONFigure SPEC filter wheel
    CONF_spec_fltw();
    delay(30);
    // CONFigure chopper
    // DMC_WRT_CHOP_CONF_PAR
    CONF_chopper("CONFChopper","nom_sky");
    CHOP_on_off("ON");
    delay(30);
    // CONFigure Grating
    CONF_grating("CONFGrat","ISTSafe");
    delay(120);
    // move filter wheel
    //  move 6 times to both positions
    for(int imove = 1 .. 6) {
        SPEC_fltw_move("POS A");
        SPEC_fltw_move("POS B");
    }
    delay(120);
    // start OBCP 8 with chopper only (224 sec)
    OBCP_spec_2_3_chop(1,1,0,0,1,0,0,80,-12000,12000,0,0,1,900000,11000,16,16,500000,0,6000,64);
    delay(60);
    // start OBCP 8 with grating only (224 sec)
    OBCP_spec_2_3_chop(240,1,0,0,1,0,0,0,-12000,12000,133,-133,1,900000,11000,16,16,500000,0,6000,64);
    delay(60);
    // start OBCP 8 with chopper and grating only (224 sec)
    OBCP_spec_2_3_chop(80,1,0,0,1,0,0,1,-12000,12000,133,-133,1,900000,11000,16,16,500000,0,6000,64);
    delay(120);
    // stop diag HK again
    Pacs_DMC_STOP_DIAG_HK();
    //   configuration of calibration sources and switch on
    CONF_cs("Both");
    CS_on_off("CS1","ON");
    CS_on_off("CS2","ON");
    delay(60);
    //  CS1 to 48 (55K) and CS2 to 58 (60K)
    CS_temp("CS1",48.0);
    CS_temp("CS2",58.0);
    delay(2700);
    //   Switch off the CSs
    CS_on_off("CS1","OFF");
    CS_on_off("CS2","OFF");
    delay(300);
    // command the red detector heater to 5mA for 5 min
    Pacs_DMC_SWON_RD_HEATER();
    delay(60);
    Pacs_DMC_SET_R_SPEC_HEAT_C(5.0);
    delay(300);
    Pacs_DMC_SET_R_SPEC_HEAT_C(0.0);
    delay(300);
    // command the blue detector heater to 5mA for 5 min
    // for a curing test (to be replaced later by a curing procedure)
    SPEC_heater_setup(5.0);
    delay(300);
    SPEC_heater_setup(1.5);
    delay(900);
    //   Switch off chopper controller
    CHOP_on_off("OFF");
    delay(120);
    //   Switch off grating controller
    Pacs_DMC_SWOF_GRAT_CONT();
    delay(120);
    //
    //
    // SWITCH OFF BLUE/RED SPECTROMETER ARRAY POWER
    Pacs_DMC_SWOF_B_SPEC();
    delay(1);
    Pacs_DMC_SWOF_R_SPEC();
    delay(300);
    // Switch-off B and R DEC power, wait 8 sec
    Pacs_DMC_SWOF_B_DEC();
    delay(60);
    Pacs_DMC_SWOF_R_DEC();
    delay(60);
    // SAFE mode
    OBCP_SAFE();
    //End of procedure
}

// CVS comments  : $Id: 
// Purpose       : Estimate several PACS parameters for each spectral
//                 line specified by the HSPOT user
//
// CUS author    :VD &  DAC
//
// Input arguments
// type           name            Description
// tuple          lines           spectral line info from HSPOT
// tuple          waveTuple       grating info associated to "lines"
// tuple          paramsSPECdef   confSPECblu & confSPECred & confOBCP
//
// Return values
// Type             Description
// tuple            Derived values for paramsSPECdef
//
// Description   : Fill the PACS state descriptors confSPECx & confOBCP, per
//                 HSPOT defined wavelength, with values obtained from
//                 OBCP32params (a CAL-U file). This procedure is called once 
//                 per spectral line. The repFactor is implemented as the
//                 number of nb_obs_cal parameter in OBCP freq switch.
//
// Dependencies  : 
//
// Preconditions :
//
// Comments      : Several confOBCP elements differ from non switched OBCPs
//                 Code keeps old confOBCP commented out for reference.
//                 NOTE.Several confOBCP elements are redefined here!!
// 
// History       : 0.1 17-sep-2009 VD unChop CalU file
//                                    PHS-1119
//               : 0.2 21-sep-2009 VD updates on parameters combination
//               : 0.3 22-sep-2009 VD updates on parameters combination
//    
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsLineSpecEstimatorOBCP32_unChop {
    {string,double,int,double,double,double,string,string} lines = {"NONE",60.2,1,0.0,0.0,0.0,"bla","bla"}; // linesTuple HSPOT
    {double,int,int,int,int} waveTuple = {100.0,1,500000,0,0}; // waveTuple          
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; // Default values
    bool verbose = true; // print debug information
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    // ORDER of the current line
    int order = waveTuple{1};
    double waveLEN = waveTuple{0};
    // User desired repetition factor for current line
    int userREPfactor = lines{2};
    // Get the "quantum" OBS time for the current order.
    // Grating info pertaining to the current wavelength is in waveTuple
    int grat_pos_LINE = waveTuple{2};
    // Get "duration" and switch parameters from OBCP22params U-CAL table
    // There is a row per order; it lists main OBCP parameters
    string calNAME = "OBCP32params_unChop";
    // The acces key is the grating order
    // Grab OBCP parameters from CALU file
    string key = "" + order;
    int nb_ramps_grat = ilookup(calNAME,key,"P6ramps");
    int nb_up_dn = ilookup(calNAME,key,"P1UpDn");
    int ditherCount = ilookup(calNAME,key,"P2shifts");
    int ditherSize = ilookup(calNAME,key,"P3dither");
    int jumpAtoB = ilookup(calNAME,key,"P7move");
    int nbABBA = ilookup(calNAME,key,"P4ABBA");
    // NOTE: nb_up_dn above is multiplied by userREPfactor
    nb_up_dn = nb_up_dn * userREPfactor;
    // Still to compute offline: offset to grat_pos_LINE so line is centered at 1/2
    // dithering cycle
    int start_offline = ditherSize + nbABBA * (jumpAtoB * 4);
    int grat_pos_LINE_start = grat_pos_LINE - start_offline;
    if(verbose) {
        debug_print("Estim.OBCP32:gratLINE/graLINE_start: " + grat_pos_LINE + "/" + grat_pos_LINE_start);
    }
    // Estimate the OBS time for this rangeInfo; estimation is for ONE nod only.
    // Get nb_rdouts_ramp from confSPECred
    int nbRdOutsRamp = confSPECred{1};
    int[] dureeOBCP32 = PacsDureeOBCP32_unChop(ditherCount,nb_up_dn,nbABBA,nb_ramps_grat,nbRdOutsRamp);
    // Use SRC/REF duration to compute quantumOBStime
    int quantumOBStime = dureeOBCP32[1] + dureeOBCP32[2];
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + waveLEN + " [&micro;m] with line repeated " + userREPfactor + " time(s)</p>";
    lineCnt = lineCnt + 1;
    if(verbose) {
        debug_print("Estim.OBCP32:jumpAtoB/gratLINE/nbABBA/ditherSize: " + jumpAtoB + "/" + grat_pos_LINE + "/" + nbABBA + "/" + ditherSize);
    }
    // Pack information into proper tuples
    // confOBCP { 0}  =   nb_up_down      ;
    // confOBCP { 0}  =   nb_obs_cal       ;
    confOBCP{0} = nb_up_dn;
    // confOBCP { 1}  =   grat_step_up     ;
    confOBCP{1} = jumpAtoB;
    // confOBCP { 2}  =   grat_step_dn     ;
    confOBCP{2} = nbABBA;
    // confOBCP { 3}  =   nb_SRC_OFF       ;
    // confOBCP { 3}  =   nb_SRC           ;
    confOBCP{4} = nb_ramps_grat;
    // confOBCP { 5}  =   nb_CS1           ;
    // confOBCP { 6}  =   nb_grat_step_up  ;
    // confOBCP { 6}  =   nb_CS2           ;
    // confOBCP { 7}  =   nb_grat_step_dn  ;
    confOBCP{7} = ditherCount;
    // confOBCP { 8}  =   grat_start_pos   ;
    confOBCP{8} = grat_pos_LINE;
    //    confOBCP { 9}  =   grat_start_time  ;
    confOBCP{9} = ditherSize;
    //    confOBCP {10}  =   grat_def_pos     ;
    //    confOBCP {11}  =   grat_def_time    ;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    //   confSPECred{0} = capa_red;
    //   confSPECred{ 1} =  nb_rdouts_ramp_red;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    // int comp_mode_red = 16;
    //   confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    //   confSPECblu{0} = capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts_ramp_blu;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    // int comp_mode_blu = 16;
    //   confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    string msgLabel = "Observing time for " + lines{0};
    PacsMessageCenter(msgLabel,lineCnt,msgLine);
    int nb_nods = 0;
    int aux3 = 0;

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,ditherCount,quantumOBStime,aux3}};
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Gra_Mec_Setup_Cold_Redun {
    /* variables to call PacsEng_Spec_Gra_Mec_Setup_Cold_Redun             */
    string calUrow = "ISTSlow_R"; // INSTRUMENT VERSION
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_Mec_Setup_Cold_Redun       */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_Mec_Setup_Cold_Redun(calUrow)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_Mec_Setup_Cold_Redun(calUrow);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : FM ILT / IST
//
// Purpose       :  Flux check on CS at wavelengths suited for filter
//                  
//
// Input arguments 
// type    name         description
// string  calsource    "CS1" or "CS2"
// string  filter           "A" or "B"
// Return values
// Type    Name      Default      Description
//
// Description   :  Uses OBCP28 
//                  
// Dependencies  : 
//
// Preconditions : 
//                 
// Comments      : 
// 
// History : 1.0 BV 12-03-2007 Creation
//              2.0 BV 06-04-2007 Ramp averages 
//              2.1 BV 27-07-2009 SPR 1798 corrected biases
procedure SPEC_fluxref {
    string calsource = "CS2" in ["CS1","CS2"]; // calsource
    string filter = "A" in ["A","B"]; // filter
}{
    int chop_def = 21200;
    // Position of CS2
    if(calsource == "CS1") {
        chop_def = -21350;
    }
    int grating_start = 790000;
    // for key wavelength in filter A
    if(filter == "B") {
        grating_start = 531000;
    }
    int capa_red = 0;
    // Red capacitor
    int capa_blu = 0;
    // Blue capacitor
    // grating start position for scan
    int grating_stepsize = 168;
    // grating step size
    int grating_numsteps = 48;
    // number of grating steps in one direction
    int grating_numramps = 2;
    // number of ramps per grating position
    int readoutsperramp = 64;
    // number of readouts per ramp
    int num_updown = 2;
    // number of grating updown scans
    int grat_def = 496000;
    // position of grating after the scan
    int chop_pos_CS1 = -21350;
    int chop_pos_CS2 = 21200;
    int detector = 1;
    // Synchronize on this detector 1:Blue 2:Red
    int nb_CS1_CS2 = 0;
    // number of cycles on calsources, 0=don't use them
    int nb_ramps_CS = 3;
    // number of ramps on CSs
    int grat_start_time = 15000;
    // time for grating to start [ms]
    int grat_def_time = 15000;
    // CRE settings
    int ramp_len_blu = readoutsperramp;
    int ramp_len_red = readoutsperramp;
    // Set up the blue and red CRE subsystem
    // cre_ctrl is a bit field:
    // 256=sync width=2, 128=T sensor on, 2=enable, 1=power on
    // Do not enable yet
    int cre_ctrl_red = 256 + 128 + 2 + 1;
    int cre_ctrl_blu = 256 + 128 + 2 + 1;
    // Give ENG values for the bias [v]
    double bias_r_blu = 0.01;
    double bias_r_red = 0.01;
    double bias_d_blu = 0.1;
    double bias_d_red = 0.042;
    SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // 
    // SPU parameters
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int nb_samp_subramp_blu = 16;
    // Nb of blue samples per sub-ramp 
    int nb_samp_subramp_red = 16;
    // Nb of red samples per sub-ramp 
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    // Reset SPU
    SPEC_spu_reset();
    // Re-start SPU in default mode
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //
    Pacs_DMC_MOVE_CHOP_ABS(chop_def);
    Pacs_DMC_MOVE_GRAT_ABS(grating_start);
    delay(60);
    OBCP_grat_scan_nochop(num_updown,grating_numsteps,grating_stepsize,-grating_stepsize,grating_numramps,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,nb_ramps_CS,grating_numsteps,chop_def,detector,grating_start,grat_start_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,readoutsperramp);
    //
    // Reset spu
    Pacs_DMC_MOVE_CHOP_ABS(650);
    SPEC_spu_reset();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       :  Test different reset intervals in spectroscopy
//                  
//                 
//
// TCL author    : HF
// TCL file      : none
// CUS author    : HF
// Script file   : SPEC_Readouts_per_Ramp_test.txt 
//
// Input arguments none
// type    name         description
//
// Return values none
// Type    Name      Default      Description
//
// Description   : Test of different values for readouts per ramp at same flux
//                           level 
//                  
//
// Preconditions : PACS must be switched-on and in Spectroscopy mode
//                 
// Comments      :  
// 
// Version	 : 2.0
// History       : 1.0 29-Mar-2005 creation by HF
//                 1.1 05-Apr-2005 modify dummy resistor bias and
//                                   length of measurement
//                 1.2 15-Apr-2005 HF, add SPU reset at the end
//                 1.3 11-Apr-2006 HF, adapted to FM, smallest capacitor
//		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//                    
obs PacsEng_Spec_Readouts_per_Ramp_Test {
    /* Needed variables to call PacsEng_Spec_Readouts_per_Ramp_Test                        */
    int ramp_len_red = 64; // Red  ramp length
    int ramp_len_blu = 64; // Blue ramp length
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Readouts_per_Ramp_Test                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Readouts_per_Ramp_Test(ramp_len_red,ramp_len_blu)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Readouts_per_Ramp_Test(ramp_len_red,ramp_len_blu);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       : Flasher curing : short flashes with dead times -> Temp & signal evolutions
//		   Third part of the Flashers Performance check (curing schemes)
//
// Author        : P. Royer
//
// Arguments     : 
//
// Prerequisite  : Flashers on
//
// Description   : Check scheme of flasher curing : short flashes with dead times
//               :
// Comments      : 
//                 
//
// Version       : 2.1
// History       : 1.0 / 09-Jun-2006 initial version by PR
//                 1.1 / 06-Apr-2007 Updated chop_pos_BB -> FMILT BB2
//		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//	2.1 01-Jul-2008 Introduced "final_delay" parameter
//		   
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.1
// @purpose Flasher curing : short flashes with dead times -> Temp & signal evolutions
// @comment - 
//
obs PacsEng_Spec_Curing {
    /* Needed variables to call PacsEng_Spec_Curing                        */
    int blue_flasher_current = 819; //4mA. [0,4095] = [0,20 mA]
    int red_flasher_current = 819; //4mA. [0,4095] = [0,20 mA]
    int nflash = 3; // Number of flashes
    int flash_time = 60; // Duration of each flash
    int idle_time = 120; // Idle time between the flashes
    int final_delay = 1; // Idle time at the end of the test (flasher cooldown, detector stabilisation),
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Curing                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Curing(blue_flasher_current,red_flasher_current,nflash,flash_time,idle_time,final_delay)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Curing(blue_flasher_current,red_flasher_current,nflash,flash_time,idle_time,final_delay);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : FM
//
// Purpose	:  Setup diagnostic housekeeping for the FM 
//                 chopper tests. Special HKs.
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: Set up 2 housekeeping parameter for diagnostic housekeeping 
//	  of the chopper for open loop tests.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and SPEC_Chop_fft_eqmimt_obs
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 1.0	
// 
// History 	: 
//	  1.0 08-11-06 HD. Spec. HK for open loop measurements.	  
block SPEC_Chopper_dhk_imt_perf_bb PACS 395 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //-------------------------------------------- 
    // Setup and start diagnostic HK for Chopper
    //-------------------------------------------- 
    int chop_diag_hk_length = 4;
    {int}[] parlist = [{244},{245},{258},{0xffff}];
    int[] aux = [244,245,258,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(chop_diag_hk_length,parlist,check_sum);
    int diag_hk_period = 0;
    // Synchronize diagnostic HK on blue spectrometer readouts
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark End of Block
    WriteEndBB();
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Move Grat Abs
//
// CUS author    : Pierre Royer
//
// Version       : 2.0
//
// History       : 1.0 29-Jul-2007
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_Gra_IST_Move_Abs {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Move_Abs                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_Move_Abs                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_IST_Move_Abs()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_IST_Move_Abs();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : SPEC_Chopper_imt504_ast_OBS.cus
//
// Purpose	:  Short performance test of Chopper in IMT
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do rectangular chopping for four frequencies with OBCP27 and its
//                corresponding DMC-sequence 12.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy
//                 
// Comments	: This script is based on the commanding during the CQM/FM ILT.
//
// Version	: 3.1	
// 
// History 	: 1.0 04-04-07 HD. IST tuned.
//		  2.0 05-07-07 HD. IST Chopper Day.
//		  3.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//                                           3.1 08-Apr-2008 HF changed to default biases for in-flight
procedure Pacs_Spec_Chopper_imt504_ast {
}{
    // Start chopper diagnostic housekeeping
    SPEC_Chopper_dhk_imt_bb();
    // Move chopper to default position
    PACS_Chopper_mov_abs_fm_bb(0);
    // Setup CRE and set to rpr32
    int ramp_len_red = 32;
    int ramp_len_blu = 32;
    double bias_d_red = 0.03;
    double bias_r_red = 0.01;
    double bias_d_blu = 0.08;
    double bias_r_blu = 0.01;
    int capa_red = 0;
    int capa_blu = 0;
    SPEC_CRE_No_Heater_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // setup the parameters for rectangular chopping with OBCP27
    int nb_up_down_27 = 1;
    int nb_grat_steps_27 = 1;
    int nb_cycles_grat_def_27 = 10;
    int chop_pos_REF1_27 = -12386;
    int nb_ramps_plateau_27 = 4;
    int chop_pos_REF2_27 = 12047;
    int nb_CS1_CS2_27 = 10;
    int chop_pos_CS1_27 = -21350;
    int chop_pos_CS2_27 = 21200;
    int grat_step_up_27 = 0;
    int grat_step_dn_27 = 0;
    int detector_27 = 1;
    int grat_pos_27 = 496000;
    int grat_time_27 = 40000;
    int comp_mode_blu_27 = 16;
    int comp_mode_red_27 = 16;
    int grat_def_27 = 496000;
    int chop_def_27 = 0;
    int grat_def_time_27 = 40000;
    int nb_rdouts_ramp_27 = 32;
    // Execute OBCP27 with rpr 32 and 3 ramps per chopper:1 Hz
    SPEC_CRE_No_Heater_setup(32,32,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    OBCP_grat_line_scan_chop_2(nb_up_down_27,nb_grat_steps_27,nb_cycles_grat_def_27,chop_pos_REF1_27,3,chop_pos_REF2_27,nb_CS1_CS2_27,chop_pos_CS1_27,chop_pos_CS2_27,grat_step_up_27,grat_step_dn_27,detector_27,grat_pos_27,grat_time_27,comp_mode_blu_27,comp_mode_red_27,grat_def_27,chop_def_27,grat_def_time_27,32);
    // Execute OBCP27 with rpr 32 and 1 ramps per chopper:2 Hz
    OBCP_grat_line_scan_chop_2(nb_up_down_27,nb_grat_steps_27,nb_cycles_grat_def_27,chop_pos_REF1_27,1,chop_pos_REF2_27,nb_CS1_CS2_27,chop_pos_CS1_27,chop_pos_CS2_27,grat_step_up_27,grat_step_dn_27,detector_27,grat_pos_27,grat_time_27,comp_mode_blu_27,comp_mode_red_27,grat_def_27,chop_def_27,grat_def_time_27,32);
    // Execute OBCP27 with rpr 16 and 1 ramps per chopper:4 Hz 
    SPEC_CRE_No_Heater_setup(16,16,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    OBCP_grat_line_scan_chop_2(nb_up_down_27,nb_grat_steps_27,nb_cycles_grat_def_27,chop_pos_REF1_27,1,chop_pos_REF2_27,nb_CS1_CS2_27,chop_pos_CS1_27,chop_pos_CS2_27,grat_step_up_27,grat_step_dn_27,detector_27,grat_pos_27,grat_time_27,comp_mode_blu_27,comp_mode_red_27,grat_def_27,chop_def_27,grat_def_time_27,16);
    // Move chopper to default position
    PACS_Chopper_mov_abs_fm_bb(0);
    // CRE setup to default values
    SPEC_CRE_No_Heater_setup(64,64,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,12,12);
    // Stop diagnostic housekeeping
    PACS_stop_dhk_fm_bb();
}

// $Id: SPEC_spu_setup.txt,v 1.6 2007/08/09 15:40:11 dcesarsk Exp $
//
// Missionphase  : PACS ILT
//
// Purpose       : Condition SPU for SPECtroscopy observations
//                  
// TCL author    : Thomas Mueller
// TCL file      : tm_spec_spu_setup.tcl, version 1.3
//                    SetupSpectroscopyWEplusFPUsim.tcl v2.8
// CUS author    : Diego Cesarsky
// Script file   : SPEC_spu_setup.txt 
//
// Input arguments
// Type Name           Default   Description
// int  comp_mode_blu  16        Compression mode Default=16; double=17;
//                               lossless=20; transp=23; 4sec reset=24; 
//                               buffer_mode=25, noise=33
// int  comp_mode_red  16        As above for RED
// int  nb_samp_subramp_blu 64   Number of samples per sub-ramp 
//                               (>=4 and <= readouts per ramp)
// int  nb_samp_subramp_red 64   As above for RED
// int  spu_nraw_blu     3       Number of raw channels transmitted by SPU
// int  spu_nraw_red     3       As above for RED
// int  glitch_det       1       Glitch detection; 0=on; 1=off
// int  ramp_fit_alg     1       Ramp fit algorithm: 0=LstSq fit,1=mean value
// bool startSPU      true       Start SPU after setting values
//
// Description   : Sets values for compression mode,
//                 threshold values (glitch, chopper, grating), raw 
//                 channel transmission, sub-ramp and detector
//                 constants, load DPU time and restart SPU. Script
//                 sets its own delays [sec] and returns the total
//                 duration in milliseconds. This version addresses
//                 BLU and RED; could make a BLU only and RED only version
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      : Based on V1.3 of TM's tm_spu_setup.tcl. Both
//                 SPUS and SPUL are initialized to same set of parameters
//
// Version         1.0
// History       : 1.0 25-04-2008 Creation based on v1.0 of SPEC_spu_setup
//                 1.1 24-mar-2009 DAC Update after SPU UM 13.95a
//             
procedure SPEC_spu_setup_wait_reset {
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 16; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 16; // Nb of red samples per sub-ramp
    int nb_raw_spu_blu = 3; // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3; // Nb of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1; // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true; // Start SPU or not [true,false]
    int wait_time = 2400; // Wait time at the end of the SPU setup
    bool stopSPU = true; // Stop SPU after the wait_time
}{
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    // Set the SPU compression modes
    // (TC arguments are defined as type {int}[], cf. definition of
    //  Pacs_DMC_WRT_SPU_TRAN_MODE; hence define comp_par accordingly)
    {int}[] comp_par = [{comp_mode_blu},{comp_mode_red}];
    // The "checksum" function needs an array as argument, hence use elements
    // of comp_par cast as an array:                      
    int[] aux = [comp_mode_blu,comp_mode_red];
    int check_sum = checksum("int",aux);
    // Issue the TC
    Pacs_DMC_WRT_SPU_TRAN_MODE(comp_par,check_sum);
    // Setting of start index of raw channels for SPUS and SPUL
    string spus_obs_mode = "SPEC";
    string spul_obs_mode = "SPEC";
    int spus_startraw = 1;
    int spul_startraw = 1;
    Pacs_SPUS_RAW_CHAN_TRAN_MODE(spus_obs_mode,nb_raw_spu_blu,spus_startraw);
    Pacs_SPUL_RAW_CHAN_TRAN_MODE(spul_obs_mode,nb_raw_spu_red,spul_startraw);
    // Spectro "Ottensamer" block ("S" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    int ppf = 0;
    // PPP: Pre-Processing Parameter
    int ppp = 0;
    // Threshold for glitch detection in spectroscopy
    int tfs = 1000;
    // Threshold for chopper position deviation in spectroscopy
    int tcs = 100;
    // Threshold for grating deviation
    int tgd = 100;
    // Readouts per SubRamp readback
    int rsrr = nb_samp_subramp_blu;
    // Glitch detection for spectroscopy
    int gdfs = glitch_det;
    // Ramp fitting algorithm
    int rfal = ramp_fit_alg;
    // Sorting algorithm
    int soal = 5;
    // lossless compression algorithm (0,1,2,3,4)
    int lcal = 4;
    // PACS Codec Order (3,4)
    int pcod = 3;
    // New 13.95a values are
    int rndb = 0;
    int rnds = 0;
    int fixrc = 0;
    int dpre = 0;
    int dpost = 0;
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    {int}[] spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUS_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    // Spectro "Ottensamer" block ("L" SPU)
    ppf = 0;
    ppp = 0;
    tfs = 1000;
    tcs = 100;
    tgd = 100;
    rsrr = nb_samp_subramp_red;
    gdfs = glitch_det;
    rfal = ramp_fit_alg;
    soal = 5;
    lcal = 4;
    pcod = 3;
    // New 13.95a values are
    rndb = 0;
    rnds = 0;
    fixrc = 0;
    dpre = 0;
    dpost = 0;
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUL_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    // Send time stamps
    // DMC_WRT_TIME: Write the time sent by the DPU into the DMC buffer
    // (No action on this one?)
    // DPU sends the time to DEC/MEC
    Pacs_DPU_SEND_TIME();
    // DMC_SET_TIME: Set the time previously written by the write time command
    Pacs_DMC_SET_TIME();
    // Start reduction/compression if commanded to do so
    if(startSPU) {
        Pacs_SPUS_START_REDUCT_COMPR();
        Pacs_SPUL_START_REDUCT_COMPR();
    }
    delay(wait_time);
    if(startSPU && stopSPU) {
        Pacs_SPUS_STOP_REDUCT_COMPR();
        Pacs_SPUL_STOP_REDUCT_COMPR();
    }
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	:  Fullfunctional Test of Chopper PTD 0.7.5
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do a chopper full field of view scan from -25000 cu to
//                + 25000 cu and vice versa with steps of 500. The grating is on a position
//		  such that in the blue we are at 87 microns and in the red at
//		  174 microns.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 7.0	
// 
// History 	: 1.0 21-07-06 creation by HD. Based on EQM IMT script "SPEC_Chop_fft_eqmimt_obs.txt"
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//			       final chopper poistion (TBC).
//                3.0 26-07-06 HD. Incremental throw included.
//		  5.0 26-07-06 HD. script works.
//		  6.0 07-11-06 HD. Update.
//		  7.0 04-mar-2008 translated into PV script VDP
//
obs PacsEng_Spec_Chopper_dhk_stop {
    /* Needed variables to call PacsEng_Spec_Chopper_dhk_stop                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Chopper_dhk_stop                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_stop_dhk_bb()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_stop_dhk_bb();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : Pierre Royer
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 1.0 27-Feb-2007 Copy of CONF_grating_OBS dedicated to SFT HeII
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//
//
obs PacsEng_CONF_grating_SFTHeII {
    /* No variables to call PacsEng_CONF_grating_SFTHeII                        */
    string calUrow = "FMILT"; // INSTRUMENT VERSION
    string calUname = "CONFGrat";
    /* End of needed variables for PacsEng_CONF_grating_SFTHeII                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_grating(calUname,calUrow)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_grating(calUname,calUrow);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS file      : CONF_spec_fltw_Warm.txt
// Missionphase  : FMILT_3 & Later
//
// Purpose       : CONFigure the spectro filter wheel for Nominal Warm
//                  
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 0.1 
// History       : 1.0 4-Jul-2007 PR creation
//               :
procedure CONF_spec_fltw_Warm {
}{
    string calUname = "CONFFWSPEC";
    // FWSPEC CALIBRATION TABLE
    string calUrow = "FMILT_W";
    // INSTRUMENT VERSION
    int rate = ilookup(calUname,calUrow,"Rate");
    int current = ilookup(calUname,calUrow,"Drive_current");
    int threshold_A = ilookup(calUname,calUrow,"Threshold_A");
    int threshold_B = ilookup(calUname,calUrow,"Threshold_B");
    int status_A = ilookup(calUname,calUrow,"Status_A");
    int status_B = ilookup(calUname,calUrow,"Status_B");
    {int}[] parlist = [{rate},{current},{threshold_A},{threshold_B},{status_A},{status_B}];
    int[] aux = [rate,current,threshold_A,threshold_B,status_A,status_B];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_FWSPEC_CONF_PAR(parlist,check_sum);
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_CRE_Setup_Warm {
    /* No variables to call PacsEng_Spec_CRE_Setup_Warm                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_CRE_Setup_Warm                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_CRE_Setup_Warm()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_CRE_Setup_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS file      : CONF_spec_fltw.txt
// Missionphase  : FMILT_3 & Later
//
// Purpose       : CONFigure the spectro filter wheel servo loop
//                  
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 0.1 13-Oct-2004 Creation by DAC
// History       : 0.2  4-jul-2006 Removed "return" statement
//                    1.0 11-Jun-2007 PR New scheme due to new format of configuration command
//                                               (DMC UM v.4.3)
//               :
procedure CONF_spec_fltw {
}{
    string calUname = "CONFFWSPEC";
    // FWSPEC CALIBRATION TABLE
    string calUrow = "FMILT";
    // INSTRUMENT VERSION
    int rate = ilookup(calUname,calUrow,"Rate");
    int current = ilookup(calUname,calUrow,"Drive_current");
    int threshold_A = ilookup(calUname,calUrow,"Threshold_A");
    int threshold_B = ilookup(calUname,calUrow,"Threshold_B");
    int status_A = ilookup(calUname,calUrow,"Status_A");
    int status_B = ilookup(calUname,calUrow,"Status_B");
    {int}[] parlist = [{rate},{current},{threshold_A},{threshold_B},{status_A},{status_B}];
    int[] aux = [rate,current,threshold_A,threshold_B,status_A,status_B];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_FWSPEC_CONF_PAR(parlist,check_sum);
}

// CVS file      : SPEC_heater_setup.cus 
// Missionphase  : FM ILT
//
// Purpose       : Set values for the BLUE detector heaters
//
// Author        : DAC
//
// Arguments     : 
//                 
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 0.1 
// History       : 0.1 17-nov-2006 Copied from SPEC_heater; updated for
//                                 inclusion into OpDataBase
//               :
procedure SPEC_heater_setup {
    double heater_blu = 0.0; //Blue HEATER value (0:0mA, 4095:20mA)
}{
    // Send the telecommand to DEC/MEC
    Pacs_DMC_SET_B_SPEC_HEAT_C(heater_blu);
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule PACS_Burstmode_Reset as an OBS
//
// CUS author    : DAC
// Description   : Set/resets OBSID, calls associated procedure
// Dependencies  : see associated procedure
// Preconditions : see associated procedure
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Burstmode_Reset {
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Burstmode_Reset()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(300.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Burstmode_Reset();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Script        : PACS_Chopper_uk_move_18000_NoConf_ast.cus
// Missionphase  : SVT / Flight
//
// Purpose	: Move chopper to absolute position  
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-18000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched on and Chopper switched on.
//                 
// Comments	: This script is based on PACS_Chopper_uk_move_18000_ast_OBS,
//                     but without configuration and with mois comments
//
// Version	: 1.0	
// 
// History 	: 1.0 17-10-2007 BV First version
//		  
procedure PACS_Chopper_uk_move_18000_NoConf_ast {
}{
    mois_comment("Perform rectangular chopping with step 18000");
    //
    int chop_pos = 18000;
    // chopper position
    int cycle = 10;
    // give cycle #
    int plateau_time = 2;
    // select plateau time in sec
    // Start Diag. HK
    mois_step("Start Diagnostic housekeeping");
    SPEC_Chopper_dhk_5hk_1khz_bb();
    mois_step("Enable chopper controller");
    // Enable Chopper Controller 
    EnDis_chopper("ON");
    delay(5);
    mois_step("Perform rectangular chopping");
    // move chopper to zero
    PACS_Chopper_mov_abs_fm_bb(0);
    delay(1);
    // do observations
    int i = 1;
    while(i <= cycle) {
        PACS_Chopper_mov_abs_fm_bb(chop_pos);
        delay(plateau_time);
        PACS_Chopper_mov_abs_fm_bb(-chop_pos);
        delay(plateau_time);
        i = i + 1;
    }
    // move chopper to zero
    PACS_Chopper_mov_abs_fm_bb(0);
    delay(1);
    mois_step("Disable chopper");
    // Disable Chopper Controller 
    EnDis_chopper("OFF");
    delay(5);
    mois_step("Disable diagnostic housekeeping");
    // Stop diagnostic housekeeping
    PACS_stop_dhk_fm_bb();
}

// CVS file      : DMC_chop_scan_phot.txt
// Missionphase  :
//
// Purpose       : Chop increasingly away from start position; then increasingly
//                 closer to start position. Whole operation may be repeated
//                 nb_up_down times
//
// Author        : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
//
// Arguments     : (only timing parameters are used in actual call)
//  int nb_up_down  P#1  number of up-down seqs.
//  int nb_rdouts   P#2  number of readouts on step
//  int nb_steps_up P#3  number of steps up
//  int nb_steps_dn P#4  number of steps down
//  int step_up     P#5  relative move up 
//  int step_dn     P#6  relative move down 
//
// Description : Chop increasing distance from start, then revert
//               and chop closer and closer to initial position
//
// Dependencies  : Stand alone DEC/MEC sequence
//
// Comments      : Follows line by line 4.1.9 in PACS-ME-LI-005
//                 Tally all readouts as REF
//
// Version       : 0.1  6-apr-2006 Creation by DAC
// History       : 
int[] procedure DMC_chop_scan_phot {
    int nb_up_down = 1; // P#1  number of up-down seqs.
    int nb_rdouts = 16; // P#2  number of readouts on step
    int nb_steps_up = 1; // P#3  number of steps up
    int nb_steps_dn = 1; // P#4  number of steps down
}{
    // Time keeping variables [readouts]
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Parameterized up and down scan with the PACS chopper.
    // WAIT 1 ; have a defined start
    duree_rdouts = duree_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; ensure LABEL 0
    // WAIT 1
    duree_rdouts = duree_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LOOP P#1 ; number of up-down seqs.
    for(int loop1 = 1 .. nb_up_down) {
        //    LABEL 193 ; special LABEL up
        //    LOOP P#3 ; number of steps up
        for(int loop3 = 1 .. nb_steps_up) {
            //       WAIT P#2 ; number of readouts on step
            duree_rdouts = duree_rdouts + nb_rdouts;
            duree_REF = duree_REF + nb_rdouts;
            //       MOVE_CHOPPER_RELATIVE P#5 ; relative move up
        }
        //    END_LOOP
        //    LOOP P#4 ; number of steps down
        for(int loop4 = 1 .. nb_steps_dn) {
            //       WAIT P#2 ; number of readouts on step
            duree_rdouts = duree_rdouts + nb_rdouts;
            duree_REF = duree_REF + nb_rdouts;
            //       MOVE_CHOPPER_RELATIVE P#6 ; relative move down
            //       LABEL 225 ; special LABEL down
        }
        //    END_LOOP
    }
    // END_LOOP
    // WAIT P#2 ; integrate on last step
    duree_rdouts = duree_rdouts + nb_rdouts;
    duree_REF = duree_REF + nb_rdouts;
    // WAIT 1
    duree_rdouts = duree_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0
    // END_SEQUENCE
    // Return durations

    return [duree_rdouts,duree_SRC,duree_REF,duree_CAL,duree_OVR];
}

// Missionphase  : PACS FM Test
//
// Purpose       : Switch on of bolometer groups
//
// Author        : T. Mueller
//
// File          : PACS_Phot_Switchon
// Arguments     : none
//                 
//
// Description   : This script will switch on the different groups
//                 of the instrument. BOLC will start in "HK only" mode.
//                              
// Comments      :  Coded based on PhFPU UM, Draft 5
//
// Version       : 1.0
// History       : 1.0 / 08-Nov-2006 initial version by TM
// 
procedure PACS_Phot_Switchon {
}{
    // PC103420 "DMC_SEND_COMMAND_BOLC" SEND COMMAND TO BOL CONTROLLER
    //         PP071420 "BOLOMETER_COMMAND"
    //
    // # Execute BOLC initialisation
    // # for CQM we switched on everything at once, now group by
    // # group starting with 1
    // 
    // # Switch-on group 1 The corresponding bits
    // # are (2^0)=1, which is 1 in hex.
    // tcsend PC103420 {PP071420 0x0A000001 LO}
    // waittime 1.0
    int operand = 0xa000001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2. The corresponding bits
    // # are (2^0+2^1)=3, which is 3 in hex.
    // tcsend PC103420 {PP071420 0x0A000003 LO}
    // waittime 1.0
    operand = 0xa000003;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3. The corresponding bits
    // # are (2^0+2^2+2^3)=7, which is 7 in hex.
    // tcsend PC103420 {PP071420 0x0A000007 LO}
    // waittime 1.0
    operand = 0xa000007;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4. The corresponding bits
    // # are (2^0+2^1+2^2+2^3)=15, which is F in hex.
    // tcsend PC103420 {PP071420 0x0A00000F LO}
    // waittime 1.0
    operand = 0xa00000f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4,5. The corresponding bits
    // # are (2^0+2^1+2^2+2^3+2^4)=31, which is 1F in hex.
    // tcsend PC103420 {PP071420 0x0A00001F LO}
    // waittime 1.0
    operand = 0xa00001f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4,5,6. The corresponding bits
    // # are (2^0+2^1+2^2+2^3+2^4+2^5)=63, which is 3F in hex.
    // tcsend PC103420 {PP071420 0x0A00003F LO}
    // waittime 1.0
    operand = 0xa00003f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Purpose       : Template for a PHOT AOT with chopped nodding in raster
//                 OBCP used: OBCP_chopped_photometry (OBCP#3)
//                 Calls nodding_raster_pointing (3.6 in Point document)
// Author        : DAC
//
// Arguments     : See input list below
//
// Prerequisite  : PACS is PHOT ready (PHOT_orbit_prologue), SPU is stopped 
//                 and ready to be (re)configured.
//
// Description   : Uses OBCP3
// Comments      :
//
// Version       : 0.1
// History       : 0.1 18-feb-2008 DAC
//                 0.2 19-feb-2008 - Use PacsPhotSlewCal
//                                 - Read more input parameters
//		   1.0 21-oct-2008 - VDP - PSF for DL
//		   1.1 23-apr-2009 VD SPR 6482
//
//                 
obs PacsCal_Phot_PSF {
    /* Needed variables to call PHOT_NodRaster                               */
    /* string fltPOS = "POS A" in ["POS A","POS B"]; // Fltw position */
    string psfMeth = "flexible" in ["flexible","tripleChop"];
    string filter = "blue1" in ["blue1","blue2"];
    string gain = "LOW" in ["LOW","HIGH"]; // BOLC gain
    int nrepeat = 1;
    /*                                 */
    /* OBCP related parameters         */
    /*                                 */
    /* PHOT compression modes          */
    /* 0x00 BOL0: Default              */
    /* 0x01 BOL1: Double Compression   */
    /* 0x02 BOL2: Half Compression     */
    /* 0x04 BOL4: Lossless Compression */
    /* 0x07 BOL7: Transparent          */
    /* 0x09 BOL9: Buffer Transmission  */
    int comp_mode_blu = 0x0; // Compression mode
    int comp_mode_red = 0x0; // Compression mode
    int nraw_blu = 3; // Number of raw pixels
    int nraw_red = 3; // Number of raw pixels
    int nb_SRC_REF = 2; // Nb of SRC-REF1-SRC-REF2 cycles
    int nb_rd_plateau = 31; // Nb rdouts/plateau (4*nn - 1)
    int nb_cycles_obs_cal = 1; // Outermost DMC loop
    int nb_CS1_CS2 = 0; // Loop on CSs
    /* Pointing parameters             */
    /* The ofssets are passed directly to the PointReq. Unless changed the */
    /* telecope boresight will fall in between SRC and REF                 */
    double ra = 0.0; // RA (returned by xHPOT pop-up window)
    double dec = 0.0; // DEC (ditto)
    double srcAngle = 0.0; // For tripleChop, double source position angle on sky [degrees]
    double yoffset = 0.0; // yoffset [arcsec] used as is in PntReq 
    double zoffset = 0.0; // zoffset [arcsec] used as is in PntReq
    bool centroid = true; // centroid Method  
    double srcSep = 0.0; // For tripleChop, sources separation [arsec]
    int naifid = 0; // (Source type: > 0 for Solar System source (N/A for tripleChop method) 
    /* Raster parameters               */
    int m = 2 in [2,100]; // Number of raster points       
    int n = 1 in [1,100]; // Number of raster lines
    double d1 = 2.0 in [2.0,480.0]; // Raster point step [arcsec]       
    double d2 = 2.0 in [2.0,480.0]; // Raster line separation [arcsec]
    bool fixed = false; // Raster in S/C (false) or SKY coordinates (true for tripleChop)
    double nodthrow = 30.0 in [2.0,960.0]; // Nod throw [arcsec]  
    double chopthrow = 30.0; // Chop throw [arcsec]
    double patt = 0.0; // Raster pattern orientation
    double pattnod = 270.0; // Nodding orientation (def: along y-axis)
    int nnod = 1; // Number of Aa aA ... nods
    bool startAtB = false; // start at off-nod B position
    /* NOTE: raster size shall not be larger than 14880x14880 arcsec */
    /* Overall "verbosity"             */
    bool verbose = true;
}{
    // Compute duration of tasks to be performed during slew to source
    // Set OBSID
    int timeOBSID = duration(WriteOBSID($OBSID));
    // Condition BOLC to gain setting. This may change the data rate but SPU
    // is still stopped and a proper comp_mode may be defined
    // Can I set the gain directly (Thomas says "yes")
    int timeGAIN = duration(PHOT_set_gain(gain));
    // Use PacsPhotSlewCal from AOT code. Define three input tuples
    // SPU-like parameters
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP-like values (none is used since SlewCal takes them from OBCP$params)
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // including a new section for Low Gain implementation SCR4196
    bool isBrightPacs = false;
    string srcID = "pointSRC";
    // Obtain default values for "Prime" mode
    paramsPHOT = PacsPhotDefaults(srcID,"Prime",isBrightPacs,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    confPHOTblu[0]{3} = comp_mode_blu;
    confPHOTblu[0]{6} = nraw_blu;
    confPHOTred[0] = paramsPHOT{1};
    confPHOTred[0]{3} = comp_mode_red;
    confPHOTred[0]{6} = nraw_red;
    confOBCP[0] = paramsPHOT{2};
    // Perform the calibration block now
    bool doProlog = true;
    int timeCAL = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,filter));
    //
    // Before dealing with the OBCP, obtain the chopper position for CS1 & CS2
    // (likely not to be used here, but just for completeness)
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","PHOT","pos_CS1");
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","PHOT","pos_CS2");
    if(psfMeth == "flexible") {
        // The chopper moves from -chopthrow/2 to +chopthrow/2 [arcsec]
        double auxSRC = -chopthrow / 2.0;
        double auxREF = +chopthrow / 2.0;
        int chop_pos_SRC = PacsReadChopSky("PHOT_CHOP_sky",auxSRC);
        int chop_pos_REF = PacsReadChopSky("PHOT_CHOP_sky",auxREF);
    } else {
        chopthrow = srcSep;
        auxSRC = -chopthrow / 2.0;
        auxREF = +chopthrow / 2.0;
        chop_pos_SRC = PacsReadChopSky("PHOT_CHOP_sky",auxSRC);
        chop_pos_REF = PacsReadChopSky("PHOT_CHOP_sky",auxREF);
    }
    // Report settings if verbose
    if(verbose) {
        debug_print("+++CHOPPER, SRC: " + auxSRC + " [arcsec] -> " + chop_pos_SRC + " [ENG]");
        debug_print("+++CHOPPER, REF: " + auxREF + " [arcsec] -> " + chop_pos_REF + " [ENG]");
    }
    // Default position for chopper
    int chop_def = ilookup("SPEC_MEC_Defaults","Photometry","chopper");
    // Duration of OBCP to be performed ON and NOD
    int tp = duration(OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def));
    if(verbose) {
        debug_print("Duration of OBCP " + tp + " [sec]");
    }
    // tp cannot be shorted than 10 sec
    if(tp < 10) {
        error("The OBCP cannot be shorter than 10 sec; adjust your OBCP parameters");
    }
    //
    // Several arguments needed for "nodding_raster_pointing"
    //
    //Execute the pointing request
    bool execute = true;
    //Minimum slew time
    int tslewmin = timeOBSID + timeGAIN + timeCAL;
    if(verbose) {
        debug_print("+++SlewMinTime is " + tslewmin + " [sec]");
    }
    //Initial hold
    int tih = 0;
    //Final hold
    // Need 1 sec to WriteEndID() and close OBS
    int tfh = 1;
    //Use PHOT virtual aperture
    string ib = "P01_0";
    //Issue PointReq
    // Still undefined pointing variables
    // Number of points/scan lines before going to OFF
    int k = 0;
    // Number of nods/raster/scan before performing a hold
    int nhold = 0;
    // Duration of a hold operation
    int thold = 0;
    // Time spent at OFF
    int top = 0;
    // Coordinates of OFF position
    double raoff = 0.0;
    double decoff = 0.0;
    // Repetitions of pattern
    // The minimum duration of return slew between repetitions
    int trepeatmin = 0;
    // Minimum duration of a "load" operation
    int tloadmin = 0;
    // Number of slews before starting a "load" slew
    int nload = 0;
    // Issue de PointReq  
    if(psfMeth == "tripleChop") {
        patt = 0.0;
        pattnod = 270.0 + srcAngle;
        if(centroid) {
            zoffset = 0.5 * srcSep * cos(srcAngle);
            yoffset = 0.5 * srcSep * sin(srcAngle);
        }
        int tpa = tp;
        int tpb = tpa;
        int[] ts = nodding_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nnod,chopthrow,tpa,tpb,tloadmin,nload,thold,nhold,startAtB);
    } else {
        ts = nodding_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodthrow,nnod,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
    }
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            int tNOW = time();
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            //      Set OBSID, move filter, set gain, perform prologue
            WriteOBSID($OBSID);
            data_rate(120.0);
            PHOT_set_gain(gain);
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,filter);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //      Call the OBCP with the known parameters
            OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            //      Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 7) {
            tNOW = time();
            if(verbose) {
                debug_print("NOD   starts at   " + tNOW);
            }
            //      Call the OBCP with the same parameters as for POINT
            OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
            tNOW = time();
            if(verbose) {
                debug_print("NOD   ends at     " + tNOW);
            }
        }
    }
}

// File          : PACS_Spec_Flash_SWON.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : SWON Flashers
//
// Author        : P. Royer
//
// Arguments     : blue & red Heater currents
//
// Description   : SWON Flashers
//               :
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 07-Jun-2006 initial version by PR
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose SWON Flashers
// @comment - 
//
block PACS_Spec_Flash_SWON PACS 165 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //
    // SWON FLASHERS
    //
    Pacs_DMC_SWON_BD_FLASHER();
    Pacs_DMC_SWON_RD_FLASHER();
    //
    // End of procedure
    //------------------
}

// CVS comments  : $Id: PacsRangeSpecCheckFillRange.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $
// Missionphase  : Operations
//
// Purpose       : Check that HSPOT given ranges agree with U-CAL values,
//                 return corresponding grating positions or null values if
//                 range exceeds U-CAL specifications. Special logic for "SED"
//                 observations
//
// CUS author    : DAC
// Script file   : PacsRangeSpecRangeCheck.txt 
//
// Input arguments
// type                                         name      description
// {string,double,double,double,double,double,  ranges    Variable from HSPOT
// Returns "rangeInfo":  {string,int,int,int,double,double}   
// {ObsType,ORDER,grat_pos_blue,grat_pos_red,grat_step,wave_blu,wave_red}
//                     returns [0,0,0] when rangeWave is invalid
// Description   : Compares HSPOT ranges with limits defined in SPEC_BAND_params
//                 CAL file. Returns grating start/stop positions for all
//                 complying ranges; grating positions are obtained from 
//                 dedicated CAL files (file names found in SPEC_BAND_params)
// Dependencies  : low level CUS functions
//
// Preconditions :
//
// Comments      : 
// 
// History       : 0.1 21-Jun-2005 DAC
// 1.0 15-sep-2005 Adapted for "OBS" CUS script, call argument is "ranges"
// 1.1 16-sep-2005 Add gratStep element to rangeInfo; renamed to 
//                 PacsRangeSpecCheckFillRange since now it adds gratStep
// 1.2 11-may-2006 Element {3} of ranges is now an integer
// 1.3 22-jun-2006 ranges now contains lineWidth. grating and density variables
//                 have changed possible values. Call them xxxNEW and use
//                 "conversion" tables not to change the logic of module
// 1.4 22-nov-2006 Move verbose into call list
// 1.5 25-jan-2007 Read CAL-U using new xcolumn function
// 2.0 12-apr-2007 Several changes for SCR-3050. For RANGE find order given
//                 BLU and RED wavelengths; for SED read directly the relevant
//                 CAL-U row based on HSPOT input
// 2.1 18-apr-2007 Now keeping user defined rangeID; change some logic to
//                 recognize RANGE and SED
// 3.0 27-apr-2007 Define rangeWave as rangeSPOT
// 4.0 11-jun-2007 SPR-3281 Change logic: now checks ORDER rather than finding
//                 ORDER. Added orderSel to input list
// 5.0 01-dec-2009 VD SCR PHS-1272
//
{string,int,int,int,int,double,double}[] procedure PacsRangeSpecCheckFillRange {
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [{"SED",55.0,70.0,0,0.0,0.0,0.0,"","",0.0}];
    string densityNEW = "high" in ["nyquist","high"];
    string gratingNEW = "nyquist" in ["nyquist","nyquist"];
    string orderSel = "order3";
    bool verbose = false;
}{
    // Old values of density and grating
    // string density = "high" in ["high","medium","low"];
    // string grating = "medium" in ["fast","low","medium"];
    // "Conversion" tables for new nomenclature
    string density = "high";
    if(densityNEW == "nyquist") {
        density = "low";
    }
    string grating = "medium";
    // Variable to map SPEC_BAND_params file in memory
    string calU = "SPEC_BAND_params";
    {string,double,double,int,int,int,string}[] file_map = [{"",0.0,0.0,0,0,0,""}];
    // Map the whole SPEC_BANDS_params table in memory and create file_map tuple
    string[] keyCol = scolumn(calU,"ORDER");
    double[] lo = dcolumn(calU,"BLU");
    double[] hi = dcolumn(calU,"RED");
    int[] lowStep = icolumn(calU,"LOW");
    int[] medStep = icolumn(calU,"MED");
    int[] hiStep = icolumn(calU,"HI");
    string[] name = scolumn(calU,"CAL_FILE");
    // Currently SPEC_BAND_params has nrows
    int nrows = table_size(calU);
    // Map it to "file_map"
    for(int order = 0 .. nrows - 1) {
        file_map[order] = {keyCol[order],lo[order],hi[order],lowStep[order],medStep[order],hiStep[order],name[order]};
    }
    // Number of input range tuples
    int nbrangeSPOT = length(rangeSPOT);
    // Review each input range for conformity with SPEC_BAND_params; if OK get 
    // the grating positions for the red and blue edges
    // Procedure returns tuple rangeInfo: 
    // {typeOBS,ORDER,bluGRAT,redGRAT,stepGRAT,bluWAVE,redWAVE}
    {string,int,int,int,int,double,double}[] rangeInfo = [{"SED",0,0,0,0,0.0,0.0}];
    // Start loop per HSPOT range (in SED mode the range tuple is furnished by
    // PacsRangeSpecSed)
    for(int loop0 = 0 .. nbrangeSPOT - 1) {
        string typeOBS = rangeSPOT[loop0]{0};
        double bluHSPOT = rangeSPOT[loop0]{1};
        double redHSPOT = rangeSPOT[loop0]{2};
        // An all [0,0,0] rangeInfo means contents of rangeSPOT not found
        rangeInfo[loop0] = {"NONE",0,0,0,0,bluHSPOT,redHSPOT};
        bool found = false;
        // If SED observations, search SPEC_BANDS_params past the
        // three canonical rows (i.e. ORDER=1, 2, and 3)
        // In RANGE mode there is no ORDER=1 specification (ORDER can be 2 or 3)
        // Always check for ORDER=1 and then for given order
        // Hence, check order from first column and then from ORDERth column
        // First index into SPEC_BAND_params
        int index0 = 0;
        //  Establish next index
        if(orderSel == "order2") {
            int index1 = 1;
        }
        if(orderSel == "order3") {
            index1 = 2;
        }
        bool isRange = orderSel == "order2" || orderSel == "order3";
        if(isRange) {
            int count = 1;
            int index = index0;
            while(!found && count < 3) {
                if(verbose) {
                    debug_print("CheckRange: using index: " + index);
                }
                found = bluHSPOT >= file_map[index]{1} && redHSPOT <= file_map[index]{2};
                //        Found the relevant row in SPEC_BAND_params!
                if(found) {
                    // Read associated CAL file; obtain grating positions
                    string file_name = file_map[index]{6};
                    // "Canonical" ORDER 1, 2, or 3, i.e. "RANGE" observations
                    if(verbose) {
                        debug_print("CheckRange found RANGE OBS at index: " + index);
                    }
                    double grat_lo = interpolate(file_name,"grat_pos",bluHSPOT);
                    double grat_hi = interpolate(file_name,"grat_pos",redHSPOT);
                    rangeInfo[loop0]{0} = typeOBS;
                    order = index + 1;
                    rangeInfo[loop0]{1} = order;
                    rangeInfo[loop0]{2} = iround(grat_lo);
                    rangeInfo[loop0]{3} = iround(grat_hi);
                    rangeInfo[loop0]{5} = bluHSPOT;
                    rangeInfo[loop0]{6} = redHSPOT;
                    // Get the gratStep (defined by "density")
                    if(density == "high") {
                        rangeInfo[loop0]{4} = file_map[index]{5};
                    }
                    if(density == "medium") {
                        rangeInfo[loop0]{4} = file_map[index]{4};
                    }
                    if(density == "low") {
                        rangeInfo[loop0]{4} = file_map[index]{3};
                    }
                    //           Found
                }
                //           Not yet found
                index = index1;
                count = count + 1;
            }
            // Enter error if RANGE not found
            if(!found) {
                error("Range " + bluHSPOT + "-" + redHSPOT + " is off allowed bounds");
            }
            // SED observations
        } else {
            if(orderSel == "sed2" || orderSel == "sed3" || orderSel == "sed4") {
                // Read relevant line according to "sedX"
                //     Entry key to SPEC_BANDS_params          
                int keyINT = 4;
                ///Now as input argument:  orderSel = typeOBS;
                if(orderSel == "sed3") {
                    keyINT = 5;
                }
                if(orderSel == "sed4") {
                    keyINT = 6;
                }
                string key = "" + keyINT;
                // Associated CAL file to obtain grating positions
                //     Update index0
                index0 = keyINT - 1;
                file_name = file_map[index0]{6};
                // Entry key to SPEC_SED
                keyINT = keyINT - 3;
                key = "" + keyINT;
                grat_lo = dlookup(file_name,key,"BLU");
                grat_hi = dlookup(file_name,key,"RED");
                order = ilookup(file_name,key,"ORDER");
                rangeInfo[loop0]{0} = typeOBS;
                rangeInfo[loop0]{1} = order;
                rangeInfo[loop0]{2} = iround(grat_lo);
                rangeInfo[loop0]{3} = iround(grat_hi);
                rangeInfo[loop0]{5} = bluHSPOT;
                rangeInfo[loop0]{6} = redHSPOT;
                //     Get the gratStep (defined by "grating")
                if(grating == "low") {
                    rangeInfo[loop0]{4} = file_map[index0]{5};
                }
                if(grating == "medium") {
                    rangeInfo[loop0]{4} = file_map[index0]{4};
                }
                if(grating == "fast") {
                    rangeInfo[loop0]{4} = file_map[index0]{3};
                }
            } else {
                if(orderSel == "sedb2b") {
                    index0 = 7;
                }
                if(orderSel == "sedb2a") {
                    index0 = 8;
                }
                if(orderSel == "sedb3a") {
                    index0 = 9;
                }
                key = "" + orderSel;
                debug_print("real: key: " + key);
                file_name = file_map[7]{6};
                grat_lo = dlookup(file_name,key,"BLU");
                grat_hi = dlookup(file_name,key,"RED");
                order = ilookup(file_name,key,"ORDER");
                rangeInfo[loop0]{0} = typeOBS;
                rangeInfo[loop0]{1} = order;
                rangeInfo[loop0]{2} = iround(grat_lo);
                rangeInfo[loop0]{3} = iround(grat_hi);
                rangeInfo[loop0]{5} = bluHSPOT;
                rangeInfo[loop0]{6} = redHSPOT;
                //     Get the gratStep (defined by "grating")
                if(grating == "low") {
                    rangeInfo[loop0]{4} = file_map[index0]{5};
                }
                if(grating == "medium") {
                    rangeInfo[loop0]{4} = file_map[index0]{4};
                }
                if(grating == "fast") {
                    rangeInfo[loop0]{4} = file_map[index0]{3};
                }
            }
            // SED mode ends here
        }
        if(verbose) {
            debug_print("###CheckFill used table " + file_name);
            debug_print("###CheckFill grat lo/hi/order: " + grat_lo + "/" + grat_hi + "/" + order);
        }
        // End loop on nbRanges
    }
    if(verbose) {
        debug_print("## PacsRangeSpecCheckFillRange reads SPEC_BAND; returns: " + rangeInfo);
    }

    return rangeInfo;
}

// File          : PACS_Spec_Flash_SWOF.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : SWOF Flashers
//
// Author        : P. Royer
//
// Arguments     : blue & red Heater currents
//
// Description   : SWOF Flashers
//               :
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 07-Jun-2006 initial version by PR
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose SWOF Flashers
// @comment - 
//
block PACS_Spec_Flash_SWOF PACS 167 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //
    // SWOF FLASHERS
    //
    Pacs_DMC_SWOF_BD_FLASHER();
    Pacs_DMC_SWOF_RD_FLASHER();
    //
    // End of procedure
    //------------------
}

// $Id: OBCP_grat_scan_chop2.txt,v 1.6 2007/08/22 10:18:28 dcesarsk Exp $ 
// Purpose       : 
//
// OBCP author   : HF
// TCL file      : N/A
// CUS author    : DAC
// Script file   : OBCP_27_grat_line_scan_chopped_2.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Belongs to Section 3.8: Grating Spectral Line Scan 
//                 of PACS-ME-LI-005
//                 Consists mainly of a sequence with repetitive up- and
//                 down-scans with the grating around a given center position,
//                 while the chopper is operating as well on either two- or
//                 three-positions. This is OBCP 3.8.2, calling DMC sequence
//                 12 (in 4.2.2)
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-apr-2005 DAC
//                 0.2 22-apr-2005 Rearranged arguments P#1 P#2 etc.
//                 0.3 25-apr-2005 DAC Use same defaults as TM's scripts
//                 0.4 27-apr-2005 DAC MIB name is GRAT_SCAN_CHOP2 (not _2)
//                 1.0 26-aug-2005 Renamed to MIB name (but lower case);
//                                 corresponding DMC is also renamed
//                 1.1 21-aug-2007 SRC-3507 Indicate end of BB
//
int[] block OBCP_grat_scan_chop2 PACS 27 {
    int nb_up_down = 1; // Nb of "up-down" sequences (P#1); 
    int nb_grat_steps = 100; // Nb of grating steps (P#2)
    int nb_SRC_REF = 1; // Nb of cycles per grating position (P#3); 
    int chop_pos_REF1 = 1000; // Chopper position 1 (P#4) 
    int nb_ramps_plateau = 1; // Nb of readouts per chopper position (P#5); 
    int chop_pos_REF2 = 3000; // Chopper position 2 (P#6)
    int nb_CS1_CS2 = 0; // Nb of cycles on the internal CSs (P#7); 
    int chop_pos_CS1 = -25000; // Chopper position on CS1 (P#8)
    int chop_pos_CS2 = 25000; // Chopper position on CS2 (P#9)
    int grat_step_up = 1600; // Grating step up (P#10) 
    int grat_step_dn = 1600; // Grating step down (P#11) 
    int detector = 2; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 445000; // Starting grating position
    int grat_time = 0; // Grating time to move to start [msec]
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopper default position
    int grat_def_time = 0; // Time to come back to default position
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    //debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    //debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duree_msec [msec] as it goes)
    // Begin 
    // OBCP_GRATING_LINE_SCAN_CHOPPED_2(seq, seq_time,
    //   P#1,&,P#11, detector, grat_def, grat_time,
    //   cmp_par_blue, cmp_par_red, grat_def, chop_def, grat_time)
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_pos) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) ; (all parameters filled 
    // by DPU based on seq parameter) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_time) 
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    // DMC_START_SEQUENCE
    //////////////////////////////////////////////////////////////////////////
    // Call DEC/MEC code to estimate its duration
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    int[] duree1 = DMC_grat_scan_chop2(nb_up_down,nb_grat_steps,nb_ramps_plateau,nb_CS1_CS2,nb_SRC_REF);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    //  debug_print("Execution time [msec] from DMC: " + seq_time);
    // duree_msec(seq_time) 
    duree_msec = duree_msec + t_cmd + seq_time;
    // WAIT(seq_time) ; Check execution status of the sequence and in case of 
    // failure stop OBCP and issue TM(1,8)+event 
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_def_time) 
    duree_msec = duree_msec + grat_def_time;
    duree_OVR = duree_OVR + grat_def_time;
    // Issue TM(1,7)
    // End 
    // Now trigger execution of OBCP
    // This OBCP is number 27, requires 21 parameters and calls DEC/MEC #12
    string obcp_ID = "GRAT_SCAN_CHOP2";
    int obcp_par_nb = 21;
    int seq_DMC = 12;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_grat_steps},{5,nb_SRC_REF},{6,chop_pos_REF1},{7,nb_ramps_plateau},{8,chop_pos_REF2},{9,nb_CS1_CS2},{10,chop_pos_CS1},{11,chop_pos_CS2},{12,grat_step_up},{13,grat_step_dn},{14,detector},{15,grat_pos},{16,grat_time},{17,comp_mode_blu},{18,comp_mode_red},{19,grat_def},{20,chop_def},{21,grat_def_time}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // debug_print(obcp_ID + ": " + time_array);
    delay(time_array[0]);
    // Mark end of BB
    WriteEndBB();
    // Return the array of times

    return time_array;
}

// File          : PACS_Spec_Gra_Diaghk_Setup.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Switch on diagnostic hk relevant to grating
//
// Author        : B.Vandenbussche
// CUSification  : DAC
// Arguments     :
//
// Description   : Grating diagnostic housekeeping ON
//               :
// Comments      : 
//                 
//
// Version       : 1.6
// History       : 1.0 / 12-Jan-2004 initial version by BV 
//                 1.1 / 12-Jan-2004 checksum on actual parameters only - BV
//                 1.2 / 13-Jan-2004 bug fix in list syntax
//                 1.3 / 22-Jun-2004 Update for DMC UM 2.8
//                 1.4 / 13-Sep-2004 Changed hk period to 5ms
//                 1.5 / 15-Nov-2004 Inclusion of LL parameter 
//                       (unification of -previously 2- diaghk_setup scripts)
//                 1.6 / 07-Apr-2006 
//                                             Turned procedure into block (called by mode)
//                                             parametrize diag_hk_period
//                                             introduce DMC_GRAT_IND_READ (512)
//                1.7 / 21-Nov-2008
//                                            Introduce IND_SINE, IND_COS & GRAT_DEG_POS
//                                            Suppress LL2_CUR, PID_ACC, GRAT_IND_READ
//  -----------------------------------
// @author B. Vandenbussche 
// @date today
// @version 1.6
// @purpose Switch on diagnostic housekeeping relevant to grating
// @comment - 
// ------------------------------
// Uncomment to test the script for tcl syntax using a normal tcl interpreter
// source offlinetest.tcl
// Uncomment till here ----------
block PACS_Spec_Gra_Diaghk_Setup PACS 150 {
    int diag_hk_period = 5; // 5 msec diag hk period 
}{
    // Register start of BB
    WriteBBID($BBID);
    // DMC_WRT_DIAG_HK_LIST
    // DMC_DATA_LENGTH            PP065420 contains the number of desired HK parameters
    // DMC_4_BYTES_WORDS_DATA     PP067420 contains the desired HK parameters' IDs
    // DMC_CHECKSUM               PP066420
    //
    // Max number of requested diag HK parameters = 16
    // (including the last one, which is always forced to the same value)
    //
    //     DMC_FWGRAT_HALLA       256
    //     DMC_FWGRAT_HALLB       257
    //     DMC_FW_GR_VMOTA        556
    //     DMC_FW_GR_VMOTB        564
    //     DMC_FW_GR_IMOTA        560
    //     DMC_FW_GR_IMOTB        567
    //     DMC_GRAT_CTRL_ST       208
    //     DMC_GRAT_CUR_POS       250
    //     DMC_GRAT_SETPOIN       251
    //     DMC_GRAT_TARGET        252
    //     DMC_GRAT_PID_ERR       253
    //     DMC_GRAT_OUTPUT        452
    //     DMC_GRAT_IND_SINE       539
    //     DMC_GRAT_IND_COS      540
    //     DMC_GRAT_DEG_POS       515
    {int}[] list_tuple = [{256},{257},{556},{564},{560},{567},{208},{250},{251},{252},{253},{452},{539},{540},{515},{0xffff}];
    int[] list_int = [256,257,556,564,560,567,208,250,251,252,253,452,539,540,515,0xffff];
    int chksum = checksum("int",list_int);
    int nbParams = length(list_int);
    Pacs_DMC_WRT_DIAG_HK_LIST(nbParams,list_tuple,chksum);
    delay(1);
    // DMC_START_DIAG_HK
    // DIAG_HK_PERIOD             PP076420
    // tcsend PC146420 [list PP076420 $diag_hk_period]
    // waittime $command_time
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    // End of procedure
    //-----------------
    // Mark End of Block
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose : Monitor the behaviour of Vrl and VhBlind
//           as a function of the temperature variation
//       <=> PCD req.1.1.6. Pixel offset with temperature
//
// Author : Koryo Okumura
//
// Argument :
//    niter : Number of small blocks to repeat
//    nVrls : Number of VRL values to explore
//    initialBiasTable : File name of a low gain biase table for the setting during the measurement
//    finalBiasTable : File name of a high gain biase table to reset at the end
//    stabilizationWaitTime : stanilization time in seconds
//    acquisitionTime : data acquisition duration in seconds
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is set
//
// Description : Observation calling the procedure Phot_small_Vrl_VhBlind
//
//
// Version	: 1.0
// History	: 0.1 0  Koryo Okumura
// 		  0.2 15-nov-2006 KO Eliminate 0.0 volts
// 		  0.3 01-dec-2006 KO Change for the high gain direct measurement
// 		  1.0 04-mar-2008 VD translated into PV script VDP
//                                           1.1 07-mar-2008 KO Input variables relocated in the first block
//                                           1.2 10-mar-2008 KO Default vhbs and vrls set for the low gain part of the complete version
obs PacsEng_Phot_VrlVhBlind {
    /* Needed variables to call PacsEng_Phot_VrlVhBlind                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    int niter = 1;
    /*double[] vhbs = [2.0,2.25];*/
    /*double[] vrls = [0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8];*/
    double[] vhbs = [2.4,2.2,2.0,1.8];
    double[] vrls = [0.05,0.1,0.2,0.25,0.3,0.4,0.5,0.6,0.65,0.7,0.8];
    string initialBiasTable = "BOLObias_preILT_standard_low";
    int stabilizationWaitTime = 90;
    int acquisitionTime = 30;
    /* End of needed variables for PacsEng_Phot_VrlVhBlind                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Phot_small_Vrl_VhBlind_IST(niter,vhbs,vrls,initialBiasTable,stabilizationWaitTime,acquisitionTime)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Phot_small_Vrl_VhBlind_IST(niter,vhbs,vrls,initialBiasTable,stabilizationWaitTime,acquisitionTime);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsLineSpecEstimatorOBCP32.txt,v 1.1 2007/10/25 12:16:47 dcesarsk Exp $ 
// Purpose       : Estimate several PACS parameters for each spectral
//                 line specified by the HSPOT user
//
// CUS author    : DAC
//
// Input arguments
// type           name            Description
// tuple          lines           spectral line info from HSPOT
// tuple          waveTuple       grating info associated to "lines"
// tuple          paramsSPECdef   confSPECblu & confSPECred & confOBCP
//
// Return values
// Type             Description
// tuple            Derived values for paramsSPECdef
//
// Description   : Fill the PACS state descriptors confSPECx & confOBCP, per
//                 HSPOT defined wavelength, with values obtained from
//                 OBCP32params (a CAL-U file). This procedure is called once 
//                 per spectral line. The repFactor is implemented as the
//                 number of nb_obs_cal parameter in OBCP freq switch.
//
// Dependencies  : 
//
// Preconditions :
//
// Comments      : Several confOBCP elements differ from non switched OBCPs
//                 Code keeps old confOBCP commented out for reference.
//                 NOTE.Several confOBCP elements are redefined here!!
// 
// History       : 0.1 18-oct-2007 DAC Based on PacsLineSpecEstimatorOBCP22
//                 0.2 25-mar-2009 DAC Removed references to "React on flux"
//                 1.0 26-mar-2009 DAC Adapted for "ABBA" line switch: added jumpREF3, jumpREF4 to
//                                 OBCP32params; renamed all jumpREFx to paramX as per DMC
//                                 description.
//                 2.0  3-jun-2009 DAC This version geared to latest OBCP32
//                 3.0  13-may-2010 cloned for PHS-1416
//    
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsLineSpecEstimatorOBCP32_simul {
    {string,double,int,double,double,double,string,string} lines = {"NONE",60.2,1,0.0,0.0,0.0,"bla","bla"}; // linesTuple HSPOT
    {double,int,int,int,int} waveTuple = {100.0,1,500000,0,0}; // waveTuple          
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; // Default values
    bool simul = true;
    bool verbose = true; // print debug information
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    // ORDER of the current line
    int order = waveTuple{1};
    double waveLEN = waveTuple{0};
    // User desired repetition factor for current line
    int userREPfactor = lines{2};
    // Get the "quantum" OBS time for the current order.
    // Grating info pertaining to the current wavelength is in waveTuple
    int grat_pos_LINE = waveTuple{2};
    // Get "duration" and switch parameters from OBCP22params U-CAL table
    // There is a row per order; it lists main OBCP parameters
    string calNAME = "OBCP32params";
    // The acces key is the grating order
    // Grab OBCP parameters from CALU file
    string key = "" + order;
    int nb_ramps_grat = ilookup(calNAME,key,"P6ramps");
    int nb_up_dn = ilookup(calNAME,key,"P1UpDn");
    int ditherCount = ilookup(calNAME,key,"P2shifts");
    int ditherSize = ilookup(calNAME,key,"P3dither");
    int jumpAtoB = ilookup(calNAME,key,"P7move");
    int nbABBA = ilookup(calNAME,key,"P4ABBA");
    // NOTE: nb_up_dn above is multiplied by userREPfactor
    nb_up_dn = nb_up_dn * userREPfactor;
    // Still to compute offline: offset to grat_pos_LINE so line is centered at 1/2
    // dithering cycle
    int offLine = 0;
    int grat_pos_LINEoff = grat_pos_LINE + offLine;
    if(verbose) {
        debug_print("Estim.OBCP32:gratLINE/graLINE+offset: " + grat_pos_LINE + "/" + grat_pos_LINEoff);
    }
    // Estimate the OBS time for this rangeInfo; estimation is for ONE nod only.
    // Get nb_rdouts_ramp from confSPECred
    int nbRdOutsRamp = confSPECred{1};
    int[] dureeOBCP32 = PacsDureeOBCP32(ditherCount,nb_up_dn,nbABBA,nb_ramps_grat,nbRdOutsRamp);
    // Use SRC/REF duration to compute quantumOBStime
    int quantumOBStime = dureeOBCP32[1] + dureeOBCP32[2];
    // Inform user
    //    string[] msgLine = [" "];
    //   int lineCnt = 0;
    //  if(simul){
    //   msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + waveLEN + " [&micro;m] with line repeated " + userREPfactor + " time(s)</p>";
    //   lineCnt = lineCnt + 1;
    //  }
    if(verbose) {
        debug_print("Estim.OBCP32:jumpAtoB/gratLINE/nbABBA/ditherSize: " + jumpAtoB + "/" + grat_pos_LINEoff + "/" + nbABBA + "/" + ditherSize);
    }
    // Pack information into proper tuples
    // confOBCP { 0}  =   nb_up_down      ;
    // confOBCP { 0}  =   nb_obs_cal       ;
    confOBCP{0} = nb_up_dn;
    // confOBCP { 1}  =   grat_step_up     ;
    confOBCP{1} = jumpAtoB;
    // confOBCP { 2}  =   grat_step_dn     ;
    confOBCP{2} = nbABBA;
    // confOBCP { 3}  =   nb_SRC_OFF       ;
    // confOBCP { 3}  =   nb_SRC           ;
    confOBCP{4} = nb_ramps_grat;
    // confOBCP { 5}  =   nb_CS1           ;
    // confOBCP { 6}  =   nb_grat_step_up  ;
    // confOBCP { 6}  =   nb_CS2           ;
    // confOBCP { 7}  =   nb_grat_step_dn  ;
    confOBCP{7} = ditherCount;
    // confOBCP { 8}  =   grat_start_pos   ;
    confOBCP{8} = grat_pos_LINEoff;
    //    confOBCP { 9}  =   grat_start_time  ;
    confOBCP{9} = ditherSize;
    //    confOBCP {10}  =   grat_def_pos     ;
    //    confOBCP {11}  =   grat_def_time    ;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    //   confSPECred{0} = capa_red;
    //   confSPECred{ 1} =  nb_rdouts_ramp_red;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    // int comp_mode_red = 16;
    //   confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    //   confSPECblu{0} = capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts_ramp_blu;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    // int comp_mode_blu = 16;
    //   confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    //    string msgLabel = "Observing time for wave-switch" + lines{0};
    //   if(simul){ 
    //      PacsMessageCenter(msgLabel,lineCnt,msgLine);
    //   }
    int nb_nods = 0;
    int aux3 = 0;

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,ditherCount,quantumOBStime,aux3}};
}

// Missionphase  : 
//
// Purpose       : Read a BOLObias calibration table and command bias
//                 voltages for VH, VL, VRL and VH_BLIND group by group
//
// Author        : Koryo Okumura
// CUS script    : Koryo Okumura modified from PHOT_set_bias_volt.txt
// CVS file      : PHOT_change_bias_volt.cus
//
// Arguments     : 
// string  calTableName    The Cal table name, f.i. BOLObias or BOLOsafe
//
// Description   : Read VH, VL, VRL and VH_BLIND from a given Bias U-CAL
//                 tables in volts and command them
//
// Dependencies  : 
//
// Preconditions : The other biases should be alredy set by PHOT_set_bias
//                 or PHOT_set_bias_volt
//
// Comments      : This script is used especially in calibration purpose
//
// Version      : 2.0
// History       :
//  24-aug-2006 KO, First try
//  22-jul-2008 KO, Reformatted for CP, PV and operation phase
//  10-oct-2008 VDP PV logic implemented
//
obs PacsEng_Phot_change_biases {
    string biasTable = "BOLObias_standard_high"; // Bias table [volts]
    string setting = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Readout mode
    string gain = "NO_CHANGE" in ["NO_CHANGE","LOW","HIGH"]; // Gain
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PHOT_change_biases(biasTable,setting,gain)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_change_biases(biasTable,setting,gain);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

//$Id: PHOT_dpu_dmc_setup.txt,v 1.5 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : 
//
// Purpose       : Prepare DPU and DMC for photometry
//
// TCL author    : TM
// TCL file      : tm_phot_dpu_dmc_setup.tcl
// CUS author    : DAC
// Script file   : PHOT_dpu_dmc_setup.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : This script will set the DPU HK list, write and set the
//                 FPGA timing parameters (if necessary), set the
//                 synchronization source for the sequencer, forward data
//                 to the packet encoder and validate the sciece data
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.1
// History       : 0.1 11-apr-2005 creation by DAC; based on V1.2 of TM
//                 0.2 13-apr-2005 DAC Graded as a procedure
//                 0.3 20-oct-2005 DAC Use FPGA parameters from SPEC
//               : 1.0 12-apr-2006 update by TM for new FPGA parameter settings
//                                 taking out switch-on of temp sensors
//                 1.1 11-aug-2006 TM delay(1) introduced between sequential
//                                 FPGA parameter settings
//                 2.0 21-nov-2006 Removed "duree" information; introduced
//                                 CAL file holding FPGA parametrer phase_inc
//                                 Spelled out FPGA parameters
//                 2.1 15-jan-2008 Script renamed *txt for PV database, added
//                                 demanded TC as per SCR-0797  
//		   2.2 15-Jul-2008 update IA_CHOP address
//		   2.3 11-nov-2008 change phase_shift_reg to 1
procedure PHOT_dpu_dmc_setup {
    string hk_list = "BOTH Array" in ["BOTH Array","BLUE Array","RED Array"];
    /* sync source                                  */
    /* 1 = synchronize on blue spectrometer ramps   */
    /* 2 = synchronize on red spectrometer ramps    */
    /* 4 = synchronize on BOL readouts              */
    int sync_srce = 4;
}{
    // Start regular HK
    Pacs_DPU_SET_HK_LIST("PHOT",hk_list);
    // Add chop_ia information as per SCR-0797 
    // Description of DMC_WRT_DIAG_HK_CONF_TAB from DEC/MEC User Manual:
    //
    // Custom Hk Configuration Table : This buffer contains configuration data
    // allowing us to increase the number of available HK measure without 
    // recompiling the application. The table is composed of 10 entries each of 
    // them being 5 words long:
    //f1. the address of the memory area to monitor
    //    int f1 = 0x3469f;
    int f1 = 0x346ab;
    //f2. the size (in words) of the memory area to monitor
    int f2 = 0x1;
    //f3. the size (in bytes) of the memory area to monitor
    int f3 = 0x2;
    //f4. a pointer to a function performing the monitoring (if you want to use this
    //    field, it is highly probable that you need to patch your code anyway to 
    //    upload the new monitoring function).
    int f4 = 0x0;
    //f5. the validity at startup (0 = invalid, 1 = valid)
    int f5 = 0x1;
    // All the fields are initialized to zero at startup. (for advanced users only)   
    {int}[] params = [{f1},{f2},{f3},{f4},{f5}];
    int[] forsum = [f1,f2,f3,f4,f5];
    int check_sum = checksum("int",forsum);
    int wrdLen = 5;
    Pacs_DMC_WRT_DIAGHK_CONF_TAB(wrdLen,params,check_sum);
    int iBOL = 4;
    params = [{iBOL}];
    check_sum = checksum("int",[iBOL]);
    Pacs_DMC_WRT_BOL_REC_OPT(params,check_sum);
    // DEC/MEC User Manual; section 4.4.3
    // 1. and 2. Stop forwarding data to packet encoder (bit 2 set)
    int iPAR = 4;
    params = [{iPAR}];
    check_sum = checksum("int",[iPAR]);
    Pacs_DMC_WRT_B_DEC_REC_OPT(params,check_sum);
    Pacs_DMC_WRT_R_DEC_REC_OPT(params,check_sum);
    // 3. Upload DMC_WRT_TIMING_FPGA_PAR with {0,1,0,26,0x977602A,0x32}
    // Write and set FPGA timing parameters
    // DMC_WRT_TIMING_FPGA_PAR
    int sync_src_det = 0;
    // changes for Phase shift from 0 to 1
    int phase_shift_reg = 1;
    int bolc_freq_div = 0;
    int pd5_reg = 26;
    //int phase_inc: read from CAL-U file FPGA_params
    int ctrl_reg = 0x32;
    // Read phase_inc from CAL-U file FPGA_params. 
    // Here we always read the row "Plast". When updating the CAL-U file rename 
    // the existing "Plast" row to "Pold1", "Pold2", etc. and add the latest 
    // phase_inc in the new row "Plast" 
    int phase_inc = ilookup("FPGA_params","Plast","phase_inc");
    int[] aux = [sync_src_det,phase_shift_reg,bolc_freq_div,pd5_reg,phase_inc,ctrl_reg];
    check_sum = checksum("int",aux);
    {int}[] parlist = Array2grp_1(aux);
    // Write to register and activate
    Pacs_DMC_WRT_TIMING_FPGA_PAR(parlist,check_sum);
    // 4. Apply the new parameters
    Pacs_DMC_SET_TIMING_FPGA_PAR();
    // 5. Change the sync signal  
    Pacs_DMC_SYNCHRONIZE_ON_DET(sync_srce);
    // 6. Wait 1 second  
    delay(1);
    //7. Upload WRT_TIMING_FPGA_PAR with {0,1,0,26,0x977602A,0x22}
    ctrl_reg = 0x22;
    aux = [sync_src_det,phase_shift_reg,bolc_freq_div,pd5_reg,phase_inc,ctrl_reg];
    check_sum = checksum("int",aux);
    parlist = Array2grp_1(aux);
    // Write to register and activate
    Pacs_DMC_WRT_TIMING_FPGA_PAR(parlist,check_sum);
    // 8. Apply the new parameters
    Pacs_DMC_SET_TIMING_FPGA_PAR();
    // 9. Start forwarding data from BOL to SPU (bit 2 is clear)
    iBOL = 0;
    params = [{iBOL}];
    check_sum = checksum("int",[iBOL]);
    Pacs_DMC_WRT_BOL_REC_OPT(params,check_sum);
    // Validate science data photometry
    Pacs_DMC_VAL_SCI_DATA_BOTH();
}

// Script file   : DMC_grat_line_scan_chop2_fast.txt 
// Purpose       : Compute execution time of DMC #17: 
//                 Grating Line Scan with Two position chopping fast
//
// TCL author    : N/A Pseudo code by HF
// TCL file      : N/A
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Similar to 4.2.2 but without "wait 1" statements
//                  
// Dependencies  : 
//
// Preconditions : None.
//                 
// Comments      : No TC are generated; only times are computed
// 
// History       : 0.1 26-jun-2006 DAC
int[] procedure DMC_grat_scan_chop2_fast {
    int nb_up_down = 1; // Seq P#1 : Nb of sequences: up down up ...
    int nb_grat_steps = 1; // Seq P#2 : Nb of grating steps (up/down scans)
    int nb_ramps_plateau = 1; // Seq P#5 : Nb of ramps per chopper position
    int nb_CS1_CS2 = 1; // Seq P#7 Nb of cycles on CS, per grating position
    int nb_cycles_grat_pos = 1; // Seq P#3 : Nb of cycles per grating position
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    // WAIT 1                                             ; have a defined start
    duree_OVR = duree_OVR + 1;
    duree_num = duree_num + 1;
    // LABEL 0                                            ; set Label to 0 
    // LOOP P#1                                           ; main loop measurement
    for(int up_down = 1 .. nb_up_down) {
        //LOOP P#2 ; grating loop up
        for(int up = 1 .. nb_grat_steps) {
            // MOVE_GRATING_RELATIVE P#10                  ; increment grating position 
            // LOOP P#3 ; chop readout cycle
            for(int chop_cycle_1 = 1 .. nb_cycles_grat_pos) {
                // MOVE_CHOPPER_ABSOLUTE P#4                ; chopper to P#4 
                // LABEL 3                                  ; first chopper pos. 
                // WAIT P#5                                 ; take P#5 ramps 
                // *Assume* P#4 is the SRC position... 
                duree_SRC = duree_SRC + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                //           *Assume* P#5 is the REF position... 
                // MOVE_CHOPPER_ABSOLUTE P#6                ; chopper to P#6 
                // LABEL 5                                  ; next chopper pos. 
                // WAIT P#5                                 ; take P#5 ramps 
                // *Assume* P#6 is the REF position... 
                duree_REF = duree_REF + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                 ; chop readout cycle done
            }
            // LOOP P#7                                    ; calibration loop
            for(int cal_loop_1 = 1 .. nb_CS1_CS2) {
                // MOVE_CHOPPER_ABSOLUTE P#8                ; chop to BB1 
                // LABEL 65                                 ; BB1 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // MOVE_CHOPPER_ABSOLUTE P#9                ; chop to BB2 
                // LABEL 129                                ; BB2 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                    ; calibration done
            }
            // END_LOOP                                      ; grating scan up done
        }
        // LOOP P#2                                      ; grating loop down
        for(int down = 1 .. nb_grat_steps) {
            // MOVE_GRATING_RELATIVE P#11                 ; decrement grating position 
            // LOOP P#3 ; chop readout cycle
            for(int chop_cycle_2 = 1 .. nb_cycles_grat_pos) {
                // MOVE_CHOPPER_ABSOLUTE P#4               ; chopper to P#4 
                // LABEL 19                                ; first chopper pos. 
                // WAIT P#5                                ; take P#5 ramps 
                duree_SRC = duree_SRC + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // MOVE_CHOPPER_ABSOLUTE P#6               ; chopper to P#6 
                // LABEL 21                                ; next chopper pos. 
                // WAIT P#5                                ; take P#5 ramps 
                duree_REF = duree_REF + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                   ; chop readout cycle done
            }
            // LOOP P#7                                    ; calibration loop
            for(int cal_loop_2 = 1 .. nb_CS1_CS2) {
                // MOVE_CHOPPER_ABSOLUTE P#8                ; chop to BB1 
                // LABEL 81                                 ; BB1 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // MOVE_CHOPPER_ABSOLUTE P#9                ; chop to BB2 
                // LABEL 145                                ; BB2 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                    ; calibration done
            }
            // END_LOOP                                      ; grating scan down done
        }
        // END_LOOP                                        ; main loop done
    }
    // LABEL 0                                            ; reset LABEL to 0 
    // END_SEQUENCE 
    // duration, in ramps : 1 + P#1 * 2 * P#2 * {(P#3 + P#7) * (2*P#5)}
    int duree = 1 + nb_up_down * 2 * nb_grat_steps * ((nb_cycles_grat_pos + nb_CS1_CS2) * 2 * nb_ramps_plateau);
    debug_print("Formula  duration DMC: " + duree + " [ramps]");
    debug_print("Computed duration DMC: " + duree_num + " [ramps]");
    // Time spent
    int duree_TCs = time() - time_start;
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// CVS comments  : $Id: PacsArrayMinMax.txt,v 1.3 2007/05/23 07:25:35 dcesarsk Exp $ 
// Script file   : PacsArrayMinMax.txt 
//
// Purpose       : Return the indices for the MIN and MAX element of an array
//
// CUS author    : DAC
//
// Input arguments
// double anyArray[]
//
// Return values
// [indexMin,indexMax]
//
// Description   : Returns the position of the largest/smallest member of
// input anyArray
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-apr-2007 DAC
//
int[] procedure PacsArrayMinMax {
    double[] anyArray = [0.0];
    bool verbose = false;
}{
    // Establish nbElem of array
    int nbElem = length(anyArray);
    // Define return values (-1 means error)
    int posMin = -1;
    int posMax = -1;
    // Impossible boundaries
    double theMax = -1.0E-30;
    double theMin = 1.0E30;
    // Review all elements of anyArray
    for(int loop = 0 .. nbElem - 1) {
        double aux = anyArray[loop];
        if(aux < theMin) {
            theMin = aux;
            posMin = loop;
        }
        if(aux > theMax) {
            theMax = aux;
            posMax = loop;
        }
    }

    return [posMin,posMax];
}

//
// Purpose       : Exercise all available OBCPs for SPECtroscopy
//                  
//                 
//
// TCL author    : N/A
// TCL file      : tN/A
// CUS author    : DAC
// Script file   : SPEC_all_aots_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Exercise all available OBCPs for PHOT
//   
// Dependencies  : 
//
// Preconditions : SPEC_setup has been executed
//     
// Comments   : 
// 
// Version      2.0
// History       0.1 25-apr-2005 DAC
// 0.2 26-apr-2005 DAC Added SPEC_spu_setup and PACS_reset
// 0.3 26-apr-2005 DAC SPEC_aot_prologue instead of SPEC_spu_setup 
// 0.4 20-sep-2005 Correcred up/dn grating steps
// 0.5 25-oct-2005 DAC Use fit_alg = 0
// 0.6 09-aug-2006 TM updated for both filters, new OBCP, new default parameters
//                             and SPEC_spu_setup (instead of SPEC_aot_prologue)
// 0.7 10-aug-2006 TM shorten execution length
// 0.8 09-aug-2006 TM synchronisation sources for OBCP27 changed from 2 to 1
// 1.0 17-nov-2006 Reviewed for OpDataBase
// 2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
procedure Pacs_Spec_all_aots {
}{
    // Register with environment
    // Start SPU
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    int nb_samp_subramp_blu = 64;
    int nb_samp_subramp_red = 64;
    int nb_raw_spu_blu = 0;
    int nb_raw_spu_red = 0;
    int glitch_det = 1;
    int ramp_fit_alg = 0;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,true);
    //
    // Position the filter wheel at POS A
    //
    SPEC_fltw_move("POS A");
    //
    // Perform OBCP_spec_2_3_chop with default parameters  
    debug_print("Start OBCP_spec_2_3_chop");
    int[] duree = OBCP_spec_2_3_chop(1,16,1,1000,1,-3000,5000,1,-22500,22500,168,-168,1,461000,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_spec_2_3_chop: " + duree);
    delay(2);
    // Perform OBCP_spec_2_3_chop_dither with default parameters  
    debug_print("Start OBCP_spec_2_3_chop_dither");
    duree = OBCP_spec_2_3_chop_dither(1,16,1,1000,1,-3000,5000,1,-22500,22500,168,-168,1,461000,20000,16,16,500000,0,10000,100,64);
    debug_print("Duration from OBCP_spec_2_3_chop_dither: " + duree);
    delay(2);
    // Perform OBCP_grat_line_scan_chop_2 with default parameters  
    debug_print("Start OBCP_grat_line_scan_chop_2");
    duree = OBCP_grat_line_scan_chop_2(1,32,1,1000,1,3000,1,-22500,22500,168,-168,1,445000,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_grat_line_scan_chop_2: " + duree);
    delay(2);
    // Perform OBCP_grat_scan_chop2_fast with default parameters
    debug_print("Start OBCP_grat_scan_chop2_fast");
    duree = OBCP_grat_scan_chop2_fast(1,48,1,1000,1,-2000,1,-22500,22500,240,-240,1,445000,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_grat_scan_chop2_fast: " + duree);
    delay(2);
    // Perform OBCP_grat_scan_nochop with default parameters  
    debug_print("Start OBCP_grat_scan_nochop");
    duree = OBCP_grat_scan_nochop(1,20,1600,-1600,3,1,-22500,22500,3,20,0,1,445000,20000,16,16,500000,10000,64);
    debug_print("Duration from OBCP_grat_scan_nochop: " + duree);
    delay(2);
    // Perform OBCP_spec_2_3_chop with default parameters  
    debug_print("Start OBCP_spec_2_3_chop");
    duree = OBCP_spec_2_3_chop(1,16,1,1000,1,-3000,5000,1,-22500,22500,2500,-2500,1,461000,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_spec_2_3_chop: " + duree);
    delay(2);
    // Perform OBCP_chop_grat_scan_cal with default parameters  
    debug_print("Start OBCP_chop_grat_scan_cal");
    duree = OBCP_chop_grat_scan_cal(1,0,16,133,2,-22500,3,22500,-133,1,461000,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_chop_grat_scan_cal: " + duree);
    delay(2);
    // Perform OBCP_chop_scan_spec with default parameters
    debug_print("Start OBCP_chop_scan_spec");
    duree = OBCP_chop_scan_spec(1,2,80,80,400,-400,1,486000,-16000,20000,16,16,500000,10000,0,64);
    debug_print("Duration from OBCP_chop_scan_spec: " + duree);
    delay(2);
    // Perform OBCP_spec_freq_switch with default parameters  
    debug_print("Start OBCP_spec_freq_switch");
    duree = OBCP_spec_freq_switch(2,1000,10,461000,3,454600,467400,1,-22500,1,22500,1,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_spec_freq_switch: " + duree);
    delay(2);
    //
    // Position the filter wheel at POS B
    //
    SPEC_fltw_move("POS B");
    //
    // Perform OBCP_spec_2_3_chop with default parameters  
    debug_print("Start OBCP_spec_2_3_chop");
    duree = OBCP_spec_2_3_chop(1,16,1,1000,1,-3000,5000,1,-22500,22500,168,-168,1,461000,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_spec_2_3_chop: " + duree);
    delay(2);
    // Perform OBCP_spec_2_3_chop_dither with default parameters  
    debug_print("Start OBCP_spec_2_3_chop_dither");
    duree = OBCP_spec_2_3_chop_dither(1,16,1,1000,1,-3000,5000,1,-22500,22500,168,-168,1,461000,20000,16,16,500000,0,10000,100,64);
    debug_print("Duration from OBCP_spec_2_3_chop_dither: " + duree);
    delay(2);
    // Perform OBCP_grat_line_scan_chop_2 with default parameters  
    debug_print("Start OBCP_grat_line_scan_chop_2");
    duree = OBCP_grat_line_scan_chop_2(1,32,1,1000,1,3000,1,-22500,22500,168,-168,1,445000,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_grat_line_scan_chop_2: " + duree);
    delay(2);
    // Perform OBCP_grat_scan_chop2_fast with default parameters
    debug_print("Start OBCP_grat_scan_chop2_fast");
    duree = OBCP_grat_scan_chop2_fast(1,48,1,1000,1,-2000,1,-22500,22500,240,-240,1,445000,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_grat_scan_chop2_fast: " + duree);
    delay(2);
    // Perform OBCP_grat_scan_nochop with default parameters  
    debug_print("Start OBCP_grat_scan_nochop");
    duree = OBCP_grat_scan_nochop(1,20,1600,-1600,3,1,-22500,22500,3,20,0,1,445000,20000,16,16,500000,10000,64);
    debug_print("Duration from OBCP_grat_scan_nochop: " + duree);
    delay(2);
    // Perform OBCP_spec_2_3_chop with default parameters  
    debug_print("Start OBCP_spec_2_3_chop");
    duree = OBCP_spec_2_3_chop(1,16,1,1000,1,-3000,5000,1,-22500,22500,2500,-2500,1,461000,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_spec_2_3_chop: " + duree);
    delay(2);
    // Perform OBCP_chop_grat_scan_cal with default parameters  
    debug_print("Start OBCP_chop_grat_scan_cal");
    duree = OBCP_chop_grat_scan_cal(1,0,16,133,2,-22500,3,22500,-133,1,461000,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_chop_grat_scan_cal: " + duree);
    delay(2);
    // Perform OBCP_chop_scan_spec with default parameters
    debug_print("Start OBCP_chop_scan_spec");
    duree = OBCP_chop_scan_spec(1,2,80,80,400,-400,1,486000,-16000,20000,16,16,500000,10000,0,64);
    debug_print("Duration from OBCP_chop_scan_spec: " + duree);
    delay(2);
    // Perform OBCP_spec_freq_switch with default parameters  
    debug_print("Start OBCP_spec_freq_switch");
    duree = OBCP_spec_freq_switch(2,1000,10,461000,3,454600,467400,1,-22500,1,22500,1,20000,16,16,500000,0,10000,64);
    debug_print("Duration from OBCP_spec_freq_switch: " + duree);
    delay(2);
    //
    // Position the filter wheel at POS A
    //
    SPEC_fltw_move("POS A");
    //
    // Stop SPU
    //
    PACS_spu_reset();
    // Leave environment
    sync();
}

// File          : procedure Pacs_Spec_Curing_Concept_Loop
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Ge:Ga detector Loop
//
// Author        : Pierre Royer
// CUS script	 : PR
// CVS file	 :
//
// Arguments     : bias, integration time, capacity, measurement time, resistor bias
//
// Description   :   Loop over bias, integration time and capacity.
//
// Dependencies  : - SPEC_CRE_No_Heater_setup
//		   - SPEC_spu_setup
//		   - PACS_Chop_Move_Abs
//		   - SPEC_spu_reset
//
// Comments      : The input arrays for bias, ramp length & capacitance must have the same length for red & blue
//
// Version       : 1.0
// History       : 1.0 / 04-Jul-2008 initial version by PR
//
procedure Pacs_Spec_Curing_Concept_Loop {
    int repeat_intern = 10; // Repetition factor inside the bias loop (ramplen+capa loops)
    double[] bias_blue = [0.08,0.1,0.125,0.15,0.175,0.2]; //bias blue
    double[] bias_red = [0.02,0.03,0.04,0.05,0.06,0.07]; //bias red red
    int[] ramp_len_blue = [32,64]; //ramp length blue (set integration time)
    int[] ramp_len_red = [32,64]; //ramp length red (set integration time)
    int[] capa_blue = [8,12]; //capacity blue
    int[] capa_red = [8,12]; //capacity red
    int meas_time = 60; //observing time in seconds per setting
    double bias_res_blue = 0.01; //resistor bias blue
    double bias_res_red = 0.01; //resistor bias red
    int chop_pos = 21200; // chopper position
    int grat_pos = 535000; // grating position
    string filter_pos = "POS A" in ["POS A","POS B"]; // FW position
    int blue_flasher_current = 819 in [0,820]; //4mA. [0,4095] = [0,20 mA]
    int red_flasher_current = 819 in [0,820]; //4mA. [0,4095] = [0,20 mA]
    int nflash = 1; // Number of flashes
    int flash_time = 90; // Duration of each flash
    int interflash_time = 30; // Idle time between the flashes
}{
    // CURING PARAMETER
    int curing_mode = 0;
    //
    // Position the grating
    // ====================
    Pacs_DMC_MOVE_GRAT_ABS(grat_pos);
    delay(15);
    //
    // Position the chopper
    // ====================
    PACS_Chop_Move_Abs(chop_pos);
    delay(1);
    //
    // Position the filter wheel
    // =============
    SPEC_fltw_move(filter_pos);
    // delay is contained in the procedure
    //
    // Declare the set of CRE variables
    // ===================
    double bias_d_blue = bias_blue[0];
    double bias_d_red = bias_red[0];
    int ramp_blue = ramp_len_blue[0];
    int ramp_red = ramp_len_red[0];
    int capacity_blue = capa_blue[0];
    int capacity_red = capa_red[0];
    // 
    // Setup SPU
    //
    // Compression mode blue channel : Nominal
    int comp_mode_blu = 16;
    // Compression mode red channel : Nominal
    int comp_mode_red = 16;
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_blu = 8;
    // Nb of red samples per sub-ramp
    int nb_samp_subramp_red = 8;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUL
    int nb_raw_spu_red = 3;
    // Glitch detection; 0=on; 1=off
    int glitch_det = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    int ramp_fit_alg = 1;
    // Start SPU or not [true,false]
    bool startSPU = true;
    //
    // determine length of arrays
    int bb = length(bias_blue);
    //length of bias blue
    int rlb = length(ramp_len_blue);
    //length of ramp length blue
    int cb = length(capa_blue);
    //length of capacity blue
    //
    // SPU RESET
    //
    SPEC_spu_reset();
    delay(1);
    //
    // Setup CREs
    SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red);
    //
    // Setup SPU
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //
    // BIAS LOOP
    //
    int blc = 0;
    while(blc < bb) {
        bias_d_blue = bias_blue[blc];
        bias_d_red = bias_red[blc];
        //
        // CURING
        //
        // SWON FLASHERS
        //
        PACS_Spec_Flash_SWON();
        delay(5);
        //
        // Actual curing
        // -----------
        for(int loopin = 1 .. nflash) {
            PACS_Spec_SPU_Reset();
            delay(1);
            curing_mode = 1;
            SPEC_CRE_Curing_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red,curing_mode);
            delay(1);
            PACS_Spec_Flash_Setup(blue_flasher_current,red_flasher_current);
            delay(flash_time);
            PACS_Spec_Flash_Setup(0,0);
            curing_mode = 0;
            SPEC_CRE_Curing_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red,curing_mode);
            SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
            delay(interflash_time);
        }
        //
        // SWOF FLASHERS
        //
        PACS_Spec_Flash_SWOF();
        delay(10);
        //
        // INTERNAL LOOP
        //
        int internloop = 0;
        while(internloop < repeat_intern) {
            //
            // RAMP LENGTH LOOP
            //
            int rlc = 0;
            while(rlc < rlb) {
                ramp_blue = ramp_len_blue[rlc];
                ramp_red = ramp_len_red[rlc];
                //
                // CAPACITY LOOP 
                //
                int clc = 0;
                while(clc < cb) {
                    capacity_blue = capa_blue[clc];
                    capacity_red = capa_red[clc];
                    //
                    // Setup CREs
                    SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red);
                    //
                    // Setup SPU
                    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
                    //
                    // OBSERVATION 
                    delay(meas_time);
                    //
                    // SPU RESET
                    SPEC_spu_reset();
                    delay(1);
                    clc = clc + 1;
                }
                rlc = rlc + 1;
            }
            //
            internloop = internloop + 1;
        }
        blc = blc + 1;
    }
    //
    //
    // Return Chopper & grating to default
    // =====================
    Pacs_DMC_MOVE_GRAT_ABS(500000);
    delay(1);
    PACS_Chop_Move_Abs(0);
    delay(15);
    //
    // SYNC
    //= = =
    sync();
    //
    // End of Script
}

// $Id: PacsCal_Spec_Rsrf.txt,v 1.2 2008/11/12 18:22:41 bart Exp $
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       :  Deep staring scan for RSRF verification with pointing
//                  
//
// Input arguments 
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Uses OBCP28 for executing a deep scan 
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                 
// Comments      : 
// Version	 : 1.1
// History	 : 1.0 30-oct-2008 BV Adopted from ILT PACS_Spec_Rsrf_OBS
//                 1.1 12-nov-2008 BV Corrected state machine section 
//
obs PacsCal_Spec_Rsrf {
    int chop_def = -21350; // chopper position during grating scan
    string filter = "POS A" in ["POS A","POS B"]; // Filter wheel position
    int grating_start = 32000; // grating start position for scan
    int grating_stepsize = 133; // grating step size
    int grating_numsteps = 7759; // number of grating steps
    int grating_numramps = 4; // number of ramps per grating position
    int readoutsperramp = 64; // number of readouts per ramp
    int capa_red = 12; // Red capacitor
    int capa_blu = 0; // Blue capacitor
    double bias_d_red = 0.0701 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_red = 0.01101 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.2101 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_r_blu = 0.01101 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    int naifid = 0; // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    double yoffset = 0.0; // yoffset [arcsec]
    double xoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
}{
    // Compute the time 
    //  Execute the pointing request
    bool execute = true;
    //  Slew
    //    Write OBSID during slew    
    int tOBSID = duration(WriteOBSID($OBSID));
    // no initial hold
    int tih = 0;
    //  Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Rsrf(chop_def,filter,grating_start,grating_stepsize,grating_numsteps,grating_numramps,readoutsperramp,capa_red,capa_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu)));
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tOBSID,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Rsrf(chop_def,filter,grating_start,grating_stepsize,grating_numsteps,grating_numramps,readoutsperramp,capa_red,capa_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// Script file   : PACS_Spec_Gra_IST_Ampl_OBS.cus 
//
// Purpose       :  Check the Amplitude of the Grating inductosyn by running a loop over it
//
// CUS author    : PR
//
// Input arguments none
// type    name         description
//
// Preconditions : PACS in SAFE MODE, or Spectroscopy Mode
//	    In any case, Controller of the Calibration Sources MUST BE OFF
//                 
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
// 		  2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
//
procedure Pacs_Spec_Gra_IST_Ampl {
}{
    // Register start of OBS
    debug_print("Configure Nominal SPEC_HK");
    PACS_Spec_HK_Setup();
    debug_print("Configure DIAG_HK");
    int diag_hk_period = 5;
    PACS_Spec_Gra_Diaghk_SINCOS_Setup(diag_hk_period);
    debug_print("Configure Grating in DEGMODE");
    CONF_grating_DEGMODE();
    debug_print("Amplitude Loop");
    PACS_Spec_Gra_Ampl_Open_Loop();
    debug_print("Reset DIAG_HK");
    PACS_Diaghk_Reset();
    debug_print("PACS to SAFE MODE");
    OBCP_SAFE();
    delay(10);
}

// $Id$
// Missionphase  : PACS 
//
// Purpose       : Checking chooper and grating hard limits
//
// Author        : VDP
//
// Arguments     :
//
//
// Description   : Computes and checks the start and end values for 
// 		   chopper and grating hard limits
//               :
// Comments      : should be modular
//
// Version       : 0.1
// History       : 0.1  22-feb-2008 created VDP
//
procedure Pacs_HardLimitsCheck {
    /* variables needed */
    int[] grating_pos = [0]; // grating position, steps and nb of steps
    double chopthrow = 30.0; // chopthrow in arcsec
}{
    // local variables
    bool chckboth = false;
    int g_len = length(grating_pos);
    //    
    if(g_len != 1) {
        chckboth = true;
    }
    int chop_max = ilookup("SPEC_MEC_Defaults","Spectroscopy","chop_max");
    int chop_min = ilookup("SPEC_MEC_Defaults","Spectroscopy","chop_min");
    int grat_max = ilookup("SPEC_MEC_Defaults","Spectroscopy","grat_max");
    int grat_min = ilookup("SPEC_MEC_Defaults","Spectroscopy","grat_min");
    double ref1 = chopthrow / 2.0;
    double ref2 = -chopthrow / 2.0;
    int chop_pos1 = PacsReadChopSky("SPEC_CHOP_sky",ref1);
    int chop_pos2 = PacsReadChopSky("SPEC_CHOP_sky",ref2);
    if(chop_pos2 < chop_min || chop_pos1 > chop_max) {
        error("Chopper position exceed hard limits");
    }
    while(chckboth) {
        int grating_f = grating_pos[0] + grating_pos[1] * grating_pos[2];
        int grating_i = grating_pos[0];
        if(grating_f >= grat_max || grating_i <= grat_min) {
            error("Grating position exceeds hard limits");
        }
    }
}

// CVS comments  : $Id: PacsProcessInfoArrayLine.txt,v 1.13 2007/10/25 12:15:42 dcesarsk Exp $ 
//
// Purpose       : Process the timing information gathered in infoArray
//
// CUS author    : DAC
//
// Input arguments
// type    name        description
// tuple   infoArray
// Slew/Point/AOT       SlewCal or pointing mode or global AOT info
// 0.0                  not in use
// TotDur               duration of the phase Slew/Point/AOT
// nbLines              number of spectral lines observed in phase Slew/point
// nnods                number of nod cycles in phase Point
// m*n                  size of raster when applicable
// wave1                each of the nbLines wavelengths or waveStart
// wave2                each of the nbLines wavelengths or waveEnd
// order                grating order for line wave
// gratStep             grating step (needed to estimate "multiplexing")
// TOT,SRC,REF,CAL,OVR  the canonical OBCP duration (/nod/raster)
//
// Return values
// Type          Description
//
// Description   : Use the information in infoArray to compute several times and
// overheads, as well as the expected RMS fluctuations for each observed line
// infoArray is a three-element tuple:
//    infoArray[0] contains information on the SlewCal phase
//    infoArray[1] contains information on the OBS phase
//    infoArray[2] contains global information on the AOT
//                  
// Dependencies  : 
//
// Comments      : 
// 
// History       : 0.1  6-Sep-2005 DAC
// 0.2 27-sep-2005 Adding elements to compute RMS
// 0.3 28-sep-2005 Add nbGratSteps to infoArray
// 0.4 29-sep-2005 Add confOBCP to input arguments since I need nb_up_dn !!
// 0.5  6-oct-2005 Corrected Raster/Staring logic
// 0.6 14-oct-2005 Text of message
// 1.0 24-oct-2005 Add HTML tags
// 1.1 23-jan-2006 Multiplication by nbNods, mRaster, nRaster no longer needed
//                 since next_state collects time per raster per nod. Also
//                 eliminate "PACS overheads"
// 1.2  1-mar-2006 Use dformat for messages
// 2.0 11-mar-2006 Deal with LINE and CONT RMS values
// 2.1 22-nov-2006 Added "verbose" to input arguments
// 3.0 17-jan-2006 "Improved" messages
// 3.1 12-feb-2007 Accept as input the tuples lines
// 3.2 14-feb-2007 Adapted to amended PacsSpecRMS, simplified code as now
//                 used only with LINE
// 3.3 12-apr-2007 Add obsOverhead for SCR-2813
// 3.4 27-apr-2007 SPR-3147: change km/s into kms
// 3.5 29-may-2007 SPR-3243 Continuum S/N: mJy/mJy
// 3.6 13-jun-2007 SPR-3307 Fewer digits in messages
// 3.7 24-oct-2007 Added nbOBS and nbOFF to input arguments; same to
//                 PacsSpecRMS
procedure PacsProcessInfoArrayLine {
    /* infoArray                                                               */
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    /* lines                                                                  */
    /* {id,redshifted wavelength,repeat factor,line flux,continuum flux,      */
    /*  line width,line flux unit,line width unit}                            */
    {string,double,int,double,double,double,string,string}[] lines = [];
    /* confOBCP                                                               */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* observatory overhead                                                    */
    int obsOverhead = 180;
    /* nbOBS and nbOFF                                                         */
    int nbOBS = 1;
    int nbOFF = 0;
    /* verbose?                                                                */
    bool verbose = true;
}{
    // Data used here is to be found in
    // infoArray[0]{0}{2}   : tslew from PointReq
    // infoArray[0]{0}{3}   : Number of key waves in AOT
    // infoArray[0]{1}[]{0} : keyWAVE[]
    // infoArray[0]{1}[]{5} : sumCalTime[][0]
    // infoArray[0]{1}[]{6} : sumCalTime[][1]
    // infoArray[0]{1}[]{7} : sumCalTime[][2]
    // infoArray[0]{1}[]{8} : sumCalTime[][3]
    // infoArray[0]{1}[]{9} : sumCalTime[][4]
    // infoArray[1]{0}{0}   : PointReq information (ex. SmSrcDither)
    // infoArray[1]{0}{1}   : Integration time per plateau
    // infoArray[1]{0}{2}   : OBCP duration *per pointing*
    // infoArray[1]{0}{3}   : Number of lines/ranges
    // infoArray[1]{0}{4}   : Number of nod cycles
    // infoArray[1]{0}{5}   : Raster m*n
    // infoArray[1]{1}[]{0} : Starting wave for line []
    // infoArray[1]{1}[]{1} : Ending wave for line []
    // infoArray[1]{1}[]{2} : Grating order for line []
    // infoArray[1]{1}[]{3} : Grating step for line []
    // infoArray[1]{1}[]{4} : Number of grating steps for line []
    // infoArray[2]{0}{0}   : OBCP information (ex. FreqSwitch)
    // infoArray[2]{0}{2}   : Total duration of AOR (SLEW+OBS)
    // infoArray[2]{0}{3}   : Raster "m" size
    // infoArray[2]{0}{4}   : Raster "n" size
    // infoArray[2]{0}{5}   : Nb of nods (does not seem to be used anywhere)
    // Number of spectral lines (SlewCal and OBS)
    int nbKeyWaves = infoArray[0]{0}{3};
    int nbLines = infoArray[1]{0}{3};
    // Number of nods (OBS)
    int nbNodCycles = infoArray[1]{0}{4};
    // Nb of "pointings" for nbNodCycles
    int nbNods = 2 * nbNodCycles;
    if(nbNods == 0) {
        nbNods = 1;
    }
    // Call module to estimate RMS fluctuations; pass information via infoArray
    // and confOBCP (for nb_up_dn)
    // To conform with PacsRangeSpec code, define dummy rangeSPOT tuple (needed
    // by new RMS module)
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [];
    // Ditto for "orderSel"
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = PacsSpecRMS("LINE","orderSel",infoArray,rangeSPOT,confOBCP,nbOBS,nbOFF,verbose);
    // Define variable to extract info from noiseTuple
    double[][] noiseWave = [[0.0]];
    // Useful variables
    int lineCnt = 0;
    string[] msgLine = ["Line1"];
    // one line of text
    // Report on nodding pattern and pointing details
    msgLine[lineCnt] = "PACS AOT: PacsLineSpec";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Pointing mode: <B>" + infoArray[1]{0}{0} + "</B> with " + nbNodCycles + " nod cycles</p>";
    lineCnt = lineCnt + 1;
    int mRaster = infoArray[2]{0}{3};
    int nRaster = infoArray[2]{0}{4};
    // When either m or n are >1 then it is raster
    if(mRaster > 1 || nRaster > 1) {
        msgLine[lineCnt] = "<p>Raster size (lines/points):" + mRaster + "/" + nRaster + "</p>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "<p> Nod pattern: nominal position A, or A->B, B->A, etc.</p>";
    lineCnt = lineCnt + 1;
    if(nbNodCycles == 0) {
        msgLine[lineCnt] = "<p>   A </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles == 1) {
        msgLine[lineCnt] = "<p>   A->B </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles == 2) {
        msgLine[lineCnt] = "<p>   A->B B->A </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles > 2) {
        int aux1 = nbNodCycles - 2;
        msgLine[lineCnt] = "<p>   A->B B->A and " + aux1 + " more A<->B leg(s) </p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("AOT, PointMode and Nodding info",lineCnt,msgLine);
    // Global timing information for this AOT
    lineCnt = 0;
    int totAOT = infoArray[2]{0}{2};
    msgLine[lineCnt] = "<p> AOT total duration: " + totAOT + " [sec] </p>";
    lineCnt = lineCnt + 1;
    //  Next is tslew returned by PntReq
    int tslew = infoArray[0]{0}{2};
    msgLine[lineCnt] = "<ul><li> CalSlew (with overheads) " + tslew + " [sec]</li>";
    lineCnt = lineCnt + 1;
    // infoArray[1]{0}{2} is defined as the elementary OBCP duration (per nod
    // and per raster pointing; includes all wavelengths)
    //int totSRCREF = mRaster * nRaster * nbNods * infoArray[1]{0}{2};
    int totSRCREF = infoArray[1]{0}{2};
    msgLine[lineCnt] = "<li> SRC+REF (with overheads) " + totSRCREF + " [sec]</li>";
    lineCnt = lineCnt + 1;
    //  Logic from RV... If tslew takes shorter than obsOverhead, we keep
    //  obsOverhead
    int cost = totAOT - tslew;
    //  But if tlsew takes longer, it becomes the new obsOverhead
    if(tslew > obsOverhead) {
        obsOverhead = tslew;
    }
    cost = cost + obsOverhead;
    msgLine[lineCnt] = "<li><b>AOT cost</b> (includes time for slewing to source): " + totSRCREF + " + " + obsOverhead + " [sec] = " + cost + " [sec]</li></ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Global AOT durations",lineCnt,msgLine);
    if(verbose) {
        debug_print("++ Start ProcessArray debug info");
        debug_print(" CalSlew: " + infoArray[0]);
        debug_print(" OBS    : " + infoArray[1]);
        debug_print(" TotDur : " + infoArray[2]);
        debug_print("++ End of ProcessArray debug info");
    }
    // Inform the details of SlewCal to HSPOT user
    //   AOT prologue
    lineCnt = 0;
    msgLine[lineCnt] = "<ul><li> AOT prologue duration: " + infoArray[0]{1}[nbKeyWaves]{5} + " [sec]</li>";
    lineCnt = lineCnt + 1;
    //  For each keyWave
    for(int loop0 = 0 .. nbKeyWaves - 1) {
        msgLine[lineCnt] = "<li> KeyWave: " + infoArray[0]{1}[loop0]{0} + " [&micro;m]; CAL duration: " + infoArray[0]{1}[loop0]{5} + " [sec]</li>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    // Display message
    PacsMessageCenter("LINE setup and CAL summary",lineCnt,msgLine);
    // Re-initialize lineCnt for new series of messages
    lineCnt = 0;
    // Continue defining noiseWave for historical reasons (it used to be returned
    // by PacsSpecRMS, now replaced by bigTuple)
    for(int loop1 = 0 .. nbLines - 1) {
        int trueObsTime = infoArray[1]{1}[loop1]{5};
        noiseWave[loop1] = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0];
        //      CONTinuum
        noiseWave[loop1][0] = bigTuple[loop1]{0}{1}[0];
        noiseWave[loop1][1] = bigTuple[loop1]{0}{1}[1];
        noiseWave[loop1][2] = bigTuple[loop1]{0}{1}[2];
        noiseWave[loop1][3] = bigTuple[loop1]{0}{1}[3];
        //      LINE
        noiseWave[loop1][4] = bigTuple[loop1]{0}{1}[4];
        noiseWave[loop1][5] = bigTuple[loop1]{0}{1}[5];
        noiseWave[loop1][6] = bigTuple[loop1]{0}{1}[6];
        noiseWave[loop1][7] = bigTuple[loop1]{0}{1}[7];
        //      CONT and LINE for refWave     
        noiseWave[loop1][8] = bigTuple[loop1]{0}{1}[8];
        noiseWave[loop1][9] = bigTuple[loop1]{0}{1}[9];
        noiseWave[loop1][10] = bigTuple[loop1]{0}{1}[10];
        //      Estimate resolution for given wavelength and order
        //      Need order and wavelength
        int order = infoArray[1]{1}[loop1]{2};
        double wave = infoArray[1]{1}[loop1]{0};
        //      Build key to read SPEC_resolution table
        string keyCOL = "resol" + order;
        double resolkm = interpolate("SPEC_resolution",keyCOL,wave);
        //      Resolution in microns
        double resolmic = resolkm * wave / 300000.0;
        // Compare instrument resolution with line width
        // User given line width
        double userWidth = lines[loop1]{5};
        // User given width units
        string unitWidth = lines[loop1]{7};
        // Is there a sensitivity degradation? 
        bool sensitDegrad = false;
        // Assume no degradation
        double degrad = 1.0;
        // Avoid division by zero
        if(resolkm > 0.0) {
            // Do not compare torchons et servillettes
            if(unitWidth == "micron" && userWidth > resolmic) {
                sensitDegrad = true;
                degrad = sqrt(userWidth / resolmic);
            }
            if(unitWidth == "kms" && userWidth > resolkm) {
                sensitDegrad = true;
                degrad = sqrt(userWidth / resolkm);
            }
        }
        if(verbose) {
            debug_print("++line parameters: " + userWidth + " " + unitWidth);
            debug_print("++sensitDegrad: " + sensitDegrad);
            debug_print("++Degrad: " + degrad);
        }
        // SrcTime includes REF!
        int trueSrcTime = infoArray[1]{1}[loop1]{6} + infoArray[1]{1}[loop1]{7};
        int lineOver = trueObsTime - trueSrcTime;
        msgLine[lineCnt] = "<h3>" + lines[loop1]{0} + ": " + dformat(infoArray[1]{1}[loop1]{0},2) + " [&micro;m]:</h3>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<ul>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<li>FWHM at current wavelength: " + dformat(resolkm,1) + " [km/s] or " + dformat(resolmic,3) + " [&micro;m]";
        lineCnt = lineCnt + 1;
        int noiseMjy = ifloor(1000.0 * noiseWave[loop1][1]);
        msgLine[lineCnt] = "<li>   Continuum RMS: " + noiseMjy + " [mJy]";
        lineCnt = lineCnt + 1;
        // SPR-3243 Wrong S/N ratio. Use the occasion to avoid divide-by-zero
        if(noiseWave[loop1][1] > 1.0E-30) {
            double s2nCONT = lines[loop1]{4} / noiseWave[loop1][1];
            s2nCONT = s2nCONT / 1000.0;
            msgLine[lineCnt] = "<li>   Continuum S/N: " + dformat(s2nCONT,2);
            lineCnt = lineCnt + 1;
        }
        double lineNoise = noiseWave[loop1][5] * 1.0E18;
        msgLine[lineCnt] = "<li>Line RMS: " + dformat(lineNoise,2) + "E-18 [w/m2]</li>";
        lineCnt = lineCnt + 1;
        double s2nLINE = lines[loop1]{3} / lineNoise;
        msgLine[lineCnt] = "<li>Line S/N: " + dformat(s2nLINE,2);
        lineCnt = lineCnt + 1;
        if(sensitDegrad) {
            msgLine[lineCnt] = "<li><b>Warning:</b> the given line width, " + userWidth + " " + unitWidth + ", exceeds the instrumental FWHM; expect a loss of " + dformat(degrad,1) + " times in the LINE Signal-to-Noise ratio</li>";
            lineCnt = lineCnt + 1;
        }
        msgLine[lineCnt] = "<li>Total duration (SRC+REF+PACS overheads): " + trueObsTime + " [sec]";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<li>SRC+REF (no overheads): " + trueSrcTime + " [sec]";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "</ul>";
        lineCnt = lineCnt + 1;
    }
    // Display message
    PacsMessageCenter("SpecLine summary",lineCnt,msgLine);
}

// CVS comments  : $Id: PacsSpecRMS.txt,v 1.30 2007/10/26 15:40:39 dcesarsk Exp $
// Purpose       : 
//
// CUS author    : 
// Script file   : PacsSpecRMS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// tuple bigTuple 
//{{string,double[],double[],double[],double[]},
// {string,double[],double[],double[],double[]},
// {string,double[],double[],double[],double[]}}[]
//
// Each bigTuple's line is of the form "noiseArray"
//  {IDstring, noise array, wave array, CONT noise array, LINE noise array} 
//
// Description   : Computes expected RMS fluctuations given observing
// parameters, described by infoArray. For LineSpec use wave (in infoArray)
// at face value. For RangeSpec create a RMS vs Wave table from waveStart
// to waveEnd, sampled every sampRate [mic] and report max and min RMS in
// the interval. It is assumed that waveXX in infoArray is compatible with
// the wave range of table SPECnoise
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1  2-Sep-2005 DAC
// 0.2 28-sep-2005 Added one more element to infoArray 
// 0.3 26-apr-2006 Use new table from AlPog
//                 Get max/min parameters for CONT and LINE
//                 Array noiseWave contains CONT and LINE information
// 0.4 11-may-2006   - stepSize may be negative; use abs()
// 0.4.1 12-sep-2006 - reduced RMS step size to reduce size of interpolation
//                     table (reduced run time from 8 sec to less than 2 sec)
//                     (SPR-2324)
// 0.5   22-nov-2006 Removed debug_print
// 1.0   22-jan-2007 Fixed SPR-2521 (too low initial rmsC,rmsL)
// 2.0   26-jan-2007 After much discussions, count the WAIT=1 as a
//                   bonafide SKY readout (this is done in PacsLineSpec
//                   and PacsRangeSpec)
//                   Correct handling of FreqSwitch (I hope...)
//                   Dithering count per SPR-2841 (smallSrcDither)
// 2.1   14-feb-2007 Logic to deal with waveRef; added rangesEXT containing
//                   refWave; added aotID
//                   Solved SPR-2838 (use min(6800/stepSize,nbSteps)
//                   Use grating width as per order
//                   Generate messages explaining data obtained in order
//                   other than demanded order
// 2.2 26-feb-2007 Added orderSel from HSPOT
// 2.3 10-mar-2007 OrderSel includes now sed mode
// 3.0 13-mar-2007 Use bigTuple to convey plot data to HSPOT
// 3.1 16-apr-2007 Modify to access the correspondig SPECcontline table
// 4.0 25-apr-2007 Redefine ranges as defined by HSPOT
// 4.1  8-may-2007 SPR-3182: bound "free" data to band limits
// 4.2 10-may-2007 SPR-3186: Raster/wOFF repeat count
// 5.0 30-may-2007 SPR-3251: Simplified "extra" data logic
// 5.1 13-jun-2007 SPR-3307 Fewer decimals for "Info for line"
// 6.0 21-aug-2007 SPR-3505 Out-of-range interpolation (more on extra data
//                          logic)
// 6.1 23-oct-2007 Added obsType in call to PacsSpecAuxRMS 
// 6.2 24-oct-2007 Get nbOBS and nbOFF from caller
//                 Added above to PacsSpecAuxRMS
// 6.3  4-jun-2009 DAC Adapted FreqSwitch message to ABBA case
// 6.3.1 5-jun-2009 DAC Finer tuning due to changed confOBCP contents
// 7.0 01-dec-2009 VD SCR PHS-1272
// 8.0 07-dec-2009 VD PHS-1282
// 9.0 18-jan-2010 VD PHS-1285 SED only!
// 10.0 21-jan-2010 VD PHS-1302
// 11.0 08-feb-2010 VD PHS-1308 WS needs nbNods to be taken into account
// 12.0 09-feb-2010 VD PHS-1320 !! SED infoArray size == 1 BUT nbRanges >= 1
// 13.0 19-mar-2010 VD PHS-1369 !! R1 range vs ref Wave in B's !!
//                              modify input Params in SpecAuxRMS_tmp to accpet orderSel as indicator for filter A 
// 14.0 21-apr-2010 VD PHS-1385 : it is NOT WS.... it is chopNod without NOD
// 15.0 28-apr-2010 VD PHS-1388 rasterNoOff instead of rasterOff 
// 16.0 03-may-2010 VD PHS-1393 order23 indeed
// 17.0 05-may-2010 VD PHS-1385 cont'd
// 18.0 07-may-2010 VD merge oder23 and unchopped Line Scan
// 
{{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] procedure PacsSpecRMS_tmp {
    /* aotID                                                                  */
    string aotID = "RANGE" in ["RANGE","LINE"];
    /* orderSel                                                               */
    string orderSel = "order2";
    /* infoArray tuple (for SLEW,OBS,AOT and per wavelength)                  */
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}]; // Tuple from Obs module
    /* rangeSPOT (the sorted version)                                         */
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [{"",0.0,0.0,0,0.0,0.0,0.0,"","",0.0}];
    /* Grating dithering */
    {double,double}[] infoRangeSed = [{0.0,0.0}];
    /* confOBCP (per wavelength)                                              */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* nbOBS and nbOFF                                                         */
    int nbOBS = 1;
    int nbOFF = 0;
    int[] gratScanObsTime = [1];
    bool verbose = false;
}{
    // Data used here is to be found in
    // infoArray[1]{0}{0}   : PointReq information (ex. SmSrcDither, RasterOFF)
    // infoArray[1]{0}{3}   : Number of lines to be observed
    // infoArray[1]{0}{1}   : Integration time per plateau
    // infoArray[1]{0}{4}   : Number of nod cycles
    // infoArray[1]{1}[]{0} : Starting wave for line []
    // infoArray[1]{1}[]{1} : Ending wave for line []
    // infoArray[1]{1}[]{2} : Grating order for line []
    // infoArray[1]{1}[]{3} : Grating step for line []
    // infoArray[1]{1}[]{4} : Number of grating steps for line []
    // infoArray[2]{0}{0}   : OBCP information (ex. FreqSwitch)
    // infoArray[2]{0}{3}   : Raster "m" size
    // infoArray[2]{0}{4}   : Raster "n" size
    // infoArray[2]{0}{5}   : Raster repeat factor in raster/wOFF
    // confOBCP[]{0}        : Number up/down, nb SRC/CS in FreqSwitch for line []
    // confOBCP[]{3}        : Number SRC/REF for line []
    // confOBCP[]{4}        : Number readouts-ramps/plateau for line []
    // confOBCP[]{7}        : Dither count (FreqSwitch) for line []
    // Define return array
    // Array noiseWave[nbLines][8] used to contain: 
    //    noiseWave[lineNb][BwlC,BrC,WwlC,WrC,BwlL,BrL,WwlL,WrL]
    // where B: best, W: worst, wl: wavelength, r: RMS, C: continuum, L: line
    // Will add three more elements refWave, rmsCont, rmsLine (RANGE)
    // NOTE: NoiseWave is no longer used; its content is now in 1st
    //       array of tuple noiseArrayx 
    // Define tuples to be used below
    // Each noiseArray contains
    // - string arrayID
    // - double[] "noiseWave" (the "historical" noiseWave)
    // - double[] wave array
    // - double[] CONT noise
    // - double[] LINE noise
    {string,double[],double[],double[],double[]} noiseArray0 = {"undefined",[0.0],[0.0],[0.0],[0.0]};
    {string,double[],double[],double[],double[]} noiseArray1 = {"undefined",[0.0],[0.0],[0.0],[0.0]};
    {string,double[],double[],double[],double[]} noiseArray2 = {"undefined",[0.0],[0.0],[0.0],[0.0]};
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = [{noiseArray0,noiseArray1,noiseArray2}];
    // Number of lines observed
    if(orderSel == "sedb2b" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        int nbLines = 1;
    } else {
        nbLines = infoArray[1]{0}{3};
    }
    // The logic to estimate the data one gets for free (there are two arrays)
    // needs to know whether the current observations are performed with filter
    // "POS A" or "POS B" (fltPos=3 or fltPos=2). Only HSPOT knows this...
    int fltPos = 0;
    if(orderSel == "order2" || orderSel == "sed2" || orderSel == "sedb2b") {
        fltPos = 2;
    }
    // PHS-1393
    if(orderSel == "order3" || orderSel == "order23" || orderSel == "sed3" || orderSel == "sed4" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        fltPos = 3;
    }
    ///////////////// Per line loop //////////////////////////////
    for(int loop0 = 0 .. nbLines - 1) {
        //   Just for checks during script development
        if(verbose) {
            debug_print("RMS:PointReq: " + infoArray[1]{0}{0});
            debug_print("RMS:OBCP    : " + infoArray[2]{0}{0});
            debug_print("RMS:Wave from:to " + infoArray[1]{1}[loop0]{0} + ":" + infoArray[1]{1}[loop0]{1} + " [mic]");
            debug_print("RMS:Grat Order/StepSize/NbSteps " + infoArray[1]{1}[loop0]{2} + "/" + infoArray[1]{1}[loop0]{3} + "/" + infoArray[1]{1}[loop0]{4});
        }
        // Next section deals with estimating the "on-sky" time per resolution element
        // and per (same) sky area
        // Spectral lines can be seen several times as they move across the 
        // "wavelength" pixels
        // How many times a line feature has been seen
        // Get actual grating width (i.e. nbSteps = 16 pixels)
        string key = "" + infoArray[1]{1}[loop0]{2};
        double gratWidth = double(ilookup("SPEC_BAND_params",key,"GRAT_WDTH"));
        if(verbose) {
            debug_print("RMS:GratWdth: " + gratWidth + " steps");
        }
        // In FreqSwitch mode the parameters are somehow different 
        // Useful variable for freqSwitch
        bool freqSwitch = false;
        bool stare = false;
        debug_print("infoArray: " + infoArray[2]{0}{0});
        if(infoArray[2]{0}{0} == "FreqSwitch" || infoArray[2]{0}{0} == "GratScanNoChop") {
            if(aotID == "LINE") {
                freqSwitch = true;
            }
        }
        if(aotID == "RANGE") {
            if(infoArray[1]{0}{0} == "RasterNoOFF") {
                stare = true;
            } else {
                if(!freqSwitch && infoArray[2]{0}{0} == "GratScanNoChop") {
                    stare = true;
                }
            }
        }
        //      howMany is the number of times the given wavelength is seen by other pixels other
        // //no stare
        if(freqSwitch) {
            double howMany = 1.0;
        } else {
            //          Case of step size=0 (PV single grating AOT)
            howMany = gratWidth / (0.01 + abs(double(infoArray[1]{1}[loop0]{3})));
            //          SPR-2838: howMany cannot be larger than the number of grating steps
            if(howMany > double(infoArray[1]{1}[loop0]{4})) {
                howMany = double(infoArray[1]{1}[loop0]{4});
                if(verbose) {
                    debug_print("RMS:Reduced howMany to NbSteps");
                }
            }
        }
        // Integration time not considering spatial redundancy - i.e. seeing again the source during
        // a scan - nor wavelength redundancy - i.e. the same wavelength seen by other pixels at any grating
        // position) 
        //      intTimePlateau x NbSrcRef x howMany x nbNods x 2*up_dn x dithCount x Nbrepeat
        //      Number of nods (OBS)
        int nbNodCycles = infoArray[1]{0}{4};
        //      Nb of "pointings" for nbNodCycles
        int nbNods = 2 * nbNodCycles;
        if(nbNods == 0) {
            nbNods = 1;
        }
        int nbUpDn = 2 * confOBCP[loop0 + 1]{0};
        //      In FreqSwtch, below counts the number of SRC-CS cycles
        int nbSRC_REF = confOBCP[loop0 + 1]{3};
        //PHS-1385
        if(nbSRC_REF == 0) {
            nbSRC_REF = 1;
        }
        //      dithCntFreqSwtch introduced for FreqSwitch, otherwise is unity
        int dithCntFreqSwtch = 1;
        //      dithCntSmSrc introduced for small source w/dithering, otherwise is unity
        int dithCntSmSrc = 1;
        if(infoArray[1]{0}{0} == "SmSrcDither") {
            //          The source is seen at each of the m X n raster points
            int m = infoArray[2]{0}{3};
            int n = infoArray[2]{0}{4};
            dithCntSmSrc = m * n;
        }
        //      In FreqSwitch mode the parameters are somehow different
        // no stare
        if(freqSwitch) {
            //          confOBCP{0} counts the number of Up/Dn ABBA-ABBA cycles (P1UpDn)
            nbUpDn = confOBCP[loop0 + 1]{0};
            //          confOBCP{2} counts the number of ABBA setings (P4ABBA)
            int nbABBA = confOBCP[loop0 + 1]{2};
            //          The line is always in sight (Line Ref Ref Line) since Ref is Line displaced
            //          by a few pixels. Hence line is seen 4 times (see singleIntTime below)
            //          The ABBA loop is repeated dithCntFreqSwtch times
            dithCntFreqSwtch = confOBCP[loop0 + 1]{7};
            if(verbose) {
                debug_print("dithCntFreqSwitch: " + dithCntFreqSwtch);
            }
        }
        //      If Raster/w OFF, take into account the number of repetions
        int nbRepeat = 1;
        if(infoArray[1]{0}{0} == "RasterNoOFF" || stare) {
            nbRepeat = infoArray[2]{0}{5};
        } else {
            if(orderSel == "sedb2b" || orderSel == "sedb2a" || orderSel == "sedb3a") {
                nbRepeat = length(infoRangeSed);
            }
        }
        //      infoArray[1]{0}{1} is the integration time per plateau
        double singleIntTime = double(nbSRC_REF * nbNods * nbUpDn * nbRepeat) * infoArray[1]{0}{1};
        if(stare) {
            singleIntTime = double(nbUpDn * nbNods * nbRepeat) * infoArray[1]{0}{1};
            if(verbose) {
                debug_print("I am  here:");
                debug_print("nbUpDn: " + nbUpDn);
                debug_print("nbNods: " + nbNods);
                debug_print("nbRepeat: " + nbRepeat);
            }
        }
        //      Another special case
        // added nbNodCycles (no nods) as needs PHS-1308
        // //no stare
        if(freqSwitch) {
            singleIntTime = double(2 * nbUpDn * dithCntFreqSwtch * nbABBA * 4 * nbNodCycles) * infoArray[1]{0}{1};
            if(verbose) {
                debug_print("nbUpDn: " + nbUpDn + " / nbABBA: " + nbABBA + " / infoArray: " + infoArray[1]{0}{1});
                debug_print("singleIntTime switch: " + singleIntTime);
            }
        }
        double intTime = double(dithCntSmSrc) * howMany * singleIntTime;
        // Another exception for scan mode
        if(infoArray[1]{0}{0} == "ScanChopNoNod") {
            intTime = infoArray[1]{0}{1};
        }
        //   Wavelength span (needed below, but useful here for message)
        double span = abs(infoArray[1]{1}[loop0]{0} - infoArray[1]{1}[loop0]{1});
        //   Logic to show "extra" data, i.e. at different order than demanded
        //   - If observing in order=1 (with 2), the user gets for free order=2 data 
        //   - If observing in order=1 (with 3), the user gets for free some order=3 
        //     data if lambda>167 microns AND the short  wavelength part of order=2 
        //     (which falls inside POS B bandpass) if lambda < 142. For lambda 
        //     167 < lambda < 142, there is no "free" data
        //   - If observing at order=2 or order=3, user gets for free order=1
        //
        //   Try to code all this.. Current logic is as follows:
        //   For each Order/Filter combination see if the expected extra data is
        //   entirely out of filter bandpass. If yes, then there is no extra data; else
        //   place extra data within filter bandpass
        //   Current line is being observed at order
        int currOrder = infoArray[1]{1}[loop0]{2};
        if(verbose) {
            debug_print("currOrder: " + currOrder);
        }
        //   Code currOrder as orderN
        string orderCurr = "order" + currOrder;
        // "sed4" is a special case
        if(orderSel == "sed4" || orderSel == "sedb2a") {
            orderCurr = "order23";
        }
        //   Nominal and extra data will be labeled with arrayID
        string arrayID = "ToBeFilledBelow";
        //   Order 1 needs no filter... so we always see data in order 1. What other
        //   order do we see (where is filter?)
        //
        //   Useful variables: low and high user defined range
        double loLam = infoArray[1]{1}[loop0]{0};
        double hiLam = infoArray[1]{1}[loop0]{1};
        // Get boundaries of filters
        double loLam1 = dlookup("SPEC_BAND_params","1","BLU");
        double hiLam1 = dlookup("SPEC_BAND_params","1","RED");
        double loLam2 = dlookup("SPEC_BAND_params","2","BLU");
        double hiLam2 = dlookup("SPEC_BAND_params","2","RED");
        double loLam23 = dlookup("SPEC_BAND_params","23","BLU");
        double hiLam23 = dlookup("SPEC_BAND_params","23","RED");
        double loLam3 = dlookup("SPEC_BAND_params","3","BLU");
        double hiLam3 = dlookup("SPEC_BAND_params","3","RED");
        // SPR-3251 Completely new logic
        //
        // Define "cross over" wavelengths, i.e. wavelength in order1 such that 2nd 
        // order falls outside filter B into filter A
        double wave1into2 = 2.0 * loLam2;
        // and 1st order grating position corresponds to in-band 3rd order
        double wave1into3 = 3.0 * loLam3;
        // Following logic creates "extra" data, i.e. data user gets for "free"
        // Data labeled xSomething is regular order seen with tje corresponding
        // filter (i.e. 2nd with filter B; 3rd with filter A)
        // Data labeled xxSomething is short wavelength 2nd order seen with 3rd
        // order filter; the so called "extended" emission 
        // Null arrays imply there is no "free" data
        double xWaveLO = 0.0;
        double xWaveHI = 0.0;
        double xxWaveLO = 0.0;
        double xxWaveHI = 0.0;
        // Order 1 scanning is the most complex since the "free" data depends on filter
        // position
        if(currOrder == 1) {
            // Filter at POS B
            if(fltPos == 2) {
                arrayID = "order2";
                // When filter is at order 2 (POS B), all order=1 grating steps
                // map to visible order=2 wavelengths, except 
                //  - hiLam shorter than wave1into2 (range is too "blue")
                //  - loLam greater than 2*hiLam2   (range is too "red")
                if(hiLam <= wave1into2 || loLam >= 2.0 * hiLam2) {
                    //               Whole band is outside filter B
                    xWaveLO = 0.0;
                    xWaveHI = 0.0;
                } else {
                    arrayID = "order2";
                    //               A priori we see 1/2 wavelength
                    xWaveLO = loLam / 2.0;
                    xWaveHI = hiLam / 2.0;
                    //               But within bandpass limits
                    if(xWaveHI > hiLam2) {
                        xWaveHI = hiLam2;
                    }
                    if(xWaveLO < loLam2) {
                        xWaveLO = loLam2;
                    }
                }
            }
            // Filter at POS A
            //       This is the most complex case since we may also see order 2 light
            if(fltPos == 3) {
                if(orderCurr == "order23") {
                    arrayID = "order23";
                } else {
                    arrayID = "order3";
                }
                // Short wave filter (order 3, POS A), some order=1 grating steps
                // map to "visible" order=2 wavelengths, except 
                // - hiLam shorter than 2*loLam23 (range is too "blue")
                // - loLam greater than 2*hiLam23 (range is too "red")
                if(hiLam <= 2.0 * loLam23 || loLam >= 2.0 * hiLam23) {
                    // Whole band is outside filter A bandpass
                    xxWaveLO = 0.0;
                    xxWaveHI = 0.0;
                } else {
                    // Short wave second order
                    xxWaveLO = loLam / 2.0;
                    xxWaveHI = hiLam / 2.0;
                    // But within "extended" bandpass limits 
                    // SPR-3505: corrected band boundaries:xxLam3 should be xxLam23
                    if(xxWaveHI > hiLam23) {
                        xxWaveHI = hiLam23;
                    }
                    if(xxWaveLO < loLam23) {
                        xxWaveLO = loLam23;
                    }
                }
                // Some order=1 grating steps map to "visible" order=3 wavelengths, except 
                // - hiLam shorter than wave1into3 (range is too "blue")
                // - loLam greater than 3*hiLam3   (range is too "red")
                if(hiLam <= 3.0 * loLam3 || loLam >= 3.0 * hiLam3) {
                    // Whole band is outside filter A
                    xWaveLO = 0.0;
                    xWaveHI = 0.0;
                } else {
                    // Short wave 3rd order
                    xWaveLO = loLam / 3.0;
                    xWaveHI = hiLam / 3.0;
                    // But within bandpass limits
                    if(xWaveHI > hiLam3) {
                        xWaveHI = hiLam3;
                    }
                    if(xWaveLO < loLam3) {
                        xWaveLO = loLam3;
                    }
                }
            }
        }
        //   When grating scans within order 2 and 3 ranges, all steps map to visible
        //   lines at order 1
        //   If we are in order=2 we see order=1 for free
        // PHS-1285 Here comes in infoRangeSed and grating positions to "dither red free range"
        string xRan = "";
        if(currOrder == 2) {
            arrayID = "order1";
            if(orderSel == "sedb2b") {
                // keeping xRan for history
                xRan = "b2bLR1";
                xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                // xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
            } else {
                if(orderSel == "sedb2a") {
                    xRan = "b2aSR1";
                    xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                    //	       xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                    xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                } else {
                    if(orderSel == "sedb3a") {
                        xRan = "b3aLR1";
                        xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                        //		  xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                        xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                    } else {
                        xWaveLO = 2.0 * loLam;
                        xWaveHI = 2.0 * hiLam;
                    }
                }
            }
            //      It may fall completely outside bandpass	
            if(xWaveLO >= hiLam1) {
                xWaveLO = 0.0;
                xWaveHI = 0.0;
            } else {
                //          Within filter boundaries
                if(xWaveHI > hiLam1) {
                    xWaveHI = hiLam1;
                }
                if(xWaveLO < loLam1) {
                    xWaveLO = loLam1;
                }
            }
        }
        //   If we are in order=3 we alse see order=1 for free
        if(currOrder == 3) {
            arrayID = "order1";
            if(orderSel == "sedb2b") {
                xRan = "b2bLR1";
                xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                //	    xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
            } else {
                if(orderSel == "sedb2a") {
                    xRan = "b2aSR1";
                    xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                    //	       xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                    xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                } else {
                    if(orderSel == "sedb3a") {
                        xRan = "b3aLR1";
                        xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                        //		  xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                        xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                    } else {
                        xWaveLO = 3.0 * loLam;
                        xWaveHI = 3.0 * hiLam;
                    }
                }
            }
            //      It may fall completely outside bandpass	
            if(xWaveLO >= hiLam1) {
                xWaveLO = 0.0;
                xWaveHI = 0.0;
            } else {
                //          Within filter boundaries
                if(xWaveHI > hiLam1) {
                    xWaveHI = hiLam1;
                }
                if(xWaveLO < loLam1) {
                    xWaveLO = loLam1;
                }
            }
        }
        if(currOrder == 23) {
            arrayID = "order1";
            if(orderSel == "sedb2b") {
                xRan = "b2bLR1";
                xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                //	    xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
            } else {
                if(orderSel == "sedb2a") {
                    xRan = "b2aSR1";
                    xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                    //	       xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                    xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                } else {
                    if(orderSel == "sedb3a") {
                        xRan = "b3aLR1";
                        xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                        //		  xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                        xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                    } else {
                        xWaveLO = 2.0 * loLam;
                        xWaveHI = 2.0 * hiLam;
                    }
                }
            }
            //      It may fall completely outside bandpass	
            if(xWaveLO >= hiLam1) {
                xWaveLO = 0.0;
                xWaveHI = 0.0;
            } else {
                //          Within filter boundaries
                if(xWaveHI > hiLam1) {
                    xWaveHI = hiLam1;
                }
                if(xWaveLO < loLam1) {
                    xWaveLO = loLam1;
                }
            }
        }
        if(verbose) {
            debug_print("RMS:current order: " + currOrder);
            debug_print("RMS:fltPos: " + fltPos);
            debug_print("RMS:LoLam: " + loLam);
            debug_print("RMS:HiLam: " + hiLam);
            debug_print("RMS:ExtraLoLam: " + xWaveLO);
            debug_print("RMS:ExtraHiLam: " + xWaveHI);
            debug_print("RMS:ExxtraLoLam: " + xxWaveLO);
            debug_print("RMS:ExxtraHiLam: " + xxWaveHI);
            debug_print("RMS:Integration/plateau: " + infoArray[1]{0}{1} + " [sec]");
            debug_print("RMS:NbSRC_REF: " + nbSRC_REF + " times");
            debug_print("RMS:ditherCount (freqSwitch): " + dithCntFreqSwtch + " times");
            debug_print("RMS:ditherCount (small srce): " + dithCntSmSrc + " times");
            debug_print("RMS:NbUpDn/NbNods: " + nbUpDn + "/" + nbNods);
            debug_print("RMS:NbRepeat: " + nbRepeat);
            debug_print("RMS:intTime (one freq. switch, no dither) " + singleIntTime + " [sec]");
            debug_print("RMS:Wavelength span: " + dformat(span,2) + " [mic]");
            debug_print("RMS:Feature seen  " + howMany + " times");
            debug_print("RMS:Time for RMS estimate: " + intTime + " [sec]");
            debug_print("RMS:SRC/REF " + infoArray[1]{1}[loop0]{6} + "/" + infoArray[1]{1}[loop0]{7} + " [sec]");
        }
        bool superbla = true;
        if(superbla) {
            if(aotID == "RANGE") {
                message("<h3> Info for range " + infoArray[1]{1}[loop0]{0} + "/" + infoArray[1]{1}[loop0]{1} + " [&micro;m]</h3>");
            } else {
                message("<h3> Info for line " + dformat(infoArray[1]{1}[loop0]{0},2) + " [&micro;m]</h3>");
            }
            message("<ul><li>PointReq: " + infoArray[1]{0}{0} + "</li>");
            message("<li>OBCP    : " + infoArray[2]{0}{0} + "</li>");
            //      Next messages only for RANGE
            if(aotID == "RANGE") {
                message("<li>Wave from-to " + infoArray[1]{1}[loop0]{0} + "-" + infoArray[1]{1}[loop0]{1} + " [&micro;m]</li>");
                //         message("<li>Wavelength span: " + dformat(span,2) + " [&micro;m]</li>");
                //         Messages for "free" data
                if(xWaveLO != 0.0) {
                    message("<li><b>Free! </b> Your data will include wavelengths between " + dformat(xWaveLO,2) + " and " + dformat(xWaveHI,2));
                }
                if(xxWaveLO != 0.0) {
                    message("<li><b>Free! </b> Your data will include wavelengths between " + dformat(xxWaveLO,2) + " and " + dformat(xxWaveHI,2));
                }
            }
            if(freqSwitch) {
                message("<li>ABBA freqSwitch at grating order: " + infoArray[1]{1}[loop0]{2} + "</li>");
                message("<li>FreqSwitch dither: " + dithCntFreqSwtch + " wavelength steps</li>");
            } else {
                message("<li>Grat Order/StepSize/NbSteps " + infoArray[1]{1}[loop0]{2} + "/" + infoArray[1]{1}[loop0]{3} + "/" + infoArray[1]{1}[loop0]{4} + "</li>");
                message("<li>NbSRC_REF: " + nbSRC_REF + " times</li>");
                message("<li>Spatial redundancy only for SmallSrc: " + dithCntSmSrc + " time(s)</li>");
            }
            message("<li>Number ramps/plateau (after synch): " + confOBCP[loop0 + 1]{4} + "</li>");
            message("<li>Integration time/plateau: " + dformat(infoArray[1]{0}{1},2) + " [sec]</li>");
            if(freqSwitch) {
                message("<li>Up/Dn ABBA loops/ABBA sets per loop: " + nbUpDn + "/" + nbABBA + "</li>");
            } else {
                message("<li>NbUpDn/NbNods/NbRepeat: " + nbUpDn + "/" + nbNods + "/" + nbRepeat + "</li>");
            }
            message("<li>Integration time per spectral and/or spatial resolution element::  " + dformat(singleIntTime,1) + " [sec]</li>");
            message("<li>Feature seen " + dformat(howMany,1) + " times (due to spatial or wavelength redundancy)</li>");
            message("<li>Integration time used to estimate RMS: " + dformat(intTime,1) + " [sec]</li>");
            message("<li>Global SRC/REF exposure: " + infoArray[1]{1}[loop0]{6} + "/" + infoArray[1]{1}[loop0]{7} + " [sec]</li></ul>");
        }
        //
        // We have now up to three wavelength ranges:
        // - nominal (user defined)        [loLam to hiLam]
        // - one "free" data array         [xWaveLO to xWaveHI]
        // - perhaps a 3rd "free" array    [xxWaveLO to xxWaveHI]
        //
        //   The reference wavelength
        if(aotID == "RANGE") {
            double waveRef = rangeSPOT[loop0]{9};
        }
        if(aotID == "LINE") {
            waveRef = infoArray[1]{1}[loop0]{0};
        }
        //   Create a table RMS vs Wave consisting of nbSamples entries
        //
        //   Create Wave arrays (remember we are inside the nbLines loop!!)
        //   Obs type for AuxRMS
        string obsType = "any";
        if(aotID == "RANGE") {
            // attention function of waveRef
            //	 if(orderSel == "sedb2b" || orderSel == "sedb2a" || orderSel == "sedb3a") {
            //	    if(waveRef >= 103.1) {
            //	       double[] waveArray = PacsSpecWaveArray(xWaveLO,xWaveHI,verbose);
            //	    } else {
            //	       waveArray = PacsSpecWaveArray(loLam,hiLam,verbose);
            //	    }
            //	 } else {
            double[] waveArray = PacsSpecWaveArray(loLam,hiLam,verbose);
            //	 }
            //        Given wavelengths are always "nominal"
            noiseArray0 = PacsSpecAuxRMS_tmp(aotID,orderCurr,orderSel,waveArray,waveRef,intTime,obsType,nbOBS,nbOFF,gratScanObsTime[loop0],verbose);
            //      Null Wave arrays have xWaveLO = 0.0
            if(xWaveLO > 10.0) {
                waveArray = PacsSpecWaveArray(xWaveLO,xWaveHI,verbose);
                ///        if (verbose){debug_print("RMS:xWaveArray: " + waveArray);}
                //        xWave array comes from arrayID source; define waveRefX
                double waveRefX = (xWaveLO + xWaveHI) / 2.0;
                noiseArray1 = PacsSpecAuxRMS_tmp(aotID,arrayID,orderSel,waveArray,waveRefX,intTime,obsType,nbOBS,nbOFF,gratScanObsTime[loop0],verbose);
            }
            //      Null Wave arrays have xxWaveLO = 0.0
            if(xxWaveLO > 10.0) {
                //        xxWave array is always 2nd order, but special since it
                //        overlaps with 3rd order. Identify as order23 (order 2 overlapping
                //        with order 3)
                waveArray = PacsSpecWaveArray(xxWaveLO,xxWaveHI,verbose);
                ///          if (verbose){debug_print("RMS:xxWaveArray: " + waveArray);}
                waveRefX = (xxWaveLO + xxWaveHI) / 2.0;
                noiseArray2 = PacsSpecAuxRMS_tmp(aotID,"order23",orderSel,waveArray,waveRefX,intTime,obsType,nbOBS,nbOFF,gratScanObsTime[loop0],verbose);
            }
        }
        if(aotID == "LINE") {
            waveArray = [infoArray[1]{1}[loop0]{0}];
            //      Identify FreqSwitch
            obsType = infoArray[2]{0}{0};
            noiseArray0 = PacsSpecAuxRMS_tmp(aotID,orderCurr,orderSel,waveArray,waveRef,intTime,obsType,nbOBS,nbOFF,gratScanObsTime[loop0],verbose);
        }
        // For memory: bigTuple is thus defined
        //  {{string,double[],double[],double[],double[]},
        //   {string,double[],double[],double[],double[]},
        //   {string,double[],double[],double[],double[]}}[]
        //   bigTuple = [{noiseArray0, noiseArray1,noiseArray2}];
        bigTuple[loop0] = {noiseArray0,noiseArray1,noiseArray2};
        // End of nbLines loop
        //   Zero the noiseArrays (a null value is used elsewhere to assert there
        //   are no "free" ranges)
        noiseArray0 = {"",[0.0],[0.0],[0.0],[0.0]};
        noiseArray1 = {"",[0.0],[0.0],[0.0],[0.0]};
        noiseArray2 = {"",[0.0],[0.0],[0.0],[0.0]};
    }

    return bigTuple;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : HF
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 18-Jun-2009 initial version
//
obs PacsEng_DropOut_Diaghk_Setup {
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_Fil_Diaghk_Setup()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_DropOut_Diaghk_Setup();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Purpose       : returns KeyWaves given the OrderSel
//                 This version gives one KeyWave per represented order in
//                 UserWaves
//
// CUS author    : JDP
// Script file   : PacsSpecKeyWaves.txt 
//
// Input arguments
// type    name        Description
// string  orderSel    oder selection
//
// Return values
// Type         Description
// double []    Key wavelength associated with orderSel
// Description   : get Key Wave a function of orderSel from calU file
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 1.0 14-may-2008 created
//                 1.1 22-apr-2009 updated SPR 5447 
//                 added selection of Key as fucntion of requested refWL
//                 as function of filter and order positions
//                 1.2 14-sep-2009 VD PHS-1174 recover grat_keyWave in additon to keyWave 
//                 2.0 01-dec-2009 VD SCR PHS-1272
//                 3.0 06-may-2010 VD PHS-1393 order 23
{double,int} procedure PacsSpecKeyWaves_grat {
    string orderSel = "order2" in ["order1","order2","order3","order23","sed2","sed3","sed4","sedb2a","sedb2b","sedb3a"];
    double[] refWL = [60.0];
}{
    string calUFile = "KEY_WAVES";
    // Local variables
    double refWL1 = refWL[0];
    string order = "2";
    string keyWave = "KeyWave1";
    string grat_keyWave = "grat_KeyWave1";
    double waves = 0.0;
    int grat_waves = 497500;
    if(refWL1 <= 103.1) {
        if(orderSel == "order2" || orderSel == "sed2" || orderSel == "sedb2b") {
            order = "2";
            keyWave = "KeyWave1";
            grat_keyWave = "grat_KeyWave1";
        } else {
            if(orderSel == "order3" || orderSel == "order23" || orderSel == "sedb2a" || orderSel == "sedb3a") {
                order = "3";
                keyWave = "KeyWave1";
                grat_keyWave = "grat_KeyWave1";
            }
        }
    } else {
        if(refWL1 > 103.1) {
            if(orderSel == "order2" || orderSel == "sed2" || orderSel == "sedb2b") {
                order = "2";
                keyWave = "KeyWave2";
                grat_keyWave = "grat_KeyWave2";
            } else {
                if(orderSel == "order3" || orderSel == "order23" || orderSel == "sedb2a" || orderSel == "sedb3a") {
                    order = "3";
                    keyWave = "KeyWave2";
                    grat_keyWave = "grat_KeyWave2";
                }
            }
        }
    }
    if(orderSel == "order1" || orderSel == "sed3") {
        order = "1";
        keyWave = "KeyWave1";
        grat_keyWave = "grat_KeyWave1";
    } else {
        if(orderSel == "sed4") {
            order = "23";
            keyWave = "KeyWave1";
            grat_keyWave = "grat_KeyWave1";
        }
    }
    waves = dlookup(calUFile,order,keyWave);
    grat_waves = ilookup(calUFile,order,grat_keyWave);
    sync();

    return {waves,grat_waves};
}

// CVS comments  : $Id: PacsPhotSlewCal.txt,v 1.10 2008/05/06 13:34:53 vanessa Exp $ 
// Purpose       : Invoke a PACS calibration OBCP during slew to source;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsPhotSlewCal.txt 
//
// Input arguments
// Type                      Description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform AOT prologue and then OBCP #13.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 DAC  30-Nov-2005 (inspired by PacsSpecSlewCal)
// 0.2 DAC 20-sep-2006 Clean up leftovers from SPEC script 
// 0.3 DAC  6-dec-2006 Adapted to simpler PHOT_fltw_move
// 0.4 DAC 27-jun-2007 SPR-3339 Always move filter wheel
// 1.0 DAC 10-oct-2007 SCR-3628 Added arguments to call aot_prologue
// 1.1 JVP 28-apr-2008 ERROR in filter_id assignation: POS A is LW for the
//     	   	       photometer (remind POS A = SW for spectro)
// 1.2 DAC 20-may-2008 Moved FLTW move into DO_PROLOGUE section                
// 2.0 SCR 4431 VDO: implemetation of data_rates
int[] procedure PacsPhotSlewCal_DataRates {
    bool verbose = true; // Debug_print or not 
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,64,0,0,0,0,0,0,0}]; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,64,0,0,0,0,0,0,0}]; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]; // OBCP parameters
    bool doPROLOG = true; // Perform/don't AOT prologue
    string filter = "blue2"; // PHOT filter
}{
    if(doPROLOG) {
        data_rate(120.0);
    }
    // Array to collect OBCP times per line
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    // Table of filter wheel positions as per MIB
    // Actually originally not blue1 = SW = POS B, and blue2 = LW = POS A for
    // the photmeter
    if(filter == "blue1") {
        string filterID = "POS B";
    }
    if(filter == "blue2") {
        filterID = "POS A";
    }
    // Long sequence to "unpack" default values from tuples
    int gain_blu = confPHOTblu[0]{0};
    int comp_mode_blu = confPHOTblu[0]{3};
    int glitch_det_blu = confPHOTblu[0]{4};
    int nb_raw_blu = confPHOTblu[0]{6};
    int gain_red = confPHOTred[0]{0};
    int comp_mode_red = confPHOTred[0]{3};
    int glitch_det_red = confPHOTred[0]{4};
    int nb_raw_red = confPHOTred[0]{6};
    int nb_cycles_obs_cal = confOBCP[0]{0};
    int nb_SRC_REF = confOBCP[0]{3};
    int nb_rdouts_plateau = confOBCP[0]{4};
    int nb_CS1_CS2 = confOBCP[0]{5};
    int chop_pos_SRC = confOBCP[0]{12};
    int chop_pos_REF1 = confOBCP[0]{13};
    int chop_pos_REF2 = confOBCP[0]{14};
    int chop_def = confOBCP[0]{17};
    int detector = confOBCP[0]{18};
    int filterPOS = confOBCP[0]{19};
    if(gain_blu == 1 && gain_red == 1) {
        string set_gain = "LOW";
    } else {
        if(gain_blu == 0 || gain_red == 0) {
            set_gain = "HIGH";
        }
    }
    // Issue PHOT_aot_prologue if demanded
    if(doPROLOG) {
        totalDUREE = PHOT_aot_prologue(set_gain,comp_mode_blu,comp_mode_red,nb_raw_blu,nb_raw_red,verbose);
        // Turn the filter wheel
        int timeFLTW = PHOT_fltw_move(filterID);
        //  increment total duration and overheads
        totalDUREE[0] = totalDUREE[0] + timeFLTW;
        totalDUREE[4] = totalDUREE[4] + timeFLTW;
    }
    // Issue now OBCP4 for demanded filter
    // Table OBCP4params has parameter values for CAL using blue1 or blue2
    // Get params for demanded filter from OBCP4params
    string calNAME = "OBCP4params";
    // Table acces key is "cal1" or "cal2", corresponding to blue1 and blue2
    // respectively.
    string key = "cal1";
    if(filter == "blue2") {
        key = "cal2";
    }
    nb_cycles_obs_cal = ilookup(calNAME,key,"nb_cycles_obs_cal");
    nb_SRC_REF = ilookup(calNAME,key,"nb_SRC_REF");
    nb_rdouts_plateau = ilookup(calNAME,key,"nb_rdouts_plateau");
    nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    // Read CS positions from CHOPPERCSparams
    int pos_CS1 = ilookup("CHOPPERCSparams","PHOT","pos_CS1");
    int pos_CS2 = ilookup("CHOPPERCSparams","PHOT","pos_CS2");
    // Update OBCP[0] tuple with CAL-U values
    confOBCP[0]{0} = nb_cycles_obs_cal;
    confOBCP[0]{3} = nb_SRC_REF;
    confOBCP[0]{4} = nb_rdouts_plateau;
    confOBCP[0]{5} = nb_CS1_CS2;
    confOBCP[0]{15} = pos_CS1;
    confOBCP[0]{16} = pos_CS2;
    // Call now OBCP with derived parameters
    int[] dureeOBCP = OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,pos_CS1,pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
    if(verbose) {
        debug_print("*** SlewCal OBCP: " + confOBCP[0]);
        debug_print("*** SlewCal OBCP returns: " + dureeOBCP);
    }
    // Tally total durations
    for(int loop0 = 0 .. 4) {
        totalDUREE[loop0] = totalDUREE[loop0] + dureeOBCP[loop0];
    }
    if(verbose) {
        debug_print("***** SlewCal performed CAL: " + key + " requires " + totalDUREE[0] + " [sec]");
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return totalDUREE;
}

// Mission phase : Performance Verification Phase
//
// Purpose : Explore the time constant after flux change for a flux levels using the low gain
//
// Author : Koryo Okumura
//
// Version : Wed Jul 29 08:48:14 EDT 2009
//
// CUS script : mode PacsCal_Phot_bandpassDirect
//
// Argument :
//   int sideField = 7134; // Chopper angle for the FOV next to BB2
//   int chop_pos_CS2 = 21196; // Chopper angle for BB2
//   string biasTable = "BOLObias_standard_low"; // Bias table
//   string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//   string calBiasTable = "BOLObias_standard_low"; // Bias table used during calibration blocks
//   string calGain = "LOW" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "DIRECT" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//   int nLoops1 = 30; // number of CSs cycles during slew
//   int nLoops2 = 30; // number of CSs cycles during initial hold
//   int nLoops5 = 30; // number of CSs cycles during final hold
//   int nReadout_plateau = 16; // number of readouts per plateau
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description : OBS script to execute PacsCal_Phot_bandpassDirect
//
// Dependencies : Previously obtaind data at high gain (PCD req.1.1.1bis)
//
// Comments : generated by IA script : cus_PVph_timeCont()
//                     SCR PACS-1873
//
obs PacsCal_Phot_bandpassDirect {
    int sideField = 7134; // Chopper angle for the FOV next to BB2
    int chop_pos_CS2 = 21196; // Chopper angle for BB2
    string biasTable = "BOLObias_standard_low"; // Bias table
    string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    string calBiasTable = "BOLObias_standard_low"; // Bias table used during calibration blocks
    string calGain = "LOW" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "DIRECT" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 16; // number of readouts per plateau
    bool verbose = true;
}{
    // Bus configuration for the Burst mode (7)
    busconfig (7);
    int nRdts = readouts_plateau - 1;
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = 0;
    int timeChgBias0 = duration(PHOT_change_biases(biasTable,"NO_CHANGE","NO_CHANGE"));
    int timeCal3CPR1 = duration(Pacs_OBCP_chopped_photometry2(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    //Minimum slew time
    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT","LOW"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT",calGain));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"LOW"));
    }
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
    }
    int tslewmin = timeOBSID + timeChgBias + timeCal3CPR1;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeChgBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_bandpassDirect(biasTable,gain,sideField,chop_pos_CS2));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            // No biases setting here because nothing changes
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            //  Call the Phot_bandpassDirect
            //************************************
            Phot_bandpassDirect(biasTable,gain,sideField,chop_pos_CS2);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// $Id
// Missionphase		: PACS PV Phase
//
// Purpose :		 : Invoke a PACS calibration OBCP during slew to source;
//                 	 leave PACS ready to start observations once in source
// Author		 : VDP
//
// Arguments	�	:
//
// Prerequisite 	: PACS does not need to be on nor setup for spectroscopy
//
// Description		: Perform AOT prologue and then OBCP #27 and then AO prologue.
//
// Comments		:
//
// Version		: 1.0
// 
// History		: 0.1 Using example from PacsCal_WaveCalChop
// 			: 1.0 perform calibrations during slew and 
//    	  	       	   then a wavelength calibration on source
//			   usng NOD=1 and Choping
//			  2.0 PacsCal version for PV
obs PacsCal_PacsSpecSlewCal {
    /* Needed variables to call PacsSpecSlewCal */
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int grat_pos = 500000; // grating start position for scan
    int grat_time = 0; // tiem for grating to move to start position [msec]
    int nb_raw_red = 3; // number of red pixels
    int nb_raw_blu = 3; // number of blue pixels
    int comp_mode_blu = 16; // compression mode for blue detector
    int comp_mode_red = 16; // compression mode for red detector
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    int nnod = 1; // number of nods (AB or BA)
    double chopthrow = 30.0; // chop/nod throw
    int order = 2;
    string confTable = "normal" in ["normal","bright"];
    bool verbose = true;
}{
    // compiting time for slw / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Verification for grating and chopper hard limits
    int[] gratpos = [0];
    Pacs_HardLimitsCheck(gratpos,chopthrow);
    // Calibration time during slew
    // SPEC parameters for BLU and RED               
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    string throw = "small";
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = PacsSpecDefaults(throw,confTable,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    confSPECblu[0]{3} = comp_mode_blu;
    confSPECred[0]{3} = comp_mode_red;
    confSPECblu[0]{6} = nb_raw_blu;
    confSPECred[0]{6} = nb_raw_red;
    confOBCP[0]{8} = grat_pos;
    confOBCP[0]{9} = grat_time;
    // frstLstGratPos is the last position for the grating after the Cals done
    // during Slew time... must be same as observations start position: grat_pos   
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    // "N/A" in string because of indexing 0,1,2,3
    string[] choix = ["N/A","order1","order2","order3"];
    string order_str = "" + order;
    double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    double[] keyWAVE = [keyWAVE1];
    //Initial hold
    int tih = duration(WriteOBSID($OBSID));
    int tslewmin = 0;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int grat_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int tepilog = duration(SPEC_aot_epilogue(grat_pos,grat_def,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]));
    if(verbose) {
        debug_print("Duration of WaveCalChop" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    debug_print("ts: " + ts);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            int tNOW = time();
            WriteOBSID($OBSID);
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]);
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 5) {
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold starts at :" + tNOW + " sec");
                    }
                    SPEC_aot_epilogue(grat_pos,grat_def,verbose);
                    WriteEndID();
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold ends at :" + tNOW + " sec");
                    }
                }
            }
        }
    }
    //    }
    // End of Observation
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version	: 1.0
// History       : 0.1 22-mar-2006
// History       : 1.0  11-feb-2008  Converted into PV script by VDP
//
obs PacsEng_Spec_Fil_nturns {
    /* Needed variables to call PacsEng_Spec_Fil_nturns                        */
    int num_turns = 3; // number of 360 deg turns
    int backward_toA = 0; // direction of FW rotation towards POS A : 0 forward; 1 backward
    int backward_toB = 0; // direction of FW rotation towards POS B : 0 forward; 1 backward
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Fil_nturns                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Fil_nturns(num_turns,backward_toA,backward_toB)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Fil_nturns(num_turns,backward_toA,backward_toB);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_lowGainBiasDirect6
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//  int nLoops2 = 30; // number of CSs cycles during initial hold
//  int nLoops5 = 30; // number of CSs cycles during final hold
//  bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_lowGainBiasDirect6
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//
// Version : Fri Apr 24 19:30:21 EST 2009
//
obs PacsCal_Phot_lowGainBiasDirect6 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(endBiasTable,"DIRECT","LOW"));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    //Minimum slew time
    int tslewmin = timeOBSID + timeSetBias;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeSetBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_lowGainBiasDirect6(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            // Call the Phot_lowGainBiasDirect6
            //************************************
            Phot_lowGainBiasDirect6(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 05-Jul-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_Fltw_Mec_Setup {
    /* No variables to call PacsEng_Phot_Fltw_Mec_Setup                        */
    /*  string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_Fltw_Mec_Setup                    */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_phot_fltw()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_phot_fltw();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_lowGainBiasDirect5
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//  int nLoops2 = 30; // number of CSs cycles during initial hold
//  int nLoops5 = 30; // number of CSs cycles during final hold
//  bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_lowGainBiasDirect5
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//
// Version : Fri Apr 24 19:30:21 EST 2009
//
obs PacsCal_Phot_lowGainBiasDirect5 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(endBiasTable,"DIRECT","LOW"));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    //Minimum slew time
    int tslewmin = timeOBSID + timeSetBias;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeSetBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_lowGainBiasDirect5(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            // Call the Phot_lowGainBiasDirect5
            //************************************
            Phot_lowGainBiasDirect5(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : Pierre Royer
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// Version	 : 2.0
// History       : 1.0 29-Jul-2007
// History       : 2.0  11-feb-2008  Converted into Eng OBS by VDP
//
//
//
obs PacsEng_CONF_grating_IST {
    /* Needed variables to call PacsEng_CONF_grating_IST                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_CONF_grating_IST                     */
}{
    string calUrow = "IST";
    string calUname = "CONFGrat";
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_grating(calUname,calUrow)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_grating(calUname,calUrow);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Purpose       : Wavelength calibration and instrumental profile
// Author        : HF
//
// Arguments     :
// string fltPOS            Filter wheel position (0="POS A", 1="POS B")
// int grat_start           Grating start position for scan
// int grat_stepsize        Grating step size
// int grat_numsteps        Number of grating steps in one direction
// int grat_numramps        Number of ramps per grating position
// int chop_def             Chopper position during grating scan
// int nb_rdout_ramp        Number of readouts per ramp
// int num_updown           Number of grating updown scans
// int grat_def             Position of grating after the scan
// int capa_red             Red capacitor
// int capa_blu             Blue capacitor
// double bias_r_blu        Bias "r" blue
// double bias_r_red        Bias "r" red
// double bias_d_blu        Bias "d" blue
// double bias_d_red        Bias "d" red
// int nb_samp_subramp_blu  Nb of blue samples per sub-ramp
// int nb_samp_subramp_red  Nb of red samples per sub-ramp
//
// Prerequisite  : PACS must be on and configured for spectroscopy
//
// Description   : Uses OBCP28 for executing a parameterized scan of any length,
//                 stepsize etc. Represents a generic non-chopped grating scan               :
// Comments      :
//
// Version       : 2.0
// History       : 0.1 10-sep-2007 Converted into Eng OBS by DAC
//                 0.2 14-jan-2008 DAC Added bias_r... input variables
//                 0.3 15-jan-2008 Renamed WaveCalProc to WaveCalNoChop
//                                 Renamed this module to PacsEng_WaveCalNoChop 
//                 1.0 15-feb-2008 DAC Use FinePointing mode instead of dummy
//                                     Renamed to PacsCal_xxxx
//                 1.1 DAC Will have to add SPEC_aot_epilogue to "final hold"
//                         and PacsSpecSlewCal to "slew" phase.           
//                 2.0 26-sep-2008 VDP: implemented PacsSpecSlewCal
//		       	    	   added SPEC_aot_epilogue to final_hold
//			    	   transfered WriteOBSID and WriteEndID from Procedure back 
//			    	   main module and added to Slew and final_hold
//				   Implemented: within WriteOBSID and Prologues/Epilogues data_rate()
//		   3.0 17-dec-2008: VD fix VERY important BUG: get PacsSpecDefaults to
//		       		    run properly PacsSpecSlewCal (to set
//				    properly detector/comp_mode and Chop_def
//		   4.0 19-feb-2009: VD. copied from PacsCal as PacsEng: i.e.
//		       		    no_pointing, removed pointing parameters
//		   5.0 22-apr-2009 VD SPR 5447
//		   6.0 23-apr-2009 VD SPR 6482
//                 7.0 22-jun-2009 HF, SCR 7157
//                 8.0 14-sep-2009 VD PHS-1173
//
obs PacsEng_WaveCalNoChop {
    /* Needed variables to call WaveCalNoChop */
    string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B"
    int order = 2; // Order selection
    int grat_start = 500000; // grating start position for scan
    int grat_stepsize = 200; // grating step size
    int grat_numsteps = 50; // number of grating steps in one direction
    int grat_numramps = 3; // number of ramps per grating position
    int chop_def = 648; // chopper position during grating scan
    int nb_rdout_ramp = 64; // number of readouts per ramp
    int num_updown = 1; // number of grating updown scans
    int grat_def = 496000; // position of grating after the scan
    int capa_red = 12; // Red capacitor
    int capa_blu = 12; // Blue capacitor
    double bias_r_blu = 0.0101; // Bias "r" blue
    double bias_r_red = 0.0101; // Bias "r" red
    double bias_d_blu = 0.19801; // Bias "d" blue
    double bias_d_red = 0.06901; // Bias "d" red
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp    
    int comp_mode_blu = 16; // compression mode for blue detector
    int comp_mode_red = 16; // compression mode for red detector
    int nb_raw_red = 3; // number of red pixels
    int nb_raw_blu = 3; // number of blue pixels
    bool verbose = true;
}{
    // compiting time for slw / calibration during slew time and others
    // Set OBSID
    int tobsid = duration(WriteOBSID($OBSID));
    // SPEC parameters for BLU and RED               
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    string throwUsage = "small";
    string extraConf = "normal";
    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // frstLstGratPos is the last position for the grating after the Cals done
    // during Slew time... must be same as observations start position: grat_pos   
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    // "N/A" in string because of indexing 0,1,2,3
    string[] choix = ["N/A","order1","order2","order3","sed4"];
    string order_str = "order" + order;
    //    if(choix[order] != "order1") {
    //        double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //    double keyWL = PacsSpecKeyWaves(order_str);
    //    double[] keyWAVE = [keyWL];
    double[] keyWAVE = [75.0];
    debug_print("choix[" + order + "]:" + choix[order]);
    debug_print("fltPOS:" + fltPOS);
    if(choix[order] == "order3" && fltPOS == "POS B") {
        error("Filter B and order 3 are not compatible");
    }
    if(choix[order] == "order1" && fltPOS == "POS A") {
        keyWAVE = [180.0];
    }
    if(choix[order] == "order1" && fltPOS == "POS B") {
        keyWAVE = [150.0];
    }
    if(choix[order] == "order2" && fltPOS == "POS B") {
        keyWAVE = [75.0];
    }
    if(choix[order] == "order3" && fltPOS == "POS A") {
        keyWAVE = [60.0];
    }
    // this is for extended Blue
    if(choix[order] == "order2" && fltPOS == "POS A") {
        keyWAVE = [60.0];
        choix[order] = "sed4";
    }
    int tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]));
    int tOBSID = duration(WriteOBSID($OBSID));
    int tepilogue = duration(SPEC_aot_epilogue(grat_start,grat_def,verbose));
    int tEndID = duration(WriteEndID());
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    //Minimum slew time
    int tslewmin = tOBSID + tpacsSlewCal;
    //Initial hold
    int tih = 0;
    //Final hold
    int tfh = tepilogue + tEndID;
    //Duration of "stable" pointing
    int tp = duration(WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_def,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red));
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            int tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]);
        } else {
            if(state[0] == 3) {
                //      Call the WaveCal procedure
                WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_def,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red);
            } else {
                if(state[0] == 5) {
                    SPEC_aot_epilogue(grat_start,grat_def,verbose);
                    WriteEndID();
                }
            }
        }
    }
}

// Missionphase  : CQM
//
// Purpose       : CONFigure the servo grating loop using parameters read from
//                 a CAL-U file
//                  
// Author        : Diego A. Cesarsky / Pierre Royer
// CUS script    : Diego A. Cesarsky / Pierre Royer
//
// Arguments     : This version reads the ROW calUrow of the -calUname CAL-U file
// string calUname  Name of the CAL-U table
// string calUrow   Name of the ROW containing the desired controler params
//
// Description   : Reads grating controler parameters from a named row (viz.
// IMTwarm, IMTcold, ORBpv1, etc.) of a CAL-U table (default is "GRATconfig"),
// 
// Dependencies  : 
//
// Preconditions :
//
// Comments      : 
//
// Version       : 0.2
// History       : 0.1 26-Jan-2006 Creation by DAC
//		   0.2 12-Jun-2006 Read Rows instead of columns
//                 0.3 13-jun-2006 Renamed CALU table
//                 1.0 19-11-2008 Update wrt fm_ist_cus_copy => allows for possibility of frequency filter in the controller
//               :
procedure PACS_Spec_Gra_Set_Ctrl_Par {
    string calUname = "CONFGrat"; // Calibration Table
    string calUrow = "FMILT"; // Row in table = Instrument Configuration
    int homing_mode_rate = 1 in [0,1]; // 0 : rate read from calibration table; 1 : rate forced = 3 (homing request)
}{
    // Read the demanded column of the given table.
    // Rows 0 to 8
    int word0 = ilookup(calUname,calUrow,"Kp");
    int word1 = ilookup(calUname,calUrow,"Ki");
    int word2 = ilookup(calUname,calUrow,"Kd");
    int word3 = ilookup(calUname,calUrow,"Kf");
    int word4 = 3;
    if(homing_mode_rate == 0) {
        word4 = ilookup(calUname,calUrow,"Rate");
    }
    int word5 = ilookup(calUname,calUrow,"AccLimit");
    int word6 = ilookup(calUname,calUrow,"OutputLimit");
    int word7 = ilookup(calUname,calUrow,"Scaling");
    int word8 = ilookup(calUname,calUrow,"ErrorLimit");
    int word9 = ilookup(calUname,calUrow,"N1");
    int word10 = ilookup(calUname,calUrow,"N2");
    int word11 = ilookup(calUname,calUrow,"N3");
    int word12 = ilookup(calUname,calUrow,"D1");
    int word13 = ilookup(calUname,calUrow,"D2");
    //CONF_PAR
    // Create the parameter list tuple
    {int}[] params = [{word0},{word1},{word2},{word3},{word4},{word5},{word6},{word7},{word8}];
    // Create the array for the checksum function
    int[] aux = [word0,word1,word2,word3,word4,word5,word6,word7,word8];
    int chksum = checksum("int",aux);
    // Send the TC
    Pacs_DMC_WRT_GRAT_CONF_PAR(params,chksum);
    // CONF_FILT
    // Create the parameter list tuple
    params = [{word9},{word10},{word11},{word12},{word13}];
    // Create the array for the checksum function
    aux = [word9,word10,word11,word12,word13];
    chksum = checksum("int",aux);
    // Send the TC
    Pacs_DMC_WRT_GRAT_CONF_FILT(params,chksum);
    delay(1);
}

// $Id: WriteEndBB.txt,v 1.2 2007/08/22 10:21:52 dcesarsk Exp $ 
// Purpose       : Set BBID to its required value to indicate the end
//                 of current BB execution (see FIRST-FSC-DOC-0200) 
//
// CUS script    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
//
// Input arguments N/A
//
// Description   : BBID will be set to its LEG value
//
// Comments      : Needed for SCR-3507
//
// Version       : 0.1 21-aug-2007 First creation
// 		 : 1.0 derived from ...made it a block
//
block PacsBbWriteIdBB PACS 1102 {
}{
    int iBBID = 0xcd2a4a5;
    // Write BBID to DEC/MEC
    Pacs_DMC_SET_BBID(iBBID);
}

// Missionphase  :  FLIGHT, CP (CPSpecGeGa)
//
// Purpose       : Perform Setup Spectroscopy
//
// CUS author    : TM, DAC,PR
// Script file   : SPEC_setup_Flex.cus
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Calls the following "elementary" scripts:
//                 - SPEC_dpu_dmc_setup
//                 - SPEC_init_det_setup
//                 - SPEC_CRE_setup
//                 - SPEC_dmc_setup
//                 - SPEC_spu_setup
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.1
// History       : 1.0  16-Jun-2009 PR. Creation, based on SPEC_setup
//                     1.1 27-Jul-2009 BV corrected biases SPR 1798
//                     1.2 20-oct-2010 PACS-3099 VD & HF remove DPU_SET_FUNCT("EVENT_DEC_SPC","ENABLE")
//                     1.3 22-oct-2010 PACS-3099 VD & HF Memory Dump  
//
block SPEC_setup_Flex PACS 101 {
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double temp_CS1 = 48.0;
    double temp_CS2 = 58.0;
    double blu_heater_curr = 0.78; // Nominal current [mA]
    int gratpos = 737500; // Starting Grating Position
    string fwpos = "POS B" in ["POS A","POS B"]; // Predefined positions [POS A, POS B]
    int choppos = 21200; // Chopper position : CS1 -21350, CS2 21200
    double bias_d_red = 0.042; // BIAS_D for red spectro  (0-1V)
    double bias_d_blu = 0.1; // BIAS_D for blue spectro (0-1V)
    int capa_red = 0; // Capacitor red  (0=0.1pF,4=0.4pF,8=0.2pf,12=1pF)
    int capa_blu = 0; // Capacitor blue (0=0.1pF,4=0.4pF,8=0.2pf,12=1pF)
}{
    // Register BBID with environment
    WriteBBID($BBID);
    // Start "elementary" scripts
    SPEC_dpu_dmc_setup();
    // Configure initial configuration for CREs
    SPEC_init_det_setup();
    // Default CRE configuration (set default bias, ramp length, and capacitor)
    // Red  ramp length
    int ramp_len_red = 64;
    // Blue ramp length
    int ramp_len_blu = 64;
    // BIAS_R for red spectro  (0-1V)
    double bias_r_red = 0.01;
    // BIAS_R for blue spectro (0-1V)
    double bias_r_blu = 0.01;
    SPEC_CRE_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,blu_heater_curr);
    // Configure all used controllers
    int chopper_def = 0;
    SPEC_dmc_setup(fltPOS,chopper_def,temp_CS1,temp_CS2);
    // configure SPU
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    int nb_samp_subramp_blu = 64;
    int nb_samp_subramp_red = 64;
    int nb_raw_spu_blu = 3;
    int nb_raw_spu_red = 3;
    int glitch_det = 1;
    int ramp_fit_alg = 0;
    bool startSPU = false;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Position the mechanisms
    SPEC_fltw_move(fwpos);
    delay(1);
    Pacs_DMC_MOVE_GRAT_ABS_RAW(gratpos);
    delay(8);
    Pacs_DMC_MOVE_CHOP_ABS_RAW(choppos);
    delay(1);
    // Last! Enable autonomy function 5
    Pacs_DPU_SET_FUNCT("COUNTER_SPEC","ENABLE");
    // Last! Enable autonomy function 20---DO NOT ENABLE- 20-oct-2010
    //    Pacs_DPU_SET_FUNCT("EVENT_DEC_SPC","ENABLE");
    // Mark End of Block
    // Memory dump
    int mem_dumpId = 0x1100;
    int mem_dump_addr = 0xbf2;
    int dump_dataLength = 0x1053;
    Pacs_DPU_MEMORY_DUMP(mem_dumpId,mem_dump_addr,dump_dataLength);
    WriteEndBB();
    sync();
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_lowGainBiasDirect3
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//  int nLoops2 = 30; // number of CSs cycles during initial hold
//  int nLoops5 = 30; // number of CSs cycles during final hold
//  bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_lowGainBiasDirect3
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//
// Version : Fri Apr 24 19:30:21 EST 2009
//
obs PacsCal_Phot_lowGainBiasDirect3 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(endBiasTable,"DIRECT","LOW"));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    //Minimum slew time
    int tslewmin = timeOBSID + timeSetBias;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeSetBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_lowGainBiasDirect3(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            // Call the Phot_lowGainBiasDirect3
            //************************************
            Phot_lowGainBiasDirect3(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_lowGainBiasDirect4
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//  int nLoops2 = 30; // number of CSs cycles during initial hold
//  int nLoops5 = 30; // number of CSs cycles during final hold
//  bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_lowGainBiasDirect4
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//
// Version : Fri Apr 24 19:30:21 EST 2009
//
obs PacsCal_Phot_lowGainBiasDirect4 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(endBiasTable,"DIRECT","LOW"));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    //Minimum slew time
    int tslewmin = timeOBSID + timeSetBias;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeSetBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_lowGainBiasDirect4(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            // Call the Phot_lowGainBiasDirect4
            //************************************
            Phot_lowGainBiasDirect4(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_lowGainBiasDirect1
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//  int nLoops1 = 30; // number of CSs cycles during slew
//  int nLoops2 = 30; // number of CSs cycles during initial hold
//  int nLoops5 = 30; // number of CSs cycles during final hold
//  bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_lowGainBiasDirect1
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//
// Version : Fri Apr 24 19:29:50 EST 2009
//
obs PacsCal_Phot_lowGainBiasDirect1 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(endBiasTable,"DIRECT","LOW"));
    int timeCal3CPR1 = duration(Pacs_OBCP_chopped_photometry2(nLoops1,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    //Minimum slew time
    int tslewmin = timeOBSID + timeSetBias + timeCal3CPR1;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeSetBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_lowGainBiasDirect1(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops1,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            // Call the Phot_lowGainBiasDirect1
            //************************************
            Phot_lowGainBiasDirect1(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_lowGainBiasDirect2
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//  int nLoops2 = 30; // number of CSs cycles during initial hold
//  int nLoops5 = 30; // number of CSs cycles during final hold
//  bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_lowGainBiasDirect2
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//
// Version : Fri Apr 24 19:30:06 EST 2009
//
obs PacsCal_Phot_lowGainBiasDirect2 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(endBiasTable,"DIRECT","LOW"));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    //Minimum slew time
    int tslewmin = timeOBSID + timeSetBias;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeSetBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_lowGainBiasDirect2(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            // Call the Phot_lowGainBiasDirect2
            //************************************
            Phot_lowGainBiasDirect2(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// CVS comments  : $Id: DMC_fixed_fixed_photo.txt,v 1.6 2007/04/25 15:14:03 dcesarsk Exp $ 
// Script file   : DMC_fixed_fixed_photo.txt
// Purpose       : Compute execution time of DMC #??
//
// TCL author    : N/A Pseudo code by HF
// TCL file      : N/A
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : DMC 4.1.8 Fixed-Fixed Chopping in Photometry
//                 Chopping is done to a set (3 pairs) of positions in order
//                 to place positive and negative beams on different
//                 pixels on the array, where the distance between 2 respective
//                 positions stays constant for a while and then the next
//                 position pair is being measured.
//                 The chopper performs the following pattern
//
//                 P#2      take nb_rdouts
//                 P#2+P#5  take nb_rdouts  }           }
//                 P#2+P#6  take nb_rdouts  } P#4 times }
//                                          }
//                 P#7      take nb_rdouts              }
//                 P#7+P#5  take nb_rdouts  }           }
//                 P#7+P#6  take nb_rdouts  } P#4 times } P#1 times
//                                          }
//                 P#8      take nb_rdouts              }
//                 P#8+P#5  take nb_rdouts  }           }
//                 P#8+P#6  take nb_rdouts  } P#4 times }
//
// TOTAL readouts (2*P#4 + 1)*3*nb_rdouts
// 
//      Usually P#6 = -P#5 so that chopper comes back to starting postion
//
// Dependencies  :
//
// Preconditions : None.
//
// Comments      : No TC are generated; only times are computed
//
// History       : 0.1 26-jun-2006 DAC
//                 0.2 22-nov-2006 Removed debug_print
//                 0.3 14-mar-2007 WAIT=1 is now considered useful data
int[] procedure DMC_fixed_fixed_photo {
    int nb_main_loops = 1; // Seq P#1   Nb of of main loops
    int nb_rdouts = 159; // Seq P#3   Nb of rdouts per chopper position
    int nb_chop_cycle = 2; // Seq P#4   Nb of chops per incremental step
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    // WAIT 1                                ; have a defined start
    duree_num = duree_num + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0                               ; set Label to 0
    // WAIT 1                                ; have a defined start
    duree_num = duree_num + 1;
    duree_OVR = duree_OVR + 1;
    // LOOP P#1                             ; main loop measurement
    for(int loop0 = 1 .. nb_main_loops) {
        //    WAIT 1                             ; sync. for chopper
        duree_num = duree_num + 1;
        duree_SRC = duree_SRC + 1;
        //    MOVE_CHOPPER_ABSOLUTE P#2          ; start pos. chopper
        //    LABEL 3                            ; 1st chopper position
        //    WAIT P#3                           ; take P#3 images
        duree_num = duree_num + nb_rdouts;
        duree_SRC = duree_SRC + nb_rdouts;
        //    LOOP P#4                           ; do P#4 chops per step
        for(int loop1 = 1 .. nb_chop_cycle) {
            //       WAIT 1                          ; sync. for chopper
            duree_num = duree_num + 1;
            duree_SRC = duree_SRC + 1;
            //       MOVE_CHOPPER_RELATIVE P#5       ; go to other chop position
            //       LABEL 5                         ; 2nd chopper position
            //       WAIT P#3                        ; take P#3 images
            duree_num = duree_num + nb_rdouts;
            duree_SRC = duree_SRC + nb_rdouts;
            //       WAIT 1                          ; sync. for chopper
            duree_num = duree_num + 1;
            duree_SRC = duree_SRC + 1;
            //       MOVE_CHOPPER_RELATIVE P#6       ; go back to previous position
            //       LABEL 3                         ; 1st chopper position
            //       WAIT P#3                        ; take P#3 images
            duree_num = duree_num + nb_rdouts;
            duree_SRC = duree_SRC + nb_rdouts;
        }
        //    END_LOOP                           ; end of chop
        //    WAIT 1                             ; sync. for chopper
        duree_num = duree_num + 1;
        duree_SRC = duree_SRC + 1;
        //    MOVE_CHOPPER_ABSOLUTE P#7          ; go to next position pair
        //    LABEL 7                            ; 3rd chopper position
        //    WAIT P#3                           ; take P#3 images
        duree_num = duree_num + nb_rdouts;
        duree_SRC = duree_SRC + nb_rdouts;
        //    LOOP P#4                           ; do P#4 chops per step
        for(int loop2 = 1 .. nb_chop_cycle) {
            //       WAIT 1                          ; sync. for chopper
            duree_num = duree_num + 1;
            duree_SRC = duree_SRC + 1;
            //       MOVE_CHOPPER_RELATIVE P#5       ; go to other chop position
            //       LABEL 9                         ; 4th chopper position
            //       WAIT P#3                        ; take P#3 images
            duree_num = duree_num + nb_rdouts;
            duree_SRC = duree_SRC + nb_rdouts;
            //       WAIT 1                          ; sync. for chopper
            duree_num = duree_num + 1;
            duree_SRC = duree_SRC + 1;
            //       MOVE_CHOPPER_RELATIVE P#6       ; go back to previous position
            //       LABEL 7                         ; 3rd chopper position
            //       WAIT P#3                        ; take P#3 images
            duree_num = duree_num + nb_rdouts;
            duree_SRC = duree_SRC + nb_rdouts;
        }
        //    END_LOOP                           ; end of chop
        //    WAIT 1                             ; sync. for chopper
        duree_num = duree_num + 1;
        duree_SRC = duree_SRC + 1;
        //    MOVE_CHOPPER_ABSOLUTE P#8          ; go to next position pair
        //    LABEL 11                           ; 5th chopper position
        //    WAIT P#3                           ; take P#3 images
        duree_num = duree_num + nb_rdouts;
        duree_SRC = duree_SRC + nb_rdouts;
        //    LOOP P#4                           ; do P#4 chops per step
        for(int loop3 = 1 .. nb_chop_cycle) {
            //       WAIT 1                          ; sync. for chopper
            duree_num = duree_num + 1;
            duree_SRC = duree_SRC + 1;
            //       MOVE_CHOPPER_RELATIVE P#5       ; go to other chop position
            //       LABEL 13                        ; 6th chopper position
            //       WAIT P#3                        ; take P#3 images
            duree_num = duree_num + nb_rdouts;
            duree_SRC = duree_SRC + nb_rdouts;
            //       WAIT 1                          ; sync. for chopper
            duree_num = duree_num + 1;
            duree_SRC = duree_SRC + 1;
            //       MOVE_CHOPPER_RELATIVE P#6       ; go back to previous position
            //       LABEL 11                        ; 5th chopper position
            //       WAIT P#3                        ; take P#3 images
            duree_num = duree_num + nb_rdouts;
            duree_SRC = duree_SRC + nb_rdouts;
        }
        //    END_LOOP                           ; end of chop
        // END_LOOP                              ; end main loop
    }
    // WAIT 1                                ; complete last plateau
    duree_num = duree_num + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0                               ; no sequence anymore
    // END_SEQUENCE
    // 8 Parameters: # of main loops (P#1);
    // Chopper start positions P#2, P#7, P#8;
    // Size of Relative chopper moves P#5, P#6;
    // # of chops per incremental step (P#4);
    // # of readouts per chopper plateau (P#3)
    // Note: P#3 must be defined such that: (P#3 + 1) mod 4 = 0; P#5 = -P#6;
    //       Sequence duration, in readouts :
    //       3 + P#1 * 3 * {(1 + P#3) + P#4 * (2 * (1+P#3))}
    int dur_theor = 3 + nb_main_loops * 3 * (1 + nb_rdouts + nb_chop_cycle * 2 * (1 + nb_rdouts));
    // debug_print("Theor duration: " + dur_theor);
    int[] duree = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    //  debug_print("++DMC_fixed_fixed: " + duree + " [rdouts]");

    return duree;
}

// File          : PACS_Phot_HK_Setup.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Prepare for Photometry HK 
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
// Arguments     : none
//                 
//
// Description   : This script will only activate Photometry HK
//                                              
// Comments      :  
//    
//
// Version       : 1.0
// History       : 1.0 / 18-Nov-2004 initial version
//                     
// 
procedure PACS_Phot_HK_Setup {
}{
    // DPU_SET_HK_LIST (Phot for both channels)
    // tcsend PC003380 {PP005380 2} {PP025380 1}
    // waittime 0.5
    Pacs_DPU_SET_HK_LIST("PHOT","BOTH Array");
    delay(1);
    message("Phot HK set");
    // ---------------------
    // End of Procedure
    // ---------------------
}

// CVS comments  : $Id: PacsProcessInfoArrayLine.txt,v 1.13 2007/10/25 12:15:42 dcesarsk Exp $ 
//
// Purpose       : Process the timing information gathered in infoArray
//
// CUS author    : DAC
//
// Input arguments
// type    name        description
// tuple   infoArray
// Slew/Point/AOT       SlewCal or pointing mode or global AOT info
// 0.0                  not in use
// TotDur               duration of the phase Slew/Point/AOT
// nbLines              number of spectral lines observed in phase Slew/point
// nnods                number of nod cycles in phase Point
// m*n                  size of raster when applicable
// wave1                each of the nbLines wavelengths or waveStart
// wave2                each of the nbLines wavelengths or waveEnd
// order                grating order for line wave
// gratStep             grating step (needed to estimate "multiplexing")
// TOT,SRC,REF,CAL,OVR  the canonical OBCP duration (/nod/raster)
//
// Return values
// Type          Description
//
// Description   : Use the information in infoArray to compute several times and
// overheads, as well as the expected RMS fluctuations for each observed line
// infoArray is a three-element tuple:
//    infoArray[0] contains information on the SlewCal phase
//    infoArray[1] contains information on the OBS phase
//    infoArray[2] contains global information on the AOT
//                  
// Dependencies  : 
//
// Comments      : 
// 
// History       : 0.1  6-Sep-2005 DAC
// 0.2 27-sep-2005 Adding elements to compute RMS
// 0.3 28-sep-2005 Add nbGratSteps to infoArray
// 0.4 29-sep-2005 Add confOBCP to input arguments since I need nb_up_dn !!
// 0.5  6-oct-2005 Corrected Raster/Staring logic
// 0.6 14-oct-2005 Text of message
// 1.0 24-oct-2005 Add HTML tags
// 1.1 23-jan-2006 Multiplication by nbNods, mRaster, nRaster no longer needed
//                 since next_state collects time per raster per nod. Also
//                 eliminate "PACS overheads"
// 1.2  1-mar-2006 Use dformat for messages
// 2.0 11-mar-2006 Deal with LINE and CONT RMS values
// 2.1 22-nov-2006 Added "verbose" to input arguments
// 3.0 17-jan-2006 "Improved" messages
// 3.1 12-feb-2007 Accept as input the tuples lines
// 3.2 14-feb-2007 Adapted to amended PacsSpecRMS, simplified code as now
//                 used only with LINE
// 3.3 12-apr-2007 Add obsOverhead for SCR-2813
// 3.4 27-apr-2007 SPR-3147: change km/s into kms
// 3.5 29-may-2007 SPR-3243 Continuum S/N: mJy/mJy
// 3.6 13-jun-2007 SPR-3307 Fewer digits in messages
// 3.7 24-oct-2007 Added nbOBS and nbOFF to input arguments; same to
//                 PacsSpecRMS
// 4.0 08-feb-2010 VD PHS-1308 chnaged to _tmp so that other dependencies are not broken                
// 4.1 08-feb-2010 VD PHS-1308 WS to take into account Nod cycles repeats in SN and RMS
// 5.0 21-apr-2010 VD PHS-1385 un-chop
// 6.0 05-may-2010 VD PHS-1385 cont's RMS simulation from freqSwitch
// 7.0 07-may-2010 VD merging
//                 
procedure PacsProcessInfoArrayLine_tmp {
    /* infoArray                                                               */
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    /* lines                                                                  */
    /* {id,redshifted wavelength,repeat factor,line flux,continuum flux,      */
    /*  line width,line flux unit,line width unit}                            */
    {string,double,int,double,double,double,string,string}[] lines = [];
    /* confOBCP                                                               */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* observatory overhead                                                    */
    int obsOverhead = 180;
    /* nbOBS and nbOFF                                                         */
    int nbOBS = 1;
    int nbOFF = 0;
    int[] gratScanObsTime = [1];
    /* verbose?                                                                */
    bool verbose = true;
}{
    // Data used here is to be found in
    // infoArray[0]{0}{2}   : tslew from PointReq
    // infoArray[0]{0}{3}   : Number of key waves in AOT
    // infoArray[0]{1}[]{0} : keyWAVE[]
    // infoArray[0]{1}[]{5} : sumCalTime[][0]
    // infoArray[0]{1}[]{6} : sumCalTime[][1]
    // infoArray[0]{1}[]{7} : sumCalTime[][2]
    // infoArray[0]{1}[]{8} : sumCalTime[][3]
    // infoArray[0]{1}[]{9} : sumCalTime[][4]
    // infoArray[1]{0}{0}   : PointReq information (ex. SmSrcDither)
    // infoArray[1]{0}{1}   : Integration time per plateau
    // infoArray[1]{0}{2}   : OBCP duration *per pointing*
    // infoArray[1]{0}{3}   : Number of lines/ranges
    // infoArray[1]{0}{4}   : Number of nod cycles
    // infoArray[1]{0}{5}   : Raster m*n
    // infoArray[1]{1}[]{0} : Starting wave for line []
    // infoArray[1]{1}[]{1} : Ending wave for line []
    // infoArray[1]{1}[]{2} : Grating order for line []
    // infoArray[1]{1}[]{3} : Grating step for line []
    // infoArray[1]{1}[]{4} : Number of grating steps for line []
    // infoArray[2]{0}{0}   : OBCP information (ex. FreqSwitch)
    // infoArray[2]{0}{2}   : Total duration of AOR (SLEW+OBS)
    // infoArray[2]{0}{3}   : Raster "m" size
    // infoArray[2]{0}{4}   : Raster "n" size
    // infoArray[2]{0}{5}   : Nb of nods (does not seem to be used anywhere)
    // Number of spectral lines (SlewCal and OBS)
    int nbKeyWaves = infoArray[0]{0}{3};
    int nbLines = infoArray[1]{0}{3};
    // Number of nods (OBS)
    int nbNodCycles = infoArray[1]{0}{4};
    // Nb of "pointings" for nbNodCycles
    int nbNods = 2 * nbNodCycles;
    if(nbNods == 0) {
        nbNods = 1;
    }
    // Call module to estimate RMS fluctuations; pass information via infoArray
    // and confOBCP (for nb_up_dn)
    // To conform with PacsRangeSpec code, define dummy rangeSPOT tuple (needed
    // by new RMS module)
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [];
    // Ditto for "orderSel"
    // add Fake infoRangeSed PHS-1308 sorry !
    {double,double}[] infoRangeSed = [{0.0,0.0}];
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = PacsSpecRMS_tmp("LINE","orderSel",infoArray,rangeSPOT,infoRangeSed,confOBCP,nbOBS,nbOFF,gratScanObsTime,verbose);
    // Define variable to extract info from noiseTuple
    double[][] noiseWave = [[0.0]];
    // Useful variables
    int lineCnt = 0;
    string[] msgLine = ["Line1"];
    // one line of text
    // Report on nodding pattern and pointing details
    msgLine[lineCnt] = "PACS AOT: PacsLineSpec";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Pointing mode: <B>" + infoArray[1]{0}{0} + "</B> with " + nbNodCycles + " nod cycles</p>";
    lineCnt = lineCnt + 1;
    int mRaster = infoArray[2]{0}{3};
    int nRaster = infoArray[2]{0}{4};
    // When either m or n are >1 then it is raster
    if(mRaster > 1 || nRaster > 1) {
        msgLine[lineCnt] = "<p>Raster size (lines/points):" + mRaster + "/" + nRaster + "</p>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "<p> Nod pattern: nominal position A, or A->B, B->A, etc.</p>";
    lineCnt = lineCnt + 1;
    if(nbNodCycles == 0) {
        msgLine[lineCnt] = "<p>   A </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles == 1) {
        msgLine[lineCnt] = "<p>   A->B </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles == 2) {
        msgLine[lineCnt] = "<p>   A->B B->A </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles > 2) {
        int aux1 = nbNodCycles - 2;
        msgLine[lineCnt] = "<p>   A->B B->A and " + aux1 + " more A<->B leg(s) </p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("AOT, PointMode and Nodding info",lineCnt,msgLine);
    // Global timing information for this AOT
    lineCnt = 0;
    int totAOT = infoArray[2]{0}{2};
    msgLine[lineCnt] = "<p> AOT total duration: " + totAOT + " [sec] </p>";
    lineCnt = lineCnt + 1;
    //  Next is tslew returned by PntReq
    int tslew = infoArray[0]{0}{2};
    msgLine[lineCnt] = "<ul><li> CalSlew (with overheads) " + tslew + " [sec]</li>";
    lineCnt = lineCnt + 1;
    // infoArray[1]{0}{2} is defined as the elementary OBCP duration (per nod
    // and per raster pointing; includes all wavelengths)
    //int totSRCREF = mRaster * nRaster * nbNods * infoArray[1]{0}{2};
    int totSRCREF = infoArray[1]{0}{2};
    msgLine[lineCnt] = "<li> SRC+REF (with overheads) " + totSRCREF + " [sec]</li>";
    lineCnt = lineCnt + 1;
    //  Logic from RV... If tslew takes shorter than obsOverhead, we keep
    //  obsOverhead
    int cost = totAOT - tslew;
    //  But if tlsew takes longer, it becomes the new obsOverhead
    if(tslew > obsOverhead) {
        obsOverhead = tslew;
    }
    cost = cost + obsOverhead;
    msgLine[lineCnt] = "<li><b>AOT cost</b> (includes time for slewing to source): " + totSRCREF + " + " + obsOverhead + " [sec] = " + cost + " [sec]</li></ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Global AOT durations",lineCnt,msgLine);
    if(verbose) {
        debug_print("++ Start ProcessArray debug info");
        debug_print(" CalSlew: " + infoArray[0]);
        debug_print(" OBS    : " + infoArray[1]);
        debug_print(" TotDur : " + infoArray[2]);
        debug_print("++ End of ProcessArray debug info");
    }
    // Inform the details of SlewCal to HSPOT user
    //   AOT prologue
    lineCnt = 0;
    msgLine[lineCnt] = "<ul><li> AOT prologue duration: " + infoArray[0]{1}[nbKeyWaves]{5} + " [sec]</li>";
    lineCnt = lineCnt + 1;
    //  For each keyWave
    for(int loop0 = 0 .. nbKeyWaves - 1) {
        msgLine[lineCnt] = "<li> KeyWave: " + infoArray[0]{1}[loop0]{0} + " [&micro;m]; CAL duration: " + infoArray[0]{1}[loop0]{5} + " [sec]</li>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    // Display message
    PacsMessageCenter("LINE setup and CAL summary",lineCnt,msgLine);
    // Re-initialize lineCnt for new series of messages
    lineCnt = 0;
    // Continue defining noiseWave for historical reasons (it used to be returned
    // by PacsSpecRMS, now replaced by bigTuple)
    for(int loop1 = 0 .. nbLines - 1) {
        int trueObsTime = infoArray[1]{1}[loop1]{5};
        noiseWave[loop1] = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0];
        //      CONTinuum
        noiseWave[loop1][0] = bigTuple[loop1]{0}{1}[0];
        noiseWave[loop1][1] = bigTuple[loop1]{0}{1}[1];
        noiseWave[loop1][2] = bigTuple[loop1]{0}{1}[2];
        noiseWave[loop1][3] = bigTuple[loop1]{0}{1}[3];
        //      LINE
        noiseWave[loop1][4] = bigTuple[loop1]{0}{1}[4];
        noiseWave[loop1][5] = bigTuple[loop1]{0}{1}[5];
        noiseWave[loop1][6] = bigTuple[loop1]{0}{1}[6];
        noiseWave[loop1][7] = bigTuple[loop1]{0}{1}[7];
        //      CONT and LINE for refWave     
        noiseWave[loop1][8] = bigTuple[loop1]{0}{1}[8];
        noiseWave[loop1][9] = bigTuple[loop1]{0}{1}[9];
        noiseWave[loop1][10] = bigTuple[loop1]{0}{1}[10];
        //      Estimate resolution for given wavelength and order
        //      Need order and wavelength
        int order = infoArray[1]{1}[loop1]{2};
        double wave = infoArray[1]{1}[loop1]{0};
        //      Build key to read SPEC_resolution table
        string keyCOL = "resol" + order;
        double resolkm = interpolate("SPEC_resolution",keyCOL,wave);
        //      Resolution in microns
        double resolmic = resolkm * wave / 300000.0;
        // Compare instrument resolution with line width
        // User given line width
        double userWidth = lines[loop1]{5};
        // User given width units
        string unitWidth = lines[loop1]{7};
        // Is there a sensitivity degradation? 
        bool sensitDegrad = false;
        // Assume no degradation
        double degrad = 1.0;
        // Avoid division by zero
        if(resolkm > 0.0) {
            // Do not compare torchons et servillettes
            if(unitWidth == "micron" && userWidth > resolmic) {
                sensitDegrad = true;
                degrad = sqrt(userWidth / resolmic);
            }
            if(unitWidth == "kms" && userWidth > resolkm) {
                sensitDegrad = true;
                degrad = sqrt(userWidth / resolkm);
            }
        }
        if(verbose) {
            debug_print("++line parameters: " + userWidth + " " + unitWidth);
            debug_print("++sensitDegrad: " + sensitDegrad);
            debug_print("++Degrad: " + degrad);
        }
        // SrcTime includes REF!
        int trueSrcTime = infoArray[1]{1}[loop1]{6} + infoArray[1]{1}[loop1]{7};
        int lineOver = trueObsTime - trueSrcTime;
        msgLine[lineCnt] = "<h3>" + lines[loop1]{0} + ": " + dformat(infoArray[1]{1}[loop1]{0},2) + " [&micro;m]:</h3>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<ul>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<li>FWHM at current wavelength: " + dformat(resolkm,1) + " [km/s] or " + dformat(resolmic,3) + " [&micro;m]";
        lineCnt = lineCnt + 1;
        int noiseMjy = ifloor(1000.0 * noiseWave[loop1][1]);
        msgLine[lineCnt] = "<li>   Continuum RMS: " + noiseMjy + " [mJy]";
        lineCnt = lineCnt + 1;
        // SPR-3243 Wrong S/N ratio. Use the occasion to avoid divide-by-zero
        if(noiseWave[loop1][1] > 1.0E-30) {
            double s2nCONT = lines[loop1]{4} / noiseWave[loop1][1];
            s2nCONT = s2nCONT / 1000.0;
            msgLine[lineCnt] = "<li>   Continuum S/N: " + dformat(s2nCONT,2);
            lineCnt = lineCnt + 1;
        }
        double lineNoise = noiseWave[loop1][5] * 1.0E18;
        msgLine[lineCnt] = "<li>Line RMS: " + dformat(lineNoise,2) + "E-18 [w/m2]</li>";
        lineCnt = lineCnt + 1;
        double s2nLINE = lines[loop1]{3} / lineNoise;
        msgLine[lineCnt] = "<li>Line S/N: " + dformat(s2nLINE,2);
        lineCnt = lineCnt + 1;
        if(sensitDegrad) {
            msgLine[lineCnt] = "<li><b>Warning:</b> the given line width, " + userWidth + " " + unitWidth + ", exceeds the instrumental FWHM; expect a loss of " + dformat(degrad,1) + " times in the LINE Signal-to-Noise ratio</li>";
            lineCnt = lineCnt + 1;
        }
        msgLine[lineCnt] = "<li>Total duration (SRC+REF+PACS overheads): " + trueObsTime + " [sec]";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<li>SRC+REF (no overheads): " + trueSrcTime + " [sec]";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "</ul>";
        lineCnt = lineCnt + 1;
    }
    // Display message
    PacsMessageCenter("SpecLine summary",lineCnt,msgLine);
}

// Mission phase : Routine Phase
//
// Purpose : Explore the time constant after flux change for a flux levels using the low gain
//
// Author : Koryo Okumura
//
// Version : Fri Jul 02 14:42:06 EDT 2010
//
// CUS script : mode PacsCal_RPPhot_bandpassDirect
//
// Argument :
//   int sideField = 7134; // Chopper angle for the FOV next to BB2
//   int chop_pos_CS2 = 21196; // Chopper angle for BB2
//   string biasTable = "BOLObias_orbit_standard"; // Bias table
//   string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
//   string biasChoice = "Nominal" in ["Low","Nominal","High"]; // Detector bias setting
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//   string calBiasTable = "BOLObias_orbit_standard"; // Bias table used during calibration blocks
//   string calGain = "LOW" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "DIRECT" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//   int nLoops1 = 10; // number of CSs cycles during slew
//   int nLoops2 = 10; // number of CSs cycles during initial hold
//   int nLoops5 = 10; // number of CSs cycles during final hold
//   int nReadout_plateau = 32; // number of readouts per plateau
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description : OBS script to execute PacsCal_RPPhot_bandpassDirect
//
// Dependencies : Previously obtaind data at high gain (PCD req.1.1.1bis)
//
// Comments : generated by IA script : cus_RP_bandpass()
// Comments : This implements SCR:PACS-2841
//
obs PacsCal_RPPhot_bandpassDirect {
    int sideField = 7134; // Chopper angle for the FOV next to BB2
    int chop_pos_CS2 = 21196; // Chopper angle for BB2
    string biasTable = "BOLObias_orbit_standard"; // Bias table
    string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
    string biasChoice = "Nominal" in ["Low","Nominal","High"]; // Detector bias setting
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    string calBiasTable = "BOLObias_orbit_standard"; // Bias table used during calibration blocks
    string calGain = "LOW" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "DIRECT" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    int nLoops1 = 10; // number of CSs cycles during slew
    int nLoops2 = 10; // number of CSs cycles during initial hold
    int nLoops5 = 10; // number of CSs cycles during final hold
    int readouts_plateau = 32; // number of readouts per plateau
    bool verbose = true;
}{
    // Bus configuration for the Burst mode (7)
    busconfig (7);
    int nRdts = readouts_plateau - 1;
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = 0;
    int timeChgBias0 = duration(PHOT_change_biases(biasTable,"NO_CHANGE","NO_CHANGE"));
    int timeCal3CPR1 = duration(Pacs_OBCP_chopped_photometry2(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    //Minimum slew time
    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT","LOW"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT",calGain));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"LOW"));
    }
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
    }
    int tslewmin = timeOBSID + timeChgBias + timeCal3CPR1;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeChgBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(RPPhot_bandpassDirect(biasTable,gain,sideField,chop_pos_CS2,biasChoice));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(300.0);
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            // No biases setting here because nothing changes
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            //  Call the RPPhot_bandpassDirect
            //************************************
            RPPhot_bandpassDirect(biasTable,gain,sideField,chop_pos_CS2,biasChoice);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       : Exercise all available OBCPs for photometry
//                  
//                 
//
// TCL author    : N/A
// TCL file      : tN/A
// CUS author    : DAC
// Script file   : PHOT_all_aots_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Exercise all available OBCPs for PHOT
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version      2.0
// History      0.1 20-apr-2005 DAC
//
//                 0.2 25-apr-2005 DAC Added moe to POS A at the end
//                 0.3 25-apr-2005 DAC Start and stop SPU with user given
//                                     compression parameters
//                 0.4 26-apr-2005 DAC Use PACS_spu_reset at end
//                 0.5 30-sep-2005 Correct typo phot_cal_III (-46145)
//                 0.6  9-nov-2005 comp_mode_xx were hardcoded in OBCP calls
//                 0.7 16-jun-2006 DAC Added 2 sec delay between OBCPs
//                 0.8  3-aug-2006 DAC Corrected OBCP freeze frame
//                 0.9  9-aug-2006 TM 2 new OBCPs have been added + some cosmetics
//                 0.95 9-aug-2006 TM, new parameters for chop_scan OBCP
//                 0.96 9-aug-2006 TM, compression mode hard-coded
//                 1.0 14-nov-2006 TM: update of chopper positions
//                 1.1 17-nov-2006 Remove freeze frame
//                 1.2 11-apr-2007 TM: take out the raw channels
//		   2.0 25-mar-2008 VDP: Translated from IST to PV phase syntax
//
obs PacsEng_Phot_all_aots {
    /* Needed variables to call PacsEng_Phot_all_aots                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_all_aots                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Phot_all_aots()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Phot_all_aots();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req.1.1.9 Measure time constants after cosmic ray impact
//
// Author : Koryo Okumura
//
// Version : June 08 2009
//
// CUS script : mode PacsEng_Phot_VrlGlitch
//
// Argument :
//   string biasTable = "BOLObias_standard_high"; // Bias table
//   string gain = "HIGH" in ["LOW","HIGH"]; // gain used during the measurements
//   int measureTime = 1200; // Measurement duration in seconds
//   string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
//   string calGain = "NO_CHANGE" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description : OBS script to execute Phot_VrlGlitch
//
// Dependencies : None
//
// Comments : None
// Update :
//   2009-06-08 : Modified from PacsCal_Phot_VrlGlitch
//
obs PacsEng_Phot_VrlGlitch {
    string biasTable = "BOLObias_standard_high"; // Bias table
    string gain = "HIGH" in ["LOW","HIGH"]; // gain used during the measurements
    int measureTime = 1400; // Measurement duration in seconds
    string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
    string calGain = "NO_CHANGE" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 16; // number of readouts per plateau
    bool verbose = true;
}{
    // Bus configuration for the Burst mode (7)
    busconfig (7);
    // Several arguments needed for "basic_fine_pointing"
    int nRdts = readouts_plateau - 1;
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    //int timeOBSID = imax(1, duration(WriteOBSID($OBSID))+ duration(data_rate(300.0)));
    //int timeEndID = imax(1, duration(data_rate(0.0))+ duration(WriteEndID()));
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = 0;
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT","LOW"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT",calGain));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"LOW"));
    }
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
    }
    //Initial hold
    int tih = timeOBSID + timeChgBias + timeCal3CPR2;
    //Final hold
    int tfh = timeChgBias + timeCal3CPR5 + timeEndID;
    //Duration of "stable" pointing
    int tp = duration(Phot_VrlGlitch(biasTable,gain,measureTime));
    //Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(300.0);
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //**********************
            //  Call Phot_VrlGlitch
            //**********************
            Phot_VrlGlitch(biasTable,gain,measureTime);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// File          : PACS_Spec_B_Heat_Setup.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Sets Blue Heater currents 
//
// Author        : P. Royer
//
// Arguments     : blue  Heater currents
//
// Description   : Sets Heater currents blue 
//               :
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 27.02.2007 initial version by PR
//
procedure PACS_Spec_B_Heat_Setup {
    double blue_heat_current = 0.0;
}{
    // SETUP HEATER
    //
    Pacs_DMC_SET_B_SPEC_HEAT_C(blue_heat_current);
    delay(1);
}

// File          : PACS_Phot_SPU_Setup.cus
// Missionphase  : PACS IST
//
// Purpose       : Prepare SPU for photometry data flow
//
// Author        : T. Mueller, H. Feuchtgruber
// CUSification  : DAC
// Arguments     : none
//                 
//
// Description   : 
//                              
// Comments      :      
//
// Version       : 1.6
// History       : 1.0 / 10-Nov-2004 initial version
//                 1.1 / 15-Dec-2004 removed calls to getChkSum                 
//                 1.2 / 13-Apr-2006 TM, update for FM, adopted from
//                       "PHOT_spu_setup.txt"
//                 1.3 / 28-mar-2007 DAC Update for SPUv13
//                 1.4    4-apr-2007 SCM back to zero
//                 1.5   10-apr-2007 SCM back to 1
//                 1.6   11-apr-2007 SCM back to 0
//                 1.7   16-jun-2007 SCM back to 1
//                 1.8   24-mar-2009 DAC Updated per SPU UM 13.95a
// 
procedure PACS_Phot_SPU_Setup {
}{
    // comp_mode_blue  integer  2  Compression blue: default=0, double=1, half=2, lossless=4, transp=7, buffer=9
    // comp_mode_red  integer  2  Compression red: default=0, double=1, half=2, lossless=4, transp=7, buffer=9
    // spus_nraw  integer  3  Enter Number of raw channels transmitted by SPUS
    // spul_nraw  integer  3  Enter Number of raw channels transmitted by SPUL
    int comp_mode_blue = 0;
    int comp_mode_red = 0;
    int spus_nraw = 0;
    int spul_nraw = 0;
    //--------------------
    // Preparation
    //--------------------
    // PC037400 "SPUS_STOP_REDUCT_COMPR" STOP THE APPLICATION PROGRAM IN SPU_SWL
    Pacs_SPUS_STOP_REDUCT_COMPR();
    delay(1);
    // PC038390 "SPUL_STOP_REDUCT_COMPR" STOP THE APPLICATION PROGRAM IN SPU_LWL
    Pacs_SPUL_STOP_REDUCT_COMPR();
    delay(1);
    //--------------------------
    // SPU compression/reduction
    //--------------------------
    // PC175420 "DMC_WRT_SPU_TRAN_MODE" WRITE THE SPU TRASMISSION MODE
    //         Fixed GroupSize: 1, repetition: 2 
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    //set tran_mode [list \
    //               [list PP067420 $comp_mode_blue] \
    //               [list PP067420 $comp_mode_red]]
    //set chksum [getChkSum -d -32 $tran_mode]
    //eval tcsend PC175420 $tran_mode \{PP066420 $chksum\}
    //tcsend PC175420 {PP067420 0} {PP067420 0} {PP066420 12606}
    //waittime 0.5
    {int}[] list_tuple = [{comp_mode_blue},{comp_mode_red}];
    int[] list_int = [comp_mode_blue,comp_mode_red];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_SPU_TRAN_MODE(list_tuple,chksum);
    delay(1);
    //----------------------------------------
    // Setting of start index for raw channels
    //----------------------------------------
    int spus_startraw = 1;
    int spul_startraw = 1;
    //-----------------------
    // Raw channel setting
    //-----------------------
    // PC035400 "SPUS_RAW_CHAN_TRAN_MODE" RAW CHANNEL TRANSMISSION MODE FOR SPUS
    //         PP050400 "SPUS_OBS_MODE"
    //         PP051400 "SPUS_RCXNB"
    //         PP052400 "SPUS_RCX"
    // set rawblu [list {PP050400 2} \
    //                  [list PP051400 $spus_nraw] \
    //                  [list PP052400 $spus_startraw]]
    // eval tcsend PC035400 $rawblu
    // waittime 0.5 
    Pacs_SPUS_RAW_CHAN_TRAN_MODE("PHOT",spus_nraw,spus_startraw);
    delay(1);
    // PC036390 "SPUL_RAW_CHAN_TRAN_MODE" RAW CHANNEL TRANSMISSION MODE FOR SPUL
    //         PP032390 "SPUL_OBS_MODE"
    //         PP033390 "SPUL_RCXNB"
    //         PP034390 "SPUL_RCX"
    // set rawred [list {PP032390 2} \
    //           [list PP033390 $spul_nraw] \
    //           [list PP034390 $spul_startraw]]
    //eval tcsend PC036390 $rawred
    //waittime 0.5
    Pacs_SPUL_RAW_CHAN_TRAN_MODE("PHOT",spul_nraw,spul_startraw);
    delay(1);
    //-------------------------------------
    // Setup detector constants photometry
    //-------------------------------------
    // Photo "Ottensamer" block ("S" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    int ppf = 0;
    // PPP: Pre-Processing Parameter
    int ppp = 0;
    // Threshold for glitch detection in photometry
    int tfp = 1000;
    // Threshold for chopper position deviation in photometry
    int tcp = 100;
    // Glitch detection for photometry (1: no glitch detection)
    int gdfp = 1;
    // Override samples to average
    int navg = 0;
    // resolution reduction parameter 2
    int rnd = 0;
    // resolution reduction parameter 3
    int rnds = 0;
    // resolution reduction parameter 4
    int scm = 1;
    // lossless compression algoithm (0,1,2,3,4)
    int lcal = 4;
    // PACS Codec Order (3,4)
    int pcod = 3;
    // New values 13.95a
    int dpre = 0;
    int dpost = 0;
    int syncdel = 1;
    // Spare elements: 10 spare element; hardcoded as 0,0,... in operand
    // Create operand
    int[] aux = [ppf,ppp,tfp,tcp,gdfp,navg,rnd,rnds,scm,lcal,pcod,dpre,dpost,syncdel,0,0,0,0,0,0,0,0,0,0];
    int check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    {int}[] spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUS_WRT_DET_CST_PHOT(spu_par,check_sum);
    delay(1);
    // Photo "Ottensamer" block ("L" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    ppf = 0;
    // PPP: Pre-Processing Parameter
    ppp = 0;
    // Threshold for glitch detection in photometry
    tfp = 1000;
    // Threshold for chopper position deviation in photometry
    tcp = 100;
    // Glitch detection for photometry (1: no glitch detection)
    gdfp = 1;
    // Override samples to average
    navg = 0;
    // resolution reduction parameter 2
    rnd = 0;
    // resolution reduction parameter 3
    rnds = 0;
    // resolution reduction parameter 4
    scm = 1;
    // lossless compression algoithm (0,1,2,3,4)
    lcal = 4;
    // PACS Codec Order (3,4)
    pcod = 3;
    // New values 13.95a
    dpre = 0;
    dpost = 0;
    syncdel = 1;
    // Spare elements: 10 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfp,tcp,gdfp,navg,rnd,rnds,scm,lcal,pcod,dpre,dpost,syncdel,0,0,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUL_WRT_DET_CST_PHOT(spu_par,check_sum);
    delay(1);
    //--------------------
    // Send time stamps
    //--------------------
    // PC148420 "DMC_WRT_TIME" WRITE THE TIME SENT BY THE DPU INTO THE DMC BUFFER
    //         Fixed GroupSize: 1, repetition: 2
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // PC007380 "DPU_SEND_TIME" DPU SENDS THE TIME TO DEC/MEC
    Pacs_DPU_SEND_TIME();
    delay(1);
    // PC077420 "DMC_SET_TIME" SET THE TIME PREVIOUSLY WRITTEN BY THE WRITE TIME COMMAND
    // tcsend PC077420
    // waittime 0.5
    Pacs_DMC_SET_TIME();
    delay(1);
    //----------------------------
    // Start reduction/compression
    //----------------------------
    // SPUS-START-REDUCT-COMPR
    // tcsend PC039400
    // waittime 0.5
    Pacs_SPUS_START_REDUCT_COMPR();
    delay(1);
    // SPUL-START-REDUCT-COMPR
    // tcsend PC040390
    // waittime 0.5
    Pacs_SPUL_START_REDUCT_COMPR();
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
//
// Purpose	 : SFT in Open Loop Mode (warm conditions)
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : SFT warm for FM1 chopper in open-loop mode. All 3 coils are
//                 operative. The chopper is commanded between -20 mA and +20mA
//                 in steps of 4 mA.
//                 The first part consists of chopper deflections equivalent to
//                 commanded chopper coil currents between 0 and +/-20 mA,
//                 alternating between positive and negative values. Absolute
//                 position commanding is used.
//                 The second part consists of a ramp of chopper deflections
//                 between -20 and +20 mA, commanded in relative steps of 4 mA.
//                 Finally, the chopper returns to its zero position.
//                  
// Dependencies  : 
//
// Preconditions : PACS switched-on in spectroscopy mode, chopper is switched
//                 off and disabled, diagnostic HK not running
//                 
// Comments	 : Adapted from PACS_Chopper_SFT_Cold_OpenLoop_OBS.cus
//
// Version	 : 1.0
// 
// History 	 : 1.0 12-03-07 creation by MN
// 		 : 2.0 13-02-08 Made into a proc to be called by 
//		   "obs" PacsEng_Chpper_SFT_Warm_OpenLoop
obs PacsEng_Chopper_SFT_Warm_OpenLoop {
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Chopper_SFT_Warm_OpenLoop()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Chopper_SFT_Warm_OpenLoop();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id
// Missionphase		: PACS PV Phase
//
// Purpose :		Fully flexible spectrometer calibration block during PacsSlew
// Author		 : P Royer
//
// Arguments		:
//
// Prerequisite 	: 
//
// Description		: Uses OBCP 35 and performs AOT prologue and epilogue
// 
// Comments		:
//
// Dependencies		: CONF_SPEC_params : The detector biases are read from column "Normal0"
//
// Version		: 1.1
// 
// History		:  1.0 08-May-2009 PR Creation from PacsCal_PacsSpecSlewCal35_Flex v1.1
//		   1.1 23-Jul-2009 PR add parameter initial_delay (see also PacsSpecSlewCal35_Flex). SPR PACS-1857
//                                                   29-Jul-2009 PR update history : last change referred to SPR PACS-1857 (SCR PHS-1128)
//
obs PacsCal_PacsSpecSlewCal35_Flex_Raster {
    /* Needed variables to call PacsSpecSlewCal */
    /* FW, WAVELENGTH & OBCP parameters */
    double[] waves = [60.0]; // Wavelengths
    int order = 2;
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int nb_up_dn = 1; //       	     nb_up_down  	   	OBCP35,DMC19 P#1
    int nb_grat_steps = 16; //	     nb_grating_steps  	   	OBCP35,DMC19 P#2
    int nb_cycles_grat = 2; //	     nb_chop_cycles_per_gratpos OBCP35,DMC19 P#4
    int nb_ramps_grat_pos = 1; //nb_ramps_per_gratpos  		OBCP35,DMC19 P#6
    int initial_delay = 30; // Fixed delay (for drifts) at the start of the OBCP (added to grat_(start)_time)
    bool no_gratmove = false; // false: gratstep read from CALU. True: gratstep forced to 0
    /* CRE & SPU PARAMETERS */
    int capa_blu = 12;
    int capa_red = 12;
    int nb_rdouts_ramp_blu = 64;
    int nb_rdouts_ramp_red = 64;
    int nb_rdouts_subramp_blu = 16;
    int nb_rdouts_subramp_red = 16;
    int ramp_fit_alg_blu = 1;
    int ramp_fit_alg_red = 1;
    int nb_raw_blu = 3;
    int nb_raw_red = 3;
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    /* POINTING PARAMETERS */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double ra = 0.0; // RA  [deg]
    double dec = 0.0; // DEC [deg]
    bool fixed = false; // Orientation constraint. True: fixed on sky. False: relative to instrument boresight (see patt)
    double patt = 0.0; // Angle from North (fixed=true) or from z-axis (fixed=false). Counterclockwise [deg]
    double yoffset = 0.0; // yoffset wrt boresight @ra&dec or naifid [arcsec]
    double zoffset = 0.0; // xoffset wrt boresight @ra&dec or naifid [arcsec]
    int m = 5; // Number of pointings in each raster line
    int n = 1; // Number of raster lines
    double d1 = 90.0; // Distance between pointings on one raster line [arcsec]
    double d2 = 0.0; // Distance between two raster lines             [arcsec]
    /* POINTING PARAMETERS SPECIFIC TO OFF POSITION => Don't use ... */
    int k = 0; // Number of pointings between visists to OFF (0 = no OFF; otherwise must be in [2,m*n])
    double raoff = 0.0; // RA  for OFF position
    double decoff = 0.0; // DEC for OFF position
    bool verbose = true;
}{
    // FIXED CRE & SPU Parameters
    int glitch_det_blu = 1;
    int glitch_det_red = 1;
    int bias_d_blu_mV = ilookup("CONF_SPEC_params","bias_d_blu","Normal0");
    int bias_d_red_mV = ilookup("CONF_SPEC_params","bias_d_red","Normal0");
    int bias_r_blu_mV = ilookup("CONF_SPEC_params","bias_r_blu","Normal0");
    int bias_r_red_mV = ilookup("CONF_SPEC_params","bias_r_red","Normal0");
    // FIXED OBCP Parameters
    // OBCP35 DMC19 P#3
    string order_str = "" + order;
    int grat_step_up = ilookup("SPEC_BAND_params",order_str,"HI");
    if(no_gratmove) {
        grat_step_up = 0;
    }
    // OBCP35,DMC19 P#11
    int grat_step_dn = -1 * grat_step_up;
    // OBCP35,DMC19 P#5 == P#9
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","SPEC","pos_CS1");
    // OBCP35,DMC19 P#7 == P#10
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    // OBCP35,DMC19 P#8
    int nb_cycles_cal = 0;
    // Synchronize on this detector 1:Blue 2:Red
    int detector = 1;
    // Chopped default position
    int chop_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int grat_pos = grat_park;
    // PacsSpecSlewCal_Flex parks the grating already
    //
    // computing time for slw / calibration during slew time and others
    // Verification for grating and chopper hard limits
    //double chopthrow = 30.0;
    //int[] gratpos = [0];
    //Pacs_HardLimitsCheck(gratpos,chopthrow);
    // Calibration time during slew
    // SPEC parameters for BLU and RED    
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{capa_blu,nb_rdouts_ramp_blu,nb_rdouts_subramp_blu,comp_mode_blu,glitch_det_blu,ramp_fit_alg_blu,nb_raw_blu,bias_r_blu_mV,bias_d_blu_mV}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{capa_red,nb_rdouts_ramp_red,nb_rdouts_subramp_red,comp_mode_red,glitch_det_red,ramp_fit_alg_red,nb_raw_red,bias_r_red_mV,bias_d_red_mV}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{nb_up_dn,nb_grat_steps,grat_step_up,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,nb_cycles_cal,detector,chop_def}];
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    //
    //Execute the pointing request
    bool execute = true;
    //Initial hold
    int tih = duration(WriteOBSID($OBSID));
    int tslewmin = 0;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int tepilog = duration(SPEC_aot_epilogue(grat_pos,grat_park,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(PacsSpecSlewCal35_Flex(verbose,confSPECblu,confSPECred,confOBCP,initial_delay,doPROLOG,waves,fltPOS,order));
    if(verbose) {
        debug_print("Duration of PacsSpecSlewCal_Flex" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    // Time to spend at OFF position (if any)
    int top = 0;
    if(k >= 1) {
        top = tp;
        debug_print("");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,k,top,raoff,decoff);
    debug_print("ts: " + ts);
    //
}{
    //int nbObs = 0;
    int nbOFF = 0;
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            int tNOW = time();
            // 
            WriteOBSID($OBSID);
            data_rate(120.0);
            if(verbose) {
                debug_print("WriteOBSID at :" + tNOW + " sec");
            }
            tNOW = time();
            if(verbose) {
                debug_print("WriteOBSID ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                tNOW = time();
                PacsSpecSlewCal35_Flex(verbose,confSPECblu,confSPECred,confOBCP,initial_delay,doPROLOG,waves,fltPOS,order);
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 4) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF starts at: " + tNOW);
                    }
                    //       Regular OBCP or frequency switched OBCP?
                    if(k >= 1) {
                        ///            obsTime =  
                        PacsSpecSlewCal35_Flex(verbose,confSPECblu,confSPECred,confOBCP,initial_delay,doPROLOG,waves,fltPOS,order);
                    }
                    nbOFF = nbOFF + 1;
                    //       Logic to sum up obsTime
                    ///         if (nbOFF == 1) {sumUpObsTime = obsTime;}
                    ///         if (nbOFF > 1)  {sumUpObsTime = SumFunction(obsTime,sumUpObsTime);}
                    if(verbose) {
                        tNOW = time();
                        ///          debug_print("    SumUpObsTime: " + sumUpObsTime);
                        debug_print("=== OFF ends at: " + tNOW);
                    }
                } else {
                    if(state[0] == 5) {
                        tNOW = time();
                        if(verbose) {
                            debug_print("Final Hold starts at :" + tNOW + " sec");
                        }
                        SPEC_aot_epilogue(grat_pos,grat_park,verbose);
                        data_rate(0.0);
                        WriteEndID();
                        tNOW = time();
                        if(verbose) {
                            debug_print("Final Hold ends at :" + tNOW + " sec");
                        }
                    }
                }
            }
        }
    }
    // End of Observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       :  Run a loop of tens of different sets of PID parameters
//
// Description  : For each set, performs a dozen of small and two larger movements
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
//                 1.1  13-Nov-2007 BV: added MOIS comments
//		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
obs PacsEng_Spec_Gra_IST_PID_Loop_Less {
    /* Needed variables to call PacsEng_Spec_Gra_IST_PID_Loop_Less                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_PID_Loop_Less                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Gra_IST_PID_Loop_Less()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Gra_IST_PID_Loop_Less();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: OBCP_fixed_fixed_photo.txt,v 1.6 2007/08/22 10:18:28 dcesarsk Exp $ 
// Script file   : OBCP_fixed_fixed_photo.txt
// Purpose       :
// OBCP author   : HF
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Belongs to Section 3.1: Two or three position chop PHOTO
//                 of PACS-ME-LI-005, issue 1.4
//                 This is OBCP 3.1.3, calling DMC sequence
//                 14 (in 4.1.8). DMC  performs the following chopper
//                 pattern:
//
//                 P#2      take nb_rdouts
//                 P#2+P#5  take nb_rdouts  }           }
//                 P#2+P#6  take nb_rdouts  } P#4 times }
//                                                      }
//                 P#7      take nb_rdouts              }
//                 P#7+P#5  take nb_rdouts  }           }
//                 P#7+P#6  take nb_rdouts  } P#4 times } P#1 times
//                                                      }
//                 P#8      take nb_rdouts              }
//                 P#8+P#5  take nb_rdouts  }           }
//                 P#8+P#6  take nb_rdouts  } P#4 times }
//
// TOTAL readouts (2*P#4 + 1)*3*nb_rdouts
// 
//      Usually P#6 = -P#5 so that chopper comes back to starting postion
//
// Dependencies  :
//
// Preconditions :
//
// Comments      :
//
// History       : 0.1 26-jun-2006 DAC
// 1.0 31-aug-2006 Return the TOTAL duration including TC timing
// 1.1 22-nov-2006 Removed debug_print
// 1.2 21-aug-2007 SRC-3507 Indicate end of BB
int[] block OBCP_fixed_fixed_photo PACS 3 {
    int nb_main_loops = 1; // Nb of main loops                     (P#1)
    int chop_pos_1 = -100; // First chopper position               (P#2)
    int nb_rdouts = 159; // Nb of readouts/chopper plateau       (P#3)
    int nb_chop_cycle = 2; // Nb of chopps per pair of positions   (P#4)
    int chop_throw_1 = 2000; // Chopper throw away from 1st position (P#5)
    int chop_throw_2 = -2000; // Chopper throw back to 1st position   (P#6)
    int chop_pos_2 = 0; // Second chopper position              (P#7)
    int chop_pos_3 = 100; // Third chopper position               (P#8)
    int comp_mode_blu = 0; // "Blue" compression
    int comp_mode_red = 0; // "Red" compression
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // BOL readout frequency [Hz] and readout period [msec]
    double bol_freq = dlookup("PACSparams","bolo_sample","freq_time");
    string bol_unit = slookup("PACSparams","bolo_sample","unit");
    double bol_period = 1000.0 / bol_freq;
    // debug_print("Bolo sample: " + bol_freq + " " + bol_unit);
    // debug_print("Bolo period: " + bol_period + "[msec]");
    // Obtain duration of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duration of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duration of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duree_msec [msec] as it goes)
    // Begin
    // OBCP_GRATING_Fixed_Fixed_PHOTOMETRY(seq, seq_time,
    //   P#1...P#8, cmp_par_blue, cmp_par_red)
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) ; (all parameters filled
    // by DPU based on seq parameter)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_START_SEQUENCE
    //////////////////////////////////////////////////////////////////////////
    // Call DEC/MEC code to estimate its duration
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    int[] duree1 = DMC_fixed_fixed_photo(nb_main_loops,nb_rdouts,nb_chop_cycle);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * bol_period) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * bol_period);
    duree_REF = iround(double(duree1[2]) * bol_period);
    duree_CAL = iround(double(duree1[3]) * bol_period);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * bol_period) + dmc_margin;
    //  debug_print("Execution time [msec] from DMC: " + seq_time);
    // duree_msec(seq_time)
    duree_msec = duree_msec + t_cmd + seq_time;
    // WAIT(seq_time) ; Check execution status of the sequence and in case of
    // failure stop OBCP and issue TM(1,8)+event
    // Issue TM(1,7)
    // End
    // Now trigger execution of OBCP
    // This OBCP is number 3, requires 12 parameters and calls DEC/MEC #??
    string obcp_ID = "FIXED_CHOP_PHOT";
    int obcp_par_nb = 12;
    int seq_DMC = 14;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_main_loops},{4,chop_pos_1},{5,nb_rdouts},{6,nb_chop_cycle},{7,chop_throw_1},{8,chop_throw_2},{9,chop_pos_2},{10,chop_pos_3},{11,comp_mode_blu},{12,comp_mode_red}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    //  debug_print(obcp_ID + "; duration: " + time_array);
    delay(time_array[0]);
    // Mark end of BB
    WriteEndBB();
    // Return actual duration
    time_array[0] = time() - time_start;
    // Return the array of times

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Missionphase  : PACS FMILT
//
// Purpose       : Configure the spec filter wheel for Redundant Warm
//
// Author        : PR
//
// Arguments     : 
//
// Description   : 
//                 
// Comments      :      
//
// Version       : 0.1 
// History       : 0.1  04-Jul-2007 Initial version
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//
obs PacsEng_CONF_spec_fltw_R_Warm {
    /* No variables to call PacsEng_CONF_spec_fltw_R_Warm                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POSB" */
    /* End of needed variables for PacsEng_CONF_spec_fltw_R_Warm                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_spec_fltw_R_Warm()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_spec_fltw_R_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       : Flasher curing : short flashes with dead times -> Temp & signal evolutions
//		   Third part of the Flashers Performance check (curing schemes)
//
// Author        : P. Royer
//
// Arguments     : 
//
// Prerequisite  : Flashers on
//
// Description   : Check scheme of flasher curing : short flashes with dead times
//               :
// Comments      : 
//                 
//
// Version       : 2.1
// History       : 1.0 / 09-Jun-2006 initial version by PR
//                 1.1 / 06-Apr-2007 Updated chop_pos_BB -> FMILT BB2
//		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//	2.1 01-Jul-2008 Introduced "final_delay" parameter
//		   
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.1
// @purpose Flasher curing : short flashes with dead times -> Temp & signal evolutions
// @comment - 
//
obs PacsEng_Spec_Curing_Explore {
    /* Needed variables to call PacsEng_Spec_Curing                        */
    int blue_flasher_current = 819; //4mA. [0,4095] = [0,20 mA]
    int red_flasher_current = 819; //4mA. [0,4095] = [0,20 mA]
    int nflash = 1; // Number of flashes
    int flash_time = 60; // Duration of each flash
    int idle_time = 120; // Idle time between the flashes
    int nflash_fine = 6; // Number of flashes
    int flash_time_fine = 10; // Duration of each flash
    int idle_time_fine = 60; // Idle time between the flashes
    int final_delay = 120; // Idle time at the end of the test (flasher cooldown, detector stabilisation),
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Curing                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Curing_Explore(blue_flasher_current,red_flasher_current,nflash,flash_time,idle_time,nflash_fine,flash_time_fine,idle_time_fine,final_delay)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Curing_Explore(blue_flasher_current,red_flasher_current,nflash,flash_time,idle_time,nflash_fine,flash_time_fine,idle_time_fine,final_delay);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
//
// Purpose 
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//   - 2-3 position chopping AOT with/without calibration block  ~0.50h
//    (1 filter may be sufficient)
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//                 
//
// TCL author    : N/A
// TCL file      : tN/A
// CUS author    : TM
// Script file   : PHOT_chopped_photometry_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version 	 : 1.0
// History       : 0.1 20-apr-2005 DAC
//                 0.2 25-apr-2005 DAC Filter back to POS A
//                 0.3 25-apr-2005 DAC Start/stop SPU
//                 0.4 26-apr-2005 DAC Use PACS_spu_reset  
//                 0.5 11-apr-2007 TM update for FM ILT
//		   1.0 25-mar-2008 VDP Ajusted to match PV phase syntax
procedure Pacs_Phot_chopped_photometry {
}{
    // Register with environment
    // Start SPU
    int comp_mode_blu = 0;
    int comp_mode_red = 0;
    int nraw_blu = 0;
    int nraw_red = 0;
    //
    PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,true);
    //
    // Position the filter wheel at POS A
    PHOT_fltw_move("POS A");
    //
    // Perform OBCP_chopped_photometry with default parameters
    debug_print("Start OBCP_chopped_photometry");
    int[] duree = OBCP_chopped_photometry(8,1000,19,-2000,5000,8,2,-21350,+21200,0,0,0);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    duree = OBCP_chopped_photometry(9,1000,19,-2000,5000,8,1,-21350,+21200,0,0,0);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    duree = OBCP_chopped_photometry(10,1000,19,-2000,5000,8,0,-21350,+21200,0,0,0);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    //
    // Position the filter wheel at POS B
    PHOT_fltw_move("POS B");
    //
    // Perform OBCP_chopped_photometry with default parameters
    debug_print("Start OBCP_chopped_photometry");
    duree = OBCP_chopped_photometry(8,1000,19,-2000,5000,8,2,-21350,+21200,0,0,0);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    duree = OBCP_chopped_photometry(9,1000,19,-2000,5000,8,1,-21350,+21200,0,0,0);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    duree = OBCP_chopped_photometry(10,1000,19,-2000,5000,8,0,-21350,+21200,0,0,0);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    //
    // Position the filter wheel at POS A
    PHOT_fltw_move("POS A");
    //
    // Stop SPU
    //
    PACS_spu_reset();
    // Exit environment
}

// File          : PACS_Spec_Heat_Setup.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Sets Heater currents (blue & red)
//
// Author        : P. Royer
//
// Arguments     : blue & red Heater currents
//
// Description   : Sets Heater currents (blue & red)
//               :
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 07-Jun-2006 initial version by PR
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose Sets heater currents (blue & red)
// @comment - 
//
block PACS_Spec_Heat_Setup PACS 163 {
    int blue_heat_current = 0;
    int red_heat_current = 0;
}{
    // Register start of BB
    WriteBBID($BBID);
    //
    // SETUP HEATERS
    //
    Pacs_DMC_SET_B_SPEC_HEAT_C_RAW(blue_heat_current);
    delay(1);
    Pacs_DMC_SET_R_SPEC_HEAT_C_RAW(red_heat_current);
    delay(1);
    //
    // End of procedure
    //------------------
    // Mark End of Block
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose	: Start Diag. HK Special for Jürgen
//                  
// Author	: Markus Nielbock
// CUS author 	: MN
//
// Description	: 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 2.0	
// 
// History 	: 1.0 MN 29-03-07. Call special HKs. 
// 		: 2.0 04-mar-2008 translated into PV script VDP
//
obs PacsEng_Spec_Chopper_dhk_5hk_1khz {
    /* Needed variables to call PacsEng_Spec_Chopper_dhk_5hk_1khz                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Chopper_dhk_5hk_1khz                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_Chopper_dhk_5hk_1khz_bb()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_Chopper_dhk_5hk_1khz_bb();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
//
// Purpose 
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//- Staring measurement on one calibration source for low frequency
//  noise TM, DC (CUS, tcl)
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
// TCL author    : N/A
// TCL file      : N/A
// CUS author    : DAC
// Script file   : PHOT_low_freq_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version	 : 1.0
// History       : 0.1 27-apr-2005 DAC
// 		  0.2 29-apr-2005 DAC 90 min in one filter (rather than 2x45 min on two filters
// 		  0.3 26-oct-2005 DAC Move chopper back to zero
// 		  0.4 11-apr-2007 TM update for FM
//		  1.0 04-mar-2008 translated into PV script VDP
//
obs PacsEng_Phot_low_freq {
    /* Needed variables to call PacsEng_Phot_low_freq                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_low_freq                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Phot_lowFreq_DDCS_IST("cs2",2000,"BOLObias_ILT_lowFreq_CS2")));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Phot_lowFreq_DDCS_IST("cs2",2000,"BOLObias_ILT_lowFreq_CS2");
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : Staring photometry 
//                 DMC Seq. 3 for OBCP 7
//             
//
// Author        : Helmut Feuchtgruber
// CUS script    : Thomas G. Mueller
// CVS file      : 
//
// Arguments     : 
//             nb_loops          Number of loops with 2 sec integration time each
//
// Description :  No operation of mechanisms, only a defined loop through a
//                specified number of bolometer readouts. Therefore this is
//                composed of a rather trivial and short sequence code. This
//                sequence will be used during nominal Line Scan observations.
//                Calibration cycles on the internal calibration sources may
//                be done before, after and at the turn-over points of the
//                spacecraft scans, by 4.1.5.
//                Sequence duration in readouts: 2 + p#1 * 40
//
// Dependencies  : Stand alone DEC/MEC sequence  
//             
// Comments      : Follows line by line 4.1.3 in PACS-ME-LI-005
//
// Version       : 1.0 13-Apr-2005 Creation by TM
// History       : 
//           :
int[] procedure DMC_phot_staring {
    int nb_loops = 60; // p01 Number of loops with 2 sec integration time each
}{
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Start tallying the duration (measured in number of readouts)
    int duration_rdouts = 0;
    // WAIT 1 ; have a defined start 
    duration_rdouts = duration_rdouts + 1;
    duree_SRC = duree_SRC + 1;
    // LABEL 0 ; set Label to 0 
    // WAIT 1 ; have a defined start 
    duration_rdouts = duration_rdouts + 1;
    duree_SRC = duree_SRC + 1;
    // LOOP P#1 
    for(int staring_loop = 1 .. nb_loops) {
        // LABEL 1 ; start of quadruple 
        // WAIT 40 ; shortest time = 1 sec 
        duration_rdouts = duration_rdouts + 40;
        duree_SRC = duree_SRC + 40;
        // END_LOOP 
    }
    // LABEL 0 ; no sequence anymore 
    // END_SEQUENCE
    // Define return array
    int[] time_array = [duration_rdouts,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    debug_print("DMC_phot_staring: " + time_array);
    // Return the array of times

    return time_array;
}

// File          : PACS_Spec_Gra_Ampl_Open_Loop
// Missionphapse  : PACS FM Test
//
// Purpose       : Performs the determination of the optimal grating inductosyn amplitude in open loop
//
// Author        : P. Royer
// Arguments     : 
//
// Description   : Loops over inductosyn amplitudes and performs a +-10 degrees updown movement for each value
//
// Prerequisite :  CONF_grating_DEGMODE
//
// Version       : 1.0
// History       : 1.0 / 02-Mar-2007 PR Creation
//
procedure PACS_Spec_Gra_Ampl_Open_Loop {
}{
    int[] ampllist = [1000,1050,1100,1125,1150,1175,1200,1250,1300];
    int nsteps = length(ampllist) - 1;
    {int}[] list_tuple = [];
    int[] list_int = [];
    int chksum = 0;
    int ampl = 1100;
    //
    for(int n = 0 .. nsteps) {
        ampl = ampllist[n];
        list_tuple = [{ampl}];
        list_int = [ampl];
        chksum = checksum("int",list_int);
        Pacs_DMC_WRT_GRAT_INDUC_AMPL(list_tuple,chksum);
        delay(180);
        //
        Pacs_DMC_MOVE_GRAT_REL_RAW(2730);
        delay(20);
        Pacs_DMC_MOVE_GRAT_REL_RAW(-2730);
        delay(20);
        //
    }
}

/////////////////////////////////////////////////////////////////////////////
/// $Id: PacsPhoto.def,v 1.69 2008/05/14 11:10:32 vanessa Exp $ 
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsPhoto AOT
// CUS author    : DAC
// Script file   : PacsPhoto.def
// Return values
// Description   : 
// This AOT has to cater to three different source morphologies:
// "point", "small", and "large". Each mode requires its own pointing modes.
// Available pointing modes (reference is to JBr's document):
// NOTE: All modes include operations during SLEW and operations at end of OBS.
// NOTE: Updated based on e-mail from MS dated 3-Dec-2005 (denoted UPDATE)
// NOTE: Updated after Saclay meeting
// ==== "point"
// no nodding                         2.1  fine_pointing
// nodding (includes "hold" periods)  3.4  nodding_pointing
// UPDATE: Nodding is always needed ==> eliminate fine_pointing
//
// ==== "small"
// (raster dimensions and steps TBD; expect 2x2 or 3x3)
// no nodding ("hold" periods and repetition) 2.13 repeated_raster_with_hold
// nodding ("hold" periods and no repetition) 2.12 nodding_in_raster
// UPDATE: Nodding always used ==> nodding_in_raster
//
// ==== "large"
// Can be RASTER or SCAN (freeze mode is based upon a SCANning PointMode)
// RASTER
// no nodding ("hold" periods and repetition) 2.13 repeated_raster_with_hold
// nodding ("hold" periods and no repetition) 2.12 nodding_in_raster
// UPDATE: Nodding not used ==> raster_pointing
//
// SCAN
// There is no nodding and no chopping. "Hold" periods are allowed (mode 2.14) 
// Leg length is restricted to 20 degrees.
//
// Dependencies  : 
//
// Preconditions : 
//
// Comments      : Almost identical to PacsPhoto. Maid differences:
//                 - accept (from XHspot) the following variables:
//                   - nholdIN User defined "nhold", overrides CAL values
//                   - confphotoparams Non-standard CONF_PHOTOparams CAL file
//                   - obcpparams Non standard OBCP3params (point source) or 
//                     OBCP4params (small source) CAL files
//                 - Calls two PV dedicated AOT scripts (search _PV in code).
//                   These scripts accept confphotoparams and obcpparams  
// 
// History       : 0.1  19-may-2008 DAC PV version based on PacsPhoto.def
//                 - Added name of OBCP3params and CONF_PHOT_params files as
//                   input parameters. Activated "nhold" logic
//                 0.2 20-may-2008 DAC
//                 -  Mostly editorial changes (useful for the AOT version
//                    as well)
//                 0.3 21-may-2008 DAC
//                  - Make nhold an input variable, ignore values in CAL files
//                    (not for the AOT version, where "nhold" in CAL files
//                     seems more adequate)  
//		   0.4 23-apr-2009 VD SPR 6482
//		   1.0 VD/TM SCR 1292: no OBCP running during scan legs: only
//                        WriteBBID and OBCP2 then delayed WriteEndID
//                 1.1 29-jul-2009 VD remove OBCP2 keep BBID write: PACS-1845
//                 1.2 23-sep-2009 VD PACS-1292
//
{int,int,int,double,{string,double,double,double,double,double,double}[]} obs PacsCal_PacsPhoto {
    string blue = "blue1" in ["blue1","blue2"];
    int repFactor = 1 in [1,1500]; // Repeat factor: i.e. nb of nods or rasters
    int nholdIN = 0; // nhold for current pointing mode, replaces CAL values
    string source = "point" in ["point","small","largeRaster","largeScan","none"]; // SrceSize
    string confphotparams = "CONF_PHOT_params"; //gain and comp_mode CAL file
    string obcpparams = "OBCP3params"; //Chop frequency, etc. CAL file 
    string mapScanSpeed = "high" in ["high","medium","low"]; // Scan rate
    double mapScanLegLength = 30.0 in [1.0,1200.0]; //Scan leg [arcmin]
    int mapScanNumLegs = 2 in [1,1500]; //Number of scan legs
    string mapScanAngleRef = "inst" in ["sky","inst","i+c","s+c"];
    double mapScanConstrFrom = 0.0 in [0.0,360.0];
    double mapScanConstrTo = 0.0 in [0.0,360.0];
    double mapScanAngle = 0.0 in [0.0,360.0];
    double mapScanCrossScan = 2.0 in [2.0,480.0]; // Scan separation [arcsec]
    bool mapScanHomCoverage = true;
    bool mapScanSquare = false;
    double pointStep = 2.0 in [2.0,480.0];
    double lineStep = 2.0 in [2.0,480.0];
    string mapRasterAngleRef = "inst" in ["inst","i+c"];
    double mapRasterConstrFrom = 0.0 in [0.0,360.0];
    double mapRasterConstrTo = 0.0 in [0.0,360.0];
    int m = 2 in [2,100];
    int n = 1 in [1,100];
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    bool dither = false;
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    double raoff = 0.0 in [0.0,360.0]; // RA OFF pos.
    double decoff = 0.0 in [-90.0,90.0]; // DEC OFF pos.
    bool refSelected = false; // OFF pos. needed
    int naifid = 0; //RA,DEC or SSO
    double fluxPntBlu = 116.0 in [0.0,2.0E7]; // Flux density in blue band mJy
    double fluxPntRed = 150.0 in [0.0,2.0E7]; // Flux density in red band mJy
    double fluxExtBlu = 116.0 in [0.0,2.0E7]; // Flux in blue band MJy/sr
    double fluxExtRed = 40.0 in [0.0,2.0E7]; // Flux in red band MJy/sr
    int obsOverhead = 180; // Slew overhead
    /* End of input section */
}{
    // Begin "pointing" section
    // Overall "verbosity"
    bool verbose = true;
    // New nodding_pointing variable
    bool startAtOFF = false;
    // Conversion to deprecated variables
    bool noddingSel = true;
    if(source == "largeRaster") {
        string largeOptions = "raster";
        bool mapRasterSel = true;
        noddingSel = false;
    }
    if(source == "largeScan") {
        largeOptions = "scan";
        mapRasterSel = false;
        noddingSel = false;
    }
    int mapRasterNumCycles = repFactor;
    // Useful variables
    // Bolo size: Short Size, i.e. 32 pixels and Long Size [arcsec]
    double boloSSize = 1.75 * 60.0;
    double boloLSize = 3.5 * 60.0;
    double boloArea = boloSSize * boloLSize;
    // 
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // Pointing mode has not been established yet
    int pointCase = 0;
    // Determine the pointing mode
    if(source == "point") {
        //     Variable needed to obtain choper throw from CAl-U
        string srcID = "pointSRC";
        //     Just for completiness, define a 1x1 raster
        m = 1;
        n = 1;
        //     Fine pointing without nodding is disallowed (pointCase remain null)
        if(!noddingSel) {
            string pointMode = "basic_fine_pointing";
            string shortDesc = "Point source (no nodding)";
            // not allowed           pointCase        = 11;
        } else {
            pointMode = "nodding_pointing";
            shortDesc = "Point source (nodding and chopping)";
            pointCase = 12;
            string yzoffsetROW = "P" + pointCase;
        }
    }
    if(source == "small") {
        srcID = "smallSRC";
        //   Obtain the size of the raster from CAL-U "SMALL_SRC_params"
        m = ilookup("SMALL_SRC_params","PHOT","mRast");
        n = ilookup("SMALL_SRC_params","PHOT","nRast");
        pointStep = dlookup("SMALL_SRC_params","PHOT","pointStep");
        lineStep = dlookup("SMALL_SRC_params","PHOT","lineStep");
        if(!noddingSel) {
            pointMode = "raster_pointing";
            shortDesc = " Small source (no nodding)";
            //         not allowed
            //           pointCase = 21;
        } else {
            pointMode = "nodding_raster_pointing";
            shortDesc = "Small source (nodding and chopping)";
            pointCase = 22;
            yzoffsetROW = "P" + pointCase;
        }
    }
    // Large source in Raster Mode
    if(source == "largeRaster") {
        srcID = "largeSRC";
        if(!noddingSel) {
            pointMode = "raster_pointing";
            shortDesc = "Large source, raster mode (chopping and no nodding)";
            pointCase = 31;
            yzoffsetROW = "P" + pointCase;
        } else {
            pointMode = "nodding_in_raster";
            shortDesc = "Large source, raster mode (chopping and nodding)";
            //         not allowed
            //           pointCase = 32;
        }
    }
    // Large source in Scan Mode
    if(source == "largeScan") {
        srcID = "largeSRC";
        pointMode = "line_scan_pointing";
        shortDesc = "Large source, line scan mode (no chopping)";
        //     For consistency
        m = 1;
        n = mapScanNumLegs;
        pointCase = 33;
        yzoffsetROW = "P" + pointCase;
    }
    // If pointCase is still 0, then something went wrong with the PointMode logic...
    if(pointCase == 0) {
        error("NODDING is incompatible with source: " + source);
    }
    // The pointing mode has been established. Continue with other input data
    // from HSPOT
    if(verbose) {
        debug_print("================> PointMode: " + pointMode);
    }
    //
    // confPHOT arrays (red and blu) compared to confSPEC
    //                       PHOT name         SPEC name
    // confPHOTred{ 0}       gain              capa_red;
    // confPHOTred{ 1}       N/A               nb_rdouts_ramp_red;
    // confPHOTred{ 2}       N/A               nb_rdouts_subramp_red;
    // confPHOTred{ 3}       same              comp_mode_red;
    // confPHOTred{ 4}       same              glitch_det_red;
    // confPHOTred{ 5}       ??                ramp_fit_alg_red;
    // confPHOTred{ 6        ??                nb_raw_red;
    // confPHOTred{ 7}       N/A               bias_r_red;
    // confPHOTred{ 8}       N/A               bias_d_red;
    //
    // Define confOBCP array.
    // NOTE: the conf arrays are inherited from PacsSpec, where the [0] element
    // represented the default values, and the [n] element represented values
    // to be used with the n-th wavelength. Here - PHOT - [0] still represents
    // the default values and [1] values corresponding to the chosen filter.
    // Could even use [1] and [2] for blue1 and blue2.... but will not!
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confPHOTblu and confPHOTred
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,0,0,0,0,0,0,0,0}];
    // Define paramsPHOT, a "tuple of tuples"
    // Estimator module returns {confPHOTblu,confPHOTred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // including a new section for Low Gain implementation SCR4196
    bool isBrightPacs = false;
    string calUFile = "isBrightPacsTrigger";
    // section defining triggering Fluxes (to be read in CALU table)
    double fluxPntRedTriggerLowGain = dlookup(calUFile,"Red","fluxPntTrigger");
    if(blue == "blue1") {
        double fluxPntBluTriggerLowGain = dlookup(calUFile,"Blue","fluxPntTrigger");
    } else {
        if(blue == "blue2") {
            fluxPntBluTriggerLowGain = dlookup(calUFile,"Green","fluxPntTrigger");
        }
    }
    double fluxExtRedTriggerLowGain = dlookup(calUFile,"Red","fluxExtTrigger");
    if(blue == "blue1") {
        double fluxExtBluTriggerLowGain = dlookup(calUFile,"Blue","fluxExtTrigger");
    } else {
        if(blue == "blue2") {
            fluxExtBluTriggerLowGain = dlookup(calUFile,"Green","fluxExtTrigger");
        }
    }
    // section test 
    if(fluxPntRedTriggerLowGain <= fluxPntRed || fluxPntBluTriggerLowGain <= fluxPntBlu || fluxExtRedTriggerLowGain <= fluxExtRed || fluxExtBluTriggerLowGain <= fluxExtBlu) {
        isBrightPacs = true;
    }
    // Obtain default values for "Prime" mode
    // DAC WARNING: using PV dedicated PacsPhotoDefaults script (not for AOT)
    paramsPHOT = PacsPhotDefaults_PV(srcID,"Prime",confphotparams,isBrightPacs,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    confPHOTred[0] = paramsPHOT{1};
    confOBCP[0] = paramsPHOT{2};
    // Now comes the module to estimate PACS parameters as a function of the
    // exposure time given by the user.
    // paramsPHOText (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,repeat_factor,nhold,dummy2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsPHOText = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for given HSPOT input. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("++Photo: confOBCP[0]: " + confOBCP[0]);
    }
    // DAC WARNING Using PV dedicated PacsPhotEstimatorOBCPn script (not for AOT)
    paramsPHOText = PacsPhotEstimatorOBCPn_PV(pointCase,blue,obcpparams,repFactor,paramsPHOT,noddingSel,dither,verbose);
    // Copy estimates to respective tuples
    confPHOTblu[1] = paramsPHOText{0};
    confPHOTred[1] = paramsPHOText{1};
    confOBCP[1] = paramsPHOText{2};
    int nb_nods = paramsPHOText{3}{0};
    int repeat_factor = paramsPHOText{3}{1};
    //DAC "nhold" is obtained as an input variable (not for AOT!!)
    int nhold = nholdIN;
    /////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source.
    // We have to collect the duration of all TCs that will be released after the
    // PointingRequest 
    // First TC is associated with setting OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // Will call PacsPhotSlewCal to perform AOT prologue and CAL during
    // slew (with prologue):
    bool doProlog = true;
    int timeSlewCalProlog = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue));
    if(verbose) {
        debug_print("Duration of SlewCalProlog: " + timeSlewCalProlog);
    }
    // Cal during "hold" cycles" (no prologue)
    doProlog = false;
    int timeSlewCal = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue));
    if(verbose) {
        debug_print("Duration of SlewCal: " + timeSlewCal);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsPhotCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsPhotCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // Duration of any nod leg or staring observation
    // Use OBCP3 for point source
    // Use OBCP4 for all others, except scan mode
    if(pointCase == 11 || pointCase == 12) {
        int timeOBS = duration(PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        if(verbose) {
            debug_print("TimeOBS OBCP3: " + timeOBS);
        }
    }
    if(pointCase == 22 || pointCase == 31) {
        timeOBS = duration(PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        if(verbose) {
            debug_print("TimeOBS OBCP4: " + timeOBS);
        }
    }
    if(pointCase == 33) {
        //    Estimate how long OBCP7 has to run to cover a scan leg
        //    Scan speed (CAL-U FILE in new version??). Default is "low": 10 arcsec/sec
        double rate = 10.0;
        if(mapScanSpeed == "medium") {
            rate = 20.0;
        }
        if(mapScanSpeed == "high") {
            rate = 60.0;
        }
        double timeLEG = mapScanLegLength * 60.0 / rate;
        int tWrite = duration(PacsBbWriteIdBB());
        int tWriteEnd = duration(PacsBbWriteEndBB());
        //     int timeSetOBCP2 = duration(OBCP_TimeSynch3());
        timeOBS = iceil(timeLEG);
    }
    if(verbose) {
        debug_print("confOBCP[1]: " + confOBCP[1]);
        debug_print("==> Duration OBCP: " + timeOBS + " [sec] per nod; pointCase: " + pointCase);
    }
    // Finally deal with PHOT_aot_epilogue and WriteEndID
    int timeEpilogue = duration(PacsBbPhot_aot_epilogue());
    int timeEndID = duration(WriteEndID());
    timeEpilogue = timeEpilogue + timeEndID;
    if(verbose) {
        debug_print("Duration aot_epilogue: " + timeEpilogue);
    }
    // We have all elements to issue a Pointing Request and generate TCs
    // - duration of SlewCAL
    // - duration of OBS (one pointing)
    // - nb of nods or nb of raster points
    // - nhold
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    //  The nodding step has been estimated already (PacsPhotDefaults). However,
    //  there are no provisions to carry that information here. Easiest is to
    //  read again the relevant CAL-U table
    //  Read nod amplitude [arcsec]
    double nodThrow = dlookup("PHOT_CHOP_params",srcID,"NOD");
    int max_dither = confOBCP[1]{1};
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("TimeSlewCal   : " + timeSlewCal);
        debug_print("TimeOBS       : " + timeOBS);
        debug_print("m/n           : " + m + "/" + n);
        debug_print("nb_nods/repeat_factor/nhold: " + nb_nods + "/" + repeat_factor + "/" + nhold);
        debug_print("NOD amplitude for " + srcID + ": " + nodThrow + " [arcsec]");
        int chpSRC = confOBCP[1]{12};
        int chpREF1 = confOBCP[1]{13};
        int chpREF2 = confOBCP[1]{14};
        debug_print("#### CHOP SRC/REF1/REF2: " + chpSRC + "/" + chpREF1 + "/" + chpREF2);
        debug_print("CHOP dither: " + max_dither);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Issue pointing request
    // Virtual aperture
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("##Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("##skewCorrec : " + skewCorrec);
    }
    // SCAN/RASTER orientation for "scan map" and "chopped raster"
    // RASTER defines mapRasterAngleRef   = "inst" in ["inst", "i+c"];
    // SCAN defines   mapScanAngleRef = "sky" in ["sky", "inst", "s+c", "i+c"]; 
    // By default S/C moves in instrument coordinates
    bool useINST = true;
    if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
        useINST = false;
    }
    // Act according to pointCase
    // POINT source, i.e. 3.4 nodding_pointing
    if(pointCase == 12) {
        //  Issue pointing request (when possible use JBr's variable names for clarity)
        //  SlewCal during slew
        string ib = "P01_0";
        int tslewmin = timeSetOBSID + timeSlewCalProlog;
        int tih = 0;
        int tfh = timeEpilogue;
        bool fixed = false;
        double pattnod = 0.0 + skewCorrec;
        int nnods = nb_nods;
        int tp = timeOBS;
        int tloadslewmin = 0;
        int nload = 0;
        int thold = timeSlewCal;
        //  int nhold        Already defined
        //  Do not start at nod position
        startAtOFF = false;
        int[] fromPntReq = nodding_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nnods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
        if(verbose) {
            debug_print("##### nodding_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tss = fromPntReq[2];
        tload = fromPntReq[3];
    }
    // SMALL source or LARGE raster with nodding
    if(pointCase == 22 || pointCase == 32) {
        //  "nodding_raster_pointing" (3.6 in Pointing document)
        ib = "P01_0";
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        tih = 0;
        tfh = timeEpilogue;
        double patt = 0.0;
        //  Chopper moves along -Y-axis
        pattnod = 270.0 + skewCorrec;
        //  Chop nodThrow was already established
        //  nodThrow = From CAL-U table
        int k = 0;
        fixed = false;
        int nrepeat = repeat_factor;
        double d1 = pointStep;
        double d2 = lineStep;
        thold = timeSlewCal;
        tp = timeOBS;
        nnods = nb_nods;
        //  New arguments for pointing request; will be dealt with next iteration
        int top = 0;
        raoff = 0.0;
        decoff = 0.0;
        nrepeat = repeat_factor;
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nnods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
        if(verbose) {
            debug_print("##### nodding_in_raster_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
    }
    // SMALL or LARGE source with no nodding 
    if(pointCase == 21 || pointCase == 31) {
        //  raster_pointing (mode 3.5)
        ib = "P01_0";
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        tih = 0;
        tfh = timeEpilogue;
        //  Perform raster in instrument coordinates
        fixed = false;
        //SPR-2431 Raster lines along y-axis
        patt = 90.0;
        d1 = pointStep;
        d2 = lineStep;
        tp = timeOBS;
        nrepeat = repeat_factor;
        thold = timeSlewCal;
        ///DAC From CAL file    nhold   = 0;
        k = 0;
        top = 0;
        raoff = 0.0;
        decoff = 0.0;
        fromPntReq = raster_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
        if(verbose) {
            debug_print("##### raster_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        trep = fromPntReq[4];
        tsop = fromPntReq[5];
    }
    if(pointCase == 33) {
        //   line_scan_pointing. Keep (most of) JBr's variable names
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        // Scan speed (CAL-U FILE in new version??). Default is "low": 10 arcsec/sec
        rate = 10.0;
        if(mapScanSpeed == "medium") {
            rate = 20.0;
        }
        if(mapScanSpeed == "high") {
            rate = 60.0;
        }
        //  Case of homogeneous coverage
        double pi = 3.1415926535;
        //  degrees to radians    
        double dtor = 0.0;
        double rtod = 0.0;
        double halfDiag = 0.0;
        double halfDiagAngle = 0.0;
        dtor = 2.0 * pi / 360.0;
        rtod = 1.0 / dtor;
        halfDiag = sqrt(boloSSize * boloSSize + boloLSize * boloLSize) / 2.0;
        halfDiagAngle = atan(boloSSize / boloLSize) * rtod;
        // Add further constraint from RV (SPR-2889)
        // Add SPR-2699 further logic: mapScanAngleRef overrides ScanHom and ScanSquare
        if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
            mapScanHomCoverage = false;
            mapScanSquare = false;
        }
        //  Could simplify logic after SPR-2699 (mapScanHomCoverage cannot be true
        //  unless inst or i+c have been specified)
        if(mapScanHomCoverage == true && (mapScanAngleRef == "inst" || mapScanAngleRef == "i+c")) {
            mapScanCrossScan = halfDiag * (abs(sin(dtor * (mapScanAngle + 90.0 - halfDiagAngle))) + abs(cos(dtor * (90.0 - halfDiagAngle - mapScanAngle + 90.0))));
            if(verbose) {
                debug_print("New mapScancCross: " + mapScanCrossScan);
            }
        }
        // Case of square map request
        if(mapScanSquare == true && mapScanHomCoverage == true) {
            mapScanNumLegs = iceil(60.0 * (mapScanLegLength / mapScanCrossScan));
            if(verbose) {
                debug_print("New mapScanNumLegs: " + mapScanNumLegs);
            }
        }
        ib = "P01_0";
        tih = 0;
        tfh = timeEpilogue;
        //   Use instrument coordinates unless HSPOT says otherwise
        fixed = false;
        if(useINST == false) {
            fixed = true;
        }
        patt = mapScanAngle;
        n = mapScanNumLegs;
        d1 = 60.0 * mapScanLegLength;
        d2 = mapScanCrossScan;
        thold = timeSlewCal;
        nrepeat = repFactor;
        if(verbose) {
            debug_print("Map reference: " + mapScanAngleRef + "=" + fixed);
        }
        fromPntReq = line_scan_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,n,d1,d2,rate,thold,nhold,nrepeat);
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tacc = fromPntReq[2];
        tdec = fromPntReq[3];
        tl = fromPntReq[4];
        tll = fromPntReq[5];
        trep = fromPntReq[6];
        if(verbose) {
            debug_print("##### line_scan_with_hold");
        }
        if(verbose) {
            debug_print("##### rate: " + rate + " arcsec/sec");
        }
        //   Here we calculate how long it takes to scan a line [sec]
        //   int scanTime = iceil(d1/rate);
        //   The "consistent" way of doing this is to rely on PntReq information
        int scanTime = tl;
        //   Gather the overheads
        int scanOVER = tacc + tdec;
    }
    if(verbose) {
        debug_print("PointReq:  " + fromPntReq + " for pointCase: " + pointCase);
        debug_print("PointMode: " + pointMode);
    }
    // End of "pointing" section
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
        debug_print("++++++++++++++++++++++++ State Machine");
    }
    // Initialize some "global" variables
    int totalOBStime = 0;
    int totalOBSover = 0;
    int totalCALtime = 0;
    int totalCALover = 0;
    int nbSCANlegs = 0;
    // Issue TCs
    int[] state = [0];
    int nbOBS = 0;
    while(state[0] >= 0) {
        state = next_state();
        //// STATE = SLEW
        if(state[0] == 1) {
            if(verbose) {
                int tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            //     Set OBSID
            WriteOBSID($OBSID);
            doProlog = true;
            // ON TARGET SLEW
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            int[] calTime = PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue);
            totalCALtime = totalCALtime + calTime[3];
            totalCALover = totalCALover + calTime[0];
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW/CAL ends at: " + tNOW);
                debug_print("    TotalCalTime: " + totalCALtime);
            }
        } else {
            //// STATE = INIT_HOLD
            if(state[0] == 2) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== INIT_HOLD starts at: " + tNOW);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("=== INIT_HOLD ends at: " + tNOW);
                }
            } else {
                //// STATE = POINT
                if(state[0] == 3) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== POINT starts at: " + tNOW);
                    }
                    if(pointCase == 12) {
                        //       Observation includes chopping
                        int[] obsTime = PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                    } else {
                        //       Observation does includes chopping
                        obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                    }
                    totalOBStime = totalOBStime + obsTime[1] + obsTime[2];
                    totalOBSover = totalOBSover + obsTime[0];
                    nbOBS = nbOBS + 1;
                    if(verbose) {
                        debug_print("POINT: POINTobs: " + nbOBS);
                        tNOW = time();
                        debug_print("=== POINT ends at: " + tNOW);
                    }
                } else {
                    //// STATE = CAL_HOLD
                    if(state[0] == 6) {
                        doProlog = false;
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== CAL-HOLD starts at: " + tNOW);
                        }
                        calTime = PacsPhotSlewCal(false,confPHOTblu,confPHOTred,confOBCP,doProlog,blue);
                        totalCALtime = totalCALtime + calTime[3];
                        totalCALover = totalCALover + calTime[0];
                        if(verbose) {
                            debug_print("Accumulated CALtime: " + totalCALtime);
                            tNOW = time();
                            debug_print("=== CAL-HOLD ends at: " + tNOW);
                        }
                    } else {
                        //// STATE = NOD
                        if(state[0] == 7) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== NOD starts at: " + tNOW);
                            }
                            if(pointCase == 12) {
                                //       Observation includes chopping
                                obsTime = PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                            } else {
                                //       Observation does includes chopping
                                obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                            }
                            totalOBStime = totalOBStime + obsTime[1] + obsTime[2];
                            totalOBSover = totalOBSover + obsTime[0];
                            nbOBS = nbOBS + 1;
                            if(verbose) {
                                debug_print("NOD: NODobs: " + nbOBS);
                                tNOW = time();
                                debug_print("=== NOD ends at: " + tNOW);
                            }
                        } else {
                            //// STATE = LINE
                            if(state[0] == 8) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== SCAN starts at: " + tNOW);
                                }
                                PacsBbWriteIdBB();
                                //                                OBCP_TimeSynch3();
                                int tDelay = fromPntReq[4] - tWriteEnd;
                                delay(tDelay);
                                PacsBbWriteEndBB();
                                totalOBStime = totalOBStime + scanTime;
                                totalOBSover = totalOBSover + scanTime + scanOVER;
                                nbSCANlegs = nbSCANlegs + 1;
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== SCAN mode, leg: " + nbSCANlegs);
                                    debug_print("    TotalOBSTime: " + totalOBStime);
                                    debug_print("    tacctdec    : " + scanOVER);
                                    debug_print("=== SCAN ends at: " + tNOW);
                                }
                            } else {
                                //// STATE = FINAL_HOLD
                                if(state[0] == 5) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== FinalHOLD starts at: " + tNOW);
                                    }
                                    // PACS-1292				   
                                    PacsBbPhot_aot_epilogue();
                                    WriteEndID();
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== FinalHOLD ends at: " + tNOW);
                                    }
                                } else {
                                    //// STATE = END
                                    if(state[0] == -1) {
                                        tNOW = time();
                                        if(verbose) {
                                            debug_print("=== END state; time now: " + tNOW);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    int overOBS = totalOBSover - totalOBStime;
    int overCAL = totalCALover - totalCALtime;
    if(verbose) {
        debug_print("+++ OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("    totalOBStime :" + totalOBStime);
        debug_print("    totalOBSover :" + overOBS);
        debug_print("    totalCALtime :" + totalCALtime);
        debug_print("    totalCALover :" + overCAL);
    }
    // Time considerations
    // The "science" part of the observations lasts tobs seconds (tobs from
    // PointReq[0])
    // Time on source is totalOBStime. Hence
    int instrumentAndObservationOverhead = tobs - totalOBStime;
    // Begin "calculation" and report section
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "ObsMode: <B>" + shortDesc + "</B>";
    lineCnt = lineCnt + 1;
    // More pointing information
    if(pointCase == 12) {
        msgLine[lineCnt] = "<p>Chopper throw: " + nodThrow + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        double mapArea = boloArea;
        msgLine[lineCnt] = "<p>PHOTO footprint: " + dformat(boloLSize,2) + " x " + dformat(boloSSize,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>PHOTO area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    if(pointCase == 21 || pointCase == 31 || pointCase == 22) {
        msgLine[lineCnt] = "<p>Raster points/lines: " + m + "/" + n + "</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Step size: " + d1 + " x " + d2 + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        //   Mapped region
        double sizeL = boloLSize + double(m - 1) * d1;
        double sizeS = boloSSize + double(n - 1) * d2;
        mapArea = sizeL * sizeS;
        msgLine[lineCnt] = "<p>PHOTO observed size: " + dformat(sizeL,2) + " x " + dformat(sizeS,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>PHOTO observed area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    if(pointCase == 33) {
        msgLine[lineCnt] = "<p>ScanLeg: " + d1 + " [arcsec]; number of legs: " + n + "; leg separation: " + dformat(d2,1) + " [arcsec], scan speed: " + dformat(rate,2) + " [arcsec/sec]</p>";
        lineCnt = lineCnt + 1;
        //  For the mapped area assume that we scan along the Large side of bolo
        //  Size along scan line
        sizeL = d1 + boloSSize;
        //  Size covered by successive legs
        sizeS = boloLSize + double(n - 1) * d2;
        msgLine[lineCnt] = "<p>PHOTO observed size: " + dformat(sizeL,2) + " x " + dformat(sizeS,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        mapArea = sizeL * sizeS;
        msgLine[lineCnt] = "<p>PHOTO observed area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    // Nodding pattern
    msgLine[lineCnt] = "<h3> Nod pattern (as applicable)</h3>";
    lineCnt = lineCnt + 1;
    if(nb_nods == 0) {
        if(pointCase != 33) {
            msgLine[lineCnt] = " No nodding, S/C stays at nominal position<";
        } else {
            msgLine[lineCnt] = " No nodding, S/C is in line scan mode<";
        }
        lineCnt = lineCnt + 1;
    }
    if(nb_nods == 1) {
        msgLine[lineCnt] = "   A->B ";
        lineCnt = lineCnt + 1;
    }
    if(nb_nods == 2) {
        msgLine[lineCnt] = "   A->B B->A ";
        lineCnt = lineCnt + 1;
    }
    if(nb_nods > 2) {
        int aux1 = nb_nods - 2;
        msgLine[lineCnt] = "   A->B B->A and " + aux1 + " more A->B or B->A leg(s) ";
        lineCnt = lineCnt + 1;
    }
    // Add dithering bla-bla
    msgLine[lineCnt] = "<h3> Dithering information</h3>";
    lineCnt = lineCnt + 1;
    if(dither && pointCase == 12) {
        int half_dither = max_dither / 2;
        msgLine[lineCnt] = "<p> Three position spatial dithering performed with the chopper (" + max_dither + " and " + half_dither + " chopper engineering units)</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Dithering information is not applicable.</p>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "<h3> Duration information</h3>";
    lineCnt = lineCnt + 1;
    tNOW = time();
    msgLine[lineCnt] = "<p>AOT duration (w/overheads): " + tNOW + " [sec]</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p><I>(AOT duration comprises 'on-sky' plus setup and CAL during slew)</I></p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Breakdown of AOT duration:</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul><li>On-sky time (w/overheads): " + tobs + " [sec]</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>(actual on-sky time: " + totalOBStime + " [sec])</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Setup and CAL during slew (w/overheads): " + tslew + " [sec]</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>(actual calibration time: " + totalCALtime + " [sec])</li></ul>";
    lineCnt = lineCnt + 1;
    // The charged obsOverhead is the MAX between tslew, nominalOverhead 
    if(tslew > obsOverhead) {
        obsOverhead = tslew;
    }
    int tcharged = tobs + obsOverhead;
    msgLine[lineCnt] = "<p><b>AOT cost</b> (includes time to slew to source): " + tobs + " + " + obsOverhead + " = " + tcharged + " [sec]</p>";
    lineCnt = lineCnt + 1;
    // On-SRC time calculations start here
    // Uses new algorithm: on-SRC = totalOBStime*boloArea/mapArea
    // OBS times above is for all pointings. For a raster, have to divide
    // by number of raster positions, i.e. m*n
    if(pointCase != 33) {
        //   If steps are smaller than boloXSize, same sky will be seen several times
        //   Compute Short and Long dimension number of sightings (assume source is
        //   placed to maximize number of sightings, i.e. at the proper edge of bolo)
        // NOTE: exchanged pointStep and lineStep as suggested by Roland V.
        int nbShort = iceil(boloSSize / lineStep);
        //   Cannot be larger than m
        if(nbShort > m) {
            nbShort = m;
        }
        int nbLong = iceil(boloLSize / pointStep);
        //   Cannot be larger than n
        if(nbLong > n) {
            nbLong = n;
        }
        if(verbose) {
            debug_print("nbShort/nbLong: " + nbShort + "/" + nbLong);
        }
        //   Time per raster point
        double auxTIMEold = double(totalOBStime * nbShort * nbLong) / double(m * n);
        double auxTIME = double(totalOBStime) * boloArea / mapArea;
        //   Small source is a special case where by design the SRC is always in view
        if(pointCase == 22) {
            auxTIME = auxTIMEold;
        }
    } else {
        //   elementary integration time [sec] will be computed as "transit" time
        //   of the source across the BOLO detector
        //   Case of scan leg size smaller than boloSize
        double sizeAux = boloSSize;
        if(d1 <= boloSSize) {
            sizeAux = d1;
        }
        //   Assume source is 1st seen on row=1; each successive scan may see again
        //   the same sky region if mapScanCrossScan is smaller than bolo width.
        //   The number of times the same sky is scanned again:
        if(mapScanCrossScan != 0.0) {
            int nbCross = iceil(boloLSize / mapScanCrossScan);
            if(verbose) {
                debug_print("nbCross: " + nbCross);
            }
        } else {
            nbCross = repFactor;
        }
        //   nbCross cannot be larger than mapScanNumLegs
        if(nbCross > mapScanNumLegs) {
            nbCross = mapScanNumLegs;
        }
        if(verbose) {
            debug_print("nbCross: " + nbCross);
        }
        //   The "crossing time"
        double crossTime = sizeAux / rate;
        if(verbose) {
            debug_print("crossTime: " + crossTime);
        }
        //   AuxTime is "crossing time" * number of crossings * repFactor
        auxTIMEold = double(repFactor * nbCross) * crossTime;
        auxTIME = double(totalOBStime) * boloArea / mapArea;
    }
    if(verbose) {
        debug_print("AuxTIMEold: " + auxTIMEold + " [sec]");
        debug_print("AuxTIME   : " + auxTIME + " [sec]");
    }
    // Pass the pointing mode to RMS (may need it for SRC,REF considerations)
    double[] pixRMS = PacsPhotNoiseRMS(pointCase,blue,auxTIME);
    msgLine[lineCnt] = "<h3> Sensitivity information </h3>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Effective on-sky time (one spatial resolution element) : " + dformat(auxTIME,1) + " [sec]</p>";
    lineCnt = lineCnt + 1;
    // Point source or extended source
    if(pointCase == 11 || pointCase == 12) {
        msgLine[lineCnt] = "<p>Point RMS (red): " + dformat(pixRMS[0],1) + " [mJy]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Point RMS (blu): " + dformat(pixRMS[1],1) + " [mJy]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Point RMS (red): " + dformat(pixRMS[0],1) + " [mJy]; extended RMS " + dformat(pixRMS[2],2) + " [MJy/sr]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Point RMS (blu): " + dformat(pixRMS[1],1) + " [mJy]; extended RMS " + dformat(pixRMS[3],2) + " [MJy/sr]</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("PACS Photometer AOT",lineCnt,msgLine);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    // Everything below is new request from RV. Use variable names consistent
    // with input variables in PacsPhoto.def
    // Return demanded tuples
    // ID for band blue1 
    string bandBlue = "60-85";
    if(blue == "blue2") {
        bandBlue = "85-130";
    }
    double pntRMSBlue = pixRMS[1];
    // Watch out for infinite division!!
    // Better watch out for silly limits (SPR-2627)
    if(pntRMSBlue > 0.0010) {
        double pntSNBlu = fluxPntBlu / pntRMSBlue;
    } else {
        pntSNBlu = 0.0;
    }
    string bandRed = "130-210";
    double pntRMSRed = pixRMS[0];
    if(pntRMSRed > 0.0010) {
        double pntSNRed = fluxPntRed / pntRMSRed;
    } else {
        pntSNRed = 0.0;
    }
    double extRMSBlue = pixRMS[3];
    // Watch out for infinite division!!
    if(extRMSBlue > 0.0010) {
        double extSNBlu = fluxExtBlu / extRMSBlue;
    } else {
        extSNBlu = 0.0;
    }
    double extRMSRed = pixRMS[2];
    if(extRMSRed > 0.0010) {
        double extSNRed = fluxExtRed / extRMSRed;
    } else {
        extSNRed = 0.0;
    }
    {string,double,double,double,double,double,double}[] noiseSummary = [{bandBlue,fluxPntBlu,pntSNBlu,pntRMSBlue,fluxExtBlu,extSNBlu,extRMSBlue},{bandRed,fluxPntRed,pntSNRed,pntRMSRed,fluxExtRed,extSNRed,extRMSRed}];
    if(verbose) {
        debug_print("NoiseSumm: " + noiseSummary);
        debug_print("OBStime/CALtime/Overhead/chopthrow: " + totalOBStime + "/" + totalCALtime + "/" + instrumentAndObservationOverhead + "/" + nodThrow);
    }
    //  return {totalOBStime,totalCALtime,instrumentAndObservationOverhead,

    return {totalOBStime,fromPntReq[1],instrumentAndObservationOverhead,nodThrow,noiseSummary};
}

// File          : CONF_chopper.cus
// Missionphase  : PACS FM Test
//
// Purpose       : Configure the chopper servo loop 
//
// Author        : DAC/MN
// CUSification  : DAC/MN
// Arguments     : 
// string calUfile  CAL-U file
// string calUcol   Column identifier
//                 
//
// Description   : Read servo loop parameters off a CALU table; a set
//                 of parameters is arranged as a column; different
//                 columns list different sets. Must specify the CALU
//                 file name and the column identification string.
//                 Example: CONF_chopper ("CONFChopper","nom_sky")
//                              
// Comments      :      
//
// Version       : 0.4
// History       : 0.1  9-nov-2006 Initial version
//                 0.2 22-feb-2007 Adapted to revised CONFChopper table
//                                (PosLimit  <=> Scaling
//                 0.3  8-mar-2007 Added 2sec delay at end per HD's mail
//                 0.4  9-jun-2007 Changed entries for new DECMEC (MN)
//                 0.4  9-jun-2007 newly optimised parameters (MN)
procedure CONF_chopper {
    string fileU = "CONFChopper"; // CAL-U file
    string calUcol = "nom_sky"; // Column identifier
}{
    // # DMC_WRT_CHOP_CONF_PAR (21 params). Use  values
    //   obtaied from CALU file
    int aKp = ilookup(fileU,"Kp",calUcol);
    int aKi = ilookup(fileU,"Ki",calUcol);
    int aKd = ilookup(fileU,"Kd",calUcol);
    int aKf = ilookup(fileU,"Kf",calUcol);
    int aRate = ilookup(fileU,"Rate",calUcol);
    int aAccumLimit = ilookup(fileU,"AccumLimit",calUcol);
    int aOutputLimit = ilookup(fileU,"OutputLimit",calUcol);
    int aPosLimit = ilookup(fileU,"PosLimit",calUcol);
    int aErrorLimit = ilookup(fileU,"ErrorLimit",calUcol);
    int aPosOffset = ilookup(fileU,"PosOffset",calUcol);
    int aKiCurr = ilookup(fileU,"KiCurr",calUcol);
    int aSelectFieldPlateLUT = ilookup(fileU,"SelectFieldPlateLUT",calUcol);
    int aSpare = ilookup(fileU,"Spare",calUcol);
    int aFilterN1 = ilookup(fileU,"FilterN1",calUcol);
    int aFilterN2 = ilookup(fileU,"FilterN2",calUcol);
    int aFilterN3 = ilookup(fileU,"FilterN3",calUcol);
    int aFilterD1 = ilookup(fileU,"FilterD1",calUcol);
    int aFilterD2 = ilookup(fileU,"FilterD2",calUcol);
    int aInductance = ilookup(fileU,"Inductance",calUcol);
    int aResistance = ilookup(fileU,"Resistance",calUcol);
    int aControlLoopGain = ilookup(fileU,"ControlLoopGain",calUcol);
    // Create tuple array and int array
    {int}[] list_tuple = [{aKp},{aKi},{aKd},{aKf},{aRate},{aAccumLimit},{aOutputLimit},{aPosLimit},{aErrorLimit},{aPosOffset},{aKiCurr},{aSelectFieldPlateLUT},{aSpare},{aFilterN1},{aFilterN2},{aFilterN3},{aFilterD1},{aFilterD2},{aInductance},{aResistance},{aControlLoopGain}];
    // Define as int [] to compute check sum
    int[] list_int = [aKp,aKi,aKd,aKf,aRate,aAccumLimit,aOutputLimit,aPosLimit,aErrorLimit,aPosOffset,aKiCurr,aSelectFieldPlateLUT,aSpare,aFilterN1,aFilterN2,aFilterN3,aFilterD1,aFilterD2,aInductance,aResistance,aControlLoopGain];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_CHOP_CONF_PAR(list_tuple,chksum);
    delay(2);
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose : Reduced NEP measurements for the new sequencer test
//           Search for the optimum bias with 11 values
//           using the high gain
//
// Author : Koryo Okumura
//
//
// Argument :
//    int response_measure_time = 60; // response measure time in seconds
//    int noise_measure_time = 120; // noise measure time in seconds
//    int lowFreq_noise_time = 1800; // long noise measure time in seconds
//    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Instrument is in safe mode
//
// Description : OBS script of PHOT_redArray_alternatePolarisation_DDCS_IST
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_newSeq_IST(0)
//
// Version 	: 1.0
// History	: 0.1 Fri Oct 05 12:19:23 CEST 2007
// 		: 1.0 translated into PV script VDP
//
obs PacsEng_Phot_redArray_alternatePolarisation_DDCS_IST {
    /* Needed variables to call PacsEng_Phot_redArray_alternatePolarisation_DDCS_IST                        */
    int response_measure_time = 60; // response measure time in seconds
    int noise_measure_time = 120; // noise measure time in seconds
    int lowFreq_noise_time = 1800; // long noise measure time in seconds
    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_redArray_alternatePolarisation_DDCS_IST                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PHOT_redArray_alternatePolarisation_DDCS_IST(response_measure_time,noise_measure_time,lowFreq_noise_time,biasFile)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_redArray_alternatePolarisation_DDCS_IST(response_measure_time,noise_measure_time,lowFreq_noise_time,biasFile);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Spec_Gra_Cont_Check_4
// Missionphase  : FM IST & Commissioning
//
// Purpose       : Prepare grating mechanism, 2 small moves & disable
//
// Author        : P. Royer
//
// Arguments     :  CALIBRATION TABLE (CONFGrat)
//		    ROW of CALU table (CONFGrat)
//		   	Row of this table = instrument version
//
// Description   : This script will fully configure the grating, incl. homing, then disable it
//                              
// Comments      :      
//
// Version       : 1.0
// History       : 1.0 / 12-JuL-2007 PR
//
procedure PACS_Spec_Gra_Cont_Check_4 {
    string calUname = "CONFGrat"; // GRATING CALIBRATION TABLE
    string calUrow = "IST"; // INSTRUMENT VERSION
}{
    // Configure the grating controller
    //
    CONF_grating(calUname,calUrow);
    delay(10);
    //
    // Make small movements
    for(int j1 = 0 .. 5) {
        Pacs_DMC_MOVE_GRAT_REL_RAW(117);
        delay(1);
    }
    for(int j2 = 0 .. 5) {
        Pacs_DMC_MOVE_GRAT_REL_RAW(-117);
        delay(1);
    }
    // Make 2 bigger movements
    Pacs_DMC_MOVE_GRAT_REL(-233010);
    delay(15);
    Pacs_DMC_MOVE_GRAT_REL(233010);
    delay(15);
    // DISABLE GRATING CONTROLLER
    Pacs_DMC_DISABLE_GRAT_CONT();
    delay(1);
    //
    //-------------------------
    // End of Procedure
    //-------------------------
}

// File          : PACS_Spec_Gra_Mec_Setup.cus
// Missionphase  : PACS FM ILT
//
// Purpose       : Prepare grating mechanism
//
// Author        : P. Royer
//
// Arguments     :  CALIBRATION TABLE (CONFGrat)
//		    ROW of CALU table (CONFGrat)
//		   	Row of this table = instrument version
//
// Description   : This script will switch on and set all required
//                 parameters for the grating
//                              
// Comments      :      
//
// Version       : 1.1
// History       : 1.0 / 13-Jun-2006 created from a non-calu-using script
// 		 : 1.1 05-dec-2008 VD change CONFGrat call with ISTSafe
//
procedure PACS_Spec_Gra_Cont_Check_1 {
    string calUname = "CONFGrat"; // GRATING CALIBRATION TABLE
    string calUrow = "ISTSafe"; // INSTRUMENT VERSION
}{
    //
    // Grating home mode: 0 = move to neg. positions; 1 = move to pos. positions
    int grat_home_mode = 1;
    // Grating central position (rough)
    int grat_center_pos = 500000;
    //
    //----------------------
    // CONTROLLER PARAMETERS
    //----------------------
    //
    PACS_Spec_Gra_Conf_Calu(calUname,calUrow);
    //
    //----------------------
    // ADDITIONAL PARAMETERS
    //----------------------
    //
    // ADDITIONAL PARAMS : 1. GRATING INDUCTOSYN AMPLITUDE
    //
    int induct_ampl = ilookup(calUname,calUrow,"InductAmpl");
    {int}[] list_tuple = [{induct_ampl}];
    int[] list_int = [induct_ampl];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_INDUC_AMPL(list_tuple,chksum);
    delay(1);
    //
    // ADDITIONAL PARAMS : 2. HALL SENSOR OFFSET
    //
    int hall_offset = ilookup(calUname,calUrow,"HallOffset");
    list_tuple = [{hall_offset}];
    list_int = [hall_offset];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_HALLOFFSET(list_tuple,chksum);
    delay(1);
    //
    // ADDITIONAL PARAMS : 3. GRATING RANGE
    //
    int range = ilookup(calUname,calUrow,"Range");
    list_tuple = [{range}];
    list_int = [range];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_RANGE(list_tuple,chksum);
    //
    // Amplitude was set => security delay of 3 minutes
    delay(180);
    //
    // ----------------------------
    // SWITCH ON GRATING CONTROLLER
    // ----------------------------
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    //
    // ENABLE GRATING CONTROLLER
    Pacs_DMC_ENABLE_GRAT_CONT();
    delay(2);
    // DISABLE GRATING CONTROLLER
    Pacs_DMC_DISABLE_GRAT_CONT();
    delay(1);
    //
    //-------------------------
    // End of Procedure
    //-------------------------
}

// File          : PACS_Spec_Gra_Mec_Setup.cus
// Missionphase  : PACS FM ILT
//
// Purpose       : Prepare grating mechanism
//
// Author        : P. Royer
//
// Arguments     :  CALIBRATION TABLE (CONFGrat)
//		    ROW of CALU table (CONFGrat)
//		   	Row of this table = instrument version
//
// Description   : This script will switch on and set all required
//                 parameters for the grating, enable the controller,
//                 make a small grating movement
//                              
// Comments      :      
//
// Version       : 1.0
// History       : 1.0 / 13-Jun-2006 created from a non-calu-using script
//
procedure PACS_Spec_Gra_Cont_Check_2 {
    string calUname = "CONFGrat"; // GRATING CALIBRATION TABLE
    string calUrow = "FMILT"; // INSTRUMENT VERSION
}{
    //
    // Grating home mode: 0 = move to neg. positions; 1 = move to pos. positions
    int grat_home_mode = 1;
    // Grating central position (rough)
    int grat_center_pos = 500000;
    //
    //----------------------
    // CONTROLLER PARAMETERS
    //----------------------
    //
    PACS_Spec_Gra_Conf_Calu(calUname,calUrow);
    //
    //----------------------
    // ADDITIONAL PARAMETERS
    //----------------------
    //
    // ADDITIONAL PARAMS : 1. GRATING INDUCTOSYN AMPLITUDE
    //
    int induct_ampl = ilookup(calUname,calUrow,"InductAmpl");
    {int}[] list_tuple = [{induct_ampl}];
    int[] list_int = [induct_ampl];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_INDUC_AMPL(list_tuple,chksum);
    delay(1);
    //
    // ADDITIONAL PARAMS : 2. HALL SENSOR OFFSET
    //
    int hall_offset = ilookup(calUname,calUrow,"HallOffset");
    list_tuple = [{hall_offset}];
    list_int = [hall_offset];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_HALLOFFSET(list_tuple,chksum);
    delay(1);
    //
    // ADDITIONAL PARAMS : 3. GRATING RANGE
    //
    int range = ilookup(calUname,calUrow,"Range");
    list_tuple = [{range}];
    list_int = [range];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_RANGE(list_tuple,chksum);
    //
    // Amplitude was set => security delay of 3 minutes
    delay(180);
    //
    // ----------------------------
    // SWITCH ON GRATING CONTROLLER
    // ----------------------------
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    //
    // ENABLE GRATING CONTROLLER
    Pacs_DMC_ENABLE_GRAT_CONT();
    delay(5);
    // Make a small movement
    Pacs_DMC_MOVE_GRAT_REL(-233010);
    delay(30);
    Pacs_DMC_MOVE_GRAT_REL(233010);
    delay(30);
    // DISABLE GRATING CONTROLLER
    Pacs_DMC_DISABLE_GRAT_CONT();
    delay(1);
    //
    //-------------------------
    // End of Procedure
    //-------------------------
}

// File          : PACS_Spec_Fil_nturns.cus
// Missionphase  : PACS FM Tests
//
// Purpose       : Position sequence test of spectrometer filterwheel  
//
// Author        : PR
//
// Arguments     :
//
// Description   : Moves the Spectrometer filter wheel <num_turns> times
//                 to position 2 and back to position 1 using absolute position
//                 commands. 
//
// Comments      : Prerequisite : spec_mec_setup has been executed 
//
// Version       : 1.0
// History       : 1.0 /Mar-2007  Adatped from PACS_Spec_Fil_Testseq
//
procedure PACS_Spec_Fil_nturns {
    int num_turns = 3; // number of 360 deg turns
    int backward_toA = 0; // direction of FW rotation towards POS A : 0 forward; 1 backward
    int backward_toB = 0; // direction of FW rotation towards POS B : 0 forward; 1 backward
}{
    debug_print("Start PACS_Spec_Fil_nturns");
    int fw_start = 1;
    // initial filter wheel position (0=A; 1=B)
    int time_on_fw_pos = 20;
    // time spent on each FW stop position (sec)
    //int[] fltPOS = ["POS A","POS B"];
    int slew_time = 15;
    // Minimum time between two filter wheel movements (sec)
    backward_toA = 2 * backward_toA;
    backward_toB = 2 * backward_toB;
    int[] backward = [backward_toA,backward_toB];
    int movepar = 0;
    // SWON FW CONTROLLER
    Pacs_DMC_SWON_FW_SPEC();
    delay(1);
    Pacs_DMC_MOVE_SPEC_FW_LOC_RAW(fw_start);
    delay(slew_time);
    // Move num_turns to position 0 and back to position 1 using absolute location commands
    for(int loop0 = 1 .. num_turns) {
        int i = (fw_start + 1) % 2;
        movepar = i + backward[i];
        Pacs_DMC_MOVE_SPEC_FW_LOC_RAW(movepar);
        delay(slew_time);
        delay(time_on_fw_pos);
        i = (fw_start + 2) % 2;
        movepar = i + backward[i];
        Pacs_DMC_MOVE_SPEC_FW_LOC_RAW(movepar);
        delay(slew_time);
        delay(time_on_fw_pos);
    }
    // RE-SWON GRAT CONTROLLER
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    //------------------
    // End of procedure
    //------------------
}

// $Id
// Missionphase		: PACS PV Phase
//
// Purpose :		Wavelength calibration during PacsSlew
// Author		 : VDP
//
// Arguments		:
//
// Prerequisite 	: PACS does not need to be on nor setup for spectroscopy
//
// Description		: Uses OBCP13 and performs AOT prologue and epilogue
// 
// Comments		:
//
// Dependencies		: CONF_SPEC_params : The detector biases are read from column "Normal0"
//
// Version		: 1.0
// 
// History		: 0.1 Using example from PacsCal_WaveCalChop
// 			: 1.0 perform calibrations during slew and 
//    	  	       	   then a wavelength calibration on source
//			   usng NOD=1 and Choping
// 			   1.1 07-May-2009 PR Upgrade ramp_fit_alg (match FS database) & nb_raw as parameters
//			                      Add parameter no_gratmove
//
obs PacsEng_PacsSpecSlewCal_Flex {
    /* Needed variables to call PacsSpecSlewCal */
    /* FW, WAVELENGTH & OBCP parameters */
    double[] waves = [60.0]; // Wavelengths
    int order = 2;
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int nb_up_dn = 1; // nb_up_down  	OBCP 13 DMCSeq. P#1
    int nb_grat_steps = 16; // nb_grating_steps  	OBCP 13 DMCSeq. P#3
    int nb_cycles_grat = 2; // nb_chop_cycles_per_gratpos  	OBCP 13 DMCSeq. P#5
    int nb_ramps_grat_pos = 1; // nb_clean_ramps_per_gratpos  	OBCP 13 DMCSeq. P#7
    bool no_gratmove = false; // false: gratstep read from CALU. True: gratstep forced to 0
    /* CRE & SPU PARAMETERS */
    int capa_blu = 12;
    int capa_red = 12;
    int nb_rdouts_ramp_blu = 64;
    int nb_rdouts_ramp_red = 64;
    int nb_rdouts_subramp_blu = 16;
    int nb_rdouts_subramp_red = 16;
    int ramp_fit_alg_blu = 1;
    int ramp_fit_alg_red = 1;
    int nb_raw_blu = 3;
    int nb_raw_red = 3;
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    bool verbose = true;
}{
    // FIXED CRE & SPU Parameters
    int glitch_det_blu = 1;
    int glitch_det_red = 1;
    int bias_d_blu_mV = ilookup("CONF_SPEC_params","bias_d_blu","Normal0");
    int bias_d_red_mV = ilookup("CONF_SPEC_params","bias_d_red","Normal0");
    int bias_r_blu_mV = ilookup("CONF_SPEC_params","bias_r_blu","Normal0");
    int bias_r_red_mV = ilookup("CONF_SPEC_params","bias_r_red","Normal0");
    // FIXED OBCP Parameters
    // OBCP 13 DMCSeq. P#2
    int grat_step_coarse = 0;
    // OBCP 13 DMCSeq. P#4
    string order_str = "" + order;
    int grat_step_up_fine = ilookup("SPEC_BAND_params",order_str,"HI");
    if(no_gratmove) {
        grat_step_up_fine = 0;
    }
    // OBCP 13 DMCSeq. P#6
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","SPEC","pos_CS1");
    // OBCP 13 DMCSeq. P#8
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    // OBCP 13 DMCSeq. P#9 : this parameter is set in PacsSpecSlewCal_Flex
    // int grat_step_dn_fine = -grat_step_up_fine;
    // Synchronize on this detector 1:Blue 2:Red
    int detector = 1;
    // Chopped default position
    int chop_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int grat_pos = grat_park;
    // PacsSpecSlewCal_Flex parks the grating in the end already
    //
    // compiting time for slw / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Calibration time during slew
    // SPEC parameters for BLU and RED    
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{capa_blu,nb_rdouts_ramp_blu,nb_rdouts_subramp_blu,comp_mode_blu,glitch_det_blu,ramp_fit_alg_blu,nb_raw_blu,bias_r_blu_mV,bias_d_blu_mV}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{capa_red,nb_rdouts_ramp_red,nb_rdouts_subramp_red,comp_mode_red,glitch_det_red,ramp_fit_alg_red,nb_raw_red,bias_r_red_mV,bias_d_red_mV}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,detector,chop_def}];
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    //
    //
    // "N/A" in string because of indexing 0,1,2,3
    //string[] choix = ["N/A","order1","order2","order3"];
    //string order_str = "" + order;
    //double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //double[] keyWAVE = [keyWAVE1];
    //
    //
    //Initial hold
    int tih = duration(WriteOBSID($OBSID));
    //Final hold
    int tendobsid = duration(WriteEndID());
    int tepilog = duration(SPEC_aot_epilogue(grat_pos,grat_park,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(PacsSpecSlewCal_Flex(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,waves,fltPOS,order));
    if(verbose) {
        debug_print("Duration of PacsSpecSlewCal_Flex" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    int[] ts = no_pointing(execute,tih,tfh,tp);
    debug_print("ts: " + ts);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            int tNOW = time();
            // 
            WriteOBSID($OBSID);
            data_rate(120.0);
            if(verbose) {
                debug_print("WriteOBSID at :" + tNOW + " sec");
            }
            tNOW = time();
            if(verbose) {
                debug_print("WriteOBSID ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                tNOW = time();
                PacsSpecSlewCal_Flex(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,waves,fltPOS,order);
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 5) {
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold starts at :" + tNOW + " sec");
                    }
                    SPEC_aot_epilogue(grat_pos,grat_park,verbose);
                    data_rate(0.0);
                    WriteEndID();
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold ends at :" + tNOW + " sec");
                    }
                }
            }
        }
    }
    // End of Observation
}

procedure TestVectorInput {
    int[] toto = [1];
}{
    message("toto: " + toto);
}

// File          : PACS_GeGa_SFT_Init_Warm.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Cold SFT of Ge:Ga detector chain 
//
// Author        : H. Feuchtgruber
//
// Arguments     : none
//                 
//
// Description   : This script will switch on and set all required parameters
//                 for a test of the Ge:Ga detector chain at RT temperature.
//                 Dummy resistor bias = 10 mV, detector bias = 2 mV
//                 
//                              
// Comments      :      
//
// Version       : 1.0
// History       : 1.0 / 16-Nov-2004 initial version
// 1.1  7-mar-2006 TeleCommand Pacs_DMC_SET_B_SPEC_HEAT_1_C renamed
//                 TeleCommand Pacs_DMC_SET_B_SPEC_HEAT_2_C renamed
// 1.2 24-mar-2006 Large overhaul based on 
//                 SetupSpectroscopyWEplusFPUsim.tcl script
// 1.3 27-nov-2006 Changed bias_d to LB value: 1mV
// 2.0  8-feb-2007 Added switchoff  SPECs and DECs
//                 
procedure PACS_GeGa_SFT_Init_Warm {
}{
    debug_print("Start PACS_GeGa_SFT_Init_Warm");
    //DPU_SET_HK_LIST (SPEC for both channels)
    Pacs_DPU_SET_HK_LIST("SPEC","BOTH Array");
    delay(1);
    // DMC_WRT_BOL_REC_OPT(ID,LENGTH,4,CHKSUM)
    int[] argum = [4];
    {int}[] argTuple = [{4}];
    int chksum = checksum("int",argum);
    Pacs_DMC_WRT_BOL_REC_OPT(argTuple,chksum);
    delay(1);
    // DMC_WRT_B_DEC_REC_OPT(ID,LENGTH,4,CHKSUM)
    argum = [4];
    argTuple = [{4}];
    chksum = checksum("int",argum);
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,chksum);
    delay(1);
    // DMC_WRT_R_DEC_OPT(ID,LENGTH,4,CHKSUM)
    argum = [4];
    argTuple = [{4}];
    chksum = checksum("int",argum);
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,chksum);
    delay(1);
    // DMC_WRT_TIMING_FPGA_PAR(ID,LENGTH,16384,40,2,32,0,P//9,CHKSUM)
    {int}[] list_tuple = [{0x0},{0x0},{0x0},{26},{0x95217cb},{0xb}];
    int[] list_int = [0x0,0x0,0x0,26,0x95217cb,0xb];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_TIMING_FPGA_PAR(list_tuple,chksum);
    delay(1);
    // DMC_SET_TIMING_FPGA_PAR
    Pacs_DMC_SET_TIMING_FPGA_PAR();
    message("Default spectroscopy timing parameters set!");
    // Switch off SPECs and DECs
    // DMC_SWOF_B_SPEC" SWITCH ON BLUE SPECTROMETER ARRAY POWER
    Pacs_DMC_SWOF_B_SPEC();
    delay(1);
    //  "DMC_SWOF_R_SPEC" SWITCH ON RED SPECTROMETER ARRAY POWER
    Pacs_DMC_SWOF_R_SPEC();
    delay(1);
    // DMC_SWOF_B_DEC SWITCH ON THE BLUE DEC POWER
    Pacs_DMC_SWOF_B_DEC();
    delay(1);
    // DMC_SWOF_R_DEC" SWITCH ON RED DEC POWER
    Pacs_DMC_SWOF_R_DEC();
    delay(10);
    //  ======== Initial detector setup ====================
    // DMC_SWON_B_DEC SWITCH ON THE BLUE DEC POWER
    Pacs_DMC_SWON_B_DEC();
    delay(8);
    // DMC_SWON_R_DEC" SWITCH ON RED DEC POWER
    Pacs_DMC_SWON_R_DEC();
    delay(8);
    // Wait after DEC switch-on
    delay(5);
    debug_print("DECs are on !");
    // Now define the startup Ge:Ga detector setup
    int read_per_ramp_b = 8;
    int cre_ctrl_b = 396;
    int bias_r_b = 0;
    int bias_d_b = 0;
    int read_per_ramp_r = 8;
    int cre_ctrl_r = 396;
    int bias_r_r = 0;
    int bias_d_r = 0;
    // DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000,chksum);
    delay(1);
    // DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000,chksum);
    delay(1);
    // DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    // DMC_SWON_B_SPEC" SWITCH ON BLUE SPECTROMETER ARRAY POWER
    Pacs_DMC_SWON_B_SPEC();
    delay(1);
    // PC091420 "DMC_SWON_R_SPEC" SWITCH ON RED SPECTROMETER ARRAY POWER
    Pacs_DMC_SWON_R_SPEC();
    delay(1);
    debug_print("SPECs are on !");
    // Wait for CRE HW sequence to finish
    delay(15);
    // now select the CREs
    cre_ctrl_b = 398;
    cre_ctrl_r = 398;
    // DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000,chksum);
    delay(1);
    // DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000,chksum);
    delay(1);
    // DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    // Now define the actual Ge:Ga detector setup
    read_per_ramp_b = 64;
    cre_ctrl_b = 398;
    bias_r_b = 41;
    bias_d_b = 4;
    read_per_ramp_r = 64;
    cre_ctrl_r = 398;
    bias_r_r = 41;
    bias_d_r = 4;
    double heater_blue = 0.0;
    // DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000,chksum);
    delay(1);
    // DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000,chksum);
    delay(1);
    // DMC-SET-PARAM-BOTH-SPEC SET TIMING PARAMTERS FOR BOTH SPEC ARRAYs
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    delay(1);
    // DMC_SWON_BD_HEATER
    Pacs_DMC_SWON_BD_HEATER();
    delay(1);
    // DMC_SET_B_SPEC_HEAT_C
    Pacs_DMC_SET_B_SPEC_HEAT_C(heater_blue);
    delay(1);
    debug_print("Detectors are up and running at default settings!");
    // DMC_SYNCHRONIZE_ON_DET(1)
    Pacs_DMC_SYNCHRONIZE_ON_DET(1);
    delay(1);
    // DMC_WRT_B_DEC_REC_OPT" WRITE THE BLUE DEC RECEIVER OPTIONS
    argTuple = [{0}];
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,0x84c0);
    delay(1);
    // DMC_WRT_R_DEC_REC_OPT" WRITE THE RED DEC RECEIVER OPTIONS
    argTuple = [{0}];
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,0x84c0);
    delay(1);
    // DMC_VAL_SCI_DATA_BOTH" VALIDATE SCIENCE DATA FROM BOTH CHANNELS
    Pacs_DMC_VAL_SCI_DATA_BOTH();
    delay(1);
    // # ==== End of detector setup ==============
}

// Missionphase  : 
//
// Purpose       : Move the PHOT filter wheel to one of the two defined
//                 positions
//                  
// TCL script    : N/A
// CUS script    : Diego A. Cesarsky
//
// CVS file      : PHOT_fltw_move.txt 
//
// Arguments     : 
// Type    Name      DefVal  Description
// string  flt_id    POS A   One of two preset positions [POS A, POS B]
//
// Description   : Switch ON filter controller, move wheel, switch OFF
//                  
// Dependencies  : Low level PACS TCs
//
// Preconditions : Servo loop already configured
//                 
// Comments      : useless comment by Bart
//                        Quite useless indeed!
//
// Version       : 0.1 13-Aug-2004 Creation by DAC
// History       : 0.2 28-Oct-2004 Renamed from FLTW_move.txt; demoded
//                                 from BB to simple procedure
//                 0.3 13-apr-2005 DAC Renamed from BOLO_flt_move, filter_id
//                                 is now a string (ENG value)
//                 0.4 20-1pr-2005 DAC Read wheel move time from PACSparams 
//                 0.5 19-feb-2008 Return time in sec
//               :
int procedure PHOT_fltw_move {
    string filter_id = "POS A" in ["POS A","POS B"];
}{
    // Get the duration of the move
    int move_time = iceil(dlookup("PACSparams","fltw_time","freq_time"));
    // Same in [sec]
    int move_time_sec = Msec2sec(move_time);
    //  debug_print("PHOT fltw moves to " + filter_id + 
    //              "; " + move_time_sec + " [sec]");
    // Set the filter wheel: switch on the filter/grating controller
    Pacs_DMC_SWON_FW_PHOTO();
    // Move filter to desired position 
    Pacs_DMC_MOVE_PHOT_FW_LOC(filter_id);
    // Wait move_time_sec sec for wheel to end its movement
    delay(move_time_sec);
    // Switch off the controller
    Pacs_DMC_SWOF_GRAT_CONT();
    // Return duration

    return move_time_sec;
}

// CVS comments  : $Id: PacsRangeSpecSed.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $
// Missionphase  : Operations
//
// Purpose       : 
//
// CUS author    : VD
// Script file   : PacsSpecCheckRefWave
//
// Input arguments
// type     name      description
// Return values
// Type                Description
//
// Description   : Check the reference WL given in the parallel band actually IS in the parallel band
//
// Preconditions :
//
// Comments      : PHS-1302
// History       : 20-jan-2010 1.0 VD: created
//               : 03-may-2010 2.0 VD PHS-1393 B2A order23
// 
// 
bool procedure PacsSpecCheckRefWave {
    double bluWaveNom = 0.0;
    double redWaveNom = 0.0;
    double refWave = 0.0;
    string orderSel = "order3";
}{
    // Return variables
    bool goodRefWave = true;
    double redWavePar = 0.0;
    double bluWavePar = 0.0;
    // create all order
    if(orderSel == "order3") {
        if(bluWaveNom < 102.0) {
            string keyB = "3";
            string interp_file_Nom = "SPEC_RSRF_Blue_SW";
            string interp_file_Par = "SPEC_grat_wl_R1";
            double bluEdge = dlookup("SPEC_BAND_params",keyB,"BLU");
            double redEdge = dlookup("SPEC_BAND_params",keyB,"RED");
        } else {
            keyB = "1";
            interp_file_Nom = "SPEC_RSRF_Red";
            interp_file_Par = "SPEC_grat_wl_B3A";
            bluEdge = dlookup("SPEC_BAND_params",keyB,"BLU");
            redEdge = dlookup("SPEC_BAND_params",keyB,"RED");
        }
    }
    if(orderSel == "order23") {
        if(bluWaveNom < 102.0) {
            keyB = "23";
            interp_file_Nom = "SPEC_RSRF_Blue_LW";
            interp_file_Par = "SPEC_grat_wl_R1";
            bluEdge = dlookup("SPEC_BAND_params",keyB,"BLU");
            redEdge = dlookup("SPEC_BAND_params",keyB,"RED");
        } else {
            keyB = "1";
            interp_file_Nom = "SPEC_RSRF_Red";
            interp_file_Par = "SPEC_grat_wl_B2A";
            bluEdge = dlookup("SPEC_BAND_params",keyB,"BLU");
            redEdge = dlookup("SPEC_BAND_params",keyB,"RED");
        }
    }
    if(orderSel == "order2") {
        if(bluWaveNom < 102.0) {
            keyB = "2";
            interp_file_Nom = "SPEC_RSRF_Blue_LW";
            interp_file_Par = "SPEC_grat_wl_R1";
            bluEdge = dlookup("SPEC_BAND_params",keyB,"BLU");
            redEdge = dlookup("SPEC_BAND_params",keyB,"RED");
        } else {
            keyB = "1";
            interp_file_Nom = "SPEC_RSRF_Red";
            interp_file_Par = "SPEC_grat_wl_B2B";
            bluEdge = dlookup("SPEC_BAND_params",keyB,"BLU");
            redEdge = dlookup("SPEC_BAND_params",keyB,"RED");
        }
    }
    // begin Section SED
    // end Section SED 
    debug_print("interp_file_Nom: " + interp_file_Par);
    double grat_blu_Nom = interpolate(interp_file_Nom,"grat_pos",bluWaveNom);
    double grat_red_Nom = interpolate(interp_file_Nom,"grat_pos",redWaveNom);
    debug_print("grat: B / R : " + grat_blu_Nom + " / " + grat_red_Nom);
    bluWavePar = interpolate(interp_file_Par,"wave",grat_blu_Nom);
    redWavePar = interpolate(interp_file_Par,"wave",grat_red_Nom);
    debug_print("wave: B / R: " + bluWavePar + " / " + redWavePar);
    if(refWave > redWaveNom || refWave < bluWaveNom) {
        if(refWave < bluWavePar || refWave > redWavePar) {
            goodRefWave = false;
        }
    }

    return goodRefWave;
}

// $Id: PacsEng_Phot_spu_setup.txt,v 1.5 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : PACS PV Phase
//
// Purpose	: Setup SPU for photometry data flow
// Author	: DAC
//
// Arguments	: 
//
//                (optionally) starts reduction/compression
//                  
// Dependencies : 
//
// Comments	:
//
// Version	: 2.0               
// History	: 1.0 10-nov-2006 DAC
//                1.1 13-nov-2006 Start SPU
//                1.2  4-apr-2007 nraw = 0
//		  2.0 04-mar-2008 translated into PV script VDP
//
obs PacsEng_Phot_spu_setup_l {
    /* Needed variables to call PacsEng_Phot_spu_setup_l                        */
    /* Compression modes: default=0, double=1, half=2, lossless=4 */
    /*                    transp=7, buffer=9                      */
    int comp_mode_blu = 0;
    int comp_mode_red = 0;
    int nraw_blu = 0; // Number of raw channels blue SPU
    int nraw_red = 0; // Number of raw channels red SPU
    bool startSPU = true; // Start SPU or not [true,false]
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_spu_setup_l                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,startSPU)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,startSPU);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsProcessInfoArrayRange.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $ 
//
// Purpose       : Process the timing information gathered in infoArray
//
// CUS author    : DAC
//
// Input arguments
// type    name        description
//
// tuple sortRanges    HSPOT input
// id, bluEdge, redEdge, repeatFactor, lineFlux, contFlux, lineWidth
//
// tuple sortRangesEXT HSPOT input added later
// fluxUnitSel, widthUnitSel, refWave
// tuple   infoArray
// Slew/Point/AOT       SlewCal or pointing mode or global AOT info
// 0.0                  not in use
// TotDur               duration of the phase Slew/Point/AOT
// nbLines              number of spectral lines observed in phase Slew/point
// nnods                number of nod cycles in phase Point
// m*n                  size of raster when applicable
// wave1                each of the nbLines wavelengths or waveStart
// wave2                each of the nbLines wavelengths or waveEnd
// order                grating order for line wave
// gratStep             grating step (needed to estimate "multiplexing")
// TOT,SRC,REF,CAL,OVR  the canonical OBCP duration (/nod/raster)
//
// Return values
// Type          Description
//
// Description   : Use the information in infoArray to compute several times and
// overheads, as well as the expected RMS fluctuations for each observed line
// infoArray is a three-element tuple:
//    infoArray[0] contains information on the SlewCal phase
//    infoArray[1] contains information on the OBS phase
//    infoArray[2] contains global information on the AOT
//                  
// Dependencies  : 
//
// Comments      : 
// 
// History       : 0.1  6-Sep-2005 DAC
// 0.2 27-sep-2005 Adding elements to compute RMS
// 0.3 28-sep-2005 Add nbGratSteps to infoArray
// 0.4 29-sep-2005 Add confOBCP to input arguments since I need nb_up_dn !!
// 0.5  6-oct-2005 Corrected Raster/Staring logic
// 0.6 14-oct-2005 Text of message
// 1.0 24-oct-2005 Add HTML tags
// 1.1 23-jan-2006 Multiplication by nbNods, mRaster, nRaster no longer needed
//                 since next_state collects time per raster per nod. Also
//                 eliminate "PACS overheads"
// 1.2  1-mar-2006 Use dformat for messages
// 2.0 11-mar-2006 Deal with LINE and CONT RMS values
// 2.1 22-nov-2006 Added "verbose" to input arguments
// 3.0 17-jan-2006 "Improved" messages
// 3.1 12-feb-2007 Accept as input the tuples sortRanges and sortRangesEXT
//                 Renamed to PacsProcessInfoArrayRange; only used
//                 for RANGE due to addition of ranges and rangesEXT
//                 Removed input aotID as only used for PacsRange
// 3.2 26-feb-2007 Added order information from HSPOT: needed by PacsSpecRMS
//                 to deal with "free" grating data
// 4.0 12-mar-2007 Call PacsSpecRMS with "bigTuple" needed to convey graphic
//                 information to main module
//                 Return bigTuple for use by main
// 4.1 12-apr-2007 Add obsOverhead for SCR-2813, implemented SCR-2924
// 4.2 19-apr-2007 Report Best,Worst, etc per "free" range
// 4.4 27-apr-2007 SPR-3147: change km/s into kms
// 4.5 23-may-2007 SPR-3210: return S/N
// 4.5 24-oct-2007 Added nbOBS and nbOFF to input arguments, same to
//                 PacsSpecRMS
// 5.0 01-dec-2009 VD SCR PHS-1272
//                 
{{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] procedure PacsProcessInfoArrayRange {
    /* infoArray                                                               */
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    /* rangeSPOT (the sorted version)                                             */
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [{"",0.0,0.0,0,0.0,0.0,0.0,"","",0.0}];
    /* confOBCP                                                                */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* order selected by user in HSPOT                                         */
    string orderSel = "order2";
    /* observatory overhead                                                    */
    int obsOverhead = 180;
    /* nbOBS and nbOFF                                                         */
    int nbOBS = 1;
    int nbOFF = 0;
    /* verbose?                                                                */
    bool verbose = true;
}{
    // How am I called?
    if(verbose) {
        debug_print("PROCArray: ranges   : " + rangeSPOT);
    }
    // Number of spectral lines (SlewCal and OBS)
    int nbKeyWaves = infoArray[0]{0}{3};
    int nbLines = infoArray[1]{0}{3};
    // Number of nods (OBS)
    int nbNodCycles = infoArray[1]{0}{4};
    // Nb of "pointings" for nbNodCycles
    int nbNods = 2 * nbNodCycles;
    if(nbNods == 0) {
        nbNods = 1;
    }
    // Call module to estimate RMS fluctuations; pass information via infoArray
    // and confOBCP (for nb_up_dn)
    // Array noiseWave[nbLines][8] used to contain: 
    //
    //    noiseWave[lineNb][BwlC,BrC,WwlC,WrC,BwlL,BrL,WwlL,WrL]
    //
    // where B: best, W: worst, wl: wavelength, r: RMS, C: continuum, L: line
    // Add three more elements refWave, rmsCont, rmsLine
    // Above is now included in "bigTuple"
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = PacsSpecRMS("RANGE",orderSel,infoArray,rangeSPOT,confOBCP,nbOBS,nbOFF,verbose);
    // Define variable to extract info from noiseTuple
    double[][] noiseWave = [[0.0]];
    // Useful variables
    int lineCnt = 0;
    string[] msgLine = ["Line1"];
    // one line of text
    // Report on nodding pattern and pointing details
    msgLine[lineCnt] = "PACS AOT: PacsRangeSpec";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Pointing mode: <B>" + infoArray[1]{0}{0} + "</B> with " + nbNodCycles + " nod cycles</p>";
    lineCnt = lineCnt + 1;
    int mRaster = infoArray[2]{0}{3};
    int nRaster = infoArray[2]{0}{4};
    // When either m or n are >1 then it is raster
    if(mRaster > 1 || nRaster > 1) {
        msgLine[lineCnt] = "<p>Raster size (lines/points):" + mRaster + "/" + nRaster + "</p>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "<p> Nod pattern: nominal position A, or A->B, B->A, etc.</p>";
    lineCnt = lineCnt + 1;
    if(nbNodCycles == 0) {
        msgLine[lineCnt] = "<p>   A </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles == 1) {
        msgLine[lineCnt] = "<p>   A->B </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles == 2) {
        msgLine[lineCnt] = "<p>   A->B B->A </p>";
        lineCnt = lineCnt + 1;
    }
    if(nbNodCycles > 2) {
        int aux1 = nbNodCycles - 2;
        msgLine[lineCnt] = "<p>   A->B B->A and " + aux1 + " more A<->B leg(s) </p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("AOT, PointMode and Nodding info",lineCnt,msgLine);
    // Global timing information for this AOT
    lineCnt = 0;
    int totAOT = infoArray[2]{0}{2};
    msgLine[lineCnt] = "<p> AOT total duration: " + totAOT + " [sec] </p>";
    lineCnt = lineCnt + 1;
    //  Next is tslew returned by PntReq
    int tslew = infoArray[0]{0}{2};
    msgLine[lineCnt] = "<ul><li> CalSlew (with overheads) " + tslew + " [sec]</li>";
    lineCnt = lineCnt + 1;
    // infoArray[1]{0}{2} is defined as the elementary OBCP duration (per nod
    // and per raster pointing; includes all wavelengths)
    //int totSRCREF = mRaster * nRaster * nbNods * infoArray[1]{0}{2};
    int totSRCREF = infoArray[1]{0}{2};
    msgLine[lineCnt] = "<li> SRC/REF (with overheads) " + totSRCREF + " [sec]</li>";
    lineCnt = lineCnt + 1;
    // 
    //    int slewSRCREF = totAOT - totSRCREF - tslew;
    //    msgLine[lineCnt] = "<li> Overheads in SRC/REF     " + 
    //                       slewSRCREF + " [sec]</li>";
    //    lineCnt = lineCnt + 1;
    int cost = totAOT - tslew;
    // If slewCal takes longer than obsOverhead, then it becomes the overhead
    if(tslew > obsOverhead) {
        obsOverhead = tslew;
    }
    cost = cost + obsOverhead;
    msgLine[lineCnt] = "<li><b>AOT cost</B> (includes time for slewing to source): " + totSRCREF + " + " + obsOverhead + " [sec] = " + cost + " [sec]</li></ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Global AOT durations",lineCnt,msgLine);
    if(verbose) {
        debug_print("++ Start ProcessArray debug info");
        debug_print(" CalSlew: " + infoArray[0]);
        debug_print(" OBS    : " + infoArray[1]);
        debug_print(" TotDur : " + infoArray[2]);
        debug_print("++ End of ProcessArray debug info");
    }
    // Inform the details of SlewCal to HSPOT user
    //   AOT prologue
    lineCnt = 0;
    msgLine[lineCnt] = "<ul><li> AOT prologue duration: " + infoArray[0]{1}[nbKeyWaves]{5} + " [sec]</li>";
    lineCnt = lineCnt + 1;
    //   For each keyWave
    for(int loop0 = 0 .. nbKeyWaves - 1) {
        msgLine[lineCnt] = "<li> KeyWave: " + infoArray[0]{1}[loop0]{0} + " [&micro;m]; CAL duration: " + infoArray[0]{1}[loop0]{5} + " [sec]</li>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    // Display message
    PacsMessageCenter("RANGE setup and CAL summary",lineCnt,msgLine);
    // Re-initialize lineCnt for new series of messages
    lineCnt = 0;
    // Report per LINE
    // Continue defining noiseWave for historical reasons (it used to be returned
    // by PacsSpecRMS, now replaced by bigTuple)
    for(int loop1 = 0 .. nbLines - 1) {
        noiseWave[loop1] = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0];
        //    CONTinuum
        noiseWave[loop1][0] = bigTuple[loop1]{0}{1}[0];
        noiseWave[loop1][1] = bigTuple[loop1]{0}{1}[1];
        noiseWave[loop1][2] = bigTuple[loop1]{0}{1}[2];
        noiseWave[loop1][3] = bigTuple[loop1]{0}{1}[3];
        //    LINE
        noiseWave[loop1][4] = bigTuple[loop1]{0}{1}[4];
        noiseWave[loop1][5] = bigTuple[loop1]{0}{1}[5];
        noiseWave[loop1][6] = bigTuple[loop1]{0}{1}[6];
        noiseWave[loop1][7] = bigTuple[loop1]{0}{1}[7];
        //    CONT and LINE for refWave     
        noiseWave[loop1][8] = bigTuple[loop1]{0}{1}[8];
        noiseWave[loop1][9] = bigTuple[loop1]{0}{1}[9];
        noiseWave[loop1][10] = bigTuple[loop1]{0}{1}[10];
        int trueObsTime = infoArray[1]{1}[loop1]{5};
        //    SrcTime includes REF!
        int trueSrcTime = infoArray[1]{1}[loop1]{6} + infoArray[1]{1}[loop1]{7};
        int lineOver = trueObsTime - trueSrcTime;
        //    Report on "free" ranges, if any...
        //    Up to three ranges: 0,1,2
        //    Tuples can only take literal indexes. Since cannot loop on index,
        //    construct bool "array exists?" of existing ranges
        bool[] good = [bigTuple[loop1]{0}{1}[0] != 0.0,bigTuple[loop1]{1}{1}[0] != 0.0,bigTuple[loop1]{2}{1}[0] != 0.0];
        //    good[0] is the nominal range; reported above
        //    Start with good[1]
        if(good[0]) {
            msgLine[lineCnt] = "<h3>" + rangeSPOT[loop1]{0} + ": " + infoArray[1]{1}[loop1]{0} + "-" + infoArray[1]{1}[loop1]{1} + " [&micro;m]:</h3>";
            lineCnt = lineCnt + 1;
            //        Go ahead and issue messages
            {int,string[]} freeMsg = {0,[""]};
            freeMsg = PacsRangeMessage(bigTuple[loop1]{0});
            //        Add new messages to already stored messages
            for(int loopM0 = 0 .. freeMsg{0} - 1) {
                msgLine[lineCnt] = freeMsg{1}[loopM0];
                lineCnt = lineCnt + 1;
            }
            //        Compute S/N ratios and insert in message stream
            //        NOTE: line in 1E-18; continuum in mJy
            //        Safeguard against division by zero
            if(bigTuple[loop1]{0}{1}[9] > 0.0010) {
                double s2nCONT = 0.0010 * rangeSPOT[loop1]{5} / bigTuple[loop1]{0}{1}[9];
                msgLine[lineCnt] = "<li>S/N continuum (ref. wavelength): " + dformat(s2nCONT,2) + "</li>";
                lineCnt = lineCnt + 1;
            }
            if(bigTuple[loop1]{0}{1}[10] > 1.0E-22) {
                double s2nLINE = 1.0E-18 * rangeSPOT[loop1]{4} / bigTuple[loop1]{0}{1}[10];
                msgLine[lineCnt] = "<li>S/N line (ref. wavelength): " + dformat(s2nLINE,2) + "</li>";
                lineCnt = lineCnt + 1;
            }
            //        Estimate resolution for given wavelength and order
            //        This is done here because the elements needed for the computation
            //        are at this level; i.e. it does not belong to bigTuple
            //        Need order and wavelength
            int order = infoArray[1]{1}[loop1]{2};
            double wave = noiseWave[loop1][8];
            debug_print("wave: " + wave);
            //        Build key to read SPEC_resolution table
            if(wave < 103.1) {
                string keyCOL = "resol" + order;
            } else {
                keyCOL = "resol1";
            }
            double resolkm = interpolate("SPEC_resolution",keyCOL,wave);
            //        Resolution in microns
            double resolmic = resolkm * wave / 300000.0;
            // Deal with possible loss of resolution
            // Compare instrument resolution with line width
            // User given line width
            double userWidth = rangeSPOT[loop1]{6};
            // User given width units
            string unitWidth = rangeSPOT[loop1]{8};
            // Is there a sensitivity degradation? 
            bool sensitDegrad = false;
            // Assume no degradtaion
            double degrad = 1.0;
            // Avoid divisiob by zero
            if(resolkm > 0.0) {
                // Do not compare torchons et servillettes
                if(unitWidth == "micron" && userWidth > resolmic) {
                    sensitDegrad = true;
                    degrad = sqrt(userWidth / resolmic);
                }
                if(unitWidth == "kms" && userWidth > resolkm) {
                    sensitDegrad = true;
                    degrad = sqrt(userWidth / resolkm);
                }
            }
            if(verbose) {
                debug_print("++line parameters: " + userWidth + " " + unitWidth);
                debug_print("++sensitDegrad: " + sensitDegrad);
                debug_print("++Degrad: " + degrad);
            }
            //        Add the information to current message stream
            msgLine[lineCnt] = "<li>FWHM at reference wavelength: " + dformat(resolkm,1) + " [km/s] or " + dformat(resolmic,3) + " [&micro;m]</li>";
            lineCnt = lineCnt + 1;
            if(sensitDegrad) {
                msgLine[lineCnt] = "<li><b>Warning:</b> the given line width, " + userWidth + " " + unitWidth + ", exceeds the instrumental FWHM; expect a loss of " + dformat(degrad,1) + " times in the LINE Signal-to-Noise ratio</li>";
                lineCnt = lineCnt + 1;
            }
            msgLine[lineCnt] = " <br>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "<li>Total duration (SRC+REF+PACS overheads) : " + trueObsTime + " [sec]</li>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "<li>SRC+REF (no overheads): " + trueSrcTime + " [sec]</li>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "</ul>";
            lineCnt = lineCnt + 1;
        }
        //    Continue with good[1]
        if(good[1]) {
            string assoc = bigTuple[loop1]{1}{0};
            //        Logic to identify LO and HI wavelength in range
            int nElem = length(bigTuple[loop1]{1}{2});
            double waveLO = bigTuple[loop1]{1}{2}[0];
            double waveHI = bigTuple[loop1]{1}{2}[nElem - 1];
            msgLine[lineCnt] = "<h4>" + dformat(waveLO,2) + "-" + dformat(waveHI,2) + " free range1 at " + assoc + "</h4>";
            lineCnt = lineCnt + 1;
            //        Go ahead and issue messages
            freeMsg = PacsRangeMessage(bigTuple[loop1]{1});
            //        Add new messages to already stored messages
            for(int loopM1 = 0 .. freeMsg{0} - 1) {
                msgLine[lineCnt] = freeMsg{1}[loopM1];
                lineCnt = lineCnt + 1;
            }
            //        Estimate resolution for given wavelength and order
            //        Need order and wavelength
            order = 1;
            if(assoc == "order2" || assoc == "order23") {
                order = 2;
            }
            if(assoc == "order3") {
                order = 3;
            }
            wave = bigTuple[loop1]{1}{1}[8];
            //        Build key to read SPEC_resolution table
            keyCOL = "resol" + order;
            resolkm = interpolate("SPEC_resolution",keyCOL,wave);
            //        Resolution in microns
            resolmic = resolkm * wave / 300000.0;
            //        Add the information to current message stream
            msgLine[lineCnt] = "<li>FWHM at reference wavelength: " + dformat(resolkm,1) + " [km/s] or " + dformat(resolmic,3) + " [&micro;m]</li>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "</ul>";
            lineCnt = lineCnt + 1;
        }
        if(good[2]) {
            assoc = bigTuple[loop1]{2}{0};
            //        Logic to identify LO and HI wavelength in range
            nElem = length(bigTuple[loop1]{2}{2});
            waveLO = bigTuple[loop1]{2}{2}[0];
            waveHI = bigTuple[loop1]{2}{2}[nElem - 1];
            msgLine[lineCnt] = "<h4>" + dformat(waveLO,2) + "-" + dformat(waveHI,2) + " free range2 at " + assoc + "</h4>";
            lineCnt = lineCnt + 1;
            //        Go ahead and issue messages
            freeMsg = PacsRangeMessage(bigTuple[loop1]{2});
            //        Add new messages to stored messages
            for(int loopM2 = 0 .. freeMsg{0} - 1) {
                msgLine[lineCnt] = freeMsg{1}[loopM2];
                lineCnt = lineCnt + 1;
            }
            //        Estimate resolution for given wavelength and order
            //        This is done here because the elements needed for the computation
            //        are at this level; i.e. it does not belong to bigTuple
            //        Need order and wavelength
            order = 1;
            if(assoc == "order2" || assoc == "order23") {
                order = 2;
            }
            if(assoc == "order3") {
                order = 3;
            }
            wave = bigTuple[loop1]{2}{1}[8];
            //        Build key to read SPEC_resolution table
            keyCOL = "resol" + order;
            resolkm = interpolate("SPEC_resolution",keyCOL,wave);
            //        Resolution in microns
            resolmic = resolkm * wave / 300000.0;
            //        Add the information to current message stream
            msgLine[lineCnt] = "<li>FWHM at reference wavelength: " + dformat(resolkm,1) + " [km/s] or " + dformat(resolmic,3) + " [&micro;m]</li>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "</ul>";
            lineCnt = lineCnt + 1;
        }
        //  End loop on nbLines
    }
    // Display message
    PacsMessageCenter("SpecRange summary",lineCnt,msgLine);
    // Return with bigTuple

    return bigTuple;
}

// CVS comments  : $Id: PacsPhotDefaults.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $ 
// Purpose       : Fill index=0 of OBCP and PHOTxxx tuples with known
//                 sensible default values
//
// CUS author    : DAC
// Script file   : PacsPhotDefaults.txt 
//
// Input arguments
// type           name     Description
// string         srcID    HSPOT define source ID
//
// Return values
// Type    Name                  Description
// tuple   confPHOTx & confOBCP  electronics and OBCP default parameters
//
// Description   : Give default values to tuples OBCP and PHOT. May
// use more information from yet to be created CAL-U files. So far
// only "throw" (HSPOT defined) appears necessary as a call argument
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 29-nov-2005 DAC. Based on PacsSpecDefaults
// 0.2 18-jan-2006 Introduced string calU variable
// 0.3 20-jan-2006 Use new PHOT_CHOP_params table where chopper positions
//     are defined in arcsec; added verbose
// 1.0  1-sep-2006 - Use sourceID instead of "throw" since chopper 
//                   throw depends on SRCE
//                 - editorial clean
// 2.0 10-oct-2007 Implemented SCR-3628: introduction of CAL-U file
//                 CONF_PHOT_params. This requires adding a new input
//                 variable: primePar
// 2.1 18-jun-2009 VD implement SCR PACS-1722
//
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} procedure PacsPhotDefaults {
    string srcID = "pointSRC" in ["pointSRC","smallSRC","largeSRC"]; // SourceID
    string primePar = "Prime" in ["Prime","Parallel"]; // Observing mode
    bool isBrightPacs = false;
    bool verbose = true; // Generate bla-bla
}{
    // Define variables to be used here
    {int,int,int,int,int,int,int,int,int} confPHOTblu = {0,0,0,0,0,0,0,0,0};
    {int,int,int,int,int,int,int,int,int} confPHOTred = {0,0,0,0,0,0,0,0,0};
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    // Open CAL-U with compression, raw pixels, etc. information
    if(isBrightPacs) {
        if(primePar == "Parallel") {
            string modePar = "ParBright";
        } else {
            if(primePar == "Prime") {
                modePar = "BrightPacs";
            }
        }
    } else {
        modePar = primePar;
    }
    int gain_red = ilookup("CONF_PHOT_params","gain_red",modePar);
    confPHOTred{0} = gain_red;
    int gain_blu = ilookup("CONF_PHOT_params","gain_blu",modePar);
    confPHOTblu{0} = gain_blu;
    int comp_mode_red = ilookup("CONF_PHOT_params","comp_mode_red",modePar);
    confPHOTred{3} = comp_mode_red;
    int comp_mode_blu = ilookup("CONF_PHOT_params","comp_mode_blu",modePar);
    confPHOTblu{3} = comp_mode_blu;
    int nb_raw_red = ilookup("CONF_PHOT_params","nb_raw_red",modePar);
    confPHOTred{6} = nb_raw_red;
    int nb_raw_blu = ilookup("CONF_PHOT_params","nb_raw_blu",modePar);
    confPHOTblu{6} = nb_raw_blu;
    // Chopper and grating expected at their default positions
    string calU = "SPEC_MEC_Defaults";
    int chop_def = ilookup(calU,"Photometry","chopper");
    confOBCP{17} = chop_def;
    // Position filter wheel at default position
    //   int fw_pos       = ilookup(calU,"Photometry","FW");
    // Initialize to don't care/don't know
    int fw_pos = 1;
    confOBCP{19} = fw_pos;
    int nb_cycles_obs_cal = 1;
    confOBCP{0} = nb_cycles_obs_cal;
    int nb_SRC_OFF = 1;
    confOBCP{3} = nb_SRC_OFF;
    int nb_rdouts_plateau = 4;
    confOBCP{4} = nb_rdouts_plateau;
    int nb_CS1_CS2 = 0;
    confOBCP{5} = nb_CS1_CS2;
    // Read chopper positions [arcsec] and convert to ENG units
    calU = "PHOT_CHOP_params";
    string convU = "PHOT_CHOP_sky";
    double auxSRC = dlookup(calU,srcID,"SRC");
    int onSRC = PacsReadChopSky(convU,auxSRC);
    double auxREF1 = dlookup(calU,srcID,"REF1");
    int onREF1 = PacsReadChopSky(convU,auxREF1);
    double auxREF2 = dlookup(calU,srcID,"REF2");
    int onREF2 = PacsReadChopSky(convU,auxREF2);
    // Report settings if verbose
    if(verbose) {
        debug_print("++PhotDefaults CHOPPER: " + auxSRC + " [arcsec] -> " + onSRC + " [ENG]");
        debug_print("++PhotDefaults CHOPPER: " + auxREF1 + " [arcsec] -> " + onREF1 + " [ENG]");
        debug_print("++PhotDefaults CHOPPER: " + auxREF2 + " [arcsec] -> " + onREF2 + " [ENG]");
    }
    confOBCP{12} = onSRC;
    confOBCP{13} = onREF1;
    confOBCP{14} = onREF2;
    // chop_pos_CS1     = confOBCP[0]{15};
    // chop_pos_CS2     = confOBCP[0]{16};
    int detector = 1;
    confOBCP{18} = detector;

    return {confPHOTblu,confPHOTred,confOBCP};
}

// Mission phase : Commissioning Phase
//
// Purpose : Exploration of VH_BLIND values to find the current telescope background level
//           during the cooling down period of the commissioning phase
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_telescBack
//
// Argument :
//  double[] dvls = [0.0,-0.5,-1.0]; // VL offset values to explore
//  double[] vhbs = [2.4, 2.25, 2.1, 1.95, 1.8]; // VH_BLIND values to explore
//  int acquisitionTime = 60; // Data acquisition time
//  string initialBiasTable = "BOLObias_firstTelescBack"; // Biase table file name to use during the measurement
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is set
//
// Description : This procedure should allow to assess the telescope backgroud
//               using a maximum numer of non saturated pixels
//
// Update:
//   2008-06-27, KO : First try
//   2008-07-04, KO : Now uses PHOT_set_biases(initialBiasTable,"DIRECT","LOW")
//   2009-04-30, KO : VL offset loop and chopper setting added
//   2009-05-04, KO, NB : Unused argument finalBiasTable removed
//
procedure Phot_telescBack {
    double[] dvls = [0.0,-0.5,-1.0]; // VL offset values to explore
    double[] vhbs = [2.4,2.25,2.1,1.95,1.8]; // VH_BLIND values to explore
    int acquisitionTime = 60; // Data acquisition time
    string initialBiasTable = "BOLObias_firstTelescBack"; // Biase table file name to use during the measurement
}{
    int stabilizationWaitTime = 60;
    // Stabilization time
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //*********************************************************
    // Set the default biases and dtart SPU, then set the gain
    //*********************************************************
    //
    PHOT_set_biases(initialBiasTable,"DIRECT","LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position 664
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    int nvls = length(dvls);
    int vhNb = 0;
    double vhVolt = 0.0;
    int vlNb = 0;
    double vlVolt = 0.0;
    for(int ivl = 0 .. nvls - 1) {
        //**********************
        // set VH and VL offset
        //**********************
        vhNb = ilookup(initialBiasTable,"VH","Bias");
        vlNb = ilookup(initialBiasTable,"VL","Bias");
        for(int igrp = 1 .. 6) {
            vhVolt = dlookup(initialBiasTable,"VH","BiasGR" + igrp);
            vlVolt = dlookup(initialBiasTable,"VL","BiasGR" + igrp);
            if(igrp == 1) {
                PHOT_bias_group_1(igrp,vhNb,"VH",vhVolt + dvls[ivl]);
                PHOT_bias_group_1(igrp,vlNb,"VL",vlVolt + dvls[ivl]);
            }
            if(igrp == 2) {
                PHOT_bias_group_2(igrp,vhNb,"VH",vhVolt + dvls[ivl]);
                PHOT_bias_group_2(igrp,vlNb,"VL",vlVolt + dvls[ivl]);
            }
            if(igrp == 3) {
                PHOT_bias_group_3(igrp,vhNb,"VH",vhVolt + dvls[ivl]);
                PHOT_bias_group_3(igrp,vlNb,"VL",vlVolt + dvls[ivl]);
            }
            if(igrp == 4) {
                PHOT_bias_group_4(igrp,vhNb,"VH",vhVolt + dvls[ivl]);
                PHOT_bias_group_4(igrp,vlNb,"VL",vlVolt + dvls[ivl]);
            }
            if(igrp == 5) {
                PHOT_bias_group_5(igrp,vhNb,"VH",vhVolt + dvls[ivl]);
                PHOT_bias_group_5(igrp,vlNb,"VL",vlVolt + dvls[ivl]);
            }
            if(igrp == 6) {
                PHOT_bias_group_6(igrp,vhNb,"VH",vhVolt + dvls[ivl]);
                PHOT_bias_group_6(igrp,vlNb,"VL",vlVolt + dvls[ivl]);
            }
        }
        //***************************
        // Loop over VHBlind forward
        //***************************
        int nvhbs = length(vhbs);
        for(int ivhb = 0 .. nvhbs - 1) {
            Pacs_BOLC_SET_VH_BLIND_G1(vhbs[ivhb]);
            Pacs_BOLC_SET_VH_BLIND_G2(vhbs[ivhb]);
            Pacs_BOLC_SET_VH_BLIND_G3(vhbs[ivhb]);
            Pacs_BOLC_SET_VH_BLIND_G4(vhbs[ivhb]);
            Pacs_BOLC_SET_VH_BLIND_G5(vhbs[ivhb]);
            Pacs_BOLC_SET_VH_BLIND_G6(vhbs[ivhb]);
            // Wait for stabilizationWaitTime s for stabilization
            delay(stabilizationWaitTime);
            // Measurement during acquisitionTime s
            TMMarker601();
            // mark the beginning of the acquisition
            delay(acquisitionTime);
            TMMarker600();
            // mark the end of the acquisition
        }
        //****************************
        // Loop over VHBlind backward
        //****************************
        for(int i = 1 .. nvhbs - 1) {
            Pacs_BOLC_SET_VH_BLIND_G1(vhbs[nvhbs - i - 1]);
            Pacs_BOLC_SET_VH_BLIND_G2(vhbs[nvhbs - i - 1]);
            Pacs_BOLC_SET_VH_BLIND_G3(vhbs[nvhbs - i - 1]);
            Pacs_BOLC_SET_VH_BLIND_G4(vhbs[nvhbs - i - 1]);
            Pacs_BOLC_SET_VH_BLIND_G5(vhbs[nvhbs - i - 1]);
            Pacs_BOLC_SET_VH_BLIND_G6(vhbs[nvhbs - i - 1]);
            // Wait for stabilizationWaitTime s for stabilization
            delay(stabilizationWaitTime);
            // Measurement during acquisitionTime s
            TMMarker601();
            // mark the beginning of the acquisition
            delay(acquisitionTime);
            TMMarker600();
            // mark the end of the acquisition
        }
    }
    //
    //*******************************
    // Select Filter B (70 microns)
    //*******************************
    //
    PHOT_fltw_move("POS B");
    //
    for(int ivl2 = 0 .. nvls - 1) {
        //**********************
        // set VH and VL offset
        //**********************
        vhNb = ilookup(initialBiasTable,"VH","Bias");
        vlNb = ilookup(initialBiasTable,"VL","Bias");
        for(int igrp2 = 1 .. 6) {
            vhVolt = dlookup(initialBiasTable,"VH","BiasGR" + igrp2);
            vlVolt = dlookup(initialBiasTable,"VL","BiasGR" + igrp2);
            if(igrp2 == 1) {
                PHOT_bias_group_1(igrp2,vhNb,"VH",vhVolt + dvls[ivl2]);
                PHOT_bias_group_1(igrp2,vlNb,"VL",vlVolt + dvls[ivl2]);
            }
            if(igrp2 == 2) {
                PHOT_bias_group_2(igrp2,vhNb,"VH",vhVolt + dvls[ivl2]);
                PHOT_bias_group_2(igrp2,vlNb,"VL",vlVolt + dvls[ivl2]);
            }
            if(igrp2 == 3) {
                PHOT_bias_group_3(igrp2,vhNb,"VH",vhVolt + dvls[ivl2]);
                PHOT_bias_group_3(igrp2,vlNb,"VL",vlVolt + dvls[ivl2]);
            }
            if(igrp2 == 4) {
                PHOT_bias_group_4(igrp2,vhNb,"VH",vhVolt + dvls[ivl2]);
                PHOT_bias_group_4(igrp2,vlNb,"VL",vlVolt + dvls[ivl2]);
            }
            if(igrp2 == 5) {
                PHOT_bias_group_5(igrp2,vhNb,"VH",vhVolt + dvls[ivl2]);
                PHOT_bias_group_5(igrp2,vlNb,"VL",vlVolt + dvls[ivl2]);
            }
            if(igrp2 == 6) {
                PHOT_bias_group_6(igrp2,vhNb,"VH",vhVolt + dvls[ivl2]);
                PHOT_bias_group_6(igrp2,vlNb,"VL",vlVolt + dvls[ivl2]);
            }
        }
        //
        //***************************
        // Loop over VHBlind forward
        //***************************
        for(int ivhb2 = 0 .. nvhbs - 1) {
            Pacs_BOLC_SET_VH_BLIND_G1(vhbs[ivhb2]);
            Pacs_BOLC_SET_VH_BLIND_G2(vhbs[ivhb2]);
            Pacs_BOLC_SET_VH_BLIND_G3(vhbs[ivhb2]);
            Pacs_BOLC_SET_VH_BLIND_G4(vhbs[ivhb2]);
            Pacs_BOLC_SET_VH_BLIND_G5(vhbs[ivhb2]);
            Pacs_BOLC_SET_VH_BLIND_G6(vhbs[ivhb2]);
            // Wait for stabilizationWaitTime s for stabilization
            delay(stabilizationWaitTime);
            // Measurement during acquisitionTime s
            TMMarker602();
            // mark the beginning of the acquisition
            delay(acquisitionTime);
            TMMarker600();
            // mark the end of the acquisition
        }
        //****************************
        // Loop over VHBlind backward
        //****************************
        for(int i2 = 1 .. nvhbs - 1) {
            Pacs_BOLC_SET_VH_BLIND_G1(vhbs[nvhbs - i2 - 1]);
            Pacs_BOLC_SET_VH_BLIND_G2(vhbs[nvhbs - i2 - 1]);
            Pacs_BOLC_SET_VH_BLIND_G3(vhbs[nvhbs - i2 - 1]);
            Pacs_BOLC_SET_VH_BLIND_G4(vhbs[nvhbs - i2 - 1]);
            Pacs_BOLC_SET_VH_BLIND_G5(vhbs[nvhbs - i2 - 1]);
            Pacs_BOLC_SET_VH_BLIND_G6(vhbs[nvhbs - i2 - 1]);
            // Wait for stabilizationWaitTime s for stabilization
            delay(stabilizationWaitTime);
            // Measurement during acquisitionTime s
            TMMarker602();
            // mark the beginning of the acquisition
            delay(acquisitionTime);
            TMMarker600();
            // mark the end of the acquisition
        }
    }
    //
    // sync the bus
    sync();
}

// VS comments  : $Id: PacsSpecAuxRMS.txt,v 1.9 2007/10/25 12:15:42 dcesarsk Exp $ 
// Purpose       : To compute RMS vs. WaveLength; to establish min,max RMS
//                 and their associated wavelength. arrayID 
//
// CUS author    : 
// Script file   : PacsSpecAuxRMS.txt 
//
// Input arguments
// type    name         description
// string  aotID        RANGE or LINE AOT
// string  arrayID      ID for current array
// double  wave         Array of wavelengths
// double  waveRef      Wave reference
// double  intTime      Integration time
// bool    verbose      Verbose or not
//
// Return values
// Type          Description
// tuple {{double[]},{double[],double[],double[]}}
// Description   : 
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 0.1
// History       : 0.1  12-mar-2007 DAC
//                 0.2  13-mar-2007 Added "string" to return tuple
//                 0.3  16-apr-2007 Use arrayID to choose the relevant
//                                  sensitivity table. Added logic to
//                                  choose one of the four SPECcontline
//                                  files
//                 1.0  23-oct-2007 Added input variable to identify
//                                  FreqSwitch
//                 1.1  24-oct-2007 Accept nbOBS and nbOFF (not used
//                                  yet)
//                 2.0 01-dec-2009 VD SCR PHS-1272 
//                 3.0 20-jan-2010 VD PHS-1302
//                 4.0 26-jan-2010 VD PHS-1302 !! sedb2a .. waveRef <102.0!
//                                                order 3 too! etc
//
{string,double[],double[],double[],double[]} procedure PacsSpecAuxRMS {
    /* RANGE or LINE AOT                                                    */
    string aotID = "RANGE";
    /* ID for this RMS computation                                          */
    string arrayID = "undefined";
    /* Array of wavelengths                                                 */
    double[] wave = [0.0];
    /* Wave reference                                                       */
    double waveRef = 100.0;
    /* Integration time                                                     */
    double intTime = 10.0;
    /* Type of observation                                                  */
    string obsType = "whatever";
    /* nbOBS and nbOFF                                                       */
    int nbOBS = 1;
    int nbOFF = 0;
    /* Verbose or not                                                        */
    bool verbose = false;
}{
    // Number of wavelengths in array
    int nbWaves = length(wave);
    if(verbose) {
        debug_print("AuxRMS:Size wave table: " + nbWaves);
    }
    // Create arrays for rmsNoiseCONT and rmsNoiseLINE
    double[] rmsNoiseC = [0.0];
    double[] rmsNoiseL = [0.0];
    // Integration time related variables
    // intTime is SRC/REF for chopping !!Each one, not the sum!!
    // For FreqSwitch, intTime is the total time LINE+REF  (assume we switch by a 
    // few pixels)
    // In either case, the "line" is the result of a subtraction (either SRC-REF 
    // or SRC - shiftedSRC). When both "SRC" and "REF" have the same rms, the RMS
    // increase introduced by the subtraction operation is sqrt(2). 
    // In raster/OFF, each raster point has a noise ONrms. However, the OFF position
    // is performed nbOFF times; its rms is OFFrms = ONrms/sqrt(nbOFF). The rms
    // of the difference is then sqrt(1 + 1/nbOFF) larger. Ignore for raster
    // for time being
    double difRMSfactor = sqrt(2.0);
    // The new frequency switch scheme uses 2 OFF positions to be subtracted
    // from the SRC - shiftedSRC array. This introduces an extra sqrt(1+1/2)
    // difRMSfactor = sqrt(2.0)*sqrt(1.5) = sqrt(3.0)
    if(obsType == "FreqSwitch") {
        difRMSfactor = sqrt(3.0);
    }
    // Scaling factor for tabulated rms (good for 1 sec time)
    debug_print("AuxRMS: intTime " + dformat(intTime,2));
    double scale = difRMSfactor / sqrt(intTime);
    if(verbose) {
        debug_print("AuxRMS: intTime " + dformat(intTime,2));
        debug_print("AuxRMS: difRMSfactor  " + dformat(difRMSfactor,2));
        debug_print("AuxRMS: scaleRMS" + dformat(scale,3));
        debug_print("AuxRMS: waveRef: " + waveRef);
    }
    // Establish which sensitivity table shall be used
    // PHS-198 in parts: waveRef MUST be entered in order 1 parallel bands
    string sensTable = "TBD";
    string sensTablePar = "TBD";
    //    if(arrayID == "order1" || waveRef >= 103.1) {
    if(arrayID == "order1") {
        sensTable = "SPECContLine1";
        sensTablePar = "SPECContLine1";
    }
    if(arrayID == "order2" && waveRef < 102.0) {
        sensTable = "SPECContLine2";
        sensTablePar = "SPECContLine2";
    } else {
        if(arrayID == "order2" && waveRef >= 102.0) {
            sensTable = "SPECContLine2";
            sensTablePar = "SPECContLine1";
        }
    }
    if(arrayID == "order3" && waveRef < 102.0) {
        sensTable = "SPECContLine3";
        sensTablePar = "SPECContLine3";
    } else {
        if(arrayID == "order3" && waveRef >= 102.0) {
            sensTable = "SPECContLine3";
            sensTablePar = "SPECContLine1";
        }
    }
    if(arrayID == "order23" && waveRef < 102.0) {
        sensTable = "SPECContLine23";
        sensTablePar = "SPECContLine23";
    } else {
        if(arrayID == "order23" && waveRef >= 102.0) {
            sensTable = "SPECContLine23";
            sensTablePar = "SPECContLine1";
        }
    }
    if(verbose) {
        debug_print("AuxRMS in Nom band will use table " + sensTable);
        debug_print("AuxRMS in Par band will use table " + sensTablePar);
    }
    if(sensTable == "TBD") {
        error("Internal error: did not find proper sensitivity table");
    }
    // Get rms/sec from SPECcontline, a value per wavelength
    // Create CONT and LINE noise arrays; wave array already exists
    ///   if (verbose) {debug_print("AuxRMS:Wave Interpol From/To]: " 
    ///                          + wave[0] + "/" + wave[nbWaves-1]);}
    for(int loop0 = 0 .. nbWaves - 1) {
        //     Current wavelength
        double waveNow = wave[loop0];
        //     Get CONT and LINE rms values
        //     Use scale factor to convert into observed noise     
        rmsNoiseC[loop0] = scale * interpolate(sensTable,"contRMS",waveNow);
        rmsNoiseL[loop0] = scale * interpolate(sensTable,"lineRMS",waveNow);
    }
    // Find min and max of rmsNoiseC
    int[] minmax = PacsArrayMinMax(rmsNoiseC,verbose);
    double noiseCmin = rmsNoiseC[minmax[0]];
    double waveCmin = wave[minmax[0]];
    double noiseCmax = rmsNoiseC[minmax[1]];
    double waveCmax = wave[minmax[1]];
    // Find min and max of rmsNoiseL
    minmax = PacsArrayMinMax(rmsNoiseL,verbose);
    double noiseLmin = rmsNoiseL[minmax[0]];
    double waveLmin = wave[minmax[0]];
    double noiseLmax = rmsNoiseL[minmax[1]];
    double waveLmax = wave[minmax[1]];
    //  Deal with reference wavelength
    if(verbose) {
        debug_print("AuxRMS:Interpolate w/lambda " + waveRef);
    }
    double noiseRefCont = scale * interpolate(sensTablePar,"contRMS",waveRef);
    double noiseRefLine = scale * interpolate(sensTablePar,"lineRMS",waveRef);
    // Compute the RMS fluctuations at special wavelengths
    // Continuum
    double noiseCref = noiseRefCont;
    // Line
    double noiseLref = noiseRefLine;
    if(verbose) {
        debug_print("AuxRMS:nbOBS/nbOFF: " + nbOBS + "/" + nbOFF);
        //      debug_print("AuxRMS:rmsCONT min/max: " + noiseCmin + "/" + noiseCmax);
        debug_print("AuxRMS:RMScont min/waveMin: " + noiseCmin + " [Jy] at " + waveCmin);
        debug_print("AuxRMS:RMScont max/waveMax: " + noiseCmax + " [Jy] at " + waveCmax);
        debug_print("AuxRMS:RMScont ref/waveRef: " + noiseCref + " [Jy] at " + waveRef);
        //      debug_print("AuxRMS:rmsLINE min/max: " + noiseLmin + "/" + noiseLmax);
        debug_print("AuxRMS:RMSline min/waveMin: " + noiseLmin + " [Jy] at " + waveLmin);
        debug_print("AuxRMS:RMSline max/waveMax: " + noiseLmax + " [Jy] at " + waveLmax);
        debug_print("AuxRMS:RMSline ref/waveRef: " + noiseLref + " [Jy] at " + waveRef);
    }
    // Copy results to noiseWave and return
    double[] noiseWave = [0.0];
    //   CONTinuum
    noiseWave[0] = waveCmin;
    noiseWave[1] = noiseCmin;
    noiseWave[2] = waveCmax;
    noiseWave[3] = noiseCmax;
    //   LINE
    noiseWave[4] = waveLmin;
    noiseWave[5] = noiseLmin;
    noiseWave[6] = waveLmax;
    noiseWave[7] = noiseLmax;
    //   CONT and LINE for refWave     
    noiseWave[8] = waveRef;
    noiseWave[9] = noiseCref;
    noiseWave[10] = noiseLref;
    if(verbose) {
        debug_print("AuxRMS:arrayID: " + arrayID);
    }

    return {arrayID,noiseWave,wave,rmsNoiseC,rmsNoiseL};
}

// Missionphase  : PACS FM Test
//
// Purpose       : Switch on of bolometer groups
//
// Author        : T. Mueller
//
// File          : PHOT_switchon_groups
// Arguments     : none
//                 
//
// Description   : This script will switch on the different groups
//                 of the instrument. BOLC will start in "HK only" mode.
//                              
// Comments      :  Coded based on PhFPU UM, Draft 5
//                         SCR PACS-1866
//
// Version       : 1.1
// History       : 1.0 / 08-Nov-2006 initial version by TM
//                    1.1 / 08-Nov-2006 TM: autonomy function 17 added
//                    1.1.1 14-nov-2006 Disable autonomy function for time being
//                    1.2 17-nov-2006 Enable AF with delay after switchon
//                    1.3 09-apr-2007 disable AFs before starting
//                 1.0 Modified from PHOT_switchon_groups and keep G5 and 6 off
// 
procedure PHOT_switchon_12346 {
}{
    // disable AF 12, AF 15, AF 17
    // disable AF 12 (to check for the protection biases)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_BIAS","DISABLE");
    // disable AF 15 (to check for the VSS currents of groups and BUs)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","DISABLE");
    // disable AF 17 (to check for group power)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_V_PWR","DISABLE");
    //
    delay(2);
    // PC103420 "DMC_SEND_COMMAND_BOLC" SEND COMMAND TO BOL CONTROLLER
    //         PP071420 "BOLOMETER_COMMAND"
    //
    // # Execute BOLC initialisation
    // # for CQM we switched on everything at once, now group by
    // # group starting with 1
    // 
    // # Switch-on group 1 The corresponding bits
    // # are (2^0)=1, which is 1 in hex.
    // tcsend PC103420 {PP071420 0x0A000001 LO}
    // waittime 1.0
    int operand = 0xa000001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2. The corresponding bits
    // # are (2^0+2^1)=3, which is 3 in hex.
    // tcsend PC103420 {PP071420 0x0A000003 LO}
    // waittime 1.0
    operand = 0xa000003;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3. The corresponding bits
    // # are (2^0+2^1+2^2)=7, which is 7 in hex.
    // tcsend PC103420 {PP071420 0x0A000007 LO}
    // waittime 1.0
    operand = 0xa000007;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4. The corresponding bits
    // # are (2^0+2^1+2^2+2^3)=15, which is F in hex.
    // tcsend PC103420 {PP071420 0x0A00000F LO}
    // waittime 1.0
    operand = 0xa00000f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4,5. The corresponding bits
    // # are (2^0+2^1+2^2+2^3+2^4)=31, which is 1F in hex.
    // tcsend PC103420 {PP071420 0x0A00001F LO}
    // waittime 1.0
    //operand = 0xa00001f;
    //Pacs_DMC_SEND_COMMAND_BOLC(operand);
    //delay(1);
    // # Switch-on groups 1,2,3,4,5,6. The corresponding bits
    // # are (2^0+2^1+2^2+2^3+2^5)=47, which is 3F in hex.
    // tcsend PC103420 {PP071420 0x0A00003F LO}
    // waittime 1.0
    operand = 0xa00002f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(8);
    //------------------------------------
    // autonomy function
    //------------------------------------
    // autonomy function 17 "generate_event_pwr" checks the
    // HK entries: PC_PWR_ANA_P_#, PC_PWR_ANA_N_# and PC_PWR_DIG_#,
    // with # = [1,2,3,4,5,6,7]
    //Pacs_DPU_SET_FUNCT("EVENT_BOL_V_PWR","ENABLE");
    // Wait another 2 sec
    delay(2);
    //
    //-----------------
    // End of Procedure
    //-----------------
}

// Missionphase  : PACS FM Test
//
// Purpose       : Switch on of bolometer groups
//
// Author        : T. Mueller
//
// File          : PHOT_switchon_groups
// Arguments     : none
//                 
//
// Description   : This script will switch on the different groups
//                 of the instrument. BOLC will start in "HK only" mode.
//                              
// Comments      :  Coded based on PhFPU UM, Draft 5
//                          SCR PACS-1866
//
// Version       : 1.1
// History       : 1.0 / 08-Nov-2006 initial version by TM
//                    1.1 / 08-Nov-2006 TM: autonomy function 17 added
//                    1.1.1 14-nov-2006 Disable autonomy function for time being
//                    1.2 17-nov-2006 Enable AF with delay after switchon
//                    1.3 09-apr-2007 disable AFs before starting
//                 1.0 Modified from PHOT_switchon_groups and keep G5 and 6 off
// 
procedure PHOT_switchon_12345 {
}{
    // disable AF 12, AF 15, AF 17
    // disable AF 12 (to check for the protection biases)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_BIAS","DISABLE");
    // disable AF 15 (to check for the VSS currents of groups and BUs)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","DISABLE");
    // disable AF 17 (to check for group power)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_V_PWR","DISABLE");
    //
    delay(2);
    // PC103420 "DMC_SEND_COMMAND_BOLC" SEND COMMAND TO BOL CONTROLLER
    //         PP071420 "BOLOMETER_COMMAND"
    //
    // # Execute BOLC initialisation
    // # for CQM we switched on everything at once, now group by
    // # group starting with 1
    // 
    // # Switch-on group 1 The corresponding bits
    // # are (2^0)=1, which is 1 in hex.
    // tcsend PC103420 {PP071420 0x0A000001 LO}
    // waittime 1.0
    int operand = 0xa000001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2. The corresponding bits
    // # are (2^0+2^1)=3, which is 3 in hex.
    // tcsend PC103420 {PP071420 0x0A000003 LO}
    // waittime 1.0
    operand = 0xa000003;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3. The corresponding bits
    // # are (2^0+2^1+2^2)=7, which is 7 in hex.
    // tcsend PC103420 {PP071420 0x0A000007 LO}
    // waittime 1.0
    operand = 0xa000007;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4. The corresponding bits
    // # are (2^0+2^1+2^2+2^3)=15, which is F in hex.
    // tcsend PC103420 {PP071420 0x0A00000F LO}
    // waittime 1.0
    operand = 0xa00000f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4,5. The corresponding bits
    // # are (2^0+2^1+2^2+2^3+2^4)=31, which is 1F in hex.
    // tcsend PC103420 {PP071420 0x0A00001F LO}
    // waittime 1.0
    operand = 0xa00001f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    //delay(1);
    // # Switch-on groups 1,2,3,4,5,6. The corresponding bits
    // # are (2^0+2^1+2^2+2^3+2^4+2^5)=63, which is 3F in hex.
    // tcsend PC103420 {PP071420 0x0A00003F LO}
    // waittime 1.0
    //operand = 0xa00003f;
    //Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(8);
    //------------------------------------
    // autonomy function
    //------------------------------------
    // autonomy function 17 "generate_event_pwr" checks the
    // HK entries: PC_PWR_ANA_P_#, PC_PWR_ANA_N_# and PC_PWR_DIG_#,
    // with # = [1,2,3,4,5,6,7]
    //Pacs_DPU_SET_FUNCT("EVENT_BOL_V_PWR","ENABLE");
    // Wait another 2 sec
    delay(2);
    //
    //-----------------
    // End of Procedure
    //-----------------
}

// CVS comments  : $Id: PacsDureeOBCP4.txt,v 1.2 2007/04/25 15:14:04 dcesarsk Exp $ 
// Purpose       : Estimate duration of OBCP4 with input parameters
//
// CUS author    : 
// Script file   : PacsDureeOBCP4.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : V0.1  24-nov-2005 DAC
// V0.2  1-Dec-2005 Add OBCP's 5 [sec] overhead to estimate based on DMC duration
int[] procedure PacsDureeOBCP4 {
    int nb_SRC_REF = 4; // p01 Nb of cycles SRC->REF1->SRC->REF2
    int nb_rdouts_plateau = 4; // p03 Nb of readouts per chopper plateau
    int nb_cycles_obs_cal = 1; // p06 Nb of repetions of OBS-CAL cycle
    int nb_CS1_CS2 = 0; // p07 Nb of cycles CS1->CS2
}{
    // Call the corresponding DMC sequence
    int[] duree = DMC_phot_2_3_chop(nb_SRC_REF,nb_rdouts_plateau,nb_cycles_obs_cal,nb_CS1_CS2);
    // Convert number of readouts into seconds
    // Obtain system parameter from PACSparams
    // BOL readout frequency [Hz] and readout period [msec]
    double bol_freq = dlookup("PACSparams","bolo_sample","freq_time");
    // string bol_unit = slookup("PACSparams","bolo_sample","unit");
    double bol_period = 1000.0 / bol_freq;
    // debug_print("Bolo sample: " + bol_freq + " " + bol_unit);
    // debug_print("Bolo period: " + bol_period + "[msec]");
    // Convert duration [rdouts] into [msec]
    // Create return time array; convert into [sec]
    int[] time_array = [0,0,0,0,0];
    for(int aux = 0 .. 4) {
        time_array[aux] = ifloor(double(duree[aux]) * bol_period);
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    //
    // V0.2 correction
    time_array[0] = time_array[0] + 5;
    time_array[4] = time_array[4] + 5;
    // Return total duration [sec] to calling program

    return time_array;
}

// Mission phase : PV Phase
//
// Purpose : PCD req.1.1.1bis for the PV Phase
//           Measure the responsivity with a 4x9 or 4x8 raster on a point source:
//           Chopped     : Noise measured after the 4x8 raster at the off chopper position
//                         during 4*measure_time. The chopped measurement requires 105 arcsec offset.
//           Non-chopped : Noise measured at last 4 pointings of the 4x9 raster of 13.5 arcsec offset.
//
// Author : Koryo Okumura
//
// Version : Wed Jul 29 12:15:01 EDT 2009
//
// CUS script : obs PacsCal_Phot_highGainBiasDirect
//
// Argument :
//   string select = "ginit" in ["ginit","g1_0","g1_3","g1_6","g1_7","g1_8","g1_9","g2_0","g2_1","g2_2","g2_3","g2_4","g2_5","g2_6","g2_7","g2_8","g2_9","g3_0","g3_1","g3_3","g3_5","binit","b1_0","b1_3","b1_6","b1_7","b1_8","b1_9","b2_0","b2_1","b2_2","b2_3","b2_4","b2_5","b2_6","b2_7","b2_8","b2_9","b3_0","b3_1","b3_3","b3_5","final"]; // Select a configuration or initialize or finalize
//   int naifid = 2000001; // SSO tracking object number
//   double ra = 0.0; // RA
//   double dec = 0.0; // Dec
//   int measure_time = 120; // measure time in seconds
//   string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
//   string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
//   int nLoops1 = 30; // number of CSs cycles during slew
//   int nLoops5 = 30; // number of CSs cycles during final hold
//   int readouts_plateau = 64; // number of readouts per chopper plateau
//   string calGain = "HIGH" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//   bool chop = true; // Chopping within FOV during the raster
//   bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + PHOT_orbit_prologue is executed (then more than the minimum requirement below is fullfilled):
//     - Bolometers are biased
//     - Sequencer is activated
//
// Description : PacsCal script of Phot_highGainBiasDirect
//   init + During the slew, CSs are measured through 2 filters
//        + Set a filter corresponding to the given seqNum
//        + Set the biases group by group
//   if no_chop
//        + Set the chopper on the optical center
//        + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group corresponding to the selected bias
//        + Do a 4x9 raster measurement
//   if chop
//        + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group corresponding to the selected bias
//        + Do a 4x8 raster with chopped measurement
//        + After the raster, noise measurement during 4xmeasure_time
//   then + After the raster, CSs and sky are measured through 2 filters
//   stop + The biases are set following a given bias table
//
// Dependencies : Commissioning and PV data at low gain of PCD req.1.1.1
// Comment : SCR PACS-1872
//
// Comments : generated by IA script : cus_PVph_highGainBias(1)
//
obs PacsCal_Phot_highGainBiasDirect {
    string select = "ginit" in ["ginit","g1_0","g1_3","g1_6","g1_7","g1_8","g1_9","g2_0","g2_1","g2_2","g2_3","g2_4","g2_5","g2_6","g2_7","g2_8","g2_9","g3_0","g3_1","g3_3","g3_5","binit","b1_0","b1_3","b1_6","b1_7","b1_8","b1_9","b2_0","b2_1","b2_2","b2_3","b2_4","b2_5","b2_6","b2_7","b2_8","b2_9","b3_0","b3_1","b3_3","b3_5","final"]; // Select a configuration
    int naifid = 2000001; // SSO tracking object number
    double ra = 0.0; // RA
    double dec = 0.0; // Dec
    int measure_time = 120; // measure time in seconds per pointing
    string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
    string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 64; // number of readouts per chopper plateau
    string calGain = "HIGH" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    bool chop = true; // Chopping within FOV during the raster
    bool verbose = true;
}{
    bool execute = true;
    int nRdts = readouts_plateau - 1;
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = duration(PHOT_change_biases(endBiasTable,calMode,calGain));
    int timeBckBias = 0;
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,"DIRECT","HIGH"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,calMode,"HIGH"));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,"DIRECT",calGain));
    }
    int timeCal3CPR1 = duration(OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644));
    int tNewSetup = duration(Phot_highGainBiasDirect(select,startBiasTable,endBiasTable));
    int tslewmin = 0;
    int tih = 0;
    int tfh = 0;
    // Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // yoffset [arcsec] (Positive offset to get an empty sky in the last 4 pointings)
    double yoffset = 13.5;
    // zoffset [arcsec] : Finally we do not risk to provoke the opposite correction
    double zoffset = 0.0;
    // Duration of "stable" pointing in seconds
    int tp = 0;
    //Issue PointReq
    int[] ts = [0];
    if(select == "ginit" || select == "binit" || select == "final") {
        // Several arguments needed for "basic_fine_pointing"
        // time to set OBSID and biases then PacsPhotSlewCal
        // Minimum slew time
        if(select == "final") {
            timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
        } else {
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT","HIGH"));
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT",calGain));
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"HIGH"));
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
            }
        }
        tslewmin = timeOBSID + timeChgBias + timeCal3CPR1 + tNewSetup;
        if(verbose) {
            debug_print("Tslewmin: " + tslewmin);
        }
        // Initial hold
        tih = 0;
        // Final hold
        tfh = timeEndID;
        // Duration of "stable" pointing in seconds
        tp = 1;
        //Issue PointReq
        ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    } else {
        // Several arguments needed for "basic_raster_pointing"
        // time to set OBSID and biases then PacsPhotSlewCal
        int timeCal3CPR5 = duration(OBCP_chopped_photometry(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,644));
        // Minimum slew time
        tslewmin = timeOBSID + timeChgBias + timeBckBias + tNewSetup + timeCal3CPR1;
        if(verbose) {
            debug_print("Tslewmin: " + tslewmin);
        }
        // Initial hold
        tih = 0;
        // Final hold
        tfh = timeChgBias + timeCal3CPR5 + timeEndID;
        // Fixed in the sky coordinates
        bool fixed = false;
        // Orientation angle (degrees)
        double patt = 0.0;
        // Number of pointings in a leg
        int m = 4;
        // Number of legs
        int n = 9;
        // Angular distance (arcsec) between 2 pointings
        double d1 = 26.0;
        // Angular distance (arcsec) between 2 legs
        double d2 = 26.5;
        // Duration of "stable" pointing in seconds
        if(chop) {
            int nLoops = measure_time * 40 / (2 * readouts_plateau);
            tp = duration(OBCP_chopped_photometry(0,0,nRdts,0,0,nLoops,1,-6578,7756,0,0,644));
            // 4x8 raster instead of 4x9
            n = 8;
            // Noise measurements after the raster
            tfh = tfh + 4 * measure_time + duration(TMMarker602()) + duration(TMMarker600());
            // Positive pointing offset for chopping to get negative chopper position offset
            yoffset = 105.0;
        } else {
            tp = measure_time;
        }
        // Go to OFF position every k pointings (not relevant with SSO tracking)
        int k = 0;
        // time in seconds on the OFF position (not relevant with SSO tracking)
        int top = 0;
        // OFF position RA coordinate (not relevant with SSO tracking)
        double raoff = 0.0;
        // OFF position Dec coordinate (not relevant with SSO tracking)
        double decoff = 0.0;
        //Issue PointReq
        ts = basic_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,k,top,raoff,decoff);
    }
}{
    int tNOW = time();
    int[] state = [0];
    if(select == "ginit" || select == "binit" || select == "final") {
        //  Start the sequence
        while(state[0] >= 0) {
            state = next_state();
            tNOW = time();
            if(state[0] == 1) {
                if(verbose) {
                    debug_print("SLEW starts at " + tNOW);
                }
                // Set OBSID
                WriteOBSID($OBSID);
                data_rate(120.0);
                // Set biases and start SPU
                if(select == "final") {
                    PHOT_change_biases(calBiasTable,calMode,calGain);
                } else {
                    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,"DIRECT","HIGH");
                    }
                    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,"DIRECT",calGain);
                    }
                    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,calMode,"HIGH");
                    }
                    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,calMode,calGain);
                    }
                }
                //************************************
                //  Call the Phot_highGainBiasDirect
                //************************************
                Phot_highGainBiasDirect(select,startBiasTable,endBiasTable);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                tNOW = time();
                if(verbose) {
                    debug_print("SLEW ends at   " + tNOW);
                }
            }
            if(state[0] == 2) {
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 3) {
                tNOW = time();
                if(verbose) {
                    debug_print("POINT starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("POINT ends at     " + tNOW);
                }
            }
            if(state[0] == 5) {
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD starts at   " + tNOW);
                }
                // Write EndID
                data_rate(0.0);
                WriteEndID();
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD ends at     " + tNOW);
                }
            }
        }
    } else {
        int finalChop = 0;
        //  Start the sequence
        while(state[0] >= 0) {
            state = next_state();
            tNOW = time();
            if(state[0] == 1) {
                if(verbose) {
                    debug_print("SLEW starts at " + tNOW);
                }
                // Set OBSID
                WriteOBSID($OBSID);
                data_rate(120.0);
                // Set biases and start SPU
                PHOT_change_biases(calBiasTable,calMode,calGain);
                //*******************************
                // Configure for the measurement
                //*******************************
                if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,"DIRECT","HIGH");
                }
                if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,calMode,"HIGH");
                }
                if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,"DIRECT",calGain);
                }
                //************************************
                //  Call the Phot_highGainBiasDirect
                //************************************
                Phot_highGainBiasDirect(select,startBiasTable,endBiasTable);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                tNOW = time();
                if(verbose) {
                    debug_print("SLEW ends at   " + tNOW);
                }
            }
            if(state[0] == 2) {
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 3) {
                tNOW = time();
                if(verbose) {
                    debug_print("POINT starts at   " + tNOW);
                }
                if(chop) {
                    //*********************************
                    // 2 positions chopping in the FOV
                    //*********************************
                    if(state[2] < m * n) {
                        finalChop = -6578;
                    } else {
                        finalChop = 7756;
                    }
                    OBCP_chopped_photometry(0,0,nRdts,0,0,nLoops,1,-6578,7756,0,0,finalChop);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("POINT ends at     " + tNOW);
                }
            }
            if(state[0] == 5) {
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD starts at   " + tNOW);
                }
                if(chop) {
                    TMMarker602();
                    delay(4 * measure_time);
                    TMMarker600();
                }
                // Set biases and start SPU
                PHOT_change_biases(calBiasTable,calMode,calGain);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                // Write EndID
                data_rate(0.0);
                WriteEndID();
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD ends at     " + tNOW);
                }
            }
        }
    }
}

// CVS comments  : $Id: PacsDureeOBCP3.txt,v 1.2 2007/04/25 15:14:04 dcesarsk Exp $ 
// Purpose       : Estimate duration of OBCP3 with input parameters
//
// CUS author    : 
// Script file   : PacsDureeOBCP3.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : Compute duration of DEC/MEC sequence associated to OBCP3.
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      :
// 
// History       : 0.1  10-aug-2006 DAC
int[] procedure PacsDureeOBCP3 {
    int nb_main_loops = 1; // p01 Nb of main loops
    int nb_rdouts_plateau = 159; // p03 Nb of readouts per chopper plateau
    int nb_chop_cycles = 2; // p04 Nb of chop_cycles
}{
    // Call the corresponding DMC sequence
    int[] duree = DMC_fixed_fixed_photo(nb_main_loops,nb_rdouts_plateau,nb_chop_cycles);
    // Convert number of readouts into seconds
    // Obtain system parameter from PACSparams
    // BOL readout frequency [Hz] and readout period [msec]
    double bol_freq = dlookup("PACSparams","bolo_sample","freq_time");
    // string bol_unit = slookup("PACSparams","bolo_sample","unit");
    double bol_period = 1000.0 / bol_freq;
    // debug_print("Bolo sample: " + bol_freq + " " + bol_unit);
    // debug_print("Bolo period: " + bol_period + "[msec]");
    // Convert duration [rdouts] into [msec]
    // Create return time array; convert into [sec]
    int[] time_array = [0,0,0,0,0];
    for(int aux = 0 .. 4) {
        time_array[aux] = ifloor(double(duree[aux]) * bol_period);
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    //
    // V0.2 correction: add OBCP overheads
    time_array[0] = time_array[0] + 4;
    time_array[4] = time_array[4] + 4;
    // Return total duration [sec] to calling program

    return time_array;
}

// CVS comments  : $Id: DMC_grat_scan_chop2.txt,v 1.4 2007/04/25 15:14:03 dcesarsk Exp $ 
// Purpose       : Compute execution time of DMC #12: 
//                 Grating Line Scan with Two position chopping
//
// TCL author    : N/A Pseudo code by HF
// TCL file      : N/A
// CUS author    : DAC
// Script file   : DMC_12_grat_line_scan_with_2_chop.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Similar to 4.2.1 but with only two chopping positions. 
//                 It is meant to allow for faster execution once only two
//                 chopping positions are used on bright targets.
//                 Of the 11 Parameters: 
//                    # of "up-down" sequences (P#1); 
//                    2 chopper positions (P#4, P#6); 
//                    # of readouts per chopper position (P#5); 
//                    # of cycles per grating position (P#3); 
//                    size of relative grating move up (P#10); 
//                    size of relative grating move down (P#11); 
//                    # of cycles on the internal calibration sources (P#7); 
//                    position of BB1 (P#8); 
//                    position of BB2 (P#9);
//                    # of grating steps (P#2)
//                  only those involved in time estimation are used here.
//                  
// Dependencies  : 
//
// Preconditions : None.
//                 
// Comments      : No TC are generated; only times are computed
// 
// History       : 0.1 14-apr-2005 DAC
//                 1.0 26-aug-2005 Renamed to match corresponding OBCP
//                 2.0 26-jan-2007 Count WAIT=1 after chopper as "good"
int[] procedure DMC_grat_scan_chop2 {
    int nb_up_down = 1; // Seq P#1 Nb of up down sequences
    int nb_grat_steps = 100; // Seq P#2 Nb of grating steps per up/down scan
    int nb_ramps_plateau = 1; // Seq P#5 Nb of ramps per chopper plateau
    int nb_CS1_CS2 = 0; // Seq P#7 Nb of CS1/CS2 per grating position
    int nb_SRC_REF = 1; // Seq P#3 Nb of SRC/REF per grating position
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    // WAIT 1                                             ; have a defined start
    duree_OVR = duree_OVR + 1;
    duree_num = duree_num + 1;
    // LABEL 0                                            ; set Label to 0 
    // LOOP P#1                                           ; main loop measurement
    for(int up_down = 1 .. nb_up_down) {
        //LOOP P#2 ; grating loop up
        for(int up = 1 .. nb_grat_steps) {
            // WAIT 1                                      ; sync. for grating 
            duree_OVR = duree_OVR + 1;
            duree_num = duree_num + 1;
            // MOVE_GRATING_RELATIVE P#10                  ; increment grating position 
            // LOOP P#3 ; chop readout cycle
            for(int chop_cycle_1 = 1 .. nb_SRC_REF) {
                // WAIT 1                                   ; sync. for chopper   
                duree_SRC = duree_SRC + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#4                ; chopper to P#4 
                // LABEL 3                                  ; first chopper pos. 
                // WAIT P#5                                 ; take P#5 ramps 
                // *Assume* P#4 is the SRC position... 
                duree_SRC = duree_SRC + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // WAIT 1                                   ; sync. for chopper
                //           *Assume* P#5 is the REF position... 
                duree_SRC = duree_SRC + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#6                ; chopper to P#6 
                // LABEL 5                                  ; next chopper pos. 
                // WAIT P#5                                 ; take P#5 ramps 
                // *Assume* P#6 is the REF position... 
                duree_REF = duree_REF + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                 ; chop readout cycle done
            }
            // LOOP P#7                                    ; calibration loop
            for(int cal_loop_1 = 1 .. nb_CS1_CS2) {
                // WAIT 1                                   ; sync. for chopper 
                duree_CAL = duree_CAL + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#8                ; chop to BB1 
                // LABEL 65                                 ; BB1 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // WAIT 1                                   ; sync. for chopper 
                duree_CAL = duree_CAL + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#9                ; chop to BB2 
                // LABEL 129                                ; BB2 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                    ; calibration done
            }
            // END_LOOP                                      ; grating scan up done
        }
        // LOOP P#2                                      ; grating loop down
        for(int down = 1 .. nb_grat_steps) {
            // WAIT 1 ; sync. for grating 
            duree_OVR = duree_OVR + 1;
            duree_num = duree_num + 1;
            // MOVE_GRATING_RELATIVE P#11                 ; decrement grating position 
            // LOOP P#3 ; chop readout cycle
            for(int chop_cycle_2 = 1 .. nb_SRC_REF) {
                // WAIT 1                                  ; sync. for chopper 
                duree_REF = duree_REF + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#4               ; chopper to P#4 
                // LABEL 19                                ; first chopper pos. 
                // WAIT P#5                                ; take P#5 ramps 
                duree_SRC = duree_SRC + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // WAIT 1                                  ; sync. for chopper 
                duree_REF = duree_REF + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#6               ; chopper to P#6 
                // LABEL 21                                ; next chopper pos. 
                // WAIT P#5                                ; take P#5 ramps 
                duree_REF = duree_REF + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                   ; chop readout cycle done
            }
            // LOOP P#7                                    ; calibration loop
            for(int cal_loop_2 = 1 .. nb_CS1_CS2) {
                // WAIT 1                                   ; sync. for chopper 
                duree_CAL = duree_CAL + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#8                ; chop to BB1 
                // LABEL 81                                 ; BB1 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // WAIT 1                                   ; sync. for chopper 
                duree_CAL = duree_CAL + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#9                ; chop to BB2 
                // LABEL 145                                ; BB2 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                    ; calibration done
            }
            // END_LOOP                                      ; grating scan down done
        }
        // END_LOOP                                        ; main loop done
    }
    // WAIT 1                                             ; complete last plateau 
    duree_OVR = duree_OVR + 1;
    duree_num = duree_num + 1;
    // LABEL 0                                            ; reset LABEL to 0 
    // END_SEQUENCE 
    // duration, in ramps : 2 + P#1 * 2 * P#2 * {1 + (P#3 + P#7) * (1 + P#5)}
    int duree = 2 + nb_up_down * 2 * nb_grat_steps * (1 + (nb_SRC_REF + nb_CS1_CS2) * 2 * (1 + nb_ramps_plateau));
    // debug_print("Formula  duration DMC: " + duree + " [ramps]");
    // debug_print("Computed duration DMC: " + duree_num + " [ramps]");
    // Time spent
    int duree_TCs = time() - time_start;
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// $Id
// Missionphase		: PACS PV Phase
//
// Purpose       : Invoke a PACS calibration OBCP during slew to source;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsPhotSlewCal.txt 
//
// Input arguments
// Type                      Description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform AOT prologue and then OBCP #13.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 DAC  30-Nov-2005 (inspired by PacsSpecSlewCal)
// 0.2 DAC 20-sep-2006 Clean up leftovers from SPEC script 
// 0.3 DAC  6-dec-2006 Adapted to simpler PHOT_fltw_move
// 0.4 DAC 27-jun-2007 SPR-3339 Always move filter wheel
// 1.0 DAC 10-oct-2007 SCR-3628 Added arguments to call aot_prologue 
// 2.0 VD  08-jan-2009 Call for default values missing: added
//                 
obs PacsEng_PacsPhotSlewCal {
    /* Needed variables to call PacsPhotSlewCal */
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int comp_mode_blu = 0;
    int nb_raw_blu = 3;
    int comp_mode_red = 0;
    int nb_raw_red = 3;
    double chopthrow = 30.0;
    bool verbose = true;
}{
    // compiting time for slw / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Set OBSID
    int tobsid = duration(WriteOBSID($OBSID));
    // Calibration time during slew
    if(fltPOS == "POS A") {
        string filter = "blue2";
    } else {
        if(fltPOS == "POS B") {
            filter = "blue1";
        }
    }
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsPhotSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // including a new section for Low Gain implementation SCR4196
    bool isBrightPacs = false;
    // we have todefine the srcID this defines the throw for science obs.: not used
    string srcID = "pointSRC";
    // Obtain default values for "Prime" mode
    paramsPHOT = PacsPhotDefaults(srcID,"Prime",isBrightPacs,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    confPHOTblu[0]{3} = comp_mode_blu;
    confPHOTblu[0]{6} = nb_raw_blu;
    confPHOTred[0] = paramsPHOT{1};
    confPHOTred[0]{3} = comp_mode_red;
    confPHOTred[0]{6} = nb_raw_red;
    confOBCP[0] = paramsPHOT{2};
    bool doProlog = true;
    //Initial hold
    int tih = duration(WriteOBSID($OBSID));
    //Final hold
    int tendobsid = duration(WriteEndID());
    int tepilog = duration(PHOT_aot_epilogue());
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,filter));
    if(verbose) {
        debug_print("Duration of WaveCalChop" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    int[] ts = no_pointing(execute,tih,tfh,tp);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            int tNOW = time();
            // 
            WriteOBSID($OBSID);
            data_rate(120.0);
            if(verbose) {
                debug_print("WriteOBSID at :" + tNOW + " sec");
            }
            tNOW = time();
            if(verbose) {
                debug_print("WriteOBSID ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,filter);
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 5) {
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold starts at :" + tNOW + " sec");
                    }
                    PHOT_aot_epilogue();
                    data_rate(0.0);
                    WriteEndID();
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold ends at :" + tNOW + " sec");
                    }
                }
            }
        }
    }
    // End of Observation
}

// Purpose        : Use the transparent mode to perform scan map measurement
//
// CUS author     : K. Okumura, R. Vavrek, B. Altieri
//
// Comments       : SCR ; PHS-1159
//                  The hold time is the same as calslew time and taken from
//                  the uplink table
//
// History: 
// 21-Aug-2009 : KO, Based on a Hifi scan map script provided by R. Vavrek
// 25-Aug-2009 : KO, First debugged version
// 27-Aug-2009 : KO, Cosmetics
// 09-Sep-2009 : KO, detsel_table changed in PACSDetSel_20090909 to cover
//                   the same sky region in blue and red
// 09-Sep-2009 : KO, duration(PacsBbWriteEndBB()) is subtracted from tl
//                   in stats[0]==8
//
obs PacsCal_Phot_TranspScan {
    string biasFile = "BOLObias_standard_high"; // Bias table to use
    string filter = "green100um" in ["green100um","blue70um"]; // Blue channel filter selection
    string scanSpeed = "High" in ["High","Medium","Low"]; // Select the speed
    string orientation = "Array" in ["Array","Sky"]; // Orientation angle reference frame
    int naifid = 0;
    double ra = 276.50625 in [0.0,360.0];
    double dec = -11.086667 in [-90.0,90.0];
    double patt = 42.0 in [0.0,360.0]; // Orientation angle (degrees)
    double yoff = 0.0;
    double zoff = 0.0;
    int n = 8 in [1,1500]; // Number of scan legs
    double scanLength = 5.0 in [0.34,1200.0]; // Scan leg lengths (arcminutes)
    double d2 = 38.0 in [0.0,480.0]; // Cross-scan step (arcseconds) 
    int nhold = 0 in [0,1500];
    int nrepeat = 1 in [1,100];
    bool verbose = true;
}{
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    if(verbose) {
        debug_print("=== timeOBSID : " + timeOBSID);
    }
    int timeChgBias1 = duration(PHOT_change_biases(biasFile,"DIRECT","HIGH"));
    if(verbose) {
        debug_print("=== timeChgBias1 : " + timeChgBias1);
    }
    int timeFilter = duration(PHOT_fltw_move("POS B"));
    if(verbose) {
        debug_print("=== timeFilter : " + timeFilter);
    }
    int timeSPU1 = duration(PHOT_spu_setup(4,4,0,0,false)) + 1;
    if(verbose) {
        debug_print("=== timeSPU1 : " + timeSPU1);
    }
    string detsel_table = "PACSDetSel_20090909";
    int timeDetSel = imax(1,duration(PACS_Det_Sel(detsel_table)));
    if(verbose) {
        debug_print("=== timeDetSel : " + timeDetSel);
    }
    int timeSPU2 = duration(PHOT_spu_setup(4,4,0,0,true)) + 1;
    if(verbose) {
        debug_print("=== timeSPU2 : " + timeSPU2);
    }
    int timeStab = 120;
    if(verbose) {
        debug_print("=== timeStab : " + timeStab);
    }
    // Define confOBCP array.
    // NOTE: the conf arrays are inherited from PacsSpec, where the [0] element
    // represented the default values, and the [n] element represented values
    // to be used with the n-th wavelength. Here - PHOT - [0] still represents
    // the default values and [1] values corresponding to the chosen filter.
    // Could even use [1] and [2] for blue1 and blue2.... but will not!
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confPHOTblu and confPHOTred
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,0,0,0,0,0,0,0,0}];
    // Define paramsPHOT, a "tuple of tuples"
    // Estimator module returns {confPHOTblu,confPHOTred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // Obtain default values for "Prime" mode
    paramsPHOT = PacsPhotDefaults("largeSRC","Prime",false,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    if(verbose) {
        debug_print("=== confPHOTblu : " + confPHOTblu);
    }
    confPHOTred[0] = paramsPHOT{1};
    if(verbose) {
        debug_print("=== confPHOTred : " + confPHOTred);
    }
    confOBCP[0] = paramsPHOT{2};
    if(verbose) {
        debug_print("=== confOBCP : " + confOBCP);
    }
    // Issue now OBCP4 for demanded filter
    // Table OBCP4params has parameter values for CAL using blue1 or blue2
    // Get params for demanded filter from OBCP4params
    string calNAME = "OBCP4params";
    // Table acces key is "cal1" or "cal2", corresponding
    // to blue70um and green100um respectively.
    string key = "cal1";
    if(filter == "green100um") {
        key = "cal2";
    }
    int nb_cycles_obs_cal = ilookup(calNAME,key,"nb_cycles_obs_cal");
    if(verbose) {
        debug_print("=== nb_cycles_obs_cal : " + nb_cycles_obs_cal);
    }
    int nb_SRC_REF = ilookup(calNAME,key,"nb_SRC_REF");
    if(verbose) {
        debug_print("=== nb_SRC_REF : " + nb_SRC_REF);
    }
    int nb_rdouts_plateau = ilookup(calNAME,key,"nb_rdouts_plateau");
    if(verbose) {
        debug_print("=== nb_rdouts_plateau : " + nb_rdouts_plateau);
    }
    int nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    if(verbose) {
        debug_print("=== nb_CS1_CS2 : " + nb_CS1_CS2);
    }
    // Read CS positions from CHOPPERCSparams
    int pos_CS1 = ilookup("CHOPPERCSparams","PHOT","pos_CS1");
    if(verbose) {
        debug_print("=== pos_CS1 : " + pos_CS1);
    }
    int pos_CS2 = ilookup("CHOPPERCSparams","PHOT","pos_CS2");
    if(verbose) {
        debug_print("=== pos_CS2 : " + pos_CS2);
    }
    int comp_mode_red = confPHOTred[0]{3};
    // lossless compression
    comp_mode_red = 4;
    if(verbose) {
        debug_print("=== comp_mode_red : " + comp_mode_red);
    }
    int comp_mode_blu = confPHOTblu[0]{3};
    // lossless compression
    comp_mode_blu = 4;
    if(verbose) {
        debug_print("=== comp_mode_blu : " + comp_mode_blu);
    }
    int chop_pos_SRC = confOBCP[0]{12};
    if(verbose) {
        debug_print("=== chop_pos_SRC : " + chop_pos_SRC);
    }
    int chop_pos_REF1 = confOBCP[0]{13};
    if(verbose) {
        debug_print("=== chop_pos_REF1 : " + chop_pos_REF1);
    }
    int chop_pos_REF2 = confOBCP[0]{14};
    if(verbose) {
        debug_print("=== chop_pos_REF2 : " + chop_pos_REF2);
    }
    int chop_def = confOBCP[0]{17};
    if(verbose) {
        debug_print("=== chop_def : " + chop_def);
    }
    int timeOBCP = duration(OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,pos_CS1,pos_CS2,comp_mode_blu,comp_mode_red,chop_def));
    if(verbose) {
        debug_print("=== timeOBCP : " + timeOBCP);
    }
    int timeChgBiasFin = duration(PHOT_change_biases(biasFile,"DIRECT","LOW"));
    if(verbose) {
        debug_print("=== timeChgBiasFin : " + timeChgBiasFin);
    }
    int timeSPUfin = duration(PHOT_spu_setup(0,0,3,3,false));
    if(verbose) {
        debug_print("=== timeSPUfin : " + timeSPUfin);
    }
    int timeDetSelfin = imax(1,duration(PACS_Det_Sel("PACSDetSel_20081203")));
    if(verbose) {
        debug_print("=== timeDetSelfin : " + timeDetSelfin);
    }
    int timeEndID = imax(1,duration(WriteEndID())) + 1;
    if(verbose) {
        debug_print("=== timeEndID : " + timeEndID);
    }
    int tslewmin = timeOBSID + timeChgBias1 + timeFilter + timeSPU1 + timeDetSel + timeSPU2 + timeStab + timeOBCP;
    if(verbose) {
        debug_print("=== tslewmin : " + tslewmin);
    }
    int tih = 0;
    int tfh = timeChgBiasFin + timeSPUfin + timeDetSelfin + timeEndID;
    if(verbose) {
        debug_print("=== tfh : " + tfh);
    }
    string ib = "P01_0";
    // Use PACS Photometer vertual aperture
    if(verbose) {
        debug_print("=== ib : " + ib);
    }
    double rate = 60.0;
    // Scan rate (arcsec / sec)
    if(scanSpeed == "Low") {
        rate = 10.0;
    }
    if(scanSpeed == "Medium") {
        rate = 20.0;
    }
    if(verbose) {
        debug_print("=== rate : " + rate);
    }
    bool fixed = true;
    // reference of the scan angle
    if(orientation == "Array") {
        fixed = false;
    }
    if(verbose) {
        debug_print("=== fixed : " + fixed);
    }
    double d1 = scanLength * 60.0;
    // Scan leg lengths (arcsec)
    if(verbose) {
        debug_print("=== d1 : " + d1);
    }
    int thold = timeOBCP;
    double timeLEG = d1 / rate;
    int timeOBS = iceil(timeLEG);
    if(verbose) {
        debug_print("=== timeOBS : " + timeOBS);
    }
    int tWriteEnd = imax(1,duration(PacsBbWriteEndBB()));
    if(verbose) {
        debug_print("=== tWriteEnd : " + tWriteEnd);
    }
    int tWrite = imax(1,duration(PacsBbWriteIdBB()));
    if(verbose) {
        debug_print("=== tWrite : " + tWrite);
    }
    int[] ts = line_scan_pointing(verbose,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoff,zoff,n,d1,d2,rate,thold,nhold,nrepeat);
    if(verbose) {
        debug_print("=== ts : " + ts);
    }
    int tslew = ts[1];
}{
    int[] state = [0];
    int tl = ts[4];
    if(verbose) {
        debug_print("=== tl : " + tl);
    }
    int tNOW = 0;
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            // Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            if(verbose) {
                tNOW = time();
                debug_print("=== OBSID set at: " + tNOW);
            }
            //
            //***********************************************
            // Bias setting of the detectors for high gain
            //***********************************************
            //
            PHOT_change_biases(biasFile,"DIRECT","HIGH");
            if(verbose) {
                tNOW = time();
                debug_print("=== PHOT_change_biases at: " + tNOW);
            }
            //
            //***************
            // Select Filter
            //***************
            //
            if(filter == "blue70um") {
                PHOT_fltw_move("POS B");
            } else {
                PHOT_fltw_move("POS A");
            }
            if(verbose) {
                tNOW = time();
                debug_print("=== Filter set at: " + tNOW);
            }
            //**************************************************
            // Stop SPU and load a new Detector selection table
            //**************************************************
            //
            PHOT_spu_setup(4,4,0,0,false);
            if(verbose) {
                tNOW = time();
                debug_print("=== SPU set without running at: " + tNOW);
            }
            PACS_Det_Sel(detsel_table);
            if(verbose) {
                tNOW = time();
                debug_print("=== PACS_Det_Sel at: " + tNOW);
            }
            //
            //****************************************************************
            // Special SPU setup to downlink 40Hz science data of some pixels
            //****************************************************************
            PHOT_spu_setup(4,4,0,0,true);
            if(verbose) {
                tNOW = time();
                debug_print("=== SPU set and run at: " + tNOW);
            }
            //
            //********************
            // Let all stabilized
            //********************
            delay(120);
            if(verbose) {
                tNOW = time();
                debug_print("=== After stabilisation wait at: " + tNOW);
            }
            //
            //**********************
            // slew time management
            //**********************
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
                if(verbose) {
                    tNOW = time();
                    debug_print("=== tslew - tslewmin at: " + tNOW);
                }
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW_CAL starts at   " + tNOW);
            }
            int[] dureeOBCP = OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,pos_CS1,pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW CAL ends at: " + tNOW);
            }
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW ends at: " + tNOW);
            }
        }
        if(state[0] == 2) {
            // Block_InitHold();
            if(verbose) {
                tNOW = time();
                debug_print("=== Initial hold starts and ends at: " + tNOW);
            }
        }
        if(state[0] == 5) {
            // Block_FinalHold();
            if(verbose) {
                tNOW = time();
                debug_print("=== Final hold starts at: " + tNOW);
            }
            //
            //***********************************
            // End bias setting of the detectors
            //***********************************
            //
            PHOT_change_biases(biasFile,"DIRECT","LOW");
            if(verbose) {
                tNOW = time();
                debug_print("=== PHOT_change_biases at: " + tNOW);
            }
            //****************************
            // Stop science data downlink
            //****************************
            PHOT_spu_setup(0,0,3,3,false);
            if(verbose) {
                tNOW = time();
                debug_print("=== Nominal SPU set without running at: " + tNOW);
            }
            //
            //****************************************
            // Stop SPU and load default DetSel Table
            //****************************************
            PACS_Det_Sel("PACSDetSel_20081203");
            if(verbose) {
                tNOW = time();
                debug_print("=== PACS_Det_Sel at: " + tNOW);
            }
            // Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
            if(verbose) {
                tNOW = time();
                debug_print("=== WriteEndID at: " + tNOW);
            }
            if(verbose) {
                tNOW = time();
                debug_print("=== Final hold ends at: " + tNOW);
            }
        }
        if(state[0] == 6) {
            // Block_CalHold(thold);
            if(verbose) {
                tNOW = time();
                debug_print("=== CAL hold starts at   " + tNOW);
            }
            dureeOBCP = OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,pos_CS1,pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
            if(verbose) {
                tNOW = time();
                debug_print("=== Cal hold ends at: " + tNOW);
            }
        }
        if(state[0] == 8) {
            if(verbose) {
                tNOW = time();
                debug_print("=== Line scan starts at: " + tNOW);
            }
            PacsBbWriteIdBB();
            if(verbose) {
                tNOW = time();
                debug_print("=== PacsBbWriteIdBB at: " + tNOW);
            }
            // Wait for the scan time before setting EndBB
            delay(tl - tWriteEnd);
            PacsBbWriteEndBB();
            if(verbose) {
                tNOW = time();
                debug_print("=== PacsBbWriteEndBB at: " + tNOW);
            }
            if(verbose) {
                tNOW = time();
                debug_print("=== One scan ends at: " + tNOW);
            }
        }
    }
    //
    // sync the bus
    sync();
}

// CVS comments  : $Id $
// Description :
//
// Dependencies  : 
//
// Comments      : Follows verbatim paragraph 4.2.10 in PACS-ME-LI-005
//                 version 1.6
//         Actual values of input parameters, except values for the
//         various loop counters, are completely irrelevant and so
//         are not used.
//         Loop counters are used to estimate the duree of the
//         sequence
//
// Version       : 0.1 15-oct-2007 Creation by DAC
// History       : 1.0 VD implementation ABBA OBCP32
//                 1.1 26-mar-2003 Removed some debug info 
//
// This debugging DEC/MEC computes grating positions
procedure PacsDebug_wave_switch_PV {
    int pos = 1000; // Grating start position
    int nb_dither_steps = 7; // number of dithering steps
    int nb_switch_cycles = 1; // nb of L-R-L-R cycles per dithering
    int param2 = 200; // DMC P#2
    int param4 = -2000; // DMC P#4
    int param6 = -2000; // DMC P#6
    int param7 = 2000; // DMC P#7
    int param8 = 2000; // DMC P#8
}{
    // Pseudo code from PACS OBCPs and DMC Sequences (4.1.7)
    // WAIT 1 ; have a defined start
    // LABEL 0 ; set Label to 0
    int grat = pos;
    // LOOP P1                           main loop for number of shifts
    for(int outLOOP = 1 .. nb_dither_steps) {
        //    WAIT 1                         sync. for chopper
        //    MOVE_GRATING_RELATIVE P2       move grating by P2 = shift
        grat = grat + param2;
        debug_print("Dithering cycle: " + outLOOP + "; grating starts at: " + grat);
        //    LOOP P3                        P3 times core loop
        for(int inLOOP = 1 .. nb_switch_cycles) {
            //       MOVE_GRATING_RELATIVE P4    move grating by P4
            grat = grat + param4;
            debug_print("----Pos 1 is: " + grat);
            //       MOVE_GRATING_RELATIVE P6    move grating by P6
            grat = grat + param6;
            debug_print("----Pos 2 is: " + grat);
            //       MOVE_GRATING_RELATIVE P7    move grating by P7
            grat = grat + param7;
            debug_print("----Pos 3 is: " + grat);
            //       MOVE_GRATING_RELATIVE P8    move grating by P8
            grat = grat + param8;
            debug_print("----Pos 4 is: " + grat);
            //    END_LOOP
        }
        // END_LOOP
    }
    // WAIT 1                            complete last plateau
    // LABEL 0                           no sequence anymore
    // END_SEQUENCE
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Purpose       : Expert HSPOT version of PACS_GeGa_SFT_Init_Warm
// Author        : 
// Arguments     :
// Prerequisite  : 
// Description   : 
// Comments      : 
// Version       : 0.2
// History       : 0.1  6-feb-2008 Converted into Eng OBS by DAC
//                 0.2 14-feb-2008 Renamed to PacsEng_GeGa.....
//
obs PacsEng_GeGa_SFT_Init_Warm {
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = duration(PACS_GeGa_SFT_Init_Warm());
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_GeGa_SFT_Init_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       :  DMC sequence 6 for OBCP 11: Photometry Calibration II
//                  
//                 
//
// Author        : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : DMC_phot_cal_II.txt
//
// Arguments     : # of main loops (P#1); 
//                 Chopper start position (P#2); 
//                 # readouts per chopper plateau (P#3); 
//                 2 Labels to indicate BB position (P#4, P#5); 
//                 5 chopper positions on the "variable BB" (from P#6 to P#10)
//                 
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : Follows line by line DMC sequence 4.1.6 in PACS OBCPs and
//                 DMC sequences 
//
// Version       : 0.1 27-Oct-2004 DAC
// History       : 
//               :
int[] procedure DMC_phot_cal_II {
    int nb_cal_cycles = 2; // p01 Number of calibartion cycles
    int nb_rdouts_plateau = 79; // p03 Number of readouts per chopper plateau
}{
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Start tallying the duration (measured in number of readouts)
    int duration_rdouts = 0;
    // WAIT 1 ; have a defined start
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; set Label to 0 
    // WAIT 1 ; have a defined start 
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LOOP P#1 ; main loop measurement
    for(int main_loop = 1 .. nb_cal_cycles) {
        //     WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //     MOVE_CHOPPER_ABSOLUTE P#2 ; define fixed start pos. 
        //     LABEL P#4 ; start quadruple on P#4 
        //     WAIT P#3 ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        //     WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //     MOVE_CHOPPER_RELATIVE P#6 ; go to other BB 
        //     LABEL P#5 ; start quadruple on P#5 
        //     WAIT P#3 ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        //     WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //     MOVE_CHOPPER_ABSOLUTE P#2 ; go back to BB1 
        //     LABEL P#4 ; start quadruple on P#4 
        //     WAIT P#3 ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        //     WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //     MOVE_CHOPPER_RELATIVE P#7 ; go to other BB 
        //     LABEL P#5 ; start quadruple on P#5 
        //     WAIT P#3 ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        //     WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //     MOVE_CHOPPER_ABSOLUTE P#2 ; go back to BB1 
        //     LABEL P#4 ; start quadruple on P#4 
        //     WAIT P#3 ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        //     WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //     MOVE_CHOPPER_RELATIVE P#8 ; go to other BB 
        //     LABEL P#5 ; start quadruple on P#5 
        //     WAIT P#3  ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        //     WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //     MOVE_CHOPPER_ABSOLUTE P#2 ; go back to BB1 
        //     LABEL P#4 ; start quadruple on P#4 
        //     WAIT P#3 ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        //     WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //     MOVE_CHOPPER_RELATIVE P#9 ; go to other BB 
        //     LABEL P#5 ; start quadruple on P#5 
        //     WAIT P#3 ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        //     WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //     MOVE_CHOPPER_ABSOLUTE P#2 ; go back to BB1 
        //     LABEL P#4 ; start quadruple on P#4 
        //     WAIT P#3 ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        //     WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        //     MOVE_CHOPPER_RELATIVE P#10 ; go to other BB 
        //     LABEL P#5 ; start quadruple on P#5 
        //     WAIT P#3 ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        // END_LOOP ; end main loop
    }
    // WAIT 1 ; complete last plateau 
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; no sequence anymore 
    // END_SEQUENCE 
    // Define return array
    int[] time_array = [duration_rdouts,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    debug_print("DMC_phot_cal_II duration [readouts]: " + duration_rdouts);
    // Return the array of times

    return time_array;
}

// CVS comments  : $Id: PHOT_aot_epilogue.txt,v 1.2 2007/04/25 15:14:03 dcesarsk Exp $ 
// Missionphase  : 
// Purpose       : Stop PHOTOmeter observations at end of AOT
//                  
// TCL author    : 
// TCL file      : 
// CUS author    : Diego Cesarsky
// Script file   : PHOT_aot_epilogue.txt 
//
// Input arguments
// Type Name           Default   Description
//
// Description   : Not much for now (just STOP SPU)
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      :
//
// History       : 0.1 19-apr-2006 First creation
// 		   1.0 23-sep-2008 SCR 4431 data_rate
procedure PHOT_aot_epilogue {
}{
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    data_rate(0.0);
    // Sync the bus (function duration will get the "true" duration)
    sync();
    // end of procedure
}

// $Id
// Missionphase		: PACS PV Phase
//
// Purpose :		Wavelength calibration during PacsSlew
// Author		 : VDP
//
// Arguments		:
//
// Prerequisite 	: PACS does not need to be on nor setup for spectroscopy
//
// Description		: Uses OBCP13 and performs AOT prologue and epilogue
// 
// Comments		:
//
// Version		: 1.0
// 
// History		: 0.1 Using example from PacsCal_WaveCalChop
// 			: 1.0 perform calibrations during slew and 
//    	  	       	   then a wavelength calibration on source
//			   usng NOD=1 and Choping
obs PacsEng_PacsSpecSlewCal {
    /* Needed variables to call PacsSpecSlewCal */
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    int nb_raw_blu = 3;
    int nb_raw_red = 3;
    int grat_pos = 500000; // grating start position for scan
    int grat_time = 0; // tiem for grating to move to start position [msec
    int order = 2;
    string confTable = "normal" in ["normal","bright"];
    double chopthrow = 30.0;
    bool verbose = true;
}{
    // compiting time for slw / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Verification for grating and chopper hard limits
    int[] gratpos = [0];
    Pacs_HardLimitsCheck(gratpos,chopthrow);
    // Calibration time during slew
    // SPEC parameters for BLU and RED               
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    string throw = "small";
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = PacsSpecDefaults(throw,confTable,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    confSPECblu[0]{3} = comp_mode_blu;
    confSPECred[0]{3} = comp_mode_red;
    confSPECblu[0]{6} = nb_raw_blu;
    confSPECred[0]{6} = nb_raw_red;
    confOBCP[0]{8} = grat_pos;
    confOBCP[0]{9} = grat_time;
    // Here comes the module to estimate PACS parameters as a function of the
    // exposure time given by the user. This is the pilar of the
    // whole AOT logic.
    // frstLstGratPos is the last position for the grating after the Cals done
    // during Slew time... must be same as observations start position: grat_pos   
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    // "N/A" in string because of indexing 0,1,2,3
    string[] choix = ["N/A","order1","order2","order3"];
    string order_str = "" + order;
    double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    double[] keyWAVE = [keyWAVE1];
    int grat_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    //Initial hold
    int tih = duration(WriteOBSID($OBSID));
    //Final hold
    int tendobsid = duration(WriteEndID());
    int tepilog = duration(SPEC_aot_epilogue(grat_pos,grat_def,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]));
    if(verbose) {
        debug_print("Duration of WaveCalChop" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    int[] ts = no_pointing(execute,tih,tfh,tp);
    debug_print("ts: " + ts);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            int tNOW = time();
            // 
            WriteOBSID($OBSID);
            data_rate(120.0);
            if(verbose) {
                debug_print("WriteOBSID at :" + tNOW + " sec");
            }
            tNOW = time();
            if(verbose) {
                debug_print("WriteOBSID ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                tNOW = time();
                PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]);
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 5) {
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold starts at :" + tNOW + " sec");
                    }
                    SPEC_aot_epilogue(grat_pos,grat_def,verbose);
                    data_rate(0.0);
                    WriteEndID();
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold ends at :" + tNOW + " sec");
                    }
                }
            }
        }
    }
    // End of Observation
}

// CVS comments  : $Id: WriteBBID.txt,v 1.6 2007/04/26 15:44:10 dcesarsk Exp $
// Missionphase  : 
//
// Purpose       :
//
// CUS script    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
// CVS file      : WriteBBID.txt
//
// Input arguments
// Type  Name    DefVal  Description
// int   iBBID   N/A     BBID obtained from environment
//
// Description   : Write BBID to DEC/MEC; print decoded BBID
//                 to output log  
//
// Dependencies  : Pacs_DMC_SET_BBID
//                 DecodeBBID   
//                 
// Comments      : 
//
// Version      : 0.1 23-Sep-2004 First creation
// History      : 0.2 28-Sep-2004 Show BBID "decoded" on output screen.
//                                Remove set_unset choice 
//                0.3  7-Oct-2004 Rationalize name convention: renamed to
//                                WriteBBID (idem with file name)
//                0.4 12-Oct-2004 Added write to EGSE equipment (will have to
//                                add later writes to IST equipment ??)
//                0.5 21-Oct-2004 Added write to CDMS     
//                0.6  9-May-2005 Remove write to EGSE and to CDMS     
//                0.7 22-nov-2006 Removed debug statement
//               :
//
procedure WriteBBID {
    int iBBID = 0x40000000; // Building Block ID  
}{
    // Write BBID to DEC/MEC and to output log
    Pacs_DMC_SET_BBID(iBBID);
    ///   DecodeBBID(iBBID);
}

// File          : PACS_Phot_Fil_Testseq.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Position sequence test of photometer filterwheel  
//
// Author        : BV, modifications by TM
// CUSification  : DAC 
// Arguments     :
//
// Description   : Moves the Photometer filter wheel <num_turns> times
//                 to position 2 and back to position 1 using absolute position
//                 commands. 
//
// Comments      : Prerequisite : spec_mec_setup has been executed 
//
// Version       : 1.6
// History       : 1.0 / 25-Nov-2003 initial version by BV 
//                 1.1 / 05-Jan-2004 Changed step strategy 
//                 1.2 / 13-Jan-2004 Taken out relative commands
//                 1.3 / 31-May-2004 Positions cfr DMC UM 2.8
//                 1.4 / 07-Jul-2004 changed for phot filter wheel
//                 1.5 / 11-Aug-2004 addition of time_on_fw_pos
//                 1.6 / 17-Nov-2004 modified for "non-interactive" EQM test
procedure PACS_Phot_Fil_Testseq {
}{
    // fw_start integer          1 Enter initial filter wheel position (0=A; 1=B)
    // num_turns integer         5 Enter number of 360 deg turns
    // time_on_fw_pos integer   20 Enter time spent on each FW stop position (sec)
    int fw_start = 1;
    int num_turns = 3;
    int time_on_fw_pos = 20;
    string[] fltPOS = ["POS A","POS B"];
    // Default time for one 'standard' command execution (sec)
    // set command_time 0.5
    // Minimum time between two filter wheel movements (sec)
    int slew_time = 15;
    // PC129420 "DMC_SWON_FW_PHOTO" SWITCH ON POWER SUPPLY OF FILTER WHEEL PHOTO
    // tcsend PC129420
    // waittime 0.5
    Pacs_DMC_SWON_FW_PHOTO();
    delay(1);
    // Start from position 1
    // PC136420 "DMC_MOVE_PHOT_FW_LOC" MOVE PHOTOMETER FILTER WHEEL TO LOCATION
    //         PP075420 "FW_ID"
    // tcsend PC136420 [list PP075420 $fw_start]
    // waittime $slew_time
    Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    // Move num_turns to position 0 and back to position 1 using absolute 
    // location commands
    for(int loop0 = 1 .. num_turns) {
        int i = (fw_start + 1) % 2;
        Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[i]);
        delay(slew_time);
        delay(time_on_fw_pos);
        i = (fw_start + 2) % 2;
        Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[i]);
        delay(slew_time);
        delay(time_on_fw_pos);
    }
    //------------------
    // End of procedure
    //------------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       :  Quick full spectral scan in about 1 hour in all bands
//                  
//
// Input arguments  Integrating capacitance blue (0,8,4,12) and red; chopper position
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Uses OBCP28 for executing quick full scans in both filters
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                 
// Comments      : 
// Version	 : 1.0
// History	 : 1.0 25-mar-2008 VDP Translated from IST to PV phase syntax
// 
obs PacsEng_Spec_QuickFullSpectrum {
    /* Needed variables to call PacsEng_Spec_QuickFullSpectrum                        */
    int chop_def = 650; // chopper position during grating scan
    int capa_red = 12; // Red capacitor
    int capa_blu = 0; // Blue capacitor
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_QuickFullSpectrum                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_QuickFullSpectrum(chop_def,capa_red,capa_blu)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_QuickFullSpectrum(chop_def,capa_red,capa_blu);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
//
// Purpose       : Cooler recycling as an ObsMode
//                 
//
// Author        : Diego A. Cesarsky
//
// Arguments     : None
//
// Description   : Simply call BOLO_cooler_cycle
//
// Dependencies  : BOLO_cool_recycle
//
// Comments      : 
//
// Version       : 0.3 17-oct-2008 KO
// History       : 0.2 22-apr-2005 DAC Renamed to BOLO_cooler_OBS to be
// History       : 0.1  11-feb-2008 Converted into Eng OBS by VDP
//                    0.3  17-oct-2008 KO, extra_cool_time and extra_stab_time variables added
//
//                                 homegeneous with other OBS scripts 
//
obs PacsEng_BOLO_cooler {
    /* Needed variables to call PacsEng_BOLO_cooler                        */
    int extra_cool_time = 0; // in second before disconnecting the evaporator from 2K
    int extra_stab_time = 0; // in second after the end of the recycling procedure
    /* End of needed variables for PacsEng_BOLO_cooler                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tobsId = duration(WriteOBSID($OBSID));
    int tCcu = duration(Pacs_CcuMonitorStartRecycle());
    int tih = tobsId + tCcu;
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tendId = duration(WriteEndID());
    int tCcuDefault = duration(Pacs_CcuMonitorDefaultRecycle());
    int tfh = tendId + tCcuDefault;
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(BOLO_cool_recycle(extra_cool_time,extra_stab_time)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            Pacs_CcuMonitorStartRecycle();
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            BOLO_cool_recycle(extra_cool_time,extra_stab_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            Pacs_CcuMonitorDefaultRecycle();
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Burstmode_Setup {
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Burstmode_Setup()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(300.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Burstmode_Setup();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS file	: PACS_spu_reset.cus
// Missionphase  : FM IMT
//
// Purpose	: Reset SPU after photometry data flow
//
// Author	: Bart Vandenbussche
//
// Arguments	: none
// Description	: Stops SPU
//                  
// Dependencies : 
// Comments	: 
// Version	: 1.0               
// History	: 1.0 18-Apr-2005 BV - copied from SPEC_spu_reset -
//
procedure PACS_spu_reset {
}{
    // Stop both "blue" (Long) and "red" (Short) SPU
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
}

// Missionphase  : CoP, PV, L2
//
// Purpose       :  SAFE mode OBCP without switching off the CSs
//                  
//                 
//
// TCL author    : HF
// TCL file      : 
// CUS author    : HF 
// Script file   : OBCP_SAFE_2.txt 
//
// Input arguments none
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Transit to SAFE mode without switching off the CSs
//                            
//                           
//                            
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy or photometer
//                             
//                 
// Comments      : 
// 
// History       : 1.0 29-Mar-2005 creation by HF
//
int block OBCP_SAFE_2 PACS 17 {
}{
    // Register start of BB
    WriteBBID($BBID);
    // Tally duration (NOTE: we use [msec] for the return value)
    int duration_msec = 0;
    Pacs_DPU_START_OBCP("GO_SAFE_MODE_2",0,[]);
    delay(10);
    duration_msec = duration_msec + 10000;
    // Mark End of Block
    WriteEndBB();
    // Return time

    return duration_msec;
}

// Missionphase  : EQM
//
// Purpose       : OnBoardControlProcedure OBCP#13: Chopped Grating
//                 scan calibration (calls DMC sequence 11)
//
// OBCP author   : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : OBCP_chop_grat_scan_cal.txt  
//
// Arguments: 
// Type  Name                 Description
//
//
// Description   : This script mimics OBCP_CHOPPED_GRATING_SCANS_CALIBRATION
//                 pseudo script, section 3.11 in PACS-ME-LI-005
//                 This CUS version computes the duration of the
//                 observation, as specified by the input parameters.
//                 It will also send the trigger TC to start the OBCP
//
// Dependencies  : DMC_chop_grat_scan_cal
//                 WriteBBID   
// Comments      : 
//
// Version       : 0.1 21-Jan-2004 Creation by DAC
// History       : 
//
int[] block OBCP_chop_grat_scan_cal PACS 13 {
    int nb_up_dn = 1; // Nb of up down up... cycles (P#1)
    int grat_step_coarse = 0; // Grating coarse movement (P#2)
    int nb_grat_steps = 16; // Seq P#3  Nb of grating  steps
    int grat_step_up_fine = 133; // Grating fine movement (P#4)
    int nb_cycles_grat = 2; // Seq P#5  Nb cycles/grating position
    int chop_pos_CS1 = -25000; // Chopper position for CS1 (P#6)
    int nb_ramps_grat_pos = 3; // Seq P#7  Nb of ramps per grating position    
    int chop_pos_CS2 = 25000; // Chopper position for CS2 (P#8)
    int grat_step_dn_fine = -133; // Grating fine movement (P#9)
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 461000; // Starting grating position
    int grat_time = 40000; // Time for grating to move to start position
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopped default position
    int grat_def_time = 20000; // Grating time to move to grat_def [msec]
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here
    // OBCP_CHOPPED_GRATING_SCANS_CALIBRATION(seq, seq_time, P#1,&, P#9, 
    //                    detector, grat_pos, grat_time, 
    //                    cmp_par_blue,cmp_par_red,
    //                    grat_def, chop_def, grat_def_time)
    // Begin 
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_pos)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHKSUM)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHKSUM)
    // WAIT(grat_time)
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    // DMC_START_SEQUENCE
    // The DMC is number seq_DMC=11 and lasts seq_time [msec]
    // Duration "duree1" is an array with five elements
    int[] duree1 = DMC_chop_grat_scan_cal(nb_up_dn,nb_grat_steps,nb_cycles_grat,nb_ramps_grat_pos);
    // Convert duration [ramps] into [msec]; add dmc_margin
    int seq_time = ifloor(double(duree1[0]) * ramp_time) + dmc_margin;
    // Convert other times as well into msec
    duree_SRC = ifloor(double(duree1[1]) * ramp_time);
    duree_REF = ifloor(double(duree1[2]) * ramp_time);
    duree_CAL = ifloor(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + ifloor(double(duree1[4]) * ramp_time) + dmc_margin;
    // WAIT(seq_time) ; Check execution status of the sequence and in case of 
    //                  failure stop OBCP and issue TM(1,8)+event
    duree_msec = duree_msec + t_cmd + seq_time;
    // DMC_MOVE_GRAT_ABS(grat_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_def_time)
    duree_msec = duree_msec + t_cmd + grat_def_time;
    duree_OVR = duree_OVR + t_cmd + grat_def_time;
    // Issue TM(1,7)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // end
    // Now trigger execution of OBCP
    // This OBCP is number 13, requires 19 parameters and lasts seq_time [msec]
    string obcp_ID = "INT_CALIB_SPEC";
    int obcp_par_nber = 19;
    int seq_DMC = 11;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_dn},{4,grat_step_coarse},{5,nb_grat_steps},{6,grat_step_up_fine},{7,nb_cycles_grat},{8,chop_pos_CS1},{9,nb_ramps_grat_pos},{10,chop_pos_CS2},{11,grat_step_dn_fine},{12,detector},{13,grat_pos},{14,grat_time},{15,comp_mode_blu},{16,comp_mode_red},{17,grat_def},{18,chop_def},{19,grat_def_time}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nber,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Return total duration [sec] to calling program
    // Create return time array; convert into [sec]
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // Set delay()
    delay(time_array[0]);
    // Ending time
    int time_elapsed = time() - time_start;
    // time_elapsed includes the TC uplink "rate time", i.e. 2 TCs/sec 
    time_array[0] = time_elapsed;
    // Return
    //Reset Block ID
    WriteEndBB();
    //Return time_array

    return time_array;
}

// CVS comments  : $Id: OBCP_wave_switch.txt,v 1.2 2008/02/07 16:21:41 dcesarsk Exp $
//
// Author OBCP   : Helmut Feuchtgruber
// CUS script    : DAC
//
// Arguments needed to call OBCP
// Type  Name              DefCal   Description
//
// int   nb_up_down                 P1 Number of up_down grating cycles
// int   nb_shift_up           P2 Number of dither (up)
// int   grat_shift_steps_up           P3  Dithering amplitude (up)
// int   nb_abba_cycles           P4 Number of switch repeatitions
// int   param5                     P5 First relative move in P4 loop
// int   nb_ramps_grat              P6 number of ramps per grating position
// int   param7                     P7 2nd relative move in P4 loop
// int   param8                     P8 3rd relative move in P4 loop
// int   param9                     P9 4th relative move in P4 loop
// int   nb_shift_dn                    P10  Number of dither (down)
// int   grat_shift_steps_dn                    P12 First relative move in P11 loop 
// int   param13                    P13 2nd relative move in P11 loop
// int   param14                    P14 3rd relative move in P11 loop
// int   param15                    P15 4th relative move in P11 loop
// int   param11                    Dithering amplitude (down)
// int   detector                   Synchronize on this detector 1:Blue 2:Red
// int   comp_mode_blu              Blue compression
// int   comp_mode_red              Red compression
// int   grat_pos                   Initial grating position
// int   chop_pos                   Chopper position during OBCP
// int   grat_time                  Time for grating to move grat_pos
// int   grat_def                   Grating default position
// int   chop_def                   Chopper default position
// int   grat_def_time              Time to move gratting to grat_def
// int   nb_rdouts_ramp             P6 Number of readouts per ramp
//
// Description:   Following from DMC description ()
//                Start with grating at grat_pos = POS
//
// OPERATION                         Where is grating
// WAIT 1                            POS
// LABEL 0                           POS
// LOOP P1                           POS
//  LOOP P2
//    MOVE_GRATING_RELATIVE P3       POS + P3
//    WAIT 1                         POS
//    LOOP P4                        POS + P3
//       WAIT 1                      POS + P3
//       MOVE_GRATING_RELATIVE P5    POS + P3 + P5
//       LABEL 33                    POS + P3 + P5
//       WAIT P6                     POS + P3 + P5  ------------ LINE1
//       WAIT 1                      POS + P3 + P5
//       MOVE_GRATING_RELATIVE P7    POS + P3 + P5 + P7
//       WAIT P6                     POS + P3 + P5 + P7 -------- REF1
//       WAIT 1                      POS + P3 + P5 + P7
//       MOVE_GRATING_RELATIVE P8    POS + P3 + P5 + P7 + P8
//       WAIT P6                     POS + P3 + P5 ------------- REF2
//       WAIT 1                      POS + P3 + P5
//       MOVE_GRATING_RELATIVE P9    POS + P3 + P5 + P8 + P9
//       WAIT P6                     POS + P3 ------------------ LINE2
//    END_LOOP                       
//  END_LOOP  
//  LOOP P10
//    MOVE_GRATING_RELATIVE P11       POS + P11
//    WAIT 1                          POS
//    LOOP P4
//       WAIT 1                       POS + P11
//       MOVE_GRATING_RELATIVE P12    POS + P11 + P12
//       LABEL 49                     POS + P11 + P12
//       WAIT P6                      POS + P11 + P12  ------------ LINE3
//       WAIT 1                       POS + P11 + P12
//       MOVE_GRATING_RELATIVE P13    POS + P11 + P12 + P13
//       WAIT P6                      POS + P11 + P12 + P13 -------- REF3
//       WAIT 1                       POS + P11 + P12 + P13
//       MOVE_GRATING_RELATIVE P14    POS + P11 + P12 + P13 + P14
//       WAIT P6                      POS + P11 + P12 ------------- REF4
//       WAIT 1                       POS + P11 + P12
//       MOVE_GRATING_RELATIVE P15    POS + P11 + P12 + P13 + P14 + P15
//       WAIT P6                      POS + P11 ------------------ LINE4
//    END_LOOP                       
//  END_LOOP  
// END_LOOP
// LABEL 0            
// END_SEQUENCE
//
// NOTE1:  P3 is the grating shift wrt LINE
//         The start grating position before dithering is 
//         POS = nominal_grating@LINE - P5
// NOTE2:  REF1 and REF2 are the same if P5 + P7 = P5 + P7 + P8
//
// Version       : 0.1 16-oct-2007 Creation by DAC
// History       : 1.0 17-dec-2008: VD SPR 5691: wrong SEQ_DMC should be 18!! 
//               : 2,0 NEW flavour for OBCP32...
//
int[] block OBCP_wave_switch PACS 32 {
    int nb_up_down = 1; // P1 up_down cycles
    int nb_shift_up = 11; // P2 nb_shift_up
    int grat_shift_steps_up = 300; // P3 grat_shift_steps
    int nb_abba_cycles = 3; // P4 Number of switch repeatitions
    int param5 = 0; // P5 First relative move in P4 loop
    int nb_ramps_grat = 1; // P6 number of ramps per grating position
    int param7 = 700; // P7 2nd relative move in P4 loop
    int param8 = 0; // P8 3rd relative move in P4 loop
    int param9 = -700; // P9 4th relative move in P4 loop
    int nb_shift_dn = 11; // P10 = P2 
    int grat_shift_steps_dn = 300; // P11 = P3
    int param12 = 0;
    int param13 = 700;
    int param14 = 0;
    int param15 = -700;
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int comp_mode_blu = 16; // Blue compression
    int comp_mode_red = 16; // Red compression
    int grat_pos = 500000; // Initial grating position
    int chop_pos = 664; // Chopper position during OBCP
    int grat_time = 10000; // Time [msec] for grating to move grat_pos
    int grat_def = 535000; // Grating default position
    int chop_def = 664; // Chopper default position
    int grat_def_time = 0; // Time to move gratting to grat_def
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Register with environment
    WriteBBID($BBID);
    // Variables for time_array
    int duree_ramps = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // duree of this OBCP (computed and returned in [msec])
    int duree_msec = 0;
    // OBCP pseudo code
    // OBCP_WAVELENGTH_SWITCHING2(seq, seq_time, P#1,
    //... P#15, detector, cmp_par_blue, cmp_par_red, grat_pos, chop_pos, 
    //    grat_time, grat_def, chop_def, grat_def_time)
    // begin
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    //DMC_SET_TIME
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    //DMC_MOVE_GRAT_ABS(grat_pos)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    //DMC_MOVE_CHOP_ABS(chop_pos)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    //DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM)
    //; (all parameters filled by DPU based on seq parameter)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    //DMC_SYNCHRONIZE_ON_DET(detector)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    //DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    //WAIT(grat_time)
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    //DMC_START_SEQUENCE
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Call DEC/MEC sequence just to know the execution time
    int[] duree1 = DMC_wave_switch(nb_shift_up,nb_shift_dn,nb_abba_cycles,nb_ramps_grat,nb_up_down);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    //WAIT(seq_time)
    duree_msec = duree_msec + t_cmd + seq_time;
    //; check execution status of the sequence and in case of
    //failure stop OBCP and issue TM(1,8) + event
    //DMC_MOVE_GRAT_ABS(grat_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    //DMC_MOVE_CHOP_ABS(chop_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    //WAIT(grat_def_time)
    duree_msec = duree_msec + t_cmd + grat_def_time;
    duree_OVR = duree_OVR + t_cmd + grat_def_time;
    //Issue TM(1,7)
    //end
    //Duration: 10 x 200ms + grat_time + grat_def_time + 0.5s
    // This procedure calls the sequence described in sec. 4.2.7.
    // Now trigger execution of OBCP
    // This OBCP is number 32, requires 25 parameters and calls DEC/MEC #18!!!
    /// NOTE: WE DON'T KNOW OBCP_ID YET
    /// CALL USING NUMBER
    string obcp_ID = "WAVE_SWITCH_GRT2";
    int obcp_nb = 32;
    int obcp_par_nb = 25;
    int seq_DMC = 18;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_shift_up},{5,grat_shift_steps_up},{6,nb_abba_cycles},{7,param5},{8,nb_ramps_grat},{9,param7},{10,param8},{11,param9},{12,nb_shift_dn},{13,grat_shift_steps_dn},{14,param12},{15,param13},{16,param14},{17,param15},{18,detector},{19,comp_mode_blu},{20,comp_mode_red},{21,grat_pos},{22,chop_pos},{23,grat_time},{24,grat_def},{25,grat_def_time}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    // Pacs_DPU_START_OBCP_RAW(obcp_nb,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // Wait for execution of OBCP
    delay(time_array[0]);
    // Mark end of BB
    WriteEndBB();
    // Return the array of times

    return time_array;
}

// File          : PACS_Spec_Heat_SFT.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Flashers Short Functional Test
//
// Author        : P. Royer
//
// Arguments     :
//
// Description   : Sends current to both flashers for short times, the goal is only to see some reaction in the HK
//
//
// Prerequisite : The flashers are SWITCHED ON ALREADY
//	  	  The correct HK & Diaghk lists are already set & acquired
//
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 08-Jun-2006 initial version by PR
// 		 : 2.0 13-02-08 Made into a proc to be called by
//		       PV "obs" PacsEng_Spec_Flash_SFT
//		       Removed WriteOBID/WriteEndID unnecessary: called in Obs
//		   
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose Flashers Short Functional Test
// @comment - 
//
procedure PACS_Spec_Flash_SFT {
}{
    // 0.1 mA  -> 1.0 mA  ->  0.0 mA
    //
    PACS_Spec_Flash_Setup(20,20);
    delay(30);
    PACS_Spec_Flash_Setup(0,0);
    delay(30);
    PACS_Spec_Flash_Setup(205,205);
    delay(30);
    PACS_Spec_Flash_Setup(0,0);
    delay(30);
    //
}

// $Id$
// Missionphase  : PACS PV Phase
//
// File          : WriteOBSID_ast_OBS.cus//
// Version       : 0.1
//
// Purpose       : Configure the chopper servo loop
//
// Author        : MN
// CUSification  : MN
// Arguments     :
//
// Description   : Write OBS ID to system
//
// Comments      :
//
// Version       : 2.0
// History       : 1.0  12-nov-2007 initial version
// History       : 2.0  04-mar-2008  Converted into PV script by VDP
//
// 
obs PacsEng_WriteOBSID_ast {
    /* Needed variables to call PacsEng_WriteOBSID_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_WriteOBSID_ast                     */
}{
    int myOBSID = $OBSID;
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(WriteOBSID($OBSID)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: SPEC_fltw_move.txt,v 1.3 2007/04/25 15:14:05 dcesarsk Exp $ 
// Missionphase  : 
//
// Purpose       : Change filter wheel in spectroscopy
//                 Attention: there is only one controller for
//                 the filter wheels and the grating, but different
//                 sets of controller parameters!                 
//
// Author        : Thomas Mueller
// CUS script    : Diego A. Cesarsky
// CVS file      : SPEC_fltw_move.txt
//
// Arguments     : 
//Type   Name       DefVal     Description
//int    filter_id       1     Position of spectroscopic filter wheel  
//
// Description   : This script will change the spectrometer filter
//                 into a specified position. This can be a predefined
//                 position (with mode = 'ABS') or a relative position
//                 (with mode = 'REL'). 
//
//                 This script performs the following operations (section
//                 4.4.8 of the DEC/MEC User's Manual):
//		  "Consider that the grating is powered on and that an
//		   acquisition sequence has ended. To change the filter wheel
//		   position now: 
//		 1. Disable the grating controller (DMC_DISABLE_GRAT_CONT) 
//               2. Switch-on the spectro filter wheel controller 
//		    (DMC_SWON_FW_SPEC). Note : this will switch-off the
//		    grating controller and the photo filter wheel controller 
//		    but the grating position encoder will remain powered-on
//		    and will then continue reading the position. 
//               3. Any of the 2 move commands can be sent 
//               4. Switch-on the grating controller (DMC_SWON_GRAT_CONT) 
//               5. Enable the grating controller (DMC_ENABLE_GRAT_CONT) 
//               6. Start the new acquisition sequence."
//
//                 NOTE: THIS SCRIPT IGNORES REL MODES
//
// Dependencies  : 
//                 
// Comments      : This script should be executed after the
//                 switch-on procedure and the MEC setup
//
// Version       : 0.1 11-Oct-2004 Creation by DAC, based on TM's 
//                                 V1.1 of tm_spec_fil_switch.tcl 
// History       : 0.2 18-Oct-2004 Normalized variable names
//                 0.3 22-apr-2005 DAC Converted into procedure
//                                 Removed useless delays, read move time
//                                 from PACSparams 
//               :
int procedure SPEC_fltw_move {
    string filter_id = "POS A" in ["POS A","POS B"]; // Predefined positions [POS A, POS B]
}{
    // Accumulated duration [milliseconds]
    int duration_msec = 0;
    // Disable grating controller
    Pacs_DMC_DISABLE_GRAT_CONT();
    // Switch on power supply of SPEC filter wheel
    Pacs_DMC_SWON_FW_SPEC();
    // Move filterwheel to the predefined position 
    Pacs_DMC_MOVE_SPEC_FW_LOC(filter_id);
    // Get the duration of the move
    int move_time = iceil(dlookup("PACSparams","fltw_time","freq_time"));
    // Same in [sec]
    int move_time_sec = Msec2sec(move_time);
    delay(move_time_sec);
    duration_msec = duration_msec + move_time;
    // Switch on grating controller
    Pacs_DMC_SWON_GRAT_CONT();
    // Enable grating controller
    Pacs_DMC_ENABLE_GRAT_CONT();

    return duration_msec;
}

// Missionphase  : PACS FM ILT tests
//
// Purpose       : FoV scan Spectroscopy (OBCP_chop_scan_spec)
//
// Author        : P. Royer
//
// Arguments     :
//	     SPU setup arguments
//	     OBCP_chop_scan_spec arguments
//	     Filter wheel position
//
// Prerequisite  : 
//
// Description   :
//	     SPU Setup
//	     Position Filter Wheel
//	     OBCP_chop_scan_spec (FoV scan)
//                        SPU reset
//
// Dependencies : 
// 	     SPEC_spu_setup
//                        SPEC_spu_reset
//	     OBCP_chop_scan_spec (calling DMC_chop_scan_spec)
//
// Comments      : We are supposed in PACS spectro before to run this procedure
//	  => no CRE setup here
//
// Version       : 1.0
// History       : 1.0 / 14-Mar-2008 initial version by PR
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose FoV scan Spectroscopy (OBCP_chop_scan_spec)
// @comment - 
//
procedure PACS_Spec_Fov_Scan {
    int nb_samp_subramp_blu = 64; // Red Subramp length  (directly connected to ramp_fit_alg)
    int nb_samp_subramp_red = 64; // Blue Subramp length
    int ramp_fit_alg = 0 in [0,1]; // Ramp fit algorithm [0=LstSq;1=mean value]
    string filter_pos = "POS A" in ["POS A","POS B"];
    int nb_up_dn = 1; // P#1  number of up-down seqs.
    int nb_ramps = 1; // P#2  number of ramps on step
    int nb_steps_up = 300; // P#3  number of steps up
    int nb_steps_dn = 300; // P#4  number of steps down
    int step_up = 150; // P#5  relative move up
    int step_dn = -150; // P#6  relative move down
    int detector = 1; // Detector to SYNCH on
    int grat_pos = 535000; // Grating position
    int chop_start_pos = 0; // Chopper start position
    int grat_time = 20000; // Grating time
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression
    int grat_def = 535000; // Grating default
    int grat_def_time = 40000; // Grating default time
    int chop_def = 0; // Chopper default position
    int nb_rdouts_ramp = 64; // Ramp length
}{
    //
    //int ramp_len_red = 64; // Red ramps length
    //int ramp_len_blu = 64; // Blue ramps length
    //double bias_d_red = 0.07 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    //double bias_d_blu = 0.21 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    //int capa_red = 8; // Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
    //int capa_blu = 8; // Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
    //
    // CRE SETUP  --> SUPPOSED IN PACS-SPECTRO --> CRE SETUP SKIPPED
    // NOTE: capa_xxx is added to cre_ctrl_xx within SPEC_cre_setup
    //
    //double bias_r_red = 0.011; // in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    //double bias_r_blu = 0.011; // in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    //int cre_ctrl_red = 386;
    //int cre_ctrl_blu = 386;
    //SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    //
    // SPU SETUP
    // ======
    // Register with environment
    WriteOBSID($OBSID);
    // Start SPU
    int nb_raw_spu_blu = 3;
    int nb_raw_spu_red = 3;
    int glitch_det = 1;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,true);
    //
    // Position the filter wheel
    // ==============
    SPEC_fltw_move(filter_pos);
    //
    // OBCP_chop_scan_spec
    // =============
    OBCP_chop_scan_spec(nb_up_dn,nb_ramps,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,grat_pos,chop_start_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,chop_def,nb_rdouts_ramp);
    //
    // Stop SPU
    // =====
    SPEC_spu_reset();
    //
    // SYNC
    // ===
    sync();
}

// File          : PACS_GeGa_SFT_Init_Cold_He2.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Cold SFT of Ge:Ga detector chain 
//
// Author        : H. Feuchtgruber
//
// Arguments     : none
//                 
//
// Description   : Copy of PACS_GeGa_SFT_Init_Cold with different dummy voltages 
//                 
//                              
// Comments      :      
//
// Version       : 1.3
// History       : 1.0 / 6-Nov-2006 initial version
//                    1.1 13-nov-2006 Resistor bias have changed
//                    1.2 12-oct-2007 BV : Included mois comments
//                    1.3 8-Apr-08 HF adapted to in-flight default biases
procedure PACS_GeGa_SFT_Init_Cold_He2 {
}{
    mois_comment("Start of procedure PACS_GeGa_SFT_init_cold_He2");
    debug_print("Start PACS_GeGa_SFT_Init_Cold");
    mois_step("Set DPU housekeeping list to spectroscopy");
    //DPU_SET_HK_LIST (SPEC for both channels)
    Pacs_DPU_SET_HK_LIST("SPEC","BOTH Array");
    delay(1);
    mois_step("Configure DMC for communication with the DECs");
    // DMC_WRT_BOL_REC_OPT(ID,LENGTH,4,CHKSUM)
    int[] argum = [4];
    {int}[] argTuple = [{4}];
    int chksum = checksum("int",argum);
    Pacs_DMC_WRT_BOL_REC_OPT(argTuple,chksum);
    delay(1);
    // DMC_WRT_B_DEC_REC_OPT(ID,LENGTH,4,CHKSUM)
    argum = [4];
    argTuple = [{4}];
    chksum = checksum("int",argum);
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,chksum);
    delay(1);
    // DMC_WRT_R_DEC_OPT(ID,LENGTH,4,CHKSUM)
    argum = [4];
    argTuple = [{4}];
    chksum = checksum("int",argum);
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,chksum);
    delay(1);
    mois_step("Write default spectroscopy timing parameters to FPGA");
    // DMC_WRT_TIMING_FPGA_PAR(ID,LENGTH,16384,40,2,32,0,P//9,CHKSUM)
    {int}[] list_tuple = [{0x0},{0x0},{0x0},{26},{0x95217cb},{0xb}];
    int[] list_int = [0x0,0x0,0x0,26,0x95217cb,0xb];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_TIMING_FPGA_PAR(list_tuple,chksum);
    delay(1);
    // DMC_SET_TIMING_FPGA_PAR
    Pacs_DMC_SET_TIMING_FPGA_PAR();
    message("Default spectroscopy timing parameters set!");
    mois_step("Detector setup");
    //  ======== Initial detector setup ====================
    // DMC_SWON_B_DEC SWITCH ON THE BLUE DEC POWER
    Pacs_DMC_SWON_B_DEC();
    delay(8);
    // DMC_SWON_R_DEC" SWITCH ON RED DEC POWER
    Pacs_DMC_SWON_R_DEC();
    delay(8);
    // Wait after DEC switch-on
    delay(5);
    debug_print("DECs are on !");
    // Now define the startup Ge:Ga detector setup
    int read_per_ramp_b = 8;
    int cre_ctrl_b = 396;
    int bias_r_b = 0;
    int bias_d_b = 0;
    int read_per_ramp_r = 8;
    int cre_ctrl_r = 396;
    int bias_r_r = 0;
    int bias_d_r = 0;
    // DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000,chksum);
    delay(1);
    // DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000,chksum);
    delay(1);
    // DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    // DMC_SWON_B_SPEC" SWITCH ON BLUE SPECTROMETER ARRAY POWER
    Pacs_DMC_SWON_B_SPEC();
    delay(1);
    // PC091420 "DMC_SWON_R_SPEC" SWITCH ON RED SPECTROMETER ARRAY POWER
    Pacs_DMC_SWON_R_SPEC();
    delay(1);
    debug_print("SPECs are on !");
    // Wait for CRE HW sequence to finish
    delay(15);
    // now select the CREs
    cre_ctrl_b = 398;
    cre_ctrl_r = 398;
    mois_step("Write the detector parameters");
    // DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000,chksum);
    delay(1);
    // DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000,chksum);
    delay(1);
    // DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    // Now define the actual Ge:Ga detector setup
    read_per_ramp_b = 64;
    cre_ctrl_b = 398;
    bias_r_b = 41;
    bias_d_b = 328;
    read_per_ramp_r = 64;
    cre_ctrl_r = 398;
    bias_r_r = 41;
    bias_d_r = 123;
    double heater_blue = 0.0;
    // DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000,chksum);
    delay(1);
    // DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000,chksum);
    delay(1);
    // DMC-SET-PARAM-BOTH-SPEC SET TIMING PARAMTERS FOR BOTH SPEC ARRAYs
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    delay(1);
    mois_step("Switch on detector heater");
    // DMC_SWON_BD_HEATER
    Pacs_DMC_SWON_BD_HEATER();
    delay(1);
    // DMC_SET_B_SPEC_HEAT_C
    Pacs_DMC_SET_B_SPEC_HEAT_C(heater_blue);
    delay(1);
    debug_print("Detectors are up and running at default settings!");
    mois_step("Select synchronisation detector and set valid science data flag");
    // DMC_SYNCHRONIZE_ON_DET(1)
    Pacs_DMC_SYNCHRONIZE_ON_DET(1);
    delay(1);
    // DMC_WRT_B_DEC_REC_OPT" WRITE THE BLUE DEC RECEIVER OPTIONS
    argTuple = [{0}];
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,0x84c0);
    delay(1);
    // DMC_WRT_R_DEC_REC_OPT" WRITE THE RED DEC RECEIVER OPTIONS
    argTuple = [{0}];
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,0x84c0);
    delay(1);
    // DMC_VAL_SCI_DATA_BOTH" VALIDATE SCIENCE DATA FROM BOTH CHANNELS
    Pacs_DMC_VAL_SCI_DATA_BOTH();
    delay(1);
    // # ==== End of detector setup ==============
}

// Script        : PACS_Chopper_uk_move_12000_NoConf_ast.cus
// Missionphase  : SVT / Flight
//
// Purpose	: Move chopper to absolute position  
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-12000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched on and Chopper switched on.
//                 
// Comments	: This script is based on PACS_Chopper_uk_move_12000_ast_OBS,
//                     but without configuration and with mois comments
//
// Version	: 1.0	
// 
// History 	: 1.0 17-10-2007 BV First version
//		  
procedure PACS_Chopper_uk_move_12000_NoConf_ast {
}{
    mois_comment("Perform rectangular chopping with step 12000");
    //
    int chop_pos = 12000;
    // chopper position
    int cycle = 10;
    // give cycle #
    int plateau_time = 2;
    // select plateau time in sec
    // Start Diag. HK
    mois_step("Start Diagnostic housekeeping");
    SPEC_Chopper_dhk_5hk_1khz_bb();
    mois_step("Enable chopper controller");
    // Enable Chopper Controller 
    EnDis_chopper("ON");
    delay(5);
    mois_step("Perform rectangular chopping");
    // move chopper to zero
    PACS_Chopper_mov_abs_fm_bb(0);
    delay(1);
    // do observations
    int i = 1;
    while(i <= cycle) {
        PACS_Chopper_mov_abs_fm_bb(chop_pos);
        delay(plateau_time);
        PACS_Chopper_mov_abs_fm_bb(-chop_pos);
        delay(plateau_time);
        i = i + 1;
    }
    // move chopper to zero
    PACS_Chopper_mov_abs_fm_bb(0);
    delay(1);
    mois_step("Disable chopper");
    // Disable Chopper Controller 
    EnDis_chopper("OFF");
    delay(5);
    mois_step("Disable diagnostic housekeeping");
    // Stop diagnostic housekeeping
    PACS_stop_dhk_fm_bb();
}

// Missionphase  : 
//
// Purpose       : Perform the cooler recycling
//
// TCL author    : TM
// TCL file      : tm_phot_cooler_recycling.tcl
// CUS author    : DAC
// Script file   : BOLO_cool_recycle.txt 
//
// Input arguments
// type    name         description
// N/A 
//
// Return values
// Type        Description
// int []      Several duration times
//
// Description   : see PhFPU UM, chapter 4
//
// Dependencies  : 
//
// Preconditions :
//
// Comments      : Based on the PhFPU UM Draft 6.0 and abundant e-mail
//                 exchanges with SAp
// 
// Version       : 2.0
// History       : 0.1 08-Apr-2005 creation by DAC; based on TM's
//                     version 1.0 of 24-Sep-2004
//                 0.2 15-apr-2005 DAC Forgot WriteBBID!!
//                 0.3 18-apr-2005 DAC Added Switch Off All Groups
//                                 and SetOn All Temp Probes
//                 0.4 20-sep-2005 Added DPU_SET_HK_LIST to "PHOT"
//                                 and to "NO_PRIME" 
//                 0.5 21-sep-2005 Zeroed several HEATER currents
//                 1.0 26-sep-2005 Added delay(600) as the last operation
//                 1.1 28-sep-2005 Modified as per Marcs's mail:
//                                "replace:
//          step 0 (1.18 mA on HSE, 0.0 mA on HSP, wait 300 sec)
//          step 1 (1.4 mA on HSE, wait 600 sec)
//                                 by
//          step 1(1.4 mA on HSE, 0.0 mA on HSP, wait 600 sec)"
//                 1.2  7-mar-2006 ....HEATER_CURR renamed to HEATER_CUR
//                 1.3 26-apr-2006  update with respect to 
//                                  Preparation_au_recyclage.txt  and
//                                  Recyclage_Auto_Time.txt       and
//                                  starting out of SAFE mode (groups
//                                  are on, but not biases are set and
//                                  temperature sensors are on)
//                 1.4 10-oct-2006  autonomy function added
//                 1.5 08-nov-2006  TM: checked for groups off
//                 1.6 13-nov-2006  TM: cleaning of SP and HSP to zero
//                 1.7 14-nov-2006 Wait 15 minutes before enabling autonomy function
//                 1.8 30-nov-2006 Wait 20 minutes before enabling autonomy function
//                 1.9 09-apr-2007 Modifications of AFs
//                 2.0 11-apr-2007 SP heater current set explicitly to zero
//                 2.1 17-oct-2008 KO, extra_cool_time and extra_stab_time variables added
//
int[] block BOLO_cool_recycle PACS 2003 {
    int extra_cool_time = 0; // in second before disconnecting the evaporator from 2K
    int extra_stab_time = 0; // in second after the end of the recycling procedure
}{
    // disable AF 14 (to check for TEMP_EV < 0.3 K)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_T_FPU","DISABLE");
    // disable AF 21 (to check if the absolute value of the HSP current is below 2*10^(-5)A)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_SP1","DISABLE");
    // enable AF 18 (to check if the current of the sorption pump heater is below 30mA)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_SP2","ENABLE");
    //
    // Obtain and set Block ID
    WriteBBID($BBID);
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    // NOTE: here all durations are given in [sec]
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Set HK to PHOT
    Pacs_DPU_SET_HK_LIST("PHOT","BOTH Array");
    // content of "Preparation_au_recyclage.txt"
    // Set SP heater current to  to 0.00000000 amperes (0)
    // # P 07 01 0000
    int operand = 0x7010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    int t_wait = 1;
    delay(t_wait);
    duree_num = t_wait;
    duree_OVR = t_wait;
    // Set HSP heater current to  to 0.00000000 amperes (0)
    // # P 07 02 0000
    operand = 0x7020000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    t_wait = 1;
    delay(t_wait);
    duree_num = duree_num + t_wait;
    duree_OVR = duree_OVR + t_wait;
    // Set HSE heater current to  to 0.00140000 amperes (3572)
    // # P 07 03 0DF4
    // Attendre 300000 ms
    // # S 01 0493E0
    operand = 0x7030df4;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    t_wait = 300;
    delay(t_wait);
    duree_num = duree_num + t_wait;
    duree_OVR = duree_OVR + t_wait;
    // Set HSE heater current to  to 0.00118000 amperes (3011)
    // # P 07 03 0BC3
    // Attendre 900000 ms
    // # S 01 0DBBA0
    operand = 0x7030bc3;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    t_wait = 900;
    delay(t_wait);
    duree_num = duree_num + t_wait;
    duree_OVR = duree_OVR + t_wait;
    //*****************************************************************
    //**                                                             **
    //**     Automatic Cooling reclycling                            **
    //**     ("Recyclage_Auto_Time.txt")                             **
    //**                                                             **
    //*****************************************************************
    //
    // - 23/01/06 Procedure of reclycling in Saclay cryostat with Phfpu MV
    // - note : this is timing version without temperature test
    //
    //         Initialisation of BOLC
    //
    // Set temp probe on/off FF hexa
    // # P 07 00 00 FF
    // 
    //         Initialisation of LTU
    //
    // Inhiber enregistrement TM
    // # S 08 
    // Valider enregistrement TM
    // # S 09
    //
    // Initial conditions
    // TEMP_SP < 10K
    // TEMP_EV < 2K
    //
    // Set SP heater current to  to 0.02730000 amperes (2231)
    // # P 07 01 08B7
    //
    // Attendre 2100000 ms
    // # S 01 200B20
    operand = 0x70108b7;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    t_wait = 2100;
    delay(t_wait);
    duree_num = duree_num + t_wait;
    duree_OVR = duree_OVR + t_wait;
    //
    // Set SP heater current to  to 0.00700000 amperes (580)
    // # P 07 01 0244
    // 
    // Attendre 2820000 ms
    // # S 01 2B07A0
    operand = 0x7010244;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    t_wait = 2820;
    delay(t_wait);
    duree_num = duree_num + t_wait;
    duree_OVR = duree_OVR + t_wait;
    //
    // Additional wait time for the evaporator cooling down
    delay(extra_cool_time);
    duree_num = duree_num + extra_cool_time;
    duree_OVR = duree_OVR + extra_cool_time;
    //
    // Set HSE heater current to  to 0.00000000 amperes (0)
    // # P 07 03 0000 
    //
    // Attendre 720000 ms
    // # S 01 0AFC80 
    operand = 0x7030000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    t_wait = 720;
    delay(t_wait);
    duree_num = duree_num + t_wait;
    duree_OVR = duree_OVR + t_wait;
    //
    // Set SP heater current to  to 0.00000000 amperes (0)
    // # P 07 01 0000
    operand = 0x7010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    t_wait = 1;
    delay(t_wait);
    duree_num = duree_num + t_wait;
    duree_OVR = duree_OVR + t_wait;
    //
    // Set HSP heater current to  to 0.00140000 amperes (3569)
    // # P 07 02 0DF1
    // 
    // Attendre 480000 ms
    // # S 01 075300 
    operand = 0x7020df1;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    t_wait = 480;
    delay(t_wait);
    duree_num = duree_num + t_wait;
    duree_OVR = duree_OVR + t_wait;
    //
    // Set HSP heater current to  to 0.00118000 amperes (3010)
    // # P 07 02 0BC2 
    operand = 0x7020bc2;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    t_wait = 1;
    delay(t_wait);
    duree_num = duree_num + t_wait;
    duree_OVR = duree_OVR + t_wait;
    //
    // ************************	
    // **                    **
    // ** end recycling      **
    // **                    **
    // ************************	
    //  Last message
    debug_print("Recycling completed, in about 20 min, TEMP_EV < 0.3 K");
    t_wait = 1200;
    duree_num = duree_num + t_wait;
    duree_OVR = duree_OVR + t_wait;
    delay(t_wait);
    //
    // AF settings
    //
    // disable AF 18 (to check if the current of the sorption pump heater is below 30mA)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_SP2","DISABLE");
    // enable AF 21 (to check if the absolute value of the HSP current is below 2*10^(-5)A)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_SP1","ENABLE");
    //
    // Set HK to NO PRIME (to have the clean SAFE settings again)
    Pacs_DPU_SET_HK_LIST("NO_PRIME","BOTH Array");
    //
    // Additional wait time for the evaporator temperature stabilisation
    delay(extra_stab_time);
    duree_num = duree_num + extra_stab_time;
    duree_OVR = duree_OVR + extra_stab_time;
    //
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// Author    	 : PR
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Gra_DEG_MODE_Diaghk_Setup {
    /* No variables to call PacsEng_Spec_Gra_DEG_MODE_Diaghk_Setup                        */
    int diag_hk_period = 5; // 5 msec diag hk period 
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_DEG_MODE_Diaghk_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_DEG_MODE_Diaghk_Setup(diag_hk_period)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_DEG_MODE_Diaghk_Setup(diag_hk_period);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Script        : PacsEng_Chopper_AutoOpt.txt
// Missionphase  : Commissioning
//
// Purpose	: Check a series of different chopper controller settings by
//                chopping between +/- 12000 units (~4 deg)
//                  
// Author	: Markus Nielbock/Helmut Dannerbauer
// CUS author 	: MN/HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-12000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions: PACS switched on and Chopper switched off.
//                 
// Comments	: This script is based on the commanding script
//                PACS_Chopper_uk_move_12000_OBS.cus
//
// Version	: 1.1
// 
// History 	: 1.0 20-Nov-2007 (MN) Script to do simple chopper cycle 
//         	  1.1 10-Mar-2008 (MN) adopted extended CUS naming conventions
//
// Initialise input parameters:
// Defines control parameter range, loops run from k(p,i,c,f)min to
// k(p,i,c,f)max defining the inverse of the ratio of parameter change w.r.t.
// the default value.
obs PacsEng_Chopper_AutoOpt {
    int kpmin = 0 in [-3,3];
    int kpmax = 0 in [-3,3];
    int kimin = 0 in [-3,3];
    int kimax = 0 in [-3,3];
    int kcmin = 0 in [-3,3];
    int kcmax = 0 in [-3,3];
    int kfmin = 0 in [-3,3];
    int kfmax = 0 in [-3,3];
}{
    // duration
    int tOPT = duration(Pacs_Chopper_AutoOpt(kpmin,kpmax,kimin,kimax,kcmin,kcmax,kfmin,kfmax));
    int tOBSID = duration(WriteOBSID($OBSID));
    int tEndID = duration(WriteEndID());
    int tp = tOPT + tOBSID + tEndID;
    // Issue the pointing request
    int[] fromPntReq = no_pointing(true,0,0,tp);
}{
    // The state machine
    int[] stateVar = [0];
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 3) {
            // Get OBSID from environment
            //Send OBSID to DMC
            WriteOBSID($OBSID);
            data_rate(120.0);
            Pacs_Chopper_AutoOpt(kpmin,kpmax,kimin,kimax,kcmin,kcmax,kfmin,kfmax);
            // Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose	: Moves the grating back & forth throughout the RSRF, with long wait times, to study the transients
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: 
//
// Description	: 
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on
//	    The grating controller is SWON and ENABLED
//                       The FWSPEC is placed on position B
//
// Comments	: 
//
// Version	: 2.0
//               
// History	: 1.0 06-Apr-2007 PR Creation
// History       :2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_Time_Constant_IST {
    /* Needed variables to call PacsEng_Spec_Time_Constant_IST                        */
    int idle_time = 240;
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Time_Constant_IST                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Time_Constant_IST(idle_time)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Time_Constant_IST(idle_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : Two or three position chopping with dithering followed by 
//                 calibration readouts chopping between CS1 and CS2. Chopping
//                 to the REF positions is done with dithering. 
//   
// DMC author    : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : DMC_spec_2_3_chop_dither.txt 
//
// Arguments used by the calling OBCP                        
// 
// Type  Name               DefVal  Description   : 
// int   nb_up_down                 number of up-down sequences
// int   nb_grat_steps              number of grating steps
// int   nb_SRC_OFF                 nb cycles on/off source per grating positn
// int   chop_pos_REF1:             chopper position 1
// int   nb_ramps_plateau           number of ramps per chopper plateau
// int   chop_pos_REF2              chopper position 2 
// int   chop_pos_REF3              chopper position 3 
// int   nb_CS1_CS2                 number of cycles on the calibration sources
//                          per grating positn
// int   chop_pos_CS1               chopper position on CS1
// int   chop_pos_CS2               chopper position on CS2
// int   grat_step_up               step size of relative grating move up 
// int   grat_step_dn               step size of relative grating move down 
//
// Description :
//   Default sequence for spectral line observations. The 
//   chopping pattern is identical to the analogous photometry 
//   case, however the number of chopper/readout cycles per 
//   grating step can be given as a parameter. Currently it is 
//   assumed that we do internal calibration measurements inside
//   this sequence on every grating step. "Up" and "Down" scans will 
//   cover the same absolute grating positions in equidistant steps, 
//   commanded by MOVE_GRATING_RELATIVE. The initial absolute start
//   position of the grating will be commanded before, from 
//   within the OBCP (3.9). The number of grating steps for a
//   line scan is determined by nb_grat_steps. The sequence may
//   consist of at least 7 LOOPs.
//   Explicitly: 
//For the number of UP/DOWN sequences
//  For each of the P#2 grating positions going up
//      Repeat P#3 times
//         SRC P#4
//         OFF P#6
//         SRC P#4
//         OFF P#7
//      End repeat P#3 times
//      Repeat P#8 times
//         CS1 P#9
//         CS2 P#10
//      End repeat P#8 times
//  End of for each of the P#2 grating positions going up
//  For each of the P#2 grating positions going down
//      Repeat P#3 times
//         SRC P#4
//         OFF P#6
//         SRC P#4
//         OFF P#7
//      End repeat P#3 times
//      Repeat P#8 times
//         CS1 P#9
//         CS2 P#10
//      End repeat P#8 times
//  End of for each of the P#2 grating positions going down
//End for the number of UP/DOWN sequences
//   This procedure returns its duration
//   in number_of_ramps. It is up to the calling program to
//   convert number_of_ramps into [sec] (this procedure does
//   not know the duree of each ramp)
//
//
// Dependencies  : Stand alone DEC/MEC sequence
//   
// Comments      : Follows verbatim paragraph 4.2.1 in PACS-ME-LI-005
//         Actual values of input parameters, except values for the
//         various loop counters, are completely irrelevant and so
//         are not used. 
//         Loop counters are used to estimate the duree of the
//         sequence
//
// Version       : 0.1 22-apr-2005 DAC from DEC/MEC #8, viz.
//                                 DMC_spec_2_3_chop
// History       :
//
// This "dummy" DEC/MEC sequence needs only the loop parameters from the
// complete list above
//
int[] procedure DMC_spec_2_3_chop_dither {
    int nb_up_down = 1; // Number of sequences: up down up ...
    int nb_grat_steps = 10; // Number of grating steps
    int nb_SRC_OFF = 10; // Nb cycles on/off source/grating position
    int nb_ramps_plateau = 10; // Number of ramps per chopper plateau
    int nb_CS1_CS2 = 10; // Nbr cycles on cal src per grating position
}{
    // Define variables for time_array
    int duree_ramps = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Pseudo code from PACS OBCPs and DMC Sequences (4.1.2)
    //
    // WAIT 1 ; have a defined start
    // Accumulated duree_ramps in number of ramps
    duree_ramps = duree_ramps + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; set Label to 0 
    // LOOP P#1 ; main loop measurement
    for(int outloop = 1 .. nb_up_down) {
        //   LOOP P#2 ; grating loop up
        for(int gratUPloop = 1 .. nb_grat_steps) {
            //  WAIT 1 ; sync. for grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            //  MOVE_GRATING_RELATIVE P#11 ; increment grating position
            //  LOOP P#3 ; chop readout cycle 
            for(int onoffUPloop = 1 .. nb_SRC_OFF) {
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#4 ; chopper to P#4 (SRC) 
                //  LABEL 3 ; first chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_SRC = duree_SRC + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE_DITHER P#6 ; chopper to P#6 (REF1)
                //  LABEL 5 ; next chopper pos. 
                //  WAIT P#5 ; take P#5 ramps 
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_REF = duree_REF + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#4 ; chopper to P#4 (SRC)
                //  LABEL 3 ; first chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_SRC = duree_SRC + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE_DITHER P#7 ; chopper to P#7 (REF2)
                //  LABEL 7 ; last chopper pos. 
                //  WAIT P#5 ; take P#5 ramps 
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_REF = duree_REF + nb_ramps_plateau;
            }
            //  END_LOOP ; chop readout cycle
            //  LOOP P#8 ; calibration loop
            for(int csUPloop = 1 .. nb_CS1_CS2) {
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE chop_pos_CS1; chop to CS1 
                //  LABEL 65 ; CS1 
                //  WAIT P#5 ; take nb_ramps_plateau 
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_CAL = duree_CAL + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE chop_pos_CS2 ; chop to CS2 
                //  LABEL 129 ; CS2 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_CAL = duree_CAL + nb_ramps_plateau;
            }
            //  END_LOOP ; calibration done
        }
        //   END_LOOP ; grating scan up done
        //   LOOP P#2 ; grating loop down
        for(int gratDNloop = 1 .. nb_grat_steps) {
            //  WAIT 1 ; sync. for grating 
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            //  MOVE_GRATING_RELATIVE grat_step_dn ;decrement grating position 
            //  LOOP P#3 ; chop readout cycle
            for(int onoffDNloop = 1 .. nb_SRC_OFF) {
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#4 ; chopper to P#4 (SRC)
                //  LABEL 3 ; first chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau 
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_SRC = duree_SRC + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE_DITHER P#6 ; chopper to P#6 (REF1) 
                //  LABEL 5 ; next chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau 
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_REF = duree_REF + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#4 ; chopper to P#4 (SRC)
                //  LABEL 3 ; first chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_SRC = duree_SRC + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE_DITHER P#7 ; chopper to P#7 (REF2)
                //  LABEL 7 ; last chopper pos. 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_REF = duree_REF + nb_ramps_plateau;
            }
            //  END_LOOP ; chop readout cycle done 
            //  LOOP P#8 ; calibration loop
            for(int csDNloop = 1 .. nb_CS1_CS2) {
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#9 ; chop to P#9 (CS1) 
                //  LABEL 65 ; CS1 
                //  WAIT P#5 ; take nb_ramps_plateau
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_CAL = duree_CAL + nb_ramps_plateau;
                //  WAIT 1 ; sync. for chopper 
                duree_ramps = duree_ramps + 1;
                duree_OVR = duree_OVR + 1;
                //  MOVE_CHOPPER_ABSOLUTE P#10 ; chop to P#10 (CS2)
                //  LABEL 129 ; CS2 
                //  WAIT P#5 ; take P#5 ramps
                duree_ramps = duree_ramps + nb_ramps_plateau;
                duree_CAL = duree_CAL + nb_ramps_plateau;
            }
            //   END_LOOP ; calibration done
        }
        //   END_LOOP ; grating scan up done
    }
    // END_LOOP ; main loop done
    // WAIT 1 ; complete last plateau 
    duree_ramps = duree_ramps + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; reset LABEL to 0 
    // END_SEQUENCE
    // Create time_array
    int[] time_array = [duree_ramps,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    debug_print("DMC_spec_2_3_chop_dither duration: " + time_array);

    return time_array;
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Preconditions : see associated procedure
//
// Comments      :
// Version	 : 1.0
// 
// History       : 0.1 22-mar-2006
// History       : 1.0 04-mar-2008  Converted into PV script by VDP
//
obs PacsEng_Spec_Gra_Diaghk_SINCOS_Setup {
    /* Needed variables to call PacsEng_Spec_Gra_Diaghk_SINCOS_Setup                        */
    int diag_hk_period = 5; // 5 msec diag hk period 
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_Diaghk_SINCOS_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_Diaghk_SINCOS_Setup(diag_hk_period)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_Diaghk_SINCOS_Setup(diag_hk_period);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req.1.1.1 for the Commissioning Phase
//           Check the bias/signal relationship using CSs
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_lowGainBias1_direct
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_lowGainBias1_direct
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_CommPh_lowGainBias1(1, "LOW")
//
// Version : Mon Jul 14 06:40:46 CEST 2008
//
obs PacsCal_Phot_lowGainBias1_direct {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    //Minimum slew time
    int tslewmin = 0;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeOBSID;
    //Final hold
    int tfh = timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_lowGainBias1_direct(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            //      Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //      Call the Phot_lowGainBias1_direct
            Phot_lowGainBias1_direct(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            //      Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// $Id: PacsCal_WaveCalChop.txt,v 1.3 2008/04/21 09:48:07 vanessad Exp $
// Missionphase		: PACS PV Phase
//
// Purpose :		Wavelength calibration and instrumental profile
// 	      	      	 with Chop/Nod
// Author		 : HF
//
// Arguments:
//
// Prerequisite 	: PACS does not need to be on nor setup for spectroscopy
//
// Description		: Uses OBCP27 for executing a parameterized scan of any length,
// 			 �stepsize etc. Represents a generic chopped grating scan
// Comments		:
//
// Version		: 1.0
// 
// History		: 0.1 Using example from PacsCal_WaveCalNoChop
// 			: 1.0 perform calibrations during slew and 
//    	  	       	   then a wavelength calibration on source
//			   usng NOD=1 and Choping
//			   1.1 17-dec-2008: VD missing PacsSpecDefault SPR 5692
//			   1.2 22-apr-2009 VD SPR 5447
//			   1.3 23-apr-2009 VD SPR 6482
//                         1.4 23-jul-2009  BV SPR 1798 (default biases)
//                         1.5 14-sep-2009 VD SCR PHS-1173
//                         
obs PacsCal_WaveCalChop {
    /* Needed variables to call WaveCalChop */
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int grat_pos = 500000; // grating start position for scan
    int grat_time = 0; // time for grating to move to start position [msec]
    int grat_step_up = 200; // grating step size
    int nb_ramps_plateau = 1; // number of readouts per grating position
    int grat_step_dn = 200; // grating step size
    int nb_grat_steps = 50; // number of grating steps in one direction
    int order = 2; // end position for order selection: 1=Red, 2= or 3= Blue)                
    int nb_SRC_REF = 3; // number of ramps (cycles) per grating position
    int nb_CS1_CS2 = 0; // nb of cycles on internal CS
    int nb_rdouts_ramp = 64; // number of readouts per ramp
    int nb_up_down = 1; // number of grating updown scans
    int nb_raw_red = 3; // number of red pixels
    int nb_raw_blu = 3; // number of blue pixels
    int capa_red = 12; // Red capacitor
    int capa_blu = 12; // Blue capacitor
    double bias_r_blu = 0.0101; // Bias "r" blue
    double bias_r_red = 0.0101; // Bias "r" red
    double bias_d_blu = 0.10001; // Bias "d" blue
    double bias_d_red = 0.04201; // Bias "d" red
    int comp_mode_blu = 16; // compression mode for blue detector
    int detector = 1; // 1=blue 2=red (sync on detector)
    int comp_mode_red = 16; // compression mode for red detector
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    int nnod = 1; // number of nods (AB or BA)
    double chopthrow = 30.0; // chop/nod throw in arcsec
    bool startAtB = false; // false = start AB cycle (true = start BA cycle)
    bool fixed = false; // false=nod in instrument coordinates, true= nod ccw with respect to north on sky
    double pattnod = 270.0; // Nod along chop direction is about 270 degree
    bool verbose = true;
}{
    // compiting time for slw / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Set OBSID
    int tobsid = duration(WriteOBSID($OBSID));
    // Verification for grating and chopper hard limits
    int[] gratpos = [0];
    Pacs_HardLimitsCheck(gratpos,chopthrow);
    // Calibration time during slew
    // SPEC parameters for BLU and RED               
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    string throwUsage = "small";
    string extraConf = "normal";
    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // frstLstGratPos is the last position for the grating after the Cals done
    // during Slew time... must be same as observations start position: grat_pos   
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    // "N/A" in string because of indexing 0,1,2,3
    string[] choix = ["N/A","order1","order2","order3","sed4"];
    string order_str = "order" + order;
    //    if(choix[order] != "order1") {
    //        double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //    double keyWL = PacsSpecKeyWaves(order_str);
    double[] keyWAVE = [150.0];
    // have to introduce the logic for KeyWL as fucntion of order + filter
    if(choix[order] == "order3" && fltPOS == "POS B") {
        error("Filter B and order 3 are not compatible");
    }
    if(choix[order] == "order1" && fltPOS == "POS A") {
        keyWAVE = [180.0];
    }
    if(choix[order] == "order1" && fltPOS == "POS B") {
        keyWAVE = [150.0];
    }
    if(choix[order] == "order2" && fltPOS == "POS B") {
        keyWAVE = [75.0];
    }
    if(choix[order] == "order3" && fltPOS == "POS A") {
        keyWAVE = [60.0];
    }
    // this is for extended Blue
    if(choix[order] == "order2" && fltPOS == "POS A") {
        keyWAVE = [60.0];
        choix[order] = "sed4";
    }
    // no need for SpecKeyWave!
    int tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]));
    //    } else {
    //        keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //        double keyWAVE2 = dlookup("KEY_WAVES",order_str,"KeyWave2");
    //        keyWAVE = [keyWAVE1,keyWAVE2];
    //        tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]));
    //   }
    //Initial hold
    int tih = 0;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int grat_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int tepilog = duration(SPEC_aot_epilogue(grat_pos,grat_def,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(WaveCalChop(fltPOS,grat_pos,grat_time,grat_step_up,grat_step_dn,nb_grat_steps,nb_CS1_CS2,nb_rdouts_ramp,nb_ramps_plateau,nb_up_down,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_SRC_REF,chopthrow,detector));
    if(verbose) {
        debug_print("Duration of WaveCalChop" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    int tloadmin = 0;
    int nload = 0;
    int thold = 0;
    int nhold = 0;
    int tpa = tp;
    int tpb = tp;
    //Issue PointReq
    int tslewmin = tobsid + tpacsSlewCal;
    if(verbose) {
        debug_print("Slewing time is:" + tslewmin + "sec");
    }
    int[] ts = nodding_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nnod,chopthrow,tpa,tpb,tloadmin,nload,thold,nhold,startAtB);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            int tNOW = time();
            // slew time calibration
            WriteOBSID($OBSID);
            if(verbose) {
                debug_print("Slewing starts at :" + tNOW + " sec");
            }
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            if(choix[order] == "order1") {
                PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]);
            } else {
                PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]);
            }
            tNOW = time();
            if(verbose) {
                debug_print("Slewing ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                WaveCalChop(fltPOS,grat_pos,grat_time,grat_step_up,grat_step_dn,nb_grat_steps,nb_CS1_CS2,nb_rdouts_ramp,nb_ramps_plateau,nb_up_down,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_SRC_REF,chopthrow,detector);
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 7) {
                    //       Call the WaveCal procedure
                    tNOW = time();
                    if(verbose) {
                        debug_print("Observation at NOD starts at :" + tNOW + " sec");
                    }
                    WaveCalChop(fltPOS,grat_pos,grat_time,grat_step_up,grat_step_dn,nb_grat_steps,nb_CS1_CS2,nb_rdouts_ramp,nb_ramps_plateau,nb_up_down,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_SRC_REF,chopthrow,detector);
                    tNOW = time();
                    if(verbose) {
                        debug_print("Observation at NOD ends at :" + tNOW + " sec");
                    }
                } else {
                    if(state[0] == 5) {
                        tNOW = time();
                        if(verbose) {
                            debug_print("Final Hold starts at :" + tNOW + " sec");
                        }
                        SPEC_aot_epilogue(grat_pos,grat_def,verbose);
                        WriteEndID();
                        tNOW = time();
                        if(verbose) {
                            debug_print("Final Hold ends at :" + tNOW + " sec");
                        }
                    }
                }
            }
        }
    }
    // End of Observation
}

// $Id: 
// Purpose        : OBS for Pacs_EDAC_to_DMC_HK
//                 
//
// CUS author     : VD + HF
//
// Input arguments: see after module identification
//
// Return values: none
// N/A
//
// Comments      : only run it once
//
// History: 1.0 09-Nov-2010 created
//          1.1 10-Nov-2010 PACS-3137 (SCR added) and Memory address to be mapped as Hspot input
//
//
obs PacsEng_Pacs_EDAC_to_DMC_HK {
    int addMem = 0x5476a; // Memory address in HEX
    int incN = 0; //Ninc Adress increment
}{
    int t_EDAC_to_DMC = duration(Pacs_EDAC_to_DMC_HK(addMem,incN));
    // Add needed time to set/unset OBSID
    int tset = duration(PacsBbWriteOBSID($OBSID));
    int tunset = duration(PacsBbWriteEndID());
    int tp = t_EDAC_to_DMC;
    // Issue PointReq
    int[] ts = no_pointing(true,tset,tunset,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            PacsBbWriteOBSID($OBSID);
        }
        if(state[0] == 3) {
            Pacs_EDAC_to_DMC_HK(addMem,incN);
        }
        if(state[0] == 5) {
            PacsBbWriteEndID();
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_HK_Setup {
    /* No variables to call PacsEng_Phot_HK_Setup                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_HK_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_HK_Setup()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_HK_Setup();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : PACS Spectrometer FoV Scan on the cryo cover
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version	: 1.0
// History       : 1.0  11-Mar-2008  Converted into PV script by PR
//
obs PacsEng_Spec_Fov_Scan {
    /* Needed variables to call PacsEng_Spec_FoV_Scan                        */
    int grat_pos = 535000; // Grating position (grating is fixed)
    string filter_pos = "POS A" in ["POS A","POS B"];
    int chop_start_pos = -23500; // Chopper start position
    int nb_steps_up = 310; // P#3  number of steps up
    int step_up = 150; // P#5  step_up:  relative move up
    int nb_up_dn = 1; // P#1  number of up-down seqs.
    int nb_ramps = 2; // P#2  number of ramps on step
    int nb_rdouts_ramp = 64; // Ramp length used in computation of OBCP duration only
    int nb_samp_subramp_blu = 64; // Red Subramp length  (directly connected to ramp_fit_alg)
    int nb_samp_subramp_red = 64; // Blue Subramp length
    int ramp_fit_alg = 0 in [0,1]; // Ramp fit algorithm [0=LstSq;1=mean value]
    /* End of needed variables for PacsEng_Spec_FoV_Scan                     */
}{
    // Fixed Parameters
    int nb_steps_dn = nb_steps_up;
    // P#4  number of steps down
    int step_dn = -step_up;
    // P#6  relative move down
    int grat_time = 15000;
    // Grating time
    int grat_def_time = 15000;
    // Grating default time
    int chop_def = 650;
    // Chopper default position
    int detector = 1;
    // Detector to SYNCH on
    int grat_def = 500000;
    // Grating default
    int comp_mode_blu = 16;
    // "Blue" compression
    int comp_mode_red = 16;
    // "Red" compression
    //
    int chop_limit_dn = ilookup("SPEC_MEC_Limits","Nominal","chop_min");
    int chop_limit_up = ilookup("SPEC_MEC_Limits","Nominal","chop_max");
    int chop_max_pos = chop_start_pos + nb_steps_up * step_up;
    if(chop_start_pos < chop_limit_dn) {
        error("ERROR! chop_start_pos " + chop_start_pos + " is beyond the max allowed negative chopper throw " + chop_limit_dn);
    }
    if(chop_max_pos > chop_limit_up) {
        error("ERROR! chop_max_pos " + chop_max_pos + " is beyond the max allowed positive chopper throw " + chop_limit_up);
    }
    //
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Fov_Scan(nb_samp_subramp_blu,nb_samp_subramp_red,ramp_fit_alg,filter_pos,nb_up_dn,nb_ramps,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,grat_pos,chop_start_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,chop_def,nb_rdouts_ramp)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Fov_Scan(nb_samp_subramp_blu,nb_samp_subramp_red,ramp_fit_alg,filter_pos,nb_up_dn,nb_ramps,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,grat_pos,chop_start_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,chop_def,nb_rdouts_ramp);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : ILT at Garching
//
// Purpose : Monitor the behaviour of Vrl and VhBlind
//           as a function of the temperature variation
//       <=> PCD req.1.1.6. Pixel offset with temperature
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_small_Vrl_VhBlind
//
// Argument :
//    niter : Number of small blocks to repeat
//    nVrls : Number of VRL values to explore
//    lowGainTable : File name of a low gain biase table for the setting during the measurement
//    highGainTable : File name of a high gain biase table to reset at the end
//    stabilizationWaitTime : stanilization time in seconds
//    acquisitionTime : data acquisition duration in seconds
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is set
//
// Description : Small exploration of Vrl and VhBlind
//
// Update :
//   Wed Nov 15 2006 : KO, First version
//   Wed Aug 26 2009 : KO, Set in direct mode at the end (SCR: PACS-1998)
//   Wed Aug 27 2009 : KO, Minor change of the default values
//
procedure Phot_small_Vrl_VhBlind_IST {
    int niter = 1; // Number of iterations
    double[] vhbs = [2.2]; // VH_BLIND values to explore
    double[] vrls = [0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8]; // VRL values to explore
    string initialBiasTable = "BOLObias_preILT_standard_low"; // Biase table file name to use during the measurement
    int stabilizationWaitTime = 30; // Stabilization time
    int acquisitionTime = 30; // Data acquisition time
}{
    //*************************************
    // Create a set of VRL values to explore
    //*************************************
    //    double[] vrls = [];
    //    for(int i = 0 .. nVrls - 1) {
    //        vrls[i] = 0.6 * double(i) / double(nVrls - 1);
    //    }
    //
    //**********************
    // Set the default biases
    //**********************
    //
    PHOT_set_bias_volt(initialBiasTable,1);
    PHOT_set_bias_volt(initialBiasTable,2);
    PHOT_set_bias_volt(initialBiasTable,3);
    PHOT_set_bias_volt(initialBiasTable,4);
    PHOT_set_bias_volt(initialBiasTable,5);
    PHOT_set_bias_volt(initialBiasTable,6);
    //
    //
    //************************************************************
    // Sequence mode : blocking on CKRL for the mode non-hache
    //************************************************************
    //
    // Set all groups bol bias 09 (CKRLH) to 2.0 volts
    Pacs_BOLC_SET_CKRLH_ALL(2.0);
    // Set all groups bol bias 10 (CKRLL) to 2.0 volts
    Pacs_BOLC_SET_CKRLL_ALL(2.0);
    // Set all groups bol bias 12 (VDECX-L) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc0000);
    // Set all groups bol bias 11 (VDECX-H) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0xb0000);
    //
    //***************************
    // Sequence mode : Sb_only
    //***************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    // Set seq mode Sb_only (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sb_only");
    //# P 09 01 00 02
    int operand = 0x9010002;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    //
    //**************************************
    // Only low gain for this reduced version
    //**************************************
    //
    Pacs_BOLC_SET_GAIN("LOW");
    //
    //*******************************
    // Repeat as much as niter times
    //*******************************
    for(int j = 0 .. niter - 1) {
        TMMarker602();
        // mark the beginning of an iteration
        //*******************
        // Loop over VHBlind
        //*******************
        for(int ivhb = 0 .. length(vhbs) - 1) {
            Pacs_BOLC_SET_VH_BLIND_G1(vhbs[ivhb]);
            Pacs_BOLC_SET_VH_BLIND_G2(vhbs[ivhb]);
            Pacs_BOLC_SET_VH_BLIND_G3(vhbs[ivhb]);
            Pacs_BOLC_SET_VH_BLIND_G4(vhbs[ivhb]);
            Pacs_BOLC_SET_VH_BLIND_G5(vhbs[ivhb]);
            Pacs_BOLC_SET_VH_BLIND_G6(vhbs[ivhb]);
            //*****************
            // Increment on Vrl
            //*****************
            for(int ivrl = 0 .. length(vrls) - 1) {
                Pacs_BOLC_SET_VRL_G1(vrls[ivrl]);
                Pacs_BOLC_SET_VRL_G2(vrls[ivrl]);
                Pacs_BOLC_SET_VRL_G3(vrls[ivrl]);
                Pacs_BOLC_SET_VRL_G4(vrls[ivrl]);
                Pacs_BOLC_SET_VRL_G5(vrls[ivrl]);
                Pacs_BOLC_SET_VRL_G6(vrls[ivrl]);
                // Wait for stabilizationWaitTime s for stabilization
                delay(stabilizationWaitTime);
                // Measurement during acquisitionTime s
                TMMarker601();
                // mark the beginning of the acquisition
                delay(acquisitionTime);
                TMMarker600();
                // mark the end of the acquisition
            }
        }
    }
    //*****************************************************
    // Set the default biases in direct mode with low gain
    //*****************************************************
    //
    PHOT_set_biases(initialBiasTable,"DIRECT","LOW");
    //
    // sync the bus
    sync();
}

// $Id: PacsCal_WaveCalNoChop.txt,v 1.3 2008/04/21 09:48:07 vanessad Exp $
// Missionphase  : PACS PV Phase
//
// Purpose       : Wavelength calibration and instrumental profile
// Author        : HF
//
// Arguments     :
//
// Prerequisite  : PACS must be on and configured for Photometry
//
// Description   : Uses OBCP4 for executing a parameterized 
//
// Comments      :
//
// Version       : 0.2
// History       : 0.1 29-apr-2008 VDP created
//                 
obs PacsCal_OBCP_chop_scan_phot {
    /* Pacs_OBCP_chop_scan_phot parameters */
    int nb_up_down = 1; // P#1  number of up-down seqs.
    int nb_rdouts = 80; // P#2  number of readouts on step
    int nb_steps_up = 163; // P#3  number of steps up
    int nb_steps_dn = 163; // P#4  number of steps down
    int step_up = 287; // P#5  relative move up
    int step_dn = -287; // P#6  relative move down
    int detector = 4; // Detector to SYNCH on
    int comp_mode_blu = 0; // "Blue" compression
    int comp_mode_red = 0; // "Red" compression
    int chop_start = -23500; // Chopper start position
    int chop_def = 648; // Chopper default position
    /* Pointing basic parameters */
    int naifid = 0; // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // zoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DECoff
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    //Minimum slew time
    int tslewmin = 0;
    //Initial hold
    int tih = imax(1,duration(WriteOBSID($OBSID)));
    //Final hold
    int tfh = imax(1,duration(WriteEndID()));
    //Duration of "stable" pointing
    int tp = duration(Pacs_OBCP_chop_scan_phot(nb_up_down,nb_rdouts,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,comp_mode_blu,comp_mode_red,chop_start,chop_def));
    //Use SPECTRO virtual aperture
    string ib = "P01_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            WriteOBSID($OBSID);
            data_rate(120.0);
        } else {
            if(state[0] == 3) {
                //     
                Pacs_OBCP_chop_scan_phot(nb_up_down,nb_rdouts,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,comp_mode_blu,comp_mode_red,chop_start,chop_def);
            } else {
                if(state[0] == 5) {
                    data_rate(0.0);
                    WriteEndID();
                }
            }
        }
    }
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : SWOF Grat
//
// CUS author    : Pierre Royer
//
// Version       : 2.0
//
// History       : 1.0 29-Jul-2007
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_Gra_IST_SWOF {
    /* Needed variables to call PacsEng_Spec_Gra_IST_SWOF                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_SWOF                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_IST_SWOF()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_IST_SWOF();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_SFT_Cooler {
    /* No variables to call PacsEng_Phot_SFT_Cooler                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_SFT_Cooler                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_SFT_Cooler()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_SFT_Cooler();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : FM ILT
//
// Purpose	 : Move chopper in open-loop mode
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : This building block moves the chopper while in open-loop
//                 mode. The parameters are assumed in ROU representing
//                 current settings that are directly sent to the chopper. 
//                  
// Dependencies  :  
//
// Preconditions : PACS switched-on, chopper is switched on, enabled and in
//                 open-loop mode
//                 
// Comments	 : 
//
// Version	 : 1.0	
// 
// History 	 : 1.0 08-03-07 creation by MN
// Begin Mode description
block PACS_SPEC_Chopper_OpenLoop_MoveRel_BB PACS 433 {
    int chop_pos = 0;
}{
    // Get BBID from environment
    int myBBID = $BBID;
    // Send BBID to DMC
    WriteBBID(myBBID);
    // Moving chopper
    debug_print("Commanding chopper movement of " + chop_pos);
    Pacs_DMC_MOVE_CHOP_REL(chop_pos);
    // Mark End of Block
    WriteEndBB();
}

// CVS comments  : $Id: 
// Purpose       : 
// 
// CUS author    : Original DAC , modified VD
// Script file   : Pacs_SPEC_aot_prologue.txt 
//
// Input arguments
// Type                     Name          Description
// bool                     verbose       Debug_print or not 
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECblu   BLUE SPU parameters
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECred   RED  SPU parameters
// {int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int}[]  confOBCP      OBCP parameters
//  bool                    doPROLOG      Perform/don't AOT prologue
//  double []               keyWAVE       One or several key wavelengths
//  int                     filter        Where to move FltW (as order)
//
// Return values
// Type     Name         Description
//
// Description   : Perform AOT prologue
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 03-sep-2009 1.0 VD 
//  
//                                 
//
int[] procedure Pacs_SPEC_aot_prologue {
    /* verbose debug print                          */
    bool verbose = false;
    /* SPEC parameters for BLU and RED              */
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,64,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,64,0,0,0,0,0,0,0}];
    /* OBCP parameters                               */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* Perform/don't AOT prologue                    */
    /* Where to leave FltW (as order)                */
    int filter = 2;
}{
    // Debug only
    if(verbose) {
        debug_print("PacsSpecSlew called with:");
        debug_print("confSPECblu: " + confSPECblu[0]);
        debug_print("confOBCP: " + confOBCP[0]);
        debug_print("filter: " + filter);
    }
    // Array to collect OBCP times per line
    // NOTE: time variables in units of either number of ramps (SPEC) or
    // number of readouts (BOLO) or plain seconds. The calling program 
    // must convert, if applicable, this information into actual duration 
    // in true time units [seconds].
    // SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky), CAL source, 
    // and overheads (wait for something). Total duration is given by duree_num. 
    // If no error, this duration must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    int[][] dureeCalKey = [[0,0,0,0,0]];
    // Long sequence to "unpack" default values from tuples
    int capa_blu = confSPECblu[0]{0};
    int nb_rdouts_ramp_blu = confSPECblu[0]{1};
    int nb_rdouts_subramp_blu = confSPECblu[0]{2};
    int comp_mode_blu = confSPECblu[0]{3};
    int glitch_det_blu = confSPECblu[0]{4};
    int ramp_fit_alg_blu = confSPECblu[0]{5};
    int nb_raw_blu = confSPECblu[0]{6};
    int bias_r_blu_mV = confSPECblu[0]{7};
    int bias_d_blu_mV = confSPECblu[0]{8};
    int capa_red = confSPECred[0]{0};
    int nb_rdouts_ramp_red = confSPECred[0]{1};
    int nb_rdouts_subramp_red = confSPECred[0]{2};
    int comp_mode_red = confSPECred[0]{3};
    int glitch_det_red = confSPECred[0]{4};
    int ramp_fit_alg_red = confSPECred[0]{5};
    int nb_raw_red = confSPECred[0]{6};
    int bias_r_red_mV = confSPECred[0]{7};
    int bias_d_red_mV = confSPECred[0]{8};
    int detector = confOBCP[0]{18};
    int filterPOS = confOBCP[0]{19};
    // Bias voltages (needed by SPEC_aot_prologue) are commanded in (double) volts
    double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
    double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
    double bias_r_red = double(bias_r_red_mV) / 1000.0;
    double bias_d_red = double(bias_d_red_mV) / 1000.0;
    if(verbose) {
        debug_print("confSPEC: capa_blu: " + capa_blu);
        debug_print("confSPEC: nb_rdouts_ramp_blu: " + nb_rdouts_ramp_blu);
        debug_print("confSPEC: nb_rdouts_subramp_blu: " + nb_rdouts_subramp_blu);
        debug_print("confSPEC: comp_mode_blu: " + comp_mode_blu);
        debug_print("confSPEC: glitch_det_blu: " + glitch_det_blu);
        debug_print("confSPEC: ramp_fit_alg_blu: " + ramp_fit_alg_blu);
        debug_print("confSPEC: nb_raw_blu: " + nb_raw_blu);
        debug_print("confSPEC: bias_r_blu_mV: " + bias_r_blu_mV);
        debug_print("confSPEC: bias_d_blu_mV: " + bias_d_blu_mV);
    }
    // Issue SPEC_aot_prologue
    totalDUREE = SPEC_aot_prologue(nb_rdouts_ramp_red,nb_rdouts_ramp_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,comp_mode_blu,comp_mode_red,nb_rdouts_subramp_blu,nb_rdouts_subramp_red,nb_raw_blu,nb_raw_red,glitch_det_red,ramp_fit_alg_red,filter,verbose);
    // no need to set the filter in position
    if(verbose) {
        debug_print("***** PHOT AOT prologue (switch on science data) requires " + totalDUREE[0] + " [sec]");
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return totalDUREE;
}

// CVS comments  : $Id: 
// Purpose       : Invoke a PACS calibration OBCP during slew to source
// 		   using ABBA hopper;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsSpecSlewCal35.txt 
//
// Input arguments
// Type                     Name          Description
// bool                     verbose       Debug_print or not 
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECblu   BLUE SPU parameters
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECred   RED  SPU parameters
// {int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int}[]  confOBCP      OBCP parameters
//  bool                    doPROLOG      Perform/don't AOT prologue
//  double []               keyWAVE       One or several key wavelengths
//  int                     filter        Where to move FltW (as order)
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per key line
//
// Description   : Perform AOT prologue and then OBCP #35.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 0.1 DAC 10-may-2006 
// 		 : 1.0 13-mar-2009 VD OBCP35
//
int[][] procedure PacsSpecSlewCal35 {
    /* verbose debug print                          */
    bool verbose = false;
    /* SPEC parameters for BLU and RED              */
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,64,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,64,0,0,0,0,0,0,0}];
    /* OBCP parameters                               */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* Perform/don't AOT prologue                    */
    bool doPROLOG = true;
    /* One or several key wavelengths                */
    double[] keyWAVE = [62.5];
    /* Where to leave FltW (as order)                */
    int filter = 2;
    /* Where to leave grating at end of CAL          */
    int frstLstGratPos = 535000;
    /* User defined grating order                    */
    string orderSel = "order3";
}{
    // Array to collect OBCP times per line
    // NOTE: time variables in units of either number of ramps (SPEC) or
    // number of readouts (BOLO) or plain seconds. The calling program 
    // must convert, if applicable, this information into actual duration 
    // in true time units [seconds].
    // SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky), CAL source, 
    // and overheads (wait for something). Total duration is given by duree_num. 
    // If no error, this duration must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    int[][] dureeCalKey = [[0,0,0,0,0]];
    // Long sequence to "unpack" default values from tuples
    int capa_blu = confSPECblu[0]{0};
    int nb_rdouts_ramp_blu = confSPECblu[0]{1};
    int nb_rdouts_subramp_blu = confSPECblu[0]{2};
    int comp_mode_blu = confSPECblu[0]{3};
    int glitch_det_blu = confSPECblu[0]{4};
    int ramp_fit_alg_blu = confSPECblu[0]{5};
    int nb_raw_blu = confSPECblu[0]{6};
    int bias_r_blu_mV = confSPECblu[0]{7};
    int bias_d_blu_mV = confSPECblu[0]{8};
    int capa_red = confSPECred[0]{0};
    int nb_rdouts_ramp_red = confSPECred[0]{1};
    int nb_rdouts_subramp_red = confSPECred[0]{2};
    int comp_mode_red = confSPECred[0]{3};
    int glitch_det_red = confSPECred[0]{4};
    int ramp_fit_alg_red = confSPECred[0]{5};
    int nb_raw_red = confSPECred[0]{6};
    int bias_r_red_mV = confSPECred[0]{7};
    int bias_d_red_mV = confSPECred[0]{8};
    int nb_up_down = confOBCP[0]{0};
    int grat_step_up = confOBCP[0]{1};
    int grat_step_dn = confOBCP[0]{2};
    int nb_SRC_OFF = confOBCP[0]{3};
    int nb_ramps_plateau = confOBCP[0]{4};
    int nb_CS1_CS2 = confOBCP[0]{5};
    int nb_grat_step_up = confOBCP[0]{6};
    int nb_grat_step_dn = confOBCP[0]{7};
    int grat_start_pos = confOBCP[0]{8};
    int grat_start_time = confOBCP[0]{9};
    int grat_def_pos = confOBCP[0]{10};
    int grat_def_time = confOBCP[0]{11};
    int chop_pos_SRC = confOBCP[0]{12};
    int chop_pos_REF1 = confOBCP[0]{13};
    int chop_pos_REF2 = confOBCP[0]{14};
    int chop_pos_CS1 = confOBCP[0]{15};
    int chop_pos_CS2 = confOBCP[0]{16};
    int chop_def = confOBCP[0]{17};
    int detector = confOBCP[0]{18};
    int filterPOS = confOBCP[0]{19};
    // Bias voltages (needed by SPEC_aot_prologue) are commanded in (double) volts
    double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
    double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
    double bias_r_red = double(bias_r_red_mV) / 1000.0;
    double bias_d_red = double(bias_d_red_mV) / 1000.0;
    if(verbose) {
        debug_print("confSPEC: capa_blu" + capa_blu);
        debug_print("confSPEC: nb_rdouts_ramp_blu" + nb_rdouts_ramp_blu);
        debug_print("confSPEC: nb_rdouts_subramp_blu" + nb_rdouts_subramp_blu);
        debug_print("confSPEC: comp_mode_blu" + comp_mode_blu);
        debug_print("confSPEC: glitch_det_blu" + glitch_det_blu);
        debug_print("confSPEC: ramp_fit_alg_blu" + ramp_fit_alg_blu);
        debug_print("confSPEC: nb_raw_blu" + nb_raw_blu);
        debug_print("confSPEC: bias_r_blu_mV" + bias_r_blu_mV);
        debug_print("confSPEC: bias_d_blu_mV" + bias_d_blu_mV);
    }
    // Issue SPEC_aot_prologue if demanded
    if(doPROLOG) {
        totalDUREE = SPEC_aot_prologue(nb_rdouts_ramp_red,nb_rdouts_ramp_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,comp_mode_blu,comp_mode_red,nb_rdouts_subramp_blu,nb_rdouts_subramp_red,nb_raw_blu,nb_raw_red,glitch_det_red,ramp_fit_alg_red,filter,verbose);
    }
    // NOTE: Grating starts at grat_start_pos determined by SPEC_get_grat. At end of
    // SlewCal grating should park. Park position is generally grat_def_pos:
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // AOT_prologue is supposed to have left grating at park position
    grat_def_pos = grat_park;
    // NOTE for version 1.0 and later. Upon execution of SpecSlew, grating is
    //      indeed where SPEC_orbit_prologue left it (the default park position);
    //      this fact remains unchanged. What is new is that SpecSlew will leave
    //      the grating not at the default park position but already at the
    //      position needed by the 1st line that will be observed. There are two
    //      advantages:
    //      1- the new logic in the OBCP incurs in less grating movements when
    //         the OBCP is repeated within a NOD or the next raster point, and
    //      2- the detector will see the illumination corresponding to the line
    //         wavelength before the actual observation starts.
    // Observe now each key wavelength
    int nbKEY = length(keyWAVE);
    {double,int,int,int,int}[] gratTuple = [{0.0,0,0,0,0}];
    for(int loopKEY = 0 .. nbKEY - 1) {
        //     We may perform the loop starting with high ORDER
        int keyWaveLoop1 = nbKEY - 1 - loopKEY;
        // or not....
        keyWaveLoop1 = loopKEY;
        //       
        //     Get grating start position (CAL is performeed with HI resolution)
        //     (frequency switch boolean is set to false)
        bool switching = false;
        string extraConf = "normal";
        //      Seek K rows in CAL-U, i.e. key wavelength parameters	
        gratTuple[keyWaveLoop1] = SPEC_get_grat_info(keyWAVE[keyWaveLoop1],"KHI",switching,extraConf,orderSel,verbose);
        //      Issue now OBCP#35 for each of the given key wavelengths
        int order = gratTuple[keyWaveLoop1]{1};
        grat_start_pos = gratTuple[keyWaveLoop1]{2};
        int nb_grat_steps = gratTuple[keyWaveLoop1]{3};
        nb_grat_step_up = nb_grat_steps;
        nb_grat_step_dn = nb_grat_steps;
        int grat_step_up_fine = gratTuple[keyWaveLoop1]{4};
        int grat_step_dn_fine = -grat_step_up_fine;
        //      Table OBCP35_Calparams is indexed by order
        string key = "" + order;
        //        string calU = "OBCP35_Calparams";
        string calU = "OBCP35params";
        nb_up_down = ilookup(calU,key,"nb_up_down");
        nb_CS1_CS2 = ilookup(calU,key,"nb_CS1_CS2");
        // SRC_OFF == 0;
        nb_SRC_OFF = ilookup(calU,key,"nb_SRC_OFF");
        int chop_pos_OFF = chop_pos_REF2;
        nb_ramps_plateau = ilookup(calU,key,"nb_ramps_plateau");
        int grat_step_coarse = 0;
        //      Lookup chopper CS1 and CS2 positions
        calU = "CHOPPERCSparams";
        chop_pos_CS1 = ilookup(calU,"SPEC","pos_CS1");
        chop_pos_CS2 = ilookup(calU,"SPEC","pos_CS2");
        int nb_rdouts_ramp = nb_rdouts_ramp_red;
        //     Grating logic (OBCP is up/down ==> grating ends where it started)
        //     Leave the grating where it is, i.e. end-of-DMC value
        int new_grat_def_pos = grat_start_pos;
        //     But the last line should leave grating at frstLstGratPos
        if(keyWaveLoop1 == nbKEY - 1) {
            new_grat_def_pos = frstLstGratPos;
        }
        //     Number of steps to start position for current line
        int steps_start = grat_def_pos - grat_start_pos;
        int grat_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("OBCPcal:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_time);
        }
        //
        int steps_end = grat_start_pos - new_grat_def_pos;
        grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("OBCPcal:GratEnd from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
        }
        int[] dureeOBCP = OBCP_grat_line_scan_chop_3_cal(nb_up_down,nb_grat_step_up,grat_step_up_fine,nb_SRC_OFF,chop_pos_SRC,nb_ramps_plateau,chop_pos_OFF,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_dn_fine,detector,grat_start_pos,grat_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
        // int[] dureeOBCP = OBCP_chop_grat_scan_cal(nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,grat_step_dn_fine,detector,grat_start_pos,grat_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp);
        if(verbose) {
            debug_print("SlewCal performed KeyWave: " + keyWAVE[keyWaveLoop1] + " [mic] requires " + dureeOBCP[0] + " [sec]");
        }
        //     Update dureeCalKey
        dureeCalKey[keyWaveLoop1] = [0,0,0,0,0];
        for(int loop1 = 0 .. 4) {
            dureeCalKey[keyWaveLoop1][loop1] = dureeOBCP[loop1];
        }
        //     Prepare the grating to be ready for the next wavelength
        grat_def_pos = new_grat_def_pos;
    }
    // Add after the KeyWaves in dureeCalKey the duration from AOT_prologue
    dureeCalKey[nbKEY] = [0,0,0,0,0];
    dureeCalKey[nbKEY][4] = totalDUREE[4];
    if(verbose) {
        debug_print("End SlewCal with dureeCalKey: " + dureeCalKey);
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return dureeCalKey;
}

// Mission phase : PV Phase
//
// Purpose : PCD req.1.1.1bis for the PV Phase
//           Measure the responsivity with a 4x9 raster on a point source
//           and the noise on a off pointing position. An offset in -Y allows to
//           measure the noise during the last 4 pointings.
//
// Author : Koryo Okumura
//
// Version : Wed Jul 29 04:26:18 EDT 2009
//
// CUS script : procedure Phot_highGainBiasDDCS
//
// Argument :
//   string select = "ginit" in ["ginit","g2_0","g2_6","g3_0","binit","b2_0","b2_6","b3_0","final"]; // Select a configuration or initialize or finalize
//   string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   According to "select" set the photometer in a configuration before a raster
//   - ginit or binit :
//     + Set a filter corresponding to the given "selection"
//     + Set the biases group by group
//     + Set the chopper on the optical center
//   - in general :
//     + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group corresponding to the selected bias
//     + Do a raster measurement by the calling obs script PacsCal_Phot_highGainBiasDDCS_Fix or PacsCal_Phot_highGainBiasDDCS
//   - final :
//     + The biases are set following a given bias table
//
// Dependencies : Commissioning and PV data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_highGainBias(0, "HIGH")
//
procedure Phot_highGainBiasDDCS {
    string select = "ginit" in ["ginit","g2_0","g2_6","g3_0","binit","b2_0","b2_6","b3_0","final"]; // Sequence number to define a configuration
    string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
}{
    if(select == "ginit") {
        //
        //*******************************
        // Select Filter A (100 microns)
        //*******************************
        //
        PHOT_fltw_move("POS A");
        //
        //*************************************************
        // Set the biases and start SPU, then set the gain
        //*************************************************
        //
        PHOT_change_biases(startBiasTable,"DDCS","HIGH");
        //
        //**********************************************
        // Set the PACS chopper at the position 664
        //**********************************************
        //
        Pacs_DMC_MOVE_CHOP_ABS(664);
        //
        //**********************************************************************
        //                       Measurement
        // Background fluxes 0.90pW on green and 4.00pW on red
        //**********************************************************************
        //
        // sync the bus
        sync();
    }
    if(select == "g2_0") {
        //***********************************************************
        // Bias 1 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.4 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.7072552504837253 Volts
        Pacs_BOLC_SET_VH_G1(1.7072552504837253);
        // Set group 1 bol bias 02 (VL) to -0.2927447495162747 Volts
        Pacs_BOLC_SET_VL_G1(-0.2927447495162747);
        // Set group 1 bol bias 03 (VRL) to 0.39300694397919855 Volts
        Pacs_BOLC_SET_VRL_G1(0.39300694397919855);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9767874572233488 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9767874572233488);
        // Set group 2 bol bias 01 (VH) to 1.692663076962388 Volts
        Pacs_BOLC_SET_VH_G2(1.692663076962388);
        // Set group 2 bol bias 02 (VL) to -0.30733692303761195 Volts
        Pacs_BOLC_SET_VL_G2(-0.30733692303761195);
        // Set group 2 bol bias 03 (VRL) to 0.3887091184811946 Volts
        Pacs_BOLC_SET_VRL_G2(0.3887091184811946);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9720936424409112 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9720936424409112);
        // Set group 3 bol bias 01 (VH) to 1.704185527633064 Volts
        Pacs_BOLC_SET_VH_G3(1.704185527633064);
        // Set group 3 bol bias 02 (VL) to -0.295814472366936 Volts
        Pacs_BOLC_SET_VL_G3(-0.295814472366936);
        // Set group 3 bol bias 03 (VRL) to 0.4014500719789626 Volts
        Pacs_BOLC_SET_VRL_G3(0.4014500719789626);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9633466285199563 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9633466285199563);
        // Set group 4 bol bias 01 (VH) to 1.7140968369777032 Volts
        Pacs_BOLC_SET_VH_G4(1.7140968369777032);
        // Set group 4 bol bias 02 (VL) to -0.2859031630222967 Volts
        Pacs_BOLC_SET_VL_G4(-0.2859031630222967);
        // Set group 4 bol bias 03 (VRL) to 0.3891942580835225 Volts
        Pacs_BOLC_SET_VRL_G4(0.3891942580835225);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9960505441377652 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9960505441377652);
        // Set group 5 bol bias 01 (VH) to 1.2990548950746752 Volts
        Pacs_BOLC_SET_VH_G5(1.2990548950746752);
        // Set group 5 bol bias 02 (VL) to -0.1009451049253246 Volts
        Pacs_BOLC_SET_VL_G5(-0.1009451049253246);
        // Set group 5 bol bias 03 (VRL) to 0.42253767898766403 Volts
        Pacs_BOLC_SET_VRL_G5(0.42253767898766403);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.073112590654842 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.073112590654842);
        // Set group 6 bol bias 01 (VH) to 1.3235509250997841 Volts
        Pacs_BOLC_SET_VH_G6(1.3235509250997841);
        // Set group 6 bol bias 02 (VL) to -0.07644907490021571 Volts
        Pacs_BOLC_SET_VL_G6(-0.07644907490021571);
        // Set group 6 bol bias 03 (VRL) to 0.4356120279464395 Volts
        Pacs_BOLC_SET_VRL_G6(0.4356120279464395);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0115879408988957 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0115879408988957);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g2_6") {
        //***********************************************************
        // Bias 2 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.1861805706356843 Volts
        Pacs_BOLC_SET_VH_G1(2.1861805706356843);
        // Set group 1 bol bias 02 (VL) to -0.413819429364316 Volts
        Pacs_BOLC_SET_VL_G1(-0.413819429364316);
        // Set group 1 bol bias 03 (VRL) to 0.4136977781342747 Volts
        Pacs_BOLC_SET_VRL_G1(0.4136977781342747);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0194569613465028 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.0194569613465028);
        // Set group 2 bol bias 01 (VH) to 2.135466372433529 Volts
        Pacs_BOLC_SET_VH_G2(2.135466372433529);
        // Set group 2 bol bias 02 (VL) to -0.46453362756647104 Volts
        Pacs_BOLC_SET_VL_G2(-0.46453362756647104);
        // Set group 2 bol bias 03 (VRL) to 0.38559250810266327 Volts
        Pacs_BOLC_SET_VRL_G2(0.38559250810266327);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9690127608204688 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9690127608204688);
        // Set group 3 bol bias 01 (VH) to 2.1595315777041786 Volts
        Pacs_BOLC_SET_VH_G3(2.1595315777041786);
        // Set group 3 bol bias 02 (VL) to -0.4404684222958214 Volts
        Pacs_BOLC_SET_VL_G3(-0.4404684222958214);
        // Set group 3 bol bias 03 (VRL) to 0.41334124907167524 Volts
        Pacs_BOLC_SET_VRL_G3(0.41334124907167524);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9973275250137286 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9973275250137286);
        // Set group 4 bol bias 01 (VH) to 2.170304299964091 Volts
        Pacs_BOLC_SET_VH_G4(2.170304299964091);
        // Set group 4 bol bias 02 (VL) to -0.42969570003590896 Volts
        Pacs_BOLC_SET_VL_G4(-0.42969570003590896);
        // Set group 4 bol bias 03 (VRL) to 0.39229709106193544 Volts
        Pacs_BOLC_SET_VRL_G4(0.39229709106193544);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9991388331630189 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9991388331630189);
        // Set group 5 bol bias 01 (VH) to 1.6865030568375055 Volts
        Pacs_BOLC_SET_VH_G5(1.6865030568375055);
        // Set group 5 bol bias 02 (VL) to -0.31349694316249443 Volts
        Pacs_BOLC_SET_VL_G5(-0.31349694316249443);
        // Set group 5 bol bias 03 (VRL) to 0.4169290649049042 Volts
        Pacs_BOLC_SET_VRL_G5(0.4169290649049042);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0452487710114853 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0452487710114853);
        // Set group 6 bol bias 01 (VH) to 1.7152182740372384 Volts
        Pacs_BOLC_SET_VH_G6(1.7152182740372384);
        // Set group 6 bol bias 02 (VL) to -0.2847817259627615 Volts
        Pacs_BOLC_SET_VL_G6(-0.2847817259627615);
        // Set group 6 bol bias 03 (VRL) to 0.4289846398856858 Volts
        Pacs_BOLC_SET_VRL_G6(0.4289846398856858);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0049545211149127 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0049545211149127);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "g3_0") {
        //***********************************************************
        // Bias 3 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.600397057706278 Volts
        Pacs_BOLC_SET_VH_G1(2.600397057706278);
        // Set group 1 bol bias 02 (VL) to -0.3996029422937219 Volts
        Pacs_BOLC_SET_VL_G1(-0.3996029422937219);
        // Set group 1 bol bias 03 (VRL) to 0.4352373155819225 Volts
        Pacs_BOLC_SET_VRL_G1(0.4352373155819225);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.996478815796946 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.996478815796946);
        // Set group 2 bol bias 01 (VH) to 2.514934658647339 Volts
        Pacs_BOLC_SET_VH_G2(2.514934658647339);
        // Set group 2 bol bias 02 (VL) to -0.485065341352661 Volts
        Pacs_BOLC_SET_VL_G2(-0.485065341352661);
        // Set group 2 bol bias 03 (VRL) to 0.39192545859088324 Volts
        Pacs_BOLC_SET_VRL_G2(0.39192545859088324);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9974948822002625 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9974948822002625);
        // Set group 3 bol bias 01 (VH) to 2.537533329053119 Volts
        Pacs_BOLC_SET_VH_G3(2.537533329053119);
        // Set group 3 bol bias 02 (VL) to -0.4624666709468811 Volts
        Pacs_BOLC_SET_VL_G3(-0.4624666709468811);
        // Set group 3 bol bias 03 (VRL) to 0.4110505916239857 Volts
        Pacs_BOLC_SET_VRL_G3(0.4110505916239857);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9950632305477918 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9950632305477918);
        // Set group 4 bol bias 01 (VH) to 2.5528988845382643 Volts
        Pacs_BOLC_SET_VH_G4(2.5528988845382643);
        // Set group 4 bol bias 02 (VL) to -0.4471011154617358 Volts
        Pacs_BOLC_SET_VL_G4(-0.4471011154617358);
        // Set group 4 bol bias 03 (VRL) to 0.39332244377654313 Volts
        Pacs_BOLC_SET_VRL_G4(0.39332244377654313);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.97793711182537 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.97793711182537);
        // Set group 5 bol bias 01 (VH) to 1.9800777632387063 Volts
        Pacs_BOLC_SET_VH_G5(1.9800777632387063);
        // Set group 5 bol bias 02 (VL) to -0.4199222367612936 Volts
        Pacs_BOLC_SET_VL_G5(-0.4199222367612936);
        // Set group 5 bol bias 03 (VRL) to 0.40944012382521133 Volts
        Pacs_BOLC_SET_VRL_G5(0.40944012382521133);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0377115768798726 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0377115768798726);
        // Set group 6 bol bias 01 (VH) to 2.01513172113205 Volts
        Pacs_BOLC_SET_VH_G6(2.01513172113205);
        // Set group 6 bol bias 02 (VL) to -0.38486827886795016 Volts
        Pacs_BOLC_SET_VL_G6(-0.38486827886795016);
        // Set group 6 bol bias 03 (VRL) to 0.4236192556113485 Volts
        Pacs_BOLC_SET_VRL_G6(0.4236192556113485);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.9995863630649058 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.9995863630649058);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "binit") {
        //*******************************
        // Select Filter B (70 microns)
        //*******************************
        //
        PHOT_fltw_move("POS B");
        //
        //*************************************************
        // Set the biases and start SPU, then set the gain
        //*************************************************
        //
        PHOT_change_biases(startBiasTable,"DDCS","HIGH");
        //
        //**********************************************
        // Set the PACS chopper at the position 664
        //**********************************************
        //
        Pacs_DMC_MOVE_CHOP_ABS(664);
        //
        //**********************************************************************
        //                       Measurement
        // Background fluxes 1.02pW on blue and 4.00pW on red
        //**********************************************************************
        //
        // sync the bus
        sync();
    }
    if(select == "b2_0") {
        //***********************************************************
        // Bias 1 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.4 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.7072552504837253 Volts
        Pacs_BOLC_SET_VH_G1(1.7072552504837253);
        // Set group 1 bol bias 02 (VL) to -0.2927447495162747 Volts
        Pacs_BOLC_SET_VL_G1(-0.2927447495162747);
        // Set group 1 bol bias 03 (VRL) to 0.39300694397919855 Volts
        Pacs_BOLC_SET_VRL_G1(0.39300694397919855);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.9767874572233488 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.9767874572233488);
        // Set group 2 bol bias 01 (VH) to 1.692663076962388 Volts
        Pacs_BOLC_SET_VH_G2(1.692663076962388);
        // Set group 2 bol bias 02 (VL) to -0.30733692303761195 Volts
        Pacs_BOLC_SET_VL_G2(-0.30733692303761195);
        // Set group 2 bol bias 03 (VRL) to 0.3887091184811946 Volts
        Pacs_BOLC_SET_VRL_G2(0.3887091184811946);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9720936424409112 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9720936424409112);
        // Set group 3 bol bias 01 (VH) to 1.704185527633064 Volts
        Pacs_BOLC_SET_VH_G3(1.704185527633064);
        // Set group 3 bol bias 02 (VL) to -0.295814472366936 Volts
        Pacs_BOLC_SET_VL_G3(-0.295814472366936);
        // Set group 3 bol bias 03 (VRL) to 0.4014500719789626 Volts
        Pacs_BOLC_SET_VRL_G3(0.4014500719789626);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9633466285199563 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9633466285199563);
        // Set group 4 bol bias 01 (VH) to 1.7140968369777032 Volts
        Pacs_BOLC_SET_VH_G4(1.7140968369777032);
        // Set group 4 bol bias 02 (VL) to -0.2859031630222967 Volts
        Pacs_BOLC_SET_VL_G4(-0.2859031630222967);
        // Set group 4 bol bias 03 (VRL) to 0.3891942580835225 Volts
        Pacs_BOLC_SET_VRL_G4(0.3891942580835225);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9960505441377652 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9960505441377652);
        // Set group 5 bol bias 01 (VH) to 1.2990548950746752 Volts
        Pacs_BOLC_SET_VH_G5(1.2990548950746752);
        // Set group 5 bol bias 02 (VL) to -0.1009451049253246 Volts
        Pacs_BOLC_SET_VL_G5(-0.1009451049253246);
        // Set group 5 bol bias 03 (VRL) to 0.42253767898766403 Volts
        Pacs_BOLC_SET_VRL_G5(0.42253767898766403);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.073112590654842 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.073112590654842);
        // Set group 6 bol bias 01 (VH) to 1.3235509250997841 Volts
        Pacs_BOLC_SET_VH_G6(1.3235509250997841);
        // Set group 6 bol bias 02 (VL) to -0.07644907490021571 Volts
        Pacs_BOLC_SET_VL_G6(-0.07644907490021571);
        // Set group 6 bol bias 03 (VRL) to 0.4356120279464395 Volts
        Pacs_BOLC_SET_VRL_G6(0.4356120279464395);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0115879408988957 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0115879408988957);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b2_6") {
        //***********************************************************
        // Bias 2 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.1861805706356843 Volts
        Pacs_BOLC_SET_VH_G1(2.1861805706356843);
        // Set group 1 bol bias 02 (VL) to -0.413819429364316 Volts
        Pacs_BOLC_SET_VL_G1(-0.413819429364316);
        // Set group 1 bol bias 03 (VRL) to 0.4136977781342747 Volts
        Pacs_BOLC_SET_VRL_G1(0.4136977781342747);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0194569613465028 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(2.0194569613465028);
        // Set group 2 bol bias 01 (VH) to 2.135466372433529 Volts
        Pacs_BOLC_SET_VH_G2(2.135466372433529);
        // Set group 2 bol bias 02 (VL) to -0.46453362756647104 Volts
        Pacs_BOLC_SET_VL_G2(-0.46453362756647104);
        // Set group 2 bol bias 03 (VRL) to 0.38559250810266327 Volts
        Pacs_BOLC_SET_VRL_G2(0.38559250810266327);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9690127608204688 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9690127608204688);
        // Set group 3 bol bias 01 (VH) to 2.1595315777041786 Volts
        Pacs_BOLC_SET_VH_G3(2.1595315777041786);
        // Set group 3 bol bias 02 (VL) to -0.4404684222958214 Volts
        Pacs_BOLC_SET_VL_G3(-0.4404684222958214);
        // Set group 3 bol bias 03 (VRL) to 0.41334124907167524 Volts
        Pacs_BOLC_SET_VRL_G3(0.41334124907167524);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9973275250137286 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9973275250137286);
        // Set group 4 bol bias 01 (VH) to 2.170304299964091 Volts
        Pacs_BOLC_SET_VH_G4(2.170304299964091);
        // Set group 4 bol bias 02 (VL) to -0.42969570003590896 Volts
        Pacs_BOLC_SET_VL_G4(-0.42969570003590896);
        // Set group 4 bol bias 03 (VRL) to 0.39229709106193544 Volts
        Pacs_BOLC_SET_VRL_G4(0.39229709106193544);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.9991388331630189 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.9991388331630189);
        // Set group 5 bol bias 01 (VH) to 1.6865030568375055 Volts
        Pacs_BOLC_SET_VH_G5(1.6865030568375055);
        // Set group 5 bol bias 02 (VL) to -0.31349694316249443 Volts
        Pacs_BOLC_SET_VL_G5(-0.31349694316249443);
        // Set group 5 bol bias 03 (VRL) to 0.4169290649049042 Volts
        Pacs_BOLC_SET_VRL_G5(0.4169290649049042);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0452487710114853 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0452487710114853);
        // Set group 6 bol bias 01 (VH) to 1.7152182740372384 Volts
        Pacs_BOLC_SET_VH_G6(1.7152182740372384);
        // Set group 6 bol bias 02 (VL) to -0.2847817259627615 Volts
        Pacs_BOLC_SET_VL_G6(-0.2847817259627615);
        // Set group 6 bol bias 03 (VRL) to 0.4289846398856858 Volts
        Pacs_BOLC_SET_VRL_G6(0.4289846398856858);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.0049545211149127 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(2.0049545211149127);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "b3_0") {
        //***********************************************************
        // Bias 3 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.600397057706278 Volts
        Pacs_BOLC_SET_VH_G1(2.600397057706278);
        // Set group 1 bol bias 02 (VL) to -0.3996029422937219 Volts
        Pacs_BOLC_SET_VL_G1(-0.3996029422937219);
        // Set group 1 bol bias 03 (VRL) to 0.4352373155819225 Volts
        Pacs_BOLC_SET_VRL_G1(0.4352373155819225);
        // Set group 1 bol bias 20 (VH_BLIND) to 1.996478815796946 Volts
        Pacs_BOLC_SET_VH_BLIND_G1(1.996478815796946);
        // Set group 2 bol bias 01 (VH) to 2.514934658647339 Volts
        Pacs_BOLC_SET_VH_G2(2.514934658647339);
        // Set group 2 bol bias 02 (VL) to -0.485065341352661 Volts
        Pacs_BOLC_SET_VL_G2(-0.485065341352661);
        // Set group 2 bol bias 03 (VRL) to 0.39192545859088324 Volts
        Pacs_BOLC_SET_VRL_G2(0.39192545859088324);
        // Set group 2 bol bias 20 (VH_BLIND) to 1.9974948822002625 Volts
        Pacs_BOLC_SET_VH_BLIND_G2(1.9974948822002625);
        // Set group 3 bol bias 01 (VH) to 2.537533329053119 Volts
        Pacs_BOLC_SET_VH_G3(2.537533329053119);
        // Set group 3 bol bias 02 (VL) to -0.4624666709468811 Volts
        Pacs_BOLC_SET_VL_G3(-0.4624666709468811);
        // Set group 3 bol bias 03 (VRL) to 0.4110505916239857 Volts
        Pacs_BOLC_SET_VRL_G3(0.4110505916239857);
        // Set group 3 bol bias 20 (VH_BLIND) to 1.9950632305477918 Volts
        Pacs_BOLC_SET_VH_BLIND_G3(1.9950632305477918);
        // Set group 4 bol bias 01 (VH) to 2.5528988845382643 Volts
        Pacs_BOLC_SET_VH_G4(2.5528988845382643);
        // Set group 4 bol bias 02 (VL) to -0.4471011154617358 Volts
        Pacs_BOLC_SET_VL_G4(-0.4471011154617358);
        // Set group 4 bol bias 03 (VRL) to 0.39332244377654313 Volts
        Pacs_BOLC_SET_VRL_G4(0.39332244377654313);
        // Set group 4 bol bias 20 (VH_BLIND) to 1.97793711182537 Volts
        Pacs_BOLC_SET_VH_BLIND_G4(1.97793711182537);
        // Set group 5 bol bias 01 (VH) to 1.9800777632387063 Volts
        Pacs_BOLC_SET_VH_G5(1.9800777632387063);
        // Set group 5 bol bias 02 (VL) to -0.4199222367612936 Volts
        Pacs_BOLC_SET_VL_G5(-0.4199222367612936);
        // Set group 5 bol bias 03 (VRL) to 0.40944012382521133 Volts
        Pacs_BOLC_SET_VRL_G5(0.40944012382521133);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.0377115768798726 Volts
        Pacs_BOLC_SET_VH_BLIND_G5(2.0377115768798726);
        // Set group 6 bol bias 01 (VH) to 2.01513172113205 Volts
        Pacs_BOLC_SET_VH_G6(2.01513172113205);
        // Set group 6 bol bias 02 (VL) to -0.38486827886795016 Volts
        Pacs_BOLC_SET_VL_G6(-0.38486827886795016);
        // Set group 6 bol bias 03 (VRL) to 0.4236192556113485 Volts
        Pacs_BOLC_SET_VRL_G6(0.4236192556113485);
        // Set group 6 bol bias 20 (VH_BLIND) to 1.9995863630649058 Volts
        Pacs_BOLC_SET_VH_BLIND_G6(1.9995863630649058);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a raster
        //
        // sync the bus
        sync();
    }
    if(select == "final") {
        //********************************
        // Epilogue : Set the end biases
        //********************************
        PHOT_change_biases(endBiasTable,"DIRECT","LOW");
        //
        // sync the bus
        sync();
    }
}

// CVS comments  : $Id: PacsMessageCenter.txt,v 1.3 2007/04/25 15:14:04 dcesarsk Exp $ 
// Purpose       : 
//
// CUS author    : 
// Script file   : PacsMessageCenter.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1  2-Sep-2005 DAC
// 13-oct-2005 Try different HTML directives
procedure PacsMessageCenter {
    string who = "From where"; // who issues the message(s)
    int nbRows = 0; // number of rows
    string[] msgLine = ["Line1"]; // one line of text
}{
    // No empty messages!
    if(nbRows > 0) {
        message("<h2> " + who + " </h2>");
        //     message(" ");
        for(int rows = 0 .. nbRows - 1) {
            //        message("<p> " + msgLine[rows] + "</p>");
            message(msgLine[rows]);
        }
    }
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req.1.1.9 Measure time constants after cosmic ray impact
//
// Author : Koryo Okumura
//
// Version : May 26 2009
//
// CUS script : mode PacsCal_Phot_glitch
//
// Argument :
//   string biasTable = "BOLObias_standard_high"; // Bias table
//   string gain = "HIGH" in ["LOW","HIGH"]; // gain used during the measurements
//   int measureTime = 1200; // Measurement duration in seconds
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//   string calBiasTable = "BOLObias_standard_low"; // Bias table used during calibration blocks
//   string calGain = "NO_CHANGE" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description : OBS script to execute Phot_glitch
//
// Dependencies : None
//
// Comments : None
// Update :
//   2009-05-26 : The default gain is set to high
//
obs PacsCal_Phot_glitch {
    string biasTable = "BOLObias_standard_low"; // Bias table
    string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
    int measureTime = 1400; // Measurement duration in seconds
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    string calBiasTable = "BOLObias_standard_low"; // Bias table used during calibration blocks
    string calGain = "NO_CHANGE" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 16; // number of readouts per plateau
    bool verbose = true;
}{
    // Bus configuration for the Burst mode (7)
    busconfig (7);
    // Several arguments needed for "basic_fine_pointing"
    int nRdts = readouts_plateau - 1;
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    //int timeOBSID = imax(1, duration(WriteOBSID($OBSID))+ duration(data_rate(300.0)));
    //int timeEndID = imax(1, duration(data_rate(0.0))+ duration(WriteEndID()));
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = 0;
    int timeChgBias0 = duration(PHOT_change_biases(biasTable,"NO_CHANGE","NO_CHANGE"));
    int timeCal3CPR1 = duration(Pacs_OBCP_chopped_photometry2(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    //Minimum slew time
    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT","LOW"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT",calGain));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"LOW"));
    }
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
    }
    int tslewmin = timeOBSID + timeChgBias + timeCal3CPR1;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeChgBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_glitch(biasTable,gain,measureTime));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(300.0);
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            // No biases setting here because nothing changes
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //********************************
            //  Call the Phot_glitch
            //********************************
            Phot_glitch(biasTable,gain,measureTime);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// Missionphase  : 
//
// Purpose       : Stop data flow from one  (or both!) SPUs
//                  
// CUS script    : Diego A. Cesarsky
// CVS file      : SPEC_spu_channel_stop.txt
//
// Arguments     : 
//            bool stopSPUS  Stop the "Short" SPU
//            bool stopSPUL  Stop the "Long" SPU
//            bool verbose   Bla bla or not
//                 
// Description   : Stops he demanded SPU
//
// Dependencies  : Only low level PACS TCs 
//                 
// Comments      :
//
// Version       : 0.1 17-jun-2009 Creation by DAC
// History       : 0.1 17-jun-2009 1st version
//                 0.2 19-jun-2009 Improved comments
//               :
procedure SPEC_spu_channel_stop {
    bool stopSPUS = false; // Stop the "Short" SPU
    bool stopSPUL = false; // Stop the "Long" SPU
    bool verbose = true; // Bla bla or not
}{
    // Stop  the demanded SPUs
    if(stopSPUS) {
        Pacs_SPUS_STOP_REDUCT_COMPR();
        if(verbose) {
            debug_print("#### ACHTUNG!!! Stopping SPUS...");
        }
    }
    if(stopSPUL) {
        Pacs_SPUL_STOP_REDUCT_COMPR();
        if(verbose) {
            debug_print("#### ACHTUNG!!! Stopping SPUL...");
        }
    }
    // Leave bus scheduler in a known state
    sync();
}

// File          : PACS_Spec_FlashHeat_Diaghk_Setup.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Switch on diagnostic hk relevant to Flashers & Heaters
//
// Author        : P. Royer
//
// Arguments     :
//
// Description   : Flashers & Heaters diagnostic housekeeping ON
//               :
// Comments      : 
//                 
//
// Version       : 1.1
// History       : 1.0 / 07-Jul-2006 creation
//                     1.1 / 19-Nov-2008 Update parameter list according to fm_ist_cus_copy v2.0 (20080925)
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose Switch on diagnostic housekeeping relevant to Flashers & Heaters
// @comment - 
//
block PACS_Spec_FlashHeat_Diaghk_Setup PACS 173 {
    int diag_hk_period = 100; // 1: synch w/ BLUE DET  2: synch w/ RED DET  >4: period in ms   0: 1KHz (not to use w/ science)
}{
    // Register start of BB
    WriteBBID($BBID);
    // DMC_WRT_DIAG_HK_LIST
    // DMC_DATA_LENGTH            PP065420 contains the number of desired HK parameters
    // DMC_4_BYTES_WORDS_DATA     PP067420 contains the desired HK parameters' IDs
    // DMC_CHECKSUM               PP066420
    //
    // Max number of requested diag HK parameters = 16
    // (including the last one, which is always forced to the same value)
    //
    //	DMC_DECB_FLASH_C	315
    //	DMC_DECB_FLASH_V	316
    //	DMC_DECR_FLASH_C	383
    //	DMC_DECR_FLASH_V	384
    //	DMC_DECB_HEAT_C		281
    //	DMC_DECB_HEAT_V		282
    //	DMC_DECR_HEAT_C		349
    //	DMC_DECR_HEAT_V		350
    //               DMC_DECB_CR_ST_3	291 |
    //               DMC_DECB_CR_ST_4	325 |----- CRE Status parameters
    //               DMC_DECB_CR_ST_1	359 |
    //               DMC_DECB_CR_ST_2	393 |
    {int}[] list_tuple = [{315},{316},{383},{384},{281},{282},{349},{350},{291},{325},{359},{393},{0xffff}];
    int[] list_int = [315,316,383,384,281,282,349,350,291,325,359,393,0xffff];
    int chksum = checksum("int",list_int);
    int nbParams = length(list_int);
    Pacs_DMC_WRT_DIAG_HK_LIST(nbParams,list_tuple,chksum);
    delay(1);
    // DMC_START_DIAG_HK
    // DIAG_HK_PERIOD             PP076420
    // tcsend PC146420 [list PP076420 $diag_hk_period]
    // waittime $command_time
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    // End of procedure
    //------------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_HK_Setup {
    /* No variables to call PacsEng_Spec_HK_Setup                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_HK_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_HK_Setup()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_HK_Setup();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_CRE_Setup_Cold {
    /* No variables to call PacsEng_Spec_CRE_Setup_Cold                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_CRE_Setup_Cold                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_CRE_Setup_Cold()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_CRE_Setup_Cold();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Script file   : SPEC_dpu_dmc_setup.cus
// Missionphase  : 
//
// Purpose       : Prepare DPU and DMC for spectrometry
//
// TCL author    : N/A
// TCL file      : N/A
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : This script will set the DPU HK list, write and set the
//                 FPGA timing parameters (if necessary), sforward data
//                 to the packet encoder and validate the sciece data
//                  
// Dependencies  : 
//
// Preconditions :
//     
// Comments      : 
// 
// History       : 0.1  3-jul-2006 DAC; based on TM's list
//                 0.2 16-nov-2006 Reviewed for inclusion in OpDataBase;
//                                 Moved input argument to body
//                 1.0 15-jan-2008 Script renamed *txt for PV database, added
//                                 demanded TC as per SCR-0797  
//		   1.1 15-Jul-2008 new IA_CHOP address
procedure SPEC_dpu_dmc_setup {
}{
    // Set HK list
    string hk_list = "BOTH Array";
    Pacs_DPU_SET_HK_LIST("SPEC",hk_list);
    // Add chop_ia information as per SCR-0797 
    // Description of DMC_WRT_DIAG_HK_CONF_TAB from DEC/MEC User Manual:
    //
    // Custom Hk Configuration Table : This buffer contains configuration data
    // allowing us to increase the number of available HK measure without 
    // recompiling the application. The table is composed of 10 entries each of 
    // them being 5 words long :
    //1. the address of the memory area to monitor
    //    int f1 = 0x3469f;
    int f1 = 0x346ab;
    //2. the size (in words) of the memory area to monitor
    int f2 = 0x1;
    //3. the size (in bytes) of the memory area to monitor
    int f3 = 0x2;
    //4. a pointer to a function performing the monitoring (if you want to use this
    //   field, it is highly probable that you need to patch your code anyway to 
    //   upload the new monitoring function).
    int f4 = 0x0;
    //5. the validity at startup (0 = invalid, 1 = valid)
    int f5 = 0x1;
    // All the fields are initialized to zero at startup. (for advanced users only)   
    {int}[] params = [{f1},{f2},{f3},{f4},{f5}];
    int[] forsum = [f1,f2,f3,f4,f5];
    int check_sum = checksum("int",forsum);
    int wrdLen = 5;
    Pacs_DMC_WRT_DIAGHK_CONF_TAB(wrdLen,params,check_sum);
    //-------------------------------------------------
    // Stop forwarding data to packet encoder
    //-------------------------------------------------
    // Don't forward data to Packet Encoder   
    int aux0 = 4;
    params = [{aux0}];
    check_sum = checksum("int",[aux0]);
    Pacs_DMC_WRT_BOL_REC_OPT(params,check_sum);
    // DMC_WRT_B_DEC_REC_OPT: Blue DEC receiver options
    aux0 = 4;
    params = [{aux0}];
    check_sum = checksum("int",[aux0]);
    Pacs_DMC_WRT_B_DEC_REC_OPT(params,check_sum);
    aux0 = 4;
    params = [{aux0}];
    check_sum = checksum("int",[aux0]);
    Pacs_DMC_WRT_R_DEC_REC_OPT(params,check_sum);
    // Write and set FPGA timing parameters (if necessary)
    // DMC_WRT_TIMING_FPGA_PAR(see DEC UM Section 4.2.1.3)
    // USe SPEC values
    int[] aux = [0x0,0x0,0x0,26,0x95217cb,0xb];
    check_sum = checksum("int",aux);
    {int}[] parlist = Array2grp_1(aux);
    Pacs_DMC_WRT_TIMING_FPGA_PAR(parlist,check_sum);
    // DMC_SET_TIMING_FPGA_PAR: Copy parameters set by WRT_TIMING to registers
    Pacs_DMC_SET_TIMING_FPGA_PAR();
}

//
// Purpose       : Exercise OBCP for chopper scan in photometry
//                  
//                 
//
// TCL author    : N/A
// TCL file      : N/A
// CUS author    : TM
// Script file   : OBCP_chop_scan_phot_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Exercise OBCP for chopper scan in photometry
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version      1.0
// History      0.1 09-oct-2006 TM
//              0.2 10-nov-2006 Calls PHOT_spu_reset (used to be PACS_spu_reset)
//		1.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
procedure Pacs_OBCP_chop_scan_phot {
    int nb_up_down = 1; // P#1  number of up-down seqs.
    int nb_rdouts = 80; // P#2  number of readouts on step
    int nb_steps_up = 163; // P#3  number of steps up
    int nb_steps_dn = 163; // P#4  number of steps down
    int step_up = 287; // P#5  relative move up
    int step_dn = -287; // P#6  relative move down
    int detector = 4; // Detector to SYNCH on
    int comp_mode_blu = 0; // "Blue" compression
    int comp_mode_red = 0; // "Red" compression
    int chop_start = -23500; // Chopper start position
    int chop_def = 648; // Chopper default position
}{
    // Register with environment
    // Start SPU
    int nraw_blu = 0;
    int nraw_red = 0;
    PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,true);
    //
    // Position the filter wheel at POS A
    //
    PHOT_fltw_move("POS A");
    //
    // Perform OBCP_chop_scan_phot with default parameters
    debug_print("Start OBCP_chop_scan_phot");
    int[] duree = OBCP_chop_scan_phot(nb_up_down,nb_rdouts,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,comp_mode_blu,comp_mode_red,chop_start,chop_def);
    delay(2);
    debug_print("Duration from OBCP_chop_scan_phot:" + duree);
    //
    // Position the filter wheel at POS B and repeat everything
    //
    PHOT_fltw_move("POS B");
    //
    // Perform OBCP_chop_scan_phot with default parameters
    debug_print("Start OBCP_chop_scan_phot");
    duree = OBCP_chop_scan_phot(nb_up_down,nb_rdouts,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,comp_mode_blu,comp_mode_red,chop_start,chop_def);
    delay(2);
    debug_print("Duration from OBCP_chop_scan_phot:" + duree);
    //
    // Position the filter wheel at POS A
    //
    PHOT_fltw_move("POS A");
    //
    // Stop SPU 
    //
    PHOT_spu_reset();
    // Leave environment
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Purpose       : Template for a PHOT AOT with chopped nodding in raster
//                 OBCP used: OBCP_chopped_photometry (OBCP#3)
//                 Calls nodding_raster_pointing (3.6 in Point document)
// Author        : DAC
//
// Arguments     : See input list below
//
// Prerequisite  : PACS is PHOT ready (PHOT_orbit_prologue), SPU is stopped 
//                 and ready to be (re)configured.
//
// Description   : Uses OBCP3
// Comments      :
//
// Version       : 0.1
// History       : 0.1 18-feb-2008 DAC
//                 0.2 19-feb-2008 - Use PacsPhotSlewCal
//                                 - Read more input parameters
//		   0.3 23-apr-2009 VD SPR 6482
//                 
obs PacsCal_PHOT_NodRaster {
    /* Needed variables to call PHOT_NodRaster                               */
    string fltPOS = "POS A" in ["POS A","POS B"]; // Fltw position
    double chopthrow = 30.0; // Chop throw [arcsec]
    string gain = "LOW" in ["LOW","HIGH"]; // BOLC gain
    /*                                 */
    /* OBCP related parameters         */
    /*                                 */
    /* PHOT compression modes          */
    /* 0x00 BOL0: Default              */
    /* 0x01 BOL1: Double Compression   */
    /* 0x02 BOL2: Half Compression     */
    /* 0x04 BOL4: Lossless Compression */
    /* 0x07 BOL7: Transparent          */
    /* 0x09 BOL9: Buffer Transmission  */
    int comp_mode_blu = 0x0; // Compression mode
    int comp_mode_red = 0x0; // Compression mode
    int nraw_blu = 3; // Number of raw pixels
    int nraw_red = 3; // Number of raw pixels
    int nb_SRC_REF = 2; // Nb of SRC-REF1-SRC-REF2 cycles
    int nb_rd_plateau = 31; // Nb rdouts/plateau (4*nn - 1)
    int nb_cycles_obs_cal = 1; // Outermost DMC loop
    int nb_CS1_CS2 = 0; // Loop on CSs
    /* Pointing parameters             */
    /* The ofssets are passed directly to the PointReq. Unless changed the */
    /* telecope boresight will fall in between SRC and REF                 */
    double yoffset = 0.0; // yoffset [arcsec] used as is in PntReq
    double zoffset = 0.0; // zoffset [arcsec] used as is in PntReq
    double ra = 0.0; // RA (returned by xHPOT pop-up window)
    double dec = 0.0; // DEC (ditto)
    /* Raster parameters               */
    int m = 2 in [2,100]; // Number of raster points       
    int n = 1 in [1,100]; // Number of raster lines
    double d1 = 2.0 in [2.0,480.0]; // Raster point step [arcsec]       
    double d2 = 2.0 in [2.0,480.0]; // Raster line separation [arcsec]
    bool fixed = false; // Raster in S/C or SKY coordinates
    double nodthrow = 30.0 in [2.0,960.0]; // Nod throw [arcsec]  
    double patt = 0.0; // Raster pattern orientation
    double pattnod = 270.0; // Nodding orientation (def: along y-axis)
    int nnod = 1; // Number of Aa aA ... nods 
    /* NOTE: raster size shall not be larger than 14880x14880 arcsec */
    /* Overall "verbosity"             */
    bool verbose = true;
}{
    // Compute duration of tasks to be performed during slew to source
    // Set OBSID
    int timeOBSID = duration(WriteOBSID($OBSID));
    // Condition BOLC to gain setting. This may change the data rate but SPU
    // is still stopped and a proper comp_mode may be defined
    // Can I set the gain directly (Thomas says "yes")
    int timeGAIN = duration(PHOT_set_gain(gain));
    // Use PacsPhotSlewCal from AOT code. Define three input tuples
    // SPU-like parameters
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,comp_mode_blu,0,nraw_blu,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,comp_mode_red,0,nraw_red,0,0,0,0,0}];
    // OBCP-like values (none is used since SlewCal takes them from OBCP$params)
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // including a new section for Low Gain implementation SCR4196
    bool isBrightPacs = false;
    string srcID = "pointSRC";
    // Obtain default values for "Prime" mode
    paramsPHOT = PacsPhotDefaults(srcID,"Prime",isBrightPacs,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    confPHOTblu[0]{3} = comp_mode_blu;
    confPHOTblu[0]{6} = nraw_blu;
    confPHOTred[0] = paramsPHOT{1};
    confPHOTred[0]{3} = comp_mode_red;
    confPHOTred[0]{6} = nraw_red;
    confOBCP[0] = paramsPHOT{2};
    // Perform the calibration block now
    // Cal block uses filter blue1 (posA) and blue2 (posB)
    string filter = "blue1";
    if(fltPOS == "POS B") {
        filter = "blue2";
    }
    bool doProlog = true;
    int timeCAL = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,filter));
    //
    // Before dealing with the OBCP, obtain the chopper position for CS1 & CS2
    // (likely not to be used here, but just for completeness)
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","PHOT","pos_CS1");
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","PHOT","pos_CS2");
    // The chopper moves from -chopthrow/2 to +chopthrow/2 [arcsec]
    double auxSRC = -chopthrow / 2.0;
    double auxREF = +chopthrow / 2.0;
    int chop_pos_SRC = PacsReadChopSky("PHOT_CHOP_sky",auxSRC);
    int chop_pos_REF = PacsReadChopSky("PHOT_CHOP_sky",auxREF);
    // Report settings if verbose
    if(verbose) {
        debug_print("+++CHOPPER, SRC: " + auxSRC + " [arcsec] -> " + chop_pos_SRC + " [ENG]");
        debug_print("+++CHOPPER, REF: " + auxREF + " [arcsec] -> " + chop_pos_REF + " [ENG]");
    }
    // Default position for chopper
    int chop_def = ilookup("SPEC_MEC_Defaults","Photometry","chopper");
    // Duration of OBCP to be performed ON and NOD
    int tp = duration(OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def));
    if(verbose) {
        debug_print("Duration of OBCP " + tp + " [sec]");
    }
    // tp cannot be shorted than 10 sec
    if(tp < 10) {
        error("The OBCP cannot be shorter than 10 sec; adjust your OBCP parameters");
    }
    //
    // Several arguments needed for "nodding_raster_pointing"
    //
    //Execute the pointing request
    bool execute = true;
    //Minimum slew time
    int tslewmin = timeOBSID + timeGAIN + timeCAL;
    if(verbose) {
        debug_print("+++SlewMinTime is " + tslewmin + " [sec]");
    }
    //Initial hold
    int tih = 0;
    //Final hold
    // Need 1 sec to WriteEndID() and close OBS
    int tfh = 1;
    //Use PHOT virtual aperture
    string ib = "P01_0";
    //Non-solar source
    int naifid = 0;
    //Issue PointReq
    // Still undefined pointing variables
    // Number of points/scan lines before going to OFF
    int k = 0;
    // Number of nods/raster/scan before performing a hold
    int nhold = 0;
    // Duration of a hold operation
    int thold = 0;
    // Time spent at OFF
    int top = 0;
    // Coordinates of OFF position
    double raoff = 0.0;
    double decoff = 0.0;
    // Repetitions of pattern
    int nrepeat = 1;
    // The minimum duration of return slew between repetitions
    int trepeatmin = 0;
    // Minimum duration of a "load" operation
    int tloadmin = 0;
    // Number of slews before starting a "load" slew
    int nload = 0;
    // Issue de PointReq  
    int[] ts = nodding_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodthrow,nnod,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            int tNOW = time();
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            //      Set OBSID, move filter, set gain, perform prologue
            WriteOBSID($OBSID);
            data_rate(120.0);
            PHOT_set_gain(gain);
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL startss at   " + tNOW);
            }
            PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,filter);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //      Call the OBCP with the known parameters
            OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            //      Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 7) {
            tNOW = time();
            if(verbose) {
                debug_print("NOD   starts at   " + tNOW);
            }
            //      Call the OBCP with the same parameters as for POINT
            OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
            tNOW = time();
            if(verbose) {
                debug_print("NOD   ends at     " + tNOW);
            }
        }
    }
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : SWON Grat
//
// CUS author    : Pierre Royer
// Version       : 2.0
//
//
// History       : 1.0 29-Jul-2007
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_Gra_IST_SWON {
    /* Needed variables to call PacsEng_Spec_Gra_IST_SWON                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_SWON                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_IST_SWON()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_IST_SWON();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : PACS AVM ILT
//
// Purpose       : Select the sequence mode
//
// Author TCL    : T. Mueller
// Author CUS    : DAC
//
// Arguments     : none
//                 
//
// Description   : This script will select the sequence mode for the bolometers
//                 After executing the sequencer setup the default sequencer
//                 mode is "Sb-Sref"
//                              
// Comments      : Coded based on PhFPU UM, Draft 2, March 31, 2004
//
// Version       : 1.0 19-apr-2005 (based on v1.0 of TM, 20-apr-2004)
// History       : 1.0
//
// Purpose       : Select the sequencer mode
//
// Arguments
// type   name      default     Description
// string seq_mode  "Sb_Sref"   
//
int[] procedure PHOT_change_seq_mode {
    string seq_mode = "Sb_Sref" in ["Sb_Sref","Sb_only","Sref_only","Sb_Sref_diff","Sb_Sref_unip_pos","Sb_Sref_unip_neg"]; // Sequencer mode
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    //------------------------------------------------
    // SET BOLC SEQ MODE
    //------------------------------------------------
    Pacs_BOLC_SET_SEQ_MODE(seq_mode);
    //-----------------
    // End of Procedure
    // Time spent
    int duree_TCs = time() - time_start;
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 16-oct-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_CRE_1pF0bias_Setup_Warm {
    /* No variables to call PacsEng_Spec_CRE_1pF0bias_Setup_Warm                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_CRE_1pF0bias_Setup_Warm                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_CRE_1pF0bias_Setup_Warm()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_CRE_1pF0bias_Setup_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id:
// Missionphase  : 
//
// Purpose       : Set the OBSID via DEC/MEC; show decoded OBSID on
//                 user screen 
//
// CUS script    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
// Original TCL  : N/A
// CVS file      : WriteOBSID.txt
//
// Input arguments
// Type  Name     DefVal  Description
// int   iOBSID   N/A     OBSID obtained from environment
//
// Description   : Obtain OBSID from run environment and send TC to DMC
//                 Write decoded OBSID to log file
//
// Dependencies  : Pacs_DMC_SET_OBSID
//                 DecodeOBSID
//                 
// Comments      : 
//
// Version       : 2.0
//   		   
// History       :0.1 07-sep-2010 Cloned from WriteOBSID
//                PHS-1164
// 
// 
block PacsBbWriteOBSID PACS 1109 {
    int iOBSID = 0x20000000; // Observation ID  
}{
    // Wait 1 second to allow for bus_configure
    delay(1);
    // Write OBSID to DEC/MEC and decode to output log
    Pacs_DMC_SET_OBSID(iOBSID);
    ess_hk_data_rate(0.31);
    non_ess_hk_data_rate(4.0);
    // sync the bus
    sync();
    // Inform CUS debugger
    //   DecodeOBSID(iOBSID);
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req. None during the Commissioning Phase
//           Try all the biases used for preview observations
//
// Author : Koryo Okumura
//
// CUS script : obs PacsEng_Phot_prePreview
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
//   int nLoops2 = 30; // number of CSs cycles during initial hold
//   int nLoops5 = 30; // number of CSs cycles during final hold
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_prePreview
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_prePreview()
//
// Version : Sun Jun 07 17:40:54 EDT 2009
//
obs PacsEng_Phot_prePreview {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(endBiasTable,"DIRECT","LOW"));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    //Initial hold
    int tih = timeOBSID + timeSetBias + timeCal3CPR2;
    //Final hold
    int tfh = timeSetBias + timeCal3CPR5 + timeEndID;
    //Duration of "stable" pointing
    int tp = duration(Phot_prePreview(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,15,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            //  Call the Phot_prePreview
            //************************************
            Phot_prePreview(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,15,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// $Id: 
// Purpose        : load updated OBCP 32 
//                 
//
// CUS author     : VD + HF
//
// Input arguments: see after module identification
//
// Return values: none
// N/A
//
// Comments      : this has to be run once and done!
//
// History: 1.0 created
//
//
block PacsDPUOBCP32Update PACS 1105 {
    /* no need for inputs this Eng will only be done once!! */
}{
    int mem_blockId = 0x1100;
    int mem_addr = 0xb1f;
    int dpu_dataLength = 52;
    int dpu_word_1 = 0x20001;
    int dpu_word_2 = 0x1;
    int dpu_word_3 = 0x10000;
    int dpu_word_4 = 0x0;
    int dpu_word_5 = 0x40001;
    int dpu_word_6 = 0x0;
    int dpu_word_7 = 0x30000;
    int dpu_word_8 = 0x0;
    int dpu_word_9 = 0x20001;
    int dpu_word_10 = 0x1;
    int dpu_word_11 = 0x40001;
    int dpu_word_12 = 0x0;
    int dpu_word_13 = 0x1;
    int dpu_word_14 = 0xf0000001;
    int dpu_word_15 = 0x1;
    int dpu_word_16 = 0xf0000002;
    int dpu_word_17 = 0x2b0001;
    int dpu_word_18 = 0xf0000003;
    int dpu_word_19 = 0x20001;
    int dpu_word_20 = 0x1;
    int dpu_word_21 = 0x1;
    int dpu_word_22 = 0xf0000004;
    int dpu_word_23 = 0x350001;
    int dpu_word_24 = 0xf0000005;
    int dpu_word_25 = 0x40001;
    int dpu_word_26 = 0x3;
    int dpu_word_27 = 0x20001;
    int dpu_word_28 = 0xf0000006;
    int dpu_word_29 = 0x350001;
    int dpu_word_30 = 0xf0000007;
    int dpu_word_31 = 0x40001;
    int dpu_word_32 = 0x5;
    int dpu_word_33 = 0x20001;
    int dpu_word_34 = 0xf0000006;
    int dpu_word_35 = 0x20001;
    int dpu_word_36 = 0xf0000006;
    int dpu_word_37 = 0x350001;
    int dpu_word_38 = 0xf0000005;
    int dpu_word_39 = 0x40001;
    int dpu_word_40 = 0x3;
    int dpu_word_41 = 0x20001;
    int dpu_word_42 = 0xf0000006;
    int dpu_word_43 = 0x10000;
    int dpu_word_44 = 0x0;
    int dpu_word_45 = 0x1;
    int dpu_word_46 = 0xf0000008;
    int dpu_word_47 = 0x350001;
    int dpu_word_48 = 0xf0000009;
    int dpu_word_49 = 0x40001;
    int dpu_word_50 = 0x41;
    int dpu_word_51 = 0x20001;
    int dpu_word_52 = 0xf0000006;
    {int}[] grp_1 = [{dpu_word_1},{dpu_word_2},{dpu_word_3},{dpu_word_4},{dpu_word_5},{dpu_word_6},{dpu_word_7},{dpu_word_8},{dpu_word_9},{dpu_word_10},{dpu_word_11},{dpu_word_12},{dpu_word_13},{dpu_word_14},{dpu_word_15},{dpu_word_16},{dpu_word_17},{dpu_word_18},{dpu_word_19},{dpu_word_20},{dpu_word_21},{dpu_word_22},{dpu_word_23},{dpu_word_24},{dpu_word_25},{dpu_word_26},{dpu_word_27},{dpu_word_28},{dpu_word_29},{dpu_word_30},{dpu_word_31},{dpu_word_32},{dpu_word_33},{dpu_word_34},{dpu_word_35},{dpu_word_36},{dpu_word_37},{dpu_word_38},{dpu_word_39},{dpu_word_40},{dpu_word_41},{dpu_word_42},{dpu_word_43},{dpu_word_44},{dpu_word_45},{dpu_word_46},{dpu_word_47},{dpu_word_48},{dpu_word_49},{dpu_word_50},{dpu_word_51},{dpu_word_52}];
    //for the checksum?
    int[] aux_1 = [dpu_word_1,dpu_word_2,dpu_word_3,dpu_word_4,dpu_word_5,dpu_word_6,dpu_word_7,dpu_word_8,dpu_word_9,dpu_word_10,dpu_word_11,dpu_word_12,dpu_word_13,dpu_word_14,dpu_word_15,dpu_word_16,dpu_word_17,dpu_word_18,dpu_word_19,dpu_word_20,dpu_word_21,dpu_word_22,dpu_word_23,dpu_word_24,dpu_word_25,dpu_word_26,dpu_word_27,dpu_word_28,dpu_word_29,dpu_word_30,dpu_word_31,dpu_word_32,dpu_word_33,dpu_word_34,dpu_word_35,dpu_word_36,dpu_word_37,dpu_word_38,dpu_word_39,dpu_word_40,dpu_word_41,dpu_word_42,dpu_word_43,dpu_word_44,dpu_word_45,dpu_word_46,dpu_word_47,dpu_word_48,dpu_word_49,dpu_word_50,dpu_word_51,dpu_word_52];
    //     PP018480 DPU_CHECKSUM             Raw          Hex          3C34
    int check_sum = checksum("int",aux_1);
    Pacs_DPU_MEMORY_LOAD_DRAM(mem_blockId,mem_addr,dpu_dataLength,grp_1,check_sum);
    //
    mem_blockId = 0x1100;
    mem_addr = 0xb53;
    dpu_dataLength = 52;
    dpu_word_1 = 0x350001;
    dpu_word_2 = 0xf000000a;
    dpu_word_3 = 0x40001;
    dpu_word_4 = 0x81;
    dpu_word_5 = 0x20001;
    dpu_word_6 = 0xf0000006;
    dpu_word_7 = 0x10000;
    dpu_word_8 = 0x0;
    dpu_word_9 = 0x10000;
    dpu_word_10 = 0x0;
    dpu_word_11 = 0x1;
    dpu_word_12 = 0xf0000002;
    dpu_word_13 = 0x2b0001;
    dpu_word_14 = 0xf000000b;
    dpu_word_15 = 0x20001;
    dpu_word_16 = 0x1;
    dpu_word_17 = 0x1;
    dpu_word_18 = 0xf0000004;
    dpu_word_19 = 0x350001;
    dpu_word_20 = 0xf0000005;
    dpu_word_21 = 0x40001;
    dpu_word_22 = 0x13;
    dpu_word_23 = 0x20001;
    dpu_word_24 = 0xf0000006;
    dpu_word_25 = 0x350001;
    dpu_word_26 = 0xf0000007;
    dpu_word_27 = 0x40001;
    dpu_word_28 = 0x15;
    dpu_word_29 = 0x20001;
    dpu_word_30 = 0xf0000006;
    dpu_word_31 = 0x20001;
    dpu_word_32 = 0xf0000006;
    dpu_word_33 = 0x350001;
    dpu_word_34 = 0xf0000005;
    dpu_word_35 = 0x40001;
    dpu_word_36 = 0x13;
    dpu_word_37 = 0x20001;
    dpu_word_38 = 0xf0000006;
    dpu_word_39 = 0x10000;
    dpu_word_40 = 0x0;
    dpu_word_41 = 0x1;
    dpu_word_42 = 0xf0000008;
    dpu_word_43 = 0x350001;
    dpu_word_44 = 0xf0000009;
    dpu_word_45 = 0x40001;
    dpu_word_46 = 0x51;
    dpu_word_47 = 0x20001;
    dpu_word_48 = 0xf0000006;
    dpu_word_49 = 0x350001;
    dpu_word_50 = 0xf000000a;
    dpu_word_51 = 0x40001;
    dpu_word_52 = 0x91;
    {int}[] grp_2 = [{dpu_word_1},{dpu_word_2},{dpu_word_3},{dpu_word_4},{dpu_word_5},{dpu_word_6},{dpu_word_7},{dpu_word_8},{dpu_word_9},{dpu_word_10},{dpu_word_11},{dpu_word_12},{dpu_word_13},{dpu_word_14},{dpu_word_15},{dpu_word_16},{dpu_word_17},{dpu_word_18},{dpu_word_19},{dpu_word_20},{dpu_word_21},{dpu_word_22},{dpu_word_23},{dpu_word_24},{dpu_word_25},{dpu_word_26},{dpu_word_27},{dpu_word_28},{dpu_word_29},{dpu_word_30},{dpu_word_31},{dpu_word_32},{dpu_word_33},{dpu_word_34},{dpu_word_35},{dpu_word_36},{dpu_word_37},{dpu_word_38},{dpu_word_39},{dpu_word_40},{dpu_word_41},{dpu_word_42},{dpu_word_43},{dpu_word_44},{dpu_word_45},{dpu_word_46},{dpu_word_47},{dpu_word_48},{dpu_word_49},{dpu_word_50},{dpu_word_51},{dpu_word_52}];
    // for the checksum
    int[] aux_2 = [dpu_word_1,dpu_word_2,dpu_word_3,dpu_word_4,dpu_word_5,dpu_word_6,dpu_word_7,dpu_word_8,dpu_word_9,dpu_word_10,dpu_word_11,dpu_word_12,dpu_word_13,dpu_word_14,dpu_word_15,dpu_word_16,dpu_word_17,dpu_word_18,dpu_word_19,dpu_word_20,dpu_word_21,dpu_word_22,dpu_word_23,dpu_word_24,dpu_word_25,dpu_word_26,dpu_word_27,dpu_word_28,dpu_word_29,dpu_word_30,dpu_word_31,dpu_word_32,dpu_word_33,dpu_word_34,dpu_word_35,dpu_word_36,dpu_word_37,dpu_word_38,dpu_word_39,dpu_word_40,dpu_word_41,dpu_word_42,dpu_word_43,dpu_word_44,dpu_word_45,dpu_word_46,dpu_word_47,dpu_word_48,dpu_word_49,dpu_word_50,dpu_word_51,dpu_word_52];
    //     PP018380 DPU_CHECKSUM             Raw          Hex          BCA1                                                   
    // 
    check_sum = checksum("int",aux_2);
    Pacs_DPU_MEMORY_LOAD_DRAM(mem_blockId,mem_addr,dpu_dataLength,grp_2,check_sum);
    //
    mem_blockId = 0x1100;
    mem_addr = 0xb87;
    dpu_dataLength = 12;
    dpu_word_1 = 0x20001;
    dpu_word_2 = 0xf0000006;
    dpu_word_3 = 0x10000;
    dpu_word_4 = 0x0;
    dpu_word_5 = 0x10000;
    dpu_word_6 = 0x0;
    dpu_word_7 = 0x10000;
    dpu_word_8 = 0x0;
    dpu_word_9 = 0x40001;
    dpu_word_10 = 0x0;
    dpu_word_11 = 0x30000;
    dpu_word_12 = 0x0;
    {int}[] grp_3 = [{dpu_word_1},{dpu_word_2},{dpu_word_3},{dpu_word_4},{dpu_word_5},{dpu_word_6},{dpu_word_7},{dpu_word_8},{dpu_word_9},{dpu_word_10},{dpu_word_11},{dpu_word_12}];
    //     PP018380 DPU_CHECKSUM             Raw          Hex          B07E   // 
    //     for the checksum
    int[] aux_3 = [dpu_word_1,dpu_word_2,dpu_word_3,dpu_word_4,dpu_word_5,dpu_word_6,dpu_word_7,dpu_word_8,dpu_word_9,dpu_word_10,dpu_word_11,dpu_word_12];
    check_sum = checksum("int",aux_3);
    Pacs_DPU_MEMORY_LOAD_DRAM(mem_blockId,mem_addr,dpu_dataLength,grp_3,check_sum);
    //
    mem_blockId = 0x1100;
    mem_addr = 0xbaa;
    dpu_dataLength = 1;
    dpu_word_1 = 0x4a;
    {int}[] grp_4 = [{dpu_word_1}];
    //    PP018380 DPU_CHECKSUM             Raw          Hex          6D4E
    // for the checksum
    int[] aux_4 = [dpu_word_1];
    check_sum = checksum("int",aux_4);
    Pacs_DPU_MEMORY_LOAD_DRAM(mem_blockId,mem_addr,dpu_dataLength,grp_4,check_sum);
    // Memory dump
    int mem_dumpId = 0x1100;
    int mem_dump_addr = 0x5bd;
    int dump_dataLength = 1532;
    Pacs_DPU_MEMORY_DUMP(mem_dumpId,mem_dump_addr,dump_dataLength);
    sync();
}

// CVS comments  : $Id: PacsPhotNoiseRMS.txt,v 1.6 2007/04/25 15:14:04 dcesarsk Exp $ 
// CVS file      : PacsPhotNoiseRMS.txt
//
// Purpose       : Returns minimum detectable flux [mJy] for S/N=1
//
// Author        : Diego A. Cesarsky
// CUS script    : DAC
//
// Arguments     : pointCase
//                 filterID
//                 time_on
//
// Description   : Noise computation based on sensitivity for time_on = 1 [sec]
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : Based on D. Lutz's "Guesstimator.pro"
//                 Newer version based on Alpog's 22-may-2006 e-mail
//
// Version       : 0.1  6-Dec-2004 Creation by DAC
// History       : 0.2  4-sep-2006 
// - Use new PHOTnoise table (based on alpog's e-mail 22-may-2006).
// - Accept PointCase (may need it for SRC,REF considerations)
//                 0.3 10-oct-2006 SPR-2378
// - the factors sqrt(2) in point source and scan map mode
//   and and 1/sqrt(2) in small and large raster shall be removed, 
//   as these factors are already taken into account in the values provided 
//   by Albrecht Poglitsch (photometer_noise.txt) to account for (chopped) 
//   background subtraction, where TIME is the pure "science time"
//  1.0  3-nov-2006 Compute also extended source RMS reading updated
//                  PHOTnoise CAL-U table; module returns now 4 values:
//                  rms[0], rms[1] : point source BLU and RED
//                  rms[2], rms[3] : extended source BLU and RED
//               :
double[] procedure PacsPhotNoiseRMS {
    int pointCase = 21; // The PointCase code of PacsPhoto
    string filter = "blue1" in ["blue1","blue2"]; // Filter ID
    double intTIME = 1.0; // ON source time [sec] 
}{
    // Sensitivity [Jy] per filter, i.e. flux for which S/N=1 is obtained in 1 sec 
    // assuming the source is always seen on the detector (excludes the noise 
    // from 'off' subtraction)
    string calU = "PHOTnoise";
    // Point Source. Here the SRC is always in view
    if(pointCase == 11 || pointCase == 12) {
        double sensRED = dlookup(calU,"red","point");
        double sensBLU = dlookup(calU,filter,"point");
        //    Compute "noise" after intTIME [sec] of integration [mJy]
        double pntRMSred = 1000.0 * sensRED / sqrt(intTIME);
        double pntRMSblu = 1000.0 * sensBLU / sqrt(intTIME);
        double extRMSred = 0.0;
        double extRMSblu = 0.0;
    }
    // Small source or raster map. Here the SRC is in view 1/2 time
    if(pointCase == 21 || pointCase == 22 || pointCase == 31 || pointCase == 32) {
        //    Point source
        sensRED = dlookup(calU,"red","small");
        sensBLU = dlookup(calU,filter,"small");
        //    Extended source
        double extsensRED = dlookup(calU,"red","EXTsmall");
        double extsensBLU = dlookup(calU,filter,"EXTsmall");
        //    Compute "noise" after intTIME [sec] of integration [mJy]
        pntRMSred = 1000.0 * sensRED / sqrt(intTIME);
        pntRMSblu = 1000.0 * sensBLU / sqrt(intTIME);
        extRMSred = extsensRED / sqrt(intTIME);
        extRMSblu = extsensBLU / sqrt(intTIME);
    }
    // Scan mode. Here the SRC is always in view
    if(pointCase == 33) {
        //    Point source     
        sensRED = dlookup(calU,"red","scan");
        sensBLU = dlookup(calU,filter,"scan");
        //    Extended source
        extsensRED = dlookup(calU,"red","EXTscan");
        extsensBLU = dlookup(calU,filter,"EXTscan");
        //    Compute "noise" after intTIME [sec] of integration [mJy]
        pntRMSred = 1000.0 * sensRED / sqrt(intTIME);
        pntRMSblu = 1000.0 * sensBLU / sqrt(intTIME);
        extRMSred = extsensRED / sqrt(intTIME);
        extRMSblu = extsensBLU / sqrt(intTIME);
    }

    return [pntRMSred,pntRMSblu,extRMSred,extRMSblu];
}

/////////////////
// $Id
////////////////
// Purpose: determine if line + continuum flux density at given reference wavelength
//          will trigger a change of capacitance, and hence which capacitance should be used
//          
// CUS author: VD  (BV and PR)
//          
// Return Values: 
// {bool,int}{switchCapa,capaVal}
// 
// Comments: this procedure results from PHS-193 and should be valid for both PacsLineSpec and PacsRangeSpec
// 
// History: 10-dec-2009 1.0 VD created
//          17-dec-2009 2.xx VD commented to add Range and SED
//          03-mai-2010 3.0 VD PHS-1393 B2A order23
{bool,int} procedure PacsSpecSwitchCapa {
    /*        {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = []; */
    /*        {string,double,int,double,double,double,string,string}[] lines = []; */
    {int,double,double,double,double,string,double,string}[] forCapaSwitch = [];
    /*   string specMode = "LINE" in ["LINE", "RANGE", "SED"]; */
}{
    // PHS-193.... add extra proc for ChangeCapa as function of input signal Line+Cont+telBckgd wrt to saturation limits
    // for the moment keep at obs level ... may move to PacsSpecDefaults or PacsSpecSlewCal???
    // simple logic based on KEY wave to select table ... otherwise:
    // based on wave and orderSel ( wave >< 103.1) can come later then 2 maxV and maxSignal and capa based on maxSignalB and maxSignalR
    // 
    // 
    int nbLines = length(forCapaSwitch);
    //
    // keyWAVE will be the same for Range and Sed mode
    // 
    double[] keyWAVE = [forCapaSwitch[0]{6}];
    double c = 299792.458;
    double telBckgd = 0.0;
    double contFlux = 0.0;
    double deltaWaveMicron = 0.0;
    double dlineWidth = 0.0;
    string resolXX = " ";
    double deltaWaveResolution = 0.0;
    double dlineFlux = 0.0;
    double fwhM = 0.0;
    double lineFluxFlambda = 0.0;
    double lineFluxJansky = 0.0;
    double wave = 0.0;
    double maxResponse = 0.0;
    string respTable = " ";
    string resolCol = " ";
    double allFlux = 0.0;
    double[] maxV = [0.0];
    double maxSignal = 0.0;
    int capa_orig = forCapaSwitch[0]{0};
    int capa = 0;
    double capa0 = 0.8 * 1.0 * 16.0;
    double capa8 = 0.8 * 1.6 * 16.0;
    double capa4 = 0.8 * 3.0 * 16.0;
    double capa12 = 7.8 * 16.0;
    double memoMax = 0.0;
    for(int loopXX = 0 .. nbLines - 1) {
        if(forCapaSwitch[loopXX]{1} != 0.0) {
            string orderSel = forCapaSwitch[loopXX]{7};
            // wave = lwave for LINE, refWave for Range and Sed
            debug_print(" loopXX: " + loopXX);
            wave = forCapaSwitch[loopXX]{1};
            debug_print("wave: " + wave);
            debug_print("orderSel: " + orderSel);
            if(orderSel == "order2" || orderSel == "sedb2b") {
                //        if(keyWAVE[0] <= 102.0) {
                if(wave < 102.0) {
                    respTable = "SPEC_MaxResp_B2B";
                    resolCol = "resol2";
                } else {
                    respTable = "SPEC_MaxResp_R1";
                    resolCol = "resol1";
                }
            }
            if(orderSel == "order3" || orderSel == "sedb3a") {
                //        if(keyWAVE[0] <= 102.0) {
                if(wave < 102.0) {
                    respTable = "SPEC_MaxResp_B3A";
                    resolCol = "resol3";
                } else {
                    respTable = "SPEC_MaxResp_R1";
                    resolCol = "resol1";
                }
            }
            if(orderSel == "sedb2a" || orderSel == "order23") {
                //        if(keyWAVE[0] <= 102.0) {
                if(wave < 102.0) {
                    respTable = "SPEC_MaxResp_B2A";
                    resolCol = "resol2";
                } else {
                    respTable = "SPEC_MaxResp_R1";
                    resolCol = "resol1";
                }
            }
            debug_print("resolCol: " + resolCol);
            telBckgd = interpolate("NewTelescopeBackground_for_Uplink","flux",wave);
            contFlux = forCapaSwitch[loopXX]{3} / 1000.0;
            dlineWidth = forCapaSwitch[loopXX]{4};
            deltaWaveMicron = dlineWidth;
            if(forCapaSwitch[loopXX]{5} == "kms") {
                deltaWaveMicron = dlineWidth / c * wave;
            }
            deltaWaveResolution = interpolate("SPEC_resolution",resolCol,wave) / c * wave;
            fwhM = max(deltaWaveMicron,deltaWaveResolution);
            dlineFlux = forCapaSwitch[loopXX]{2};
            // ATT .. units!!  dLineFlux is 1.0E-18 w/m2 .. fwhm 1.0E-6 m)
            lineFluxFlambda = dlineFlux / fwhM;
            // Units
            lineFluxJansky = lineFluxFlambda * (wave * wave) / c * 0.1;
            maxResponse = interpolate(respTable,"maxResp",wave);
            allFlux = lineFluxJansky + contFlux + telBckgd;
            maxV[loopXX] = allFlux * maxResponse;
            debug_print("maxV[" + loopXX + "]: " + maxV[loopXX]);
            if(nbLines > 1 && loopXX >= 1) {
                maxSignal = max(maxV[loopXX],memoMax);
                memoMax = maxSignal;
            } else {
                maxSignal = maxV[loopXX];
                memoMax = maxV[loopXX];
            }
            if(maxSignal < capa0) {
                capa = 0;
                debug_print("capa 0: " + capa0);
            } else {
                if(maxSignal < capa8) {
                    capa = 8;
                    debug_print("capa 8: " + capa8);
                } else {
                    if(maxSignal < capa4) {
                        capa = 4;
                        debug_print("capa 4: " + capa4);
                    } else {
                        if(maxSignal < capa12) {
                            capa = 12;
                            debug_print("capa 12: " + capa12);
                        } else {
                            error("Line flux and/or continuum are too bright for PACS capabilities");
                        }
                    }
                }
            }
        } else {
            capa = capa_orig;
        }
    }
    bool change_capa = false;
    if(capa != capa_orig) {
        //      message("Beware: because of very bright Lines, the entire AOR will be observed with a capa of: " + capa);
        //        capaBlue = capa;
        //        capaRed = capa;
        change_capa = true;
    }
    {bool,int} switchCapa = {change_capa,capa};
    //

    return switchCapa;
}

/////////////////
// $Id
////////////////
// Purpose: Determine if Range Continuum flux density at given reference wavelength
//          will trigger a change of capacitance, and hence which capacitance should be used
//          
// CUS author: VD  (BV and PR)
//          
// Return Values: 
// {bool,bool,int,int}{switchCapablu,switchCapaRed,capaValBlu,CapaValRed}
// 
// Comments: this procedure results from PHS-193 and should be valid for PacsRangeSpec
// 
// History: 15-mar-2010 PHS-1355: bands limits
//        : 17-mar-2010 PHS-1365 Error in Parallel bands and failing to fill the forSwitchCapaXXX arrays tuples
// 
{{bool,int},{bool,int}} procedure PacsSpecCheckCapacitance {
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [];
    string orderSel = "order2";
}{
    int nbRanges = length(rangeSPOT);
    //  WE need to remember red and blue ranges .... 
    {int,double,double,double,double,string,double,string}[] forCapaSwitchBlu = [{0,0.0,0.0,0.0,0.0,"",0.0,""}];
    {int,double,double,double,double,string,double,string}[] forCapaSwitchRed = [{0,0.0,0.0,0.0,0.0,"",0.0,""}];
    {int,double,double,double,double,string,double,string}[] forCapaSwitch = [{0,0.0,0.0,0.0,0.0,"",0.0,""}];
    string arrayID = orderSel;
    if(orderSel == "sedb2b") {
        arrayID = "order2";
    }
    if(orderSel == "sedb2a") {
        arrayID = "order23";
    }
    if(orderSel == "sedb3a") {
        arrayID = "order3";
    }
    int capaDefBlu = ilookup("CONF_SPEC_param","Normal0BLU","capa");
    int capaDefRed = ilookup("CONF_SPEC_param","Normal0RED","capa");
    for(int loopXY = 0 .. nbRanges - 1) {
        debug_print("rangeSPOT{5}: " + rangeSPOT[loopXY]{5});
        double waveRef = rangeSPOT[loopXY]{9};
        if(waveRef < 102.0) {
            int capaDef = capaDefBlu;
        } else {
            capaDef = capaDefRed;
        }
        // getting the Edges-- order,blu_grat,red_grat
        {double,double,bool} edge = PacsSpecGetParBand(rangeSPOT[loopXY]{1},rangeSPOT[loopXY]{2},orderSel);
        // 
        if(rangeSPOT[loopXY]{1} < 102.0) {
            double bluEdgeBlu = rangeSPOT[loopXY]{1};
            double redEdgeBlu = rangeSPOT[loopXY]{2};
            double bluEdgeRed = edge{0};
            double redEdgeRed = edge{1};
        } else {
            bluEdgeRed = rangeSPOT[loopXY]{1};
            redEdgeRed = rangeSPOT[loopXY]{2};
            bluEdgeBlu = edge{0};
            redEdgeBlu = edge{1};
        }
        bool noParBand = edge{2};
        debug_print("edges: " + edge);
        //get wavelength in both Nominal and Parallel bands at which the responsivity is highest
        if(!noParBand) {
            double[] waveBlu = PacsSpecWaveArray(bluEdgeBlu,redEdgeBlu,false);
            double[] waveRed = PacsSpecWaveArray(bluEdgeRed,redEdgeRed,false);
            double[] waveRespBlu = PacsSpecMinMaxRMS(waveBlu,waveRef,arrayID);
            double[] waveRespRed = PacsSpecMinMaxRMS(waveRed,waveRef,"order1");
            double waveHighRespBlu = waveRespBlu[0];
            double waveHighRespRed = waveRespRed[0];
            debug_print("waveHighRespBlu / waveHighRespRed: " + waveHighRespBlu + " / " + waveHighRespRed);
            debug_print("waveRef: " + waveRef + "rangeSPOT[" + loopXY + "]{5}: " + rangeSPOT[loopXY]{5});
            double contFluxRJBlu = PacsSpecRJ(rangeSPOT[loopXY]{5},waveRef,waveHighRespBlu);
            double contFluxRJRed = PacsSpecRJ(rangeSPOT[loopXY]{5},waveRef,waveHighRespRed);
            debug_print("contFluxRJBlu: " + contFluxRJBlu);
            debug_print("contFluxRJRed: " + contFluxRJRed);
            double lineFlux = rangeSPOT[loopXY]{4};
            double lineWidth = rangeSPOT[loopXY]{6};
            string lineWidthUnit = rangeSPOT[loopXY]{8};
            forCapaSwitchBlu[loopXY] = {capaDefBlu,waveHighRespBlu,lineFlux,contFluxRJBlu,lineWidth,lineWidthUnit,waveRef,orderSel};
            forCapaSwitchRed[loopXY] = {capaDefRed,waveHighRespRed,lineFlux,contFluxRJRed,lineWidth,lineWidthUnit,waveRef,orderSel};
            // PHS-1365 to avoid create NULL tuple which execption cannot be handled
            forCapaSwitch[loopXY] = {0,0.0,0.0,0.0,0.0,"",0.0,""};
            debug_print("switchCapaBlu:" + forCapaSwitchBlu);
            debug_print("switchCapaRed:" + forCapaSwitchRed);
            {bool,int} switchCapaBlu = PacsSpecSwitchCapa(forCapaSwitchBlu);
            {bool,int} switchCapaRed = PacsSpecSwitchCapa(forCapaSwitchRed);
        } else {
            double[] wave = PacsSpecWaveArray(bluEdgeBlu,redEdgeBlu,false);
            if(rangeSPOT[loopXY]{1} < 102.0) {
                double[] waveResp = PacsSpecMinMaxRMS(wave,waveRef,arrayID);
            } else {
                waveResp = PacsSpecMinMaxRMS(wave,waveRef,"order1");
            }
            double waveHighResp = waveResp[0];
            double contFluxRJ = PacsSpecRJ(rangeSPOT[loopXY]{5},waveRef,waveHighResp);
            lineFlux = rangeSPOT[loopXY]{4};
            lineWidth = rangeSPOT[loopXY]{6};
            lineWidthUnit = rangeSPOT[loopXY]{8};
            forCapaSwitch[loopXY] = {capaDef,waveHighResp,lineFlux,contFluxRJ,lineWidth,lineWidthUnit,waveRef,orderSel};
            //PHS-1365 : should not create NULL tuples: exception cannot be logically handled
            forCapaSwitchBlu[loopXY] = {0,0.0,0.0,0.0,0.0,"",0.0,""};
            forCapaSwitchRed[loopXY] = {0,0.0,0.0,0.0,0.0,"",0.0,""};
            debug_print("switchCapa:" + forCapaSwitch);
            {bool,int} switchCapa = PacsSpecSwitchCapa(forCapaSwitch);
            if(rangeSPOT[loopXY]{1} < 102.0) {
                switchCapaBlu = switchCapa;
                switchCapaRed = {false,capaDefRed};
            } else {
                switchCapaBlu = {false,capaDefBlu};
                switchCapaRed = switchCapa;
            }
        }
    }

    return {switchCapaBlu,switchCapaRed};
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req.1.1.9 Measure time constants after cosmic ray impact
//
// Author : Koryo Okumura
//
// Version : May 26 2009
//
// CUS script : procedure Phot_glitch
//
// Argument :
//   string biasTable = "BOLObias_standard_high" : Bias table file name containing the initial values
//   string gain = "HIGH" in ["LOW","HIGH"] : gain used during the measurements
//   int mesureTime = 1200 : Measurement duration in seconds
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description :
//   + All the biases are set group by group
//   + Set the direct mode
//   + Data acquisition in buffer transmission mode and in burst mode
//
// Dependencies : None
//
// Comments : None
// Update :
//   2009-05-26 : The default gain is set to high and TMMarker added
//
procedure Phot_glitch {
    string biasTable = "BOLObias_standard_high"; // Bias table file name containing the initial values
    string gain = "HIGH" in ["LOW","HIGH"]; // gain used during the measurements
    int measureTime = 1200; // Measurement duration in seconds
}{
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    PHOT_fltw_move("POS A");
    //
    //*******************************
    // Bias setting of the detectors
    //*******************************
    //
    PHOT_change_biases(biasTable,"DIRECT",gain);
    //
    // Set the PACS chopper at the central position
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //************************
    // Set DPU for Burst mode
    //************************
    Pacs_DPU_SET_BUS_LIST("ENABLE");
    //
    // Set SPU to the default mode
    PHOT_spu_setup(9,9,0,0,true);
    TMMarker601();
    delay(measureTime);
    TMMarker600();
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //************************
    // Set DPU for Burst mode
    //************************
    Pacs_DPU_SET_BUS_LIST("DISABLE");
    //
    // Sychronize
    //
    sync();
}

// Missionphase		: PACS PV Phase
//
// Purpose :		Chopped Raster
//
// Author		 : HF
//
// Arguments		:
//
// Prerequisite 	: PACS has to be set to spectroscopy mode already
//
// Description		: Uses OBCP27 for executing an almost infinite length measurement while doing 
//                      a chopped raster
// Comments		:
//
// Version		: 1.0
// 
// History		: 1.0 Initial version
//                      : 1.1 VD implementation of the SPR 5447 keyWL as fnct of filter+order comb.
//			: 1.2 VD SPR 6482
//			: 1.3 VD SCR PHS-1173
//			   
obs PacsCal_Spec_Chopped_Raster {
    /* Needed variables to call WaveCalChop */
    /* Spectro definitions */
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int grat_pos = 500000; // grating start position for scan
    int grat_time = 0; // time for grating to move to start position [msec]
    int order = 2; // end position for order selection: 1=Red, 2= or 3= Blue)    
    int nb_ramps_plateau = 2; // number of readouts per chopper plateau
    /* Detector definitions */
    int nb_raw_red = 3; // number of red pixels
    int nb_raw_blu = 3; // number of blue pixels
    int capa_red = 12; // Red capacitor
    int capa_blu = 12; // Blue capacitor
    double bias_r_blu = 0.0101; // Bias "r" blue
    double bias_r_red = 0.0101; // Bias "r" red
    double bias_d_blu = 0.1701; // Bias "d" blue
    double bias_d_red = 0.0601; // Bias "d" red
    int comp_mode_blu = 16; // compression mode for blue detector
    int detector = 1; // 1=blue 2=red (sync on detector)
    int comp_mode_red = 16; // compression mode for red detector
    int nb_samp_subramp_blu = 16; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 16; // Nb of red samples per sub-ramp
    /* Pointing parameters */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    double raoff = 0.0 in [0.0,360.0];
    double decoff = 0.0 in [-90.0,90.0];
    /* raster */
    int m = 3 in [2,100]; // Number of points in a raster line
    int n = 3 in [1,100]; // number of raster lines
    double d1 = 2.0 in [2.0,480.0]; // Raster point separation in a line [arcsec]
    double d2 = 2.0 in [2.0,480.0]; // Raster line separation [arcsec]
    bool fixed = false; // Raster in S/C (=false) or SKY coordinates (=true)
    int chop_pos1 = 664; // initial chopper position
    int chop_pos2 = 664; // chopper off position
    double patt = 0.0; // Raster pattern orientation
    bool verbose = true;
    int raster_pos_dwell = 10; //Raster position dwell in seconds
    int k = 0; // off after this amount of raster positions
    int top = 10; // time at off position in seconds
}{
    // computing time for slew / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Set OBSID
    int tobsid = duration(WriteOBSID($OBSID));
    // Fake obcp parameters to have a infinite obcp
    int grat_step_up = 0;
    // grating step size
    int grat_step_dn = 0;
    // grating step size
    int nb_grat_steps = 10000;
    // number of grating steps in one direction
    int nb_SRC_REF = 1000;
    // number of ramps (cycles) per grating position
    int nb_CS1_CS2 = 0;
    // nb of cycles on internal CS
    int nb_rdouts_ramp = 64;
    // number of readouts per ramp
    int nb_up_down = 10000;
    // number of grating updown scans
    // Calibration time during slew
    // SPEC parameters for BLU and RED               
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,comp_mode_blu,nb_raw_blu,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,comp_mode_red,nb_raw_red,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    string throwUsage = "small";
    string extraConf = "normal";
    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // frstLstGratPos is the last position for the grating after the Cals done
    // during Slew time... must be same as observations start position: grat_pos   
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    // "N/A" in string because of indexing 0,1,2,3
    string[] choix = ["N/A","order1","order2","order3"];
    string order_str = "order" + order;
    //    if(choix[order] != "order1") {
    //        double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //    double keyWL = PacsSpecKeyWaves(order_str);
    double[] keyWAVE = [82.0];
    if(choix[order] == "order1" && fltPOS == "POS_A") {
        keyWAVE = [180.0];
    }
    if(choix[order] == "order1" && fltPOS == "POS_B") {
        keyWAVE = [150.0];
    }
    if(choix[order] == "order2" && fltPOS == "POS_B") {
        keyWAVE = [75.0];
    }
    if(choix[order] == "order3" && fltPOS == "POS_A") {
        keyWAVE = [60.0];
    }
    // this is for extended Blue
    if(choix[order] == "order2" && fltPOS == "POS_A") {
        keyWAVE = [60.0];
    }
    // no need for SpecKeyWave!
    int tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]));
    //   } else {
    //       keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //       double keyWAVE2 = dlookup("KEY_WAVES",order_str,"KeyWave2");
    //       keyWAVE = [keyWAVE1,keyWAVE2];
    //        tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]));
    //   }
    //Initial hold for commanding the start of the long OBCP
    int tih = 30;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int grat_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int tepilog = duration(SPEC_aot_epilogue_stopOBCP(grat_pos,grat_def,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing is fixed to an input parameter
    //int tp = duration(WaveCalChop(fltPOS,grat_pos,grat_time,grat_step_up,grat_step_dn,nb_grat_steps,nb_CS1_CS2,nb_rdouts_ramp,nb_ramps_plateau,nb_up_down,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_SRC_REF,nodthrow,detector));
    int tp = raster_pos_dwell;
    if(verbose) {
        debug_print("Duration of WaveCalChop" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    int thold = 0;
    int nhold = 0;
    int nrepeat = 1;
    // minimum duration of the slew between repeats
    int trepeatmin = 0;
    //Issue PointReq
    int tslewmin = tobsid + tpacsSlewCal;
    if(verbose) {
        debug_print("Slewing time is:" + tslewmin + "sec");
    }
    int[] ts = raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            int tNOW = time();
            // slew time calibration
            WriteOBSID($OBSID);
            if(verbose) {
                debug_print("Slewing starts at :" + tNOW + " sec");
            }
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            if(choix[order] == "order1") {
                PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]);
            } else {
                PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]);
            }
            tNOW = time();
            if(verbose) {
                debug_print("Slewing ends at " + tNOW + " sec");
            }
        }
        if(state[0] == 2) {
            //       Call the WaveCal procedure
            tNOW = time();
            if(verbose) {
                debug_print("Observation on SRC starts at :" + tNOW + " sec");
            }
            SpatialCalChop(fltPOS,grat_pos,grat_time,grat_step_up,grat_step_dn,nb_grat_steps,nb_CS1_CS2,nb_rdouts_ramp,nb_ramps_plateau,nb_up_down,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_SRC_REF,chop_pos1,chop_pos2,detector);
            tNOW = time();
            if(verbose) {
                debug_print("Observation on SRC ends at :" + tNOW + " sec");
            }
        }
        if(state[0] == 3) {
            //       Call the WaveCal procedure
            tNOW = time();
            if(verbose) {
                debug_print("Observation on SRC starts at :" + tNOW + " sec");
            }
            // Do nothing but continue the OBCP 
            tNOW = time();
            if(verbose) {
                debug_print("Observation on SRC ends at :" + tNOW + " sec");
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("Final Hold starts at :" + tNOW + " sec");
            }
            SPEC_aot_epilogue_stopOBCP(grat_pos,grat_def,verbose);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("Final Hold ends at :" + tNOW + " sec");
            }
        }
    }
    // End of Observation
}

// Script file   : PACS_Spec_Gra_IST_Check_4_OBS.cus 
//
// Purpose       :  Check the Stability of the grating under a given set of controller parameters
//
// Description  : Configuration of the grating (incl Homing), enable & disable the grating after 2 relative movements.
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
//                 1.1  13-Nov-2007 BV - added MOIS comments
//		   2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
//
procedure Pacs_Spec_Gra_IST_Check_4 {
}{
    // Register start of OBS
    mois_comment("Start of procedure: home & perform a few movements");
    //
    debug_print("Configure Nominal SPEC_HK");
    mois_step("Configure Nominal SPEC_HK");
    PACS_Spec_HK_Setup();
    //
    debug_print("Configure DIAG_HK");
    mois_step("Configure DIAG_HK");
    PACS_Spec_Gra_Diaghk1khz_Setup();
    //
    debug_print("Configure/Enable/Home/Move/Disable Grating");
    mois_step("Configure/Enable/Disable Grating");
    string calUname = "CONFGrat";
    string calUrow = "IST";
    PACS_Spec_Gra_Cont_Check_4(calUname,calUrow);
    //
    mois_comment("Reset DIAG_HK");
    debug_print("Reset DIAG_HK");
    PACS_Diaghk_Reset();
    //
    debug_print("PACS to SAFE MODE");
    mois_comment("PACS to SAFE MODE");
    OBCP_SAFE();
    delay(10);
}

// File          : CONF_grating.cus
// Missionphase  : PACS FM ILT
//
// Purpose       : Prepare grating mechanism
//
// Author        : P. Royer
//
// Arguments     :  CALIBRATION TABLE (CONFGrat)
//		    ROW of CALU table (CONFGrat)
//		   	Row of this table = instrument version
//
// Description   : This script will switch on and set all required
//                 parameters for the grating
//                              
// Comments      :      
//
// Version       : 1.0
// History       : 1.0 / 13-Jun-2006 created from a non-calu-using script
//                 1.1 / 08-Nov-2006 Additional delay after setting the inductosyn amplitude
//		   1.2 / 09-Nov-2006 Homing always occurs with a rate of 3 (1 deg/sec), the rate is only set after
//                 1.2.1 17-nov-2006 Homing mode to 0 
//                 1.2.2 29-nov-2006 Homing mode to 1
//                 1.2.3 30-nov-2006 Homing back to 0
//
procedure CONF_grating {
    string calUname = "CONFGrat"; // GRATING CALIBRATION TABLE
    string calUrow = "ISTSafe"; // INSTRUMENT VERSION
}{
    //
    // Grating home mode: 0 = move to neg. positions; 1 = move to pos. positions
    int grat_home_mode = 0;
    // Grating central position (rough)
    int grat_center_pos = 500000;
    //
    //----------------------
    // CONTROLLER PARAMETERS  1. Force A SAFE HOMING RATE (3)
    //----------------------
    //
    int homing_mode_rate = 1;
    PACS_Spec_Gra_Set_Ctrl_Par(calUname,calUrow,homing_mode_rate);
    //
    //----------------------
    // ADDITIONAL PARAMETERS
    //----------------------
    //
    // ADDITIONAL PARAMS : 1. GRATING INDUCTOSYN AMPLITUDE
    //
    int induct_ampl = ilookup(calUname,calUrow,"InductAmpl");
    {int}[] list_tuple = [{induct_ampl}];
    int[] list_int = [induct_ampl];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_INDUC_AMPL(list_tuple,chksum);
    delay(1);
    //
    // ADDITIONAL PARAMS : 2. HALL SENSOR OFFSET
    //
    int hall_offset = ilookup(calUname,calUrow,"HallOffset");
    list_tuple = [{hall_offset}];
    list_int = [hall_offset];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_HALLOFFSET(list_tuple,chksum);
    delay(1);
    //
    // ADDITIONAL PARAMS : 3. GRATING RANGE
    //
    int range = ilookup(calUname,calUrow,"Range");
    list_tuple = [{range}];
    list_int = [range];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_RANGE(list_tuple,chksum);
    delay(1);
    //
    // DELAY NECESSARY FOR FM ILT (CAN BE SUPPRESSED IN FLIGHT, when correct value is defaulted in OBSW)
    // NECESSARY WAIT TIME AFTER SETTING THE AMPLITUDE
    //
    delay(180);
    //
    // ----------------------------
    // SWITCH ON GRATING CONTROLLER
    // ----------------------------
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    //
    // ENABLE GRATING CONTROLLER
    Pacs_DMC_ENABLE_GRAT_CONT();
    delay(1);
    //
    // ----------------
    // HOME THE GRATING
    // ----------------
    // Search for the origin and initialize the position encoder correctly
    // PARAM: 0 = move towards negative positions;
    //        1 = move towards positive positions;
    // Duration: max 70 sec (if the Grating param 'rate' is 3), 
    //           depending on the initial position of the grating.
    // Failure code: 0xAA: Grating controller is not enabled
    //
    string[] homeMode = ["NEGATIVE","POSITIVE"];
    Pacs_DMC_HOME_GRAT(homeMode[grat_home_mode]);
    delay(70);
    //
    //----------------------
    // CONTROLLER PARAMETERS  2. USE RATE FROM THE CHOSEN CALIBRATION TABLE
    //----------------------
    //
    homing_mode_rate = 0;
    PACS_Spec_Gra_Set_Ctrl_Par(calUname,calUrow,homing_mode_rate);
    delay(1);
    //
    //-------------------------
    // End of Procedure
    //-------------------------
}

// Script file   : PACS_Spec_Gra_IST_Check_1_OBS.cus 
//
// Purpose       :  Check the Stability of the grating under a given set of controller parameters
//
// Description  : Configuration of the grating, enable & disable the grating after a few seconds.
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
//                 1.1  13-Nov-2007 BV Added MOIS comments
//		   2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
procedure Pacs_Spec_Gra_IST_Check_1 {
}{
    mois_comment("Start of procedure: Configure the grating and enable for 5s (no homing)");
    // Register start of OBS
    //
    mois_step("Configure Nominal SPEC_HK");
    debug_print("Configure Nominal SPEC_HK");
    PACS_Spec_HK_Setup();
    //
    mois_step("Configure DIAG_HK");
    debug_print("Configure DIAG_HK");
    PACS_Spec_Gra_Diaghk1khz_Setup();
    //
    debug_print("Configure/Enable/Disable Grating");
    mois_step("Configure/Enable/Disable Grating");
    string calUname = "CONFGrat";
    string calUrow = "IST";
    PACS_Spec_Gra_Cont_Check_1(calUname,calUrow);
    //
    mois_step("Reset DIAG_HK");
    debug_print("Reset DIAG_HK");
    PACS_Diaghk_Reset();
    //
    mois_step("PACS to SAFE MODE");
    debug_print("PACS to SAFE MODE");
    OBCP_SAFE();
    delay(10);
}

// Script file   : PACS_Spec_Gra_IST_Check_2_OBS.cus 
//
// Purpose       :  Check the Stability of the grating under a given set of controller parameters
//
// Description  : Configuration of the grating, enable & disable the grating after two relative movements
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
//                 1.1  13-Nov-2007 BV : Mois comments
//		   2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
//
procedure Pacs_Spec_Gra_IST_Check_2 {
}{
    mois_comment("Start of procedure: Enable and perfom a few movements, disable (no homing)");
    // Register start of OBS
    //
    debug_print("Configure Nominal SPEC_HK");
    mois_step("Configure Nominal SPEC_HK");
    PACS_Spec_HK_Setup();
    //
    debug_print("Configure DIAG_HK");
    mois_step("Configure Nominal SPEC_HK");
    PACS_Spec_Gra_Diaghk1khz_Setup();
    //
    debug_print("Configure/Enable/Disable Grating");
    mois_step("Configure/Enable/Disable Grating");
    string calUname = "CONFGrat";
    string calUrow = "IST";
    PACS_Spec_Gra_Cont_Check_2(calUname,calUrow);
    //
    debug_print("Reset DIAG_HK");
    mois_step("Reset DIAG_HK");
    PACS_Diaghk_Reset();
    //
    mois_step("PACS to SAFE MODE");
    debug_print("PACS to SAFE MODE");
    OBCP_SAFE();
    delay(10);
}

// Mission phase : PV Phase
//
// Purpose : PCD req.1.1.1bis for the PV Phase
//           Measure the responsivity with a 8x4 raster on a point source (not SSO):
//           Noise is measured after the 8x4 raster at the off pointing position during "timeOFF".
//
// Author : Koryo Okumura
//
// Version : Wed Jul 29 12:16:22 EDT 2009
//
// CUS script : obs PacsCal_Phot_highGainBiasDDCS_Fix
//
// Argument :
//   string select = "ginit" in ["ginit","g2_0","g2_6","g3_0","binit","b2_0","b2_6","b3_0","final"]; // Select a configuration or initialize or finalize
//   double ra = 70.7235; // RA 4h42m53.64s
//   double dec = 36.1148; // Dec +36d06m53.4s
//   double raoff = 70.82; // OFF position RA coordinaten
//   double decoff = 36.21; // OFF position Dec coordinate
//   bool refSelected = true; // OFF position needed
//   int measure_time = 120; // measure time in seconds
//   int timeOFF = 480; // time of noise measurement in seconds on the OFF position
//   string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
//   string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
//   int nLoops1 = 30; // number of CSs cycles during slew
//   int nLoops5 = 30; // number of CSs cycles during final hold
//   int readouts_plateau = 64; // number of readouts per chopper plateau
//   string calGain = "HIGH" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//   bool chop = true; // Chopping within FOV during the raster
//   bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + PHOT_orbit_prologue is executed (then more than the minimum requirement below is fullfilled):
//     - Bolometers are biased
//     - Sequencer is activated
//
// Description : PacsCal script of Phot_highGainBiasDDCS
//   init + During the slew, CSs are measured through 2 filters
//        + Set a filter corresponding to the given seqNum
//        + Set the biases group by group
//   if no_chop
//        + Set the chopper on the optical center
//        + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group corresponding to the selected bias
//        + Do a 4x9 raster measurement
//   if chop
//        + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group corresponding to the selected bias
//        + Do a 4x8 raster with chopped measurement
//        + After the raster, noise measurement during 4xmeasure_time
//   then + After the raster, CSs and sky are measured through 2 filters
//   stop + The biases are set following a given bias table
//
// Dependencies : Commissioning and PV data at low gain of PCD req.1.1.1
// Comment : SCR PACS-1872
//
// Comments : generated by IA script : cus_PVph_highGainBias(0)
//
obs PacsCal_Phot_highGainBiasDDCS_Fix {
    string select = "ginit" in ["ginit","g2_0","g2_6","g3_0","binit","b2_0","b2_6","b3_0","final"]; // Select a configuration
    double ra = 70.7235; // RA 4h42m53.64s
    double dec = 36.1148; // Dec +36d06m53.4s
    double raoff = 70.82; // OFF position RA coordinaten
    double decoff = 36.21; // OFF position Dec coordinate
    bool refSelected = true; // OFF position needed
    int measure_time = 120; // measure time in seconds per pointing
    int timeOFF = 480; // time of noise measurement in seconds on the OFF position
    string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
    string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 64; // number of readouts per chopper plateau
    string calGain = "HIGH" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    bool chop = true; // Chopping within FOV during the raster
    bool verbose = true;
}{
    bool execute = true;
    int nRdts = readouts_plateau - 1;
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = duration(PHOT_change_biases(endBiasTable,calMode,calGain));
    int timeBckBias = 0;
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,"DDCS","HIGH"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,calMode,"HIGH"));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,"DDCS",calGain));
    }
    int timeCal3CPR1 = duration(OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644));
    int tNewSetup = duration(Phot_highGainBiasDDCS(select,startBiasTable,endBiasTable));
    int tslewmin = 0;
    int tih = 0;
    int tfh = 0;
    // Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // SSO tracking object number
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // zoffset [arcsec] : Finally we do not risk to provoke the opposite correction
    double zoffset = 0.0;
    // Duration of "stable" pointing in seconds
    int tp = 0;
    //Issue PointReq
    int[] ts = [0];
    if(select == "ginit" || select == "binit" || select == "final") {
        // Several arguments needed for "basic_fine_pointing"
        // time to set OBSID and biases then PacsPhotSlewCal
        // Minimum slew time
        if(select == "final") {
            timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
        } else {
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,"DDCS","HIGH"));
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,"DDCS",calGain));
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"HIGH"));
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
            }
        }
        tslewmin = timeOBSID + timeChgBias + timeCal3CPR1 + tNewSetup;
        if(verbose) {
            debug_print("Tslewmin: " + tslewmin);
        }
        // Initial hold
        tih = 0;
        // Final hold
        tfh = timeEndID;
        // Duration of "stable" pointing in seconds
        tp = 1;
        //Issue PointReq
        ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    } else {
        // Several arguments needed for "basic_raster_pointing"
        // time to set and reset BBID
        int timeBBID = imax(1,duration(TMMarker601()) + duration(TMMarker600()));
        // time to set OBSID and biases then PacsPhotSlewCal
        int timeCal3CPR5 = duration(OBCP_chopped_photometry(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,644));
        // Minimum slew time
        tslewmin = timeOBSID + timeChgBias + timeBckBias + tNewSetup + timeCal3CPR1;
        if(verbose) {
            debug_print("Tslewmin: " + tslewmin);
        }
        // Initial hold
        tih = 0;
        // Final hold
        tfh = timeChgBias + timeCal3CPR5 + timeEndID;
        // Fixed in the sky coordinates
        bool fixed = false;
        // Orientation angle (degrees)
        double patt = 0.0;
        // Number of pointings in a leg
        int m = 4;
        // Number of legs
        int n = 8;
        // Angular distance (arcsec) between 2 pointings
        double d1 = 26.0;
        // Angular distance (arcsec) between 2 legs
        double d2 = 26.5;
        // Duration of "stable" pointing in seconds
        if(chop) {
            int nLoops = measure_time * 40 / (2 * readouts_plateau);
            tp = duration(OBCP_chopped_photometry(0,0,nRdts,0,0,nLoops,1,-6578,7756,0,0,644));
            // Positive pointing offset for chopping to get negative chopper position offset
            yoffset = 105.0;
        } else {
            tp = measure_time;
        }
        // Go to OFF position every k pointings (not relevant with SSO tracking)
        int k = m * n;
        // time in seconds on the OFF position (not relevant with SSO tracking)
        int top = timeOFF + timeBBID;
        //Issue PointReq
        ts = basic_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,k,top,raoff,decoff);
    }
}{
    int tNOW = time();
    int[] state = [0];
    if(select == "ginit" || select == "binit" || select == "final") {
        //  Start the sequence
        while(state[0] >= 0) {
            state = next_state();
            tNOW = time();
            if(state[0] == 1) {
                if(verbose) {
                    debug_print("SLEW starts at " + tNOW);
                }
                // Set OBSID
                WriteOBSID($OBSID);
                data_rate(120.0);
                // Set biases and start SPU
                if(select == "final") {
                    PHOT_change_biases(calBiasTable,calMode,calGain);
                } else {
                    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,"DDCS","HIGH");
                    }
                    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,"DDCS",calGain);
                    }
                    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,calMode,"HIGH");
                    }
                    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,calMode,calGain);
                    }
                }
                //************************************
                //  Call the Phot_highGainBiasDDCS
                //************************************
                Phot_highGainBiasDDCS(select,startBiasTable,endBiasTable);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                tNOW = time();
                if(verbose) {
                    debug_print("SLEW ends at   " + tNOW);
                }
            }
            if(state[0] == 2) {
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 3) {
                tNOW = time();
                if(verbose) {
                    debug_print("POINT starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("POINT ends at     " + tNOW);
                }
            }
            if(state[0] == 5) {
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD starts at   " + tNOW);
                }
                // Write EndID
                data_rate(0.0);
                WriteEndID();
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD ends at     " + tNOW);
                }
            }
        }
    } else {
        int finalChop = 0;
        //  Start the sequence
        while(state[0] >= 0) {
            state = next_state();
            tNOW = time();
            if(state[0] == 1) {
                if(verbose) {
                    debug_print("SLEW starts at " + tNOW);
                }
                // Set OBSID
                WriteOBSID($OBSID);
                data_rate(120.0);
                // Set biases and start SPU
                PHOT_change_biases(calBiasTable,calMode,calGain);
                //*******************************
                // Configure for the measurement
                //*******************************
                if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,"DDCS","HIGH");
                }
                if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,calMode,"HIGH");
                }
                if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,"DDCS",calGain);
                }
                //************************************
                //  Call the Phot_highGainBiasDDCS
                //************************************
                Phot_highGainBiasDDCS(select,startBiasTable,endBiasTable);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                tNOW = time();
                if(verbose) {
                    debug_print("SLEW ends at   " + tNOW);
                }
            }
            if(state[0] == 2) {
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 3) {
                tNOW = time();
                if(verbose) {
                    debug_print("POINT starts at   " + tNOW);
                }
                if(chop) {
                    //*********************************
                    // 2 positions chopping in the FOV
                    //*********************************
                    OBCP_chopped_photometry(0,0,nRdts,0,0,nLoops,1,-6578,7756,0,0,-6578);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("POINT ends at     " + tNOW);
                }
            }
            if(state[0] == 4) {
                tNOW = time();
                if(verbose) {
                    debug_print("OFF pointing starts at   " + tNOW);
                }
                //********************************
                // OFF position noise measurement
                //********************************
                TMMarker601();
                delay(timeOFF);
                TMMarker600();
                tNOW = time();
                if(verbose) {
                    debug_print("OFF pointing ends at     " + tNOW);
                }
            }
            if(state[0] == 5) {
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD starts at   " + tNOW);
                }
                // Set biases and start SPU
                PHOT_change_biases(calBiasTable,calMode,calGain);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                // Write EndID
                data_rate(0.0);
                WriteEndID();
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD ends at     " + tNOW);
                }
            }
        }
    }
}

// Mission phase : ILT at Garching
//
// Purpose : Set the direct mode of the PACS bolometer
//
// Author : Koryo Okumura
//
// CUS script : procedure PhotSetDirectMode
//
// Argument : None
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//
// Description :
//
// Dependencies : None
//
// Comments : This script has been written to recover the direct mode
//
// Version : Thu Dec 07 2006
//
procedure PhotSetDirectMode {
}{
    //********************************************************
    // Sequence mode : blocking on VDEC_X for the direct mode
    //********************************************************
    //
    // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
    // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
    //
    //**************************
    // Sequence mode : Sref_only
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
    //# P 09 01 00 01
    int operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
}

// Missionphase  : IMT
//
// Purpose	:  Performance Test of internal PACS calibration sources
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We start with a heat-up of the calibration sources. 
//                     After monitoring for some while the behaviour on the desired temperature of
//                     both internal PACS calibration sources, we do a smaller heat-up which is followed 
//                     by a cooling down. The monitoring is based on diag. HK. 
//                     PTD 0.7.11 and 0.7.12 are the basis for this test. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy 
//                 
// Comments	: This script is based on the commanding during the CQM ILT Tests. 
//
// Version	: 1.0	
// 
// History 	: 1.0 Retuned on IST requirements.
block SPEC_CS_imt511_bb PACS 380 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //-------------------------------------------- 
    //------------------------------------------------------------------------------
    // Heat the calibration sources up to 48 (55K;CS1) and 58 
    // (60.0K;CS2) Ohm --- big step
    //------------------------------------------------------------------------------
    // start temperature CS1 in Ohm
    double cs1_temp = 48.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // start temperature CS2 in Ohm 	
    double cs2_temp = 58.0;
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    // Assume that CSs are on since long and already stabilized, monitor them for 5 minutes only
    delay(300);
    //--------------------------------------------------------------------------------
    // Heat the calibration sources up to 53 and 63 Ohm --- small step
    //--------------------------------------------------------------------------------
    cs1_temp = 53.0;
    cs2_temp = 63.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    //After 30 minutes of heating-up and stay on the desired temperatures do cooling-down
    delay(1800);
    //------------------------------------------
    // Cool both calibration sources down to 39 (50.5K) 
    //------------------------------------------
    cs1_temp = 39.0;
    cs2_temp = 39.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    // Cool down for about 30 minutes
    delay(1800);
    //------------------------------------------
    // Go to default values of 48 (CS1) and 58 (CS2) 
    //------------------------------------------
    cs1_temp = 48.0;
    cs2_temp = 58.0;
    // Set the temperature of the black body 1
    Pacs_DMC_SET_TEMP_BB_1(cs1_temp);
    // Set the temperature of the black body 2
    Pacs_DMC_SET_TEMP_BB_2(cs2_temp);
    // Mark End of Block
    WriteEndBB();
}

// Missionphase  : 
// Purpose       : Stop SPECtroscopy observations at end of AOT
//                  
// TCL author    : 
// TCL file      : 
// CUS author    : Diego Cesarsky
// Script file   : SPEC_aot_epilogue.txt 
//
// Input arguments
// Type Name           Default   Description
//
// Description   : Not much for now (just STOP SPU)
//                 Move grating from wwwhere OBCPs left it to the park
//                 position
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      : Based on V1.3 of TM's tm_spu_setup.tcl. Both
//                 SPUS and SPUL are initialized to same set of parameters
//
// Version       : 1.0
// History       : 0.1 cloned from SPEC_aot_epilogue
//                 PHS-1164
//                 
// 
block Pacs_SPEC_aot_epilogue PACS 1120 {
    int gratFrom = 500000; // Where OBCPs have left the grating
    int gratTo = 535000; // Grating park position
    bool verbose = false;
}{
    // Register start of BB
    WriteBBID($BBID);
    // Park the grating
    SPEC_grat_move(gratFrom,gratTo,verbose);
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    data_rate(0.0);
    //Reset Block ID
    WriteEndBB();
    // Sync the bus (function duration will get the "true" duration)
    sync();
    // end of procedure
}

// File          : PACS_Spec_Gra_Mec_Setup_Cold.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Prepare grating mechanism for cold test
//
// Author        : T. Mueller, P. Royer, H. Feuchtgruber
// CUSification  : DAC
// Arguments     : none
//
// Description   : This script will switch on and set all required
//                 parameters for the grating
//                              
// Comments      :      
//
// Version       : 1.0
// History       : 1.0 / 15-Nov-2004 adapted from spec_mec_setup.tcl v1.3
//                 1.1    7-mar-2006 GRAT_INDUCT renamed
//                 1.2    7-apr-2006 homeMode changed to [NEG,POS]
//                                   Add synch on detector
//                                   Removed INDUC command
//
procedure PACS_Spec_Gra_Mec_Setup_Cold {
}{
    // Grating home mode: 0 = move to neg. positions; 1 = move to pos. positions
    int grat_home_mode = 0;
    // Grating central position (rough)
    int grat_center_pos = 500000;
    // Add synchronize on BOLO readout to insure that grating moves (see DEC/MEC
    // status bit DMC_GRAT_CTRL_ST bit 27)
    // Apparently the grating homes only if a synch source is defined
    // Synch on BOLO readouts (4)
    Pacs_DMC_SYNCHRONIZE_ON_DET_RAW(4);
    //-------------------------------------
    // GRATING (cold controller parameters)
    //-------------------------------------
    // PC162420 "DMC_WRT_GRAT_CONF_PAR" WRITE THE PARAMETERS TO CONFIGURE THE
    // GRATING SERVO LOOP
    //         Fixed GroupSize: 1, repetition: 9
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // set grat_par [list [list PP067420 [expr 0x250]] \
    //                   [list PP067420 [expr 0x2710]] \
    //                   [list PP067420 [expr 0x5]] \
    //                        {PP067420 0} \
    //                   [list PP067420 [expr 0x3]] \
    //                   [list PP067420 [expr 0x51EAE1]] \
    //                   [list PP067420 [expr 0x3331]] \
    //                   [list PP067420 [expr 0x800]] \
    //                  [list PP067420 [expr 0x7FFFFFFF]]]
    // set chksum [getChkSum -d -32 $grat_par]
    // eval tcsend PC162420 $grat_par \{PP066420 $chksum\}
    // waittime 0.5
    {int}[] list_tuple = [{0x250},{0x2710},{0x5},{0x0},{0x3},{0x51eae1},{0x3331},{0x800},{0x7fffffff}];
    int[] list_int = [0x250,0x2710,0x5,0x0,0x3,0x51eae1,0x3331,0x800,0x7fffffff];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_GRAT_CONF_PAR(list_tuple,chksum);
    // PC108420 "DMC_SWON_GRAT_CONT" SWITCH ON GRATING CONTROLLER
    // tcsend PC108420
    // waittime 0.5
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    // PC203420 "DMC_WRT_GRAT_INDUCT_SIGN" REVERSE THE SIGN OF THE INDUCTOSYN
    // POSITION READOUT
    //	PP067420 "DMC_4_BYTES_WORDS_DATA"
    //	PP066420 "DMC_CHECKSUM"
    int induct_par = 1;
    list_tuple = [{induct_par}];
    list_int = [induct_par];
    chksum = checksum("int",list_int);
    // eval tcsend PC203420 $induct_par \{PP066420 $chksum\}
    // waittime 0.5
    ///    Pacs_DMC_WRT_GRAT_INDUC_AMPL(list_tuple,chksum);
    ///    delay(1);
    // PC110420 "DMC_ENABLE_GRAT_CONT" ENABLE GRATING CONTROLLER
    // tcsend PC110420
    // waittime 0.5
    Pacs_DMC_ENABLE_GRAT_CONT();
    delay(1);
    // PC114420 "DMC_HOME_GRAT" MOVE GRATING TO THE HOME POSITION
    //         PP077420 "HOMING_MODE"
    // Search for the origin and initialize the position encoder correctly
    // PARAM: 0 = move towards negative positions;
    //        1 = move towards positive positions;
    // Duration: max 70 sec (if the Grating PID is 3), depending on the
    //           initial position of the grating.
    // Failure code: 0xAA: Grating controller is not enabled
    //tcsend PC114420 [list PP077420 $grat_home_mode]
    // waittime 70
    string[] homeMode = ["NEGATIVE","POSITIVE"];
    Pacs_DMC_HOME_GRAT(homeMode[grat_home_mode]);
    delay(70);
    // PC112420 "DMC_MOVE_GRAT_ABS" MOVE GRATING TO AN ABSOLUTE POSITION
    //        PP079420 "SET_POINT"
    // tcsend PC112420 [list PP079420 $grat_center_pos]
    // waittime 30
    Pacs_DMC_MOVE_GRAT_ABS(grat_center_pos);
    delay(30);
    //-------------------------
    // End of Procedure
    //-------------------------
}

// File          : PACS_Spec_Flash_SFT_Warm.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Flashers Short Functional Test
//
// Author        : P. Royer
//
// Arguments     :
//
// Description   : Sends current to both flashers for short times, the goal is only to see some reaction in the HK
//
//
// Prerequisite : The flashers are SWITCHED ON ALREADY
//	  	  The correct HK & Diaghk lists are already set & acquired
//
// Comments      : 
//                 
//
// Version       : 2.0
// History       : 1.0 / 08-Jun-2006 initial version by PR
//		   1.1 / 09-Oct-2006 replacement 1mA -> 0.05mA
//		   2.0 / 13-Feb-2008 Made into a proc to be called by
//		       	 PV standard "obs" PacsEng_Spec_Flash_SFT_Warm
//			 removed call for WriteOBSID/WriteEndID
//		
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose Flashers Short Functional Test
// @comment - 
//
procedure PACS_Spec_Flash_SFT_Warm {
}{
    //
    // 0.05 mA  -> 0.1 mA  ->  0.0 mA
    //
    PACS_Spec_Flash_Setup(10,10);
    delay(30);
    PACS_Spec_Flash_Setup(20,20);
    delay(30);
    PACS_Spec_Flash_Setup(0,0);
    delay(30);
    //
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       : Perform Setup Spectroscopy with redundant control parameters
//
// CUS author    : BV
//
// Input arguments
// type     name         description
// string   fltPOS         Initial filter wheel position
// double temp_CS1  Calibration source 1 temperature (resistance value)
// double temp_CS2  Calibration source 2 temperature (resistance value)
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform PACS setup for spectroscopy with redundant control parameters
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 2.0
// 
// History       : 1.0 BV 10-04-2007 Initial version based on SPEC_setup_OBS
// History       : 2.0  04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_setup_redundant {
    /* Needed variables to call PacsEng_Spec_setup_redundant                        */
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double temp_CS1 = 48.0;
    double temp_CS2 = 58.0;
    double blu_heater_curr = 0.78; // Heater current [mA]
    /* End of needed variables for PacsEng_Spec_setup_redundant                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_setup_redundant(fltPOS,temp_CS1,temp_CS2,blu_heater_curr)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_setup_redundant(fltPOS,temp_CS1,temp_CS2,blu_heater_curr);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id $
// Description :
//
// Dependencies  : 
//
// Comments      : Follows verbatim paragraph 4.2.10 in PACS-ME-LI-005
//                 version 1.6
//         Actual values of input parameters, except values for the
//         various loop counters, are completely irrelevant and so
//         are not used.
//         Loop counters are used to estimate the duree of the
//         sequence
//
// Version       : 0.1 15-oct-2007 Creation by DAC
// History       : 0.2 26-mar-2009 DAC Removed low-hi information
//                 1.0  4-jun-2009 DAC Adapted for new OBCP32 (in order not
//                                 to change the nb of parameters, some of
//                                 them have become useless)
//
// This debugging DEC/MEC computes grating positions
procedure PacsDebug_wave_switch {
    int pos = 1000; // Grating start position
    int nb_dither_steps = 7; // number of dithering steps
    int nbABBA = 3; // nb of ABBA cycles
    int ditherSize = 300; // dither size
    int param4 = -2000; // dummy
    int param6 = -2000; // dummy
    int param7 = 700; // Amplitude of A->B jump
    int param8 = 0; // P#8
}{
    // To achieve ABBA
    int param5 = 0;
    param8 = 0;
    int param9 = -param7;
    int param11 = -ditherSize;
    // OBCP moves grating to
    int grat = pos;
    debug_print("----WaveSwitch starts at: " + grat);
    // Pseudo code from PACS OBCPs and DMC Sequences (4.2.10)
    // There is the outermost nb_up_down loop not considered here
    // WAIT 1 ; have a defined start
    // LABEL 0 ; set Label to 0
    // LOOP P1                           main loop for nb_up_dn
    // LOOP P2                       number of shifts up
    for(int outLOOP = 1 .. nb_dither_steps) {
        //   WAIT 1                         sync. for chopper
        //   MOVE_GRATING_RELATIVE P2       move grating by P3 (dither size)
        grat = grat + ditherSize;
        debug_print("UpDither loop: " + outLOOP + "; grating at: " + grat);
        //   LOOP P4                        nbABBA times core loop
        for(int inLOOP = 1 .. nbABBA) {
            //        MOVE_GRATING_RELATIVE P5    move grating by P5
            grat = grat + param5;
            debug_print("----A (up): " + grat);
            //        MOVE_GRATING_RELATIVE P7    move grating by P7
            grat = grat + param7;
            debug_print("----B (up): " + grat);
            //        MOVE_GRATING_RELATIVE P8    move grating by P8
            grat = grat + param8;
            debug_print("----B (up): " + grat);
            //        MOVE_GRATING_RELATIVE P9    move grating by P9 (-P7)
            grat = grat + param9;
            debug_print("----A (up): " + grat);
            //   END_LOOP nbABBA
        }
        // END_LOOP P2
    }
    // LOOP P10                number of shifts down
    for(int outLOOPdn = 1 .. nb_dither_steps) {
        //   WAIT 1                         sync. for chopper
        //   MOVE_GRATING_RELATIVE P2       move grating by -P3 (-dither size)
        grat = grat - ditherSize;
        debug_print("DnDither loop: " + outLOOPdn + "; grating at: " + grat);
        //   LOOP P4                        nbABBA times core loop
        for(int inLOOPdn = 1 .. nbABBA) {
            //        MOVE_GRATING_RELATIVE P5    move grating by P5
            grat = grat + param5;
            debug_print("----A (down): " + grat);
            //        MOVE_GRATING_RELATIVE P7    move grating by P7
            grat = grat + param7;
            debug_print("----B (down): " + grat);
            //        MOVE_GRATING_RELATIVE P8    move grating by P8
            grat = grat + param8;
            debug_print("----B (down): " + grat);
            //        MOVE_GRATING_RELATIVE P9    move grating by P9 (-P7)
            grat = grat + param9;
            debug_print("----A (down): " + grat);
            //   END_LOOP nbABBA
        }
        // END_LOOP P2
    }
    // WAIT 1                            complete last plateau
    // LABEL 0                           no sequence anymore
    // END_SEQUENCE
}

// File          : PACS_Spec_Heat_SFT.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Heaters Short Functional Test
//
// Author        : P. Royer
//
// Arguments     :
//
// Description   : Sends current to both heaters for short times, the goal is only to see some reaction in the HK
//
//
// Prerequisite : The heaters are SWITCHED ON ALREADY
//	  The correct HK & Diaghk lists are already set & acquired
//
// Comments      : 
//                 
//
// Version       : 2.0
// History       : 1.0 / 08-Jun-2006 initial version by PR
// 		   2.0 / 14-Feb-2008 Made into a procedure to be called 
//		       by PacsEng_Spec_Heat_SFT	 
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose Heaters Short Functional Test
// @comment - 
//
procedure PACS_Spec_Heat_SFT {
}{
    // 0.1mA  -> 1.0 mA  ->  0.0 mA
    //
    PACS_Spec_Heat_Setup(20,20);
    delay(30);
    PACS_Spec_Heat_Setup(205,205);
    delay(30);
    PACS_Spec_Heat_Setup(0,0);
    delay(30);
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Purpose	: Setup SPU for photometry data flow
// Author	: DAC
//
// Arguments	: 
//
//                (optionally) starts reduction/compression
//                  
// Dependencies : 
//
// Comments	:
//
// Version	: 2.0               
// History	: 1.0 10-nov-2006 DAC
//                1.1 13-nov-2006 Start SPU
//                1.2  4-apr-2007 nraw = 0
//		  2.0 04-mar-2008 translated into PV script VDP
//
obs PacsEng_Phot_spu_setup {
    /* Needed variables to call PacsEng_Phot_spu_setup                        */
    /* Compression modes: default=0, double=1, half=2, lossless=4 */
    /*                    transp=7, buffer=9                      */
    int comp_mode_blu = 0;
    int comp_mode_red = 0;
    int nraw_blu = 0; // Number of raw channels blue SPU
    int nraw_red = 0; // Number of raw channels red SPU
    bool startSPU = true; // Start SPU or not [true,false]
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_spu_setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,startSPU)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,startSPU);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase     : PV phase
//
// Purpose          : Wavelength calibration and instrumental profile
//                    Source is observed chopping/nodding
//
// CUS author       : DAC, based on WaveCalNoChop
// Script file      : WaveCalChop.txt
//
//
// Description      : Uses OBCP27 for executing a parameterized scan of any length, stepsize etc.
//                   Represents a generic nchopped grating scan
//
// Dependencies     : SPEC_heater, SPEC_cre_setup
//
// Preconditions    : PACS must be on and configured for spectroscopy
//
// Comments         : Can be run for wavelength calibration, instrumental profile and ghost search
// Version          : 0.3
// History    	      : 0.1 21-sep-2007 DAC adapted from WaveCalNoChop
//                            0.2 23-jul-2009 BV SPR PACS-1798: default bias settings
//                           0.3 22-Sep-2009 HF moved reset SPU to the begin	  	       
//
procedure WaveCalChop {
    string fltPOS = "POS A"; // Filter wheel position (0="POS A", 1="POS B")
    int grat_pos = 500000; // grating start position for scan
    int grat_time = 0; // Grating time to move to start [msec]
    int grat_step_up = 200; // grating step size
    int grat_step_dn = 200; // grating steop size down
    int nb_grat_steps = 50; // number of grating steps in one direction
    int nb_CS1_CS2 = 0; // nb of cycles on internal CS
    int nb_rdouts_ramp = 64; // number of readouts per ramp
    int nb_ramps_plateau = 1; //Nb of readouts per chopper position
    int nb_up_down = 1; // number of grating updown scans
    int capa_red = 0; // Red capacitor
    int capa_blu = 0; // Blue capacitor
    double bias_r_blu = 0.01; // Bias "r" blue
    double bias_r_red = 0.01; // Bias "r" red
    double bias_d_blu = 0.1; // Bias "d" blue
    double bias_d_red = 0.042; // Bias "d" red
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp
    int nb_SRC_REF = 3; // nb of cycles (ramps) per grating position
    double chopthrow = 30.0;
    int detector = 1; // 1= blue detecor 2=red detector
}{
    // Reset SPU
    SPEC_spu_reset();
    // Condition the CREs and detectors
    int ramp_len_blu = nb_rdouts_ramp;
    int ramp_len_red = nb_rdouts_ramp;
    // Set up the blue and red CRE subsystem
    // cre_ctrl is a bit field:
    // 256=sync width=2, 128=T sensor on, 2=enable, 1=power on
    // Do not enable yet
    int cre_ctrl_red = 256 + 128 + 2 + 1;
    int cre_ctrl_blu = 256 + 128 + 2 + 1;
    SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // Set BLUE heater parameters (mA)
    double heater_blu = 0.78;
    SPEC_heater_setup(heater_blu);
    //
    // SPU parameters
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]  
    // Re-start SPU in default mode
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Move the filter wheel
    SPEC_fltw_move(fltPOS);
    // Get CSn positions from dedicated CAL-U file
    double ref1 = chopthrow / 2.0;
    double ref2 = -chopthrow / 2.0;
    int chop_pos_REF1 = PacsReadChopSky("SPEC_CHOP_sky",ref1);
    int chop_pos_REF2 = PacsReadChopSky("SPEC_CHOP_sky",ref2);
    int chop_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    //     int grat_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating"); 
    //     grat_def should be grat_pos in this case
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","SPEC","pos_CS1");
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    int grat_def_time = 0;
    // Time to come back to default position set to 0
    //                           because grating already in position
    //
    int[] duree3 = OBCP_grat_scan_chop2(nb_up_down,nb_grat_steps,nb_SRC_REF,chop_pos_REF1,nb_ramps_plateau,chop_pos_REF2,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_up,grat_step_dn,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_pos,chop_def,grat_def_time,nb_rdouts_ramp);
    // Reset SPU
    SPEC_spu_reset();
}

// Missionphase  : FM
//
// Purpose       : Exercise OBCP for chopped photometry
//                  
//                 
//
// TCL author    : N/A
// TCL file      : N/A
// CUS author    : TM
// Script file   : OBCP_chopped_photometry_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Exercise OBCP for chopped photometry
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version      0.1
// History      0.1 09-oct-2006 TM
//
procedure Pacs_OBCP_chopped_photometry {
    int nb_SRC_REF = 8; // p01 Number of observations in OBS loop
    int chop_pos_SRC = 1000; // p02 Chopper position for SRCE
    int nb_rdouts_plateau = 39; // p03 Number of readouts per chopper position 
    int chop_pos_REF1 = -2000; // p04 Chopper position for BKG1
    int chop_pos_REF2 = 5000; // p05 Chopper position for BB2
    int nb_cycles_obs_cal = 2; // p06 Number of obs/cal cycles
    int nb_CS1_CS2 = 2; // p07 Number of observations in CAL loop
    int chop_pos_CS1 = -25000; // p08 Chopper position for CS1
    int chop_pos_CS2 = 25000; // p09 Chopper position for CS2
    int comp_mode_blu = 0; // Compression mode BLUE channel
    int comp_mode_red = 0; // Compression mode RED channel
    int chop_def = 0; // Chopper default position
}{
    // Register with environment
    // Start SPU
    int nraw_blu = 3;
    int nraw_red = 3;
    PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,true);
    //
    // Position the filter wheel at POS A
    //
    PHOT_fltw_move("POS A");
    //
    // Perform OBCP_chopped_photometry with default parameters
    debug_print("Start OBCP_chopped_photometry");
    int[] duree = OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
    delay(2);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    //
    // Position the filter wheel at POS B and repeat everything
    //
    PHOT_fltw_move("POS B");
    // Perform OBCP_chopped_photometry with default parameters
    debug_print("Start OBCP_chopped_photometry");
    duree = OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
    delay(2);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    //
    // Position the filter wheel at POS A
    //
    PHOT_fltw_move("POS A");
    //
    // Stop SPU 
    //
    PACS_spu_reset();
    sync();
}

// File          : Pacs_Spec_GeGa_Loop_Comm.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Ge:Ga detector Loop
//
// Author        : P. Royer
// CUS script	 : PR
// CVS file	 :
//
// Arguments     : bias, integration time, capacity, measurement time, resistor bias
//
// Description   :   Loop over bias, integration time and capacity.
//
// Dependencies  : - SPEC_CRE_No_Heater_setup
//		   - SPEC_spu_setup
//		   - PACS_Chop_Move_Abs
//		   - SPEC_spu_reset
//
// Comments      : The input arrays for bias, ramp length & capacitance must have the same length for red & blue
//
// Version       : 1.0
// History       : 1.0 / 20090608 PR, based on Pacs_Spec_GeGa_Loop_Comm
//
procedure Pacs_Spec_BufferTransmission_Loop {
    int repeat_global = 2; // Global repetition factor (main loop)
    int repeat_intern = 1; // Repetition factor inside the bias loop (ramplen+capa loops)
    double[] bias_blue = [0.06,0.08,0.1,0.12]; //bias blue
    double[] bias_red = [0.03,0.04,0.05,0.06]; //bias red red
    int[] ramp_len_blue = [32,64]; //ramp length blue (set integration time)
    int[] ramp_len_red = [32,64]; //ramp length red (set integration time)
    int[] capa_blue = [8,12]; //capacity blue
    int[] capa_red = [8,12]; //capacity red
    int meas_time = 360; //observing time in seconds per setting
    double bias_res_blue = 0.01; //resistor bias blue
    double bias_res_red = 0.01; //resistor bias red
    int chop_pos = 0; // chopper position
    int grat_pos = 737500; // grating position
    string filter_pos = "POS B" in ["POS A","POS B"]; // FW position
}{
    // Begin of Script
    // define variables
    int idle_time = 360;
    if(repeat_intern > 1) {
        idle_time = 60;
    }
    // Position the filter wheel
    // =========================
    SPEC_fltw_move(filter_pos);
    // delay is contained in the procedure
    //
    // Position the grating
    // ====================
    Pacs_DMC_MOVE_GRAT_ABS(grat_pos);
    delay(15);
    //
    // Position the chopper
    // ====================
    PACS_Chop_Move_Abs(chop_pos);
    delay(1);
    //
    // Declare the set of CRE variables
    // ================================
    double bias_d_blue = bias_blue[0];
    double bias_d_red = bias_red[0];
    int ramp_blue = ramp_len_blue[0];
    int ramp_red = ramp_len_red[0];
    int capacity_blue = capa_blue[0];
    int capacity_red = capa_red[0];
    // 
    //
    // DPU SETUP -> BURST MODE
    //
    Pacs_DPU_SET_BUS_LIST("ENABLE");
    //
    // SPU SETUP
    //
    int comp_mode_blu = 0x19;
    // Compression mode blue channel: BUFFER TRANSMISSION
    int comp_mode_red = 0x19;
    // Compression mode red channel: BUFFER TRANSMISSION
    int nb_samp_subramp_blu = ramp_blue;
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = ramp_red;
    // Nb of red samples per sub-ramp
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    delay(5);
    //
    // determine length of arrays
    int bb = length(bias_blue);
    //length of bias blue
    int rlb = length(ramp_len_blue);
    //length of ramp length blue
    int cb = length(capa_blue);
    //length of capacity blue
    // 
    // MAIN LOOP
    //
    int iteration = 0;
    while(iteration < repeat_global) {
        //
        // BIAS LOOP
        //
        int blc = 0;
        while(blc < bb) {
            bias_d_blue = bias_blue[blc];
            bias_d_red = bias_red[blc];
            //
            // INTERNAL LOOP
            //
            // (to be used e.g. to measure all settings once instead of just 
            // waiting a long 'idle_time' after each bias change)
            int internloop = 0;
            while(internloop < repeat_intern) {
                //
                // RAMP LENGTH LOOP
                //
                int rlc = 0;
                while(rlc < rlb) {
                    ramp_blue = ramp_len_blue[rlc];
                    ramp_red = ramp_len_red[rlc];
                    nb_samp_subramp_blu = ramp_blue;
                    nb_samp_subramp_red = ramp_red;
                    ramp_fit_alg = 1;
                    //
                    // CAPACITY LOOP 
                    //
                    int clc = 0;
                    while(clc < cb) {
                        capacity_blue = capa_blue[clc];
                        capacity_red = capa_red[clc];
                        //
                        // Setup CREs
                        SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red);
                        //
                        // Setup SPU
                        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
                        //
                        // if this is the first measurement with this bias -> delay
                        if(rlc == 0 && clc == 0 && internloop == 0) {
                            delay(idle_time);
                        }
                        //
                        // OBSERVATION 
                        delay(meas_time);
                        //
                        // SPU RESET
                        SPEC_spu_reset();
                        delay(1);
                        //
                        clc = clc + 1;
                    }
                    rlc = rlc + 1;
                }
                internloop = internloop + 1;
            }
            blc = blc + 1;
        }
        iteration = iteration + 1;
    }
    //
    //
    // Return Chopper & grating to default
    // ===================================
    Pacs_DMC_MOVE_GRAT_ABS(500000);
    delay(1);
    PACS_Chop_Move_Abs(0);
    delay(15);
    //
    // DPU SETUP -> CANCEL BURST MODE
    //
    Pacs_DPU_SET_BUS_LIST("DISABLE");
    //
    // SYNC
    //= = =
    sync();
    //
    // End of Script
}

// File          : PACS_Phot_Cold_Startinputsignal.cus
// Missionphase  : PACS FM Test
//
// Purpose       : BOLC starting the input signal for cold (2-4K) environment
//
// Author        : T. Mueller
// CUSification  : DAC
// Arguments     : none
//
//
// Description   : See PhFPU UM, draft 5, chapter 4.2.5
//
// Comments      :  Coded based on PhFPU UM, draft 5, chapter 4.2.5
//
// Version       : 1.5
// History       : 1.0 / 18-Nov-2004 initial version by TM
//                 1.1    7-mar-2006  TC SEND_COMMAND_TO_BOLC renamed
//                 1.2   11-aug-2006 TM update for PhFPU UM, draft 5, chapter 4.2.5
//                 1.3   27-oct-2006 OB (!) updated according to equivalent 300K test, increased wait times from 5 to 10 seconds
//                 1.4   08-nov-2006 TM update for SPU stop/start and wait times
//                 1.5   13-nov-2006 TM wait time after GND_BU increased to 3 sec
//
procedure PACS_Phot_Cold_Startinputsignal {
}{
    // ---------------------------------------------
    // Functional tests at 4K and 2K
    // ---------------------------------------------
    // start recording TM
    //# S 09
    // Set data mode Bolo & HK
    //# P 09 02 00 01
    int operand = 0x9020001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Reset bias all groups
    //# P 00 00 00 00
    operand = 0x0;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Validate TM recording
    //# S 09
    delay(20);
    // Set all groups bol bias 22 (VDD-PROT-BU) ON (1)
    //# P 00 16 0001
    operand = 0x160001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 21 (VDD-PROT-CL) ON (1)
    //# P 00 15 0001
    operand = 0x150001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 23 (GND-BU) ON (1)
    //# P 00 17 0001
    operand = 0x170001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(3);
    // Set all groups bol bias 05 (VCH) to 0.00000000 Volt (0)
    //# P 00 05 0000
    operand = 0x50000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 19 (VGL-BU) to 2.60000000 Volt (2125)
    //# P 00 13 084D
    operand = 0x13084d;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 18 (VDL-BU) to 4.20000000 Volt (3435)
    //# P 00 12 0D6B
    operand = 0x120d6b;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 17 (VSS-BU) to 1.50000000 Volt (1227)
    //# P 00 11 04CB
    operand = 0x1104cb;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // Start of BU test
    // ---------------------------------------------
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    TMMarker601();
    // ---------------------------------------------
    // Set seq mode Sref only
    //# P 09 01 00 01
    operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // ---------------------------------------------
    // Set all groups bol bias 15 (VGG) to 0.00000000 Volt (1)
    //# P 00 0F 0001
    operand = 0xf0001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set gain low
    //# P 08 00 00 01
    operand = 0x8000001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 20 (VH_BLIND) to 1.50000000 Volt (1227)
    //# P 00 14 04CB
    operand = 0x1404cb;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 16 (VDD) to 1.40050000 Volt (1146)
    //# P 00 10 047A
    operand = 0x10047a;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // output level should be around 30000 ADU
    // ---------------------------------------------
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 16 (VDD) to 1.42000000 Volt (1162)
    //# P 00 10 048A
    operand = 0x10048a;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 16 (VDD) to 1.44000000 Volt (1178)
    //# P 00 10 049A
    operand = 0x10049a;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 16 (VDD) to 1.46000000 Volt (1195)
    //# P 00 10 04AB
    operand = 0x1004ab;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 20 (VH_BLIND) to 1.52000000 Volt (1244)
    //# P 00 14 04DC
    operand = 0x1404dc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 20 (VH_BLIND) to 1.54000000 Volt (1260)
    //# P 00 14 04EC
    operand = 0x1404ec;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 20 (VH_BLIND) to 1.56000000 Volt (1276)
    //# P 00 14 04FC
    operand = 0x1404fc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // ---------------------------------------------
    // End of BU test
    // ---------------------------------------------
    // We set the system to "PEL commute" mode
    // ---------------------------------------------
    // Set all groups bol bias 15 (VGG) to 1.30000000 Volt (1064)
    //# P 00 0F 0428
    operand = 0xf0428;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 16 (VDD) to 2.60000000 Volt (2128)
    //# P 00 10 0850
    operand = 0x100850;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 08 (VGL) to 3.00000000 Volt (3447)
    //# P 00 08 0D77
    operand = 0x80d77;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 06 (VDL) to 3.00000000 Volt (3447)
    //# P 00 06 0D77
    operand = 0x60d77;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 07 (VSS) to 1.30000000 Volt (1494)
    //# P 00 07 05D6
    operand = 0x705d6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // Start of VRL test
    TMMarker601();
    // ---------------------------------------------
    // Set all groups bol bias 11 (VDECX-H) to 0.00000000 Volt (0)
    //# P 00 0B 0000
    operand = 0xb0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 12 (VDECX-L) to 0.00000000 Volt (0)
    //# P 00 0C 0000
    operand = 0xc0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 09 (CKRLH) to 1.50000000 Volt (1724)
    //# P 00 09 06BC
    operand = 0x906bc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 10 (CKRLL) to 1.50000000 Volt (1724)
    //# P 00 0A 06BC
    operand = 0xa06bc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 14 (VSMS-L) to 3.00000000 Volt (3447)
    //# P 00 0E 0D77
    operand = 0xe0d77;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 13 (VSMS-H) to 0.00000000 Volt (0)
    //# P 00 0D 0000
    operand = 0xd0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 15 (VGG) to 1.15000000 Volt (941)
    //# P 00 0F 03AD
    operand = 0xf03ad;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // The CL current (I_VSS_BU) should be between 100 and 300 nA
    TMMarker601();
    // ---------------------------------------------
    // Set all groups bol bias 20 (VH_BLIND) to 1.75000000 Volt (1432)
    //# P 00 14 0598
    operand = 0x140598;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 00 03 00E6
    operand = 0x300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 00 03 0159
    operand = 0x30159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 03 (VRL) to 0.40000000 Volt (460)
    //# P 00 03 01CC
    operand = 0x301cc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 00 03 0159
    operand = 0x30159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 00 03 00E6
    operand = 0x300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // ---------------------------------------------
    // fin de test de VRL for all groups
    // ---------------------------------------------
    // ---------------------------------------------
    // VRL test group-by-group
    // ---------------------------------------------
    // group 1
    TMMarker602();
    // ---------------------------------------------
    // Set group 1 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 01 03 00E6
    operand = 0x10300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 1 bol bias 03 (VRL) to 0.40000000 Volt (460)
    //# P 01 03 01CC
    operand = 0x10301cc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 1 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 01 03 00E6
    operand = 0x10300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // group 2
    TMMarker602();
    // ---------------------------------------------
    // Set group 2 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 02 03 00E6
    operand = 0x20300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 2 bol bias 03 (VRL) to 0.40000000 Volt (460)
    //# P 02 03 01CC
    operand = 0x20301cc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 2 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 02 03 00E6
    operand = 0x20300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // group 3
    TMMarker602();
    // ---------------------------------------------
    // Set group 3 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 03 03 00E6
    operand = 0x30300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 3 bol bias 03 (VRL) to 0.40000000 Volt (460)
    //# P 03 03 01CC
    operand = 0x30301cc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 3 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 03 03 00E6
    operand = 0x30300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // group 4
    TMMarker602();
    // ---------------------------------------------
    // Set group 4 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 04 03 00E6
    operand = 0x40300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 4 bol bias 03 (VRL) to 0.40000000 Volt (460)
    //# P 04 03 01CC
    operand = 0x40301cc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 4 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 04 03 00E6
    operand = 0x40300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // group 5
    TMMarker602();
    // ---------------------------------------------
    // Set group 5 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 05 03 00E6
    operand = 0x50300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 5 bol bias 03 (VRL) to 0.40000000 Volt (460)
    //# P 05 03 01CC
    operand = 0x50301cc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 5 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 05 03 00E6
    operand = 0x50300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // group 6
    TMMarker602();
    // ---------------------------------------------
    // Set group 6 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 06 03 00E6
    operand = 0x60300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 6 bol bias 03 (VRL) to 0.40000000 Volt (460)
    //# P 06 03 01CC
    operand = 0x60301cc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 6 bol bias 03 (VRL) to 0.20000000 Volt (230)
    //# P 06 03 00E6
    operand = 0x60300e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // end of test group-by-group
    TMMarker600();
    // ---------------------------------------------
    // Set all groups bol bias 09 (CKRLH) to 0.00000000 Volt (0)
    //# P 00 09 0000
    operand = 0x90000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 10 (CKRLL) to 0.00000000 Volt (0)
    //# P 00 0A 0000
    operand = 0xa0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 11 (VDECX-H) to 2.00000000 Volt (2298)
    //# P 00 0B 08FA
    operand = 0xb08fa;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 12 (VDECX-L) to 2.00000000 Volt (2298)
    //# P 00 0C 08FA
    operand = 0xc08fa;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 04 (VINJ) to 3.00000000 Volt (3447)
    //# P 00 04 0D77
    operand = 0x40d77;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 20 (VH_BLIND) to 1.70000000 Volt (1391)
    //# P 00 14 056F 
    operand = 0x14056f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set gain high
    //# P 08 00 00 00
    operand = 0x8000000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    TMMarker601();
    // Set all groups bol bias 01 (VH) to 0.50000000 Volt (575)
    //# P 00 01 023F
    operand = 0x1023f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 02 (VL) to -0.15000000 Volt (416)
    //# P 00 02 01A0
    operand = 0x201a0;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 01 (VH) to 0.00000000 Volt (0)
    //# P 00 01 0000
    operand = 0x10000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 02 (VL) to 0.00000000 Volt (0)
    //# P 00 02 0000
    operand = 0x20000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //---------------------------------
    // Extra wait 30000 ms for a noise check
    TMMarker603();
    delay(30);
    TMMarker601();
    //---------------------------------
    //# S 01 001388
    // Set all groups bol bias 12 (VDECX-L) to 0.00000000 Volt (0)
    //# P 00 0C 0000
    operand = 0xc0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 09 (CKRLH) to 2.00000000 Volt (2298)
    //# P 00 09 08FA
    operand = 0x908fa;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //---------------------------------
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    //---------------------------------
    // Set seq mode Sb only
    //# P 09 01 00 02
    operand = 0x9010002;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    //---------------------------------
    // Wait 30000 ms
    delay(30);
    //# S 01 001388
    //---------------------------------
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    //---------------------------------
    // Set seq mode Sref only
    //# P 09 01 00 01
    operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // ---------------------------------------------
    // Wait 30000 ms
    delay(30);
    //# S 01 001388
    //---------------------------------
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    //---------------------------------
    // Set seq mode Sb-Sref
    //# P 09 01 00 00
    operand = 0x9010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // ---------------------------------------------
    // Wait 30000 ms
    delay(30);
    //# S 01 001388
    // Close TM file
    //# S 08
    // ---------------------------------------------
    //-----------------
    // End of Procedure
    //-----------------
}

// CVS comments  : $Id: PacsLineSpecKeyWaves.txt,v 1.3 2007/04/25 15:14:04 dcesarsk Exp $ 
// Purpose       : Give a series of KeyWaves given an array of UserWaves,
//                 This version gives one KeyWave per represented order in
//                 UserWaves
//
// CUS author    : DAC
// Script file   : PacsLineSpecKeyWaves.txt 
//
// Input arguments
// type    name        Description
// tuple   waveTuple   Grating info associated to HSPOT defined spectral lines
//
// Return values
// Type         Description
// double []    Array of "key" wavelengths from CAL-U file
// Description   : Sort input waveUSER by order. For each order, compute
//                 the mean wavelength; return the waveKEY closest to the
//                 mean wavelength
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1  8-jun-2005 DAC
//                 0.2 21-jun-2005 READ_key_wave_table renamed to
//                                 PacsReadKeyWave; module removed from this 
//                                 file, created as stand-alone
// 1.0 26-aug-2005 Use new SPEC_get_grat_info, hence
//                 input argument is now waveTuple
// 1.1 13-apr-2006 Order KeyWaves by increasiing order
double[] procedure PacsLineSpecKeyWaves {
    {double,int,int,int,int}[] waveTuple = [{0.0,0,0,0,0}]; // waveTuple
}{
    // Local variables
    int[] orders = [0];
    double[] waves = [0.0];
    double nORDER1 = 0.0;
    double nORDER2 = 0.0;
    double nORDER3 = 0.0;
    double sum1 = 0.0;
    double sum2 = 0.0;
    double sum3 = 0.0;
    double[] answer = [0.0];
    // Associate wavelengths to their respective order
    int nbWAVES = length(waveTuple);
    for(int loop1 = 0 .. nbWAVES - 1) {
        //      Create vector of intermediate results
        orders[loop1] = waveTuple[loop1]{1};
        waves[loop1] = waveTuple[loop1]{0};
    }
    // Compute mean wavelength for each order
    for(int loop2 = 0 .. nbWAVES - 1) {
        if(orders[loop2] == 1) {
            nORDER1 = nORDER1 + 1.0;
            sum1 = sum1 + waves[loop2];
        }
        if(orders[loop2] == 2) {
            nORDER2 = nORDER2 + 1.0;
            sum2 = sum2 + waves[loop2];
        }
        if(orders[loop2] == 3) {
            nORDER3 = nORDER3 + 1.0;
            sum3 = sum3 + waves[loop2];
        }
    }
    // Compute mean values and fetch closest key wavelength
    int nb_answer = 0;
    if(nORDER1 >= 1.0) {
        sum1 = sum1 / nORDER1;
        double keyWAVE1 = PacsReadKeyWave("1",sum1);
        answer[nb_answer] = keyWAVE1;
        nb_answer = nb_answer + 1;
    }
    if(nORDER2 >= 1.0) {
        sum2 = sum2 / nORDER2;
        double keyWAVE2 = PacsReadKeyWave("2",sum2);
        answer[nb_answer] = keyWAVE2;
        nb_answer = nb_answer + 1;
    }
    if(nORDER3 >= 1.0) {
        sum3 = sum3 / nORDER3;
        double keyWAVE3 = PacsReadKeyWave("3",sum3);
        answer[nb_answer] = keyWAVE3;
        nb_answer = nb_answer + 1;
    }

    return answer;
}

// CVS comments  : $Id: PacsPhotSlewCal.txt,v 1.10 2008/05/06 13:34:53 vanessa Exp $ 
// Purpose       : Invoke a PACS calibration OBCP during slew to source;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsPhotSlewCal.txt 
//
// Input arguments
// Type                      Description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform AOT prologue and then OBCP #13.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 DAC  30-Nov-2005 (inspired by PacsSpecSlewCal)
// 0.2 DAC 20-sep-2006 Clean up leftovers from SPEC script 
// 0.3 DAC  6-dec-2006 Adapted to simpler PHOT_fltw_move
// 0.4 DAC 27-jun-2007 SPR-3339 Always move filter wheel
// 1.0 DAC 10-oct-2007 SCR-3628 Added arguments to call aot_prologue
// 1.1 JVP 28-apr-2008 ERROR in filter_id assignation: POS A is LW for the
//     	   	       photometer (remind POS A = SW for spectro)
// 1.2 DAC 20-may-2008 Moved FLTW move into DO_PROLOGUE section                
// 2.0 SCR 4431 VDO: implemetation of data_rates
// 2.1 16-sep-2009 VD implementation 5sec delay post-cal: PACS-2039
// 
// 
int[] procedure PacsPhotSlewCal {
    bool verbose = true; // Debug_print or not 
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,64,0,0,0,0,0,0,0}]; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,64,0,0,0,0,0,0,0}]; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]; // OBCP parameters
    bool doPROLOG = true; // Perform/don't AOT prologue
    string filter = "blue2"; // PHOT filter
}{
    // Array to collect OBCP times per line
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    // Table of filter wheel positions as per MIB
    // Actually originally not blue1 = SW = POS B, and blue2 = LW = POS A for
    // the photmeter
    if(filter == "blue1") {
        string filterID = "POS B";
    }
    if(filter == "blue2") {
        filterID = "POS A";
    }
    // Long sequence to "unpack" default values from tuples
    int gain_blu = confPHOTblu[0]{0};
    int comp_mode_blu = confPHOTblu[0]{3};
    int glitch_det_blu = confPHOTblu[0]{4};
    int nb_raw_blu = confPHOTblu[0]{6};
    int gain_red = confPHOTred[0]{0};
    int comp_mode_red = confPHOTred[0]{3};
    int glitch_det_red = confPHOTred[0]{4};
    int nb_raw_red = confPHOTred[0]{6};
    int nb_cycles_obs_cal = confOBCP[0]{0};
    int nb_SRC_REF = confOBCP[0]{3};
    int nb_rdouts_plateau = confOBCP[0]{4};
    int nb_CS1_CS2 = confOBCP[0]{5};
    int chop_pos_SRC = confOBCP[0]{12};
    int chop_pos_REF1 = confOBCP[0]{13};
    int chop_pos_REF2 = confOBCP[0]{14};
    int chop_def = confOBCP[0]{17};
    int detector = confOBCP[0]{18};
    int filterPOS = confOBCP[0]{19};
    if(gain_blu == 1 && gain_red == 1) {
        string set_gain = "LOW";
    } else {
        if(gain_blu == 0 || gain_red == 0) {
            set_gain = "HIGH";
        }
    }
    // Issue PHOT_aot_prologue if demanded
    if(doPROLOG) {
        totalDUREE = PHOT_aot_prologue(set_gain,comp_mode_blu,comp_mode_red,nb_raw_blu,nb_raw_red,verbose);
        // Turn the filter wheel
        int timeFLTW = PHOT_fltw_move(filterID);
        //  increment total duration and overheads
        totalDUREE[0] = totalDUREE[0] + timeFLTW;
        totalDUREE[4] = totalDUREE[4] + timeFLTW;
    }
    // Issue now OBCP4 for demanded filter
    // Table OBCP4params has parameter values for CAL using blue1 or blue2
    // Get params for demanded filter from OBCP4params
    string calNAME = "OBCP4params";
    // Table acces key is "cal1" or "cal2", corresponding to blue1 and blue2
    // respectively.
    string key = "cal1";
    if(filter == "blue2") {
        key = "cal2";
    }
    nb_cycles_obs_cal = ilookup(calNAME,key,"nb_cycles_obs_cal");
    nb_SRC_REF = ilookup(calNAME,key,"nb_SRC_REF");
    nb_rdouts_plateau = ilookup(calNAME,key,"nb_rdouts_plateau");
    nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    // Read CS positions from CHOPPERCSparams
    int pos_CS1 = ilookup("CHOPPERCSparams","PHOT","pos_CS1");
    int pos_CS2 = ilookup("CHOPPERCSparams","PHOT","pos_CS2");
    // Update OBCP[0] tuple with CAL-U values
    confOBCP[0]{0} = nb_cycles_obs_cal;
    confOBCP[0]{3} = nb_SRC_REF;
    confOBCP[0]{4} = nb_rdouts_plateau;
    confOBCP[0]{5} = nb_CS1_CS2;
    confOBCP[0]{15} = pos_CS1;
    confOBCP[0]{16} = pos_CS2;
    // Call now OBCP with derived parameters
    int[] dureeOBCP = OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,pos_CS1,pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
    if(verbose) {
        debug_print("*** SlewCal OBCP: " + confOBCP[0]);
        debug_print("*** SlewCal OBCP returns: " + dureeOBCP);
    }
    // Tally total durations
    for(int loop0 = 0 .. 4) {
        totalDUREE[loop0] = totalDUREE[loop0] + dureeOBCP[loop0];
    }
    if(verbose) {
        debug_print("***** SlewCal performed CAL: " + key + " requires " + totalDUREE[0] + " [sec]");
    }
    // here we have to add 5sec delay
    // this 5 sec MUST be labeled soooooo 
    PacsBbDelayScience(4);
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return totalDUREE;
}

// Missionphase  : FM
//
// Purpose	:  Setup diagnostic housekeeping for the FM 
//                 chopper tests. Special HKs.
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: Set up 2 housekeeping parameter for diagnostic housekeeping 
//	  of the chopper for open loop tests.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and SPEC_Chop_fft_eqmimt_obs
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 1.0	
// 
// History 	: 
//	  1.0 08-11-06 HD. Spec. HK for open loop measurements.	  
block SPEC_Chopper_dhk_imt_spec_bb PACS 390 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //-------------------------------------------- 
    // Setup and start diagnostic HK for Chopper
    //-------------------------------------------- 
    int chop_diag_hk_length = 3;
    {int}[] parlist = [{244},{258},{0xffff}];
    int[] aux = [244,258,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(chop_diag_hk_length,parlist,check_sum);
    int diag_hk_period = 0;
    // Synchronize diagnostic HK on blue spectrometer readouts
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark End of Block
    WriteEndBB();
}

// FileName      : PACS_Spec_Gra_Mec_Setup_Redun_OBS.cus
// Missionphase  : Operations
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    :HF
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Versions	 : 2.0
// History       : 1.0 02-Aug-2007 Simple copy of PACS_Spec_Gra_Mec_Setup_OBS.cus
//                                                for use in SFT redundant
//		   2.0 14-Feb-2008 Made into a procedure to be called by
//		       by PacsEng_Spec_gra_Mec_Setup_Cold_redun
//
//
// VARIOUS INSTRUMENT VERSION AVAILABLE FROM THE CALU (2006.06.14)
// Different rows here pertain to different PACS models or environmental conditions
// Row BreadBoard		 Values used at the pre-ILT Level, with the dummy/breadboard version of the mechanisms
// Row DMCUMWarm                 Values extracted from the DMC User Manual v4.0 (OBSW 6.000). Warm conditions.   Nominal chain.
// Row DMCUMWarmRedun            Values extracted from the DMC User Manual v4.0 (OBSW 6.000). Warm conditions.   Redundant chain.
// Row DMCUM                     Values extracted from the DMC User Manual v4.0 (OBSW 6.000).     4.2 K.	 Nominal chain.
// Row DMCUMRedun                Values extracted from the DMC User Manual v4.0 (OBSW 6.000).     4.2 K.	 Redundant chain.
// Row DMCUMFreqSwitch           Values extracted from the DMC User Manual v4.0 (OBSW 6.000).     4.2 K.	 Nominal chain.   Frequency Switching
// Row DMCUMFreqSwitchRedun      values extracted from the DMC User Manual v4.0 (OBSW 6.000).     4.2 K.	 Redundant chain. Frequency Switching
// Row DMCUMFast                 Values extracted from the DMC User Manual v4.0 (OBSW 6.000).     4.2 K.	 Nominal chain.   Rate->12 (4 degrees / second)
// Row DMCUMFastRedun            Values extracted from the DMC User Manual v4.0 (OBSW 6.000).     4.2 K.	 Redundant chain. Rate->12 (4 degrees / second)
//
procedure PACS_Spec_Gra_Mec_Setup_Cold_Redun {
    string calUrow = "ISTSlow_R"; // INSTRUMENT VERSION
}{
    // GRATING CALIBRATION TABLE : CONFGrat
    // ------------------------------------
    string calUname = "CONFGrat";
    // GRATING CALIBRATION TABLE
    //
    // call procedure
    PACS_Spec_Gra_Mec_Setup(calUname,calUrow);
}

// File          : PACS_Spec_SPU_Buffer_Setup.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Prepare SPU for spectroscopy buffer transmission mode
//
// Author        : T. Mueller, H. Feuchtgruber
// CUSification  : DAC
// Arguments     : none
//                 
//
// Description   : 
//                              
// Comments      :      
//
// Version       : 1.2
// History       : 1.0 / 16-Nov-2004 initial version
//                 1.1  6-apr-2006 DMC v6.0.1
//                 1.2  28-mar-2007 DAC Update for SPU V13.x
//                 1.3  24-mar-2009 DAC Update after SPU UM 13.95a
//
procedure PACS_Spec_SPU_Buffer_Setup {
}{
    debug_print("Start PACS_Spec_SPU_Buffer_Setup");
    int comp_mode = 25;
    int spu_nraw = 3;
    //--------------------
    // Preparation
    //--------------------
    Pacs_SPUS_STOP_REDUCT_COMPR();
    delay(1);
    Pacs_SPUL_STOP_REDUCT_COMPR();
    delay(1);
    //--------------------------
    // SPU compression/reduction
    //--------------------------
    {int}[] list_tuple = [{comp_mode},{comp_mode}];
    int[] list_int = [comp_mode,comp_mode];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_SPU_TRAN_MODE(list_tuple,chksum);
    delay(1);
    //----------------------------------------------------------
    // Setting of start index of raw channels for SPUS and SPUL
    //----------------------------------------------------------
    int spus_startraw = 1;
    int spul_startraw = 1;
    //------------------------
    // Raw channel settings 
    //------------------------
    Pacs_SPUS_RAW_CHAN_TRAN_MODE("SPEC",spu_nraw,spus_startraw);
    delay(1);
    Pacs_SPUL_RAW_CHAN_TRAN_MODE("SPEC",spu_nraw,spul_startraw);
    delay(1);
    //---------------------------------------------
    // Sub-ramp and detector const. setting to SPU
    // Spectro "Ottensamer" block ("S" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    int ppf = 0;
    // PPP: Pre-Processing Parameter
    int ppp = 0;
    // Threshold for glitch detection in spectroscopy
    int tfs = 1000;
    // Threshold for chopper position deviation in spectroscopy
    int tcs = 100;
    // Threshold for grating deviation
    int tgd = 100;
    // Readouts per SubRamp readback
    int rsrr = 16;
    // Glitch detection for spectroscopy
    int gdfs = 1;
    // Ramp fitting algorithm
    int rfal = 0;
    // 13.95a values for soal & lcal are 5 & 4
    // Sorting algorithm
    int soal = 5;
    // lossless compression algorithm (0,1,2,3,4)
    int lcal = 4;
    // PACS Codec Order (3,4)
    int pcod = 3;
    // New 13.95a values are
    int rndb = 0;
    int rnds = 0;
    int fixrc = 0;
    int dpre = 0;
    int dpost = 0;
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    int[] aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    int check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    {int}[] spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUS_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    // Spectro "Ottensamer" block ("L" SPU)
    ppf = 0;
    ppp = 0;
    tfs = 1000;
    tcs = 100;
    tgd = 100;
    rsrr = 16;
    gdfs = 1;
    rfal = 0;
    soal = 5;
    lcal = 4;
    pcod = 3;
    // New 13.95a values are
    rndb = 0;
    rnds = 0;
    fixrc = 0;
    dpre = 0;
    dpost = 0;
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUL_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    //--------------------
    // Send time stamps
    //--------------------
    // PC148420 "DMC_WRT_TIME" WRITE THE TIME SENT BY THE DPU INTO THE DMC BUFFER
    //         Fixed GroupSize: 1, repetition: 2
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // PC007380 "DPU_SEND_TIME" DPU SENDS THE TIME TO DEC/MEC
    //tcsend PC007380
    //waittime 0.5
    Pacs_DPU_SEND_TIME();
    delay(1);
    // PC077420 "DMC_SET_TIME" SET THE TIME PREVIOUSLY WRITTEN BY THE WRITE TIME COMMAND
    // tcsend PC077420
    // waittime 0.5
    Pacs_DMC_SET_TIME();
    delay(1);
    //----------------------------
    // Start reduction/compression
    //----------------------------
    // SPUS-START-REDUCT-COMPR
    // tcsend PC039400
    // waittime 0.5
    Pacs_SPUS_START_REDUCT_COMPR();
    delay(1);
    // SPUL-START-REDUCT-COMPR
    // tcsend PC040390
    // waittime 0.5
    Pacs_SPUL_START_REDUCT_COMPR();
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Script        : PACS_Chopper_uk_move_21000_ast_OBS.cus
//
//
// Missionphase  : IST Chopper Day
//
// Purpose	: Move chopper to absolute position  
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-21000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched on and Chopper switched on.
//                 
// Comments	: This script is based on the commanding during the CQM/FM ILT.
//
// Version	: 4.0	
// 
// History 	: 1.0 02-03-07 HD. Script to do simple chopper cycle 
//		  2.0 05-07-07 HD. IST Chopper Day
//		  3.0 05-07-07 MN. edited for SVT/PV conformance
//              : 4.0  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Chopper_uk_move_21000_ast {
    /* Needed variables to call PacsEng_Chopper_uk_move_21000_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Chopper_uk_move_21000_ast                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Chopper_uk_move_21000_NoConf_ast()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Chopper_uk_move_21000_NoConf_ast();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsSpecWaveArray.txt,v 1.5 2007/10/19 15:32:56 dcesarsk Exp $ 
// Purpose       : To create an array given values for 1st and last element,
//                 subjected to the following rules:
//                 - at least 10 elements
//                 - at most 120 elements
//                 - nominal step = 0.5                  
// 
// CUS author    : 
// Script file   : PacsSpecWaveArray.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : Utility for PacsSpecRMS. Given waveLO and waveHI, compute
//                 a [waveArray] subjected to the following rules:
//                 - at least 10 elements
//                 - at most 120 elements
//                 - nominal waveStep = 0.5                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 0.1
// History       : 0.1 10-mar-2007 DAC
//
double[] procedure PacsSpecWaveArray {
    /* Input wavelengths                                                       */
    double waveLO = 100.0;
    double waveHI = 110.0;
    bool verbose = true;
}{
    if(verbose) {
        debug_print("AUX:LO and HI: " + waveLO + "/" + waveHI);
    }
    // Nominal waveStep
    double[] waveStep = [5.0E-4,0.0010,0.01,0.05,0.1,0.2,0.5,1.0,2.0];
    // Input span
    double span = abs(waveHI - waveLO);
    // Nb of samples with nominal step
    int stepIndex = 4;
    int nbSamples = ifloor(span / waveStep[stepIndex]);
    // Is it within range?
    while(nbSamples > 120 && stepIndex <= 7) {
        stepIndex = stepIndex + 1;
        nbSamples = ifloor(span / waveStep[stepIndex]);
    }
    while(nbSamples < 10 && stepIndex >= 1) {
        stepIndex = stepIndex - 1;
        nbSamples = ifloor(span / waveStep[stepIndex]);
    }
    // Take estimated nbSamples and compute exact waveStep
    double theStep = span / double(nbSamples);
    if(verbose) {
        debug_print("AUX:Size RMS table: " + nbSamples + "; Sample: " + theStep);
    }
    // Create and fill wave array
    double[] wave = [0.0];
    for(int loop = 0 .. nbSamples) {
        wave[loop] = waveLO + double(loop) * theStep;
    }

    return wave;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_CRE_Setup_Cold_HeI {
    /* No variables to call PacsEng_Spec_CRE_Setup_Cold_HeI                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_CRE_Setup_Cold_HeI                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_CRE_Setup_Cold_HeI()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_CRE_Setup_Cold_HeI();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Spec_Gra_Diaghk1khz_Setup.cus
// Missionphase  : PACS FM ILT
//
// Purpose       : Switch on 1khz diagnostic hk relevant to grating
//
// Author        : B.Vandenbussche
// 
// Arguments     :
//
// Description   : Grating diagnostic housekeeping ON - 1khz
//               :
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 07-nov-2006 initial version by BV 
//          
//  -----------------------------------
// @author B. Vandenbussche 
// @date today
// @version 1.0
// @purpose Switch on diagnostic housekeeping relevant to grating at 1khz
// @comment - 
// ------------------------------
// Uncomment to test the script for tcl syntax using a normal tcl interpreter
// source offlinetest.tcl
// Uncomment till here ----------
block PACS_Spec_Gra_Diaghk1khz_Setup PACS 157 {
}{
    // Register start of BB
    WriteBBID($BBID);
    // Rate : 1Khz
    int diag_hk_period = 0;
    // DMC_WRT_DIAG_HK_LIST
    // DMC_DATA_LENGTH            PP065420 contains the number of desired HK parameters
    // DMC_4_BYTES_WORDS_DATA     PP067420 contains the desired HK parameters' IDs
    // DMC_CHECKSUM               PP066420
    //
    // Max number of requested diag HK parameters = 16
    // (including the last one, which is always forced to the same value)
    //
    //     DMC_FWGRAT_HALLA       256
    //     DMC_FWGRAT_HALLB       257
    //     DMC_GRAT_CUR_POS       250
    //     DMC_GRAT_SETPOIN       251
    //     DMC_GRAT_OUTPUT        452
    {int}[] list_tuple = [{256},{257},{250},{251},{452},{0xffff}];
    int[] list_int = [256,257,250,251,452,0xffff];
    int chksum = checksum("int",list_int);
    int nbParams = length(list_int);
    Pacs_DMC_WRT_DIAG_HK_LIST(nbParams,list_tuple,chksum);
    delay(1);
    // DMC_START_DIAG_HK
    // DIAG_HK_PERIOD             PP076420
    // tcsend PC146420 [list PP076420 $diag_hk_period]
    // waittime $command_time
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    // End of procedure
    //-----------------
    // Mark End of Block
    WriteEndBB();
}

// File          : PACS_Spec_Flash_IST.cus
//
// Purpose       : Check performance of flashers under various low power regimes
//		   
//
// Author        : P. Royer
//
// Arguments     : 
//
// Prerequisite  : Flashers on
//
// Description   : Loops over low, but increasing currents sent to the flashers
//               :
// Comments      : 
//                 
//
// Version       : 2.0
// History       : 1.0 / 11-Aug-2006 initial version by PR
//                 1.1 / 05-Apr-2007 Update position of BB
//                       Include SWON/SWOF Flashers
//		   2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.1
// @purpose Check performance of flashers under low power regimes
// @comment - 
//
procedure Pacs_Spec_Flash_IST {
}{
    //
    // Position FWSPEC on POS B
    //
    SPEC_fltw_move("POS B");
    //
    // SWON FLASHERS
    PACS_Spec_Flash_SWON();
    //
    // Internal parameters
    // -------------------
    int chop_pos_BB1 = -21350;
    int chop_pos_BB2 = 21200;
    //
    int nchop = 1;
    double[] multi = [1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,15.0,20.0];
    int stab_time = 5;
    //
    // 20.475 = 0.1 mA
    double current_step = 20.475;
    double current_ini = 0.0;
    int current = 0;
    //
    // Set the Flashers to initial values
    // ----------------------------------
    // PACS_Spec_Flash_Setup(current_ini, current_ini);
    // delay(stab_time);
    //
    // Loop on low power regimes
    // -------------------------
    for(int loop = 1 .. length(multi)) {
        current = ifloor(current_ini + multi[loop - 1] * current_step);
        for(int loopin = 1 .. nchop) {
            // OPERATE ON BB1
            PACS_Chop_Move_Abs(chop_pos_BB1);
            delay(stab_time);
            PACS_Spec_Flash_Setup(current,current);
            delay(stab_time);
            PACS_Spec_Flash_Setup(0,0);
            delay(2 * stab_time);
            // OPERATE ON BB2
            PACS_Chop_Move_Abs(chop_pos_BB2);
            delay(stab_time);
            PACS_Spec_Flash_Setup(current,current);
            delay(stab_time);
            PACS_Spec_Flash_Setup(0,0);
            delay(2 * stab_time);
        }
    }
    //
    // Reset the Flashers to 0 current
    // ------------------------------
    PACS_Spec_Flash_Setup(0,0);
    delay(20);
    //
    // SWOF FLASHERS
    PACS_Spec_Flash_SWOF();
    //
}

// Script        : Pacs_Chopper_AutoOptPlateau.txt
// Missionphase  : Commissioning
//
// Purpose	: Check a series of different chopper controller settings.
//                  
// Author	: Markus Nielbock
// CUS author 	: MN
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called.
//                  
// Dependencies : 
//
// Preconditions: PACS switched on and Chopper switched off.
//                 
// Comments	: This script is based on the commanding scripts
//                PACS_Chopper_uk_move_12000_OBS.cus and
//                Pacs_Chopper_AutoOpt.txt
//
// Version	: 1.0
// 
// History 	: 1.0 09-Jun-2009 (MN) Script to do simple chopper cycle 
//
// Initialise input parameters:
// Defines control parameter range, loops run from k(p,i,c,f)min to
// k(p,i,c,f)max defining the inverse of the ratio of parameter change w.r.t.
// the default value.
procedure Pacs_Chopper_AutoOptPlateau {
    int chop_pos = 12000;
    int cycle = 10;
    int plateau_time = 2;
    int kpmin = 0 in [-3,3];
    int kpmax = 0 in [-3,3];
    int kimin = 0 in [-3,3];
    int kimax = 0 in [-3,3];
    int kcmin = 0 in [-3,3];
    int kcmax = 0 in [-3,3];
    int kfmin = 0 in [-3,3];
    int kfmax = 0 in [-3,3];
}{
    // PACS instrument code for BBID
    int instrument = 0x40000000;
    // Initialise variables for conversion from int to string and double
    string sU = "+0";
    string sV = "+0";
    string sW = "+0";
    string sX = "+0";
    double dU = 0.0;
    double dV = 0.0;
    double dW = 0.0;
    double dX = 0.0;
    int bU = 0x4000;
    int bV = 0x400;
    int bW = 0x40;
    int bX = 0x4;
    // CALU table file to be accessed
    string fileU = "PacsTable_CONFChopper_auto";
    // Start diag. HK
    SPEC_Chopper_dhk_5hk_1khz_bb();
    // Cycle through calibration table columns 
    if(kpmax < kpmin) {
        kpmax = kpmin;
    }
    if(kimax < kimin) {
        kimax = kimin;
    }
    if(kcmax < kcmin) {
        kcmax = kcmin;
    }
    if(kfmax < kfmin) {
        kfmax = kfmin;
    }
    for(int u = kpmin .. kpmax) {
        for(int v = kimin .. kimax) {
            for(int w = kcmin .. kcmax) {
                for(int x = kfmin .. kfmax) {
                    // calculate inverse -> ratio of changes
                    if(u != 0) {
                        dU = 1.0 / double(u);
                    } else {
                        dU = 0.0;
                    }
                    if(v != 0) {
                        dV = 1.0 / double(v);
                    } else {
                        dV = 0.0;
                    }
                    if(w != 0) {
                        dW = 1.0 / double(w);
                    } else {
                        dW = 0.0;
                    }
                    if(x != 0) {
                        dX = 1.0 / double(x);
                    } else {
                        dX = 0.0;
                    }
                    if(abs(dU + dV + dW + dX) < 0.01) {
                        // convert int to string variables
                        // and determine BBID for column recovery
                        // BBID is a 32 bit word with:
                        // 2 bits: Instrument (PACS = 01)
                        // 14 bits: block number (not used here)
                        // 16 bits: a counter, used here as follows:
                        //          4 bits for every PID parameter (P, I, C, F)
                        //          of this: 2 bits for the sign (01 = +, 10 = -)
                        //                   2 bits for the number (01, 10, 11 = 1, 2, 3)
                        if(u >= 0) {
                            sU = "+" + u;
                            bU = 16384 + 4096 * u;
                        } else {
                            sU = "" + u;
                            bU = 32768 - 4096 * u;
                        }
                        if(v >= 0) {
                            sV = "+" + v;
                            bV = 1024 + 256 * v;
                        } else {
                            sV = "" + v;
                            bV = 2048 - 256 * v;
                        }
                        if(w >= 0) {
                            sW = "+" + w;
                            bW = 64 + 16 * w;
                        } else {
                            sW = "" + w;
                            bW = 128 - 16 * w;
                        }
                        if(x >= 0) {
                            sX = "+" + x;
                            bX = 4 + x;
                        } else {
                            sX = "" + x;
                            bX = 8 - x;
                        }
                        // construct column identifier
                        string calUcol = "P" + sU + "I" + sV + "C" + sW + "F" + sX;
                        debug_print("CALU column is " + calUcol);
                        int bbid = instrument + bU + bV + bW + bX;
                        WriteBBID(bbid);
                        // Upload Chopper Controller Parameter
                        CONF_chopper(fileU,calUcol);
                        delay(2);
                        // Switch on and enable chopper controller 
                        PACS_Chopper_SWON_SWOF_only("ON");
                        delay(2);
                        EnDis_chopper("ON");
                        delay(2);
                        // move chopper to zero
                        PACS_Chopper_mov_abs_fm_bb(0);
                        delay(1);
                        // chop cycle
                        int i = 1;
                        while(i <= cycle) {
                            PACS_Chopper_mov_abs_fm_bb(chop_pos);
                            delay(plateau_time);
                            PACS_Chopper_mov_abs_fm_bb(-chop_pos);
                            delay(plateau_time);
                            i = i + 1;
                        }
                        // move chopper to zero
                        PACS_Chopper_mov_abs_fm_bb(0);
                        delay(1);
                        // Disable and switch off chopper controller 
                        EnDis_chopper("OFF");
                        delay(2);
                        PACS_Chopper_SWON_SWOF_only("OFF");
                        delay(2);
                    }
                }
            }
        }
    }
    // Stop diagnostic housekeeping
    PACS_stop_dhk_fm_bb();
    sync();
}

// Missionphase  : FM ILT
//
// Purpose	: Move chopper absolute
//
// Author	: Pierre Royer 
//
// CVS file	: 
//
// Arguments	: 
//
// Description	: 
//
// Dependencies : 
//
// Preconditions : 
//                 
// Comments	: 
//
//
// Version	: 1.0
//               
// History	: 1.0 08-Jun-2006 Creation by PR
//
procedure PACS_Chop_Move_Abs {
    int chop_pos = 0; //Chopper target position
}{
    Pacs_DMC_MOVE_CHOP_ABS_RAW(chop_pos);
    delay(1);
}

// $Id
// 
// Purpose       : Compute the Raleigh-Jeans law at various WL
// 
// CUS author    : VD
// Script file   : PacsSpecRJ
//
// Input arguments
// Return values
// Type          Description
// Description   : 
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 0.1
// History       : 0.1 10-feb-2010 VD creation: PHS-193 Range Spec capa switching
//                 0.2 26-feb-2010 VD PHS-193 wrong fnu -> flam implementation
// 
// 
// 
double procedure PacsSpecRJ {
    double contFluxNom = 0.0;
    double waveRefNom = 100.0;
    double waveRefPar = 100.0;
}{
    double c = 2.99792458E8;
    double contFluxLamNom = contFluxNom * c * 1.0E-19 / (waveRefNom * waveRefNom);
    double contFluxLamPar = contFluxLamNom * (waveRefNom / waveRefPar * (waveRefNom / waveRefPar) * (waveRefNom / waveRefPar) * (waveRefNom / waveRefPar));
    double contFluxRJ = contFluxLamPar * (waveRefPar * waveRefPar / (c * 1.0E-19));

    return contFluxRJ;
}

// Missionphase : 
//
// Purpose	:  Stops the diagnostic housekeeping
//                  
// Author	: 
// CUS author 	: 
//
// Description	: 
//
// Dependencies : 
//
// Preconditions   : PACS switched-on
//                 
// Comments	: 
//
// Version	: 2.0	
// 
// History 	: 0.1 04-05-06 creation by SC
//                1.0 24-07-06 SC. test script.
//                2.0 25-07-06 SC. script works.
//
block SPEC_DiagHK_DynRange_block_stop PACS 404 {
}{
    // Register start of BB
    WriteBBID($BBID);
    // Diagnostic HK stops
    Pacs_DMC_STOP_DIAG_HK();
    // Mark End of Block
    WriteEndBB();
}

command PacsCcuMonitorPeriodRecycle HFKACQP2 {
} {
    bus_schedule(SC, 6);
}

// Missionphase  : 
//
// Purpose       : Perform Setup Photometry according to TM's input:
//                 Scripts:
//      a) tm_phot_dpu_dmc_setup.tcl  <phot_hk 1, syn_source 4>
//      b) tm_phot_mec_setup.tcl      <phot_filter_wheel_id 1,
//                                     chop_def_pos 0, temp_bb1 800000
//                                     temp_bb2 920000 >
//      c) tm_phot_sequencer_setup.tcl
//      d) tm_phot_polar_bestM7_setup.tcl
//         (Setting of optimal polarisations in the cold 0.3K)
//      e) tm_phot_change_datamode.tcl  <"Bolo & HK">
//      f) tm_phot_change_seq_mode.tcl  <"Sbolo-Sref">
//      g) PACS_Phot_Gain_high.tcl
//         (gain setting  <"high">)
//      h) tm_phot_spu_setup.tcl   <comp_mode_blue 0, comp_mode_red 0
//                                  spus_nraw 3, spul_nraw 3>
//
//
// CUS author    : DAC
// Script file   : PHOT_setup.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : SCR PACS-1866
// 
// Version       : 3.0
// History:
// 0.1 DAC 22-apr-2005
// 0.2 DAC 25-apr-2005 New default: Do not start SPU
// 1.0 TM  12-apr-2006, update for FM with new settings
// 1.1 TM  08-aug-2006, new procedure to read bias tables in [V]
// 1.2 TM  10-oct-2006, autonomy function added
// 2.0 DAC 17-oct-2006 Use BIAS tables in volts, eliminate useless
//                     timing calculation, call with BIAS table name and
//                     initial filter position, initial CS temperatures
// 2.1 TM 08-Nov-2006 add the switch on of the groups
// 2.2 TM 08-Nov-2006 autonomy function 17 added
// 2.3 TM 08-Nov-2006 autonomy functions modified again (moved to PHOT_switchon_groups)
// 2.4 TM 10-Nov-2006 default bias table changed, low gain
// 2.5 13-nov-2006 Use RAW bias tables
// 2.6 15-nov-2006 Using volts again
// 2.7  8-dec-2006 Add temperature autonomy function
// 2.8  5-mar-2007 update for chopper, CSs
// 2.9  4-apr-2007 TM: number of raw channels set to zero
// 3.0  9-apr-2007 TM & KO: update of AFs
// 3.1  9-apr-2007 TM & KO: AF 15 taken out again
// 3.2 21-aug-2007 SRC-3507 Indicate end of BB
//                 Sync bus at end of script
// 3.3 06-oct-2008 TM & VDP: PHOT_change_seq_mode set to Sref_only 
// 3.4 12-nov-2008 KO: gotoDirect option added
// 1.0 22-jul-2009 KO: Copied from PHOT_setup and Group6 stays off
//                     (for red detector tests in PV)
//
int[] block PHOT_setup1234 PACS 201 {
    string calUfile = "BOLObias_preILT_standard_low"; //BIAS table name
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double set_CS1 = 48.0; // CS1 settings (ohms)
    double set_CS2 = 58.0; // CS2 settings (ohms)
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
}{
    // Register BBID with environment
    WriteBBID($BBID);
    // Define variables to communicate various durations to HSPOT.
    int time_start = time();
    PHOT_dpu_dmc_setup("BOTH Array",4);
    // Place filter wheel
    PHOT_dmc_setup(fltPOS,0,set_CS1,set_CS2);
    // switch on groups and enable AF 17
    PHOT_switchon_1234();
    // Set polarisations
    PHOT_set_bias_volt(calUfile,1);
    PHOT_set_bias_volt(calUfile,2);
    PHOT_set_bias_volt(calUfile,3);
    PHOT_set_bias_volt(calUfile,4);
    //PHOT_set_bias_volt(calUfile,5);
    //PHOT_set_bias_volt(calUfile,6);
    // Set sequencer
    PHOT_seq_setup();
    // Set data mode
    PHOT_change_data_mode("Bolo_HK");
    //  PHOT_change_seq_mode("Sb_Sref"); New setup post-SOVT1
    // Now we set the direct mode post-SOVT1
    int operand = 0;
    if(gotoDirect) {
        //*********************************************************
        // Sequence mode : blocking on VDEC_X for the direct mode
        //*********************************************************
        //
        // Set groups 1234 bol bias 09 (CKRLH) to 0.0 volt (0)
        //Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
        Pacs_BOLC_SET_CKRLH_G1_RAW(0);
        Pacs_BOLC_SET_CKRLH_G2_RAW(0);
        Pacs_BOLC_SET_CKRLH_G3_RAW(0);
        Pacs_BOLC_SET_CKRLH_G4_RAW(0);
        // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
        //Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
        Pacs_BOLC_SET_VDECX_L_G1(2.0);
        Pacs_BOLC_SET_VDECX_L_G2(2.0);
        Pacs_BOLC_SET_VDECX_L_G3(2.0);
        Pacs_BOLC_SET_VDECX_L_G4(2.0);
        // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
        //# P 09 01 00 01
        operand = 0x9010001;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
    } else {
        // Set seq mode Sb_Sref (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sb_Sref");
        //# P 09 01 00 00
        operand = 0x9010000;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
    }
    // Set gain LOW
    PHOT_set_gain("LOW");
    // Set SPU but do not start it yet
    PHOT_spu_setup(0,0,0,0,false);
    // Time spent
    int duree_TCs = time() - time_start;
    int duree_num = duree_TCs;
    // Return the array of times
    int[] time_array = [duree_num,0,0,0,0];
    //
    // enable AF 12 (to check for the protection biases)
    //Pacs_DPU_SET_FUNCT("EVENT_BOL_BIAS","ENABLE");
    // enable AF 14 to check for TEMP_EV < 0.3 K
    Pacs_DPU_SET_FUNCT("EVENT_BOL_T_FPU","ENABLE");
    // enable AF 15 (to check for the VSS currents of groups and BUs)
    // Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","ENABLE");
    // Mark end of BB
    WriteEndBB();
    // Sync bus
    sync();

    return time_array;
}

// CVS file      : CONF_spec_fltw_R.txt
// Missionphase  : FMILT_3 & Later
//
// Purpose       : CONFigure the spectro filter wheel Redundant Cold
//                  
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// History       : 1.0 04-Jul-2007 PR
//
procedure CONF_spec_fltw_R {
}{
    string calUname = "CONFFWSPEC";
    // FWSPEC CALIBRATION TABLE
    string calUrow = "FMILT_R";
    // INSTRUMENT VERSION
    int rate = ilookup(calUname,calUrow,"Rate");
    int current = ilookup(calUname,calUrow,"Drive_current");
    int threshold_A = ilookup(calUname,calUrow,"Threshold_A");
    int threshold_B = ilookup(calUname,calUrow,"Threshold_B");
    int status_A = ilookup(calUname,calUrow,"Status_A");
    int status_B = ilookup(calUname,calUrow,"Status_B");
    {int}[] parlist = [{rate},{current},{threshold_A},{threshold_B},{status_A},{status_B}];
    int[] aux = [rate,current,threshold_A,threshold_B,status_A,status_B];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_FWSPEC_CONF_PAR(parlist,check_sum);
}

// File          : PACS_Chopper_EnDis_PlateauTest_NoConf_ast.cus
// Missionphase  : SVT / flight 
//
// Purpose       : Switch-on/switch-off and enanle/disable test of chopper at pos 3000
//
// Author        : MN/HD
// CUSification  : MN/HD
// Arguments     :
//
// Description   : Flight procedure to verify the stability of the chopper.
//                      Produces diagnostic housekeeping data, enables the
//                      chopper, move to pos 3000 for 300 seconds, and disables again.
//
// Comments      : Copied from PACS_Chopper_EnDis_Test_ast300_OBS
//                         without the configuration and with MOIS comments
//
// Version       : 1.0
// History       : 1.0 17-Oct-2007 BV initial version
//		  
//
procedure PACS_Chopper_EnDis_PlateauTest_NoConf_ast {
}{
    mois_comment("Start of procedure: verify the stability of the PACS chopper during 5sec at pos 3000");
    //  Time 5 sec
    int n = 5;
    // Chopper position 3000
    int pos = 3000;
    //
    mois_step("Enable diagnostic housekeeping");
    // Set diagnostic HK (1 kHz, 4 parameters)
    PACS_Chopper_EnDis_Test_dhk("ON");
    delay(10);
    //
    mois_step("Switch on and enable chopper for 5 seconds at position 3000");
    // Switch on and enable chopper for n seconds, while n is given by the user
    PACS_Chopper_SWON_SWOF_only("ON");
    delay(20);
    EnDis_chopper("ON");
    delay(20);
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(pos);
    delay(n);
    //Go Back to Zero Position 
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(0);
    delay(1);
    EnDis_chopper("OFF");
    delay(20);
    PACS_Chopper_SWON_SWOF_only("OFF");
    delay(20);
    mois_step("Stop diagnostic housekeeping");
    // Stop diagnostic HK
    PACS_Chopper_EnDis_Test_dhk("OFF");
}

// $Id: PacsCal_Spec_QuickFullSpectrum.txt,v 1.2 2008/11/12 18:22:41 bart Exp $
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       :  Quick full spectral scan in about 1 hour in all bands with pointing
//                  
//
// Input arguments  Integrating capacitance blue (0,8,4,12) and red; chopper position
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Uses OBCP28 for executing quick full scans in both filters
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                 
// Comments      : 
// Version	 : 1.1
// History	 : 1.0 23-oct-2008 BV Adopted from PacsEng_Spec_QuickFullSpectrum
//                 1.1 12-nov-2008 BV corrected state machine section
//
obs PacsCal_Spec_QuickFullSpectrum {
    int chop_def = 650; // chopper position during grating scan
    int capa_red = 12; // Red capacitor
    int capa_blu = 0; // Blue capacitor
    int naifid = 0; // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    double yoffset = 0.0; // yoffset [arcsec]
    double xoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
}{
    // Compute the time 
    //  Execute the pointing request
    bool execute = true;
    //  Slew
    //    Write OBSID during slew    
    int tOBSID = duration(WriteOBSID($OBSID));
    // no initial hold
    int tih = 0;
    //  Final hold 12-nov-2008 BV corrected state machine section
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_QuickFullSpectrum(chop_def,capa_red,capa_blu)));
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tOBSID,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_QuickFullSpectrum(chop_def,capa_red,capa_blu);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_lowGainBiasDirect
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0s
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_lowGainBiasDirect
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//
// Version : Mon Jul 14 05:57:16 CEST 2008
//
obs PacsCal_Phot_lowGainBiasDirect {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0s
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(endBiasTable,"DIRECT","LOW"));
    int timeCal3CPR1 = duration(Pacs_OBCP_chopped_photometry2(nLoops1,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false));
    //Minimum slew time
    int tslewmin = timeOBSID + timeSetBias + timeCal3CPR1;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeSetBias + timeCal3CPR5 + timeEndID;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_lowGainBiasDirect(measure_time,startBiasTable,endBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops1,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //************************************
            // Call the Phot_lowGainBiasDirect
            //************************************
            Phot_lowGainBiasDirect(measure_time,startBiasTable,endBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

/////////////////////////////////////////////////////////////////////////////
/// $Id: PacsPhoto.def,v 1.69 2008/05/14 11:10:32 vanessa Exp $ 
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsPhoto AOT
// CUS author    : DAC
// Script file   : PacsPhoto.def
// Return values
// Description   : 
// This AOT has to cater to three different source morphologies:
// "point", "small", and "large". Each mode requires its own pointing modes.
// Available pointing modes (reference is to JBr's document):
// NOTE: All modes include operations during SLEW and operations at end of OBS.
// NOTE: Updated based on e-mail from MS dated 3-Dec-2005 (denoted UPDATE)
// NOTE: Updated after Saclay meeting
// ==== "point"
// no nodding                         2.1  fine_pointing
// nodding (includes "hold" periods)  3.4  nodding_pointing
// UPDATE: Nodding is always needed ==> eliminate fine_pointing
//
// ==== "small"
// (raster dimensions and steps TBD; expect 2x2 or 3x3)
// no nodding ("hold" periods and repetition) 2.13 repeated_raster_with_hold
// nodding ("hold" periods and no repetition) 2.12 nodding_in_raster
// UPDATE: Nodding always used ==> nodding_in_raster
//
// ==== "large"
// Can be RASTER or SCAN (freeze mode is based upon a SCANning PointMode)
// RASTER
// no nodding ("hold" periods and repetition) 2.13 repeated_raster_with_hold
// nodding ("hold" periods and no repetition) 2.12 nodding_in_raster
// UPDATE: Nodding not used ==> raster_pointing
//
// SCAN
// There is no nodding and no chopping. "Hold" periods are allowed (mode 2.14) 
// Leg length is restricted to 20 degrees.
//
//
// Dependencies  : 
//
// Preconditions : 
//
// Comments      : 
// 
// History       : 0.1  2-Sep-2005 DAC
// 4.5  2-may-2007 For history before today see CVS
//                 Fixed SPR-3160 as tih = duration(OBCP7)
// 4.6 22-may-2007 SPR-3211 Include overheads in Calibration time
// 4.6.1 31-may-2007 Renamed patt to pattnod in "nodding_pointing"
// 4.6.2 27-jun-2007 SPR-3339 Correct SlewCal module    
// 4.7   20-sep-2007 SCR-3552 Add skewCorrec (in PACSyzoffsets) to pattnod
// 4.8   10-oct-2007 SCR-3628 Add Prime/Parallel to PacsPhotDefaults
// 5.0   14-jan-2008 DAC Use standard names for RA,DEC
// 6.0	 28-apr-2008 VDP SPR3689: fixed mapScanLegLength to be decimal
// ..... SCR 4196: implement Low Gain for Bright sources
// 6.1   24-jun-2008 DAC MapScanLength back to integer
// 6.2   17-jul-2008 DAC Inserted TMMarker600 at begin of each scan leg
// 7.0 	 15-sep-2008 VDP implement data_rates and HK rates SCR 4431
// 7.1   26-sep-2008 VDP remove data_rate (already in WriteOBSID and
// 	 	     	 PHOT_aot_proplogue/epilogue
//			 Merged with DAC on the fly  modif
// 7.2	 30-sep-2008 VDP MapScanLegLength back to double
// 7.3    9-oct-2008 VDP&DAC Debugged SCAN mode: removed no longer needed
//                           TMMarker, delay() and WriteBBend. Remove
//                           use of OBCP7 
// 7.4	23-apr-2009 VD SPR 6482
// 8.0  28-may-2009 VD/TM SCR 1292: no OBCP running during scan legs: only
// 		    	  WriteBBID and OBCP2 then delayed WriteEndID
// 9.0	10-jun-2009 VD SCR 7005: turn on science data (y/n) at slew time
// 		       (inc. extra prologue)
// 10.0 14-jul-2009 VD SCR: ??? removed Time Sync causing time shifts		       
// 11.0 09-sep-2009 VD SPR PACS-1292 added delay in final hold because of 
//                     scanMap loosing date due to too short tdec
// 12.0 11-sep-2009 VD PACS-1292 extra 12sec removed other solution from ROttsamer
//                     To be implmented later for testing
//                     PACS-???? nhold implementd for scanMap longer than 2hrs (7200sec)
// 13.0 15-sep-2009 VD PACS-1292 delay + 12sec removed... better solution in discussion   
// 14.0 09-oct-2009 VD PHS-1211     correcting PHS-1181 1800sec impl. 
// 15.0 27-oct-2009 VD PHS-1223 disable PHS-200 (hardcode == false)                
// 16.0 25-nov-2009 VD PHS-1255 mapScanAngle for Hommogenous coverage is mapScanAngle + 2.7 deg
//                              boloLSize = 219.0
// 17.0 27-nov-2009 VD PHS-1255 removed... something is fishy    
// 18.0 27-nov-2009 VD PHS-1255 re-instated.... with "critical" line corected   
// 19.0 01-dec-2009 VD PHS-1276                       
// 20.0 04-dec-2009 VD PHS-1276 corrections
// 21.0 09-mar-2020 VD PHS-1338: return sensitivity at central pixel in Scan Map
// 22.0 06-may-2010 VD PHS-1410 verbose == false
// 23.0 12-may-2010 VD PHS-1367 full implementation
// 24.0 21-sep-2010 VD PHS-1540 Slide Cal block back to the beginning of the slew
//
{int,int,int,double,{string,double,double,double,double,double,double,double}[]} obs PacsPhoto {
    string blue = "blue1" in ["blue1","blue2"];
    int repFactor = 1 in [1,1500]; // Hard limit for source = "point"
    string source = "point" in ["point","small","largeRaster","largeScan","none"]; // SrceSize
    string mapScanSpeed = "high" in ["high","medium","low"]; // Scan rate
    double mapScanLegLength = 30.0 in [1.0,1200.0]; //Scan leg [arcmin]
    int mapScanNumLegs = 2 in [1,1500]; //Number of scan legs
    string mapScanAngleRef = "inst" in ["sky","inst","i+c","s+c"];
    double mapScanConstrFrom = 0.0 in [0.0,360.0];
    double mapScanConstrTo = 0.0 in [0.0,360.0];
    double mapScanAngle = 0.0 in [0.0,360.0];
    double mapScanCrossScan = 2.0 in [2.0,480.0]; // Scan separation [arcsec]
    bool mapScanHomCoverage = true;
    bool mapScanSquare = false;
    double pointStep = 2.0 in [2.0,480.0];
    double lineStep = 2.0 in [2.0,480.0];
    string mapRasterAngleRef = "inst" in ["inst","i+c"];
    double mapRasterConstrFrom = 0.0 in [0.0,360.0];
    double mapRasterConstrTo = 0.0 in [0.0,360.0];
    int m = 2 in [2,100];
    int n = 1 in [1,100];
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    bool dither = false;
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    int naifid = 0; //RA,DEC or SSO
    double fluxPntBlu = 116.0 in [0.0,2.0E7]; // Flux density in blue band mJy
    double fluxPntRed = 150.0 in [0.0,2.0E7]; // Flux density in red band mJy
    double fluxExtBlu = 116.0 in [0.0,2.0E7]; // Flux in blue band MJy/sr
    double fluxExtRed = 40.0 in [0.0,2.0E7]; // Flux in red band MJy/sr
    int obsOverhead = 180; // Slew overhead
    /* End of input section */
}{
    // Begin "pointing" section
    // Overall "verbosity"
    bool verbose = false;
    // New nodding_pointing variable
    bool startAtOFF = false;
    // Conversion to deprecated variables
    bool noddingSel = true;
    if(source == "largeRaster") {
        string largeOptions = "raster";
        bool mapRasterSel = true;
        noddingSel = false;
    }
    if(source == "largeScan") {
        largeOptions = "scan";
        mapRasterSel = false;
        noddingSel = false;
    }
    int mapRasterNumCycles = repFactor;
    // Useful variables
    // Bolo size: Short Size, i.e. 32 pixels and Long Size [arcsec]
    double boloSSize = 1.75 * 60.0;
    double boloLSize = 219.0;
    //    double boloLSize = 3.5 * 60.0; 
    double boloArea = boloSSize * boloLSize;
    // 
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // Pointing mode has not been established yet
    int pointCase = 0;
    // Determine the pointing mode
    if(source == "point") {
        //     Variable needed to obtain choper throw from CAl-U
        string srcID = "pointSRC";
        //     Just for completiness, define a 1x1 raster
        m = 1;
        n = 1;
        //     Fine pointing without nodding is disallowed (pointCase remain null)
        if(!noddingSel) {
            string pointMode = "basic_fine_pointing";
            string shortDesc = "Point source (no nodding)";
            // not allowed           pointCase        = 11;
        } else {
            pointMode = "nodding_pointing";
            shortDesc = "Point source (nodding and chopping)";
            pointCase = 12;
            string yzoffsetROW = "P" + pointCase;
        }
    }
    if(source == "small") {
        srcID = "smallSRC";
        //   Obtain the size of the raster from CAL-U "SMALL_SRC_params"
        m = ilookup("SMALL_SRC_params","PHOT","mRast");
        n = ilookup("SMALL_SRC_params","PHOT","nRast");
        pointStep = dlookup("SMALL_SRC_params","PHOT","pointStep");
        lineStep = dlookup("SMALL_SRC_params","PHOT","lineStep");
        if(!noddingSel) {
            pointMode = "raster_pointing";
            shortDesc = " Small source (no nodding)";
            //         not allowed
            //           pointCase = 21;
        } else {
            pointMode = "nodding_raster_pointing";
            shortDesc = "Small source (nodding and chopping)";
            pointCase = 22;
            yzoffsetROW = "P" + pointCase;
        }
    }
    // Large source in Raster Mode
    if(source == "largeRaster") {
        srcID = "largeSRC";
        if(!noddingSel) {
            pointMode = "raster_pointing";
            shortDesc = "Large source, raster mode (chopping and no nodding)";
            pointCase = 31;
            yzoffsetROW = "P" + pointCase;
        } else {
            pointMode = "nodding_in_raster";
            shortDesc = "Large source, raster mode (chopping and nodding)";
            //         not allowed
            //           pointCase = 32;
        }
    }
    // Large source in Scan Mode
    if(source == "largeScan") {
        srcID = "largeSRC";
        pointMode = "line_scan_pointing";
        shortDesc = "Large source, line scan mode (no chopping)";
        //     For consistency
        m = 1;
        n = mapScanNumLegs;
        pointCase = 33;
        yzoffsetROW = "P" + pointCase;
    }
    // If pointCase is still 0, then something went wrong with the PointMode logic...
    if(pointCase == 0) {
        error("NODDING is incompatible with source: " + source);
    }
    // The pointing mode has been established. Continue with other input data
    // from HSPOT
    if(verbose) {
        debug_print("================> PointMode: " + pointMode);
    }
    //
    // confPHOT arrays (red and blu) compared to confSPEC
    //                       PHOT name         SPEC name
    // confPHOTred{ 0}       gain              capa_red;
    // confPHOTred{ 1}       N/A               nb_rdouts_ramp_red;
    // confPHOTred{ 2}       N/A               nb_rdouts_subramp_red;
    // confPHOTred{ 3}       same              comp_mode_red;
    // confPHOTred{ 4}       same              glitch_det_red;
    // confPHOTred{ 5}       ??                ramp_fit_alg_red;
    // confPHOTred{ 6        ??                nb_raw_red;
    // confPHOTred{ 7}       N/A               bias_r_red;
    // confPHOTred{ 8}       N/A               bias_d_red;
    //
    // Define confOBCP array.
    // NOTE: the conf arrays are inherited from PacsSpec, where the [0] element
    // represented the default values, and the [n] element represented values
    // to be used with the n-th wavelength. Here - PHOT - [0] still represents
    // the default values and [1] values corresponding to the chosen filter.
    // Could even use [1] and [2] for blue1 and blue2.... but will not!
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confPHOTblu and confPHOTred
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,0,0,0,0,0,0,0,0}];
    // Define paramsPHOT, a "tuple of tuples"
    // Estimator module returns {confPHOTblu,confPHOTred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // including a new section for Low Gain implementation SCR4196
    bool isBrightPacs = false;
    string calUFile = "isBrightPacsTrigger";
    // section defining triggering Fluxes (to be read in CALU table)
    double fluxPntRedTriggerLowGain = dlookup(calUFile,"Red","fluxPntTrigger");
    if(blue == "blue1") {
        double fluxPntBluTriggerLowGain = dlookup(calUFile,"Blue","fluxPntTrigger");
    } else {
        if(blue == "blue2") {
            fluxPntBluTriggerLowGain = dlookup(calUFile,"Green","fluxPntTrigger");
        }
    }
    double fluxExtRedTriggerLowGain = dlookup(calUFile,"Red","fluxExtTrigger");
    if(blue == "blue1") {
        double fluxExtBluTriggerLowGain = dlookup(calUFile,"Blue","fluxExtTrigger");
    } else {
        if(blue == "blue2") {
            fluxExtBluTriggerLowGain = dlookup(calUFile,"Green","fluxExtTrigger");
        }
    }
    // section test 
    if(fluxPntRedTriggerLowGain <= fluxPntRed || fluxPntBluTriggerLowGain <= fluxPntBlu || fluxExtRedTriggerLowGain <= fluxExtRed || fluxExtBluTriggerLowGain <= fluxExtBlu) {
        isBrightPacs = true;
    }
    // Obtain default values for "Prime" mode
    paramsPHOT = PacsPhotDefaults(srcID,"Prime",isBrightPacs,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    confPHOTred[0] = paramsPHOT{1};
    confOBCP[0] = paramsPHOT{2};
    // Now comes the module to estimate PACS parameters as a function of the
    // exposure time given by the user.
    // paramsPHOText (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,repeat_factor,nhold,dummy2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsPHOText = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for given HSPOT input. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("++Photo: confOBCP[0]: " + confOBCP[0]);
    }
    paramsPHOText = PacsPhotEstimatorOBCPn(pointCase,blue,repFactor,paramsPHOT,noddingSel,dither,verbose);
    // Copy estimates to respective tuples
    confPHOTblu[1] = paramsPHOText{0};
    confPHOTred[1] = paramsPHOText{1};
    confOBCP[1] = paramsPHOText{2};
    int nb_nods = paramsPHOText{3}{0};
    int repeat_factor = paramsPHOText{3}{1};
    int nhold = paramsPHOText{3}{2};
    /////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source.
    // We have to collect the duration of all TCs that will be released after the
    // PointingRequest 
    // First TC is associated with setting OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // compute aot_prologue for turning on the science data (SCR 7005)
    int timeDoSlewScience = duration(Pacs_PHOT_aot_Prologue(verbose,confPHOTblu,confPHOTred,confOBCP,blue));
    // Will call PacsPhotSlewCal to perform AOT prologue and CAL during
    // The time needed to perform these activities during slew is
    // with no prologue:
    bool doProlog = false;
    int timeSlewCal = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue));
    if(verbose) {
        debug_print("Duration of SlewCal: " + timeSlewCal);
    }
    // With prologue
    doProlog = true;
    int timeSlewCalProlog = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue));
    if(verbose) {
        debug_print("Duration of SlewCalProlog: " + timeSlewCalProlog);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsPhotCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsPhotCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // Duration of any nod leg or staring observation
    // Use OBCP3 for point source
    // Use OBCP4 for all others, except scan mode
    if(pointCase == 11 || pointCase == 12) {
        int timeOBS = duration(PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        if(verbose) {
            debug_print("TimeOBS OBCP3: " + timeOBS);
        }
    }
    if(pointCase == 22 || pointCase == 31) {
        timeOBS = duration(PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        if(verbose) {
            debug_print("TimeOBS OBCP4: " + timeOBS);
        }
    }
    if(pointCase == 33) {
        //    Scan speed (CAL-U FILE in new version??). Default is "low": 10 arcsec/sec
        double rate = 10.0;
        if(mapScanSpeed == "medium") {
            rate = 20.0;
        }
        if(mapScanSpeed == "high") {
            rate = 60.0;
        }
        double timeLEG = mapScanLegLength * 60.0 / rate;
        int tWriteEnd = duration(PacsBbWriteEndBB());
        int tWrite = duration(PacsBbWriteIdBB());
        //        int timeSetOBCP2 = duration(OBCP_TimeSynch3());
        timeOBS = iceil(timeLEG);
    }
    if(verbose) {
        debug_print("confOBCP[1]: " + confOBCP[1]);
        debug_print("==> Duration OBCP: " + timeOBS + " [sec] per nod; pointCase: " + pointCase);
    }
    // Finally deal with PHOT_aot_epilogue and WriteEndID
    //   int timeEpilogue = duration(PHOT_aot_epilogue());
    //   testing PACS-1292
    int timeEpilogue = duration(PacsBbPhot_aot_epilogue());
    int timeEndID = duration(WriteEndID());
    timeEpilogue = timeEpilogue + timeEndID;
    if(verbose) {
        debug_print("Duration aot_epilogue: " + timeEpilogue);
    }
    // We have all elements to issue a Pointing Request and generate TCs
    // - duration of SlewCAL
    // - duration of OBS (one pointing)
    // - nb of nods or nb of raster points
    // - nhold
    ///DAC
    // TBD    nhold = 0;
    ///DAC
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    //  The nodding step has been estimated already (PacsPhotDefaults). However,
    //  there are no provisions to carry that information here. Easiest is to
    //  read again the relevant CAL-U table
    //  Read nod amplitude [arcsec]
    double nodThrow = dlookup("PHOT_CHOP_params",srcID,"NOD");
    int max_dither = confOBCP[1]{1};
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("TimeSlewCal   : " + timeSlewCal);
        debug_print("TimeOBS       : " + timeOBS);
        debug_print("m/n           : " + m + "/" + n);
        debug_print("nb_nods/repeat_factor/nhold: " + nb_nods + "/" + repeat_factor + "/" + nhold);
        debug_print("NOD amplitude for " + srcID + ": " + nodThrow + " [arcsec]");
        int chpSRC = confOBCP[1]{12};
        int chpREF1 = confOBCP[1]{13};
        int chpREF2 = confOBCP[1]{14};
        debug_print("#### CHOP SRC/REF1/REF2: " + chpSRC + "/" + chpREF1 + "/" + chpREF2);
        debug_print("CHOP dither: " + max_dither);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Issue pointing request
    // Virtual aperture
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("##Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("##skewCorrec : " + skewCorrec);
    }
    // SCAN/RASTER orientation for "scan map" and "chopped raster"
    // RASTER defines mapRasterAngleRef   = "inst" in ["inst", "i+c"];
    // SCAN defines   mapScanAngleRef = "sky" in ["sky", "inst", "s+c", "i+c"]; 
    // By default S/C moves in instrument coordinates
    bool useINST = true;
    if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
        useINST = false;
    }
    // Act according to pointCase
    // POINT source, i.e. 3.4 nodding_pointing
    if(pointCase == 12) {
        //  Issue pointing request (when possible use JBr's variable names for clarity)
        //  SlewCal during slew
        string ib = "P01_0";
        int tslewmin = timeSetOBSID + timeSlewCalProlog;
        int tih = 0;
        // I wanted to be smart but I cannot because tfh is NOT flexible
        int tfh = timeEpilogue;
        bool fixed = false;
        double pattnod = 0.0 + skewCorrec;
        int nnods = nb_nods;
        int tp = timeOBS;
        int tloadslewmin = 0;
        int nload = 0;
        int thold = timeSlewCal;
        //  int nhold        Already defined
        //  Do not start at nod position
        startAtOFF = false;
        int[] fromPntReq = nodding_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nnods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
        if(verbose) {
            debug_print("##### nodding_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tss = fromPntReq[2];
        tload = fromPntReq[3];
    }
    // SMALL source or LARGE raster with nodding
    if(pointCase == 22 || pointCase == 32) {
        //  "nodding_raster_pointing" (3.6 in Pointing document)
        ib = "P01_0";
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        tih = 0;
        tfh = timeEpilogue;
        double patt = 0.0;
        //  Chopper moves along -Y-axis
        pattnod = 270.0 + skewCorrec;
        //  Chop nodThrow was already established
        //  nodThrow = From CAL-U table
        int k = 0;
        fixed = false;
        int nrepeat = repeat_factor;
        double d1 = pointStep;
        double d2 = lineStep;
        thold = timeSlewCal;
        tp = timeOBS;
        nnods = nb_nods;
        //  New arguments for pointing request; will be dealt with next iteration
        int top = 0;
        double raoff = 0.0;
        double decoff = 0.0;
        nrepeat = repeat_factor;
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nnods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
        if(verbose) {
            debug_print("##### nodding_in_raster_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
    }
    // SMALL or LARGE source with no nodding 
    if(pointCase == 21 || pointCase == 31) {
        //  raster_pointing (mode 3.5)
        ib = "P01_0";
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        tih = 0;
        tfh = timeEpilogue;
        //  Perform raster in instrument coordinates
        fixed = false;
        //SPR-2431 Raster lines along y-axis
        patt = 90.0;
        d1 = pointStep;
        d2 = lineStep;
        tp = timeOBS;
        nrepeat = repeat_factor;
        thold = timeSlewCal;
        nhold = 0;
        k = 0;
        top = 0;
        raoff = 0.0;
        decoff = 0.0;
        fromPntReq = raster_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
        if(verbose) {
            debug_print("##### raster_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        trep = fromPntReq[4];
        tsop = fromPntReq[5];
    }
    if(pointCase == 33) {
        //   line_scan_pointing. Keep (most of) JBr's variable names
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        //  Case of homogeneous coverage
        double pi = 3.1415926535;
        //  degrees to radians    
        double dtor = 0.0;
        double rtod = 0.0;
        double halfDiag = 0.0;
        double halfDiagAngle = 0.0;
        dtor = 2.0 * pi / 360.0;
        rtod = 1.0 / dtor;
        halfDiag = sqrt(boloSSize * boloSSize + boloLSize * boloLSize) / 2.0;
        halfDiagAngle = atan(boloSSize / boloLSize) * rtod;
        // Add further constraint from RV (SPR-2889)
        // Add SPR-2699 further logic: mapScanAngleRef overrides ScanHom and ScanSquare
        if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
            mapScanHomCoverage = false;
            mapScanSquare = false;
        }
        //  Could simplify logic after SPR-2699 (mapScanHomCoverage cannot be true
        //  unless inst or i+c have been specified)
        // PHS-1255
        // 
        //        if(mapScanHomCoverage == true && (mapScanAngleRef == "inst" || mapScanAngleRef == "i+c")) {
        //            mapScanCrossScan = halfDiag * (abs(sin(dtor * (mapScanAngle + 90.0 - halfDiagAngle))) + abs(cos(dtor * (90.0 - halfDiagAngle - mapScanAngle + 90.0))));
        //            if(verbose) {
        //                debug_print("New mapScancCross: " + mapScanCrossScan);
        //            }
        //        }else{
        //	   if(mapScanAngleRef == "inst" || mapScanAngleRef == "i+c") {
        //	      mapScanAngle = mapScanAngle + 2.5;
        //	   }
        //	}
        //	
        if(mapScanAngleRef == "inst" || mapScanAngleRef == "i+c") {
            if(mapScanHomCoverage == true) {
                mapScanCrossScan = halfDiag * (abs(sin(dtor * (mapScanAngle + 90.0 - halfDiagAngle))) + abs(cos(dtor * (90.0 - halfDiagAngle - mapScanAngle + 90.0))));
                mapScanAngle = mapScanAngle + 2.5;
                if(verbose) {
                    debug_print("New mapScancCross: " + mapScanCrossScan);
                }
            } else {
                mapScanAngle = mapScanAngle + 2.5;
            }
        }
        // Case of square map request
        if(mapScanSquare == true && mapScanHomCoverage == true) {
            mapScanNumLegs = iceil(60.0 * mapScanLegLength / mapScanCrossScan);
            if(verbose) {
                debug_print("New mapScanNumLegs: " + mapScanNumLegs);
            }
        }
        ib = "P01_0";
        tih = 0;
        tfh = timeEpilogue;
        //   Use instrument coordinates unless HSPOT says otherwise
        fixed = false;
        if(useINST == false) {
            fixed = true;
        }
        patt = mapScanAngle;
        n = mapScanNumLegs;
        d1 = 60.0 * mapScanLegLength;
        d2 = mapScanCrossScan;
        thold = timeSlewCal;
        // BACK to nhold = 0: see PHS-1211
        nhold = 0;
        //        double onTargetTime = double(n * timeOBS);
        //        double minTimeNoHold = 1800.0;
        //        int n_to_hold = iceil(onTargetTime / minTimeNoHold);
        //        double n_to_hold = onTargetTime / minTimeNoHold;
        //        if(n_to_hold > 1.0) {
        //            double nLegs = double(n);
        //            nhold = iceil((nLegs - 1.0) / n_to_hold);
        //        } else {
        //            if(repFactor > 1) {
        //                nhold = n;
        //            } else {
        //                nhold = 0;
        //            }
        //        }
        //        if(verbose) {
        //            debug_print("onTargetTime/nhold/ntohold:" + onTargetTime + "/" + nhold + "/" + n_to_hold);
        //        }
        nrepeat = repFactor;
        if(verbose) {
            debug_print("Map reference: " + mapScanAngleRef + "=" + fixed);
        }
        fromPntReq = line_scan_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,n,d1,d2,rate,thold,nhold,nrepeat);
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tacc = fromPntReq[2];
        tdec = fromPntReq[3];
        tl = fromPntReq[4];
        tll = fromPntReq[5];
        trep = fromPntReq[6];
        if(verbose) {
            debug_print("##### line_scan_with_hold");
        }
        if(verbose) {
            debug_print("##### rate: " + rate + " arcsec/sec");
        }
        //   Here we record how long it takes to scan a line [sec]
        int scanTime = tl;
        //   Gather the overheads
        int scanOVER = tacc + tdec;
    }
    if(verbose) {
        debug_print("PointReq:  " + fromPntReq + " for pointCase: " + pointCase);
        debug_print("PointMode: " + pointMode);
    }
    // End of "pointing" section
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
        debug_print("++++++++++++++++++++++++ State Machine");
    }
    // Initialize some "global" variables
    int totalOBStime = 0;
    int totalOBSover = 0;
    int totalCALtime = 0;
    int totalCALover = 0;
    int nbSCANlegs = 0;
    // Issue TCs
    int[] state = [0];
    int nbOBS = 0;
    while(state[0] >= 0) {
        state = next_state();
        //// STATE = SLEW
        if(state[0] == 1) {
            if(verbose) {
                int tNOW = time();
                debug_print("=== SLEW/CAL starts at: " + tNOW);
            }
            //     Set OBSID
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            doProlog = true;
            //                if(tslew > tslewmin) {
            //                    delay(tslew - tslewmin);
            //                }
            //                tNOW = time();
            //                if(verbose) {
            //                    debug_print("SLEW_CAL starts at   " + tNOW);
            //                }
            int[] calTime = PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue);
            totalCALtime = totalCALtime + calTime[3];
            totalCALover = totalCALover + calTime[0];
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW/CAL ends at: " + tNOW);
                debug_print("    TotalCalTime: " + totalCALtime);
            }
        } else {
            //// STATE = INIT_HOLD
            if(state[0] == 2) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== INIT_HOLD starts at: " + tNOW);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("=== INIT_HOLD ends at: " + tNOW);
                }
            } else {
                //// STATE = POINT
                if(state[0] == 3) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== POINT starts at: " + tNOW);
                    }
                    if(pointCase == 12) {
                        //       Observation includes chopping
                        int[] obsTime = PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                    } else {
                        //       Observation does includes chopping
                        obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                    }
                    totalOBStime = totalOBStime + obsTime[1] + obsTime[2];
                    totalOBSover = totalOBSover + obsTime[0];
                    nbOBS = nbOBS + 1;
                    if(verbose) {
                        debug_print("POINT: POINTobs: " + nbOBS);
                    }
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== POINT ends at: " + tNOW);
                    }
                } else {
                    //// STATE = CAL_HOLD
                    if(state[0] == 6) {
                        doProlog = false;
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== CAL-HOLD starts at: " + tNOW);
                        }
                        calTime = PacsPhotSlewCal(false,confPHOTblu,confPHOTred,confOBCP,doProlog,blue);
                        totalCALtime = totalCALtime + calTime[3];
                        totalCALover = totalCALover + calTime[0];
                        if(verbose) {
                            debug_print("Accumulated CALtime: " + totalCALtime);
                        }
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== CAL-HOLD ends at: " + tNOW);
                        }
                    } else {
                        //// STATE = NOD
                        if(state[0] == 7) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== NOD starts at: " + tNOW);
                            }
                            if(pointCase == 12) {
                                //       Observation includes chopping
                                obsTime = PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                            } else {
                                //       Observation does includes chopping
                                obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                            }
                            totalOBStime = totalOBStime + obsTime[1] + obsTime[2];
                            totalOBSover = totalOBSover + obsTime[0];
                            nbOBS = nbOBS + 1;
                            if(verbose) {
                                debug_print("NOD: NODobs: " + nbOBS);
                            }
                        } else {
                            //// STATE = LINE
                            if(state[0] == 8) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== SCAN starts at: " + tNOW);
                                }
                                PacsBbWriteIdBB();
                                //                                OBCP_TimeSynch3();
                                int tDelay = fromPntReq[4] - tWriteEnd;
                                delay(tDelay);
                                PacsBbWriteEndBB();
                                totalOBStime = totalOBStime + scanTime;
                                totalOBSover = totalOBSover + scanTime + scanOVER;
                                nbSCANlegs = nbSCANlegs + 1;
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== SCAN mode, leg: " + nbSCANlegs);
                                    debug_print("    TotalOBSTime: " + totalOBStime);
                                    debug_print("    tacctdec    : " + scanOVER);
                                    debug_print("=== SCAN ends at: " + tNOW);
                                }
                            } else {
                                //// STATE = FINAL_HOLD
                                if(state[0] == 5) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== FinalHOLD starts at: " + tNOW);
                                    }
                                    //                                    PHOT_aot_epilogue();
                                    //                                    Testing PACS-1292
                                    PacsBbPhot_aot_epilogue();
                                    WriteEndID();
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== FinalHOLD ends at: " + tNOW);
                                    }
                                } else {
                                    //// STATE = END
                                    if(state[0] == -1) {
                                        tNOW = time();
                                        if(verbose) {
                                            debug_print("=== END state; time now: " + tNOW);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    int overOBS = totalOBSover - totalOBStime;
    int overCAL = totalCALover - totalCALtime;
    if(verbose) {
        debug_print("+++ OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("    totalOBStime :" + totalOBStime);
        debug_print("    totalOBSover :" + overOBS);
        debug_print("    totalCALtime :" + totalCALtime);
        debug_print("    totalCALover :" + overCAL);
    }
    // Time considerations
    // The "science" part of the observations lasts tobs seconds (tobs from
    // PointReq[0])
    // Time on source is totalOBStime. Hence
    int instrumentAndObservationOverhead = tobs - totalOBStime;
    // Begin "calculation" and report section
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "ObsMode: <B>" + shortDesc + "</B>";
    lineCnt = lineCnt + 1;
    // More pointing information
    if(pointCase == 12) {
        msgLine[lineCnt] = "<p>Chopper throw: " + nodThrow + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        double mapArea = boloArea;
        msgLine[lineCnt] = "<p>PHOTO footprint: " + dformat(boloLSize,2) + " x " + dformat(boloSSize,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>PHOTO area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    if(pointCase == 21 || pointCase == 31 || pointCase == 22) {
        msgLine[lineCnt] = "<p>Raster points/lines: " + m + "/" + n + "</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Step size: " + d1 + " x " + d2 + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        //   Mapped region
        double sizeL = boloLSize + double(m - 1) * d1;
        double sizeS = boloSSize + double(n - 1) * d2;
        mapArea = sizeL * sizeS;
        msgLine[lineCnt] = "<p>PHOTO observed size: " + dformat(sizeL,2) + " x " + dformat(sizeS,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>PHOTO observed area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    if(pointCase == 33) {
        msgLine[lineCnt] = "<p>ScanLeg: " + d1 + " [arcsec]; number of legs: " + n + "; leg separation: " + dformat(d2,1) + " [arcsec], scan speed: " + dformat(rate,2) + " [arcsec/sec]</p>";
        lineCnt = lineCnt + 1;
        //  For the mapped area assume that we scan along the Large side of bolo
        //  Size along scan line
        sizeL = d1 + boloSSize;
        //  Size covered by successive legs
        sizeS = boloLSize + double(n - 1) * d2;
        msgLine[lineCnt] = "<p>PHOTO observed size: " + dformat(sizeL,2) + " x " + dformat(sizeS,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        mapArea = sizeL * sizeS;
        msgLine[lineCnt] = "<p>PHOTO observed area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    // Nodding pattern
    msgLine[lineCnt] = "<h3> Nod pattern (as applicable)</h3>";
    lineCnt = lineCnt + 1;
    if(nb_nods == 0) {
        if(pointCase != 33) {
            msgLine[lineCnt] = " No nodding, S/C stays at nominal position<";
        } else {
            msgLine[lineCnt] = " No nodding, S/C is in line scan mode<";
        }
        lineCnt = lineCnt + 1;
    }
    if(nb_nods == 1) {
        msgLine[lineCnt] = "   A->B ";
        lineCnt = lineCnt + 1;
    }
    if(nb_nods == 2) {
        msgLine[lineCnt] = "   A->B B->A ";
        lineCnt = lineCnt + 1;
    }
    if(nb_nods > 2) {
        int aux1 = nb_nods - 2;
        msgLine[lineCnt] = "   A->B B->A and " + aux1 + " more A->B or B->A leg(s) ";
        lineCnt = lineCnt + 1;
    }
    // Add dithering bla-bla
    msgLine[lineCnt] = "<h3> Dithering information</h3>";
    lineCnt = lineCnt + 1;
    if(dither && pointCase == 12) {
        int half_dither = max_dither / 2;
        msgLine[lineCnt] = "<p> Three position spatial dithering performed with the chopper (" + max_dither + " and " + half_dither + " chopper engineering units)</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Dithering information is not applicable.</p>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "<h3> Duration information</h3>";
    lineCnt = lineCnt + 1;
    tNOW = time();
    msgLine[lineCnt] = "<p>AOT duration (w/overheads): " + tNOW + " [sec]</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p><I>(AOT duration comprises 'on-sky' plus setup and CAL during slew)</I></p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Breakdown of AOT duration:</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul><li>On-sky time (w/overheads): " + tobs + " [sec]</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>(actual on-sky time: " + totalOBStime + " [sec])</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Setup and CAL during slew (w/overheads): " + tslew + " [sec]</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>(actual calibration time: " + totalCALtime + " [sec])</li></ul>";
    lineCnt = lineCnt + 1;
    // The charged obsOverhead is the MAX between tslew, nominalOverhead 
    if(tslew > obsOverhead) {
        obsOverhead = tslew;
    }
    int tcharged = tobs + obsOverhead;
    msgLine[lineCnt] = "<p><b>AOT cost</b> (includes time to slew to source): " + tobs + " + " + obsOverhead + " = " + tcharged + " [sec]</p>";
    lineCnt = lineCnt + 1;
    // On-SRC time calculations start here
    // Uses new algorithm: on-SRC = totalOBStime*boloArea/mapArea
    // OBS times above is for all pointings. For a raster, have to divide
    // by number of raster positions, i.e. m*n
    if(pointCase != 33) {
        //   If steps are smaller than boloXSize, same sky will be seen several times
        //   Compute Short and Long dimension number of sightings (assume source is
        //   placed to maximize number of sightings, i.e. at the proper edge of bolo)
        // NOTE: exchanged pointStep and lineStep as suggested by Roland V.
        int nbShort = iceil(boloSSize / lineStep);
        //   Cannot be larger than m
        if(nbShort > m) {
            nbShort = m;
        }
        int nbLong = iceil(boloLSize / pointStep);
        //   Cannot be larger than n
        if(nbLong > n) {
            nbLong = n;
        }
        if(verbose) {
            debug_print("nbShort/nbLong: " + nbShort + "/" + nbLong);
        }
        //   Time per raster point
        double auxTIMEold = double(totalOBStime * nbShort * nbLong) / double(m * n);
        double auxTIME = double(totalOBStime) * boloArea / mapArea;
        //   Small source is a special case where by design the SRC is always in view
        if(pointCase == 22) {
            auxTIME = auxTIMEold;
        }
    } else {
        //   elementary integration time [sec] will be computed as "transit" time
        //   of the source across the BOLO detector
        //   Case of scan leg size smaller than boloSize
        // PHS-1338 need to return sensitivity at central pixel for small maps
        // 
        double sizeAux = boloSSize;
        if(d1 <= boloSSize) {
            sizeAux = d1;
        }
        //   Assume source is 1st seen on row=1; each successive scan may see again
        //   the same sky region if mapScanCrossScan is smaller than bolo width.
        //   The number of times the same sky is scanned again:
        if(mapScanCrossScan != 0.0) {
            int nbCross = iceil(boloLSize / mapScanCrossScan);
            if(verbose) {
                debug_print("nbCross: " + nbCross);
            }
        } else {
            nbCross = repFactor;
        }
        //   nbCross cannot be larger than mapScanNumLegs
        if(nbCross > mapScanNumLegs) {
            nbCross = mapScanNumLegs;
        }
        if(verbose) {
            debug_print("nbCross: " + nbCross);
        }
        //   The "crossing time"
        double crossTime = sizeAux / rate;
        if(verbose) {
            debug_print("crossTime: " + crossTime);
        }
        //   AuxTime is "crossing time" * number of crossings * repFactor
        auxTIMEold = double(repFactor * nbCross) * crossTime;
        // New way of estimating the "observing" time     
        auxTIME = double(totalOBStime) * boloArea / mapArea;
        // PHS-1338
        if(mapScanLegLength < 4.0) {
            double centTIME = mapScanLegLength * 60.0 / rate * double(mapScanNumLegs * repFactor);
        } else {
            centTIME = 4.0 * 60.0 / rate * double(mapScanNumLegs * repFactor);
        }
        // s = sens / sqrt(time)
        //with time = (length / speed ) * n* r
        // with:
        // * length = scan leg length if length < 4 arcmin otherwise 4 arcmin,
        // * speed = scan speed (20"/s or 60"/s)
        // * n = number of scan legs
        // * r = map repetition factor
        //
    }
    if(verbose) {
        debug_print("AuxTIMEold: " + auxTIMEold + " [sec]");
        debug_print("AuxTIME   : " + auxTIME + " [sec]");
        if(pointCase == 33) {
            debug_print("centTIME   : " + centTIME + " [sec]");
        }
    }
    // Pass the pointing mode to RMS (may need it for SRC,REF considerations)
    double[] pixRMS = PacsPhotNoiseRMS(pointCase,blue,auxTIME);
    // PHS-1338
    if(pointCase == 33) {
        double[] centPixRMS = PacsPhotNoiseRMS(pointCase,blue,centTIME);
    } else {
        centPixRMS = [0.0,0.0];
    }
    msgLine[lineCnt] = "<h3> Sensitivity information </h3>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Effective on-sky time (one spatial resolution element) : " + dformat(auxTIME,1) + " [sec]</p>";
    if(pointCase == 33) {
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Effective on-sky time (central resolution element) : " + dformat(centTIME,1) + " [sec]</p>";
    }
    lineCnt = lineCnt + 1;
    // Point source or extended source
    if(pointCase == 11 || pointCase == 12) {
        msgLine[lineCnt] = "<p>Point RMS (red): " + dformat(pixRMS[0],1) + " [mJy]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Point RMS (blu): " + dformat(pixRMS[1],1) + " [mJy]</p>";
        lineCnt = lineCnt + 1;
    } else {
        if(pointCase == 33) {
            msgLine[lineCnt] = "<p>central area point-source sensitivity (red): " + dformat(centPixRMS[0],2) + " [mJy]";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "<p>central area point-source sensitivity (blue): " + dformat(centPixRMS[1],2) + " [mJy]";
            lineCnt = lineCnt + 1;
        }
        msgLine[lineCnt] = "<p>map averaged point-source sensitivity (red): " + dformat(pixRMS[0],2) + " [mJy]; extended surface brightness sensitivity: " + dformat(pixRMS[2],2) + " [MJy/sr]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>map averaged point-source sensitivity (blue): " + dformat(pixRMS[1],2) + " [mJy]; extended surface brightness sensitivity: " + dformat(pixRMS[3],2) + " [MJy/sr]</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("PACS Photometer AOT",lineCnt,msgLine);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    // Everything below is new request from RV. Use variable names consistent
    // with input variables in PacsPhoto.def
    // Return demanded tuples
    // ID for band blue1 
    string bandBlue = "60-85";
    if(blue == "blue2") {
        bandBlue = "85-130";
    }
    double pntRMSBlue = pixRMS[1];
    // Watch out for infinite division!!
    // Better watch out for silly limits (SPR-2627)
    if(pntRMSBlue > 0.0010) {
        double pntSNBlu = fluxPntBlu / pntRMSBlue;
    } else {
        pntSNBlu = 0.0;
    }
    string bandRed = "130-210";
    double pntRMSRed = pixRMS[0];
    if(pntRMSRed > 0.0010) {
        double pntSNRed = fluxPntRed / pntRMSRed;
    } else {
        pntSNRed = 0.0;
    }
    double extRMSBlue = pixRMS[3];
    // Watch out for infinite division!!
    if(extRMSBlue > 0.0010) {
        double extSNBlu = fluxExtBlu / extRMSBlue;
    } else {
        extSNBlu = 0.0;
    }
    double extRMSRed = pixRMS[2];
    if(extRMSRed > 0.0010) {
        double extSNRed = fluxExtRed / extRMSRed;
    } else {
        extSNRed = 0.0;
    }
    double centPixRMSblu = centPixRMS[1];
    double centPixRMSred = centPixRMS[0];
    {string,double,double,double,double,double,double,double}[] noiseSummary = [{bandBlue,fluxPntBlu,pntSNBlu,pntRMSBlue,fluxExtBlu,extSNBlu,extRMSBlue,centPixRMSblu},{bandRed,fluxPntRed,pntSNRed,pntRMSRed,fluxExtRed,extSNRed,extRMSRed,centPixRMSred}];
    if(verbose) {
        debug_print("NoiseSumm: " + noiseSummary);
        debug_print("OBStime/CALtime/Overhead/chopthrow: " + totalOBStime + "/" + totalCALtime + "/" + instrumentAndObservationOverhead + "/" + nodThrow);
    }
    //  return {totalOBStime,totalCALtime,instrumentAndObservationOverhead,

    return {totalOBStime,fromPntReq[1],instrumentAndObservationOverhead,nodThrow,noiseSummary};
}

// File          : PACS_Spec_Gra_Tune_PID
// Missionphase  : PACS FM Test
//
// Purpose       : Dedicated test as input to CSL to constrain the Grating PID parameters
//
// Author        : P. Royer
// Arguments     : grat_start_pos : grating starting position
//
// Description   : positions the grating at ~ 5 degrees from hard stop
//	   executes 10 small grating steps up & down
//	   executes a big grating step up (~ 5 degrees)
//
// Comments : . Prerequisite : spec_mec_setup  has been executed
//                   . Diag HK is supposed to be recorded at 1KHz
//
// Version       : 1.0
// History       : 1.0 / 19-Apr-2006 
//
block PACS_Spec_Gra_Tune_PID PACS 156 {
    int grat_start_pos = 80000; // grating starting position (~3 degrees from the hard stop)
}{
    // Register start of BB
    WriteBBID($BBID);
    // PARAMETERS
    // 
    int nsteps_small = 5;
    // nb   of small grating steps
    int nsteps_big = 4;
    // nb   of big    grating steps
    int grat_step_small = 117;
    // size of small grating steps
    int grat_step_big = 233010;
    // size of big    grating steps
    int slew_time_small = 1;
    // slew time for small grating steps
    int slew_time_big = 15;
    // slew time for big    grating steps
    int grat_step_small_neg = -grat_step_small;
    // small grating step for movements down
    //
    // PRE-POSITION THE GRATING
    //
    Pacs_DMC_MOVE_GRAT_ABS(grat_start_pos);
    delay(45);
    //
    // GRATING MOVEMENTS (small steps loops, separated by big steps)
    //
    for(int loop1 = 1 .. nsteps_big) {
        for(int loop2 = 1 .. nsteps_small) {
            Pacs_DMC_MOVE_GRAT_REL(grat_step_small);
            delay(slew_time_small);
        }
        for(int loop3 = 1 .. nsteps_small) {
            Pacs_DMC_MOVE_GRAT_REL(grat_step_small_neg);
            delay(slew_time_small);
        }
        Pacs_DMC_MOVE_GRAT_REL(grat_step_big);
        delay(slew_time_big);
    }
    //
    // FINAL LOOPS ON SMALL STEPS
    //
    for(int loop4 = 1 .. nsteps_small) {
        Pacs_DMC_MOVE_GRAT_REL(grat_step_small);
        delay(slew_time_small);
    }
    for(int loop5 = 1 .. nsteps_small) {
        Pacs_DMC_MOVE_GRAT_REL(grat_step_small_neg);
        delay(slew_time_small);
    }
    //
    // RE-POSITION THE GRATING
    //
    Pacs_DMC_MOVE_GRAT_ABS(500000);
    delay(45);
    // Mark End of Block
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       :  Check the Stability of the grating under a given set of controller parameters
//
// Description  : Configuration of the grating (incl Homing), enable & disable the grating after 2 relative movements.
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
//                 1.1  13-Nov-2007 BV - added MOIS comments
//		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
obs PacsEng_Spec_Gra_IST_Check_4 {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Check_4                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_Check_4                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Gra_IST_Check_4()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Gra_IST_Check_4();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       :  Check the Stability of the grating under a given set of controller parameters
//
// Description  : Configuration of the grating, enable & disable the grating after a few seconds.
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
//                 1.1  13-Nov-2007 BV Added MOIS comments
//		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
obs PacsEng_Spec_Gra_IST_Check_1 {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Check_1                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_Check_1                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Gra_IST_Check_1()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Gra_IST_Check_1();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       :  Check the Stability of the grating under a given set of controller parameters
//
// Description  : Configuration of the grating, enable & disable the grating after two relative movements
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
//                 1.1  13-Nov-2007 BV : Mois comments
//		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
obs PacsEng_Spec_Gra_IST_Check_2 {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Check_2                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_Check_2                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Gra_IST_Check_2()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Gra_IST_Check_2();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Purpose       : returns KeyWaves given the OrderSel
//                 This version gives one KeyWave per represented order in
//                 UserWaves
//
// CUS author    : JDP
// Script file   : PacsSpecKeyWaves.txt 
//
// Input arguments
// type    name        Description
// string  orderSel    oder selection
//
// Return values
// Type         Description
// double []    Key wavelength associated with orderSel
// Description   : get Key Wave a function of orderSel from calU file
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 1.0 14-may-2008 created
//                 1.1 22-apr-2009 updated SPR 5447 
//                 added selection of Key as fucntion of requested refWL
//                 as function of filter and order positions
//                 1.2 24-nov-2009 VD PHS-1264 change bands...
//                 2.0 PHS-1272 and PHS-1274
double procedure PacsSpecKeyWaves {
    string orderSel = "order2" in ["order1","order2","order3","sed2","sed3","sed4","sedb2a","sedb2b","sedb3a"];
    double[] refWL = [60.0];
}{
    string calUFile = "KEY_WAVES";
    // Local variables
    double refWL1 = refWL[0];
    string order = "2";
    string keyWave = "KeyWave1";
    double waves = 0.0;
    if(refWL1 < 103.1) {
        if(orderSel == "order2" || orderSel == "sed2" || orderSel == "sedb2b") {
            order = "2";
            keyWave = "KeyWave1";
        } else {
            if(orderSel == "order3" || orderSel == "sedb2a" || orderSel == "sedb3a") {
                order = "3";
                keyWave = "KeyWave1";
            }
        }
    } else {
        if(refWL1 >= 103.1) {
            if(orderSel == "order2" || orderSel == "sed2" || orderSel == "sedb2b") {
                order = "2";
                keyWave = "KeyWave2";
            } else {
                if(orderSel == "order3" || orderSel == "sedb2a" || orderSel == "sedb3a") {
                    order = "3";
                    keyWave = "KeyWave2";
                }
            }
        }
    }
    if(orderSel == "order1" || orderSel == "sed3") {
        order = "1";
        keyWave = "KeyWave1";
    } else {
        if(orderSel == "sed4") {
            order = "23";
            keyWave = "KeyWave1";
        }
    }
    waves = dlookup(calUFile,order,keyWave);
    sync();

    return waves;
}

// CVS comments  : $Id: PacsSpecSlewCal_Flex.txt,v 1.13 2008/02/07 16:17:14 dcesarsk Exp $ 
// Purpose       : Invoke a PACS calibration OBCP during slew to source;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsSpecSlewCal_Flex.txt 
//
// Input arguments
// Type                     Name          Description
// bool                     verbose       Debug_print or not 
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECblu   BLUE SPU parameters
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECred   RED  SPU parameters
// {int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int}[]  confOBCP      OBCP parameters
//  bool                    doPROLOG      Perform/don't AOT prologue
//  double []               keyWAVE       One or several key wavelengths
//  int                     filter        Where to move FltW (as order)
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per key line
//
// Description   : Perform AOT prologue and then OBCP #13.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 0.1 DAC 10-may-2006 New version losely based on old 
//                     PacsSpecSlewCal. Implies recasting OBCP13params as 
//                     other OBCP CAL-U files
// 0.2 30-may-2006 Adapted to SPEC_get_grat_info modified for freq switch
// 0.3  1-jun-2006 ORDER 2 and 3 are nolonger simultaneously allowed
//                 Use grating strategy as OBCP22 and 27: grating remains
//                 where DMC left it (grat_def_time = 0)
// 1.0 15-feb-2007 SlewCal is supposed to leave the grating ready to start
//                 observing the 1st "science" line
//     16-feb-2007 Error in call to OBCP: grating should remain at 
//                 new_grat_def_pos (was grat_park) 
// 1.1 14-mar-2007 Add extraConf in call to SPEC_get_grat_info  
// 1.2  8-may-2007 Add orderSel needd by SPEC_get_grat_info
// 1.3 10-oct-2007 SCR3632. SPEC_get_grat_info is called with KHI
int[][] procedure PacsSpecSlewCal_Flex {
    /* verbose debug print                          */
    bool verbose = false;
    /* SPEC parameters for BLU and RED              */
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{12,64,16,16,1,1,3,80,30}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{12,64,16,16,1,1,3,80,30}];
    /* OBCP parameters                               */
    {int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{1,0,1,133,1,-21200,2,21350,1,664}];
    /* Perform/don't AOT prologue                    */
    bool doPROLOG = true;
    /* One or several key wavelengths                */
    double[] waves = [60.0];
    /* Where to leave FltW (as order)                */
    string fltPOS = "POS A";
    /* User defined grating order                    */
    int order = 2;
}{
    // Array to collect OBCP times per line
    // NOTE: time variables in units of either number of ramps (SPEC) or
    // number of readouts (BOLO) or plain seconds. The calling program 
    // must convert, if applicable, this information into actual duration 
    // in true time units [seconds].
    // SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky), CAL source, 
    // and overheads (wait for something). Total duration is given by duree_num. 
    // If no error, this duration must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    int[][] dureeCalKey = [[0,0,0,0,0]];
    // Long sequence to "unpack" default values from tuples
    //
    // UNPACK confSPEC blu & red
    //
    int capa_blu = confSPECblu[0]{0};
    int nb_rdouts_ramp_blu = confSPECblu[0]{1};
    int nb_rdouts_subramp_blu = confSPECblu[0]{2};
    int comp_mode_blu = confSPECblu[0]{3};
    int glitch_det_blu = confSPECblu[0]{4};
    int ramp_fit_alg_blu = confSPECblu[0]{5};
    int nb_raw_blu = confSPECblu[0]{6};
    int bias_r_blu_mV = confSPECblu[0]{7};
    int bias_d_blu_mV = confSPECblu[0]{8};
    int capa_red = confSPECred[0]{0};
    int nb_rdouts_ramp_red = confSPECred[0]{1};
    int nb_rdouts_subramp_red = confSPECred[0]{2};
    int comp_mode_red = confSPECred[0]{3};
    int glitch_det_red = confSPECred[0]{4};
    int ramp_fit_alg_red = confSPECred[0]{5};
    int nb_raw_red = confSPECred[0]{6};
    int bias_r_red_mV = confSPECred[0]{7};
    int bias_d_red_mV = confSPECred[0]{8};
    //
    // UNPACK confOBCP
    //
    int nb_up_dn = confOBCP[0]{0};
    int grat_step_coarse = confOBCP[0]{1};
    int nb_grat_steps = confOBCP[0]{2};
    int grat_step_up_fine = confOBCP[0]{3};
    int nb_cycles_grat = confOBCP[0]{4};
    int chop_pos_CS1 = confOBCP[0]{5};
    int nb_ramps_grat_pos = confOBCP[0]{6};
    int chop_pos_CS2 = confOBCP[0]{7};
    int detector = confOBCP[0]{8};
    int chop_def = confOBCP[0]{9};
    // We will scan by decreasing grating angle, i.e. negative step size:
    // OBCP 13 P#9 
    int grat_step_dn_fine = -grat_step_up_fine;
    string order_str = "" + order;
    // PARAMETERS STILL TO BE CHECKED
    // double[] keyWAVE = [65.0];
    //string orderSel = "order"+order_str;
    // END PARAMETERS STILL TO BE CHECKED
    // Bias voltages (needed by SPEC_aot_prologue) are commanded in (double) volts
    double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
    double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
    double bias_r_red = double(bias_r_red_mV) / 1000.0;
    double bias_d_red = double(bias_d_red_mV) / 1000.0;
    if(verbose) {
        debug_print(" ");
        debug_print("confSPEC: capa_blu              " + capa_blu);
        debug_print("confSPEC: nb_rdouts_ramp_blu    " + nb_rdouts_ramp_blu);
        debug_print("confSPEC: nb_rdouts_subramp_blu " + nb_rdouts_subramp_blu);
        debug_print("confSPEC: comp_mode_blu         " + comp_mode_blu);
        debug_print("confSPEC: glitch_det_blu        " + glitch_det_blu);
        debug_print("confSPEC: ramp_fit_alg_blu      " + ramp_fit_alg_blu);
        debug_print("confSPEC: nb_raw_blu            " + nb_raw_blu);
        debug_print("confSPEC: bias_r_blu_mV         " + bias_r_blu_mV);
        debug_print("confSPEC: bias_d_blu_mV         " + bias_d_blu_mV);
        debug_print(" ");
        debug_print("confSPEC: capa_red              " + capa_red);
        debug_print("confSPEC: nb_rdouts_ramp_red    " + nb_rdouts_ramp_red);
        debug_print("confSPEC: nb_rdouts_subramp_red " + nb_rdouts_subramp_red);
        debug_print("confSPEC: comp_mode_red         " + comp_mode_red);
        debug_print("confSPEC: glitch_det_red        " + glitch_det_red);
        debug_print("confSPEC: ramp_fit_alg_blu      " + ramp_fit_alg_red);
        debug_print("confSPEC: nb_raw_red            " + nb_raw_red);
        debug_print("confSPEC: bias_r_red_mV         " + bias_r_red_mV);
        debug_print("confSPEC: bias_d_red_mV         " + bias_d_red_mV);
        debug_print(" ");
        debug_print("confOBCP: P#1 nb_up_dn          " + nb_up_dn);
        debug_print("confOBCP: P#2 grat_step_coarse  " + grat_step_coarse);
        debug_print("confOBCP: P#3 nb_grat_steps     " + nb_grat_steps);
        debug_print("confOBCP: P#4 grat_step_up_fine " + grat_step_up_fine);
        debug_print("confOBCP: P#6 chop_pos_CS1      " + chop_pos_CS1);
        debug_print("confOBCP: P#8 chop_pos_CS2      " + chop_pos_CS2);
        debug_print("confOBCP: P#5 nb_cycles_grat    " + nb_cycles_grat);
        debug_print("confOBCP: P#7 nb_ramps_grat_pos " + nb_ramps_grat_pos);
        debug_print("confOBCP: detector              " + detector);
        debug_print("confOBCP: chop_def              " + chop_def);
    }
    // Issue SPEC_aot_prologue if demanded
    if(doPROLOG) {
        int filter = 2;
        //aotprologue: string[] fltPOS = ["N/A","NoFilter","POS B","POS A"];
        if(fltPOS == "POS A") {
            filter = 3;
        }
        totalDUREE = SPEC_aot_prologue(nb_rdouts_ramp_red,nb_rdouts_ramp_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,comp_mode_blu,comp_mode_red,nb_rdouts_subramp_blu,nb_rdouts_subramp_red,nb_raw_blu,nb_raw_red,glitch_det_red,ramp_fit_alg_red,filter,verbose);
    }
    // NOTE: Grating starts at grat_start_pos determined by SPEC_get_grat. At end of
    // SlewCal grating should park. Park position is generally grat_def_pos:
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // AOT_prologue is supposed to have left grating at park position
    int grat_def_pos = grat_park;
    // NOTE for version 1.0 and later. Upon execution of SpecSlew, grating is
    //      indeed where SPEC_orbit_prologue left it (the default park position);
    //      this fact remains unchanged. What is new is that SpecSlew will leave
    //      the grating not at the default park position but already at the
    //      position needed by the 1st line that will be observed. There are two
    //      advantages:
    //      1- the new logic in the OBCP incurs in less grating movements when
    //         the OBCP is repeated within a NOD or the next raster point, and
    //      2- the detector will see the illumination corresponding to the line
    //         wavelength before the actual observation starts.
    // Observe now each key wavelength
    int nbWaves = length(waves);
    for(int loopWaves = 0 .. nbWaves - 1) {
        //
        // RSRF PCSS
        // R1  :  32000 - 1056000
        // B2A : 620000 - 1056000
        // B2B :  32000 - 1056000
        // B3A :  32000 -  670000
        //
        //     Get grating start position (CAL is performeed with HI resolution)
        string waveCalTable = slookup("SPEC_BAND_params",order_str,"CAL_FILE");
        double wave_grat_pos = interpolate(waveCalTable,"grat_pos",waves[loopWaves]);
        int grat_start_pos = iround(wave_grat_pos + double(grat_step_up_fine) * double(nb_grat_steps) / 2.0);
        //     Number of steps to start position for current line
        int steps_start = grat_def_pos - grat_start_pos;
        int grat_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("OBCPcal:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_time);
        }
        //
        //     After the OBCP, leave the grating where it is, i.e. end-of-DMC value
        //     But the last line should leave grating at default from CALU
        grat_def_pos = grat_start_pos;
        if(loopWaves == nbWaves - 1) {
            grat_def_pos = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
        }
        //
        int steps_end = grat_start_pos - grat_def_pos;
        int grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print(" ");
            debug_print("OBCPcal:GratEnd from/to: " + grat_start_pos + "/" + grat_def_pos + "; time: " + grat_def_time);
            debug_print(" ");
            debug_print("confOBCP: P#4 grat_step_up_fine  " + grat_step_up_fine);
            debug_print("confOBCP: P#9 grat_step_dn_fine  " + grat_step_dn_fine);
            debug_print("confOBCP: wavelength -> grat pos " + waves[loopWaves] + " " + wave_grat_pos);
            debug_print("confOBCP: grat_start_pos         " + grat_start_pos);
        }
        int[] dureeOBCP = OBCP_chop_grat_scan_cal(nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,grat_step_dn_fine,detector,grat_start_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
        if(verbose) {
            debug_print("SlewCal performed wavelength: " + waves[loopWaves] + " [mic] requires " + dureeOBCP[0] + " [sec]");
        }
        //     Update dureeCalKey
        dureeCalKey[loopWaves] = [0,0,0,0,0];
        for(int loop1 = 0 .. 4) {
            dureeCalKey[loopWaves][loop1] = dureeOBCP[loop1];
        }
    }
    // Add after the KeyWaves in dureeCalKey the duration from AOT_prologue
    dureeCalKey[nbWaves] = [0,0,0,0,0];
    dureeCalKey[nbWaves][4] = totalDUREE[4];
    if(verbose) {
        debug_print("End SlewCal with dureeCalKey: " + dureeCalKey);
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return dureeCalKey;
}

// Missionphase  : FM
//
// Purpose	:  Setup diagnostic housekeeping for the FM 
//                 chopper tests. Special HKs.
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: Set up 5 housekeeping parameter for diagnostic housekeeping 
//	  of the chopper for open loop tests.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and SPEC_Chop_fft_eqmimt_obs
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 1.0	
// 
// History 	: 
//	  1.0 29-03-07 MN. Spec. HK for open loop measurements.
//
block SPEC_Chopper_dhk_4hk_1khz_bb PACS 475 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //-------------------------------------------- 
    // Setup and start diagnostic HK for Chopper
    //-------------------------------------------- 
    int chop_diag_hk_length = 5;
    {int}[] parlist = [{244},{245},{258},{561},{0xffff}];
    int[] aux = [244,245,258,561,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(chop_diag_hk_length,parlist,check_sum);
    int diag_hk_period = 0;
    // Synchronize diagnostic HK on blue spectrometer readouts
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark End of Block
    WriteEndBB();
}

// $Id: Pacs_Background_Adjustment.txt,v 1.1 2008/04/08 13:56:15 vanessad Exp $
// Filename	 : Pacs_background_Adjustment
// Purpose       :  Near real time adjustment of LHe flow for cryocover mirror 
//                  
//                 
//
// TCL author    : HF
// TCL file      : 
// CUS author    : HF 
// Script file   : Background_Radiance_Adjustment.txt 
//
// Input arguments none
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Uses OBCP 8 to interactively adjust the LHe flow through the
//                            cryocover mirror for telescope background simulation. Chops between
//                            CS1 - 0 - CS2 for a number of specified loops at a given capacitor and
//                            otherwise default detector settings. 
//                  
// Dependencies  : OBCP_spec_2_3_chop, SPEC_heater, SPEC_cre_setup
//
// Preconditions : PACS must be on and configured for spectroscopy
//                             nominal detector settings and reset interval = 64, default C=0.1pF 
//                 
// Comments      : Can be run with different capacitors for EQM IMT purposes
// 
// Version	 : 2.1
// History
// 1.0 24-Mar-2005 creation by HF
// 1.1 25-apr-2005 DAC Corrected for amended OBCP_spec_2_3_chop
// 1.2 23-jun-2005 HF, added SPU setup and reset
// 1.3 10-Apr-2006 HF, adapted for FM
// 1.4 26-Apr-2006 HF, added move to FW position B 
// 1.5 03-Apr-2007 HF, adapted to FM ILT results
// 2.0 25-mar-2008 VDP adjusted to match PV phase syntax
// 2.1 15-Apr-2008 VDP adjusted heater_blu (current) from 
//                     1.5 to 0.78 mA
// 2.2 11-Jun-2009 BV corrected bias values - SPR-7054
//
procedure Pacs_Background_Adjustment {
    int nb_up_down = 3; // Number of sequences: up down up ...
    int nb_grat_steps = 5; // Number of grating steps
    int nb_SRC_OFF = 5; // Nb cycles on/off source/grating position
    int nb_CS1_CS2 = 0; // Nbr cycles on cal src per grating position
    int grat_step = 0; // Grating step size
    int capa_blu = 0; // 0=0.1pf 8=0.2pf 4=0.4pF 12=1pF
    int capa_red = 0; // 0=0.1pf 8=0.2pf 4=0.4pF 12=1pF
}{
    // Accumulated duration of this obs mode
    int duration_msec = 0;
    //
    // Condition the CREs and detectors
    int ramp_len_blu = 64;
    int ramp_len_red = 64;
    // Set up the blue and red CRE subsystem
    // cre_ctrl is a bit field:
    // 256=sync width=2, 128=T sensor on, 2=enable, 1=power on
    // Do not enable yet
    int cre_ctrl_red = 256 + 128 + 2 + 1;
    int cre_ctrl_blu = 256 + 128 + 2 + 1;
    // Give ENG values for the bias [v]
    double bias_r_blu = 0.0050;
    double bias_r_red = 0.0050;
    double bias_d_blu = 0.08;
    double bias_d_red = 0.03;
    SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // Set BLUE heater parameters (mA)
    double heater_blu = 0.78;
    SPEC_heater(heater_blu);
    //
    // SPU parameters
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int nb_samp_subramp_blu = ramp_len_blu;
    // Nb of blue samples per sub-ramp 
    int nb_samp_subramp_red = ramp_len_red;
    // Nb of red samples per sub-ramp 
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    // No sub ramps or means    
    nb_samp_subramp_blu = ramp_len_blu;
    nb_samp_subramp_red = ramp_len_red;
    // Reset SPU
    SPEC_spu_reset();
    // Re-start SPU in default mode
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Variables that are hardcoded    
    string filterwheelpos = "POS B";
    // Move the filter wheel  
    SPEC_fltw_move(filterwheelpos);
    // Number of readouts per ramp
    int nb_rdouts_ramp = 64;
    // Number of ramps per plateau-1
    int nb_ramps_plateau = 5;
    // grating start position  
    int grat_start = 500000;
    // Chopper position on CS1
    int chop_pos_CS1 = -21350;
    // Chopper position on CS2
    int chop_pos_CS2 = 21200;
    // Chopper position 1
    int chop_pos_REF1 = 0;
    // Chopper position 2
    int chop_pos_REF2 = -21350;
    // Chopper position 3
    int chop_pos_REF3 = 21200;
    // Synchronize on this detector 1:Blue 2:Red
    int detector = 1;
    // Time for grating to move to start position
    int grat_time = 15000;
    // SPU compression mode
    int comp_mode = 16;
    // Grating default position
    int grat_def = 500000;
    // Chopper default position
    int chop_def = 648;
    // Grating to move to grat_def position [msec]
    int grat_def_time = 2000;
    // Now call OBCP 8 with all its parameters
    int[] duree3 = OBCP_spec_2_3_chop(nb_up_down,nb_grat_steps,nb_SRC_OFF,chop_pos_REF1,nb_ramps_plateau,chop_pos_REF2,chop_pos_REF3,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step,-grat_step,detector,grat_start,grat_time,comp_mode,comp_mode,grat_def,chop_def,grat_def_time,nb_rdouts_ramp);
    // Reset SPU
    SPEC_spu_reset();
    //   Tally total duration [msec]		  
    duration_msec = duration_msec + duree3[0];
    sync();
}

// Missionphase  : EQM IMT
//
// Purpose	: Compute duration of DMC Sequence 13 : grating scan without
//                chopping
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: 
//
// Description	: For all internal details about DMC Seq 13, see PACS-ME-LI-005
//                and pseudo code here. Identical to "Grating line scan with
//                two or three position choping" but with out choping on source.
//                Meant mostly for ILT to allow for fast execution of 
//                measurements on "absolute" flux sources.
//                  
// Dependencies : None
//
// Preconditions: N/A
//                 
// Comments     : 1. No single command is executed here, only the duration is 
//                   computed here. Hence, not all parameters of the actual DMC
//                   Seq. are relevant here!
//                2. In version 1.0 the whole pseudo code is not developped yet
//                   As a consequence, duree_SRC, duree_REF, duree_CAL & 
//                   duree_OVR are NOT COMPUTED, ONLY duree_num IS!! 
//                   (formula in PACS-ME-LI-005)
//                3. All durations are now computed (DAC dixit)
//
// Version      : 2.0
//               
// History      : 1.0 05-Apr-2005 Creation by PR
//                2.0 06-Apr-2005 Completed by DAC with pseudo code and
//                                full duration computation.
//                2.1 25-apr-2005 DAC Arranged arguments in P#1,#2 order
//                                Renamed DMC_grat_scan_nochop as OBCP 
//
int[] procedure DMC_grat_scan_nochop {
    int nb_up_dn = 1; // Seq P#1  Nb of sequences: up down up ...
    int nb_grat_steps_up = 10; // Seq P#2  Nb of grating up steps
    int nb_ramps_grat_pos = 2; // Seq P#5  Nb of ramps per grating position    
    int nb_CS1_CS2 = 0; // Seq P#6  Nb of cycles on CS, per grat position
    int nb_ramps_cs = 2; // Seq P#9  Nb of ramps per plateau on the CS
    int nb_grat_steps_dn = 10; // Seq P#10 Nb of grating down steps
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Start of pseudo code
    //
    // WAIT 1 ; have a defined start 
    // Accumulated duree_num in number of ramps
    duree_num = duree_num + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; set Label to 0 
    // LOOP P#1 Start main loop of UP and DOWN cycles
    for(int outloop = 1 .. nb_up_dn) {
        //  LOOP P#2 ; grating loop going up
        for(int gratUPloop = 1 .. nb_grat_steps_up) {
            //  WAIT 1 ; sync. for grating 
            duree_num = duree_num + 1;
            duree_OVR = duree_OVR + 1;
            //  MOVE_GRATING_RELATIVE P#3 ; increment grating position 
            //  LABEL 3 ; first chopper pos. 
            //  WAIT P#5 ; take P#5 ramps
            duree_num = duree_num + nb_ramps_grat_pos;
            duree_SRC = duree_SRC + nb_ramps_grat_pos;
            // LOOP P#6 ; calibration loop
            for(int csUPloop = 1 .. nb_CS1_CS2) {
                // WAIT 1 ; sync. for chopper 
                duree_num = duree_num + 1;
                duree_OVR = duree_OVR + 1;
                // MOVE_CHOPPER_ABSOLUTE P#7 ; chop to BB1 
                // LABEL 65 ; BB1 
                // WAIT P#9 ; take P#9 ramps 
                duree_num = duree_num + nb_ramps_cs;
                duree_CAL = duree_CAL + nb_ramps_cs;
                // WAIT 1 ; sync. for chopper 
                duree_num = duree_num + 1;
                duree_OVR = duree_OVR + 1;
                // MOVE_CHOPPER_ABSOLUTE P#8 ; chop to BB2 
                // LABEL 129 ; BB2 
                // WAIT P#9 ; take P#9 ramps 
                duree_num = duree_num + nb_ramps_cs;
                duree_CAL = duree_CAL + nb_ramps_cs;
                // END_LOOP ; calibration done
            }
            // MOVE_CHOPPER_ABSOLUTE P#11 ; chopper to default 
            // END_LOOP ; grating scan up done
        }
        //  LOOP P#10 ; grating loop going down
        for(int gratDNloop = 1 .. nb_grat_steps_dn) {
            //  WAIT 1 ; sync. for grating 
            duree_num = duree_num + 1;
            duree_OVR = duree_OVR + 1;
            //  MOVE_GRATING_RELATIVE P#4 ; decrement grating position 
            //  LABEL 19 ; first chopper pos. 
            //  WAIT P#5 ; take P#5 ramps
            duree_num = duree_num + nb_ramps_grat_pos;
            duree_SRC = duree_SRC + nb_ramps_grat_pos;
            // LOOP P#6 ; calibration loop
            for(int csDNloop = 1 .. nb_CS1_CS2) {
                // WAIT 1 ; sync. for chopper 
                duree_num = duree_num + 1;
                duree_OVR = duree_OVR + 1;
                // MOVE_CHOPPER_ABSOLUTE P#7 ; chop to BB1 
                // LABEL 81 ; BB1 
                // WAIT P#9 ; take P#9 ramps 
                duree_num = duree_num + nb_ramps_cs;
                duree_CAL = duree_CAL + nb_ramps_cs;
                // WAIT 1 ; sync. for chopper 
                duree_num = duree_num + 1;
                duree_OVR = duree_OVR + 1;
                // MOVE_CHOPPER_ABSOLUTE P#8 ; chop to BB2 
                // LABEL 145 ; BB2 
                // WAIT P#9 ; take P#9 ramps 
                duree_num = duree_num + nb_ramps_cs;
                duree_CAL = duree_CAL + nb_ramps_cs;
                // END_LOOP ; calibration done
            }
            // MOVE_CHOPPER_ABSOLUTE P#11 ; chopper to default 
            // END_LOOP ; grating scan up done
        }
        // END_LOOP ; main loop done
    }
    // WAIT 1 ; complete last plateau 
    duree_num = duree_num + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; reset LABEL to 0 
    // END_SEQUENCE 
    // Sequence duration, in ramps : 2+P#1*{(P#2+P#10)*[1+P#5+P#6*2*(1 + P#9)]}
    // Create time_array
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    //  debug_print("DMC_Gra_scan_nochop duree (TOTAL SRC REF CAL OVR): " + time_array);

    return time_array;
}

// Missionphase  : CP/PV 
//
// Purpose	 : Test of Chopper Movement
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : Move chopper in open-loop mode. All 3 coils are
//                 operative (nominal setting). The chopper is commanded
//                 between the two internal calibration sources in small
//                 equidistant steps.
//                  
// Dependencies  : 
//
// Preconditions : PACS switched-on in safe mode
//                 
// Comments	 :
//
// Version	 : 1.0
// 
// History 	 : 1.0 12-Jun-08 creation by MN
// Begin Mode description
obs PacsEng_ChopperOpenLoop_FullRange {
}{
    // duration
    int tPROC = duration(Pacs_ChopperOpenLoop_FullRange());
    int tOBSID = duration(WriteOBSID($OBSID));
    int tEndID = duration(WriteEndID());
    int tp = tPROC + tOBSID + tEndID;
    // Issue the pointing request
    int[] fromPntReq = no_pointing(true,0,0,tp);
}{
    // The state machine
    int[] stateVar = [0];
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 3) {
            // Get OBSID from environment
            int myOBSID = $OBSID;
            // Send OBSID to DMC
            WriteOBSID(myOBSID);
            // Open Loop measurement
            Pacs_ChopperOpenLoop_FullRange();
            // Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Gra_Healthcheck {
    /* variables to call PacsEng_Spec_Gra_Healthcheck                        */
    int n_homes = 1; // Number of Homings & "Grating Health Checks" to be performed
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_Healthcheck                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_Healthcheck(n_homes)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_Healthcheck(n_homes);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Move Grat Abs
//
// CUS author    : Pierre Royer
//
//
// Version       : 2.0
// History       : 1.0 29-Jul-2007
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_Gra_IST_Move_Rel {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Move_Rel                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_Move_Rel                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_IST_Move_Rel()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_IST_Move_Rel();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsReadChopSky.txt,v 1.3 2007/04/25 15:14:04 dcesarsk Exp $ 
// Missionphase  : 
//
// Purpose       : To read with (linear) interpolation the SKY <-> chopper
//                 U-CAL table
//
// CUS author    : 
// Script file   : PacsReadChopSky.txt from AOT code
//
// Input arguments
// type    name      description
// string  uCAL      Name of the U-CAL table
// double  skyOff    Desired sky offset following a chopper move [arcsec]
//
// Return values
// Type         Description
// int chopREF  Chopper command operand (ENG units)
//
// Description   : Read the table XXX_chop_sky with "interpole"
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      :
// 
// Version       : 0.2 
// History       : 0.1 04-apr-2005 DAC
//                 0.2 22-mar-2007 CAL-U files amended to list ENG instead
//                                 of misleading "REF"
int procedure PacsReadChopSky {
    string uCAL = "PHOT_CHOP_sky"; // Name of the U-CAL table
    /*  Watch out! current uCAL extends only to 360 [arcsec */
    double skyOff = 0.0; // Required sky offset
}{
    // Open and read uCAL table with interpolate
    double auxRef = interpolate(uCAL,"ENG",skyOff);
    int ref = iround(auxRef + 0.5);
    if(auxRef < 0.0) {
        ref = iround(auxRef - 0.5);
    }

    return ref;
}

/////////////////////////////////////////////////////////////////////////////
/// $Id
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsRangeSpec AOT
//
// CUS author    : DAC
// Script file   : PacsRangeSpec.def
//
// Input arguments
// type    name         description
//
// Return values
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : If the file is called PacsRangeSpecObs.def, it is the 
//                 CUSGUI version. To use with HSPOT:
//                 - copy and rename PacsRangeSpec.def
//                 - rename module to PacsRangeSpec
//                 - remove extra code for CUSGUI
//                 - do not forget to set verbose = false
//
// History: 
// For history before 24-apr-2007 see v1.42 in CVS
// 25-apr-2007 14.4 Suppressed history before today (kept in CVS though)
//                  Use rangeSPOT throughtout (i.e. merged ranges & rangeEXT)
//  9-may-2007 14.5 SPR-3186 Use userNODcycles as map repetion for OFF
// 22-may-2007 14.6 SPR-3199 Return SRC time without overheads
// 29-may-2007 14.7 SPR-3237
// 11-jun-2007 14.8 SPR-3277 Use referenceWave (rangeSPOT{9}) for SED mode
// 20-sep-2007 14.9 SPR-3570 RA,DEC offsets may be negative
//                  SCR-3552 Read skewCorrec from PACSyzoffsets; add to pattnod
// 24-sep-2007 15.0 SPR-3581 S/N is not computed in SED mode
// 28-mar-2008 16.0 remove mapRasterRefXXX replaced by raoff,
// 	       	    decoff and refSelected (refSelected is complement to
//		    chopNod hence not used in our logics)
// 29-mar-2008 17.0 Removed section computing ABS or REL offsets: now an HSPOT
//   	       	    functionality
// 28-apr-2008 18.0 raoff and decoff had the wrong range: in dgrees now
// 23-sep-2008: SCR 4632
// 13-oct-2008	19.0 implement default range values for HSC
// 		     but was buggy: implement a test to use only if no Hspot
//		     values are given
// 22-apr-2009 20.0 VD: SPR5447 added keyWL as fnct of order+filter comb.
// 23-apr-2009 21.0 VD SPR 6482
// 12-may-2009 22.0 VD modified Default parameters SED bug
// 29-jul-2009 23.0 VD implement OBCP35 in SCI block and OBCP35(BBID 350) in CAL block
// 03-sep-2009 24.0 VD PHS-200, doSlewScience
// 20-oct-2009 25.0 VD PHS-1225
// 27-oct-2009 26.0 VD PHS-1227 disable PHS-200 (hardcode == false)
// 02-nov-2009 27.0 BV PHS-1239 Key wavelengths in grating position
// 30-nov-2009 30.0 VD & BV PHS-1272 (inc PHS-1273 and PHS-1274) AOT SED mode release
// 07-dec-2009 31.0 VD PHS-1282
// 08-dec-2009 3x.x VD PHS-1285 WL dither for SED mode
// 17-dec-2009 32.0 VD PHS-1274: updated sed4 and sedb2a : order 2 + filter = 3
// 12-jan-2010 33.0 VD PHS-1285 SED dithering: logic add-on on RangeSpecSed and CheckFillRange
// 20-jan-2010 34.0 VD PHS-1302 RefWL in Parallel band
// 08-feb-2010 35.0 VD PHS-1315 RefWl wrong in the Check for SED
// 09-feb-2010 36.0 VD PHS-1320 SED info display: nbRanges > 1 only original SED range + RMS/SN fn(sqrt(nb_Ranges)
// 10-feb-2010 37.0 VD PHS-193 capacitance for Range and SED
// 12-feb-2010 38.0 VD update Error message for Capacitance switch
// 24-feb-2010 39.0 PHS-1285 terce ... Range dither
// 22-mar-2010 40.0 PHS-1370 parallel band reference wavelength is not checked if nbRanges > 1
// 12-apr-2010 41.0 PHS-? VD computation of times are all mmessed up for repFactor >1
// 28-apr-2010 42.0 PHS-1388 un-chopped range Scan
//                  PHS-1393 cosmetics: pre-release 5.0
// 03-may-2010  43.0 VD made it standard AOT for Hspot 5.0 testing and twisiting
// 03-may-2010  44.0 VD PHS-1393: added order 23
// 10-may-2010  45.0 VD Hspot 5.0
// 14-jun-2010 46.0 VD PHS-1464 reversed instrument and Sky orientation in Raster mode
// 06-jul-2010 47.0 VD PHS-1477 point mode unchopped repeat "basic_pointing"
//  
{int,int,int,{string,double[],double[],double[],string,double[],double[],double[],string,double[],double[],double[]}[]} obs PacsRangeSpec {
    /* "rangeSPOT" is a tuple defined by HSPOT                                 */
    /*  It contains                                                            */
    /* {id, bluEdge, redEdge, repeatFactor, lineFlux, contFlux, lineWidth,     */
    /*  fluxUnitSel, widthUnitSel, refWave}                                    */
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [];
    /* here is Range default setup for default duration calculation */
    string[] rangeId = ["My Range"];
    double[] bluWave = [55.0]; // blue limit in [55.0,220.0]
    double[] redWave = [60.0]; // red limit in [55.0,220.0]
    int[] repeatRange = [1]; // repeat Range in [0,10]
    double[] lineFlux = [111.0]; // Line Flux in [0.0,10000.0]
    double[] lineWidth = [400.0]; // line width in [0.0,1000.0]
    string[] widthUnit = ["kms"]; // width unit in ["kms","micron"]
    double[] lcontFlux = [111.11]; // continuum flux in [0.0,10000.0]
    double[] refWave = [60.0];
    /* end of default setup */
    int userNODcycles = 1 in [1,100];
    string orderSel = "order3" in ["order2","order3","order23","sed2","sed3","sed4","sedb2a","sedb2b","sedb3a"];
    bool chopNod = true;
    /* PHS 1387 */
    bool gratScan = false;
    /* No OFF end */
    string density = "nyquist" in ["nyquist","high"];
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    string throw = "large" in ["large","medium","small"];
    string source = "point" in ["point","dithered","large"];
    double mapRasterAngle = 0.0 in [0.0,360.0];
    /* PHS-1387 */
    bool mapRasterAngleRefFrame = true;
    /* end */
    int m = 2 in [2,32];
    int n = 1 in [1,32];
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    int naifid = 0; // RA,DEC or SSO
    double pointStep = 2.0 in [0.0,480.0];
    double lineStep = 2.0 in [0.0,480.0];
    bool refSelected = false; // true for chopNod = false
    double raoff = 0.0 in [0.0,360.0]; // units in degrees
    double decoff = 0.0 in [-90.0,90.0]; // units in degrees
    int obsOverhead = 180; // Slew overhead
    bool verbose = false; // verbose Debugging
}{
    //* ------ Used only when default values in CUS are used --------------------*/
    int rangeIdLength = length(rangeId);
    int rangeLength = length(rangeSPOT);
    if(rangeLength == 0) {
        // checking order's relevance for SED
        for(int rloop00 = 0 .. rangeIdLength - 1) {
            if(orderSel == "sed3" || orderSel == "sed4") {
                if(bluWave[rloop00] == 55.0 && redWave[rloop00] == 60.0) {
                    error("Reference wavelength should be comprised between 55.0 and 73.0");
                }
            } else {
                rangeSPOT[rloop00] = {rangeId[rloop00],bluWave[rloop00],redWave[rloop00],repeatRange[rloop00],lineFlux[rloop00],lcontFlux[rloop00],lineWidth[rloop00],"",widthUnit[rloop00],refWave[rloop00]};
            }
        }
    }
    {double,double}[] infoRangeSed = [{0.0,0.0}];
    //*----------- End of default CUS setup -----------------*/
    // catching pre-release PHS-1393
    // if(orderSel == "order23") {
    //    error("Only as pre-release: not implemented yet");
    //}
    // PHS-1227
    //    bool doSlewScience = false;
    // Boolean variables "range" and "sedXXX" are mutually exclusive for HSPOT. For 
    // time being I will use them independently of each other
    // Specifying bool sed = true is a special case of predefined ranges.
    // 30-oct-2006
    // Variables "sed" or "range" have disappeared from front end. Define as
    bool range = true;
    bool sed = false;
    if(orderSel == "sed2" || orderSel == "sed3" || orderSel == "sed4" || orderSel == "sedb2a" || orderSel == "sedb2b" || orderSel == "sedb3a") {
        range = false;
        sed = true;
    }
    // Yet to be defined symbol to access CAL-U file info for detector setup
    // May come from HSPOT front-end in the future
    // The future has come!!!
    string confTable = "normal";
    // In SED or nyquist sample, we use the option "bright"   
    if(sed || density == "nyquist") {
        confTable = "bright";
    }
    //PHS-1388 making sure that chopNod and gratScan are NOT true toghether
    if(chopNod && gratScan) {
        error("This observing mode is NOT allowed");
    }
    if(!chopNod && !gratScan) {
        error("This observing mode is NOT allowed");
    }
    // to make sure that no-one gets funny idea about refSelected
    refSelected = !chopNod;
    // New parameter for nodding_pointing
    bool startAtOFF = false;
    // Variable "grating" has disapeared from the front end. Since it's used by
    // several modules, I keep it with its new (default) definition
    string grating = "nyquist";
    // OFF pointing only when in raster mode
    //if(mapOff && source != "large") {
    //    error("NOD = false only allowed for large sources");
    // }
    // Start of "Pointing" section
    // 
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    bool goodRefWL = true;
    // In "sed" mode, rangeSPOT is filled by module PacsRangeSpecSed
    debug_print("MAIN: Here starts the section for Ref Wave Checks");
    if(sed) {
        //   Define the RefWave as the mean value of bluWave and redWave
        //   double meanRef = (rangeSPOT[0]{1} + rangeSPOT[0]{2})/2.0;
        // SPR-3277  Save waveRef first!
        // Catch case of rangeSPOT not being defined
        // 
        // OBSOLETE!!!
        // 
        int theLength = length(rangeSPOT);
        if(theLength == 0) {
            error("ERROR! Need a reference wavelength for the SED observation (see UM)");
        }
        // caught! Now extract wavelength
        double waveRef = rangeSPOT[0]{9};
        // SPR-3581. Save information to compute S/N 
        double contFlux = rangeSPOT[0]{5};
        int repeatFactor = rangeSPOT[0]{3};
        //
        //
        //
        //    Fill rangeSPOT with SED information
        int repeatSed = repeatFactor;
        // OLD       rangeSPOT = PacsRangeSpecSed(orderSel,repeatSed);
        // PHS-1285
        {{string,double,double,int,double,double,double,string,string,double}[],{double,double}[]} sedRange = PacsRangeSpecSed_tmp(orderSel,repeatSed);
        // 
        rangeSPOT = sedRange{0};
        infoRangeSed = sedRange{1};
        double redRangeBluEdge = 0.0;
        double redRangeRedEdge = 0.0;
        if(orderSel == "sedb2a") {
            redRangeBluEdge = dlookup("SPEC_BAND_params","b2aSR1","BLU");
            redRangeRedEdge = dlookup("SPEC_BAND_params","b2aSR1","RED");
        }
        if(orderSel == "sedb2b") {
            redRangeBluEdge = dlookup("SPEC_BAND_params","b2bLR1","BLU");
            redRangeRedEdge = dlookup("SPEC_BAND_params","b2bLR1","RED");
        }
        if(orderSel == "sedb3a") {
            redRangeBluEdge = dlookup("SPEC_BAND_params","b3aLR1","BLU");
            redRangeRedEdge = dlookup("SPEC_BAND_params","b3aLR1","RED");
        }
        // Insure that user given reference is within order range
        //         if(waveRef < rangeSPOT[0]{1} || waveRef > rangeSPOT[0]{2}) {
        //            error("Reference wave must be comprised between " + rangeSPOT[0]{1} + " and " + rangeSPOT[0]{2} + " for " + orderSel);
        //        }
        //	  debug_print("2 waveRef: " + waveRef);
        if(waveRef < rangeSPOT[0]{1} || waveRef > redRangeRedEdge) {
            error(" OutSide: Reference wave must be comprised between  [" + rangeSPOT[0]{1} + "," + rangeSPOT[0]{2} + "] and [" + redRangeBluEdge + "," + redRangeRedEdge + "] for " + orderSel);
        } else {
            if(waveRef > rangeSPOT[0]{2} && waveRef < redRangeBluEdge) {
                error(" Inside: Reference wave must be comprised between  [" + rangeSPOT[0]{1} + "," + rangeSPOT[0]{2} + "] and [" + redRangeBluEdge + "," + redRangeRedEdge + "] for " + orderSel);
            }
        }
        for(int loopXX = 0 .. repeatFactor - 1) {
            rangeSPOT[loopXX]{9} = waveRef;
            rangeSPOT[loopXX]{5} = contFlux;
        }
    } else {
        debug_print("MAIN: Range Check Wave Ref");
        int allRanges = length(rangeSPOT);
        for(int rloop02 = 0 .. allRanges - 1) {
            infoRangeSed[rloop02] = {0.0,0.0};
            // add here on the refWavelength: PHS-1302...
            debug_print("rangeSPOT[" + rloop02 + "] Reference:" + rangeSPOT[rloop02]{9});
            goodRefWL = PacsSpecCheckRefWave(rangeSPOT[rloop02]{1},rangeSPOT[rloop02]{2},rangeSPOT[rloop02]{9},orderSel);
            if(!goodRefWL) {
                error("In range #" + rloop02 + " the given reference wavelength " + rangeSPOT[rloop02]{9} + " is not accessible in the parallel band. Please check the Users manual for information");
            }
        }
    }
    // Cannot call with empty "rangeSPOT"
    // PHS-1320
    if(sed) {
        int nbRanges = repeatSed;
    } else {
        nbRanges = length(rangeSPOT);
    }
    int nbRanges1 = nbRanges - 1;
    if(nbRanges == 0) {
        error("STOP!! There are no spectral ranges defined!");
    }
    // No more than 10 ranges or repetitions
    int nbRangesRep = 0;
    for(int loop00 = 0 .. nbRanges - 1) {
        //  Default repetion factor is 1
        int repFactor = rangeSPOT[loop00]{3};
        if(repFactor == 0) {
            repFactor = 1;
        }
        nbRangesRep = nbRangesRep + repFactor;
    }
    if(verbose) {
        debug_print("Total ranges/repeat: " + nbRangesRep);
    }
    if(nbRangesRep > 10) {
        error("STOP!! The number of ranges/repetitions exceeds 10");
    }
    // Decode "rangeSPOT" (only if verbose mode)
    if(verbose) {
        for(int iiii = 0 .. nbRanges1) {
            debug_print("RANGE or SED: " + orderSel);
            debug_print("Wave from/to : " + rangeSPOT[iiii]{1} + "/" + rangeSPOT[iiii]{2});
            debug_print("RefWave      : " + rangeSPOT[iiii]{9});
            debug_print("repeat factor: " + rangeSPOT[iiii]{3});
        }
    }
    // Establish now the applicable Pointing Mode (use same pointCase convention
    // used in PacsPhoto and PacsLineSpec)
    // Pointing mode is still undefined
    int pointCase = 0;
    // FinePointingMode with setup time
    if(source == "point") {
        //    For completiness define a 1x1 raster
        m = 1;
        n = 1;
        //    without nodding
        if(gratScan) {
            string pointMode = "fine_pointing";
            string userMode = "Point source (no nodding";
            pointCase = 11;
            string yzoffsetROW = "S" + pointCase;
        } else {
            if(chopNod) {
                //    with nodding      
                pointMode = "composite_nodding";
                userMode = "Point source (nodding)";
                pointCase = 12;
                yzoffsetROW = "S" + pointCase;
            }
        }
    }
    // For source "dithered" use predetermined raster parameters
    if(source == "dithered") {
        m = ilookup("SMALL_SRC_params","SPEC","mRast");
        n = ilookup("SMALL_SRC_params","SPEC","nRast");
        pointStep = dlookup("SMALL_SRC_params","SPEC","pointStep");
        lineStep = dlookup("SMALL_SRC_params","SPEC","lineStep");
        //    Raster mode without noding
        if(!chopNod) {
            pointMode = "repeated_raster_with_hold";
            userMode = "Small source (dithering and no nodding)";
            pointCase = 21;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Small source (dithering and nodding)";
            pointCase = 22;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For source "large" user given raster parameters
    if(source == "large") {
        //    Raster mode without noding
        if(gratScan) {
            chopNod = false;
            pointMode = "raster_pointing";
            userMode = "Large source (raster w/o OFF, no nodding)";
            pointCase = 30;
            yzoffsetROW = "S" + pointCase;
        } else {
            if(chopNod) {
                //      with nodding
                pointMode = "nodding_in_raster";
                userMode = "Large source (nodding)";
                pointCase = 32;
                yzoffsetROW = "S" + pointCase;
            }
        }
    }
    // NO longer used 
    //For symmetrical chopping, virtual apertures are dependent on the chopper
    // throw. 
    // Use special throw value in case of raster w/OFF as we chop between SRC and 
    // CS1
    //if(mapOff) {
    //     throw = "offraster";
    // }
    // Add this information to the CALU key entry
    yzoffsetROW = throw + "" + yzoffsetROW;
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("     PointCase ID: " + pointCase);
        debug_print("     PointMode   : " + pointMode);
        debug_print("     CALU entry  : " + yzoffsetROW);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Check that rangeSPOT is commensurate with U-CAL SPEC_BAND_params; get
    // grating positions on the fly
    // NOTE: rangeInfo is defined as 
    //       {typeOBS,order,blu_grat,red_grat,gratStep,bluWave,redWave}
    // PHS-1285 NEW login in PacsRangeSpecCheckFillRange .... override SED dithering
    // 
    {string,int,int,int,int,double,double}[] rangeInfo = PacsRangeSpecCheckFillRange_tmp(rangeSPOT,infoRangeSed,density,grating,orderSel,verbose);
    if(verbose) {
        for(int loopA = 0 .. nbRanges1) {
            debug_print("++RangeInfo: " + rangeInfo[loopA]);
        }
    }
    // Reject invalid ranges; abort CUS if invalid ranges are present
    for(int loop000 = 0 .. nbRanges1) {
        if(rangeInfo[loop00]{1} == 0) {
            error("Demanded range " + rangeInfo[loop000]{5} + "-" + rangeInfo[loop000]{6} + " [microns] is out of allowed boundaries");
        }
    }
    // rangeInfo contains all the relevant information. We can sort here, either
    // by wavelength or by start grating position. Create arrays to be sorted
    // Define array of wavelengths and start grating positions; create "order" array
    // in case we want to enforce the no order mixing rule
    double[] rangeWave = [0.0];
    double[] rangeGrat = [0.0];
    int[] orders = [0];
    // order array as float for sort algorithm
    double[] dorder = [0.0];
    // Populate the arrays
    for(int loop0 = 0 .. nbRanges1) {
        rangeWave[loop0] = rangeInfo[loop0]{5};
        //   SORT algorithm requires float input!
        rangeGrat[loop0] = double(rangeInfo[loop0]{2});
        orders[loop0] = rangeInfo[loop0]{1};
        dorder[loop0] = double(rangeInfo[loop0]{1});
    }
    // To reject forbidden order combination, count how many orders
    int nORDER1 = 0;
    int nORDER2 = 0;
    //    int nORDER23 = 0;   
    int nORDER3 = 0;
    for(int loop2 = 0 .. nbRanges1) {
        if(orders[loop2] == 1) {
            nORDER1 = nORDER1 + 1;
        }
        //        if(orders[loop2] == 23) {
        //            nORDER23 = nORDER23 + 1;
        //        }
        if(orders[loop2] == 2) {
            nORDER2 = nORDER2 + 1;
        }
        if(orders[loop2] == 3) {
            nORDER3 = nORDER3 + 1;
        }
    }
    if(nORDER2 != 0 && nORDER3 != 0) {
        //     Report band limits
        double[] band2 = SPEC_BAND_read("2");
        double[] band3 = SPEC_BAND_read("3");
        error("Combination of 2nd (" + band2[0] + "-" + band2[1] + " mic) and 3rd (" + band3[0] + "-" + band3[1] + " mic) grating orders is not allowed");
    }
    // Reject lines not belonging to authorized order
    if(nORDER2 != 0 && orderSel == "order3") {
        error("You have chosen " + orderSel + " but have specified one/several order2 lines");
    }
    if(nORDER3 != 0 && orderSel == "order2") {
        error("You have chosen " + orderSel + " but have specified one/several order3 lines");
    }
    // Determine the filter needed with given lines
    // No filter needed, i.e. ORDER=1
    // This case is history: 
    // HSPOT proposes order 1&2 or 1&3, reported as 2 or 3; filter=1 is no
    // longer possible
    int filter = 1;
    // Determine filter based on HSPUT input
    if(orderSel == "order2" || orderSel == "sed2" || orderSel == "sedb2b") {
        filter = 2;
    }
    if(orderSel == "order3" || orderSel == "order23" || orderSel == "sed3" || orderSel == "sed4" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        //    if(orderSel == "order3" || orderSel == "sed3" || orderSel == "sed4" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        filter = 3;
    }
    if(verbose) {
        debug_print("ORDER array: " + orders + "; FILTER: " + filter);
        debug_print("The whole OBS will be performed with filter " + filter);
    }
    // Sort by order
    //   int [] sortIndex = SortProc(verbose,dorder);
    // Sort grat_pos from smallest to largest
    int[] sortIndex = SortProc(verbose,rangeGrat);
    // Sort by wavelengths (from blue to red)
    // int sortIndex = SortProc(verbose,rangeWave);
    // Recast "rangeSPOT" and rangeInfo according to the ordered grating 
    // positions
    {string,double,double,int,double,double,double,string,string,double}[] sortRanges = clone(rangeSPOT);
    {string,int,int,int,int,double,double}[] sortRangeInfo = clone(rangeInfo);
    if(!sed) {
        for(int reSORT = 0 .. nbRanges1) {
            //    Reversed sort
            // No reverse SORT (start observations with filter A)
            //    int revSORT           = nbRanges1 - reSORT;
            int revSORT = reSORT;
            int sortedIndex = sortIndex[revSORT];
            sortRanges[reSORT] = rangeSPOT[sortedIndex];
            sortRangeInfo[reSORT] = rangeInfo[sortedIndex];
        }
    }
    // The tuple arrays confOBCP, confSPECred, and confSPECblu play a major
    // role. They contain the parameters related to commanding different PACS
    // subsystems. They are susceptible of changing with the observing conditions.
    // Hence, they have to be watched for changes since these imply sending one or
    // more TCs (usually invoking a building block)
    // Define confOBCP array
    // confOBCP{0 -> 19} contains:
    // nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
    // nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
    // grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
    // chop_pos_SRC     chop_pos_REF1    chop_pos_REF2
    // chop_pos_CS1     chop_pos_CS2     chop_def
    // detector         order
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confSPECblu and confSPECred
    // confSPEC{0 -> 8} contains:
    //   capa       nb_rdouts_ramp nb_rdouts_subramp  comp_mode
    //   glitch_det ramp_fit_alg   nb_raw             bias_r      bias_d
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // Estimator module returns {confSPECblu,confSPECred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    // Obtain default values
    // NEW. Saturation and capacitor/samples choice
    // Most SPEC configuration values are obtained from CONF_SPEC_params (read
    // in PacsSpecDefaults). Have to analyze given fluxes for each reference
    // wavelength. It may happen that a saturation situation will be found
    // Review the reference wavelengths, obtain telescope background, and PSF
    // fraction
    for(int rangeLOOP0 = 1 .. nbRanges) {
        int range1 = rangeLOOP0 - 1;
        waveRef = sortRanges[range1]{9};
        contFlux = sortRanges[range1]{5};
        debug_print("waveRef: " + waveRef);
        //    Obtain background and PSF fraction from CALU
        double telBckg = interpolate("SPEC_BCKG_FRAC","BackG",waveRef);
        double psfFrac = interpolate("SPEC_BCKG_FRAC","FracPnt",waveRef);
        debug_print("SATUR. Wave  " + waveRef);
        debug_print("SATUR. Flux  " + contFlux);
        debug_print("SATUR. Backg " + telBckg);
        debug_print("SATUR. PSF   " + psfFrac);
        debug_print("SATUR. Order " + sortRangeInfo[range1]{1});
    }
    paramsSPECdef = PacsSpecDefaults(throw,confTable,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // we need the keyWAVE here   
    double[] refWL = [waveRef];
    // BV 02/11/2009 SCR 1239: take key wavelength specified in gratpos
    //
    // double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    {double,int} keys = PacsSpecKeyWaves_grat(orderSel,refWL);
    double keyWL = keys{0};
    int grat_keyWL = keys{1};
    double[] keyWAVE = [keyWL];
    int[] grat_keyWAVE = [grat_keyWL];
    //   double [] keyWAVE = PacsRangeSpecKeyWaves(sortRangeInfo);
    int nbKeyWAVE = 1;
    //   int nbKeyWAVE = length(keyWAVE);
    // Capa Checks
    // PHS-193
    {{bool,int},{bool,int}} capaChecks = PacsSpecCheckCapacitance(rangeSPOT,orderSel);
    {bool,int} switchCapaBlu = {capaChecks{0}{0},capaChecks{0}{1}};
    {bool,int} switchCapaRed = {capaChecks{1}{0},capaChecks{1}{1}};
    if(switchCapaRed{0}) {
        debug_print("switchCapa{1}:" + switchCapaRed{1});
        message("<h1> Attention!! </h1>");
        message("<p>The Capacitance in the <font color=red> Red </font>  channel has changed from the default value 0 to a higher value " + switchCapaRed{1} + " due to high flux density in one or several requested ranges </p>");
        message("<p>This will cause a loss of sensitivity in the faintest lines and/or in the faintest part of the continuum. Please refer to the User's manual, and/or to the PacsRangeSpec Release notes for more informations </p>");
        confSPECred[0]{0} = switchCapaRed{1};
    }
    if(switchCapaBlu{0}) {
        debug_print("switchCapa{1}:" + switchCapaBlu{1});
        message("<h1> Attention!! </h1>");
        message("<p>The Capacitance in the <font color=blue> Blue </font> channel has changed from the default value 0 to a higher value " + switchCapaBlu{1} + " due to high flux density in one or several requested ranges </p>");
        message("<p>This will cause a loss of sensitivity in the faintest lines and/or in the faintest part of the continuum. Please refer to the User's manual, and/or to the PacsRangeSpec Release notes for more informations </p>");
        confSPECblu[0]{0} = switchCapaBlu{1};
    }
    //             End Capa Checks   
    // Here comes the module to estimate PACS parameters as a function of the
    // exposure time given by the user. This is the pilar of the
    // whole AOT logic.
    //Define tuple to contain the "variable" parameters
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPEC = clone(paramsSPECdef);
    // paramsSPECext (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,nb_up_dn,aux1,aux2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for each wavelength. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("confOBCP[0]: " + confOBCP[0]);
    }
    int nbNods = 0;
    double waveMAXnods = 0.0;
    // Accumulated total OBS time
    // SCR- ... OBCP 35
    int totalOBS = 0;
    if(chopNod) {
        for(int rangeLOOP = 1 .. nbRanges) {
            range1 = rangeLOOP - 1;
            //        paramsSPECext = PacsRangeSpecEstimatorOBCP27(sortRanges[range1],sortRangeInfo[range1],paramsSPEC,chopNod,verbose);
            paramsSPECext = PacsRangeSpecEstimatorOBCP35(sortRanges[range1],sortRangeInfo[range1],paramsSPEC,chopNod,verbose);
            //    Copy estimates to respective tuples
            confSPECblu[rangeLOOP] = paramsSPECext{0};
            confSPECred[rangeLOOP] = paramsSPECext{1};
            confOBCP[rangeLOOP] = paramsSPECext{2};
            //    nb_nods below is the quantity used by Estimator to compute its duration
            int nb_nods = paramsSPECext{3}{0};
            //     
            if(verbose) {
                debug_print("confOBCP[" + rangeLOOP + "]: " + confOBCP[rangeLOOP]);
            }
            //    Accumulated time
            totalOBS = totalOBS + paramsSPECext{3}{2};
        }
    } else {
        if(gratScan) {
            for(int rangeLOOPX = 1 .. nbRanges) {
                range1 = rangeLOOPX - 1;
                //        paramsSPECext = PacsRangeSpecEstimatorOBCP27(sortRanges[range1],sortRangeInfo[range1],paramsSPEC,chopNod,verbose);
                paramsSPECext = PacsRangeSpecEstimatorOBCP28(sortRanges[range1],sortRangeInfo[range1],paramsSPEC,gratScan,verbose);
                //    Copy estimates to respective tuples
                confSPECblu[rangeLOOPX] = paramsSPECext{0};
                confSPECred[rangeLOOPX] = paramsSPECext{1};
                confOBCP[rangeLOOPX] = paramsSPECext{2};
                //    nb_nods below is the quantity used by Estimator to compute its duration
                // PHS-1388/7 no NODS
                // nb_nods = paramsSPECext{3}{0};
                nb_nods = 0;
                //     
                if(verbose) {
                    debug_print("confOBCP[" + rangeLOOPX + "]: " + confOBCP[rangeLOOPX]);
                }
                //    Accumulated time
                totalOBS = totalOBS + paramsSPECext{3}{2};
            }
        }
    }
    if(verbose) {
        debug_print("Minimum required time: " + totalOBS + " [sec] for " + nb_nods + " nod cycles");
    }
    if(chopNod) {
        nbNods = userNODcycles;
        if(verbose) {
            debug_print("The PointReq will contain " + nbNods + " nod cycles");
        }
    } else {
        //PHS-1477
        if(gratScan && source == "point") {
            nbNods = userNODcycles;
        } else {
            nbNods = 0;
        }
    }
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Estimated total OBStime (SRC+REF) for requested ranges: " + totalOBS + "[sec]</p>";
    lineCnt = lineCnt + 1;
    int nodTotal = nbNods * totalOBS;
    if(chopNod) {
        msgLine[lineCnt] = "<p>With the specified NOD count, " + nbNods + ", the total OBS time amounts to " + nodTotal + "[sec]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Since no NOD was specified the total OBS time is equal" + " to the estimated SRC+REF time. OBS times can be changed" + " by specifying the line(s) repeat factor</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("Accumulated SRC+REF time estimation",lineCnt,msgLine);
    // Messages on general Detector/SPU parameters
    lineCnt = 0;
    msgLine[lineCnt] = "<p>Red channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECred[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    int subRamps = confSPECred[0]{1} / confSPECred[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECred[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECred[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Blue channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECblu[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    subRamps = confSPECblu[0]{1} / confSPECblu[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECblu[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECblu[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Selected PACS setup parameters",lineCnt,msgLine);
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source
    // First operation is to set the OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    if(verbose) {
        debug_print("Duration WriteOBSID: " + timeSetOBSID);
    }
    // Will call PacsSpecSlewCal to perform AOT prologue and CAL during
    // slew to source. Establish an array of key wavelengths, one per order,
    // commensurate with user given wavelengths
    // 
    // With latest versions of CommandOBCP35 the grating is
    // supposed to be left by SlewCal at the position needed for the 1st line
    // The OBCPs will leave the grating at that same position
    int frstLstGratPos = confOBCP[1]{8};
    if(verbose) {
        debug_print("MAIN:keyWAVES " + keyWAVE);
        debug_print("MAIN:SlewCal should leave grating at: " + frstLstGratPos);
    }
    // Time needed to perform these activities during slew (includes AOTprologue)
    // ATT SlewCal includes now OBCP35 (BBID 350)
    bool doAOTprologue = true;
    // BV 02/11/2009 SCR 1239: take key wavelength specified in gratpos
    //int timeSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel));
    int timeSlewCal = duration(PacsSpecSlewCal_grat(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,grat_keyWAVE,keyWAVE,filter,frstLstGratPos,orderSel));
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during slew: " + timeSlewCal);
    }
    // compute aot_prologue for turning on the science data (SCR 7005)
    int timeDoSlewScience = duration(Pacs_SPEC_aot_prologue(false,confSPECblu,confSPECred,confOBCP,filter));
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsSpecCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsSpecCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // IMPORTANT NOTE: the duration may be different for the first cycle through 
    // all wavelengths than for the following ones owing to differing initial state.
    // However, all steps have been taken so that PACS starts the actual observation
    // in the same state as it would be left at the end of any wavelength cycle
    // Duration of any nod leg or staring observation
    // 
    // OBCP 35
    //    int timeOBS = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
    bool dither = false;
    int timeOBS = 0;
    if(!sed && density == "nyquist") {
        dither = true;
    }
    if(chopNod) {
        timeOBS = duration(PacsSpecCommandOBCP35_dither(confSPECblu,confSPECred,confOBCP,dither,verbose));
        if(verbose) {
            debug_print("Duration OBCP35: " + timeOBS + " [sec] per nod;  nb_nods: " + nb_nods);
        }
    }
    //PHS-1477
    if(gratScan) {
        if(source == "point") {
            for(int outterLOOP = 0 .. userNODcycles - 1) {
                timeOBS = timeOBS + duration(PacsSpecCommandOBCP28_dither(confSPECblu,confSPECred,confOBCP,dither,verbose));
            }
        } else {
            timeOBS = duration(PacsSpecCommandOBCP28_dither(confSPECblu,confSPECred,confOBCP,dither,verbose));
        }
        if(verbose) {
            debug_print("Duration OBCP35: " + timeOBS + " [sec] per nod;  nb_nods: " + nb_nods);
        }
    }
    // Get duration of module to close AOT operations
    // This includes parking the grating
    // Park position
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // The grating was left by OBCPs at frstLstGratPos
    int timeEpilogue = duration(SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose));
    // WriteEndID will be the last TC; get its duration
    int timeEndID = duration(WriteEndID());
    if(verbose) {
        debug_print("Duration WriteEndID: " + timeEndID);
    }
    // Summary of relevant data collected so far
    // timeSlewCal: duration of the leading CAL, including AOT_prologue
    // timeOBS    : duration of a single pointed OBS
    // nb_nods    : number of nods for staring mode or per raster position
    // chopNod : invoke nodding or not (nb_nods = 0 is equivalent to no nod)
    // m, n       : raster nb_points/line, nbRanges per RREQ
    // pointStep,lineStep: more raster parameters
    // ra,dec: more pointing parameters
    //
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Ready to issue a FinePointing mode with/without nodding or
    // a RasterReq with/without nodding. Either one needs some time during
    // slew to perform leading CAL.
    // Make sure that the Preq is possible (possible reason for failure: too short
    // dwell time - currently 10 sec
    int minTdwell = 10;
    if(timeOBS < minTdwell) {
        error("Estimated dwell time is too short. Perhaps your range span is too small");
    }
    //
    // The chopper throws have been read already (PacsSpecDefaults) and angles
    // have been converted into ENG units (OBCPconf). Here,angles are needed in 
    // [arcsec]; easiest is to read again the relevant CAL-U table. 
    // Read chopper position SRC and REF1 [arcsec]
    // 
    // PHS-1225
    // 
    double chopAngleSrc = dlookup("SPEC_CHOP_params",throw,"SRC");
    double chopAngleRef = dlookup("SPEC_CHOP_params",throw,"REF1");
    double nodAngleSrc = dlookup("SPEC_NOD_params",throw,"SRC");
    double nodAngleRef = dlookup("SPEC_NOD_params",throw,"REF1");
    // The total nodThrow = chopperTotalThrow
    double nodThrow = abs(nodAngleSrc - nodAngleRef);
    if(verbose) {
        debug_print("PacsSpecDef: CHOP/NOD params SRC/REF/NOD: " + chopAngleSrc + "/" + chopAngleRef + "/" + nodThrow);
    }
    // Issue pointing request (when possible use JBr's variable names for clarity)
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    // Virtual aperture
    string ib = "P02_0";
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("#### skewCorrec : " + skewCorrec);
    }
    int tslewmin = timeSetOBSID + timeSlewCal;
    int tinithold = 0;
    int tfinalhold = timeEndID + timeEpilogue;
    int tp = timeOBS;
    double patt = 0.0;
    double pattnod = 270.0 + skewCorrec;
    int k = 0;
    int thold = 0;
    int nhold = 0;
    int nload = 0;
    int tloadslewmin = 0;
    bool fixed = true;
    if(pointCase == 11) {
        //   FinePointingMode without nodding
        int[] fromPntReq = basic_fine_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,yoffset,zoffset,tp);
    }
    if(pointCase == 12) {
        //   FinePointingMode with nodding, section 3.4
        ib = "P02_0";
        //   Nodding angle is specified wrt spacecraft
        fixed = false;
        //   Nodding is along y axis, opposite chop
        pattnod = 270.0 + skewCorrec;
        fromPntReq = nodding_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nbNods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
    }
    if(pointCase == 21 || pointCase == 31) {
        //   RasterMode without nodding, section 3.5
        ib = "P02_0";
        //   Raster in instrument coordinates
        fixed = false;
        double d1 = pointStep;
        double d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        k = 0;
        int ncover = 1;
        //   New arguments for pointing request; will be dealt with next iteration
        int top = 0;
        raoff = 0.0;
        decoff = 0.0;
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,ncover,thold,nhold,k,top,raoff,decoff);
    }
    if(pointCase == 30) {
        //   RasterMode with no nodding and No OFF PHS-1387
        ib = "P02_0";
        //   SPR-3237: fix is true, patt is inherited from HSPOT
        // !! for gratScan nope .... added bool
        // PHS-1463... oops
        if(mapRasterAngleRefFrame) {
            fixed = true;
            patt = mapRasterAngle;
        } else {
            fixed = false;
            patt = 0.0;
        }
        //   Raster steps
        d1 = pointStep;
        d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        // OFF periodicity (here at beginning and at end of raster)
        // PHS-1388/7 No OFF
        //        k = m * n;
        k = 0;
        //   The number of repetions is given in this case by the NOD count SPR-3186
        int nrepeat = userNODcycles;
        if(nrepeat == 0) {
            nrepeat = 1;
        }
        //   Same Tobs during OFF that during "SRC"
        top = tp;
        trepeatmin = 0;
        tloadmin = 0;
        nload = 0;
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
    }
    if(pointCase == 22 || pointCase == 32) {
        //   RasterMode with nodding, section 3.6
        ib = "P02_0";
        //   Raster in instrument coordinates
        fixed = false;
        //   Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        //   Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        k = 0;
        nrepeat = 1;
        //   New arguments for pointing request; will be dealt with next iteration
        top = 0;
        raoff = 0.0;
        decoff = 0.0;
        trepeatmin = 0;
        tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nbNods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
    }
    // Parameters returned by PointReq
    if(verbose) {
        debug_print("=====> Return from " + pointMode + ": " + fromPntReq);
    }
    //Info from API (nomenclature from Jon Br)
    tobs = fromPntReq[0];
    tslew = fromPntReq[1];
    ///////////////////////// end of "timing" section //////////////////////////
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
    }
    if(verbose) {
        int tNOW = time();
        debug_print("=== Issued PointReq Time_now: " + tNOW);
    }
    // Issue TCs
    int[] stateVar = [0];
    int nbOBS = 0;
    int nbOFF = 0;
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            //       Write OBSID (logical part of SlewCal)
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            //          if(!doSlewScience) {
            tNOW = time();
            if(verbose) {
                debug_print(" AOT science Data OFF: " + tNOW);
            }
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            // BV 02/11/2009 - SPR 1239 - cal block in grat pos
            // int[][] calTime = PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel);
            int[][] calTime = PacsSpecSlewCal_grat(false,confSPECblu,confSPECred,confOBCP,true,grat_keyWAVE,keyWAVE,filter,frstLstGratPos,orderSel);
            //            }
            //            if(doSlewScience) {
            //                tNOW = time();
            //                if(verbose) {
            //                    debug_print("Aot Science Data ON: " + tNOW);
            //                }
            //                int[] aotTime = Pacs_SPEC_aot_prologue(false,confSPECblu,confSPECred,confOBCP,filter);
            //                if(tslew > tslewmin) {
            //                    delay(tslew - tslewmin);
            //                }
            // Now, execute the standard calibration block pushed to the end of the slew
            //                tNOW = time();
            //                if(verbose) {
            //                    debug_print("SLEW_CAL starts at   " + tNOW);
            //                }
            //                // BV 02/11/2009 - SPR 1239 - cal block in grat pos
            //                //calTime = PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel);
            //                calTime = PacsSpecSlewCal_grat(false,confSPECblu,confSPECred,confOBCP,false,grat_keyWAVE,keyWAVE,filter,frstLstGratPos,orderSel);
            //            }
            //       Define accumulated Cal time
            int[][] sumUpCalTime = calTime;
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW ends at: " + tNOW);
                debug_print("    SumUpCalTime: " + sumUpCalTime);
            }
        } else {
            if(stateVar[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== POINT starts at: " + tNOW);
                }
                //                int[][] obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                if(chopNod) {
                    int[][] obsTime = PacsSpecCommandOBCP35_dither(confSPECblu,confSPECred,confOBCP,dither,false);
                    nbOBS = nbOBS + 1;
                }
                if(gratScan) {
                    // PHS-1477
                    if(source == "point") {
                        for(int pointLOOP = 0 .. userNODcycles - 1) {
                            obsTime = PacsSpecCommandOBCP28_dither(confSPECblu,confSPECred,confOBCP,dither,false);
                            nbOBS = nbOBS + 1;
                            if(nbOBS == 1) {
                                int[][] sumUpObsTimeU = obsTime;
                            }
                            if(nbOBS > 1) {
                                sumUpObsTimeU = SumFunction(obsTime,sumUpObsTimeU);
                            }
                        }
                    } else {
                        obsTime = PacsSpecCommandOBCP28_dither(confSPECblu,confSPECred,confOBCP,dither,false);
                        nbOBS = nbOBS + 1;
                    }
                }
                debug_print("nbOBS: " + nbOBS);
                if(chopNod || source != "point") {
                    if(nbOBS == 1) {
                        int[][] sumUpObsTime = obsTime;
                    }
                    if(nbOBS > 1) {
                        sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                    }
                }
                //       Logic to sum up obsTime
                if(verbose) {
                    tNOW = time();
                    if(gratScan && source == "point") {
                        debug_print("    SumUpObsTime: " + sumUpObsTimeU);
                    } else {
                        debug_print("    SumUpObsTime: " + sumUpObsTime);
                    }
                    debug_print("=== POINT ends at: " + tNOW);
                }
            } else {
                if(stateVar[0] == 4) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF starts at: " + tNOW);
                    }
                    //                    obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                    obsTime = PacsSpecCommandOBCP35_dither(confSPECblu,confSPECred,confOBCP,dither,false);
                    nbOFF = nbOFF + 1;
                    //       Logic to sum up obsTime
                    if(nbOFF == 1) {
                        int[][] sumUpOffTime = obsTime;
                    }
                    if(nbOFF > 1) {
                        sumUpOffTime = SumFunction(obsTime,sumUpOffTime);
                    }
                    if(verbose) {
                        tNOW = time();
                        debug_print("    SumUpOffTime: " + sumUpOffTime);
                        debug_print("=== OFF ends at: " + tNOW);
                    }
                } else {
                    if(stateVar[0] == 7) {
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== NOD started at: " + tNOW);
                        }
                        //                        obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                        obsTime = PacsSpecCommandOBCP35_dither(confSPECblu,confSPECred,confOBCP,dither,false);
                        nbOBS = nbOBS + 1;
                        //       Logic to sum up obsTime
                        if(nbOBS == 1) {
                            sumUpObsTime = obsTime;
                        }
                        if(nbOBS > 1) {
                            if(verbose) {
                                debug_print("obsTime: " + obsTime + " /sumUpObsTime: " + sumUpObsTime);
                            }
                            sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                        }
                        if(verbose) {
                            tNOW = time();
                            debug_print("    SumUpObsTime: " + sumUpObsTime);
                            debug_print("=== NOD ends at: " + tNOW);
                        }
                    } else {
                        if(stateVar[0] == 6) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== HOLD starts at: " + tNOW);
                            }
                            // BV 02/11/2009 - SPR 1239 - cal block in grat pos
                            // calTime = PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel);
                            calTime = PacsSpecSlewCal_grat(false,confSPECblu,confSPECred,confOBCP,false,grat_keyWAVE,keyWAVE,filter,frstLstGratPos,orderSel);
                            sumUpCalTime = SumFunction(calTime,sumUpCalTime);
                            if(verbose) {
                                tNOW = time();
                                debug_print("    SumUpCalTime: " + sumUpCalTime);
                                debug_print("=== HOLD ends at: " + tNOW);
                            }
                        } else {
                            if(stateVar[0] == 5) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== FinalHOLD  starts at: " + tNOW);
                                }
                                SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose);
                                WriteEndID();
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== FinalHOLD  ends at: " + tNOW);
                                }
                            } else {
                                if(stateVar[0] == -1) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== AOT ends at: " + tNOW);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    if(verbose) {
        debug_print("OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
    }
    // The original concept of returning durations did not take into 
    // account the bandwidth of the TC bus (2 TCs/sec). The "real" 
    // duration is given by the result from the "duration()" function. Hence
    // the true total duration of the SlewCal phase is given by
    ///   calTime[0] = timeSlewCal;
    // as a result, the overheads are now
    ///   calTime[4] = calTime[0]-(calTime[1]+calTime[2]+calTime[3]); 
    if(verbose) {
        debug_print("Slew & HOLD Cal return: " + sumUpCalTime);
    }
    // changed into OBCP35: orginal comments on OBCP27
    // The same holds true for the OBCP35 phase. However, I cannot make the
    // break-down by wavelength (the OBCP35 duration is given for ALL ranges).
    // We may add up the SRC, CAL, and OVR components of OBCP35 duration. For
    // this we need a tuple so we can add the wavelength and other relevant
    // information to the (per wave) duration arrays.
    //
    //    infoArray[] contains a "fixed" global information part
    //    infoArray[0]: {Slew,   intTime,TotDur,nbRanges,nnods,m*n}
    //    infoArray[1]: {Point,  intTime,TotDur,nbRanges,nnods,m*n}
    //    infoArray[2]: {AOTinfo,intTime,TotDur,nbRanges,nnods,m*n}
    // and per wavelength array(s):
    //    [waveSTART,waveEND,order,gratStep,nbGratSteps,TOT,SRC,REF,CAL,OVR]
    // TotDur as given by duration(); TOT,SRC,REF,CAL,OVR are also in [sec]
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    // Fill infoArray with data from SlewCal
    // Instead of using timeSlewCal, use tslew time returned by PointReq
    // infoArray[0] = {{"SlewCal",0.0,timeSlewCal,0,0,0},[{0.,0.,0,0,0,0,0,0,0,0}]};
    infoArray[0] = {{"SlewCal",0.0,tslew,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Fill infoArray with data from OBCP35
    // Compute integration time per chopper plateau
    // intTime = nbRamps/plateau x nbRdouts/ramp x sampleInterval 
    // Sampling frequency
    double specSample = dlookup("PACSparams","spec_sample","freq_time");
    // Number of readouts per ramp
    int nbRdoutRamp = confSPECblu[1]{1};
    // NOTE: WAIT=1 are now counted as useful ramps; hence
    int nbRampPlateau = confOBCP[1]{4} + 1;
    // 
    double intTime = double(nbRampPlateau * nbRdoutRamp) / specSample;
    if(verbose) {
        debug_print("MAIN:AOT          : " + userMode);
        debug_print("MAIN:Rdouts/ramp  : " + nbRdoutRamp);
        debug_print("MAIN:Ramps/plateau: " + nbRampPlateau);
        debug_print("MAIN:IntTime (incl. WAIT=1): " + intTime);
    }
    // Replace timeOBS (per raster and per nod) with tobs from PntReq (matching
    // change in PacsProcessInfoArray)   
    // infoArray[1] = {{userMode,intTime,timeOBS,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    infoArray[1] = {{userMode,intTime,tobs,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    //PHS-1320
    if(sed) {
        nbRanges1 = repeatSed - 1;
        //          for(int loop3 = 0 .. nbRanges1) {
        //     Create element [loop3]
        infoArray[1]{1}[0] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy from/to wavelengths
        infoArray[1]{1}[0]{0} = sortRanges[0]{1};
        infoArray[1]{1}[0]{1} = sortRanges[0]{2};
        //     copy the grating order
        infoArray[1]{1}[0]{2} = sortRangeInfo[0]{1};
        //     copy the grating step
        infoArray[1]{1}[0]{3} = sortRangeInfo[0]{4};
        //     copy the number of grating step
        infoArray[1]{1}[0]{4} = confOBCP[0 + 1]{6};
        //     copy other data from obsTime
        for(int loopSED = 0 .. nbRanges1) {
            //PHS-1477
            if(gratScan && source == "point") {
                infoArray[1]{1}[0]{5} = sumUpObsTimeU[0][0];
                infoArray[1]{1}[0]{6} = sumUpObsTimeU[0][1];
                infoArray[1]{1}[0]{7} = sumUpObsTimeU[0][2];
                infoArray[1]{1}[0]{8} = sumUpObsTimeU[0][3];
                infoArray[1]{1}[0]{9} = sumUpObsTimeU[0][4];
            } else {
                infoArray[1]{1}[0]{5} = infoArray[1]{1}[0]{5} + sumUpObsTime[loopSED][0];
                infoArray[1]{1}[0]{6} = infoArray[1]{1}[0]{6} + sumUpObsTime[loopSED][1];
                infoArray[1]{1}[0]{7} = infoArray[1]{1}[0]{7} + sumUpObsTime[loopSED][2];
                infoArray[1]{1}[0]{8} = infoArray[1]{1}[0]{8} + sumUpObsTime[loopSED][3];
                infoArray[1]{1}[0]{9} = infoArray[1]{1}[0]{9} + sumUpObsTime[loopSED][4];
            }
        }
    } else {
        for(int loop3X = 0 .. nbRanges1) {
            //     Create element [loop3X]
            infoArray[1]{1}[loop3X] = {0.0,0.0,0,0,0,0,0,0,0,0};
            //     copy from/to wavelengths
            infoArray[1]{1}[loop3X]{0} = sortRanges[loop3X]{1};
            infoArray[1]{1}[loop3X]{1} = sortRanges[loop3X]{2};
            //     copy the grating order
            infoArray[1]{1}[loop3X]{2} = sortRangeInfo[loop3X]{1};
            //     copy the grating step
            infoArray[1]{1}[loop3X]{3} = sortRangeInfo[loop3X]{4};
            //     copy the number of grating step
            infoArray[1]{1}[loop3X]{4} = confOBCP[loop3X + 1]{6};
            //     copy other data from obsTime
            // PHS-1477
            if(gratScan && source == "point") {
                infoArray[1]{1}[loop3X]{5} = sumUpObsTimeU[loop3X][0];
                infoArray[1]{1}[loop3X]{6} = sumUpObsTimeU[loop3X][1];
                infoArray[1]{1}[loop3X]{7} = sumUpObsTimeU[loop3X][2];
                infoArray[1]{1}[loop3X]{8} = sumUpObsTimeU[loop3X][3];
                infoArray[1]{1}[loop3X]{9} = sumUpObsTimeU[loop3X][4];
            } else {
                infoArray[1]{1}[loop3X]{5} = sumUpObsTime[loop3X][0];
                infoArray[1]{1}[loop3X]{6} = sumUpObsTime[loop3X][1];
                infoArray[1]{1}[loop3X]{7} = sumUpObsTime[loop3X][2];
                infoArray[1]{1}[loop3X]{8} = sumUpObsTime[loop3X][3];
                infoArray[1]{1}[loop3X]{9} = sumUpObsTime[loop3X][4];
            }
        }
    }
    // Add more data from SlewCal to infoArray
    for(int loop4 = 0 .. nbKeyWAVE - 1) {
        //     for some reason it has to be "initialized"
        infoArray[0]{1}[loop4] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the wavelength
        infoArray[0]{1}[loop4]{0} = keyWAVE[loop4];
        //     copy other data from sumUpCalTime
        infoArray[0]{1}[loop4]{5} = sumUpCalTime[loop4][0];
        infoArray[0]{1}[loop4]{6} = sumUpCalTime[loop4][1];
        infoArray[0]{1}[loop4]{7} = sumUpCalTime[loop4][2];
        infoArray[0]{1}[loop4]{8} = sumUpCalTime[loop4][3];
        infoArray[0]{1}[loop4]{9} = sumUpCalTime[loop4][4];
    }
    // Further update of infoArray: add information from AOT_prologue    
    infoArray[0]{1}[nbKeyWAVE] = {0.0,0.0,0,0,0,0,0,0,0,0};
    // Copy OVR and TOT times
    infoArray[0]{1}[nbKeyWAVE]{9} = calTime[nbKeyWAVE][4];
    infoArray[0]{1}[nbKeyWAVE]{5} = calTime[nbKeyWAVE][4];
    // Copy the number of ranges observed and the number of key waves used
    infoArray[0]{0}{3} = nbKeyWAVE;
    infoArray[1]{0}{3} = nbRanges;
    // Copy the number of nod cycles and the number of raster points visited
    infoArray[1]{0}{4} = nbNods;
    infoArray[1]{0}{5} = m * n;
    // The duration of the OBS phase is given by timeObsEnd - timeSlewCal
    // Now get it from PntReq: timeObsPhase == tobs
    // int timeObsPhase = timeObsEnd - timeSlewCal - 1 - timeSetOBSID;
    if(verbose) {
        debug_print("CalSlew phase lasted [sec]: " + timeSlewCal);
        debug_print("The OBS phase lasted [sec]: " + tobs);
    }
    // Slew time during the OBS phase is then given by
    int timeSlewObs = tobs - nbOBS * timeOBS;
    if(verbose) {
        debug_print("Total slew during OBS [sec]: " + timeSlewObs);
    }
    // Populate the 3rd dimension of infoArray: global timing and AOT information
    // timeObsEnd is the total duration of the AOT
    infoArray[2] = {{"RangeSpec",0.0,timeObsEnd,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Case of SmallSrc with dithering
    if(source == "dithered") {
        infoArray[1]{0}{0} = "SmSrcDither";
    }
    // Use available entries to convey m,n, and nbNods
    infoArray[2]{0}{3} = m;
    infoArray[2]{0}{4} = n;
    // PointSources are also seen with composite_nodding
    if(pointMode == "fine_pointing" || pointMode == "composite_nodding") {
        infoArray[2]{0}{3} = 1;
        infoArray[2]{0}{4} = 1;
    }
    infoArray[2]{0}{5} = nbNods;
    // Case of raster/w/o  OFF, repeated map
    if(gratScan) {
        infoArray[1]{0}{0} = "GratScanNoChop";
        if(source == "large") {
            infoArray[1]{0}{0} = "RasterNoOFF";
        }
        infoArray[2]{0}{5} = nbRangesRep;
    }
    // Process the information contained in infoArray
    // NOTE: since implementing waveRef and fluxes, have to pass also 
    //       sortRanges and sortRangesExt data to ProcessInfoArray
    // aotID is no longer needed as only u<sed for Range
    // but orderSel is needed by PacsSpecRMS
    // SPR-2927 Return bigTuple with information for plotting
    // Add nbOBS and nbOFF to ProcessInfoArray
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = PacsProcessInfoArrayRange_tmp(infoArray,sortRanges,infoRangeSed,confOBCP,orderSel,obsOverhead,nbOBS,nbOFF,verbose);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    //////// Silly code to convert bigTuple into smallTuple ////////////////////
    // bigTuple is too big for HSPOT. I have to remove the 1st double[] to
    // please HSPOT. Create smallTupleN
    {string,double[],double[],double[],string,double[],double[],double[],string,double[],double[],double[]}[] smallTuple = [{"1",[0.0],[0.0],[0.0],"2",[0.0],[0.0],[0.0],"3",[0.0],[0.0],[0.0]}];
    // Old returned tuples
    {int,int,{{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[]} returnTuple = {fromPntReq[0],fromPntReq[1],bigTuple};
    // Copy returnTuple onto smallTuple
    nbRanges = length(bigTuple);
    if(verbose) {
        debug_print("bigTuple size: " + nbRanges);
    }
    // The accumulated SRC+REF time
    int accumSrceRef = 0;
    for(int loopR = 0 .. nbRanges - 1) {
        //  Use the nbRanges loop to add up SrceRef times (SRC + REF)
        if(verbose) {
            debug_print("infoArray time overheads etc..: ");
            debug_print("infoArray[1]{1}{6}: " + infoArray[1]{1}[loopR]{6});
            debug_print("infoArray[1]{1}{7}: " + infoArray[1]{1}[loopR]{7});
        }
        accumSrceRef = accumSrceRef + infoArray[1]{1}[loopR]{6} + infoArray[1]{1}[loopR]{7};
        //  Define smallTuple
        smallTuple[loopR] = {"1",[0.0],[0.0],[0.0],"2",[0.0],[0.0],[0.0],"3",[0.0],[0.0],[0.0]};
        //   Extract vectors; retrun CONT noise in mJy
        //   First tuple is always the nominal range. Label it as RangeID + "Nominal"
        string id = sortRanges[loopR]{0} + "-nominal";
        smallTuple[loopR]{0} = id;
        double[] wave = returnTuple{2}[loopR]{0}{2};
        double[] cont = returnTuple{2}[loopR]{0}{3};
        double[] line = returnTuple{2}[loopR]{0}{4};
        int nbElem = length(wave);
        for(int loopT1 = 0 .. nbElem - 1) {
            smallTuple[loopR]{1}[loopT1] = wave[loopT1];
            smallTuple[loopR]{2}[loopT1] = 1000.0 * cont[loopT1];
            smallTuple[loopR]{3}[loopT1] = line[loopT1];
        }
        wave = returnTuple{2}[loopR]{1}{2};
        cont = returnTuple{2}[loopR]{1}{3};
        line = returnTuple{2}[loopR]{1}{4};
        nbElem = length(wave);
        //   If there is no "free" data
        id = "undefined";
        //   Else label second tuple as RangeID + "-free1"
        if(nbElem > 1) {
            id = sortRanges[loopR]{0} + "-free1";
        }
        smallTuple[loopR]{4} = id;
        for(int loopT2 = 0 .. nbElem - 1) {
            smallTuple[loopR]{5}[loopT2] = wave[loopT2];
            smallTuple[loopR]{6}[loopT2] = 1000.0 * cont[loopT2];
            smallTuple[loopR]{7}[loopT2] = line[loopT2];
        }
        wave = returnTuple{2}[loopR]{2}{2};
        cont = returnTuple{2}[loopR]{2}{3};
        line = returnTuple{2}[loopR]{2}{4};
        nbElem = length(wave);
        //   If existing, label third tuple as RangeID + "-free2"
        id = "undefined";
        if(nbElem > 1) {
            id = sortRanges[loopR]{0} + "-free2";
        }
        smallTuple[loopR]{8} = id;
        for(int loopT3 = 0 .. nbElem - 1) {
            smallTuple[loopR]{9}[loopT3] = wave[loopT3];
            smallTuple[loopR]{10}[loopT3] = 1000.0 * cont[loopT3];
            smallTuple[loopR]{11}[loopT3] = line[loopT3];
        }
        //  End loop on nbRanges
    }
    // Compute overheads as total "sky" time minus SRC+REF time
    int overPACSandSC = fromPntReq[0] - accumSrceRef;
    if(verbose) {
        debug_print("overPACSandSC: PntReq - accumSrceRef");
        debug_print("PntReq: " + fromPntReq[0]);
        debug_print("accumSrceRef: " + accumSrceRef);
    }

    return {accumSrceRef,fromPntReq[1],overPACSandSC,smallTuple};
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Missionphase  : IST Chopper Day
//
// Purpose	:  Chopper synchronous operation with detectors in spec
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do OBCP13 with different RIs
//                  
// Dependencies : DXS7602.
//
// Preconditions   : PACS switched-on and setup spectroscopy.
//                 
// Comments	: 
//
// Version	: 6.0	
// 
// History 	: 0.1 26-07-06 creation by HD. script test.
//
//                0.2 27-07-06 HD. with all three RIs.
//                0.3 27-07-06 HD. script works
//		  0.4 16-08-06 HD. Included setup and reset of burst
//				   mode.
//		  1.0 24-08-06 HD. DXS&LLC, wo BM.
//		  2.0 24-08-06 HD. script works
//                3.0 06-12-06 HD. Renamed file and mode to xxxx_OBS, sets DetSel table
//				 and resets to default at end of procedure..
//		  4.0 20-06-07 HD. Prepare Test for FM-ILT3.
//		  5.0 05-07-07 HD. IST Chopper Day
//		  6.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//                7.0 10-feb-2009 HD. Including switch to burst mode (SPR-1136).
obs PacsEng_Spec_Chopper_fmilt076spec_detsel_llc_ast_V2 {
    /* Needed variables to call PacsEng_Spec_Chopper_fmilt076spec_detsel_llc_ast_V2                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Chopper_fmilt076spec_detsel_llc_ast_V2                     */
}{
    //
    busconfig (7);
    // BURST MODE :     4:PACS PRIME  -  7:BURST MODE  - 8:PARALLEL MODE
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Chopper_fmilt076spec_detsel_llc_ast_V2()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(300.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Chopper_fmilt076spec_detsel_llc_ast_V2();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsDureeOBCP27.txt,v 1.2 2007/04/25 15:14:04 dcesarsk Exp $ 
// Purpose       : Estimate duration of OBCP27 with input parameters
//
// CUS author    : 
// Script file   : PacsDureeOBCP27.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1  16-Sep-2005 DAC
int[] procedure PacsDureeOBCP27 {
    int nb_up_down = 1; // Number up/down grating cycles
    int nb_grat_step_up = 43; // Number of grating steps
    int nb_ramps_plateau = 2; // Number of ramps per chopper plateau
    int nb_CS1_CS2 = 0; // Number of chopper cycles CS1<=>CS2
    int nb_SRC_OFF = 1; // Number of chopper cycles SRC<=>REF
    int nb_rdouts_ramp = 64; // Number of rdouts per ramp
}{
    // Call the corresponding DMC sequence
    int[] duree = DMC_grat_scan_chop2(nb_up_down,nb_grat_step_up,nb_ramps_plateau,nb_CS1_CS2,nb_SRC_OFF);
    // Convert number of ramps into seconds
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    // Convert duration [ramps] into [msec]
    // Create return time array; convert into [sec]
    int[] time_array = [0,0,0,0,0];
    for(int aux = 0 .. 4) {
        time_array[aux] = ifloor(double(duree[aux]) * ramp_time);
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    //
    // Return total duration [sec] to calling program

    return time_array;
}

// CVS comments  : $Id: PacsDureeOBCP27.txt,v 1.2 2007/04/25 15:14:04 dcesarsk Exp $ 
// Purpose       : Estimate duration of OBCP27 with input parameters
//
// CUS author    : 
// Script file   : PacsDureeOBCP35.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1  16-Sep-2005 DAC
//  		 : 1.0 11-mar-2009 VD OBCP35
//  		 : 2.0 23-mar-2010 VD Cloned
//  		 : 3.0 modified according to DMC seq 
//
int[] procedure PacsDureeOBCP28 {
    int nb_up_down = 1; // Number up/down grating cycles
    int nb_grat_steps_up = 43; // Number of grating steps
    int nb_ramps_grat_pos = 2; // Number of ramps per chopper plateau
    int nb_CS1_CS2 = 0; // Number of chopper cycles CS1<=>CS2
    int nb_ramps_cs = 0;
    int nb_rdouts_ramp = 32; //Number of rdouts per ramp
}{
    // Call the corresponding DMC sequence
    int nb_grat_steps_dn = -nb_grat_steps_up;
    //     int[] duree = DMC_19_grat_line_scan(nb_up_down,nb_grat_step_up,nb_ramps_plateau,nb_CS1_CS2,nb_SRC_OFF);
    int[] duree = DMC_grat_scan_nochop(nb_up_down,nb_grat_steps_up,nb_ramps_grat_pos,nb_CS1_CS2,nb_ramps_cs,nb_grat_steps_dn);
    // Convert number of ramps into seconds
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    // Convert duration [ramps] into [msec]
    // Create return time array; convert into [sec]
    int[] time_array = [0,0,0,0,0];
    for(int aux = 0 .. 4) {
        time_array[aux] = ifloor(double(duree[aux]) * ramp_time);
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    //
    // Return total duration [sec] to calling program

    return time_array;
}

// File          : PACS_Spec_SPU_Reset.cus
// Missionphase  : PACS IST
//
// Purpose       : Reset SPU after spectroscopy data flow
//
// Author        : T. Mueller, H. Feuchtgruber
// CUSification  : DAC
// Arguments     : None
//                 
//
// Description   : Resets all settings of both SPU to their default values
//                 and stops the data compression/reduction
//                              
// Comments      :      
//
// Version       : 1.2
// History       : 1.0 / 10-Nov-2004 initial version
//                 1.1 14-apr-2006 Adapted to SPU v12.1
//                 1.2 28-mar-2007 DAC Update for SPUV13.
//                 1.3 24-mar-2009 DAC Update after SPU UM 13.95a
//
procedure PACS_Spec_SPU_Reset {
}{
    //-------------------------
    // Preparation
    //-------------------------
    Pacs_SPUS_STOP_REDUCT_COMPR();
    delay(1);
    Pacs_SPUL_STOP_REDUCT_COMPR();
    delay(1);
    // number of raw channels
    int spus_nraw = 3;
    int spul_nraw = 3;
    int spus_startraw = 1;
    int spul_startraw = 1;
    Pacs_SPUS_RAW_CHAN_TRAN_MODE("SPEC",spus_nraw,spus_startraw);
    delay(1);
    Pacs_SPUL_RAW_CHAN_TRAN_MODE("SPEC",spul_nraw,spul_startraw);
    delay(1);
    // default compression mode
    int comp_mode_blue = 16;
    int comp_mode_red = 16;
    {int}[] list_tuple = [{comp_mode_blue},{comp_mode_red}];
    int[] list_int = [comp_mode_blue,comp_mode_red];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_SPU_TRAN_MODE(list_tuple,chksum);
    delay(1);
    // Spectro "Ottensamer" block ("S" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    int ppf = 0;
    // PPP: Pre-Processing Parameter
    int ppp = 0;
    // Threshold for glitch detection in spectroscopy
    int tfs = 1000;
    // Threshold for chopper position deviation in spectroscopy
    int tcs = 100;
    // Threshold for grating deviation
    int tgd = 100;
    // Readouts per SubRamp readback
    int rsrr = 16;
    // Glitch detection for spectroscopy
    int gdfs = 1;
    // Ramp fitting algorithm
    int rfal = 0;
    // 13.95a values for soal & lcal are 5 & 4
    // Sorting algorithm
    int soal = 5;
    // lossless compression algorithm (0,1,2,3,4)
    int lcal = 4;
    // PACS Codec Order (3,4)
    int pcod = 3;
    // New 13.95a values are
    int rndb = 0;
    int rnds = 0;
    int fixrc = 0;
    int dpre = 0;
    int dpost = 0;
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    int[] aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    int check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    {int}[] spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUS_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    // Spectro "Ottensamer" block ("L" SPU)
    ppf = 0;
    ppp = 0;
    tfs = 1000;
    tcs = 100;
    tgd = 100;
    rsrr = 16;
    gdfs = 1;
    rfal = 0;
    soal = 5;
    lcal = 4;
    pcod = 3;
    // New 13.95a values are
    rndb = 0;
    rnds = 0;
    fixrc = 0;
    dpre = 0;
    dpost = 0;
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUL_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    //----------------------------
    // End of Procedure
    //----------------------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose	:  Chopper synchronous operation with detectors in spec
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do OBCP13 with different RIs
//                  
// Dependencies : DXS7602.
//
// Preconditions   : PACS switched-on and setup spectroscopy.
//                 
// Comments	: 
//
// Version	: 6.0	
// 
// History 	: 0.1 26-07-06 creation by HD. script test.
//
//                0.2 27-07-06 HD. with all three RIs.
//                0.3 27-07-06 HD. script works
//		  0.4 16-08-06 HD. Included setup and reset of burst
//				   mode.
//		  1.0 24-08-06 HD. DXS&LLC, wo BM.
//		  2.0 24-08-06 HD. script works
//                3.0 06-12-06 HD. Renamed file and mode to xxxx_OBS, sets DetSel table
//				 and resets to default at end of procedure..
//		  4.0 20-06-07 HD. Prepare Test for FM-ILT3.
//		  5.0 05-07-07 HD. IST Chopper Day
//		  6.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//		  7.0 10-feb-2009 HD. Including switch to burst mode (SPR-1136).
obs PacsEng_Spec_Chopper_fmilt076spec_detsel_llc_ast_V1 {
    /* Needed variables to call PacsEng_Spec_Chopper_fmilt076spec_detsel_llc_ast_V1                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Chopper_fmilt076spec_detsel_llc_ast_V1                     */
}{
    //
    busconfig (7);
    // BURST MODE :     4:PACS PRIME  -  7:BURST MODE  - 8:PARALLEL MODE
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Chopper_fmilt076spec_detsel_llc_ast_V1()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(300.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Chopper_fmilt076spec_detsel_llc_ast_V1();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : PACS AVM ILT
//
// Purpose       : Select the data mode
//
// Author TCL    : T. Mueller
// Author CUS    : DAC
// CUS script    : PHOT_change_data_mode.txt
//
// Arguments     : 
// type    name   default      Description
// string  mode   "Bolo_HK"    Select the data mode for bolometers
//                 
// Description   : This script will select the data mode for the bolometers
//                 After switch on of the bolometers the default data mode
//                 is "HK only", after executing the sequencer setup the
//                 default mode is "Bolo & HK"
//                              
// Comments      : Coded based on PhFPU UM, Draft 2, March 31, 2004
//
// Version       : 1.0 18-apr-2005 DAC Based on TM's V1.0 0f 20-apr-2004
// History       : 
//
int[] procedure PHOT_change_data_mode {
    string data_mode = "Bolo_HK" in ["Bolo_HK","HK_only","Test_Pat_HK"]; //Data mode for the bolometers
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    //------------------------------------------------
    // SET BOLC Data Mode data & HK
    //------------------------------------------------
    // PC103420 "DMC_SEND_COMMAND_BOLC" SEND COMMAND TO BOL CONTROLLER
    //         PP071420 "BOLOMETER_COMMAND"
    Pacs_BOLC_SET_DATA_MODE(data_mode);
    // Time spent
    int duree_TCs = time() - time_start;
    duree_OVR = duree_TCs;
    duree_num = duree_OVR;
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// $Id: PacsEng_Spec_Fltw_Mec_Setup.txt,v 1.5 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 05-Jul-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Fltw_Mec_Setup_u {
    /* No variables to call PacsEng_Spec_Fltw_Mec_Setup_u                        */
    /*  string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Fltw_Mec_Setup_u                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_spec_fltw()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_spec_fltw();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsDureeOBCP32.txt,v 1.1 2007/10/25 12:16:47 dcesarsk Exp $ 
// Purpose       : Estimate duration of OBCP32 with input parameters
//
// CUS author    : 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : Based on PacsDureeOBCP22
// Version       : 0.1
// History       : 0.1  18-oct-2007 DAC
//                 1.0   3-jun-2009 DAC Rewritten for new OBCP32
//
int[] procedure PacsDureeOBCP32 {
    int ditherCount = 11; // Number of dither cycles
    int nb_up_dn = 1; // Number of up/down cycles
    int nbABBA = 3; // Number ABBA cycles
    int nb_ramps_grat = 1; // Number of ramps per grating positiom
    int nb_rdouts_ramp = 64; // Number of rdouts per ramp
}{
    // Use "theoretical formula
    int dureeUpDn = ditherCount * (nbABBA * 4 * nb_ramps_grat + 1);
    int duree = nb_up_dn * 2 * dureeUpDn;
    //  Create duree array the usual DMC way
    int[] duree_array = [duree,duree / 2,duree / 2,0,0];
    // Use classical method
    int[] classic = DMC_wave_switch(ditherCount,ditherCount,nbABBA,nb_ramps_grat,nb_up_dn);
    // Convert number of ramps into seconds
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    // Convert duration [ramps] into [msec]
    // Create return time array; convert into [sec]
    int[] time_array = [0,0,0,0,0];
    for(int aux = 0 .. 4) {
        time_array[aux] = ifloor(double(duree_array[aux]) * ramp_time);
        time_array[aux] = Msec2sec(time_array[aux]);
        classic[aux] = ifloor(double(classic[aux]) * ramp_time);
        classic[aux] = Msec2sec(classic[aux]);
    }
    //
    // Return total duration [sec] to calling program
    //   return time_array;

    return classic;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
//
// Purpose : Reduced NEP measurements for the new sequencer test
//           Search for the optimum bias with 11 values
//           using the high gain
//
// Author : Koryo Okumura
//
//
// Argument :
//    int response_measure_time = 60; // response measure time in seconds
//    int noise_measure_time = 120; // noise measure time in seconds
//    int lowFreq_noise_time = 1800; // long noise measure time in seconds
//    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Instrument is in safe mode
//
// Description : OBS script of PHOT_redArray_alternatePolarisation_direct_IST
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_newSeq_IST(1)
//
// Version 	: 1.0
// History	: 0.1 Fri Oct 05 12:21:33 CEST 2007
// 		: 1.0 translated into PV script VDP
//
obs PacsEng_Phot_redArray_alternatePolarisation_direct_IST {
    /* Needed variables to call PacsEng_Phot_redArray_alternatePolarisation_direct_IST                        */
    int response_measure_time = 60; // response measure time in seconds
    int noise_measure_time = 120; // noise measure time in seconds
    int lowFreq_noise_time = 1800; // long noise measure time in seconds
    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_redArray_alternatePolarisation_direct_IST                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PHOT_redArray_alternatePolarisation_direct_IST(response_measure_time,noise_measure_time,lowFreq_noise_time,biasFile)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_redArray_alternatePolarisation_direct_IST(response_measure_time,noise_measure_time,lowFreq_noise_time,biasFile);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsRangeSpecSed.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $
// Missionphase  : Operations
//
// Purpose       : 
//
// CUS author    : VD
// Script file   : NomToPar
//
// Input arguments
// type     name      description
// Return values
// Type                Description
//
// Description   : Creates RED or BLU "range" variable for Parallel Ranges
//
// Preconditions :
//
// Comments      : PHS-193 PHS-198
// History       : 19-jan-2010 1.0 VD: created
//               : addapted
//               : 15-mar-2010 1.1 VD: PHS-1355 bands limits
//               : 03-05-2010 2.0 VD PHS-1392 B2A order23
//               : 4.0 11-jun-2010 VD PHS-1463
// 
{double,double,bool} procedure PacsSpecGetParBand {
    double wave_blu_Nom = 0.0;
    double wave_red_Nom = 0.0;
    string orderSel = "order3";
}{
    // Return variables
    debug_print("wave_blu_Nom: " + wave_blu_Nom);
    debug_print("wave_red_Nom: " + wave_red_Nom);
    double bluWavePar = 0.0;
    double redWavePar = 0.0;
    // create all order
    string interp_file_Par = "TBD";
    string interp_file_Par_ex = "TBD";
    string interp_grat_Nom = "TBD";
    double grat_blu_Nom = 0.0;
    double grat_red_Nom = 0.0;
    double waveCheckBLU = 0.0;
    double waveCheckRED = 0.0;
    bool needCheck = false;
    bool noParBand = false;
    // grab grat_xxx_nom
    if(wave_blu_Nom >= 102.0) {
        if(orderSel == "order2") {
            interp_grat_Nom = "SPEC_RSRF_Red";
            interp_file_Par = "SPEC_grat_wl_B2B";
            grat_blu_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_blu_Nom);
            grat_red_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_red_Nom);
            bluWavePar = interpolate(interp_file_Par,"wave",grat_blu_Nom);
            redWavePar = interpolate(interp_file_Par,"wave",grat_red_Nom);
            waveCheckBLU = dlookup("SPEC_BAND_params","2","BLU");
            waveCheckRED = dlookup("SPEC_BAND_params","2","RED");
            if(redWavePar < waveCheckBLU || bluWavePar > waveCheckRED) {
                redWavePar = wave_red_Nom;
                bluWavePar = wave_blu_Nom;
                noParBand = true;
            } else {
                if(redWavePar < waveCheckRED && bluWavePar < waveCheckBLU) {
                    bluWavePar = waveCheckBLU;
                }
                if(bluWavePar > waveCheckBLU && redWavePar > waveCheckRED) {
                    redWavePar = waveCheckRED;
                }
                if(bluWavePar < waveCheckBLU && redWavePar > waveCheckRED) {
                    redWavePar = waveCheckRED;
                    bluWavePar = waveCheckBLU;
                }
            }
        }
        if(orderSel == "order23") {
            interp_grat_Nom = "SPEC_RSRF_Red";
            interp_file_Par = "SPEC_grat_wl_B2A";
            grat_blu_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_blu_Nom);
            grat_red_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_red_Nom);
            bluWavePar = interpolate(interp_file_Par,"wave",grat_blu_Nom);
            redWavePar = interpolate(interp_file_Par,"wave",grat_red_Nom);
            waveCheckBLU = dlookup("SPEC_BAND_params","23","BLU");
            waveCheckRED = dlookup("SPEC_BAND_params","23","RED");
            debug_print("bluWavePar/redWavePar/waveCheckBLU/waveCheckRED: " + bluWavePar + "/" + redWavePar + "/" + waveCheckBLU + "/" + waveCheckRED);
            if(redWavePar < waveCheckBLU || bluWavePar > waveCheckRED) {
                redWavePar = wave_red_Nom;
                bluWavePar = wave_blu_Nom;
                noParBand = true;
            } else {
                if(redWavePar < waveCheckRED && bluWavePar < waveCheckBLU) {
                    bluWavePar = waveCheckBLU;
                }
                if(bluWavePar > waveCheckBLU && redWavePar > waveCheckRED) {
                    redWavePar = waveCheckRED;
                }
                if(bluWavePar < waveCheckBLU && redWavePar > waveCheckRED) {
                    redWavePar = waveCheckRED;
                    bluWavePar = waveCheckBLU;
                }
            }
        }
        if(orderSel == "order3") {
            interp_grat_Nom = "SPEC_RSRF_Red";
            interp_file_Par = "SPEC_grat_wl_B3A";
            interp_file_Par_ex = "SPEC_grat_wl_B2A";
            grat_blu_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_blu_Nom);
            grat_red_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_red_Nom);
            bluWavePar = interpolate(interp_file_Par,"wave",grat_blu_Nom);
            redWavePar = interpolate(interp_file_Par,"wave",grat_red_Nom);
            double bluWavePar_ex = interpolate(interp_file_Par_ex,"wave",grat_blu_Nom);
            double redWavePar_ex = interpolate(interp_file_Par_ex,"wave",grat_red_Nom);
            waveCheckBLU = dlookup("SPEC_BAND_params","3","BLU");
            waveCheckRED = dlookup("SPEC_BAND_params","3","RED");
            if(redWavePar < waveCheckBLU || bluWavePar > waveCheckRED) {
                if(redWavePar_ex < waveCheckBLU || bluWavePar_ex > waveCheckRED) {
                    redWavePar = wave_red_Nom;
                    bluWavePar = wave_blu_Nom;
                    noParBand = true;
                } else {
                    if(bluWavePar_ex >= waveCheckBLU && redWavePar_ex <= waveCheckRED) {
                        redWavePar = redWavePar_ex;
                        bluWavePar = bluWavePar_ex;
                    } else {
                        if(bluWavePar_ex < waveCheckBLU && redWavePar_ex <= waveCheckRED) {
                            bluWavePar = waveCheckBLU;
                            redWavePar = redWavePar_ex;
                        }
                        if(bluWavePar_ex >= waveCheckBLU && redWavePar_ex > waveCheckRED) {
                            redWavePar = waveCheckRED;
                            bluWavePar = bluWavePar_ex;
                        }
                    }
                }
            } else {
                if(bluWavePar < waveCheckBLU && redWavePar <= waveCheckRED) {
                    bluWavePar = waveCheckBLU;
                    redWavePar = redWavePar;
                }
                if(bluWavePar >= waveCheckBLU && redWavePar > waveCheckRED) {
                    redWavePar = waveCheckRED;
                    bluWavePar = bluWavePar;
                }
                if(bluWavePar < waveCheckBLU && redWavePar > waveCheckRED) {
                    bluWavePar = waveCheckBLU;
                    redWavePar = waveCheckRED;
                }
            }
        }
        if(orderSel == "sedb2b") {
            bluWavePar = dlookup("SPEC_BAND_params","b2b","BLU");
            redWavePar = dlookup("SPEC_BAND_params","b2b","RED");
        }
        if(orderSel == "sedb2a") {
            bluWavePar = dlookup("SPEC_BAND_params","b2a","BLU");
            redWavePar = dlookup("SPEC_BAND_params","b2a","RED");
        }
        if(orderSel == "sedb3a") {
            bluWavePar = dlookup("SPEC_BAND_params","b3a","BLU");
            redWavePar = dlookup("SPEC_BAND_params","b3a","RED");
        }
    } else {
        if(orderSel == "sedb2b") {
            bluWavePar = dlookup("SPEC_BAND_params","b2bLR1","BLU");
            redWavePar = dlookup("SPEC_BAND_params","b2bLR1","RED");
        } else {
            if(orderSel == "sedb2a") {
                bluWavePar = dlookup("SPEC_BAND_params","b2aSR1","BLU");
                redWavePar = dlookup("SPEC_BAND_params","b2aSR1","RED");
            } else {
                if(orderSel == "sedb3a") {
                    bluWavePar = dlookup("SPEC_BAND_params","b3aLR1","BLU");
                    redWavePar = dlookup("SPEC_BAND_params","b3aLR1","RED");
                } else {
                    if(orderSel == "order2") {
                        interp_grat_Nom = "SPEC_RSRF_Blue_LW";
                        interp_file_Par = "SPEC_grat_wl_R1";
                        grat_blu_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_blu_Nom);
                        grat_red_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_red_Nom);
                        bluWavePar = interpolate(interp_file_Par,"wave",grat_blu_Nom);
                        redWavePar = interpolate(interp_file_Par,"wave",grat_red_Nom);
                    }
                    if(orderSel == "order3") {
                        interp_grat_Nom = "SPEC_RSRF_Blue_SW";
                        interp_file_Par = "SPEC_grat_wl_R1";
                        grat_blu_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_blu_Nom);
                        grat_red_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_red_Nom);
                        bluWavePar = interpolate(interp_file_Par,"wave",grat_blu_Nom);
                        redWavePar = interpolate(interp_file_Par,"wave",grat_red_Nom);
                    }
                    if(orderSel == "order23") {
                        interp_grat_Nom = "SPEC_RSRF_Blue_LW";
                        interp_file_Par = "SPEC_grat_wl_R1";
                        grat_blu_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_blu_Nom);
                        grat_red_Nom = interpolate(interp_grat_Nom,"grat_pos",wave_red_Nom);
                        bluWavePar = interpolate(interp_file_Par,"wave",grat_blu_Nom);
                        redWavePar = interpolate(interp_file_Par,"wave",grat_red_Nom);
                    }
                }
            }
        }
    }

    return {bluWavePar,redWavePar,noParBand};
}

// CVS comments  : $Id: PacsDureeOBCP27.txt,v 1.2 2007/04/25 15:14:04 dcesarsk Exp $ 
// Purpose       : Estimate duration of OBCP27 with input parameters
//
// CUS author    : 
// Script file   : PacsDureeOBCP35.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1  16-Sep-2005 DAC
//  		 : 1.0 11-mar-2009 VD OBCP35
//
int[] procedure PacsDureeOBCP35 {
    int nb_up_down = 1; // Number up/down grating cycles
    int nb_grat_step_up = 43; // Number of grating steps
    int nb_ramps_plateau = 2; // Number of ramps per chopper plateau
    int nb_CS1_CS2 = 0; // Number of chopper cycles CS1<=>CS2
    int nb_SRC_OFF = 1; // Number of chopper cycles SRC<=>REF
    int nb_rdouts_ramp = 64; // Number of rdouts per ramp
}{
    // Call the corresponding DMC sequence
    int[] duree = DMC_19_grat_line_scan(nb_up_down,nb_grat_step_up,nb_ramps_plateau,nb_CS1_CS2,nb_SRC_OFF);
    // Convert number of ramps into seconds
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    // Convert duration [ramps] into [msec]
    // Create return time array; convert into [sec]
    int[] time_array = [0,0,0,0,0];
    for(int aux = 0 .. 4) {
        time_array[aux] = ifloor(double(duree[aux]) * ramp_time);
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    //
    // Return total duration [sec] to calling program

    return time_array;
}

//  $Id:
// Purpose       : To compute RMS vs. WaveLength; to establish min,max RMS
//                 and their associated wavelength. arrayID 
//
// CUS author    : 
// Script file   : PacsSpecMinMaxRMS.txt 
//
// Input arguments
// Return values
// Type          Description
// Description   : 
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 0.1
// History       : 0.1 10-feb-2010 VD creation: PHS-193 Range Spec capa switching
// 
// 
// 
double[] procedure PacsSpecMinMaxRMS {
    double[] wave = [0.0];
    /* Wave reference                                                       */
    double waveRef = 100.0;
    string arrayID = "order2";
}{
    bool verbose = false;
    // Number of wavelengths in array
    int nbWaves = length(wave);
    // Create arrays for rmsNoise
    double[] rmsNoiseC = [0.0];
    double[] rmsNoiseL = [0.0];
    // Integration time related variables
    // 
    double difRMSfactor = sqrt(2.0);
    double scale = difRMSfactor / 1.0;
    // The new frequency switch scheme uses 2 OFF positions to be subtracted
    // from the SRC - shiftedSRC array. This introduces an extra sqrt(1+1/2)
    // difRMSfactor = sqrt(2.0)*sqrt(1.5) = sqrt(3.0)
    // Scaling factor for tabulated rms (good for 1 sec time)
    // Establish which sensitivity table shall be used
    // PHS-198 in parts: waveRef MUST be entered in order 1 parallel bands
    string sensTable = "TBD";
    string sensTablePar = "TBD";
    //    if(arrayID == "order1" || waveRef >= 103.1) {
    if(arrayID == "order1") {
        sensTable = "SPECContLine1";
        sensTablePar = "SPECContLine1";
    }
    if(arrayID == "order2" && waveRef < 102.0) {
        sensTable = "SPECContLine2";
        sensTablePar = "SPECContLine2";
    } else {
        if(arrayID == "order2" && waveRef >= 102.0) {
            sensTable = "SPECContLine2";
            sensTablePar = "SPECContLine1";
        }
    }
    if(arrayID == "order3" && waveRef < 102.0) {
        sensTable = "SPECContLine3";
        sensTablePar = "SPECContLine3";
    } else {
        if(arrayID == "order3" && waveRef >= 102.0) {
            sensTable = "SPECContLine3";
            sensTablePar = "SPECContLine1";
        }
    }
    if(arrayID == "order23" && waveRef < 102.0) {
        sensTable = "SPECContLine23";
        sensTablePar = "SPECContLine23";
    } else {
        if(arrayID == "order23" && waveRef >= 102.0) {
            sensTable = "SPECContLine23";
            sensTablePar = "SPECContLine1";
        }
    }
    if(sensTable == "TBD") {
        error("Internal error: did not find proper sensitivity table");
    }
    // Get rms/sec from SPECcontline, a value per wavelength
    // Create CONT and LINE noise arrays; wave array already exists
    ///   if (verbose) {debug_print("AuxRMS:Wave Interpol From/To]: " 
    ///                          + wave[0] + "/" + wave[nbWaves-1]);}
    for(int loop0 = 0 .. nbWaves - 1) {
        //     Current wavelength
        double waveNow = wave[loop0];
        //     Get CONT and LINE rms values
        //     Use scale factor to convert into observed noise     
        rmsNoiseC[loop0] = scale * interpolate(sensTable,"contRMS",waveNow);
        rmsNoiseL[loop0] = scale * interpolate(sensTable,"lineRMS",waveNow);
    }
    // Find min and max of rmsNoiseC
    int[] minmax = PacsArrayMinMax(rmsNoiseC,verbose);
    double noiseCmin = rmsNoiseC[minmax[0]];
    double waveCmin = wave[minmax[0]];
    double noiseCmax = rmsNoiseC[minmax[1]];
    double waveCmax = wave[minmax[1]];
    // Find min and max of rmsNoiseL
    minmax = PacsArrayMinMax(rmsNoiseL,verbose);
    double noiseLmin = rmsNoiseL[minmax[0]];
    double waveLmin = wave[minmax[0]];
    double noiseLmax = rmsNoiseL[minmax[1]];
    double waveLmax = wave[minmax[1]];
    if(verbose) {
        debug_print("AuxRMS:RMScont min/waveMin: " + noiseCmin + " [Jy] at " + waveCmin);
        debug_print("AuxRMS:RMScont max/waveMax: " + noiseCmax + " [Jy] at " + waveCmax);
        //      debug_print("AuxRMS:rmsLINE min/max: " + noiseLmin + "/" + noiseLmax);
        debug_print("AuxRMS:RMSline min/waveMin: " + noiseLmin + " [Jy] at " + waveLmin);
        debug_print("AuxRMS:RMSline max/waveMax: " + noiseLmax + " [Jy] at " + waveLmax);
    }
    // Copy results to noiseWave and return
    double[] noiseWave = [0.0];
    //   CONTinuum
    noiseWave[0] = waveCmin;
    noiseWave[1] = noiseCmin;
    noiseWave[2] = waveCmax;
    noiseWave[3] = noiseCmax;
    //   LINE
    noiseWave[4] = waveLmin;
    noiseWave[5] = noiseLmin;
    noiseWave[6] = waveLmax;
    noiseWave[7] = noiseLmax;

    return noiseWave;
}

// File          : PACS_Phot_SPU_Reset.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Reset SPU after photometry data flow
//
// Arguments     : none
//                 
//
// Description   : 
//                              
// Comments      :      
//
// Version       : 1.7
// History       : 1.0 / 28-Nov-2003 initial version
//                 1.1 / 16-Feb-2004 Second transmission mode parameter added
//                 1.2 / 20-Apr-2004 Default setting for compression mode: "half"
//                 1.3 / 12-Oct-2006 setting default mode to "0" and update command
//                 1.4 / 27-mar-2007 Adapted for SPU13.1
//                 1.5    4-apr-2007 SCM back to zero 
//                 1.6   10-apr-2007 SCM back to 1
//                 1.7   11-apr-2007 SCM back to 0
//                 1.8   16-jun-2007 SCM back to 1
//                 1.9   24-mar-2009 DAC Updated per SPU UM 13.95a
//
procedure PACS_Phot_SPU_Reset {
}{
    //--------------------
    // Preparation
    //--------------------
    int comp_mode_blue = 0;
    int comp_mode_red = 0;
    int spus_nraw = 3;
    int spul_nraw = 3;
    int spus_startraw = 1;
    int spul_startraw = 1;
    //-----------------------------
    // Stop reduction/compression
    //-----------------------------
    // PC037400 "SPUS_STOP_REDUCT_COMPR" STOP THE APPLICATION PROGRAM IN SPU_SWL
    // tcsend PC037400 
    // waittime 0.5
    Pacs_SPUS_STOP_REDUCT_COMPR();
    delay(1);
    // PC038390 "SPUL_STOP_REDUCT_COMPR" STOP THE APPLICATION PROGRAM IN SPU_LWL
    // tcsend PC038390
    // waittime 0.5
    Pacs_SPUL_STOP_REDUCT_COMPR();
    delay(1);
    //--------------------------------
    // Reset SPU compression/reduction
    //--------------------------------
    // PC175420 "DMC_WRT_SPU_TRAN_MODE" WRITE THE SPU TRASMISSION MODE
    //         Fixed GroupSize: 1, repetition: 2 
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // set tran_mode [list \
    //               [list PP067420 $comp_mode_blue] \
    //               [list PP067420 $comp_mode_red]]
    // set chksum [getChkSum -d -32 $tran_mode]
    // eval tcsend PC175420 $tran_mode \{PP066420 $chksum\}
    // waittime 0.5
    {int}[] list_tuple = [{comp_mode_blue},{comp_mode_red}];
    int[] list_int = [comp_mode_blue,comp_mode_red];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_SPU_TRAN_MODE(list_tuple,chksum);
    delay(1);
    //----------------------------
    // Reset Raw channel selection
    //----------------------------
    // PC035400 "SPUS_RAW_CHAN_TRAN_MODE" RAW CHANNEL TRANSMISSION MODE FOR SPUS
    //         PP050400 "SPUS_OBS_MODE"
    //         PP051400 "SPUS_RCXNB"
    //         PP052400 "SPUS_RCX"
    //if {$spus_nraw != 0} \
    //then {set rawblu [list {PP050400 2} \
    //                  [list PP051400 $spus_nraw] \
    //                  [list PP052400 $spus_startraw]]; \
    //      eval tcsend PC035400 $rawblu; \
    //      eval waittime 0.5 \
    //}
    Pacs_SPUS_RAW_CHAN_TRAN_MODE("PHOT",spus_nraw,spus_startraw);
    delay(1);
    // PC036390 "SPUL_RAW_CHAN_TRAN_MODE" RAW CHANNEL TRANSMISSION MODE FOR SPUL
    //         PP032390 "SPUL_OBS_MODE"
    //         PP033390 "SPUL_RCXNB"
    //         PP034390 "SPUL_RCX"
    //if {$spul_nraw != 0} \
    //then {set rawred [list {PP032390 2} \
    //                  [list PP033390 $spul_nraw] \
    //                  [list PP034390 $spul_startraw]]; \
    //      eval tcsend PC036390 $rawred; \
    //      eval waittime 0.5 \
    //}
    Pacs_SPUL_RAW_CHAN_TRAN_MODE("PHOT",spul_nraw,spul_startraw);
    delay(1);
    //------------------------------------
    // Reset detector constants photometry
    //------------------------------------
    // "Ottensamer" block ("S" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    int ppf = 0;
    // PPP: Pre-Processing Parameter
    int ppp = 0;
    // Threshold for glitch detection in photometry
    int tfp = 1000;
    // Threshold for chopper position deviation in photometry
    int tcp = 100;
    // Glitch detection for photometry (1: no glitch detection)
    int gdfp = 1;
    // Override samples to average
    int navg = 0;
    // resolution reduction parameter 2
    int rnd = 0;
    // resolution reduction parameter 3
    int rnds = 0;
    // resolution reduction parameter 4
    int scm = 1;
    // lossless compression algoithm (0,1,2,3,4)
    int lcal = 4;
    // PACS Codec Order (3,4)
    int pcod = 3;
    // New values 13.95a
    int dpre = 0;
    int dpost = 0;
    int syncdel = 1;
    // Spare elements: 10 spare element; hardcoded as 0,0,... in operand
    // Create operand
    int[] aux = [ppf,ppp,tfp,tcp,gdfp,navg,rnd,rnds,scm,lcal,pcod,dpre,dpost,syncdel,0,0,0,0,0,0,0,0,0,0];
    int check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    {int}[] spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUS_WRT_DET_CST_PHOT(spu_par,check_sum);
    delay(1);
    // "Ottensamer" block ("L" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    ppf = 0;
    // PPP: Pre-Processing Parameter
    ppp = 0;
    // Threshold for glitch detection in photometry
    tfp = 1000;
    // Threshold for chopper position deviation in photometry
    tcp = 100;
    // Glitch detection for photometry (1: no glitch detection)
    gdfp = 1;
    // Override samples to average
    navg = 0;
    // resolution reduction parameter 2
    rnd = 0;
    // resolution reduction parameter 3
    rnds = 0;
    // resolution reduction parameter 4
    scm = 1;
    // lossless compression algoithm (0,1,2,3,4)
    lcal = 4;
    // PACS Codec Order (3,4)
    pcod = 3;
    // New values 13.95a
    dpre = 0;
    dpost = 0;
    syncdel = 1;
    // Spare elements: 10 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfp,tcp,gdfp,navg,rnd,rnds,scm,lcal,pcod,dpre,dpost,syncdel,0,0,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUL_WRT_DET_CST_PHOT(spu_par,check_sum);
    delay(1);
    // End of Procedure
}

// Missionphase  : PACS AVM ILT Orbit-Operations
//
// Purpose       : OBCP 12: Photometry Calibration III, calls DMC sequence 7
//
// OBCP author   : Helmut Feuchtgruber
// CUS script    : Thomas G. Mueller
//
// Arguments:
// Type  Name                  Description
// int   nb_main_loop          p01 number of times main loop is repeated
// int   chop_pos_CS1          p02 Chopper position on CS1
// int   nb_rdouts_plateau     p03 Number of readouts per chopper plateau
// int   nb_CS1_CS2_cycles     p04 Number of chopper cycles per incremental step
// int   chop_step_CS1_CS2     p05 Step size to go from CS1 to CS2
// int   chop_step_CS2_CS1     p06 Step size to go from CS2 to CS1
// int   chop_step_CS1         p07 Step size on CS1
// int   nb_steps              p08 Number of incremental steps
//
// Description   : This script mimics the OBCP_PHOT_CAL_III
//                 pseudo script, section 3.11.3 in PACS-ME-LI-005, Ver.1.0
//                 This CUS version computes the duration of the
//                 observation, as specified by the input parameters.
//                 It will also send the trigger TC to start the OBCP
//
int[] block OBCP_phot_cal_III PACS 12 {
    int nb_main_loop = 2; // p01 number of times main loop is repeated
    int chop_pos_CS1 = -23680; // p02 Chopper position on CS1
    int nb_rdouts_plateau = 39; // p03 Number of readouts per chopper plateau
    int nb_CS1_CS2_cycles = 1; // p04 Number of chopper cycles per incremental step
    int chop_step_CS1_CS2 = 46270; // p05 Step size to go from CS1 to CS2
    int chop_step_CS2_CS1 = -46145; // p06 Step size to go from CS2 to CS1
    int chop_step_CS1 = 125; // p07 Step size on CS1
    int nb_steps = 6; // p08 Number of incremental steps
    int comp_mode_blu = 0; // Compression mode BLUE channel
    int comp_mode_red = 0; // Compression mode RED channel
    int chop_def = 0; // Chopper default position
}{
    // Starting time
    int time_start = time();
    // Anounce start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Bolo sampling rate (needed to compute readout duration)
    double bol_freq = dlookup("PACSparams","bolo_sample","freq_time");
    string bol_unit = slookup("PACSparams","bolo_sample","unit");
    double bol_period = 1000.0 / bol_freq;
    debug_print("Bolo frequency: " + bol_freq + " " + bol_unit);
    debug_print("Bolo period: " + bol_period + "[msec]");
    // Obtain duration of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duration of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duration of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Accumulated duration of this script [msec]
    int duration_msec = 0;
    // OBCP pseudo-code starts here; accumulate duration as it goes)
    // OBCP_PHOT_CAL_III(seq, seq_time, P#1,&, P#8, cmp_par_blue_cmp_par_red, chop_def)
    // Begin
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM)
    //                         ; (all parameters filled by DPU based on seq parameter)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Call CUS version of DECMEC sequence to obtain duration
    // Returns array with [duration_rdouts,duree_SRC,duree_REF,duree_CAL,duree_OVR]
    int[] duree1 = DMC_phot_cal_III(nb_main_loop,nb_rdouts_plateau,nb_CS1_CS2_cycles,nb_steps);
    // Convert duration [readouts] into [msec]; add dmc_margin
    int seq_time = ifloor(double(duree1[0]) * bol_period) + dmc_margin;
    // Convert other times as well into msec
    duree_SRC = ifloor(double(duree1[1]) * bol_period);
    duree_REF = ifloor(double(duree1[2]) * bol_period);
    duree_CAL = ifloor(double(duree1[3]) * bol_period);
    duree_OVR = duree_OVR + ifloor(double(duree1[4]) * bol_period) + dmc_margin;
    // Tally into accumulated duration of OBCP
    duration_msec = duration_msec + seq_time;
    // DMC_SYNCHRONIZE_ON_DET(4)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 1, cmp_par, CHHKSUM)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_START_SEQUENCE
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(seq_time)
    //    ; Check execution status of the sequence and in case of
    //      failure stop OBCP and issue TM(1,8) + event
    // DMC_MOVE_CHOP_ABS(chop_def)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Issue TM(1,7)
    // End
    // Duration: 9 x 200ms + seq_time + 0.5s
    // This procedure calls the sequence described in sec.4.1.7.
    //
    // Now trigger execution of OBCP
    // This OBCP is number 12, requires 13 parameters, call DEC seq #7
    // which lasts seq_time [msec]
    string obcp_ID = "PHOT_CALIB_III";
    int obcp_par_nber = 13;
    int seq_DMC = 7;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_main_loop},{4,chop_pos_CS1},{5,nb_rdouts_plateau},{6,nb_CS1_CS2_cycles},{7,chop_step_CS1_CS2},{8,chop_step_CS2_CS1},{9,chop_step_CS1},{10,nb_steps},{11,comp_mode_blu},{12,comp_mode_red},{13,chop_def}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nber,grp);
    // Add the OBCP "jitter"
    duration_msec = duration_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Return total duration [sec] to calling program
    // Create return time array; convert into [sec]
    int[] time_array = [duration_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // Set delay()
    delay(time_array[0]);
    // Ending time
    int time_elapsed = time() - time_start;
    time_array[0] = time_elapsed;
    // Return

    return time_array;
}

// CVS comments  : $Id: PacsSpecRMS.txt,v 1.30 2007/10/26 15:40:39 dcesarsk Exp $
// Purpose       : 
//
// CUS author    : 
// Script file   : PacsSpecRMS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// tuple bigTuple 
//{{string,double[],double[],double[],double[]},
// {string,double[],double[],double[],double[]},
// {string,double[],double[],double[],double[]}}[]
//
// Each bigTuple's line is of the form "noiseArray"
//  {IDstring, noise array, wave array, CONT noise array, LINE noise array} 
//
// Description   : Computes expected RMS fluctuations given observing
// parameters, described by infoArray. For LineSpec use wave (in infoArray)
// at face value. For RangeSpec create a RMS vs Wave table from waveStart
// to waveEnd, sampled every sampRate [mic] and report max and min RMS in
// the interval. It is assumed that waveXX in infoArray is compatible with
// the wave range of table SPECnoise
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1  2-Sep-2005 DAC
// 0.2 28-sep-2005 Added one more element to infoArray 
// 0.3 26-apr-2006 Use new table from AlPog
//                 Get max/min parameters for CONT and LINE
//                 Array noiseWave contains CONT and LINE information
// 0.4 11-may-2006   - stepSize may be negative; use abs()
// 0.4.1 12-sep-2006 - reduced RMS step size to reduce size of interpolation
//                     table (reduced run time from 8 sec to less than 2 sec)
//                     (SPR-2324)
// 0.5   22-nov-2006 Removed debug_print
// 1.0   22-jan-2007 Fixed SPR-2521 (too low initial rmsC,rmsL)
// 2.0   26-jan-2007 After much discussions, count the WAIT=1 as a
//                   bonafide SKY readout (this is done in PacsLineSpec
//                   and PacsRangeSpec)
//                   Correct handling of FreqSwitch (I hope...)
//                   Dithering count per SPR-2841 (smallSrcDither)
// 2.1   14-feb-2007 Logic to deal with waveRef; added rangesEXT containing
//                   refWave; added aotID
//                   Solved SPR-2838 (use min(6800/stepSize,nbSteps)
//                   Use grating width as per order
//                   Generate messages explaining data obtained in order
//                   other than demanded order
// 2.2 26-feb-2007 Added orderSel from HSPOT
// 2.3 10-mar-2007 OrderSel includes now sed mode
// 3.0 13-mar-2007 Use bigTuple to convey plot data to HSPOT
// 3.1 16-apr-2007 Modify to access the correspondig SPECcontline table
// 4.0 25-apr-2007 Redefine ranges as defined by HSPOT
// 4.1  8-may-2007 SPR-3182: bound "free" data to band limits
// 4.2 10-may-2007 SPR-3186: Raster/wOFF repeat count
// 5.0 30-may-2007 SPR-3251: Simplified "extra" data logic
// 5.1 13-jun-2007 SPR-3307 Fewer decimals for "Info for line"
// 6.0 21-aug-2007 SPR-3505 Out-of-range interpolation (more on extra data
//                          logic)
// 6.1 23-oct-2007 Added obsType in call to PacsSpecAuxRMS 
// 6.2 24-oct-2007 Get nbOBS and nbOFF from caller
//                 Added above to PacsSpecAuxRMS
// 6.3  4-jun-2009 DAC Adapted FreqSwitch message to ABBA case
// 6.3.1 5-jun-2009 DAC Finer tuning due to changed confOBCP contents
// 7.0 01-dec-2009 VD SCR PHS-1272
// 8.0 07-dec-2009 VD PHS-1282
// 
{{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] procedure PacsSpecRMS {
    /* aotID                                                                  */
    string aotID = "RANGE" in ["RANGE","LINE"];
    /* orderSel                                                               */
    string orderSel = "order2";
    /* infoArray tuple (for SLEW,OBS,AOT and per wavelength)                  */
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}]; // Tuple from Obs module
    /* rangeSPOT (the sorted version)                                         */
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [{"",0.0,0.0,0,0.0,0.0,0.0,"","",0.0}];
    /* confOBCP (per wavelength)                                              */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* nbOBS and nbOFF                                                         */
    int nbOBS = 1;
    int nbOFF = 0;
    bool verbose = false;
}{
    // Data used here is to be found in
    // infoArray[1]{0}{0}   : PointReq information (ex. SmSrcDither, RasterOFF)
    // infoArray[1]{0}{3}   : Number of lines to be observed
    // infoArray[1]{0}{1}   : Integration time per plateau
    // infoArray[1]{0}{4}   : Number of nod cycles
    // infoArray[1]{1}[]{0} : Starting wave for line []
    // infoArray[1]{1}[]{1} : Ending wave for line []
    // infoArray[1]{1}[]{2} : Grating order for line []
    // infoArray[1]{1}[]{3} : Grating step for line []
    // infoArray[1]{1}[]{4} : Number of grating steps for line []
    // infoArray[2]{0}{0}   : OBCP information (ex. FreqSwitch)
    // infoArray[2]{0}{3}   : Raster "m" size
    // infoArray[2]{0}{4}   : Raster "n" size
    // infoArray[2]{0}{5}   : Raster repeat factor in raster/wOFF
    // confOBCP[]{0}        : Number up/down, nb SRC/CS in FreqSwitch for line []
    // confOBCP[]{3}        : Number SRC/REF for line []
    // confOBCP[]{4}        : Number readouts-ramps/plateau for line []
    // confOBCP[]{7}        : Dither count (FreqSwitch) for line []
    // Define return array
    // Array noiseWave[nbLines][8] used to contain: 
    //    noiseWave[lineNb][BwlC,BrC,WwlC,WrC,BwlL,BrL,WwlL,WrL]
    // where B: best, W: worst, wl: wavelength, r: RMS, C: continuum, L: line
    // Will add three more elements refWave, rmsCont, rmsLine (RANGE)
    // NOTE: NoiseWave is no longer used; its content is now in 1st
    //       array of tuple noiseArrayx 
    // Define tuples to be used below
    // Each noiseArray contains
    // - string arrayID
    // - double[] "noiseWave" (the "historical" noiseWave)
    // - double[] wave array
    // - double[] CONT noise
    // - double[] LINE noise
    {string,double[],double[],double[],double[]} noiseArray0 = {"undefined",[0.0],[0.0],[0.0],[0.0]};
    {string,double[],double[],double[],double[]} noiseArray1 = {"undefined",[0.0],[0.0],[0.0],[0.0]};
    {string,double[],double[],double[],double[]} noiseArray2 = {"undefined",[0.0],[0.0],[0.0],[0.0]};
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = [{noiseArray0,noiseArray1,noiseArray2}];
    // Number of lines observed
    int nbLines = infoArray[1]{0}{3};
    // The logic to estimate the data one gets for free (there are two arrays)
    // needs to know whether the current observations are performed with filter
    // "POS A" or "POS B" (fltPos=3 or fltPos=2). Only HSPOT knows this...
    int fltPos = 0;
    if(orderSel == "order2" || orderSel == "sed2" || orderSel == "sedb2b") {
        fltPos = 2;
    }
    if(orderSel == "order3" || orderSel == "sed3" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        fltPos = 3;
    }
    ///////////////// Per line loop //////////////////////////////
    for(int loop0 = 0 .. nbLines - 1) {
        //   Just for checks during script development
        if(verbose) {
            debug_print("RMS:PointReq: " + infoArray[1]{0}{0});
            debug_print("RMS:OBCP    : " + infoArray[2]{0}{0});
            debug_print("RMS:Wave from:to " + infoArray[1]{1}[loop0]{0} + ":" + infoArray[1]{1}[loop0]{1} + " [mic]");
            debug_print("RMS:Grat Order/StepSize/NbSteps " + infoArray[1]{1}[loop0]{2} + "/" + infoArray[1]{1}[loop0]{3} + "/" + infoArray[1]{1}[loop0]{4});
        }
        // Next section deals with estimating the "on-sky" time per resolution element
        // and per (same) sky area
        // Spectral lines can be seen several times as they move across the 
        // "wavelength" pixels
        // How many times a line feature has been seen
        // Get actual grating width (i.e. nbSteps = 16 pixels)
        string key = "" + infoArray[1]{1}[loop0]{2};
        double gratWidth = double(ilookup("SPEC_BAND_params",key,"GRAT_WDTH"));
        if(verbose) {
            debug_print("RMS:GratWdth: " + gratWidth + " steps");
        }
        // In FreqSwitch mode the parameters are somehow different 
        // Useful variable for freqSwitch
        bool freqSwitch = false;
        bool stare = false;
        if(infoArray[2]{0}{0} == "FreqSwitch") {
            freqSwitch = true;
        }
        if(infoArray[2]{0}{0} == "Stare") {
            stare = true;
        }
        //      howMany is the number of times the given wavelength is seen by other pixels other
        if(freqSwitch || stare) {
            double howMany = 1.0;
        } else {
            //          Case of step size=0 (PV single grating AOT)
            howMany = gratWidth / (0.01 + abs(double(infoArray[1]{1}[loop0]{3})));
            //          SPR-2838: howMany cannot be larger than the number of grating steps
            if(howMany > double(infoArray[1]{1}[loop0]{4})) {
                howMany = double(infoArray[1]{1}[loop0]{4});
                if(verbose) {
                    debug_print("RMS:Reduced howMany to NbSteps");
                }
            }
        }
        // Integration time not considering spatial redundancy - i.e. seeing again the source during
        // a scan - nor wavelength redundancy - i.e. the same wavelength seen by other pixels at any grating
        // position) 
        //      intTimePlateau x NbSrcRef x howMany x nbNods x 2*up_dn x dithCount x Nbrepeat
        //      Number of nods (OBS)
        int nbNodCycles = infoArray[1]{0}{4};
        //      Nb of "pointings" for nbNodCycles
        int nbNods = 2 * nbNodCycles;
        if(nbNods == 0) {
            nbNods = 1;
        }
        int nbUpDn = 2 * confOBCP[loop0 + 1]{0};
        //      In FreqSwtch, below counts the number of SRC-CS cycles  
        int nbSRC_REF = confOBCP[loop0 + 1]{3};
        //      dithCntFreqSwtch introduced for FreqSwitch, otherwise is unity
        int dithCntFreqSwtch = 1;
        //      dithCntSmSrc introduced for small source w/dithering, otherwise is unity
        int dithCntSmSrc = 1;
        if(infoArray[1]{0}{0} == "SmSrcDither") {
            //          The source is seen at each of the m X n raster points
            int m = infoArray[2]{0}{3};
            int n = infoArray[2]{0}{4};
            dithCntSmSrc = m * n;
        }
        //      In FreqSwitch mode the parameters are somehow different 
        if(freqSwitch || stare) {
            //          confOBCP{0} counts the number of Up/Dn ABBA-ABBA cycles (P1UpDn)
            nbUpDn = confOBCP[loop0 + 1]{0};
            //          confOBCP{2} counts the number of ABBA setings (P4ABBA)
            int nbABBA = confOBCP[loop0 + 1]{2};
            //          The line is always in sight (Line Ref Ref Line) since Ref is Line displaced
            //          by a few pixels. Hence line is seen 4 times (see singleIntTime below)
            //          The ABBA loop is repeated dithCntFreqSwtch times
            dithCntFreqSwtch = confOBCP[loop0 + 1]{7};
        }
        //      If Raster/w OFF, take into account the number of repetions
        int nbRepeat = 1;
        if(infoArray[1]{0}{0} == "RasterOFF") {
            nbRepeat = infoArray[2]{0}{5};
        }
        //      infoArray[1]{0}{1} is the integration time per plateau
        double singleIntTime = double(nbSRC_REF * nbNods * nbUpDn * nbRepeat) * infoArray[1]{0}{1};
        //      Special case of ScanChopNoNod
        if(infoArray[1]{0}{0} == "ScanChopNoNod") {
            singleIntTime = infoArray[1]{0}{1};
        }
        //      Another special case
        if(freqSwitch || stare) {
            singleIntTime = double(2 * nbUpDn * dithCntFreqSwtch * nbABBA * 4) * infoArray[1]{0}{1};
        }
        double intTime = double(dithCntSmSrc) * howMany * singleIntTime;
        // Another exception for scan mode
        if(infoArray[1]{0}{0} == "ScanChopNoNod") {
            intTime = infoArray[1]{0}{1};
        }
        //   Wavelength span (needed below, but useful here for message)
        double span = abs(infoArray[1]{1}[loop0]{0} - infoArray[1]{1}[loop0]{1});
        //   Logic to show "extra" data, i.e. at different order than demanded
        //   - If observing in order=1 (with 2), the user gets for free order=2 data 
        //   - If observing in order=1 (with 3), the user gets for free some order=3 
        //     data if lambda>167 microns AND the short  wavelength part of order=2 
        //     (which falls inside POS B bandpass) if lambda < 142. For lambda 
        //     167 < lambda < 142, there is no "free" data
        //   - If observing at order=2 or order=3, user gets for free order=1
        //
        //   Try to code all this.. Current logic is as follows:
        //   For each Order/Filter combination see if the expected extra data is
        //   entirely out of filter bandpass. If yes, then there is no extra data; else
        //   place extra data within filter bandpass
        //   Current line is being observed at order
        int currOrder = infoArray[1]{1}[loop0]{2};
        //   Code currOrder as orderN
        string orderCurr = "order" + currOrder;
        // "sed4" is a special case
        if(orderSel == "sed4") {
            orderCurr = "order23";
        }
        //   Nominal and extra data will be labeled with arrayID
        string arrayID = "ToBeFilledBelow";
        //   Order 1 needs no filter... so we always see data in order 1. What other
        //   order do we see (where is filter?)
        //
        //   Useful variables: low and high user defined range
        double loLam = infoArray[1]{1}[loop0]{0};
        double hiLam = infoArray[1]{1}[loop0]{1};
        // Get boundaries of filters
        double loLam1 = dlookup("SPEC_BAND_params","1","BLU");
        double hiLam1 = dlookup("SPEC_BAND_params","1","RED");
        double loLam2 = dlookup("SPEC_BAND_params","2","BLU");
        double hiLam2 = dlookup("SPEC_BAND_params","2","RED");
        double loLam23 = dlookup("SPEC_BAND_params","23","BLU");
        double hiLam23 = dlookup("SPEC_BAND_params","23","RED");
        double loLam3 = dlookup("SPEC_BAND_params","3","BLU");
        double hiLam3 = dlookup("SPEC_BAND_params","3","RED");
        // SPR-3251 Completely new logic
        //
        // Define "cross over" wavelengths, i.e. wavelength in order1 such that 2nd 
        // order falls outside filter B into filter A
        double wave1into2 = 2.0 * loLam2;
        // and 1st order grating position corresponds to in-band 3rd order
        double wave1into3 = 3.0 * loLam3;
        // Following logic creates "extra" data, i.e. data user gets for "free"
        // Data labeled xSomething is regular order seen with tje corresponding
        // filter (i.e. 2nd with filter B; 3rd with filter A)
        // Data labeled xxSomething is short wavelength 2nd order seen with 3rd
        // order filter; the so called "extended" emission 
        // Null arrays imply there is no "free" data
        double xWaveLO = 0.0;
        double xWaveHI = 0.0;
        double xxWaveLO = 0.0;
        double xxWaveHI = 0.0;
        // Order 1 scanning is the most complex since the "free" data depends on filter
        // position
        if(currOrder == 1) {
            // Filter at POS B
            if(fltPos == 2) {
                arrayID = "order2";
                // When filter is at order 2 (POS B), all order=1 grating steps
                // map to visible order=2 wavelengths, except 
                //  - hiLam shorter than wave1into2 (range is too "blue")
                //  - loLam greater than 2*hiLam2   (range is too "red")
                if(hiLam <= wave1into2 || loLam >= 2.0 * hiLam2) {
                    //               Whole band is outside filter B
                    xWaveLO = 0.0;
                    xWaveHI = 0.0;
                } else {
                    arrayID = "order2";
                    //               A priori we see 1/2 wavelength
                    xWaveLO = loLam / 2.0;
                    xWaveHI = hiLam / 2.0;
                    //               But within bandpass limits
                    if(xWaveHI > hiLam2) {
                        xWaveHI = hiLam2;
                    }
                    if(xWaveLO < loLam2) {
                        xWaveLO = loLam2;
                    }
                }
            }
            // Filter at POS A
            //       This is the most complex case since we may also see order 2 light
            if(fltPos == 3) {
                arrayID = "order3";
                // Short wave filter (order 3, POS A), some order=1 grating steps
                // map to "visible" order=2 wavelengths, except 
                // - hiLam shorter than 2*loLam23 (range is too "blue")
                // - loLam greater than 2*hiLam23 (range is too "red")
                if(hiLam <= 2.0 * loLam23 || loLam >= 2.0 * hiLam23) {
                    // Whole band is outside filter A bandpass
                    xxWaveLO = 0.0;
                    xxWaveHI = 0.0;
                } else {
                    // Short wave second order
                    xxWaveLO = loLam / 2.0;
                    xxWaveHI = hiLam / 2.0;
                    // But within "extended" bandpass limits 
                    // SPR-3505: corrected band boundaries:xxLam3 should be xxLam23
                    if(xxWaveHI > hiLam23) {
                        xxWaveHI = hiLam23;
                    }
                    if(xxWaveLO < loLam23) {
                        xxWaveLO = loLam23;
                    }
                }
                // Some order=1 grating steps map to "visible" order=3 wavelengths, except 
                // - hiLam shorter than wave1into3 (range is too "blue")
                // - loLam greater than 3*hiLam3   (range is too "red")
                if(hiLam <= 3.0 * loLam3 || loLam >= 3.0 * hiLam3) {
                    // Whole band is outside filter A
                    xWaveLO = 0.0;
                    xWaveHI = 0.0;
                } else {
                    // Short wave 3rd order
                    xWaveLO = loLam / 3.0;
                    xWaveHI = hiLam / 3.0;
                    // But within bandpass limits
                    if(xWaveHI > hiLam3) {
                        xWaveHI = hiLam3;
                    }
                    if(xWaveLO < loLam3) {
                        xWaveLO = loLam3;
                    }
                }
            }
        }
        //   When grating scans within order 2 and 3 ranges, all steps map to visible
        //   lines at order 1
        //   If we are in order=2 we see order=1 for free
        string xRan = "";
        if(currOrder == 2) {
            arrayID = "order1";
            debug_print(" 2 where am I here?");
            if(orderSel == "sedb2b") {
                debug_print("2 I should be HERE");
                xRan = "b2bLR1";
                xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
            } else {
                if(orderSel == "sedb2a") {
                    xRan = "b2aSR1";
                    xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                    xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                } else {
                    if(orderSel == "sedb3a") {
                        xRan = "b3aLR1";
                        xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                        xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                    } else {
                        xWaveLO = 2.0 * loLam;
                        xWaveHI = 2.0 * hiLam;
                    }
                }
            }
            //      It may fall completely outside bandpass	
            if(xWaveLO >= hiLam1) {
                xWaveLO = 0.0;
                xWaveHI = 0.0;
            } else {
                //          Within filter boundaries
                if(xWaveHI > hiLam1) {
                    xWaveHI = hiLam1;
                }
                if(xWaveLO < loLam1) {
                    xWaveLO = loLam1;
                }
            }
        }
        //   If we are in order=3 we alse see order=1 for free
        if(currOrder == 3) {
            arrayID = "order1";
            debug_print(" 3 where am I here?");
            if(orderSel == "sedb2b") {
                xRan = "b2bLR1";
                xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
            } else {
                if(orderSel == "sedb2a") {
                    xRan = "b2aSR1";
                    xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                    xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                } else {
                    if(orderSel == "sedb3a") {
                        xRan = "b3aLR1";
                        xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                        xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                    } else {
                        debug_print("3 or bloody there");
                        xWaveLO = 3.0 * loLam;
                        xWaveHI = 3.0 * hiLam;
                    }
                }
            }
            //      It may fall completely outside bandpass	
            if(xWaveLO >= hiLam1) {
                xWaveLO = 0.0;
                xWaveHI = 0.0;
            } else {
                //          Within filter boundaries
                if(xWaveHI > hiLam1) {
                    xWaveHI = hiLam1;
                }
                if(xWaveLO < loLam1) {
                    xWaveLO = loLam1;
                }
            }
        }
        if(verbose) {
            debug_print("RMS:current order: " + currOrder);
            debug_print("RMS:fltPos: " + fltPos);
            debug_print("RMS:LoLam: " + loLam);
            debug_print("RMS:HiLam: " + hiLam);
            debug_print("RMS:ExtraLoLam: " + xWaveLO);
            debug_print("RMS:ExtraHiLam: " + xWaveHI);
            debug_print("RMS:ExxtraLoLam: " + xxWaveLO);
            debug_print("RMS:ExxtraHiLam: " + xxWaveHI);
            debug_print("RMS:Integration/plateau: " + infoArray[1]{0}{1} + " [sec]");
            debug_print("RMS:NbSRC_REF: " + nbSRC_REF + " times");
            debug_print("RMS:ditherCount (freqSwitch): " + dithCntFreqSwtch + " times");
            debug_print("RMS:ditherCount (small srce): " + dithCntSmSrc + " times");
            debug_print("RMS:NbUpDn/NbNods: " + nbUpDn + "/" + nbNods);
            debug_print("RMS:NbRepeat: " + nbRepeat);
            debug_print("RMS:intTime (one freq. switch, no dither) " + singleIntTime + " [sec]");
            debug_print("RMS:Wavelength span: " + dformat(span,2) + " [mic]");
            debug_print("RMS:Feature seen  " + howMany + " times");
            debug_print("RMS:Time for RMS estimate: " + intTime + " [sec]");
            debug_print("RMS:SRC/REF " + infoArray[1]{1}[loop0]{6} + "/" + infoArray[1]{1}[loop0]{7} + " [sec]");
        }
        bool superbla = true;
        if(superbla) {
            if(aotID == "RANGE") {
                message("<h3> Info for range " + infoArray[1]{1}[loop0]{0} + "/" + infoArray[1]{1}[loop0]{1} + " [&micro;m]</h3>");
            } else {
                message("<h3> Info for line " + dformat(infoArray[1]{1}[loop0]{0},2) + " [&micro;m]</h3>");
            }
            message("<ul><li>PointReq: " + infoArray[1]{0}{0} + "</li>");
            message("<li>OBCP    : " + infoArray[2]{0}{0} + "</li>");
            //      Next messages only for RANGE
            if(aotID == "RANGE") {
                message("<li>Wave from-to " + infoArray[1]{1}[loop0]{0} + "-" + infoArray[1]{1}[loop0]{1} + " [&micro;m]</li>");
                //         message("<li>Wavelength span: " + dformat(span,2) + " [&micro;m]</li>");
                //         Messages for "free" data
                if(xWaveLO != 0.0) {
                    message("<li><b>Free! </b> Your data will include wavelengths between " + dformat(xWaveLO,2) + " and " + dformat(xWaveHI,2));
                }
                if(xxWaveLO != 0.0) {
                    message("<li><b>Free! </b> Your data will include wavelengths between " + dformat(xxWaveLO,2) + " and " + dformat(xxWaveHI,2));
                }
            }
            if(freqSwitch) {
                message("<li>ABBA freqSwitch at grating order: " + infoArray[1]{1}[loop0]{2} + "</li>");
                message("<li>FreqSwitch dither: " + dithCntFreqSwtch + " wavelength steps</li>");
            } else {
                message("<li>Grat Order/StepSize/NbSteps " + infoArray[1]{1}[loop0]{2} + "/" + infoArray[1]{1}[loop0]{3} + "/" + infoArray[1]{1}[loop0]{4} + "</li>");
                message("<li>NbSRC_REF: " + nbSRC_REF + " times</li>");
                message("<li>Spatial redundancy only for SmallSrc: " + dithCntSmSrc + " time(s)</li>");
            }
            message("<li>Number ramps/plateau (after synch): " + confOBCP[loop0 + 1]{4} + "</li>");
            message("<li>Integration time/plateau: " + dformat(infoArray[1]{0}{1},2) + " [sec]</li>");
            if(freqSwitch) {
                message("<li>Up/Dn ABBA loops/ABBA sets per loop: " + nbUpDn + "/" + nbABBA + "</li>");
            } else {
                message("<li>NbUpDn/NbNods/NbRepeat: " + nbUpDn + "/" + nbNods + "/" + nbRepeat + "</li>");
            }
            message("<li>Integration time per spectral and/or spatial resolution element::  " + dformat(singleIntTime,1) + " [sec]</li>");
            message("<li>Feature seen " + dformat(howMany,1) + " times (due to spatial or wavelength redundancy)</li>");
            message("<li>Integration time used to estimate RMS: " + dformat(intTime,1) + " [sec]</li>");
            message("<li>Global SRC/REF exposure: " + infoArray[1]{1}[loop0]{6} + "/" + infoArray[1]{1}[loop0]{7} + " [sec]</li></ul>");
        }
        //
        // We have now up to three wavelength ranges:
        // - nominal (user defined)        [loLam to hiLam]
        // - one "free" data array         [xWaveLO to xWaveHI]
        // - perhaps a 3rd "free" array    [xxWaveLO to xxWaveHI]
        //
        //   The reference wavelength
        if(aotID == "RANGE") {
            double waveRef = rangeSPOT[loop0]{9};
        }
        if(aotID == "LINE") {
            waveRef = infoArray[1]{1}[loop0]{0};
        }
        //   Create a table RMS vs Wave consisting of nbSamples entries
        //
        //   Create Wave arrays (remember we are inside the nbLines loop!!)
        //   Obs type for AuxRMS
        string obsType = "any";
        if(aotID == "RANGE") {
            // attention function of waveRef
            if(orderSel == "sedb2b" || orderSel == "sedb2a" || orderSel == "sedb3a") {
                if(waveRef >= 103.1) {
                    double[] waveArray = PacsSpecWaveArray(xWaveLO,xWaveHI,verbose);
                } else {
                    waveArray = PacsSpecWaveArray(loLam,hiLam,verbose);
                }
            } else {
                waveArray = PacsSpecWaveArray(loLam,hiLam,verbose);
            }
            //        Given wavelengths are always "nominal"
            noiseArray0 = PacsSpecAuxRMS(aotID,orderCurr,waveArray,waveRef,intTime,obsType,nbOBS,nbOFF,verbose);
            //      Null Wave arrays have xWaveLO = 0.0
            if(xWaveLO > 10.0) {
                waveArray = PacsSpecWaveArray(xWaveLO,xWaveHI,verbose);
                ///        if (verbose){debug_print("RMS:xWaveArray: " + waveArray);}
                //        xWave array comes from arrayID source; define waveRefX
                double waveRefX = (xWaveLO + xWaveHI) / 2.0;
                noiseArray1 = PacsSpecAuxRMS(aotID,arrayID,waveArray,waveRefX,intTime,obsType,nbOBS,nbOFF,verbose);
            }
            //      Null Wave arrays have xxWaveLO = 0.0
            if(xxWaveLO > 10.0) {
                //        xxWave array is always 2nd order, but special since it
                //        overlaps with 3rd order. Identify as order23 (order 2 overlapping
                //        with order 3)
                waveArray = PacsSpecWaveArray(xxWaveLO,xxWaveHI,verbose);
                ///          if (verbose){debug_print("RMS:xxWaveArray: " + waveArray);}
                waveRefX = (xxWaveLO + xxWaveHI) / 2.0;
                noiseArray2 = PacsSpecAuxRMS(aotID,"order23",waveArray,waveRefX,intTime,obsType,nbOBS,nbOFF,verbose);
            }
        }
        if(aotID == "LINE") {
            waveArray = [infoArray[1]{1}[loop0]{0}];
            //      Identify FreqSwitch
            obsType = infoArray[2]{0}{0};
            noiseArray0 = PacsSpecAuxRMS(aotID,orderCurr,waveArray,waveRef,intTime,obsType,nbOBS,nbOFF,verbose);
        }
        // For memory: bigTuple is thus defined
        //  {{string,double[],double[],double[],double[]},
        //   {string,double[],double[],double[],double[]},
        //   {string,double[],double[],double[],double[]}}[]
        //   bigTuple = [{noiseArray0, noiseArray1,noiseArray2}];
        bigTuple[loop0] = {noiseArray0,noiseArray1,noiseArray2};
        // End of nbLines loop
        //   Zero the noiseArrays (a null value is used elsewhere to assert there
        //   are no "free" ranges)
        noiseArray0 = {"",[0.0],[0.0],[0.0],[0.0]};
        noiseArray1 = {"",[0.0],[0.0],[0.0],[0.0]};
        noiseArray2 = {"",[0.0],[0.0],[0.0],[0.0]};
    }

    return bigTuple;
}

// Missionphase  : 
//
// Purpose       : 
//                  
//                 
//
// OBCP author   : HF
// TCL file      : N/A
// CUS author    : VD (based on DAC)
// Script file   : OBCP_grat_line_scan_chopped_3.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Belongs to Section 3.7: Grating Spectral Line Scan 
//                 of PACS-ME-LI-005
//                 Consists mainly of a sequence with repetitive up- and
//                 down-scans with the grating around a given center position,
//                 while the chopper is operating on ABBA pattern: section
//		   3.7.6 (ABBA chopping OBCP 35, DMC 19)
//
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : This is a COPY of OBCP_grat_line_scan_chop_3. 
//                 The goal is to dispose of a copy of the standard ABBA 
//                 chopping OBCP 35, to be used to perform the calibration
//                 block in the AOTs using the ABBA chopping scheme
//		   with another building block number
// 
// History       : 1 02-Apr-2009 PR COPY of OBCP_grat_line_scan_chop_3
// 		   1.1 24-jun-2009 VD/DAC implement ABBA on CSs
//		       		   DAC Added logic to perform the CAL
//                                 using the science loop, i.e. the ABBA
//                                 We recognize that a CAL is intended when
//                                 nb_CS1_CS2 is different from zero.
//
//
int[] block OBCP_grat_line_scan_chop_3_cal PACS 350 {
    int nb_up_down = 1; // Nb of "up-down" sequences (P#1); 
    int nb_grat_steps = 16; // Nb of grating steps (P#2)
    int grat_step_up = 168; // Grating step up (P#3) 
    int nb_ABBA_sci = 2; // Nb of on-sky (fake) cycles per grating position (P#4); 
    int chop_pos_REF1 = -1000; // Chopper position 1 SRC (P#5) 
    int nb_ramps_plateau = 3; // Nb of readouts per chopper position (P#6); 
    int chop_pos_REF2 = 2000; // Chopper position 2 REF (P#7)
    int nb_CS1_CS2 = 1; // Nb of cycles on the internal CSs (P#8); 
    int chop_pos_CS1 = -21350; // Chopper position on CS1 (P#9)
    int chop_pos_CS2 = 21200; // Chopper position on CS2 (P#10)
    int grat_step_dn = -168; // Grating step down (P#11) 
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 445000; // Starting grating position
    int grat_time = 40000; // Grating time to move to start [msec]
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopper default position
    int grat_def_time = 20000; // Time to come back to default position
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Logic to perform CAL using the science part of the OBCP
    // It is  CAL
    //      debug_print ("========= OBCP35 called for CAL");
    //    Set nb_ABBA_sci equal to nb_CS1_CS2; set nb_CS1_CS2 to zero
    nb_ABBA_sci = nb_CS1_CS2;
    nb_CS1_CS2 = 0;
    //    Set chop_REF1 and chop_REF2 equal to chop_CS1 and chop_CS2
    chop_pos_REF1 = chop_pos_CS1;
    chop_pos_REF2 = chop_pos_CS2;
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duree_msec [msec] as it goes)
    // Begin 
    // OBCP_GRATING_LINE_SCAN_CHOPPED_3(seq, seq_time,
    //   P#1,&,P#11, detector, grat_def, grat_time,
    //   cmp_par_blue, cmp_par_red, grat_def, chop_def, grat_time)
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(P#5)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) ; (all parameters filled 
    // by DPU based on seq parameter) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_time) 
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    // DMC_START_SEQUENCE
    //////////////////////////////////////////////////////////////////////////
    // Call DC/MEC code to estimate its duration
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    int[] duree1 = DMC_19_grat_line_scan(nb_up_down,nb_grat_steps,nb_ramps_plateau,nb_CS1_CS2,nb_ABBA_sci);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    debug_print("Execution time [msec] from DMC: " + seq_time);
    // duree_msec(seq_time) 
    duree_msec = duree_msec + t_cmd + seq_time;
    // WAIT(seq_time) ; Check execution status of the sequence and in case of 
    // failure stop OBCP and issue TM(1,8)+event 
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_def_time) 
    duree_msec = duree_msec + grat_def_time;
    duree_OVR = duree_OVR + grat_def_time;
    // Issue TM(1,7)
    // End 
    // Now trigger execution of OBCP
    // This OBCP is number 35, requires 21 parameters and calls DEC/MEC #19
    //    string obcp_ID = "GRAT_SCAN_CHOP3";
    int obcp_ID = 35;
    int obcp_par_nb = 21;
    int seq_DMC = 19;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_grat_steps},{5,grat_step_up},{6,nb_ABBA_sci},{7,chop_pos_REF1},{8,nb_ramps_plateau},{9,chop_pos_REF2},{10,nb_CS1_CS2},{11,chop_pos_CS1},{12,chop_pos_CS2},{13,grat_step_dn},{14,detector},{15,grat_pos},{16,grat_time},{17,comp_mode_blu},{18,comp_mode_red},{19,grat_def},{20,chop_def},{21,grat_def_time}];
    //     Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp); Mnemonic not impl. use RAW
    Pacs_DPU_START_OBCP_RAW(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    //    debug_print(obcp_ID + ": " + time_array);
    delay(time_array[0]);
    // Return the array of times

    return time_array;
}

// $Id: PacsEng_Spec_cre_setup.txt,v 1.6 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : PACS PV Phase
//
// CVS file      : SPEC_CRE_setup_OBS.cus
//
//
//
// Purpose       : TOPE schedule SPEC_cre_setup
//                  
// Author        : DAC
//
// Arguments     : 
// Type     Name          DefVal   Description
// int      ramp_len_red     64    Red ramps' length
// int      ramp_len_blu     64    Blue ramps' lengthl
// double   bias_d_red    0.070    BIAS_D for red spectrometer (1V=4095)
// double   bias_r_red    0.010    BIAS_R for red spectrometer (1V=4095)
// double   bias_d_blu    0.210    BIAS_D for blue spectrometer (1V=4095)
// double   bias_r_blu    0.010    BIAS_R for blue spectrometer (1V=4095)
// int      capa_red         12    Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
// int      capa_blu         12    Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
//
// Version       : 1.1
// History       : 0.1 17-nov-2006 DAC
// History       : 1.0 04-mar-2008  Converted into PV script by VDP
//                 1.1 15-Apr-2008  changed blue_heat_current from 1.5 
//                                  to 0.78 mAmp (HF)
//
//
obs PacsEng_Spec_cre_setup_l {
    /* Needed variables to call PacsEng_Spec_cre_setup_l                        */
    int ramp_len_red = 64; // Red  ramp length
    int ramp_len_blu = 64; // Blue ramp length
    double bias_d_red = 0.0701 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_red = 0.0101 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.2101 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_r_blu = 0.0101 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    int capa_red = 12; // Capacitor red  (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_blu = 12; // Capacitor blue (0=100fF,4=400fF,8=0.2pf,12=1pF)
    double blue_heat_current = 0.7801 in [0.0,10.001]; // Current [mAmp]
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_cre_setup_l                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_CRE_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,blue_heat_current)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_CRE_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,blue_heat_current);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Purpose        : Bring PACS from switched off condition to standby
//                  for SPEC observations, however with short set-up
//		    time for CSs.
//
// CUS author     : Composed from various ILT modules
//
// Input arguments: see after module identification
//
// Return values
// N/A
//
// Comments      :
//
// History: 
// 1.0  12-nov-2008  Helmut Dannerbauer did this script based on 
//		     PacsEng_SPEC_orbit_prologue only having a
//		     shorter CS set-up time.
// 1.1 12-nov-2008 VD : need make variable consistent for setting CS1: given in Ohms not Kelvin
//		      see PHOT procs
obs PacsEng_SPEC_orbit_prologue_short {
}{
    // Settling time for CS 
    int tSET = 900;
    string fltPOS = "POS A";
    double set_CS1 = 48.0;
    double set_CS2 = 58.0;
    double blu_heater_curr = 0.78;
    // Get duration 
    int tp = duration(SPEC_setup(fltPOS,set_CS1,set_CS2,blu_heater_curr));
    tp = tp + tSET;
    bool execute = true;
    // Add needed time to set/unset OBSID
    int tset = duration(WriteOBSID($OBSID));
    int tunset = duration(WriteEndID());
    int tih = tset;
    int tfh = tunset;
    // Issue PointReq       
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //     Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //     Call the SPEC setup script
            SPEC_setup(fltPOS,set_CS1,set_CS2,blu_heater_curr);
            //     Wait for CS to stabilize
            delay(tSET);
            if(state[0] == 5) {
                //     Reset OBSID and BBID
                data_rate(0.0);
                WriteEndID();
            }
        }
    }
}

// CVS comments  : $Id: 
// Purpose       : Invoke a PACS calibration OBCP during slew to source
// 		   using ABBA chopper scheme;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsSpecSlewCal.txt 
//
// Input arguments
// Type                     Name          Description
// bool                     verbose       Debug_print or not 
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECblu   BLUE SPU parameters
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECred   RED  SPU parameters
// {int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int}[]  confOBCP      OBCP parameters
//  bool                    doPROLOG      Perform/don't AOT prologue
//  double []               keyWAVE       One or several key wavelengths
//  int                     filter        Where to move FltW (as order)
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per key line
//
// Description   : Perform AOT prologue and then OBCP #35.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 0.1 DAC 10-may-2006 
// 		 : 1.0 13-mar-2009 VD OBCP35
//                 1.1  3-jun-2009 DAC Original PacsPacsSpecSlewCal35 from
//                                 VD renamed PacsSpecSlewCal
//                 1.2 18-jun-2009 DAC Enter into OBCP35params with K-orders
//                                 to schedule KeyWave calibrations
//                 1.3 20-jul-2009 VD introduces the faintLines (extraConf == bright for calU CAL block                
//                                 
//
int[][] procedure PacsSpecSlewCal {
    /* verbose debug print                          */
    bool verbose = false;
    /* SPEC parameters for BLU and RED              */
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,64,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,64,0,0,0,0,0,0,0}];
    /* OBCP parameters                               */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* Perform/don't AOT prologue                    */
    bool doPROLOG = true;
    /* One or several key wavelengths                */
    double[] keyWAVE = [62.5];
    /* Where to leave FltW (as order)                */
    int filter = 2;
    /* Where to leave grating at end of CAL          */
    int frstLstGratPos = 535000;
    /* User defined grating order                    */
    string orderSel = "order3";
}{
    // Debug only
    if(verbose) {
        debug_print("PacsSpecSlew called with:");
        debug_print("confSPECblu: " + confSPECblu[0]);
        debug_print("confSPECred: " + confSPECred[0]);
        debug_print("confOBCP: " + confOBCP[0]);
        debug_print("doPROLOG: " + doPROLOG);
        debug_print("keyWAVE: " + keyWAVE);
        debug_print("filter: " + filter);
        debug_print("frstLstGrat: " + frstLstGratPos);
        debug_print("orderSel: " + orderSel);
    }
    // Array to collect OBCP times per line
    // NOTE: time variables in units of either number of ramps (SPEC) or
    // number of readouts (BOLO) or plain seconds. The calling program 
    // must convert, if applicable, this information into actual duration 
    // in true time units [seconds].
    // SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky), CAL source, 
    // and overheads (wait for something). Total duration is given by duree_num. 
    // If no error, this duration must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    int[][] dureeCalKey = [[0,0,0,0,0]];
    // Long sequence to "unpack" default values from tuples
    int capa_blu = confSPECblu[0]{0};
    int nb_rdouts_ramp_blu = confSPECblu[0]{1};
    int nb_rdouts_subramp_blu = confSPECblu[0]{2};
    int comp_mode_blu = confSPECblu[0]{3};
    int glitch_det_blu = confSPECblu[0]{4};
    int ramp_fit_alg_blu = confSPECblu[0]{5};
    int nb_raw_blu = confSPECblu[0]{6};
    int bias_r_blu_mV = confSPECblu[0]{7};
    int bias_d_blu_mV = confSPECblu[0]{8};
    int capa_red = confSPECred[0]{0};
    int nb_rdouts_ramp_red = confSPECred[0]{1};
    int nb_rdouts_subramp_red = confSPECred[0]{2};
    int comp_mode_red = confSPECred[0]{3};
    int glitch_det_red = confSPECred[0]{4};
    int ramp_fit_alg_red = confSPECred[0]{5};
    int nb_raw_red = confSPECred[0]{6};
    int bias_r_red_mV = confSPECred[0]{7};
    int bias_d_red_mV = confSPECred[0]{8};
    int nb_up_down = confOBCP[0]{0};
    int grat_step_up = confOBCP[0]{1};
    int grat_step_dn = confOBCP[0]{2};
    int nb_SRC_OFF = confOBCP[0]{3};
    int nb_ramps_plateau = confOBCP[0]{4};
    int nb_CS1_CS2 = confOBCP[0]{5};
    int nb_grat_step_up = confOBCP[0]{6};
    int nb_grat_step_dn = confOBCP[0]{7};
    int grat_start_pos = confOBCP[0]{8};
    int grat_start_time = confOBCP[0]{9};
    int grat_def_pos = confOBCP[0]{10};
    int grat_def_time = confOBCP[0]{11};
    int chop_pos_SRC = confOBCP[0]{12};
    int chop_pos_REF1 = confOBCP[0]{13};
    int chop_pos_REF2 = confOBCP[0]{14};
    int chop_pos_CS1 = confOBCP[0]{15};
    int chop_pos_CS2 = confOBCP[0]{16};
    int chop_def = confOBCP[0]{17};
    int detector = confOBCP[0]{18};
    int filterPOS = confOBCP[0]{19};
    // Bias voltages (needed by SPEC_aot_prologue) are commanded in (double) volts
    double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
    double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
    double bias_r_red = double(bias_r_red_mV) / 1000.0;
    double bias_d_red = double(bias_d_red_mV) / 1000.0;
    if(verbose) {
        debug_print("confSPEC: capa_blu: " + capa_blu);
        debug_print("confSPEC: nb_rdouts_ramp_blu: " + nb_rdouts_ramp_blu);
        debug_print("confSPEC: nb_rdouts_subramp_blu: " + nb_rdouts_subramp_blu);
        debug_print("confSPEC: comp_mode_blu: " + comp_mode_blu);
        debug_print("confSPEC: glitch_det_blu: " + glitch_det_blu);
        debug_print("confSPEC: ramp_fit_alg_blu: " + ramp_fit_alg_blu);
        debug_print("confSPEC: nb_raw_blu: " + nb_raw_blu);
        debug_print("confSPEC: bias_r_blu_mV: " + bias_r_blu_mV);
        debug_print("confSPEC: bias_d_blu_mV: " + bias_d_blu_mV);
    }
    // Issue SPEC_aot_prologue if demanded
    if(doPROLOG) {
        totalDUREE = SPEC_aot_prologue(nb_rdouts_ramp_red,nb_rdouts_ramp_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,comp_mode_blu,comp_mode_red,nb_rdouts_subramp_blu,nb_rdouts_subramp_red,nb_raw_blu,nb_raw_red,glitch_det_red,ramp_fit_alg_red,filter,verbose);
    }
    // NOTE: Grating starts at grat_start_pos determined by SPEC_get_grat. At end of
    // SlewCal grating should park. Park position is generally grat_def_pos:
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // AOT_prologue is supposed to have left grating at park position
    grat_def_pos = grat_park;
    // NOTE for version 1.0 and later. Upon execution of SpecSlew, grating is
    //      indeed where SPEC_orbit_prologue left it (the default park position);
    //      this fact remains unchanged. What is new is that SpecSlew will leave
    //      the grating not at the default park position but already at the
    //      position needed by the 1st line that will be observed. There are two
    //      advantages:
    //      1- the new logic in the OBCP incurs in less grating movements when
    //         the OBCP is repeated within a NOD or the next raster point, and
    //      2- the detector will see the illumination corresponding to the line
    //         wavelength before the actual observation starts.
    // Observe now each key wavelength
    int nbKEY = length(keyWAVE);
    {double,int,int,int,int}[] gratTuple = [{0.0,0,0,0,0}];
    for(int loopKEY = 0 .. nbKEY - 1) {
        //     We may perform the loop starting with high ORDER
        int keyWaveLoop1 = nbKEY - 1 - loopKEY;
        // or not....
        keyWaveLoop1 = loopKEY;
        //       
        //     Get grating start position (CAL is performeed with HI resolution)
        //     (frequency switch boolean is set to false)
        bool switching = false;
        // dirty trick to get extraConf bright or normal back!!!
        if(nb_rdouts_ramp_blu != 64) {
            string extraConf = "bright";
        } else {
            extraConf = "normal";
        }
        //        string extraConf = "normal";
        //      Seek K rows in CAL-U, i.e. key wavelength parameters	
        gratTuple[keyWaveLoop1] = SPEC_get_grat_info(keyWAVE[keyWaveLoop1],"KHI",switching,extraConf,orderSel,verbose);
        //      Issue now OBCP#35 for each of the given key wavelengths
        int order = gratTuple[keyWaveLoop1]{1};
        grat_start_pos = gratTuple[keyWaveLoop1]{2};
        int nb_grat_steps = gratTuple[keyWaveLoop1]{3};
        nb_grat_step_up = nb_grat_steps;
        nb_grat_step_dn = nb_grat_steps;
        int grat_step_up_fine = gratTuple[keyWaveLoop1]{4};
        int grat_step_dn_fine = -grat_step_up_fine;
        //
        // Read K-lines of table OBCP35params
        // add B if bright mode
        if(extraConf == "bright") {
            string key = "BK" + order;
        } else {
            key = "K" + order;
        }
        if(verbose) {
            debug_print("PacsSlewCal: key " + key);
        }
        string calU = "OBCP35params";
        nb_up_down = ilookup(calU,key,"nb_up_down");
        nb_CS1_CS2 = ilookup(calU,key,"nb_CS1_CS2");
        // SRC_OFF == 0;
        nb_SRC_OFF = 0;
        int chop_pos_OFF = chop_pos_REF2;
        nb_ramps_plateau = ilookup(calU,key,"nb_ramps_plateau");
        int grat_step_coarse = 0;
        //      Lookup chopper CS1 and CS2 positions
        calU = "CHOPPERCSparams";
        chop_pos_CS1 = ilookup(calU,"SPEC","pos_CS1");
        chop_pos_CS2 = ilookup(calU,"SPEC","pos_CS2");
        int nb_rdouts_ramp = nb_rdouts_ramp_red;
        //     Grating logic (OBCP is up/down ==> grating ends where it started)
        //     Leave the grating where it is, i.e. end-of-DMC value
        int new_grat_def_pos = grat_start_pos;
        //     But the last line should leave grating at frstLstGratPos
        if(keyWaveLoop1 == nbKEY - 1) {
            new_grat_def_pos = frstLstGratPos;
        }
        //     Number of steps to start position for current line
        int steps_start = grat_def_pos - grat_start_pos;
        int grat_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("OBCPcal:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + ";  time: " + grat_time);
        }
        //
        int steps_end = grat_start_pos - new_grat_def_pos;
        grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("OBCPcal:GratEnd from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
        }
        int[] dureeOBCP = OBCP_grat_line_scan_chop_3_cal(nb_up_down,nb_grat_step_up,grat_step_up_fine,nb_SRC_OFF,chop_pos_SRC,nb_ramps_plateau,chop_pos_OFF,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_dn_fine,detector,grat_start_pos,grat_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
        if(verbose) {
            debug_print("SlewCal performed KeyWave: " + keyWAVE[keyWaveLoop1] + " [mic] requires " + dureeOBCP[0] + " [sec]");
        }
        //     Update dureeCalKey
        dureeCalKey[keyWaveLoop1] = [0,0,0,0,0];
        for(int loop1 = 0 .. 4) {
            dureeCalKey[keyWaveLoop1][loop1] = dureeOBCP[loop1];
        }
        //     Prepare the grating to be ready for the next wavelength
        grat_def_pos = new_grat_def_pos;
    }
    // Add after the KeyWaves in dureeCalKey the duration from AOT_prologue
    dureeCalKey[nbKEY] = [0,0,0,0,0];
    dureeCalKey[nbKEY][4] = totalDUREE[4];
    if(verbose) {
        debug_print("End SlewCal with dureeCalKey: " + dureeCalKey);
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return dureeCalKey;
}

// Missionphase  : FM
//
// Purpose	:  Setup diagnostic housekeeping for the FM 
//                 detector test PTD 0.7.6 in photometry.
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: Set up  housekeeping parameter for diagnostic housekeeping 
//	  of the detector.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup photometry.
//                 
// Comments	: 
//
// Version	: 3.0	
// 
// History 	: 1.0 16-08-06 creation by HD. script test.
//		  2.0 23-08-06 HD. number of HK's modified.
//		  3.0 23-08-06 HD. script works.
block PHOT_chop_det_dhk_fmilt076phot_bb PACS 360 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //----------------------------------------------------- 
    // Setup and start diagnostic HK for PTD 0.7.6
    //----------------------------------------------------- 
    int diag_hk_length = 5;
    {int}[] parlist = [{209},{244},{245},{246},{0xffff}];
    int[] aux = [209,244,245,246,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(diag_hk_length,parlist,check_sum);
    int diag_hk_period = 4;
    // Synchronize diagnostic HK on blue spectrometer readouts
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark End of Block
    WriteEndBB();
}

// File          : Pacs_Spec_GeGa_Loop_Comm.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Ge:Ga detector Loop
//
// Author        : Helmut Dannerbauer
// CUS script	 : HD
// CVS file	 :
//
// Arguments     : bias, integration time, capacity, measurement time, resistor bias
//
// Description   :   Loop over bias, integration time and capacity.
//
// Dependencies  : - SPEC_CRE_No_Heater_setup
//		   - SPEC_spu_setup
//		   - PACS_Chop_Move_Abs
//		   - SPEC_spu_reset
//
// Comments      : The input arrays for bias, ramp length & capacitance must have the same length for red & blue
//
// Version       : 1.0
// History       : 1.0 / 14-Apr-2008 initial version by HD.
//	 1.1 / 17-Apr-2008 PR
//		introduced positionning of grating & FW
//		introduced main loop (global repetition)
//		introduced internal loop (flexibility)
//		suppressed unused variables 'cr' & 'br'
//		modified set of default parameters
//		1.2 17-Nov-2008 PR Flexible handling of SPU parameters
//	1.2 / 30-Mar-2009 PR Position grating after FW (inverse order).
//	1.3 / 06-May-2009 PR add parameters for raw ramps & all_slopefit
//		         Improvement of delay after bias change was coded in 
//                                                  March or April but didn't make it in the history then
//
procedure Pacs_Spec_GeGa_Loop_Comm {
    int repeat_global = 15; // Global repetition factor (main loop)
    int repeat_intern = 2; // Repetition factor inside the bias loop (ramplen+capa loops)
    double[] bias_blue = [0.06,0.08,0.1,0.12]; //bias blue
    double[] bias_red = [0.03,0.04,0.05,0.06]; //bias red red
    int[] ramp_len_blue = [32,64]; //ramp length blue (set integration time)
    int[] ramp_len_red = [32,64]; //ramp length red (set integration time)
    int[] capa_blue = [8,12]; //capacity blue
    int[] capa_red = [8,12]; //capacity red
    int meas_time = 60; //observing time in seconds per setting
    double bias_res_blue = 0.01; //resistor bias blue
    double bias_res_red = 0.01; //resistor bias red
    int chop_pos = 0; // chopper position
    int grat_pos = 737500; // grating position
    string filter_pos = "POS B" in ["POS A","POS B"]; // FW position
    int nb_raw_spu_blu = 3; // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3; // Nb of raw channels transmitted by SPUL
    bool subramps_of_8 = false; // true = subramps of 8 samples, false = slope fit for ramps<1/4s otherwise subramps of 16
    bool all_slopefit = true; // true = SPU forced in in slope fitting for all setups. Does not overrule subramps_of_8
}{
    // Begin of Script
    // define variables
    int idle_time = 420;
    if(repeat_intern > 1) {
        idle_time = 60;
    }
    // Position the filter wheel
    // =========================
    SPEC_fltw_move(filter_pos);
    // delay is contained in the procedure
    //
    // Position the grating
    // ====================
    Pacs_DMC_MOVE_GRAT_ABS(grat_pos);
    delay(15);
    //
    // Position the chopper
    // ====================
    PACS_Chop_Move_Abs(chop_pos);
    delay(1);
    //
    // Declare the set of CRE variables
    // ================================
    double bias_d_blue = bias_blue[0];
    double bias_d_red = bias_red[0];
    int ramp_blue = ramp_len_blue[0];
    int ramp_red = ramp_len_red[0];
    int capacity_blue = capa_blue[0];
    int capacity_red = capa_red[0];
    // 
    // SetUp SPU
    //
    // Compression mode blue channel : Nominal
    int comp_mode_blu = 16;
    // Compression mode red channel : Nominal
    int comp_mode_red = 16;
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_blu = 8;
    // Nb of red samples per sub-ramp
    int nb_samp_subramp_red = 8;
    // Glitch detection; 0=on; 1=off
    int glitch_det = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    int ramp_fit_alg = 1;
    // Start SPU or not [true,false]
    bool startSPU = true;
    //
    // determine length of arrays
    int bb = length(bias_blue);
    //length of bias blue
    int rlb = length(ramp_len_blue);
    //length of ramp length blue
    int cb = length(capa_blue);
    //length of capacity blue
    // 
    // MAIN LOOP
    //
    int iteration = 0;
    while(iteration < repeat_global) {
        //
        // BIAS LOOP
        //
        int blc = 0;
        while(blc < bb) {
            bias_d_blue = bias_blue[blc];
            bias_d_red = bias_red[blc];
            //
            // INTERNAL LOOP
            //
            // (to be used e.g. to measure all settings once instead of just 
            // waiting a long 'idle_time' after each bias change)
            int internloop = 0;
            while(internloop < repeat_intern) {
                //
                // RAMP LENGTH LOOP
                //
                int rlc = 0;
                while(rlc < rlb) {
                    ramp_blue = ramp_len_blue[rlc];
                    ramp_red = ramp_len_red[rlc];
                    //
                    if(subramps_of_8) {
                        nb_samp_subramp_blu = 8;
                        nb_samp_subramp_red = 8;
                        ramp_fit_alg = 1;
                    } else {
                        if(all_slopefit) {
                            nb_samp_subramp_blu = ramp_blue;
                            nb_samp_subramp_red = ramp_red;
                            ramp_fit_alg = 0;
                        } else {
                            if(ramp_blue < 64 || ramp_red < 64) {
                                nb_samp_subramp_blu = ramp_blue;
                                nb_samp_subramp_red = ramp_red;
                                ramp_fit_alg = 0;
                            } else {
                                nb_samp_subramp_blu = 16;
                                nb_samp_subramp_red = 16;
                                ramp_fit_alg = 1;
                            }
                        }
                    }
                    //
                    // CAPACITY LOOP 
                    //
                    int clc = 0;
                    while(clc < cb) {
                        capacity_blue = capa_blue[clc];
                        capacity_red = capa_red[clc];
                        //
                        // Setup CREs
                        SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red);
                        //
                        // Setup SPU
                        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
                        //
                        // if this is the first measurement with this bias -> delay
                        if(rlc == 0 && clc == 0 && internloop == 0) {
                            delay(idle_time);
                        }
                        //
                        // OBSERVATION 
                        delay(meas_time);
                        //
                        // SPU RESET
                        SPEC_spu_reset();
                        delay(1);
                        //
                        clc = clc + 1;
                    }
                    rlc = rlc + 1;
                }
                internloop = internloop + 1;
            }
            blc = blc + 1;
        }
        iteration = iteration + 1;
    }
    //
    //
    // Return Chopper & grating to default
    // ===================================
    Pacs_DMC_MOVE_GRAT_ABS(500000);
    delay(1);
    PACS_Chop_Move_Abs(0);
    delay(15);
    //
    // SYNC
    //= = =
    sync();
    //
    // End of Script
}

// CVS comments  : $Id: PacsSpecCommandOBCP32.txt,v 1.1 2007/10/25 12:16:47 dcesarsk Exp $ 
// Purpose       : Issue FreqSwitch PACS commands at each stable pointing in 
//                 order to observe all the HSPOT defined spectral lines
//
// CUS author    : DAC
//
// Input arguments
// Type                                                 Description
// {int,int,int,int,int,int,int,int,int}[] confSPECblu  BLUE SPU parameters
// {int,int,int,int,int,int,int,int,int}[] confSPECred  RED  SPU parameters
// {int,int,int,int,int,int,int,int,int,int,int,
//  int,int,int,int,int,int,int,int,int}[] confOBCP     OBCP parameters
// bool verbose                                         Print debug information
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per spectral line
// Description   : Loops over all wavelengths at current stable pointing; sends
//                 start OBCP telecommand per spectral line
// IMPORTANT NOTE: the duration for the first stable pointing could have been
//                 different than that for the following points, due to the
//                 fact that we start from the default configuration whereas for
//                 any subsequent point, we start from where we ended at
//                 point-1. All OBCPs dealing with the grating will leave the
//                 grating at the position used for the 1st line/range.
//
// Dependencies  : 
//
// Preconditions :
// Comments      : OBCP tuples have slightly different contents than for
//                 non switched OBCPs. See PacsSpecEstimatorOBCP32 for
//                 more details
// Version       : 0.1
// History       : 
// 0.1 DAC  18-oct-2007 First version based on PacsSpecCommandOBCP22
// 1.0 DAC   3-jun-2009 Adapted for new OBCP32 
//
int[][] procedure PacsSpecCommandOBCP32 {
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    bool verbose = true; // Print debug information
}{
    // Create array of durations; one duration per line
    int[][] time_array = [[0,0,0,0,0]];
    // Grating was left at 1st line by SlewCal
    int grat_def_pos = confOBCP[1]{8};
    // How many lines are we supposed to observe? confOBCP[0] is default tuple;
    // bonafide lines are described by confOBCP[1,2...])
    int nbLines = length(confOBCP) - 1;
    if(verbose) {
        debug_print("Comm.OBCP32:Starting SpecCommandOBCP32 with NbLines:" + nbLines);
        debug_print("Comm.OBCP32:Grating at position:" + grat_def_pos);
    }
    // ========================= LOOP on lines ===============================
    for(int lineNb = 1 .. nbLines) {
        //  Initialise time_array
        time_array[lineNb - 1] = [0,0,0,0,0];
        //      Long sequence to "unpack" contents of tuples
        //      Both SPECs
        int nb_rdouts_ramp_blu = confSPECblu[lineNb]{1};
        int comp_mode_blu = confSPECblu[lineNb]{3};
        int comp_mode_red = confSPECred[lineNb]{3};
        //     OBCP
        //  - Switch cycles (includes userREPfactr)
        int nb_up_dn = confOBCP[lineNb]{0};
        //  - OBCP32 is based on relative moves (to REF1 and to REF2)
        int jumpAtoB = confOBCP[lineNb]{1};
        int nbABBA = confOBCP[lineNb]{2};
        //  - Number of ramps per grating position
        int nb_ramps_grat = confOBCP[lineNb]{4};
        //  - Number of dither cycles (better be odd number)
        int ditherCount = confOBCP[lineNb]{7};
        //  - Nominal grating position for observed line 
        //    confOBCP{8} includes offset offLine of table OBCP32params:
        //    GratStartPos = grat_pos_LINE + offLine, i.e. nominal position + offLine
        int grat_pos_LINE = confOBCP[lineNb]{8};
        //  - Relative displacement of the ensemble LINE-REF1-LINE-REF2 per dither
        //    cycle
        int ditherSize = confOBCP[lineNb]{9};
        int chop_pos_SRC = confOBCP[lineNb]{12};
        int detector = confOBCP[lineNb]{18};
        //      This module is invoked at start of a stable pointing. Herein, OBCP32
        //      is called once per spectral line. 
        //
        //      Grating performs LINE1-REF1-REF1-LINE1. The DMC internal loop will
        //      shift the "switching" pattern by ditherSize each time around the loop.
        //      The first grating position within the loop is gratPos + ditherSize.
        //      We would like the line to be centered at half dithering cycle. The
        //      nominal wavelength  should correspond to
        //      grat_pos_LINE = gratPos + ditherSize + ditherSize*(ditherCount-1)/2
        int gratPos = grat_pos_LINE - ditherSize - ditherSize * (ditherCount - 1) / 2;
        //      Last correction: move the grating back by 1/2 jumpAtoB:
        gratPos = gratPos - jumpAtoB / 2;
        //      Before OBCP grating is parked at grat_def_pos (1st line nominal setting)
        int steps_start = grat_def_pos - gratPos;
        //  Time needed to get there [msec]
        int grat_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("Comm.OBCP32:GratStart from/to: " + grat_def_pos + "/" + gratPos);
            debug_print("Comm.OBCP32:GratStartTime: " + grat_time + " [msec]");
        }
        //  At the end of the OBCP, the grating finishes at
        int totalDither = (ditherCount - 1) * ditherSize;
        int grat_end = gratPos + ditherCount * ditherSize;
        //  We would like to leave it ready for the next line
        if(lineNb < nbLines) {
            grat_def_pos = confOBCP[lineNb + 1]{8};
        } else {
            grat_def_pos = confOBCP[1]{8};
        }
        //  Number of steps to go to grat_def_pos
        int steps_end = grat_end - grat_def_pos;
        //  Time needed to get there [msec]
        int grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("Comm.OBCP32:GratEnd from/to: " + grat_end + "/" + grat_def_pos);
            debug_print("Comm.OBCP32:GratEndTime: " + grat_def_time + " [msec]");
        }
        //
        //  Start the OBCP now.
        // Name params as in OBCP document
        // P1 = nb_up_dn
        int param1 = confOBCP[lineNb]{0};
        // P2 = Nb shifts up EQUAL Nb shifts down    	
        int param2 = confOBCP[lineNb]{7};
        int param10 = param2;
        // P3 dither amplitude up EQUAL dither amplitude down (sign!)
        int param3 = confOBCP[lineNb]{9};
        int param11 = -param3;
        // P4 = Nb ABBA cycles
        int param4 = confOBCP[lineNb]{2};
        // P5  relative move after P3; symmetrical of P12 going down  	
        int param5 = 0;
        int param12 = param5;
        // P6 Nb ramps per grating position
        int param6 = confOBCP[lineNb]{4};
        // P7 Actual wavelength switch, i.e. from A to B; P9 from B to A (up cycle)
        int param7 = confOBCP[lineNb]{1};
        int param9 = -param7;
        // P8 relative move after 1st B (up; same for down)
        int param8 = 0;
        int param14 = param8;
        // P13 Actual wavelength switch, i.e. from A to B; P15 from B to A (down cycle)
        int param13 = confOBCP[lineNb]{1};
        int param15 = -param13;
        // Call OBCP_wave_switch
        int[] timeOBCP = OBCP_wave_switch(param1,param2,param3,param4,param5,param6,param7,param8,param9,param10,param11,param12,param13,param14,param15,detector,comp_mode_blu,comp_mode_red,gratPos,chop_pos_SRC,grat_time,grat_def_pos,chop_pos_SRC,grat_def_time,nb_rdouts_ramp_blu);
        //  This OBCP is rather confusing; print enough debugging information
        if(verbose) {
            debug_print("Comm.OBCP32: NominalLine: " + grat_pos_LINE);
            debug_print("Comm.OBCP32: totalDither: " + totalDither);
            debug_print("Comm.OBCP32: ditherCount: " + ditherCount);
            debug_print("Comm.OBCP32: P#2        : " + param2);
            debug_print("Comm.OBCP32: P#3        : " + ditherSize);
            debug_print("Comm.OBCP32: P#4        : " + param4);
            debug_print("Comm.OBCP32: P#6        : " + param6);
            debug_print("Comm.OBCP32: P#7        : " + param7);
            debug_print("Comm.OBCP32: P#8        : " + param8);
            debug_print("Comm.OBCP32: gratPos    : " + gratPos);
            debug_print("Comm.OBCP32: gratDefPos : " + grat_def_pos);
            debug_print("Comm.OBCP32: chopSrc    : " + chop_pos_SRC);
            debug_print("Comm.OBCP32: gratTime   : " + grat_time);
            debug_print("Comm.OBCP32: gratDefTime: " + grat_def_time);
            //    Call PacsDebug with only one inner loop!!
            PacsDebug_wave_switch(gratPos,ditherCount,1,ditherSize,param4,param6,param7,param8);
        }
        //  Compute duration for ensemble of dithered cycles
        for(int loop4 = 0 .. 4) {
            time_array[lineNb - 1][loop4] = time_array[lineNb - 1][loop4] + timeOBCP[loop4];
        }
        // End of nbLines loop
    }
    // time_array indeces are [wavelength][mode]     
    if(verbose) {
        debug_print("Comm.CmdOBCP32 returns " + time_array);
    }
    // Add sync()
    sync();

    return time_array;
}

// CVS comments  : $Id
// Purpose       : Issue PACS commands at each raster position in order to
//                 observe all the HSPOT defined spectral lines
//
// CUS author    : DAC
// Script file   : PacsSpecCommand.txt 
//
// Input arguments
// Type                                                 Description
// {int,int,int,int,int,int,int,int,int}[] confSPECblu  BLUE SPU parameters
// {int,int,int,int,int,int,int,int,int}[] confSPECred  RED  SPU parameters
// {int,int,int,int,int,int,int,int,int,int,int,
//  int,int,int,int,int,int,int,int,int}[] confOBCP     OBCP parameters
// bool verbose                                         Print debug information
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per spectral line
//
// Description   : Loops over all wavelengths at current raster point. If raster
// identifier "rast_pnt" is a negative number, it means that we are in the
// "nodding" phase of "rast_pnt". Chopper pattern ABBA
// IMPORTANT NOTE: the duration for the first raster position
//                 may be different than the following raster points, due to the
//                 fact that we start at the default configuration whereas for
//                 any subsequent raster point, we start from where we ended at
//                 raster_point-1.
// NOTE: starting with version 3.0, grating is left at start position used by
//       first line in OBCP. This minimizes grating movements within a raster
//       or when nodding
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 3.0
// History       : 
// 0.1 DAC  6-May-2005
// 1.0 11-mar-2009 VD OBCP35
// 1.1 23-mar-2009 remove PacsSpecConfSet ... not allowed
//
int[][] procedure PacsSpecCommandOBCP35 {
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}]; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}]; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]; // OBCP parameters
    bool verbose = true; // Print debug information
}{
    // Create array of durations; one duration per line
    int[][] time_array = [[0,0,0,0,0]];
    // Start grating position should be the 1st line to observe
    // later it will be commanded elsewhere
    int grat_def_pos = confOBCP[1]{8};
    // How many lines are we supposed to observe?
    int nbLines = length(confOBCP) - 1;
    // ========================= LOOP on lines ===============================
    for(int loop2 = 1 .. nbLines) {
        //   Long sequence to "unpack" contents of tuples
        int capa_blu = confSPECblu[loop2]{0};
        int nb_rdouts_ramp_blu = confSPECblu[loop2]{1};
        int nb_rdouts_subramp_blu = confSPECblu[loop2]{2};
        int comp_mode_blu = confSPECblu[loop2]{3};
        int glitch_det_blu = confSPECblu[loop2]{4};
        int ramp_fit_alg_blu = confSPECblu[loop2]{5};
        int nb_raw_blu = confSPECblu[loop2]{6};
        int bias_r_blu_mV = confSPECblu[loop2]{7};
        int bias_d_blu_mV = confSPECblu[loop2]{8};
        int capa_red = confSPECred[loop2]{0};
        int nb_rdouts_ramp_red = confSPECred[loop2]{1};
        int nb_rdouts_subramp_red = confSPECred[loop2]{2};
        int comp_mode_red = confSPECred[loop2]{3};
        int glitch_det_red = confSPECred[loop2]{4};
        int ramp_fit_alg_red = confSPECred[loop2]{5};
        int nb_raw_red = confSPECred[loop2]{6};
        int bias_r_red_mV = confSPECred[loop2]{7};
        int bias_d_red_mV = confSPECred[loop2]{8};
        int nb_up_down = confOBCP[loop2]{0};
        int grat_step_up = confOBCP[loop2]{1};
        int grat_step_dn = confOBCP[loop2]{2};
        int nb_SRC_OFF = confOBCP[loop2]{3};
        int nb_ramps_plateau = confOBCP[loop2]{4};
        int nb_CS1_CS2 = confOBCP[loop2]{5};
        int nb_grat_step_up = confOBCP[loop2]{6};
        int nb_grat_step_dn = confOBCP[loop2]{7};
        int grat_start_pos = confOBCP[loop2]{8};
        //   int grat_start_time       = confOBCP[loop2]{ 9};
        //   int grat_def_pos          = confOBCP[loop2]{10};
        //   int grat_def_time         = confOBCP[loop2]{11};
        int chop_pos_SRC = confOBCP[loop2]{12};
        int chop_pos_REF1 = confOBCP[loop2]{13};
        int chop_pos_REF2 = confOBCP[loop2]{14};
        int chop_pos_CS1 = confOBCP[loop2]{15};
        int chop_pos_CS2 = confOBCP[loop2]{16};
        int chop_def = confOBCP[loop2]{17};
        int detector = confOBCP[loop2]{18};
        int filterPOS = confOBCP[loop2]{19};
        //   Bias voltages (needed by SPEC_aot_prologue) are commanded in 
        //  (double) volts
        double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
        double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
        double bias_r_red = double(bias_r_red_mV) / 1000.0;
        double bias_d_red = double(bias_d_red_mV) / 1000.0;
        //   Call OBCP once per spectral line (local loop) 
        //   (this module is invoked once per per raster position)
        //   Grating movement facts and strategy:
        //   0-  OBCP starts with grating already at grat_start_pos (done by SlewCal) 
        //   1-  OBCP moves grating from grat_start_pos to grat_start_pos 
        //   1a- above operation takes grat_start_time = 0 seconds
        //   2-  perform all the CHOPPER, CAL, loops
        //   2a- above operation takes whatever time
        //   3-  at end, OBCP moves grating to grat_start_pos for 1st line
        //   3a- above operation takes grat_def_time
        //
        //   This is up-down scan. Hence grating ends at position grat_start_pos
        //   If we set grat_def_pos position to grat_start_pos  for the next line, 
        //   we reduce grat_start_time to 0 [sec] for all lines but the first.
        //   At end of line "n", place grating at the position expected by line 
        //   "n+1" for all lines but last. For last observed wavelength use 
        //   grat_def_pos to ensure that next cycle will start exactly as this one,
        //   i.e. with grating parked at grat_def_pos
        //   Leave the grating where it is, i.e. end-of-DMC position
        int new_grat_def_pos = confOBCP[loop2]{8};
        //   The last observed line should leave the grating ready to start
        //   all over again
        if(loop2 == nbLines) {
            new_grat_def_pos = confOBCP[1]{8};
        }
        //   Starting times, viz. grat_time.
        //   NOTE: grat_start_pos is in OBCP tuple {8}
        int steps_start = grat_def_pos - grat_start_pos;
        int grat_start_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("OBCP35:Observing line/of:" + loop2 + "/" + nbLines);
            debug_print("OBCP35:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_start_time);
        }
        //   Ending times, viz. grat_def_time
        //   NOTE: DMC of OBCP35 leaves grating at start position
        int steps_end = grat_start_pos - new_grat_def_pos;
        int grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("OBCP35:GratEnd   from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
        }
        //   Call OBCP35 with derived parameters 
        time_array[loop2 - 1] = OBCP_grat_line_scan_chop_3(nb_up_down,nb_grat_step_up,grat_step_up,nb_SRC_OFF,chop_pos_SRC,nb_ramps_plateau,chop_pos_REF1,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_dn,detector,grat_start_pos,grat_start_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
        //   Prepare the grating to be ready for the next wavelength
        grat_def_pos = new_grat_def_pos;
        // End of nbLines loop
    }
    // time_array is indexed [wavelength][durations]     
    if(verbose) {
        debug_print("CmdOBCP35 returns " + time_array);
    }
    //SPR1707 Add sync()
    sync();

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose	: Condition SPU for SPECtroscopy observations
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: none
//
// Description	: Simply calling procedure "SPEC_spu_setup". See there for details.
//                  
// Dependencies : Only low level PACS TCs 
//
// Comments	: 
//
// Version	: 1.0
//               
// History	: 1.0 25-Apr-2008 PR Creation based on PacsEng_Spec_spu_setup
//
obs PacsEng_Spec_spu_setup_wait_reset {
    /* Needed variables to call PacsEng_Spec_spu_setup                        */
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp 
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp 
    int nb_raw_spu_blu = 3; // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3; // Nb of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0; // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true; // Start SPU or not [true,false]
    int wait_time = 2400; // Wait time at the end of the SPU setup
    bool stopSPU = true; // Stop SPU after the wait_time
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_spu_setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_spu_setup_wait_reset(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU,wait_time,stopSPU)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_spu_setup_wait_reset(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU,wait_time,stopSPU);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Filename	 : Pacs_Spec_Readouts_per_Ramp_Test
//
// Purpose       :  Test different reset intervals in spectroscopy
//                  
//                 
//
// TCL author    : HF
// TCL file      : none
// CUS author    : HF
// Script file   : SPEC_Readouts_per_Ramp_test.txt 
//
// Input arguments none
// type    name         description
//
// Return values none
// Type    Name      Default      Description
//
// Description   : Test of different values for readouts per ramp at same flux
//                           level 
//                  
//
// Preconditions : PACS must be switched-on and in Spectroscopy mode
//                 
// Comments      :  
// 
// Version	 : 2.1
// History       : 1.0 29-Mar-2005 creation by HF
//                 1.1 05-Apr-2005 modify dummy resistor bias and
//                                 length of measurement
//                 1.2 15-Apr-2005 HF, add SPU reset at the end
//                 1.3 11-Apr-2006 HF, adapted to FM, smallest capacitor
//                 1.4 03-Apr-2007 HF, adapted bias and chopper position to FM ILT values
//		   2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//                 2.1 08-Apr-2008 HF changed to in-flight default biases
//                    
int procedure Pacs_Spec_Readouts_per_Ramp_Test {
    int ramp_len_red = 64; // Red  ramp length
    int ramp_len_blu = 64; // Blue ramp length
}{
    // Tally duration (NOTE: we use [msec] for the return value)
    int duration_msec = 0;
    // CRE parameters default at 0.1pF
    int cre_ctrl_red = 386;
    // Red  CRE register (capa_red=0)
    int cre_ctrl_blu = 386;
    // Blue CRE register (capa_blu=0)
    double bias_d_red = 0.03;
    // BIAS_D for red spectro  (0-1V)  
    double bias_d_blu = 0.08;
    // BIAS_D for blue spectro (0-1V)
    double bias_r_red = 0.01;
    // BIAS_R for red spectro  (0-1V)
    double bias_r_blu = 0.01;
    // BIAS_R for blue spectro (0-1V)
    int capa_red = 0;
    // Capacitor red  (0=100fF,8=200fF,4=400fF,12=1pF)
    int capa_blu = 0;
    // Capacitor blue (0=100fF,8=200fF,4=400fF,12=1pF)
    // SPU parameters
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int nb_samp_subramp_blu = ramp_len_blu;
    // Nb of blue samples per sub-ramp 
    int nb_samp_subramp_red = ramp_len_red;
    // Nb of red samples per sub-ramp 
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    // No sub ramps or means    
    nb_samp_subramp_blu = ramp_len_blu;
    nb_samp_subramp_red = ramp_len_red;
    // Reset SPU
    SPEC_spu_reset();
    // Set chopper and grating (to key wavelength) 
    SPEC_MOV_CHOP_and_GRAT(648,535000);
    // Change readouts per ramp
    SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // Re-start SPU in default mode
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    delay(130);
    duration_msec = duration_msec + 130000;
    // Reset SPU
    SPEC_spu_reset();
    sync();

    return duration_msec;
}

// CVS file      : CONF_phot_fltw_R_Warm.txt
// Missionphase  : FMILT_3 & Later
//
// Purpose       : CONFigure the PHOT filter wheel for Redundant Warm
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      :
//
// History       : 1.0 04-Jul-2007 PR Initial version
//               :
procedure CONF_phot_fltw_R_Warm {
}{
    string calUname = "CONFFWPHOT";
    // FWPHOT CALIBRATION TABLE
    string calUrow = "FMILT_WR";
    // INSTRUMENT VERSION
    int rate = ilookup(calUname,calUrow,"Rate");
    int current = ilookup(calUname,calUrow,"Drive_current");
    int threshold_A = ilookup(calUname,calUrow,"Threshold_A");
    int threshold_B = ilookup(calUname,calUrow,"Threshold_B");
    int status_A = ilookup(calUname,calUrow,"Status_A");
    int status_B = ilookup(calUname,calUrow,"Status_B");
    {int}[] parlist = [{rate},{current},{threshold_A},{threshold_B},{status_A},{status_B}];
    int[] aux = [rate,current,threshold_A,threshold_B,status_A,status_B];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_FWPHOT_CONF_PAR(parlist,check_sum);
}

// CVS comments  : $Id: DMC_wave_switch.txt,v 1.2 2007/10/26 15:40:39 dcesarsk Exp $
// Description :
// 4.2.10 Line Observation with Wavelength Switching (OBCP 32, DMC Seq. 18)
// Wavelength switching will be required on extended sources. 
// No chopping will be done. Instead, the grating will be moved in a 2 or 3 
// position pattern around the spectral line to be observed. This version of 
// the wavelength switching DMC sequence does not contain any internal 
// calibration block. Internal calibrations are thought to be done outside the 
// sequence in a dedicated calibration block. This version allows for more 
// shifts of the grating pattern with at the same time smaller overheads.
//
// Dependencies  : Stand alone DEC/MEC sequence
//
// Comments      : Follows verbatim paragraph 4.2.10 in PACS-ME-LI-005
//                 version 1.6
//         Actual values of input parameters, except values for the
//         various loop counters, are completely irrelevant and so
//         are not used.
//         Loop counters are used to estimate the duree of the
//         sequence
//
// Version       : 0.1 15-oct-2007 Creation by DAC
// History       : 1.0 ABBA shifts implemented
//                     includes 15 Parameters
//                     P#1 = nb_up_down
//                     P#2 = nb_shift_up
//                     P#3,P#5,P#7,P#8,P#9,P#11, P#12,P#13,P#14,P#15 = grating relative moves
//                     P#4 nb_ABBA_cycle
//                     P#10 = nb_shift_down
//                     P#6 -= nb_rdouts_ramp
//                  2.0 updated DMC 18 PHS-1119 added wait time for grat sync
//                     
//                     
//
// This "dummy" DEC/MEC sequence needs only the loop parameters from the
// complete list above
int[] procedure DMC_wave_switch {
    int nb_shift_up = 11; // P#2 number of dithering/shift steps
    int nb_shift_dn = 11; // P#10 number of dithering/shift steps
    int nb_switch_cycles = 3; // P#4 nb of ABBA cycles per dithering
    int nb_ramps_grat = 1; // P#6 nb of ramps/grating position
    int nb_up_down = 1; // P#1 number of up-down cycles
}{
    // Define variables for time_array
    int duree_ramps = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Pseudo code from PACS OBCPs and DMC Sequences (4.1.7)
    // WAIT 1 ; have a defined start
    duree_ramps = duree_ramps + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; set Label to 0
    // LOOP P1                           main loop for number of shifts
    for(int inLOOP = 1 .. nb_up_down) {
        // LOOP P2
        for(int twoLOOP = 1 .. nb_shift_up) {
            //    WAIT 1                         sync. for chopper
            // duree_ramps = duree_ramps + 1;
            // duree_OVR = duree_OVR + 1;
            //    MOVE_GRATING_RELATIVE P3       move grating by P3 = shift
            // WAIT Move grating
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            //    LOOP P4                        P4 times core loop
            for(int fourLOOP = 1 .. nb_switch_cycles) {
                //       MOVE_GRATING_RELATIVE P5    move grating by P5
                //       LABEL 33                    wavelength switching
                //       WAIT P6                     take P6 ramps
                duree_ramps = duree_ramps + nb_ramps_grat;
                duree_SRC = duree_SRC + nb_ramps_grat;
                //       WAIT 1                      sync. for grating
                // duree_ramps = duree_ramps + 1;
                // duree_SRC = duree_SRC + 1;
                //       MOVE_GRATING_RELATIVE P7    move grating by P7
                //       WAIT P6                     take P6 ramps
                duree_ramps = duree_ramps + nb_ramps_grat;
                duree_REF = duree_REF + nb_ramps_grat;
                //       WAIT 1                      sync. for grating
                //duree_ramps = duree_ramps + 1;
                //duree_REF = duree_REF + 1;
                //       MOVE_GRATING_RELATIVE P8    move grating by P8
                //       WAIT P6                     take P6 ramps
                duree_ramps = duree_ramps + nb_ramps_grat;
                duree_SRC = duree_SRC + nb_ramps_grat;
                //       WAIT 1                      sync. for grating
                // duree_ramps = duree_ramps + 1;
                // duree_SRC = duree_SRC + 1;
                //       MOVE_GRATING_RELATIVE P9    move grating by P9
                //       WAIT P6                     take P6 ramps
                duree_ramps = duree_ramps + nb_ramps_grat;
                duree_REF = duree_REF + nb_ramps_grat;
                //    END_LOOP P4
            }
            // END_LOOP P3
        }
        // LOOP P10
        for(int tenLOOP = 1 .. nb_shift_dn) {
            //    WAIT 1                         sync. for chopper
            duree_ramps = duree_ramps + 1;
            duree_OVR = duree_OVR + 1;
            //    LOOP P4                        P4 times core loop
            for(int four2LOOP = 1 .. nb_switch_cycles) {
                //       MOVE_GRATING_RELATIVE P12    move grating by P12
                //       LABEL 33                    wavelength switching
                //       WAIT P6                     take P6 ramps
                duree_ramps = duree_ramps + nb_ramps_grat;
                duree_SRC = duree_SRC + nb_ramps_grat;
                //       WAIT 1                      sync. for grating
                // duree_ramps = duree_ramps + 1;
                // duree_SRC = duree_SRC + 1;
                //       MOVE_GRATING_RELATIVE P13    move grating by P13
                //       WAIT P6                     take P6 ramps
                duree_ramps = duree_ramps + nb_ramps_grat;
                duree_REF = duree_REF + nb_ramps_grat;
                //       WAIT 1                      sync. for grating
                // duree_ramps = duree_ramps + 1;
                // duree_REF = duree_REF + 1;
                //       MOVE_GRATING_RELATIVE P14    move grating by P14
                //       WAIT P6                     take P6 ramps
                duree_ramps = duree_ramps + nb_ramps_grat;
                duree_SRC = duree_SRC + nb_ramps_grat;
                //       WAIT 1                      sync. for grating
                // duree_ramps = duree_ramps + 1;
                // duree_SRC = duree_SRC + 1;
                //       MOVE_GRATING_RELATIVE P15    move grating by P15
                //       WAIT P6                     take P6 ramps
                duree_ramps = duree_ramps + nb_ramps_grat;
                duree_REF = duree_REF + nb_ramps_grat;
                //    END_LOOP P4
            }
            //    MOVE_GRATING_RELATIVE P11       move grating by P11 = shift
            // END_LOOP P10
        }
        // WAIT Grat SYNC PHS-1119
        duree_ramps = duree_ramps + 1;
        duree_REF = duree_REF + 1;
        // END LOOP P1
    }
    //  LABEL 0                           no sequence anymore
    //  END_SEQUENCE
    // 
    // No more in-between WAITs
    // 
    //  15 Parameters:
    //  P1: number of full sequences
    //  P2 nb_shift_up
    //  P4: ABBA core loop
    //  P3 P5 P7 P8 P9 P11 P12 P13 P14 P15: grating relative moves 
    //  P6: number of readouts per grating position
    //  P10 nb_shift_dn
    //
    //  Note: In order to establish the desired switching pattern, it is 
    //  recommended that:
    //   P5 = P8 == 0  P9 = -P7 P12 = P14 == 0 P13 = -P15
    //   P2 = P10
    //   P3 = P11
    //
    //
    // Sequence duration, in ramps :
    // 1 + P1*[P2*(P4*4*P6 +1)+ P10*(P4*4*P6 +1)]
    // Create time_array
    int[] time_array = [duree_ramps,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// Mission phase : ILT at Garching
//
// Purpose : PCD req.1.1.11
//           Low frequency noise measurement (12 hours each mode)
//           This is a variant using different bias (VH-VL) values
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowFreq_direct_EMT
//
// Argument :
//   measureTime : response measure time in seconds [3600s = 1hour]
//   biasFile    : Bias table file containing the initial values ["BOLObias_ILT_standard_high"]
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + SPU is ON in a normal downlink
//
// Description :
//   Low frequency measurement on one of the CSs
//
// Dependencies : None
//
// Comments : 
//
// Version : Thu Mar 29 2007
//
procedure Phot_lowFreq_direct_IST {
    string cs_num = "cs1" in ["cs1","cs2"]; // CS1 or CS2
    int measureTime = 2000; // response measure time in seconds
    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
    string finalBiasTable = "BOLObias_preILT_standard_low";
}{
    int[] cs_pos = [-23382,22347];
    int i_cs = 0;
    if(cs_num == "cs2") {
        i_cs = 1;
    }
    //
    //***********************************************
    //***********************************************
    //
    //	Bias setting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(biasFile,1);
    PHOT_set_bias_volt(biasFile,2);
    PHOT_set_bias_volt(biasFile,3);
    PHOT_set_bias_volt(biasFile,4);
    PHOT_set_bias_volt(biasFile,5);
    PHOT_set_bias_volt(biasFile,6);
    //
    //********************************************************
    // Sequence mode : blocking on VDEC_X for the direct mode
    //********************************************************
    //
    // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
    // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
    //
    //**************************
    // Sequence mode : Sref_only
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
    //# P 09 01 00 01
    int operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // Set gain high
    Pacs_BOLC_SET_GAIN("HIGH");
    //
    //*******************************
    // Select Filter A (110 microns)
    //*******************************
    PHOT_fltw_move("POS A");
    //
    //********************
    // Let all stabilized
    //********************
    delay(300);
    //
    //************************************
    // Response measurement during 300 (s)
    //************************************
    TMMarker602();
    OBCP_chopped_photometry(0,0,39,0,0,150,1,cs_pos[0],cs_pos[1],0,0,0);
    TMMarker600();
    //
    //**********************************************
    // Set the PACS chopper at the central position
    //**********************************************
    Pacs_DMC_MOVE_CHOP_ABS(cs_pos[i_cs]);
    //
    //********************
    // Let all stabilized
    //********************
    delay(300);
    //
    //*****************************************
    // Noise measurement during measureTime (s)
    //*****************************************
    TMMarker601();
    delay(measureTime);
    TMMarker600();
    //
    //********************
    // Let all stabilized
    //********************
    delay(300);
    //
    //************************************
    // Response measurement during 300 (s)
    //************************************
    TMMarker602();
    OBCP_chopped_photometry(0,0,39,0,0,150,1,cs_pos[0],cs_pos[1],0,0,0);
    TMMarker600();
    //
    // Stop SPU
    PHOT_spu_reset();
    //***********************************************
    //***********************************************
    //
    //	Bias resetting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(finalBiasTable,1);
    PHOT_set_bias_volt(finalBiasTable,2);
    PHOT_set_bias_volt(finalBiasTable,3);
    PHOT_set_bias_volt(finalBiasTable,4);
    PHOT_set_bias_volt(finalBiasTable,5);
    PHOT_set_bias_volt(finalBiasTable,6);
    //
    // Set seq mode Sb-Sref (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sb-Sref");
    //# P 09 01 00 00
    operand = 0x9010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set gain low
    Pacs_BOLC_SET_GAIN("LOW");
    //
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Perform Thermal behaviour photometry test
//                 Check before executing:
//                 o  TEMP_EV still below 0.3 K?
//                    (cooler recycling has to be finished)
//                 o  detector groups off
//                 o  CSs have to off and cold
//                 o  chopper and filter wheel controller off
//                 o  Check that the temperature sensors are on
//
//                 Duration: 53 min
//
// CUS author    : TM
// Script file   : PHOT_thermal_OBS.cus
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 0.1 creation by XXX
//                 0.3 09-nov-2006 TM: updated for FM-ILT
//                 0.4 10-nov-2006 TM: new bias table, low gain
//                 0.5 10-nov-2006 DAC New CONF_xxx scripts    
//                 0.6 14-nov-2006 TM: update of the bias setting
//                 0.7 05-mar-2007 TM: diagHk for OBCP, new CONF_chopper
//		   1.0 04-mar-2008 translated into PV script VDP
//
//
obs PacsEng_Phot_thermal {
    /* Needed variables to call PacsEng_Phot_thermal                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_thermal                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PHOT_thermal()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_thermal();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : PACS FM ILT tests
//
// Purpose       : FoV scan Spectroscopy (OBCP_spec_2_3_chop)
//
// Author        : P. Royer
//
// Arguments     :
//	     SPU setup arguments
//	     OBCP_spec_2_3_chop
//	     Filter wheel position
//
// Prerequisite  : 
//
// Description   :
//	     SPU Setup
//	     Position Filter Wheel
//	     OBCP_spec_2_3_chop
//		- center to chop throw small
//		- center to chop throw medium
//		- center to chop throw large
//		- center to chop throw medium incl. DMC internal calibration block
//
//                        SPU reset
//
// Dependencies : 
// 	     SPEC_spu_setup
//                        SPEC_spu_reset
//	     OBCP_spec_2_3_chop (calling DMC_spec_2_3_chop)
//
// Comments      : We are supposed in PACS spectro before to run this procedure
//	  => no CRE setup here
//
// Version       : 1.0
// History       : 1.0 / 15-Apr-2008 initial version by PR
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose 3 Pos chopping Spectroscopy (OBCP_spec_2_3_chop)
// @comment - 
//
procedure PACS_Spec_GeGa_Chop_2_3 {
    int nb_samp_subramp_blu = 64; // Red Subramp length  (directly connected to ramp_fit_alg)
    int nb_samp_subramp_red = 64; // Blue Subramp length
    int ramp_fit_alg = 0 in [0,1]; // Ramp fit algorithm [0=LstSq;1=mean value]
    string filter_pos = "POS A" in ["POS A","POS B"];
    int nb_up_down = 1; // Number of sequences: up down up  P#1
    int nb_grat_steps = 1; // Number of grating steps          P#2
    int nb_SRC_OFF = 10; // Nb cycles grating position       P#3
    int chop_pos_REF1 = 664; // Chopper position 1              P#4
    int nb_ramps_plateau = 2; // Nb of ramps per chopper plateau P#5
    int chop_pos_CS1 = -21350; // Chopper position on CS1       P#9
    int chop_pos_CS2 = 21200; // Chopper position on CS2        P#10
    int grat_step_up = 0; // Grating step                   P#11
    int grat_step_dn = 0; // Grating step                   P#12
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 461000; // Starting grating position
    int grat_time = 15000; // Time for grating to move to start position
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 664; // Chopped default position
    int grat_def_time = 15000; // Grating time to move to grat_def [msec]
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    //
    //int ramp_len_red = 64; // Red ramps length
    //int ramp_len_blu = 64; // Blue ramps length
    //double bias_d_red = 0.07 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    //double bias_d_blu = 0.21 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    //int capa_red = 8; // Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
    //int capa_blu = 8; // Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
    //
    // CRE SETUP  --> SUPPOSED IN PACS-SPECTRO --> CRE SETUP SKIPPED
    // NOTE: capa_xxx is added to cre_ctrl_xx within SPEC_cre_setup
    //
    //double bias_r_red = 0.011; // in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    //double bias_r_blu = 0.011; // in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    //int cre_ctrl_red = 386;
    //int cre_ctrl_blu = 386;
    //SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    //
    // SPU SETUP
    // ======
    // Register with environment
    WriteOBSID($OBSID);
    // Start SPU
    int nb_raw_spu_blu = 3;
    int nb_raw_spu_red = 3;
    int glitch_det = 1;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,true);
    //
    // Position the filter wheel
    // ==============
    SPEC_fltw_move(filter_pos);
    //
    // OBCP_spec_2_3_chop
    // =============
    //
    // A. Center <-> +- Small Throw
    //
    int chop_pos_REF2 = -1408;
    // Chopper position 2              P#6
    int chop_pos_REF3 = 2724;
    // Chopper position 3              P#7
    int nb_CS1_CS2 = 0;
    // Nbr cycles on CS                P#8
    OBCP_spec_2_3_chop(nb_up_down,nb_grat_steps,nb_SRC_OFF,chop_pos_REF1,nb_ramps_plateau,chop_pos_REF2,chop_pos_REF3,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_up,grat_step_dn,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,nb_rdouts_ramp);
    //
    // B. Center <-> +- Medium Throw
    //
    chop_pos_REF2 = -5552;
    // Chopper position 2              P#6
    chop_pos_REF3 = 6769;
    // Chopper position 3              P#7
    nb_CS1_CS2 = 0;
    // Nbr cycles on CS                P#8
    OBCP_spec_2_3_chop(nb_up_down,nb_grat_steps,nb_SRC_OFF,chop_pos_REF1,nb_ramps_plateau,chop_pos_REF2,chop_pos_REF3,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_up,grat_step_dn,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,nb_rdouts_ramp);
    //
    // C. Center <-> +- Large Throw
    //
    chop_pos_REF2 = -11580;
    // Chopper position 2              P#6
    chop_pos_REF3 = 12444;
    // Chopper position 3              P#7
    nb_CS1_CS2 = 0;
    // Nbr cycles on CS                P#8
    OBCP_spec_2_3_chop(nb_up_down,nb_grat_steps,nb_SRC_OFF,chop_pos_REF1,nb_ramps_plateau,chop_pos_REF2,chop_pos_REF3,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_up,grat_step_dn,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,nb_rdouts_ramp);
    //
    // D. Center <-> +- Medium Throw + visit the CSs
    //
    chop_pos_REF2 = -5552;
    // Chopper position 2              P#6
    chop_pos_REF3 = 6769;
    // Chopper position 3              P#7
    nb_CS1_CS2 = 10;
    // Nbr cycles on CS                P#8
    OBCP_spec_2_3_chop(nb_up_down,nb_grat_steps,nb_SRC_OFF,chop_pos_REF1,nb_ramps_plateau,chop_pos_REF2,chop_pos_REF3,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_up,grat_step_dn,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,nb_rdouts_ramp);
    //
    // Stop SPU
    // =====
    SPEC_spu_reset();
    //
    // SYNC
    //= = =
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	: Record data in BOL-C test pattern mode
//
// Author	: Bart Vandenbussche
// CUS script	: PHOT_TestPattern_obs
// CVS file	: 
//
// Arguments	: time_in_testmode : time to stay in test pattern mode
//
// Description	: Switch to BOL-C HK+test pattern data mode
//                     wait <time_in_testmode> seconds
//                     Switch to BOL-C HK + bolometer data mode 
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on with configured BOLC
//                 
// Comments	: 
//
// Version	: 3.0
//               
// History	: 1.0 13-apr-2005 BV - First version
//                2.0 DAC 19-oct-2005 Added SPU start and stop
//                2.1 BV   11-04-2007  Changed raw channels to 0
//		  3.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
obs PacsEng_Phot_TestPattern {
    /* Needed variables to call PacsEng_Phot_TestPattern                        */
    int time_in_testmode = 60;
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_TestPattern                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Phot_TestPattern(time_in_testmode)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Phot_TestPattern(time_in_testmode);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsSpecCommandOBCP27.txt,v 1.6 2007/08/13 08:58:03 dcesarsk Exp $ 
// Purpose       : Issue PACS commands at each raster position in order to
//                 observe all the HSPOT defined spectral lines
//
// CUS author    : DAC
// Script file   : PacsSpecCommand.txt 
//
// Input arguments
// Type                                                 Description
// {int,int,int,int,int,int,int,int,int}[] confSPECblu  BLUE SPU parameters
// {int,int,int,int,int,int,int,int,int}[] confSPECred  RED  SPU parameters
// {int,int,int,int,int,int,int,int,int,int,int,
//  int,int,int,int,int,int,int,int,int}[] confOBCP     OBCP parameters
// bool verbose                                         Print debug information
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per spectral line
//
// Description   : Loops over all wavelengths at current raster point. If raster
// identifier "rast_pnt" is a negative number, it means that we are in the
// "nodding" phase of "rast_pnt".
// IMPORTANT NOTE: the duration for the first raster position
//                 may be different than the following raster points, due to the
//                 fact that we start at the default configuration whereas for
//                 any subsequent raster point, we start from where we ended at
//                 raster_point-1.
// NO LONGER TRUE (see history for version 2.0) No longer a reference to leg
// or raster number is needed: PACS is assumed to start the OBS phase in the
// same state it would be at the end of a nod leg; namely, filter wheel at last
// commanded position and grating at default position.
// NOTE: starting with version 3.0, grating is left at start position used by
//       first line in OBCP. This minimizes grating movements within a raster
//       or when nodding
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 3.0
// History       : 
// 0.1 DAC  6-May-2005
// 1.0 19-May-2005 Use tuples as input arguments
// 1.1 31-May-2005 All elements in confSPEC are int
// 1.2  1-Jun-2005 Adapted for CAL during slew: moved SPEC_aot_prolog to 
//                 PacsLineSpecSlewCal
// 1.3  7-Jun-2005 confOBCP is now all {int}
// 1.4 14-jun-2005 No confSPEC changes allowed within OBS
// 1.5 29-aug-2005 Added "verbose" input argument
// 2.0 29-aug-2005 Amended logic assuming that PACS will start all cycles
//                 always in the same state. This means that the previous
//                 non observing phase (SlewCal or AOT_prologue) has left
//                 PACS as it would be left after completing an OBS cycle, viz.
//                 filter wheel at last commanded position and grating at
//                 default position
//                 Renamed to PacsLineSpecCommandOBCP27 since using OBCP#27
// 2.1 19-sep-2005 Renamed to PacsSpecCommandOBCP27 since sme module for
//                 Line and Range
// 2.2 23-sep-2005 Added sync() on account of SPR-1707
// 2.3  1-jun-2006 Harmonize with OBCP22: leave grating where it is instead
//                 of moving to next line. There is no longer a FLTW movement
//                 (no order mix; FLTW set by SPEC_aot_prologue)
// 3.0 14-feb-2007 Grating starts and ends at position used for 1st line
//                 Requires that SlewCal places grating at this position
//                 Before leaving AOT, grating should be moved to park position
// 3.1  2-may-2007 Adopt renamed PacsSpecConfSet 
// 3.2  23-mar-2009 Remove PacsSpecConfSet because not allowed
// 
int[][] procedure PacsSpecCommandOBCP27 {
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}]; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}]; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]; // OBCP parameters
    bool verbose = true; // Print debug information
}{
    // Create array of durations; one duration per line
    int[][] time_array = [[0,0,0,0,0]];
    // Start grating position should be the 1st line to observe
    // later it will be commanded elsewhere
    int grat_def_pos = confOBCP[1]{8};
    // How many lines are we supposed to observe?
    int nbLines = length(confOBCP) - 1;
    // ========================= LOOP on lines ===============================
    for(int loop2 = 1 .. nbLines) {
        //   Long sequence to "unpack" contents of tuples
        int capa_blu = confSPECblu[loop2]{0};
        int nb_rdouts_ramp_blu = confSPECblu[loop2]{1};
        int nb_rdouts_subramp_blu = confSPECblu[loop2]{2};
        int comp_mode_blu = confSPECblu[loop2]{3};
        int glitch_det_blu = confSPECblu[loop2]{4};
        int ramp_fit_alg_blu = confSPECblu[loop2]{5};
        int nb_raw_blu = confSPECblu[loop2]{6};
        int bias_r_blu_mV = confSPECblu[loop2]{7};
        int bias_d_blu_mV = confSPECblu[loop2]{8};
        int capa_red = confSPECred[loop2]{0};
        int nb_rdouts_ramp_red = confSPECred[loop2]{1};
        int nb_rdouts_subramp_red = confSPECred[loop2]{2};
        int comp_mode_red = confSPECred[loop2]{3};
        int glitch_det_red = confSPECred[loop2]{4};
        int ramp_fit_alg_red = confSPECred[loop2]{5};
        int nb_raw_red = confSPECred[loop2]{6};
        int bias_r_red_mV = confSPECred[loop2]{7};
        int bias_d_red_mV = confSPECred[loop2]{8};
        int nb_up_down = confOBCP[loop2]{0};
        int grat_step_up = confOBCP[loop2]{1};
        int grat_step_dn = confOBCP[loop2]{2};
        int nb_SRC_OFF = confOBCP[loop2]{3};
        int nb_ramps_plateau = confOBCP[loop2]{4};
        int nb_CS1_CS2 = confOBCP[loop2]{5};
        int nb_grat_step_up = confOBCP[loop2]{6};
        int nb_grat_step_dn = confOBCP[loop2]{7};
        int grat_start_pos = confOBCP[loop2]{8};
        //   int grat_start_time       = confOBCP[loop2]{ 9};
        //   int grat_def_pos          = confOBCP[loop2]{10};
        //   int grat_def_time         = confOBCP[loop2]{11};
        int chop_pos_SRC = confOBCP[loop2]{12};
        int chop_pos_REF1 = confOBCP[loop2]{13};
        int chop_pos_REF2 = confOBCP[loop2]{14};
        int chop_pos_CS1 = confOBCP[loop2]{15};
        int chop_pos_CS2 = confOBCP[loop2]{16};
        int chop_def = confOBCP[loop2]{17};
        int detector = confOBCP[loop2]{18};
        int filterPOS = confOBCP[loop2]{19};
        //   Bias voltages (needed by SPEC_aot_prologue) are commanded in 
        //  (double) volts
        double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
        double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
        double bias_r_red = double(bias_r_red_mV) / 1000.0;
        double bias_d_red = double(bias_d_red_mV) / 1000.0;
        //   Call OBCP once per spectral line (local loop) 
        //   (this module is invoked once per per raster position)
        //   Grating movement facts and strategy:
        //   0-  OBCP starts with grating already at grat_start_pos (done by SlewCal) 
        //   1-  OBCP moves grating from grat_start_pos to grat_start_pos 
        //   1a- above operation takes grat_start_time = 0 seconds
        //   2-  perform all the CHOPPER, CAL, loops
        //   2a- above operation takes whatever time
        //   3-  at end, OBCP moves grating to grat_start_pos for 1st line
        //   3a- above operation takes grat_def_time
        //
        //   This is up-down scan. Hence grating ends at position grat_start_pos
        //   If we set grat_def_pos position to grat_start_pos  for the next line, 
        //   we reduce grat_start_time to 0 [sec] for all lines but the first.
        //   At end of line "n", place grating at the position expected by line 
        //   "n+1" for all lines but last. For last observed wavelength use 
        //   grat_def_pos to ensure that next cycle will start exactly as this one,
        //   i.e. with grating parked at grat_def_pos
        //   Leave the grating where it is, i.e. end-of-DMC position
        int new_grat_def_pos = confOBCP[loop2]{8};
        //   The last observed line should leave the grating ready to start
        //   all over again
        if(loop2 == nbLines) {
            new_grat_def_pos = confOBCP[1]{8};
        }
        //   Starting times, viz. grat_time.
        //   NOTE: grat_start_pos is in OBCP tuple {8}
        int steps_start = grat_def_pos - grat_start_pos;
        int grat_start_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("OBCP27:Observing line/of:" + loop2 + "/" + nbLines);
            debug_print("OBCP27:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_start_time);
        }
        //   Ending times, viz. grat_def_time
        //   NOTE: DMC of OBCP27 leaves grating at start position
        int steps_end = grat_start_pos - new_grat_def_pos;
        int grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("OBCP27:GratEnd   from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
        }
        //   Call OBCP27 with derived parameters 
        time_array[loop2 - 1] = OBCP_grat_scan_chop2(nb_up_down,nb_grat_step_up,nb_SRC_OFF,chop_pos_SRC,nb_ramps_plateau,chop_pos_REF1,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_up,grat_step_dn,detector,grat_start_pos,grat_start_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
        //   Prepare the grating to be ready for the next wavelength
        grat_def_pos = new_grat_def_pos;
        // End of nbLines loop
    }
    // time_array is indexed [wavelength][durations]     
    if(verbose) {
        debug_print("CmdOBCP27 returns " + time_array);
    }
    //SPR1707 Add sync()
    sync();

    return time_array;
}

// Script        : PACS_Chopper_AutoOpt.cus
// Missionphase  : Commissioning
//
// Purpose	: Check a series of different chopper controller settings by
//                chopping between +/- 12000 units (~4 deg)
//                  
// Author	: Markus Nielbock/Helmut Dannerbauer
// CUS author 	: MN/HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-12000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions: PACS switched on and Chopper switched off.
//                 
// Comments	: This script is based on the commanding script
//                PACS_Chopper_uk_move_12000_OBS.cus
//
// Version	: 1.0	
// 
// History 	: 1.0 20-Nov-2007 (MN) Script to do simple chopper cycle 
//		  
//
// Initialise input parameters:
// Defines control parameter range, loops run from k(p,i,c,f)min to
// k(p,i,c,f)max defining the inverse of the ratio of parameter change w.r.t.
// the default value.
procedure PACS_Chopper_AutoOpt {
    int kpmin = 0 in [-3,3];
    int kpmax = 0 in [-3,3];
    int kimin = 0 in [-3,3];
    int kimax = 0 in [-3,3];
    int kcmin = 0 in [-3,3];
    int kcmax = 0 in [-3,3];
    int kfmin = 0 in [-3,3];
    int kfmax = 0 in [-3,3];
}{
    // PACS instrument code for BBID
    int instrument = 0x40000000;
    // chopper position (approx. +/- 4 deg in FPU)
    int chop_pos = 12000;
    // number of chop cycles
    int cycle = 10;
    // length of plateau time in seconds
    int plateau_time = 2;
    // Initialise variables for conversion from int to string and double
    string sU = "+0";
    string sV = "+0";
    string sW = "+0";
    string sX = "+0";
    double dU = 0.0;
    double dV = 0.0;
    double dW = 0.0;
    double dX = 0.0;
    int bU = 0x4000;
    int bV = 0x400;
    int bW = 0x40;
    int bX = 0x4;
    // CALU table file to be accessed
    string fileU = "CONFChopper_auto";
    // Start diag. HK
    SPEC_Chopper_dhk_5hk_1khz_bb();
    // Cycle through calibration table columns 
    if(kpmax < kpmin) {
        kpmax = kpmin;
    }
    if(kimax < kimin) {
        kimax = kimin;
    }
    if(kcmax < kcmin) {
        kcmax = kcmin;
    }
    if(kfmax < kfmin) {
        kfmax = kfmin;
    }
    for(int u = kpmin .. kpmax) {
        for(int v = kimin .. kimax) {
            for(int w = kcmin .. kcmax) {
                for(int x = kfmin .. kfmax) {
                    // calculate inverse -> ratio of changes
                    if(u != 0) {
                        dU = 1.0 / double(u);
                    } else {
                        dU = 0.0;
                    }
                    if(v != 0) {
                        dV = 1.0 / double(v);
                    } else {
                        dV = 0.0;
                    }
                    if(w != 0) {
                        dW = 1.0 / double(w);
                    } else {
                        dW = 0.0;
                    }
                    if(x != 0) {
                        dX = 1.0 / double(x);
                    } else {
                        dX = 0.0;
                    }
                    if(abs(dU + dV + dW + dX) < 0.01) {
                        // convert int to string variables
                        // and determine BBID for column recovery
                        // BBID is a 32 bit word with:
                        // 2 bits: Instrument (PACS = 01)
                        // 14 bits: block number (not used here)
                        // 16 bits: a counter, used here as follows:
                        //          4 bits for every PID parameter (P, I, C, F)
                        //          of this: 2 bits for the sign (01 = +, 10 = -)
                        //                   2 bits for the number (01, 10, 11 = 1, 2, 3)
                        if(u >= 0) {
                            sU = "+" + u;
                            bU = 16384 + 4096 * u;
                        } else {
                            sU = "" + u;
                            bU = 32768 - 4096 * u;
                        }
                        if(v >= 0) {
                            sV = "+" + v;
                            bV = 1024 + 256 * v;
                        } else {
                            sV = "" + v;
                            bV = 2048 - 256 * v;
                        }
                        if(w >= 0) {
                            sW = "+" + w;
                            bW = 64 + 16 * w;
                        } else {
                            sW = "" + w;
                            bW = 128 - 16 * w;
                        }
                        if(x >= 0) {
                            sX = "+" + x;
                            bX = 4 + x;
                        } else {
                            sX = "" + x;
                            bX = 8 - x;
                        }
                        // construct column identifier
                        string calUcol = "P" + sU + "I" + sV + "C" + sW + "F" + sX;
                        debug_print("CALU column is " + calUcol);
                        int bbid = instrument + bU + bV + bW + bX;
                        WriteBBID(bbid);
                        // Upload Chopper Controller Parameter
                        CONF_chopper(fileU,calUcol);
                        delay(2);
                        // Switch on and enable chopper controller 
                        PACS_Chopper_SWON_SWOF_only("ON");
                        delay(2);
                        EnDis_chopper("ON");
                        delay(5);
                        // move chopper to zero
                        PACS_Chopper_mov_abs_fm_bb(0);
                        delay(1);
                        // chop cycle
                        int i = 1;
                        while(i <= cycle) {
                            PACS_Chopper_mov_abs_fm_bb(chop_pos);
                            delay(plateau_time);
                            PACS_Chopper_mov_abs_fm_bb(-chop_pos);
                            delay(plateau_time);
                            i = i + 1;
                        }
                        // move chopper to zero
                        PACS_Chopper_mov_abs_fm_bb(0);
                        delay(1);
                        // Disable and switch off chopper controller 
                        EnDis_chopper("OFF");
                        delay(2);
                        PACS_Chopper_SWON_SWOF_only("OFF");
                        delay(5);
                    }
                }
            }
        }
    }
    // Stop diagnostic housekeeping
    PACS_stop_dhk_fm_bb();
    sync();
}

// CVS comments  : $Id
// Purpose       : Issue PACS commands at each raster position in order to
//                 observe all the HSPOT defined spectral lines
//
// CUS author    : DAC
// Script file   : PacsSpecCommand.txt 
//
// Input arguments
// Type                                                 Description
// {int,int,int,int,int,int,int,int,int}[] confSPECblu  BLUE SPU parameters
// {int,int,int,int,int,int,int,int,int}[] confSPECred  RED  SPU parameters
// {int,int,int,int,int,int,int,int,int,int,int,
//  int,int,int,int,int,int,int,int,int}[] confOBCP     OBCP parameters
// bool verbose                                         Print debug information
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per spectral line
//
// Description   : Loops over all wavelengths at current raster point. If raster
// identifier "rast_pnt" is a negative number, it means that we are in the
// "nodding" phase of "rast_pnt". NO Chopper
// IMPORTANT NOTE: the duration for the first raster position
//                 may be different than the following raster points, due to the
//                 fact that we start at the default configuration whereas for
//                 any subsequent raster point, we start from where we ended at
//                 raster_point-1.
// NOTE: starting with version 3.0, grating is left at start position used by
//       first line in OBCP. This minimizes grating movements within a raster
//       or when nodding
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 3.0
// History       : 
// 0.1 DAC  6-May-2005
// 1.0 11-mar-2009 VD OBCP35
// 1.1 23-mar-2009 remove PacsSpecConfSet ... not allowed
// 2.0 23-mar-2010 VD Cloned
//
int[][] procedure PacsSpecCommandOBCP28 {
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}]; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}]; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]; // OBCP parameters
    bool verbose = true; // Print debug information
}{
    // Create array of durations; one duration per line
    int[][] time_array = [[0,0,0,0,0]];
    // Start grating position should be the 1st line to observe
    // later it will be commanded elsewhere
    int grat_def_pos = confOBCP[1]{8};
    // How many lines are we supposed to observe?
    int nbLines = length(confOBCP) - 1;
    // ========================= LOOP on lines ===============================
    for(int loop2 = 1 .. nbLines) {
        //   Long sequence to "unpack" contents of tuples
        int capa_blu = confSPECblu[loop2]{0};
        int nb_rdouts_ramp_blu = confSPECblu[loop2]{1};
        int nb_rdouts_subramp_blu = confSPECblu[loop2]{2};
        int comp_mode_blu = confSPECblu[loop2]{3};
        int glitch_det_blu = confSPECblu[loop2]{4};
        int ramp_fit_alg_blu = confSPECblu[loop2]{5};
        int nb_raw_blu = confSPECblu[loop2]{6};
        int bias_r_blu_mV = confSPECblu[loop2]{7};
        int bias_d_blu_mV = confSPECblu[loop2]{8};
        int capa_red = confSPECred[loop2]{0};
        int nb_rdouts_ramp_red = confSPECred[loop2]{1};
        int nb_rdouts_subramp_red = confSPECred[loop2]{2};
        int comp_mode_red = confSPECred[loop2]{3};
        int glitch_det_red = confSPECred[loop2]{4};
        int ramp_fit_alg_red = confSPECred[loop2]{5};
        int nb_raw_red = confSPECred[loop2]{6};
        int bias_r_red_mV = confSPECred[loop2]{7};
        int bias_d_red_mV = confSPECred[loop2]{8};
        int nb_up_down = confOBCP[loop2]{0};
        int grat_step_up = confOBCP[loop2]{1};
        int grat_step_dn = confOBCP[loop2]{2};
        int nb_SRC_OFF = confOBCP[loop2]{3};
        int nb_ramps_grat_pos = confOBCP[loop2]{4};
        int nb_CS1_CS2 = confOBCP[loop2]{5};
        int nb_grat_step_up = confOBCP[loop2]{6};
        int nb_grat_step_dn = confOBCP[loop2]{7};
        int grat_start_pos = confOBCP[loop2]{8};
        //   int grat_start_time       = confOBCP[loop2]{ 9};
        //   int grat_def_pos          = confOBCP[loop2]{10};
        //   int grat_def_time         = confOBCP[loop2]{11};
        int chop_pos_SRC = confOBCP[loop2]{12};
        int chop_pos_REF1 = confOBCP[loop2]{13};
        int chop_pos_REF2 = confOBCP[loop2]{14};
        int chop_pos_CS1 = confOBCP[loop2]{15};
        int chop_pos_CS2 = confOBCP[loop2]{16};
        int chop_def = confOBCP[loop2]{17};
        int detector = confOBCP[loop2]{18};
        int filterPOS = confOBCP[loop2]{19};
        //   Bias voltages (needed by SPEC_aot_prologue) are commanded in 
        //  (double) volts
        double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
        double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
        double bias_r_red = double(bias_r_red_mV) / 1000.0;
        double bias_d_red = double(bias_d_red_mV) / 1000.0;
        //   Call OBCP once per spectral line (local loop) 
        //   (this module is invoked once per per raster position)
        //   Grating movement facts and strategy:
        //   0-  OBCP starts with grating already at grat_start_pos (done by SlewCal) 
        //   1-  OBCP moves grating from grat_start_pos to grat_start_pos 
        //   1a- above operation takes grat_start_time = 0 seconds
        //   2-  perform all the CHOPPER, CAL, loops
        //   2a- above operation takes whatever time
        //   3-  at end, OBCP moves grating to grat_start_pos for 1st line
        //   3a- above operation takes grat_def_time
        //
        //   This is up-down scan. Hence grating ends at position grat_start_pos
        //   If we set grat_def_pos position to grat_start_pos  for the next line, 
        //   we reduce grat_start_time to 0 [sec] for all lines but the first.
        //   At end of line "n", place grating at the position expected by line 
        //   "n+1" for all lines but last. For last observed wavelength use 
        //   grat_def_pos to ensure that next cycle will start exactly as this one,
        //   i.e. with grating parked at grat_def_pos
        //   Leave the grating where it is, i.e. end-of-DMC position
        int new_grat_def_pos = confOBCP[loop2]{8};
        //   The last observed line should leave the grating ready to start
        //   all over again
        if(loop2 == nbLines) {
            new_grat_def_pos = confOBCP[1]{8};
        }
        //   Starting times, viz. grat_time.
        //   NOTE: grat_start_pos is in OBCP tuple {8}
        int steps_start = grat_def_pos - grat_start_pos;
        int grat_start_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("OBCP28:Observing line/of:" + loop2 + "/" + nbLines);
            debug_print("OBCP28:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_start_time);
        }
        //   Ending times, viz. grat_def_time
        //   NOTE: DMC of OBCP28 leaves grating at start position
        int steps_end = grat_start_pos - new_grat_def_pos;
        int grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("OBCP28:GratEnd   from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
        }
        //   Call OBCP28 with derived parameters 
        time_array[loop2 - 1] = OBCP_grat_scan_nochop(nb_up_down,nb_grat_step_up,grat_step_up,grat_step_dn,nb_ramps_grat_pos,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,nb_ramps_grat_pos,nb_grat_step_dn,chop_def,detector,grat_start_pos,grat_start_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,grat_def_time,nb_rdouts_ramp_red);
        //   Prepare the grating to be ready for the next wavelength
        grat_def_pos = new_grat_def_pos;
        // End of nbLines loop
    }
    // time_array is indexed [wavelength][durations]     
    if(verbose) {
        debug_print("CmdOBCP28 returns " + time_array);
    }
    //SPR1707 Add sync()
    sync();

    return time_array;
}

// Missionphase  : PACS AVM ILT Orbit-Operations
//
// Purpose       : OnBoardControlProcedure to perform
//                 chopped SPEC with dithering (OBCP #9)
//
// Author        : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : OBCP_spec_2_3_chop_dither.txt
//
// Arguments needed to call OBCP
// Type  Name              DefCal   Description
// int   nb_up_down             1   Number of sequences: up down up ...
// int   nb_grat_steps         10   Number of grating steps
// int   nb_SRC_OFF 1               Nb cycles on/off source/grating position
// int   chop_pos_REF1       1000   Chopper position REF1
// int   nb_ramps_plateau      11   Number of ramps per chopper plateau
// int   chop_pos_REF2      -2000   Chopper position REF2 
// int   chop_pos_REF3       3000   Chopper position REF3 
// int   nb_CS1_CS2 1               Nbr cycles on cal src per grating position
// int   chop_pos_CS1      -25000   Chopper position on CS1
// int   chop_pos_CS2       25000   Chopper position on CS2
// int   grat_step_up          50   Grating step 
// int   grat_step_dn         -50   Grating step 
// int   detector               1   Synchronize on this detector 1:Blue 2:Red
// int   grat_pos                   Starting grating position
// int   grat_time                  Time for grating to move to start position
// int   comp_mode_blu             "Blue" compression
// int   comp_mode_red             "Red" compression 
// int   grat_def          50000    Grating default position
// int   chop_def              0    Chopper default position
// int   grat_def_time              Gratting time to move to grat_def position
// int   nb_rdouts_ramp             Number of readouts per ramp
//
// Description   : This script mimics the OBCP_GRATING_LINE_SCAN_CHOPPED
//                 pseudo script, section 3.9.1 in PACS-ME-LI-005
//                 This CUS version computes the duree of the
//                 observation, as specified by the input parameters.
//                 It will also send the trigger TC to start the OBCP
//
// Dependencies  : Calls "two_three_position_chopped_spectroscopy" DEC
//                 MEC sequence 4.2.1, DMC_spec_2_3_chop.txt
// Comments      : 
//
// Version       : 0.1 17-Aug-2004 Creation by DAC
// History       : 0.2 16-Sep-2004 OBCP and corresponding DMC files renamed
//                                 Block renamed as well
//                 0.3 18-Oct-2004 Normalized variable names 
//                 0.4 22-Oct-2004 Added "communication jitter" after
//                                 test on PACS QM
//                 0.5 12-Nov-2004 Added time_array elements; return duree
//                                 times in [sec]
//                 1.0 24-Mar-2005 HF modified debug_print statement
//                 1.1 11-Apr-2005 DAC Corrected returned time array
//                 1.2 22-apr-2005 DAC Changed default values to match TM's
//                 1.3 25-apr-2005 DAC Added grat_step_dn
//                 1.4 26-apr-2005 DAC Corrected name OBCP: GRAT_LINE_DITHER
//
int[] block OBCP_spec_2_3_chop_dither PACS 9 {
    int nb_up_down = 1; // Number of sequences: up down up ...
    int nb_grat_steps = 16; // Number of grating steps
    int nb_SRC_OFF = 2; // Nb cycles on/off source/grating position
    int chop_pos_REF1 = 1000; // Chopper position 1
    int nb_ramps_plateau = 3; // Number of ramps per chopper plateau
    int chop_pos_REF2 = -3000; // Chopper position 2 
    int chop_pos_REF3 = 5000; // Chopper position 3 
    int nb_CS1_CS2 = 1; // Nbr cycles on cal src per grating position
    int chop_pos_CS1 = -25000; // Chopper position on CS1
    int chop_pos_CS2 = 25000; // Chopper position on CS2
    int grat_step_up = 133; // Grating step 
    int grat_step_dn = -133; // Grating step 
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 461000; // Starting grating position
    int grat_time = 40000; // Time for grating to move to start position
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopped default position
    int grat_def_time = 20000; // Grating time to move to grat_def [msec]
    int max_dither = 100; // Maximum dither
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Register with environment
    WriteBBID($BBID);
    // Variables for time_array
    int duree_ramps = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // duree of this OBCP (computed and returned in [msec])
    int duree_msec = 0;
    // OBCP pseudo code 
    // OBCP_GRAT_LINE_SCAN_CHOPPPED_DITH(seq, seq_time, P#1,&,P#12,  
    //                          detector, grat_pos, grat_time,
    //                          comp_mode_blu, comp_mode_red, 
    //                          grat_def, chop_def, grat_def_time) 
    // Begin 
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_pos) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_MAX_DITHER(max_dith) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // (all parameters filled by DPU based on seq parameter) 
    // DMC_SYNCHRONIZE_ON_DET(detector) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, comp_mode_blu, comp_mode_red, CHHKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT (grat_time) 
    duree_msec = duree_msec + t_cmd + grat_time;
    duree_OVR = duree_OVR + t_cmd + grat_time;
    // DMC_START_SEQUENCE
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Call DEC/MEC sequence just to know the execution time
    int[] duree1 = DMC_spec_2_3_chop_dither(nb_up_down,nb_grat_steps,nb_SRC_OFF,nb_ramps_plateau,nb_CS1_CS2);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    // WAIT (seq_time) 
    duree_msec = duree_msec + t_cmd;
    duree_msec = duree_msec + seq_time;
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT (grat_def_time) 
    duree_msec = duree_msec + t_cmd + grat_def_time;
    duree_OVR = duree_OVR + t_cmd + grat_def_time;
    // Issue TM(1,7) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Now trigger execution of OBCP
    // This OBCP is number, requires 22 parameters and calls DEC/MEC #8
    string obcp_ID = "GRAT_LINE_DITHER";
    int obcp_par_nb = 23;
    int seq_DMC = 9;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_grat_steps},{5,nb_SRC_OFF},{6,chop_pos_REF1},{7,nb_ramps_plateau},{8,chop_pos_REF2},{9,chop_pos_REF3},{10,nb_CS1_CS2},{11,chop_pos_CS1},{12,chop_pos_CS2},{13,grat_step_up},{14,grat_step_dn},{15,detector},{16,grat_pos},{17,grat_time},{18,comp_mode_blu},{19,comp_mode_red},{20,grat_def},{21,chop_def},{22,grat_def_time},{23,max_dither}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    debug_print("OBCP_spec_2_3_chop_dither [sec]: " + time_array);
    delay(time_array[0]);
    // Return the array of times

    return time_array;
}

// Missionphase  : FMIST
//
// Purpose       : Move Grat Rel
//
// Author        : PR
// Arguments     : 
//
// Version       : 1.0 
// History       : 1.0 29-Jul-2007 PR
//
procedure PACS_Spec_Gra_IST_Move_Rel {
}{
    // NEW TARGET POSITION
    int gratstep = 1000;
    int delayTime = 2;
    // Move
    Pacs_DMC_MOVE_GRAT_REL_RAW(gratstep);
    delay(delayTime);
}

// File          : PACS_Spec_Flash_Setup.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Sets Flasher currents (blue & red)
//
// Author        : P. Royer
//
// Arguments     : blue & red Flasher currents
//
// Description   : Sets Flasher currents (blue & red)
//               :
// Comments      : 
//                 
//
// Version       : 1.1
// History       : 1.0 / 07-Jun-2006 initial version by PR
//                    1.1 / 12-Oct-2006 TM: change command to set the flasher current
//                            (and not the heater current)
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose Sets Flasher currents (blue & red)
// @comment - 
//
block PACS_Spec_Flash_Setup PACS 166 {
    int blue_flash_current = 0;
    int red_flash_current = 0;
}{
    // Register start of BB
    WriteBBID($BBID);
    //
    // SETUP FLASHERS
    //
    Pacs_DMC_SET_B_SPEC_FLASH_C_RAW(blue_flash_current);
    delay(1);
    Pacs_DMC_SET_R_SPEC_FLASH_C_RAW(red_flash_current);
    delay(1);
    //
    // End of procedure
    //------------------
    // Mark End of Block
    WriteEndBB();
}

// Missionphase  : FM ILT
//
// Purpose	 : SFT in Open Loop Mode (warm conditions)
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : SFT warm for FM1 chopper in open-loop mode. All 3 coils are
//                 operative. The chopper is commanded between -20 mA and +20mA
//                 in steps of 4 mA.
//                 The first part consists of chopper deflections equivalent to
//                 commanded chopper coil currents between 0 and +/-20 mA,
//                 alternating between positive and negative values. Absolute
//                 position commanding is used.
//                 The second part consists of a ramp of chopper deflections
//                 between -20 and +20 mA, commanded in relative steps of 4 mA.
//                 Finally, the chopper returns to its zero position.
//                  
// Dependencies  : 
//
// Preconditions : PACS switched-on in spectroscopy mode, chopper is switched
//                 off and disabled, diagnostic HK not running
//                 
// Comments	 : Adapted from PACS_Chopper_SFT_Cold_OpenLoop_OBS.cus
//
// Version	 : 1.0
// 
// History 	 : 1.0 12-03-07 creation by MN
// 		 : 2.0 13-02-08 Made into a proc to be called by 
//		               "obs" PacsEng_Chpper_SFT_Warm_OpenLoop
//                              Removed declaration of myOBSID
procedure PACS_Chopper_SFT_Warm_OpenLoop {
}{
    // Start diagnostic HK
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_dHK_BB("ON");
    delay(5);
    // Set default spectroscopy timing parameters
    SPEC_Chopper_SynchBlue();
    // Set Chopper Controller Parameters: CONFChopper -> SFTwarm
    CONF_chopper("CONFChopper","SFTwarm");
    delay(2);
    // Switch on chopper
    PACS_Chopper_SWON_SWOF_only("ON");
    delay(10);
    // Set open-loop mode and enable chopper
    PACS_SPEC_Chopper_SetOpenLoop_BB("ON");
    delay(1);
    EnDis_chopper("ON");
    delay(10);
    // Translate mA into ROU
    // The conversion factor is in fact 130, but we use 133 in order to be able
    // to compare the measurement with previous ones, where the same value was
    // assumed.
    double chop_max_ma = 20.0;
    // chopper maximal deflection in mA
    double chop_step_ma = 4.0;
    // chopper movement step size in mA
    int chop_damptime = 15;
    // chopper timescale in seconds allowing for
    // initial oscillation damping in open-loop mode
    double chop_max_rou = chop_max_ma * 32767.0 / 133.0;
    double chop_step_rou = chop_step_ma * 32767.0 / 133.0;
    int ichop_max_rou = iround(chop_max_rou);
    int ichop_step_rou = iround(chop_step_rou);
    // Create table of chopper positions for absolute movement
    // Starting position (integer)
    int ichop_pos = 0;
    // Array of chopper positions sequence 1
    int[] chop_steps = [];
    // Running variable
    int i = 0;
    chop_steps[i] = ichop_pos;
    i = i + 1;
    ichop_pos = ichop_pos + ichop_step_rou;
    while(ichop_pos <= ichop_max_rou) {
        chop_steps[i] = ichop_pos;
        i = i + 1;
        chop_steps[i] = -ichop_pos;
        i = i + 1;
        ichop_pos = ichop_pos + ichop_step_rou;
    }
    int len = length(chop_steps);
    //Length of array
    // First sequence: alternating chopper movement
    for(int s1 = 0 .. len - 1) {
        PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(chop_steps[s1]);
        delay(chop_damptime);
    }
    // End of first sequence
    // Move chopper to zero position
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(0);
    delay(chop_damptime);
    // Second sequence: alternating chopper movement, repeated once -> k loop
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(-5 * ichop_step_rou);
    delay(chop_damptime);
    for(int s2 = 1 .. 10) {
        PACS_SPEC_Chopper_OpenLoop_MoveRel_BB(ichop_step_rou);
        delay(chop_damptime);
    }
    // End of second sequence
    // Move chopper to zero position
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(0);
    delay(chop_damptime);
    // Disable chopper and switch off open-loop mode
    EnDis_chopper("OFF");
    PACS_SPEC_Chopper_SetOpenLoop_BB("OFF");
    delay(10);
    // Switch off chopper 
    PACS_Chopper_SWON_SWOF_only("OFF");
    delay(5);
    // Set Chopper Controller Parameters: CONFChopper -> SFTwarm
    CONF_chopper("CONFChopper","SFTwarm");
    delay(2);
    // Stop diagnostic HK
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_dHK_BB("OFF");
}

//$Id:
// Purpose       : Set the BBID and OBSID to the predefined values shown
//                 in FIRST-FSC-DOC-0200 
//
// CUS script    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
// Original TCL  : N/A
// CVS file      : WriteEndID.txt
//
// Input arguments 
// Type  Name     DefVal  Description
//
// Description   : Equivalent of WriteOBSID and WriteBBID but using preset
//                 values for $OBSID and $BBID
//
// Dependencies  : Pacs_DMC_SET_BBID and Pacs_DMC_SET_OBSID
//
// Comments      : 
//
// Version       : 0.1 12-Oct-2004 First creation
// History       : 0.1 cloned from WriteEndID
//                PHS-1164
// 
//
block PacsBbWriteEndID PACS 1107 {
}{
    int iOBSID = 0x50000000;
    // Write OBSID to DEC/MEC
    Pacs_DMC_SET_OBSID(iOBSID);
    sync();
}

// Mission phase : ILT at Garching
//
// Purpose :
//   Reduced NEP measurements for the new sequencer test
//
// Author : Koryo Okumura
//
// CUS script : procedure PHOT_redArray_alternatePolarisation_DDCS_IST
//
// Argument :
//    int response_measure_time = 60; // response measure time in seconds
//    int noise_measure_time = 120; // noise measure time in seconds
//    int lowFreq_noise_time = 1800; // long noise measure time in seconds
//    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//
// Description :
//   + First, all 24 biases are set group by group
//   + Loop over 11 sets of 4 baisc biases (VH, VL, VRL, VH-BLIND) are set group by group
//   + Set PACS chopper on CS1 to measure the noise
//   + Loop over 11 sets of 4 baisc biases (VH, VL, VRL, VH-BLIND) are set group by group
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_newSeq_IST(0)
//
// Version : Thu Oct 04 20:26:01 CEST 2007
//
procedure PHOT_redArray_alternatePolarisation_DDCS_IST {
    int response_measure_time = 60; // response measure time in seconds
    int noise_measure_time = 120; // noise measure time in seconds
    int lowFreq_noise_time = 1800; // long noise measure time in seconds
    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
}{
    int operand = 0;
    int posCS1 = -21500;
    int posCS2 = 21500;
    //*********************************
    // Apply the new sequencer setting
    //*********************************
    //
    PACS_Phot_Sequencer_SetupNew();
    //
    //*******************************
    // Select Filter A (110 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //***********************************************
    //***********************************************
    //
    //	Bias setting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(biasFile,1);
    PHOT_set_bias_volt(biasFile,2);
    PHOT_set_bias_volt(biasFile,3);
    PHOT_set_bias_volt(biasFile,4);
    PHOT_set_bias_volt(biasFile,5);
    PHOT_set_bias_volt(biasFile,6);
    //
    //**************************
    // Sequence mode : Sb_Sref
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sb_Sref (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sb_Sref");
    //# P 09 01 00 00
    operand = 0x9010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // Set gain high
    Pacs_BOLC_SET_GAIN("HIGH");
    //
    //**********************************************
    // Set the PACS chopper at the central position
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(0);
    //
    //**********************************************************************
    //                       Response Measurement
    // Expected fluxes : 1.7 and 2.0pW on the blue
    //               and 5.3 and 6.2pW on the red
    //**********************************************************************
    //
    TMMarker600();
    //***********************************************************
    // Bias 1 (Vh-Vl)blue = 1.0 Volts, (Vh-Vl)red = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G1(0.99);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.2875928897414196 Volts
    Pacs_BOLC_SET_VRL_G1(0.2875928897414196);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.78435816010763 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.78435816010763);
    // Set group 2 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G2(0.99);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.2976890643549285 Volts
    Pacs_BOLC_SET_VRL_G2(0.2976890643549285);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.7946385038224304 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.7946385038224304);
    // Set group 3 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G3(0.99);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.2921869021406959 Volts
    Pacs_BOLC_SET_VRL_G3(0.2921869021406959);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.8111181679623898 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.8111181679623898);
    // Set group 4 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G4(0.99);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.2833032550752384 Volts
    Pacs_BOLC_SET_VRL_G4(0.2833032550752384);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.8038951101792082 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.8038951101792082);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3346340277410602 Volts
    Pacs_BOLC_SET_VRL_G5(0.3346340277410602);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8466792279676985 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8466792279676985);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.32636237036822335 Volts
    Pacs_BOLC_SET_VRL_G6(0.32636237036822335);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8367532617835844 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8367532617835844);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)blue = 1.2 Volts, (Vh-Vl)red = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G1(1.19);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.3577080013822565 Volts
    Pacs_BOLC_SET_VRL_G1(0.3577080013822565);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9420622421434064 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9420622421434064);
    // Set group 2 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G2(1.19);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.36696811904468774 Volts
    Pacs_BOLC_SET_VRL_G2(0.36696811904468774);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9515329512935697 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9515329512935697);
    // Set group 3 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G3(1.19);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.3640303856110917 Volts
    Pacs_BOLC_SET_VRL_G3(0.3640303856110917);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9482056457093682 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9482056457093682);
    // Set group 4 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G4(1.19);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3523579205628669 Volts
    Pacs_BOLC_SET_VRL_G4(0.3523579205628669);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9603646239045185 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9603646239045185);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4064368830411808 Volts
    Pacs_BOLC_SET_VRL_G5(0.4064368830411808);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8950576820742784 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8950576820742784);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.39643145192214363 Volts
    Pacs_BOLC_SET_VRL_G6(0.39643145192214363);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8837201139355604 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8837201139355604);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)blue = 1.4 Volts, (Vh-Vl)red = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.3525857926230986 Volts
    Pacs_BOLC_SET_VH_G1(1.3525857926230986);
    // Set group 1 bol bias 02 (VL) to -0.047414207376901184 Volts
    Pacs_BOLC_SET_VL_G1(-0.047414207376901184);
    // Set group 1 bol bias 03 (VRL) to 0.3926244201072773 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926244201072773);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.976547929868054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.976547929868054);
    // Set group 2 bol bias 01 (VH) to 1.3374255283716547 Volts
    Pacs_BOLC_SET_VH_G2(1.3374255283716547);
    // Set group 2 bol bias 02 (VL) to -0.06257447162834509 Volts
    Pacs_BOLC_SET_VL_G2(-0.06257447162834509);
    // Set group 2 bol bias 03 (VRL) to 0.38802799053825054 Volts
    Pacs_BOLC_SET_VRL_G2(0.38802799053825054);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9723540060682856 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9723540060682856);
    // Set group 3 bol bias 01 (VH) to 1.341267296137658 Volts
    Pacs_BOLC_SET_VH_G3(1.341267296137658);
    // Set group 3 bol bias 02 (VL) to -0.058732703862341994 Volts
    Pacs_BOLC_SET_VL_G3(-0.058732703862341994);
    // Set group 3 bol bias 03 (VRL) to 0.38970189090896923 Volts
    Pacs_BOLC_SET_VRL_G3(0.38970189090896923);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9735810667835696 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9735810667835696);
    // Set group 4 bol bias 01 (VH) to 1.352746675150765 Volts
    Pacs_BOLC_SET_VH_G4(1.352746675150765);
    // Set group 4 bol bias 02 (VL) to -0.04725332484923491 Volts
    Pacs_BOLC_SET_VL_G4(-0.04725332484923491);
    // Set group 4 bol bias 03 (VRL) to 0.3856108728986011 Volts
    Pacs_BOLC_SET_VRL_G4(0.3856108728986011);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9932003720526934 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9932003720526934);
    // Set group 5 bol bias 01 (VH) to 1.320583197395035 Volts
    Pacs_BOLC_SET_VH_G5(1.320583197395035);
    // Set group 5 bol bias 02 (VL) to -0.07941680260496485 Volts
    Pacs_BOLC_SET_VL_G5(-0.07941680260496485);
    // Set group 5 bol bias 03 (VRL) to 0.4116095244710064 Volts
    Pacs_BOLC_SET_VRL_G5(0.4116095244710064);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055742088043621 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055742088043621);
    // Set group 6 bol bias 01 (VH) to 1.3562697990163495 Volts
    Pacs_BOLC_SET_VH_G6(1.3562697990163495);
    // Set group 6 bol bias 02 (VL) to -0.04373020098365052 Volts
    Pacs_BOLC_SET_VL_G6(-0.04373020098365052);
    // Set group 6 bol bias 03 (VRL) to 0.43594530124025854 Volts
    Pacs_BOLC_SET_VRL_G6(0.43594530124025854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.011921670046162 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.011921670046162);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)blue = 1.6 Volts, (Vh-Vl)red = 1.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4783736198117614 Volts
    Pacs_BOLC_SET_VH_G1(1.4783736198117614);
    // Set group 1 bol bias 02 (VL) to -0.12162638018823857 Volts
    Pacs_BOLC_SET_VL_G1(-0.12162638018823857);
    // Set group 1 bol bias 03 (VRL) to 0.392515090355521 Volts
    Pacs_BOLC_SET_VRL_G1(0.392515090355521);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9764399412468519 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9764399412468519);
    // Set group 2 bol bias 01 (VH) to 1.4615686869832905 Volts
    Pacs_BOLC_SET_VH_G2(1.4615686869832905);
    // Set group 2 bol bias 02 (VL) to -0.13843131301670974 Volts
    Pacs_BOLC_SET_VL_G2(-0.13843131301670974);
    // Set group 2 bol bias 03 (VRL) to 0.3878839845398352 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878839845398352);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9722117106846373 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9722117106846373);
    // Set group 3 bol bias 01 (VH) to 1.4655563032867613 Volts
    Pacs_BOLC_SET_VH_G3(1.4655563032867613);
    // Set group 3 bol bias 02 (VL) to -0.13444369671323875 Volts
    Pacs_BOLC_SET_VL_G3(-0.13444369671323875);
    // Set group 3 bol bias 03 (VRL) to 0.38996914633068824 Volts
    Pacs_BOLC_SET_VRL_G3(0.38996914633068824);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9738455591218464 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9738455591218464);
    // Set group 4 bol bias 01 (VH) to 1.4803815567917744 Volts
    Pacs_BOLC_SET_VH_G4(1.4803815567917744);
    // Set group 4 bol bias 02 (VL) to -0.11961844320822568 Volts
    Pacs_BOLC_SET_VL_G4(-0.11961844320822568);
    // Set group 4 bol bias 03 (VRL) to 0.3860593630979322 Volts
    Pacs_BOLC_SET_VRL_G4(0.3860593630979322);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9936441996882226 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9936441996882226);
    // Set group 5 bol bias 01 (VH) to 1.3828510880972673 Volts
    Pacs_BOLC_SET_VH_G5(1.3828510880972673);
    // Set group 5 bol bias 02 (VL) to -0.11714891190273273 Volts
    Pacs_BOLC_SET_VL_G5(-0.11714891190273273);
    // Set group 5 bol bias 03 (VRL) to 0.4109562973201683 Volts
    Pacs_BOLC_SET_VRL_G5(0.4109562973201683);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055094312734005 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055094312734005);
    // Set group 6 bol bias 01 (VH) to 1.4187389541758537 Volts
    Pacs_BOLC_SET_VH_G6(1.4187389541758537);
    // Set group 6 bol bias 02 (VL) to -0.08126104582414631 Volts
    Pacs_BOLC_SET_VL_G6(-0.08126104582414631);
    // Set group 6 bol bias 03 (VRL) to 0.4349651037009118 Volts
    Pacs_BOLC_SET_VRL_G6(0.4349651037009118);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0109400872654906 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0109400872654906);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)blue = 1.7 Volts, (Vh-Vl)red = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.542293926761549 Volts
    Pacs_BOLC_SET_VH_G1(1.542293926761549);
    // Set group 1 bol bias 02 (VL) to -0.15770607323845098 Volts
    Pacs_BOLC_SET_VL_G1(-0.15770607323845098);
    // Set group 1 bol bias 03 (VRL) to 0.3926294451860477 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926294451860477);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9765528932845227 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9765528932845227);
    // Set group 2 bol bias 01 (VH) to 1.5247596019367946 Volts
    Pacs_BOLC_SET_VH_G2(1.5247596019367946);
    // Set group 2 bol bias 02 (VL) to -0.17524039806320546 Volts
    Pacs_BOLC_SET_VL_G2(-0.17524039806320546);
    // Set group 2 bol bias 03 (VRL) to 0.3878550325870832 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878550325870832);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9721831025166574 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9721831025166574);
    // Set group 3 bol bias 01 (VH) to 1.5286400044176514 Volts
    Pacs_BOLC_SET_VH_G3(1.5286400044176514);
    // Set group 3 bol bias 02 (VL) to -0.1713599955823485 Volts
    Pacs_BOLC_SET_VL_G3(-0.1713599955823485);
    // Set group 3 bol bias 03 (VRL) to 0.3901485670988867 Volts
    Pacs_BOLC_SET_VRL_G3(0.3901485670988867);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9740231261405279 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9740231261405279);
    // Set group 4 bol bias 01 (VH) to 1.5451742923820575 Volts
    Pacs_BOLC_SET_VH_G4(1.5451742923820575);
    // Set group 4 bol bias 02 (VL) to -0.15482570761794245 Volts
    Pacs_BOLC_SET_VL_G4(-0.15482570761794245);
    // Set group 4 bol bias 03 (VRL) to 0.3871858356177216 Volts
    Pacs_BOLC_SET_VRL_G4(0.3871858356177216);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9947589297629622 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9947589297629622);
    // Set group 5 bol bias 01 (VH) to 1.4463934011524333 Volts
    Pacs_BOLC_SET_VH_G5(1.4463934011524333);
    // Set group 5 bol bias 02 (VL) to -0.15360659884756683 Volts
    Pacs_BOLC_SET_VL_G5(-0.15360659884756683);
    // Set group 5 bol bias 03 (VRL) to 0.4101701125060366 Volts
    Pacs_BOLC_SET_VRL_G5(0.4101701125060366);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.054314719447538 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.054314719447538);
    // Set group 6 bol bias 01 (VH) to 1.4826068632993925 Volts
    Pacs_BOLC_SET_VH_G6(1.4826068632993925);
    // Set group 6 bol bias 02 (VL) to -0.11739313670060761 Volts
    Pacs_BOLC_SET_VL_G6(-0.11739313670060761);
    // Set group 6 bol bias 03 (VRL) to 0.4338779750444286 Volts
    Pacs_BOLC_SET_VRL_G6(0.4338779750444286);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.009851264439135 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.009851264439135);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)blue = 1.8 Volts, (Vh-Vl)red = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.60690529764583 Volts
    Pacs_BOLC_SET_VH_G1(1.60690529764583);
    // Set group 1 bol bias 02 (VL) to -0.19309470235416992 Volts
    Pacs_BOLC_SET_VL_G1(-0.19309470235416992);
    // Set group 1 bol bias 03 (VRL) to 0.39257168553053945 Volts
    Pacs_BOLC_SET_VRL_G1(0.39257168553053945);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9987180645064364 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9987180645064364);
    // Set group 2 bol bias 01 (VH) to 1.5888225493633414 Volts
    Pacs_BOLC_SET_VH_G2(1.5888225493633414);
    // Set group 2 bol bias 02 (VL) to -0.2111774506366586 Volts
    Pacs_BOLC_SET_VL_G2(-0.2111774506366586);
    // Set group 2 bol bias 03 (VRL) to 0.387719891228717 Volts
    Pacs_BOLC_SET_VRL_G2(0.387719891228717);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9720495652990864 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9720495652990864);
    // Set group 3 bol bias 01 (VH) to 1.5926816774791708 Volts
    Pacs_BOLC_SET_VH_G3(1.5926816774791708);
    // Set group 3 bol bias 02 (VL) to -0.20731832252082927 Volts
    Pacs_BOLC_SET_VL_G3(-0.20731832252082927);
    // Set group 3 bol bias 03 (VRL) to 0.39036266684895493 Volts
    Pacs_BOLC_SET_VRL_G3(0.39036266684895493);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.974235015140725 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.974235015140725);
    // Set group 4 bol bias 01 (VH) to 1.6103713769916332 Volts
    Pacs_BOLC_SET_VH_G4(1.6103713769916332);
    // Set group 4 bol bias 02 (VL) to -0.1896286230083667 Volts
    Pacs_BOLC_SET_VL_G4(-0.1896286230083667);
    // Set group 4 bol bias 03 (VRL) to 0.38763171869999546 Volts
    Pacs_BOLC_SET_VRL_G4(0.38763171869999546);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9952001524800798 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9952001524800798);
    // Set group 5 bol bias 01 (VH) to 1.575230733402161 Volts
    Pacs_BOLC_SET_VH_G5(1.575230733402161);
    // Set group 5 bol bias 02 (VL) to -0.22476926659783908 Volts
    Pacs_BOLC_SET_VL_G5(-0.22476926659783908);
    // Set group 5 bol bias 03 (VRL) to 0.40838061675412257 Volts
    Pacs_BOLC_SET_VRL_G5(0.40838061675412257);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.052540349440553 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.052540349440553);
    // Set group 6 bol bias 01 (VH) to 1.6128643450774607 Volts
    Pacs_BOLC_SET_VH_G6(1.6128643450774607);
    // Set group 6 bol bias 02 (VL) to -0.1871356549225394 Volts
    Pacs_BOLC_SET_VL_G6(-0.1871356549225394);
    // Set group 6 bol bias 03 (VRL) to 0.4319097861053989 Volts
    Pacs_BOLC_SET_VRL_G6(0.4319097861053989);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.007881605555887 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.007881605555887);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)blue = 2.0 Volts, (Vh-Vl)red = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.739376176417995 Volts
    Pacs_BOLC_SET_VH_G1(1.739376176417995);
    // Set group 1 bol bias 02 (VL) to -0.2606238235820051 Volts
    Pacs_BOLC_SET_VL_G1(-0.2606238235820051);
    // Set group 1 bol bias 03 (VRL) to 0.3921536831520859 Volts
    Pacs_BOLC_SET_VRL_G1(0.3921536831520859);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9760829613086472 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9760829613086472);
    // Set group 2 bol bias 01 (VH) to 1.719809813472755 Volts
    Pacs_BOLC_SET_VH_G2(1.719809813472755);
    // Set group 2 bol bias 02 (VL) to -0.28019018652724503 Volts
    Pacs_BOLC_SET_VL_G2(-0.28019018652724503);
    // Set group 2 bol bias 03 (VRL) to 0.38744168454874117 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744168454874117);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9717746579976725 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9717746579976725);
    // Set group 3 bol bias 01 (VH) to 1.7343527587435847 Volts
    Pacs_BOLC_SET_VH_G3(1.7343527587435847);
    // Set group 3 bol bias 02 (VL) to -0.2656472412564153 Volts
    Pacs_BOLC_SET_VL_G3(-0.2656472412564153);
    // Set group 3 bol bias 03 (VRL) to 0.4017790445564455 Volts
    Pacs_BOLC_SET_VRL_G3(0.4017790445564455);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9855314406558735 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9855314406558735);
    // Set group 4 bol bias 01 (VH) to 1.7440573141484068 Volts
    Pacs_BOLC_SET_VH_G4(1.7440573141484068);
    // Set group 4 bol bias 02 (VL) to -0.2559426858515932 Volts
    Pacs_BOLC_SET_VL_G4(-0.2559426858515932);
    // Set group 4 bol bias 03 (VRL) to 0.38894738596666634 Volts
    Pacs_BOLC_SET_VRL_G4(0.38894738596666634);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.996502027278406 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.996502027278406);
    // Set group 5 bol bias 01 (VH) to 1.6403549621270441 Volts
    Pacs_BOLC_SET_VH_G5(1.6403549621270441);
    // Set group 5 bol bias 02 (VL) to -0.25964503787295584 Volts
    Pacs_BOLC_SET_VL_G5(-0.25964503787295584);
    // Set group 5 bol bias 03 (VRL) to 0.4071234038646236 Volts
    Pacs_BOLC_SET_VRL_G5(0.4071234038646236);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051293864758269 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051293864758269);
    // Set group 6 bol bias 01 (VH) to 1.6787311020540112 Volts
    Pacs_BOLC_SET_VH_G6(1.6787311020540112);
    // Set group 6 bol bias 02 (VL) to -0.22126889794598872 Volts
    Pacs_BOLC_SET_VL_G6(-0.22126889794598872);
    // Set group 6 bol bias 03 (VRL) to 0.4305158637367362 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305158637367362);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0064867220677454 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0064867220677454);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)blue = 2.3 Volts, (Vh-Vl)red = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.9636608873020274 Volts
    Pacs_BOLC_SET_VH_G1(1.9636608873020274);
    // Set group 1 bol bias 02 (VL) to -0.3363391126979725 Volts
    Pacs_BOLC_SET_VL_G1(-0.3363391126979725);
    // Set group 1 bol bias 03 (VRL) to 0.40278769107629514 Volts
    Pacs_BOLC_SET_VRL_G1(0.40278769107629514);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9865763456310306 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9865763456310306);
    // Set group 2 bol bias 01 (VH) to 1.927696912686972 Volts
    Pacs_BOLC_SET_VH_G2(1.927696912686972);
    // Set group 2 bol bias 02 (VL) to -0.37230308731302775 Volts
    Pacs_BOLC_SET_VL_G2(-0.37230308731302775);
    // Set group 2 bol bias 03 (VRL) to 0.3858403551587576 Volts
    Pacs_BOLC_SET_VRL_G2(0.3858403551587576);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9924144642105024 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9924144642105024);
    // Set group 3 bol bias 01 (VH) to 1.9431226670014545 Volts
    Pacs_BOLC_SET_VH_G3(1.9431226670014545);
    // Set group 3 bol bias 02 (VL) to -0.35687733299854535 Volts
    Pacs_BOLC_SET_VL_G3(-0.35687733299854535);
    // Set group 3 bol bias 03 (VRL) to 0.4024839037666154 Volts
    Pacs_BOLC_SET_VRL_G3(0.4024839037666154);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9862268670149914 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9862268670149914);
    // Set group 4 bol bias 01 (VH) to 1.9579270398291708 Volts
    Pacs_BOLC_SET_VH_G4(1.9579270398291708);
    // Set group 4 bol bias 02 (VL) to -0.3420729601708289 Volts
    Pacs_BOLC_SET_VL_G4(-0.3420729601708289);
    // Set group 4 bol bias 03 (VRL) to 0.3906771012878555 Volts
    Pacs_BOLC_SET_VRL_G4(0.3906771012878555);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.99821351608857 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.99821351608857);
    // Set group 5 bol bias 01 (VH) to 1.7079035410760286 Volts
    Pacs_BOLC_SET_VH_G5(1.7079035410760286);
    // Set group 5 bol bias 02 (VL) to -0.29209645892397146 Volts
    Pacs_BOLC_SET_VL_G5(-0.29209645892397146);
    // Set group 5 bol bias 03 (VRL) to 0.405804322083024 Volts
    Pacs_BOLC_SET_VRL_G5(0.405804322083024);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0499861292550787 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0499861292550787);
    // Set group 6 bol bias 01 (VH) to 1.7476622867412348 Volts
    Pacs_BOLC_SET_VH_G6(1.7476622867412348);
    // Set group 6 bol bias 02 (VL) to -0.2523377132587652 Volts
    Pacs_BOLC_SET_VL_G6(-0.2523377132587652);
    // Set group 6 bol bias 03 (VRL) to 0.429562228366719 Volts
    Pacs_BOLC_SET_VRL_G6(0.429562228366719);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.005532468489443 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.005532468489443);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)blue = 2.6 Volts, (Vh-Vl)red = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2151628880310112 Volts
    Pacs_BOLC_SET_VH_G1(2.2151628880310112);
    // Set group 1 bol bias 02 (VL) to -0.3848371119689889 Volts
    Pacs_BOLC_SET_VL_G1(-0.3848371119689889);
    // Set group 1 bol bias 03 (VRL) to 0.41342338183313837 Volts
    Pacs_BOLC_SET_VRL_G1(0.41342338183313837);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0193446104924915 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0193446104924915);
    // Set group 2 bol bias 01 (VH) to 2.1588489399994213 Volts
    Pacs_BOLC_SET_VH_G2(2.1588489399994213);
    // Set group 2 bol bias 02 (VL) to -0.4411510600005787 Volts
    Pacs_BOLC_SET_VL_G2(-0.4411510600005787);
    // Set group 2 bol bias 03 (VRL) to 0.3838811209851186 Volts
    Pacs_BOLC_SET_VRL_G2(0.3838811209851186);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9682559687629309 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9682559687629309);
    // Set group 3 bol bias 01 (VH) to 2.1867239063317037 Volts
    Pacs_BOLC_SET_VH_G3(2.1867239063317037);
    // Set group 3 bol bias 02 (VL) to -0.4132760936682966 Volts
    Pacs_BOLC_SET_VL_G3(-0.4132760936682966);
    // Set group 3 bol bias 03 (VRL) to 0.4136603871411812 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136603871411812);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9973179392427267 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9973179392427267);
    // Set group 4 bol bias 01 (VH) to 2.20827452044462 Volts
    Pacs_BOLC_SET_VH_G4(2.20827452044462);
    // Set group 4 bol bias 02 (VL) to -0.39172547955538 Volts
    Pacs_BOLC_SET_VL_G4(-0.39172547955538);
    // Set group 4 bol bias 03 (VRL) to 0.4039414339062088 Volts
    Pacs_BOLC_SET_VRL_G4(0.4039414339062088);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.011301244644244 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.011301244644244);
    // Set group 5 bol bias 01 (VH) to 1.7875017871866707 Volts
    Pacs_BOLC_SET_VH_G5(1.7875017871866707);
    // Set group 5 bol bias 02 (VL) to -0.31249821281332946 Volts
    Pacs_BOLC_SET_VL_G5(-0.31249821281332946);
    // Set group 5 bol bias 03 (VRL) to 0.41576367399178094 Volts
    Pacs_BOLC_SET_VRL_G5(0.41576367399178094);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.037668873916454 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.037668873916454);
    // Set group 6 bol bias 01 (VH) to 1.8172008318899895 Volts
    Pacs_BOLC_SET_VH_G6(1.8172008318899895);
    // Set group 6 bol bias 02 (VL) to -0.2827991681100106 Volts
    Pacs_BOLC_SET_VL_G6(-0.2827991681100106);
    // Set group 6 bol bias 03 (VRL) to 0.42845474144203777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42845474144203777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.004424303719793 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.004424303719793);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)blue = 2.9 Volts, (Vh-Vl)red = 2.3 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.517666343337925 Volts
    Pacs_BOLC_SET_VH_G1(2.517666343337925);
    // Set group 1 bol bias 02 (VL) to -0.382333656662075 Volts
    Pacs_BOLC_SET_VL_G1(-0.382333656662075);
    // Set group 1 bol bias 03 (VRL) to 0.4351367995957048 Volts
    Pacs_BOLC_SET_VRL_G1(0.4351367995957048);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9965703186107444 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9965703186107444);
    // Set group 2 bol bias 01 (VH) to 2.4353683146246183 Volts
    Pacs_BOLC_SET_VH_G2(2.4353683146246183);
    // Set group 2 bol bias 02 (VL) to -0.4646316853753816 Volts
    Pacs_BOLC_SET_VL_G2(-0.4646316853753816);
    // Set group 2 bol bias 03 (VRL) to 0.39230855172448975 Volts
    Pacs_BOLC_SET_VRL_G2(0.39230855172448975);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9765832317921543 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9765832317921543);
    // Set group 3 bol bias 01 (VH) to 2.4565430314555052 Volts
    Pacs_BOLC_SET_VH_G3(2.4565430314555052);
    // Set group 3 bol bias 02 (VL) to -0.4434569685444947 Volts
    Pacs_BOLC_SET_VL_G3(-0.4434569685444947);
    // Set group 3 bol bias 03 (VRL) to 0.4116559215687209 Volts
    Pacs_BOLC_SET_VRL_G3(0.4116559215687209);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175436768747823 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175436768747823);
    // Set group 4 bol bias 01 (VH) to 2.4726040303622487 Volts
    Pacs_BOLC_SET_VH_G4(2.4726040303622487);
    // Set group 4 bol bias 02 (VL) to -0.4273959696377513 Volts
    Pacs_BOLC_SET_VL_G4(-0.4273959696377513);
    // Set group 4 bol bias 03 (VRL) to 0.3940712295914811 Volts
    Pacs_BOLC_SET_VRL_G4(0.3940712295914811);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.023793793137234 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.023793793137234);
    // Set group 5 bol bias 01 (VH) to 1.9226793871045598 Volts
    Pacs_BOLC_SET_VH_G5(1.9226793871045598);
    // Set group 5 bol bias 02 (VL) to -0.37732061289544 Volts
    Pacs_BOLC_SET_VL_G5(-0.37732061289544);
    // Set group 5 bol bias 03 (VRL) to 0.40093587460771146 Volts
    Pacs_BOLC_SET_VRL_G5(0.40093587460771146);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.022938134951507 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.022938134951507);
    // Set group 6 bol bias 01 (VH) to 1.9672658597937258 Volts
    Pacs_BOLC_SET_VH_G6(1.9672658597937258);
    // Set group 6 bol bias 02 (VL) to -0.332734140206274 Volts
    Pacs_BOLC_SET_VL_G6(-0.332734140206274);
    // Set group 6 bol bias 03 (VRL) to 0.4263945599495246 Volts
    Pacs_BOLC_SET_VRL_G6(0.4263945599495246);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.002362975913312 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.002362975913312);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)blue = 3.2 Volts, (Vh-Vl)red = 2.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.847199981495237 Volts
    Pacs_BOLC_SET_VH_G1(2.847199981495237);
    // Set group 1 bol bias 02 (VL) to -0.3528000185047631 Volts
    Pacs_BOLC_SET_VL_G1(-0.3528000185047631);
    // Set group 1 bol bias 03 (VRL) to 0.4347941377293029 Volts
    Pacs_BOLC_SET_VRL_G1(0.4347941377293029);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.018449774761696 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.018449774761696);
    // Set group 2 bol bias 01 (VH) to 2.7602559944480873 Volts
    Pacs_BOLC_SET_VH_G2(2.7602559944480873);
    // Set group 2 bol bias 02 (VL) to -0.43974400555191273 Volts
    Pacs_BOLC_SET_VL_G2(-0.43974400555191273);
    // Set group 2 bol bias 03 (VRL) to 0.4036708891743245 Volts
    Pacs_BOLC_SET_VRL_G2(0.4036708891743245);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.0099936291338243 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.0099936291338243);
    // Set group 3 bol bias 01 (VH) to 2.805732095961401 Volts
    Pacs_BOLC_SET_VH_G3(2.805732095961401);
    // Set group 3 bol bias 02 (VL) to -0.3942679040385992 Volts
    Pacs_BOLC_SET_VL_G3(-0.3942679040385992);
    // Set group 3 bol bias 03 (VRL) to 0.4339248022480186 Volts
    Pacs_BOLC_SET_VRL_G3(0.4339248022480186);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175166229478236 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175166229478236);
    // Set group 4 bol bias 01 (VH) to 2.8132260321912117 Volts
    Pacs_BOLC_SET_VH_G4(2.8132260321912117);
    // Set group 4 bol bias 02 (VL) to -0.3867739678087883 Volts
    Pacs_BOLC_SET_VL_G4(-0.3867739678087883);
    // Set group 4 bol bias 03 (VRL) to 0.4141623922109569 Volts
    Pacs_BOLC_SET_VRL_G4(0.4141623922109569);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.0213933637092976 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.0213933637092976);
    // Set group 5 bol bias 01 (VH) to 2.1145200531318697 Volts
    Pacs_BOLC_SET_VH_G5(2.1145200531318697);
    // Set group 5 bol bias 02 (VL) to -0.38547994686813014 Volts
    Pacs_BOLC_SET_VL_G5(-0.38547994686813014);
    // Set group 5 bol bias 03 (VRL) to 0.4292977832137159 Volts
    Pacs_BOLC_SET_VRL_G5(0.4292977832137159);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.006817368773259 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.006817368773259);
    // Set group 6 bol bias 01 (VH) to 2.1293608950052523 Volts
    Pacs_BOLC_SET_VH_G6(2.1293608950052523);
    // Set group 6 bol bias 02 (VL) to -0.3706391049947475 Volts
    Pacs_BOLC_SET_VL_G6(-0.3706391049947475);
    // Set group 6 bol bias 03 (VRL) to 0.4231555942593115 Volts
    Pacs_BOLC_SET_VRL_G6(0.4231555942593115);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9769002872568586 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9769002872568586);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //
    //
    //************************************************************************
    //                           Noise Measurement
    // Expected fluxes : 1.7pW on the blue and 5.3pW on the red detector
    //************************************************************************
    //
    //*****************************
    // Set the PACS chopper on CS1
    //*****************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(posCS1);
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)blue = 1.0 Volts, (Vh-Vl)red = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G1(0.99);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.2875928897414196 Volts
    Pacs_BOLC_SET_VRL_G1(0.2875928897414196);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.78435816010763 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.78435816010763);
    // Set group 2 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G2(0.99);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.2976890643549285 Volts
    Pacs_BOLC_SET_VRL_G2(0.2976890643549285);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.7946385038224304 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.7946385038224304);
    // Set group 3 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G3(0.99);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.2921869021406959 Volts
    Pacs_BOLC_SET_VRL_G3(0.2921869021406959);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.8111181679623898 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.8111181679623898);
    // Set group 4 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G4(0.99);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.2833032550752384 Volts
    Pacs_BOLC_SET_VRL_G4(0.2833032550752384);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.8038951101792082 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.8038951101792082);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3346340277410602 Volts
    Pacs_BOLC_SET_VRL_G5(0.3346340277410602);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8466792279676985 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8466792279676985);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.32636237036822335 Volts
    Pacs_BOLC_SET_VRL_G6(0.32636237036822335);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8367532617835844 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8367532617835844);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)blue = 1.2 Volts, (Vh-Vl)red = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G1(1.19);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.3577080013822565 Volts
    Pacs_BOLC_SET_VRL_G1(0.3577080013822565);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9420622421434064 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9420622421434064);
    // Set group 2 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G2(1.19);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.36696811904468774 Volts
    Pacs_BOLC_SET_VRL_G2(0.36696811904468774);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9515329512935697 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9515329512935697);
    // Set group 3 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G3(1.19);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.3640303856110917 Volts
    Pacs_BOLC_SET_VRL_G3(0.3640303856110917);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9482056457093682 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9482056457093682);
    // Set group 4 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G4(1.19);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3523579205628669 Volts
    Pacs_BOLC_SET_VRL_G4(0.3523579205628669);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9603646239045185 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9603646239045185);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4064368830411808 Volts
    Pacs_BOLC_SET_VRL_G5(0.4064368830411808);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8950576820742784 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8950576820742784);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.39643145192214363 Volts
    Pacs_BOLC_SET_VRL_G6(0.39643145192214363);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8837201139355604 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8837201139355604);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)blue = 1.4 Volts, (Vh-Vl)red = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.3525857926230986 Volts
    Pacs_BOLC_SET_VH_G1(1.3525857926230986);
    // Set group 1 bol bias 02 (VL) to -0.047414207376901184 Volts
    Pacs_BOLC_SET_VL_G1(-0.047414207376901184);
    // Set group 1 bol bias 03 (VRL) to 0.3926244201072773 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926244201072773);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.976547929868054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.976547929868054);
    // Set group 2 bol bias 01 (VH) to 1.3374255283716547 Volts
    Pacs_BOLC_SET_VH_G2(1.3374255283716547);
    // Set group 2 bol bias 02 (VL) to -0.06257447162834509 Volts
    Pacs_BOLC_SET_VL_G2(-0.06257447162834509);
    // Set group 2 bol bias 03 (VRL) to 0.38802799053825054 Volts
    Pacs_BOLC_SET_VRL_G2(0.38802799053825054);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9723540060682856 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9723540060682856);
    // Set group 3 bol bias 01 (VH) to 1.341267296137658 Volts
    Pacs_BOLC_SET_VH_G3(1.341267296137658);
    // Set group 3 bol bias 02 (VL) to -0.058732703862341994 Volts
    Pacs_BOLC_SET_VL_G3(-0.058732703862341994);
    // Set group 3 bol bias 03 (VRL) to 0.38970189090896923 Volts
    Pacs_BOLC_SET_VRL_G3(0.38970189090896923);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9735810667835696 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9735810667835696);
    // Set group 4 bol bias 01 (VH) to 1.352746675150765 Volts
    Pacs_BOLC_SET_VH_G4(1.352746675150765);
    // Set group 4 bol bias 02 (VL) to -0.04725332484923491 Volts
    Pacs_BOLC_SET_VL_G4(-0.04725332484923491);
    // Set group 4 bol bias 03 (VRL) to 0.3856108728986011 Volts
    Pacs_BOLC_SET_VRL_G4(0.3856108728986011);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9932003720526934 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9932003720526934);
    // Set group 5 bol bias 01 (VH) to 1.320583197395035 Volts
    Pacs_BOLC_SET_VH_G5(1.320583197395035);
    // Set group 5 bol bias 02 (VL) to -0.07941680260496485 Volts
    Pacs_BOLC_SET_VL_G5(-0.07941680260496485);
    // Set group 5 bol bias 03 (VRL) to 0.4116095244710064 Volts
    Pacs_BOLC_SET_VRL_G5(0.4116095244710064);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055742088043621 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055742088043621);
    // Set group 6 bol bias 01 (VH) to 1.3562697990163495 Volts
    Pacs_BOLC_SET_VH_G6(1.3562697990163495);
    // Set group 6 bol bias 02 (VL) to -0.04373020098365052 Volts
    Pacs_BOLC_SET_VL_G6(-0.04373020098365052);
    // Set group 6 bol bias 03 (VRL) to 0.43594530124025854 Volts
    Pacs_BOLC_SET_VRL_G6(0.43594530124025854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.011921670046162 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.011921670046162);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)blue = 1.6 Volts, (Vh-Vl)red = 1.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4783736198117614 Volts
    Pacs_BOLC_SET_VH_G1(1.4783736198117614);
    // Set group 1 bol bias 02 (VL) to -0.12162638018823857 Volts
    Pacs_BOLC_SET_VL_G1(-0.12162638018823857);
    // Set group 1 bol bias 03 (VRL) to 0.392515090355521 Volts
    Pacs_BOLC_SET_VRL_G1(0.392515090355521);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9764399412468519 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9764399412468519);
    // Set group 2 bol bias 01 (VH) to 1.4615686869832905 Volts
    Pacs_BOLC_SET_VH_G2(1.4615686869832905);
    // Set group 2 bol bias 02 (VL) to -0.13843131301670974 Volts
    Pacs_BOLC_SET_VL_G2(-0.13843131301670974);
    // Set group 2 bol bias 03 (VRL) to 0.3878839845398352 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878839845398352);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9722117106846373 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9722117106846373);
    // Set group 3 bol bias 01 (VH) to 1.4655563032867613 Volts
    Pacs_BOLC_SET_VH_G3(1.4655563032867613);
    // Set group 3 bol bias 02 (VL) to -0.13444369671323875 Volts
    Pacs_BOLC_SET_VL_G3(-0.13444369671323875);
    // Set group 3 bol bias 03 (VRL) to 0.38996914633068824 Volts
    Pacs_BOLC_SET_VRL_G3(0.38996914633068824);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9738455591218464 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9738455591218464);
    // Set group 4 bol bias 01 (VH) to 1.4803815567917744 Volts
    Pacs_BOLC_SET_VH_G4(1.4803815567917744);
    // Set group 4 bol bias 02 (VL) to -0.11961844320822568 Volts
    Pacs_BOLC_SET_VL_G4(-0.11961844320822568);
    // Set group 4 bol bias 03 (VRL) to 0.3860593630979322 Volts
    Pacs_BOLC_SET_VRL_G4(0.3860593630979322);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9936441996882226 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9936441996882226);
    // Set group 5 bol bias 01 (VH) to 1.3828510880972673 Volts
    Pacs_BOLC_SET_VH_G5(1.3828510880972673);
    // Set group 5 bol bias 02 (VL) to -0.11714891190273273 Volts
    Pacs_BOLC_SET_VL_G5(-0.11714891190273273);
    // Set group 5 bol bias 03 (VRL) to 0.4109562973201683 Volts
    Pacs_BOLC_SET_VRL_G5(0.4109562973201683);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055094312734005 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055094312734005);
    // Set group 6 bol bias 01 (VH) to 1.4187389541758537 Volts
    Pacs_BOLC_SET_VH_G6(1.4187389541758537);
    // Set group 6 bol bias 02 (VL) to -0.08126104582414631 Volts
    Pacs_BOLC_SET_VL_G6(-0.08126104582414631);
    // Set group 6 bol bias 03 (VRL) to 0.4349651037009118 Volts
    Pacs_BOLC_SET_VRL_G6(0.4349651037009118);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0109400872654906 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0109400872654906);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)blue = 1.7 Volts, (Vh-Vl)red = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.542293926761549 Volts
    Pacs_BOLC_SET_VH_G1(1.542293926761549);
    // Set group 1 bol bias 02 (VL) to -0.15770607323845098 Volts
    Pacs_BOLC_SET_VL_G1(-0.15770607323845098);
    // Set group 1 bol bias 03 (VRL) to 0.3926294451860477 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926294451860477);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9765528932845227 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9765528932845227);
    // Set group 2 bol bias 01 (VH) to 1.5247596019367946 Volts
    Pacs_BOLC_SET_VH_G2(1.5247596019367946);
    // Set group 2 bol bias 02 (VL) to -0.17524039806320546 Volts
    Pacs_BOLC_SET_VL_G2(-0.17524039806320546);
    // Set group 2 bol bias 03 (VRL) to 0.3878550325870832 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878550325870832);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9721831025166574 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9721831025166574);
    // Set group 3 bol bias 01 (VH) to 1.5286400044176514 Volts
    Pacs_BOLC_SET_VH_G3(1.5286400044176514);
    // Set group 3 bol bias 02 (VL) to -0.1713599955823485 Volts
    Pacs_BOLC_SET_VL_G3(-0.1713599955823485);
    // Set group 3 bol bias 03 (VRL) to 0.3901485670988867 Volts
    Pacs_BOLC_SET_VRL_G3(0.3901485670988867);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9740231261405279 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9740231261405279);
    // Set group 4 bol bias 01 (VH) to 1.5451742923820575 Volts
    Pacs_BOLC_SET_VH_G4(1.5451742923820575);
    // Set group 4 bol bias 02 (VL) to -0.15482570761794245 Volts
    Pacs_BOLC_SET_VL_G4(-0.15482570761794245);
    // Set group 4 bol bias 03 (VRL) to 0.3871858356177216 Volts
    Pacs_BOLC_SET_VRL_G4(0.3871858356177216);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9947589297629622 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9947589297629622);
    // Set group 5 bol bias 01 (VH) to 1.4463934011524333 Volts
    Pacs_BOLC_SET_VH_G5(1.4463934011524333);
    // Set group 5 bol bias 02 (VL) to -0.15360659884756683 Volts
    Pacs_BOLC_SET_VL_G5(-0.15360659884756683);
    // Set group 5 bol bias 03 (VRL) to 0.4101701125060366 Volts
    Pacs_BOLC_SET_VRL_G5(0.4101701125060366);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.054314719447538 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.054314719447538);
    // Set group 6 bol bias 01 (VH) to 1.4826068632993925 Volts
    Pacs_BOLC_SET_VH_G6(1.4826068632993925);
    // Set group 6 bol bias 02 (VL) to -0.11739313670060761 Volts
    Pacs_BOLC_SET_VL_G6(-0.11739313670060761);
    // Set group 6 bol bias 03 (VRL) to 0.4338779750444286 Volts
    Pacs_BOLC_SET_VRL_G6(0.4338779750444286);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.009851264439135 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.009851264439135);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)blue = 1.8 Volts, (Vh-Vl)red = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.60690529764583 Volts
    Pacs_BOLC_SET_VH_G1(1.60690529764583);
    // Set group 1 bol bias 02 (VL) to -0.19309470235416992 Volts
    Pacs_BOLC_SET_VL_G1(-0.19309470235416992);
    // Set group 1 bol bias 03 (VRL) to 0.39257168553053945 Volts
    Pacs_BOLC_SET_VRL_G1(0.39257168553053945);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9987180645064364 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9987180645064364);
    // Set group 2 bol bias 01 (VH) to 1.5888225493633414 Volts
    Pacs_BOLC_SET_VH_G2(1.5888225493633414);
    // Set group 2 bol bias 02 (VL) to -0.2111774506366586 Volts
    Pacs_BOLC_SET_VL_G2(-0.2111774506366586);
    // Set group 2 bol bias 03 (VRL) to 0.387719891228717 Volts
    Pacs_BOLC_SET_VRL_G2(0.387719891228717);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9720495652990864 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9720495652990864);
    // Set group 3 bol bias 01 (VH) to 1.5926816774791708 Volts
    Pacs_BOLC_SET_VH_G3(1.5926816774791708);
    // Set group 3 bol bias 02 (VL) to -0.20731832252082927 Volts
    Pacs_BOLC_SET_VL_G3(-0.20731832252082927);
    // Set group 3 bol bias 03 (VRL) to 0.39036266684895493 Volts
    Pacs_BOLC_SET_VRL_G3(0.39036266684895493);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.974235015140725 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.974235015140725);
    // Set group 4 bol bias 01 (VH) to 1.6103713769916332 Volts
    Pacs_BOLC_SET_VH_G4(1.6103713769916332);
    // Set group 4 bol bias 02 (VL) to -0.1896286230083667 Volts
    Pacs_BOLC_SET_VL_G4(-0.1896286230083667);
    // Set group 4 bol bias 03 (VRL) to 0.38763171869999546 Volts
    Pacs_BOLC_SET_VRL_G4(0.38763171869999546);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9952001524800798 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9952001524800798);
    // Set group 5 bol bias 01 (VH) to 1.575230733402161 Volts
    Pacs_BOLC_SET_VH_G5(1.575230733402161);
    // Set group 5 bol bias 02 (VL) to -0.22476926659783908 Volts
    Pacs_BOLC_SET_VL_G5(-0.22476926659783908);
    // Set group 5 bol bias 03 (VRL) to 0.40838061675412257 Volts
    Pacs_BOLC_SET_VRL_G5(0.40838061675412257);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.052540349440553 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.052540349440553);
    // Set group 6 bol bias 01 (VH) to 1.6128643450774607 Volts
    Pacs_BOLC_SET_VH_G6(1.6128643450774607);
    // Set group 6 bol bias 02 (VL) to -0.1871356549225394 Volts
    Pacs_BOLC_SET_VL_G6(-0.1871356549225394);
    // Set group 6 bol bias 03 (VRL) to 0.4319097861053989 Volts
    Pacs_BOLC_SET_VRL_G6(0.4319097861053989);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.007881605555887 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.007881605555887);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)blue = 2.0 Volts, (Vh-Vl)red = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.739376176417995 Volts
    Pacs_BOLC_SET_VH_G1(1.739376176417995);
    // Set group 1 bol bias 02 (VL) to -0.2606238235820051 Volts
    Pacs_BOLC_SET_VL_G1(-0.2606238235820051);
    // Set group 1 bol bias 03 (VRL) to 0.3921536831520859 Volts
    Pacs_BOLC_SET_VRL_G1(0.3921536831520859);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9760829613086472 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9760829613086472);
    // Set group 2 bol bias 01 (VH) to 1.719809813472755 Volts
    Pacs_BOLC_SET_VH_G2(1.719809813472755);
    // Set group 2 bol bias 02 (VL) to -0.28019018652724503 Volts
    Pacs_BOLC_SET_VL_G2(-0.28019018652724503);
    // Set group 2 bol bias 03 (VRL) to 0.38744168454874117 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744168454874117);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9717746579976725 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9717746579976725);
    // Set group 3 bol bias 01 (VH) to 1.7343527587435847 Volts
    Pacs_BOLC_SET_VH_G3(1.7343527587435847);
    // Set group 3 bol bias 02 (VL) to -0.2656472412564153 Volts
    Pacs_BOLC_SET_VL_G3(-0.2656472412564153);
    // Set group 3 bol bias 03 (VRL) to 0.4017790445564455 Volts
    Pacs_BOLC_SET_VRL_G3(0.4017790445564455);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9855314406558735 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9855314406558735);
    // Set group 4 bol bias 01 (VH) to 1.7440573141484068 Volts
    Pacs_BOLC_SET_VH_G4(1.7440573141484068);
    // Set group 4 bol bias 02 (VL) to -0.2559426858515932 Volts
    Pacs_BOLC_SET_VL_G4(-0.2559426858515932);
    // Set group 4 bol bias 03 (VRL) to 0.38894738596666634 Volts
    Pacs_BOLC_SET_VRL_G4(0.38894738596666634);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.996502027278406 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.996502027278406);
    // Set group 5 bol bias 01 (VH) to 1.6403549621270441 Volts
    Pacs_BOLC_SET_VH_G5(1.6403549621270441);
    // Set group 5 bol bias 02 (VL) to -0.25964503787295584 Volts
    Pacs_BOLC_SET_VL_G5(-0.25964503787295584);
    // Set group 5 bol bias 03 (VRL) to 0.4071234038646236 Volts
    Pacs_BOLC_SET_VRL_G5(0.4071234038646236);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051293864758269 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051293864758269);
    // Set group 6 bol bias 01 (VH) to 1.6787311020540112 Volts
    Pacs_BOLC_SET_VH_G6(1.6787311020540112);
    // Set group 6 bol bias 02 (VL) to -0.22126889794598872 Volts
    Pacs_BOLC_SET_VL_G6(-0.22126889794598872);
    // Set group 6 bol bias 03 (VRL) to 0.4305158637367362 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305158637367362);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0064867220677454 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0064867220677454);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)blue = 2.3 Volts, (Vh-Vl)red = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.9636608873020274 Volts
    Pacs_BOLC_SET_VH_G1(1.9636608873020274);
    // Set group 1 bol bias 02 (VL) to -0.3363391126979725 Volts
    Pacs_BOLC_SET_VL_G1(-0.3363391126979725);
    // Set group 1 bol bias 03 (VRL) to 0.40278769107629514 Volts
    Pacs_BOLC_SET_VRL_G1(0.40278769107629514);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9865763456310306 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9865763456310306);
    // Set group 2 bol bias 01 (VH) to 1.927696912686972 Volts
    Pacs_BOLC_SET_VH_G2(1.927696912686972);
    // Set group 2 bol bias 02 (VL) to -0.37230308731302775 Volts
    Pacs_BOLC_SET_VL_G2(-0.37230308731302775);
    // Set group 2 bol bias 03 (VRL) to 0.3858403551587576 Volts
    Pacs_BOLC_SET_VRL_G2(0.3858403551587576);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9924144642105024 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9924144642105024);
    // Set group 3 bol bias 01 (VH) to 1.9431226670014545 Volts
    Pacs_BOLC_SET_VH_G3(1.9431226670014545);
    // Set group 3 bol bias 02 (VL) to -0.35687733299854535 Volts
    Pacs_BOLC_SET_VL_G3(-0.35687733299854535);
    // Set group 3 bol bias 03 (VRL) to 0.4024839037666154 Volts
    Pacs_BOLC_SET_VRL_G3(0.4024839037666154);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9862268670149914 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9862268670149914);
    // Set group 4 bol bias 01 (VH) to 1.9579270398291708 Volts
    Pacs_BOLC_SET_VH_G4(1.9579270398291708);
    // Set group 4 bol bias 02 (VL) to -0.3420729601708289 Volts
    Pacs_BOLC_SET_VL_G4(-0.3420729601708289);
    // Set group 4 bol bias 03 (VRL) to 0.3906771012878555 Volts
    Pacs_BOLC_SET_VRL_G4(0.3906771012878555);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.99821351608857 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.99821351608857);
    // Set group 5 bol bias 01 (VH) to 1.7079035410760286 Volts
    Pacs_BOLC_SET_VH_G5(1.7079035410760286);
    // Set group 5 bol bias 02 (VL) to -0.29209645892397146 Volts
    Pacs_BOLC_SET_VL_G5(-0.29209645892397146);
    // Set group 5 bol bias 03 (VRL) to 0.405804322083024 Volts
    Pacs_BOLC_SET_VRL_G5(0.405804322083024);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0499861292550787 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0499861292550787);
    // Set group 6 bol bias 01 (VH) to 1.7476622867412348 Volts
    Pacs_BOLC_SET_VH_G6(1.7476622867412348);
    // Set group 6 bol bias 02 (VL) to -0.2523377132587652 Volts
    Pacs_BOLC_SET_VL_G6(-0.2523377132587652);
    // Set group 6 bol bias 03 (VRL) to 0.429562228366719 Volts
    Pacs_BOLC_SET_VRL_G6(0.429562228366719);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.005532468489443 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.005532468489443);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)blue = 2.6 Volts, (Vh-Vl)red = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2151628880310112 Volts
    Pacs_BOLC_SET_VH_G1(2.2151628880310112);
    // Set group 1 bol bias 02 (VL) to -0.3848371119689889 Volts
    Pacs_BOLC_SET_VL_G1(-0.3848371119689889);
    // Set group 1 bol bias 03 (VRL) to 0.41342338183313837 Volts
    Pacs_BOLC_SET_VRL_G1(0.41342338183313837);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0193446104924915 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0193446104924915);
    // Set group 2 bol bias 01 (VH) to 2.1588489399994213 Volts
    Pacs_BOLC_SET_VH_G2(2.1588489399994213);
    // Set group 2 bol bias 02 (VL) to -0.4411510600005787 Volts
    Pacs_BOLC_SET_VL_G2(-0.4411510600005787);
    // Set group 2 bol bias 03 (VRL) to 0.3838811209851186 Volts
    Pacs_BOLC_SET_VRL_G2(0.3838811209851186);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9682559687629309 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9682559687629309);
    // Set group 3 bol bias 01 (VH) to 2.1867239063317037 Volts
    Pacs_BOLC_SET_VH_G3(2.1867239063317037);
    // Set group 3 bol bias 02 (VL) to -0.4132760936682966 Volts
    Pacs_BOLC_SET_VL_G3(-0.4132760936682966);
    // Set group 3 bol bias 03 (VRL) to 0.4136603871411812 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136603871411812);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9973179392427267 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9973179392427267);
    // Set group 4 bol bias 01 (VH) to 2.20827452044462 Volts
    Pacs_BOLC_SET_VH_G4(2.20827452044462);
    // Set group 4 bol bias 02 (VL) to -0.39172547955538 Volts
    Pacs_BOLC_SET_VL_G4(-0.39172547955538);
    // Set group 4 bol bias 03 (VRL) to 0.4039414339062088 Volts
    Pacs_BOLC_SET_VRL_G4(0.4039414339062088);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.011301244644244 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.011301244644244);
    // Set group 5 bol bias 01 (VH) to 1.7875017871866707 Volts
    Pacs_BOLC_SET_VH_G5(1.7875017871866707);
    // Set group 5 bol bias 02 (VL) to -0.31249821281332946 Volts
    Pacs_BOLC_SET_VL_G5(-0.31249821281332946);
    // Set group 5 bol bias 03 (VRL) to 0.41576367399178094 Volts
    Pacs_BOLC_SET_VRL_G5(0.41576367399178094);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.037668873916454 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.037668873916454);
    // Set group 6 bol bias 01 (VH) to 1.8172008318899895 Volts
    Pacs_BOLC_SET_VH_G6(1.8172008318899895);
    // Set group 6 bol bias 02 (VL) to -0.2827991681100106 Volts
    Pacs_BOLC_SET_VL_G6(-0.2827991681100106);
    // Set group 6 bol bias 03 (VRL) to 0.42845474144203777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42845474144203777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.004424303719793 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.004424303719793);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)blue = 2.9 Volts, (Vh-Vl)red = 2.3 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.517666343337925 Volts
    Pacs_BOLC_SET_VH_G1(2.517666343337925);
    // Set group 1 bol bias 02 (VL) to -0.382333656662075 Volts
    Pacs_BOLC_SET_VL_G1(-0.382333656662075);
    // Set group 1 bol bias 03 (VRL) to 0.4351367995957048 Volts
    Pacs_BOLC_SET_VRL_G1(0.4351367995957048);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9965703186107444 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9965703186107444);
    // Set group 2 bol bias 01 (VH) to 2.4353683146246183 Volts
    Pacs_BOLC_SET_VH_G2(2.4353683146246183);
    // Set group 2 bol bias 02 (VL) to -0.4646316853753816 Volts
    Pacs_BOLC_SET_VL_G2(-0.4646316853753816);
    // Set group 2 bol bias 03 (VRL) to 0.39230855172448975 Volts
    Pacs_BOLC_SET_VRL_G2(0.39230855172448975);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9765832317921543 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9765832317921543);
    // Set group 3 bol bias 01 (VH) to 2.4565430314555052 Volts
    Pacs_BOLC_SET_VH_G3(2.4565430314555052);
    // Set group 3 bol bias 02 (VL) to -0.4434569685444947 Volts
    Pacs_BOLC_SET_VL_G3(-0.4434569685444947);
    // Set group 3 bol bias 03 (VRL) to 0.4116559215687209 Volts
    Pacs_BOLC_SET_VRL_G3(0.4116559215687209);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175436768747823 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175436768747823);
    // Set group 4 bol bias 01 (VH) to 2.4726040303622487 Volts
    Pacs_BOLC_SET_VH_G4(2.4726040303622487);
    // Set group 4 bol bias 02 (VL) to -0.4273959696377513 Volts
    Pacs_BOLC_SET_VL_G4(-0.4273959696377513);
    // Set group 4 bol bias 03 (VRL) to 0.3940712295914811 Volts
    Pacs_BOLC_SET_VRL_G4(0.3940712295914811);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.023793793137234 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.023793793137234);
    // Set group 5 bol bias 01 (VH) to 1.9226793871045598 Volts
    Pacs_BOLC_SET_VH_G5(1.9226793871045598);
    // Set group 5 bol bias 02 (VL) to -0.37732061289544 Volts
    Pacs_BOLC_SET_VL_G5(-0.37732061289544);
    // Set group 5 bol bias 03 (VRL) to 0.40093587460771146 Volts
    Pacs_BOLC_SET_VRL_G5(0.40093587460771146);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.022938134951507 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.022938134951507);
    // Set group 6 bol bias 01 (VH) to 1.9672658597937258 Volts
    Pacs_BOLC_SET_VH_G6(1.9672658597937258);
    // Set group 6 bol bias 02 (VL) to -0.332734140206274 Volts
    Pacs_BOLC_SET_VL_G6(-0.332734140206274);
    // Set group 6 bol bias 03 (VRL) to 0.4263945599495246 Volts
    Pacs_BOLC_SET_VRL_G6(0.4263945599495246);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.002362975913312 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.002362975913312);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)blue = 3.2 Volts, (Vh-Vl)red = 2.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.847199981495237 Volts
    Pacs_BOLC_SET_VH_G1(2.847199981495237);
    // Set group 1 bol bias 02 (VL) to -0.3528000185047631 Volts
    Pacs_BOLC_SET_VL_G1(-0.3528000185047631);
    // Set group 1 bol bias 03 (VRL) to 0.4347941377293029 Volts
    Pacs_BOLC_SET_VRL_G1(0.4347941377293029);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.018449774761696 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.018449774761696);
    // Set group 2 bol bias 01 (VH) to 2.7602559944480873 Volts
    Pacs_BOLC_SET_VH_G2(2.7602559944480873);
    // Set group 2 bol bias 02 (VL) to -0.43974400555191273 Volts
    Pacs_BOLC_SET_VL_G2(-0.43974400555191273);
    // Set group 2 bol bias 03 (VRL) to 0.4036708891743245 Volts
    Pacs_BOLC_SET_VRL_G2(0.4036708891743245);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.0099936291338243 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.0099936291338243);
    // Set group 3 bol bias 01 (VH) to 2.805732095961401 Volts
    Pacs_BOLC_SET_VH_G3(2.805732095961401);
    // Set group 3 bol bias 02 (VL) to -0.3942679040385992 Volts
    Pacs_BOLC_SET_VL_G3(-0.3942679040385992);
    // Set group 3 bol bias 03 (VRL) to 0.4339248022480186 Volts
    Pacs_BOLC_SET_VRL_G3(0.4339248022480186);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175166229478236 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175166229478236);
    // Set group 4 bol bias 01 (VH) to 2.8132260321912117 Volts
    Pacs_BOLC_SET_VH_G4(2.8132260321912117);
    // Set group 4 bol bias 02 (VL) to -0.3867739678087883 Volts
    Pacs_BOLC_SET_VL_G4(-0.3867739678087883);
    // Set group 4 bol bias 03 (VRL) to 0.4141623922109569 Volts
    Pacs_BOLC_SET_VRL_G4(0.4141623922109569);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.0213933637092976 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.0213933637092976);
    // Set group 5 bol bias 01 (VH) to 2.1145200531318697 Volts
    Pacs_BOLC_SET_VH_G5(2.1145200531318697);
    // Set group 5 bol bias 02 (VL) to -0.38547994686813014 Volts
    Pacs_BOLC_SET_VL_G5(-0.38547994686813014);
    // Set group 5 bol bias 03 (VRL) to 0.4292977832137159 Volts
    Pacs_BOLC_SET_VRL_G5(0.4292977832137159);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.006817368773259 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.006817368773259);
    // Set group 6 bol bias 01 (VH) to 2.1293608950052523 Volts
    Pacs_BOLC_SET_VH_G6(2.1293608950052523);
    // Set group 6 bol bias 02 (VL) to -0.3706391049947475 Volts
    Pacs_BOLC_SET_VL_G6(-0.3706391049947475);
    // Set group 6 bol bias 03 (VRL) to 0.4231555942593115 Volts
    Pacs_BOLC_SET_VRL_G6(0.4231555942593115);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9769002872568586 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9769002872568586);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //
    //
    //************************************************************************
    //                   Longer Noise Measurement
    // Expected fluxes : 1.7pW on the blue and 5.3pW on the red detector
    //************************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)blue = 1.8 Volts, (Vh-Vl)red = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.60690529764583 Volts
    Pacs_BOLC_SET_VH_G1(1.60690529764583);
    // Set group 1 bol bias 02 (VL) to -0.19309470235416992 Volts
    Pacs_BOLC_SET_VL_G1(-0.19309470235416992);
    // Set group 1 bol bias 03 (VRL) to 0.39257168553053945 Volts
    Pacs_BOLC_SET_VRL_G1(0.39257168553053945);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9987180645064364 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9987180645064364);
    // Set group 2 bol bias 01 (VH) to 1.5888225493633414 Volts
    Pacs_BOLC_SET_VH_G2(1.5888225493633414);
    // Set group 2 bol bias 02 (VL) to -0.2111774506366586 Volts
    Pacs_BOLC_SET_VL_G2(-0.2111774506366586);
    // Set group 2 bol bias 03 (VRL) to 0.387719891228717 Volts
    Pacs_BOLC_SET_VRL_G2(0.387719891228717);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9720495652990864 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9720495652990864);
    // Set group 3 bol bias 01 (VH) to 1.5926816774791708 Volts
    Pacs_BOLC_SET_VH_G3(1.5926816774791708);
    // Set group 3 bol bias 02 (VL) to -0.20731832252082927 Volts
    Pacs_BOLC_SET_VL_G3(-0.20731832252082927);
    // Set group 3 bol bias 03 (VRL) to 0.39036266684895493 Volts
    Pacs_BOLC_SET_VRL_G3(0.39036266684895493);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.974235015140725 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.974235015140725);
    // Set group 4 bol bias 01 (VH) to 1.6103713769916332 Volts
    Pacs_BOLC_SET_VH_G4(1.6103713769916332);
    // Set group 4 bol bias 02 (VL) to -0.1896286230083667 Volts
    Pacs_BOLC_SET_VL_G4(-0.1896286230083667);
    // Set group 4 bol bias 03 (VRL) to 0.38763171869999546 Volts
    Pacs_BOLC_SET_VRL_G4(0.38763171869999546);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9952001524800798 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9952001524800798);
    // Set group 5 bol bias 01 (VH) to 1.320583197395035 Volts
    Pacs_BOLC_SET_VH_G5(1.320583197395035);
    // Set group 5 bol bias 02 (VL) to -0.07941680260496485 Volts
    Pacs_BOLC_SET_VL_G5(-0.07941680260496485);
    // Set group 5 bol bias 03 (VRL) to 0.4116095244710064 Volts
    Pacs_BOLC_SET_VRL_G5(0.4116095244710064);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055742088043621 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055742088043621);
    // Set group 6 bol bias 01 (VH) to 1.3562697990163495 Volts
    Pacs_BOLC_SET_VH_G6(1.3562697990163495);
    // Set group 6 bol bias 02 (VL) to -0.04373020098365052 Volts
    Pacs_BOLC_SET_VL_G6(-0.04373020098365052);
    // Set group 6 bol bias 03 (VRL) to 0.43594530124025854 Volts
    Pacs_BOLC_SET_VRL_G6(0.43594530124025854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.011921670046162 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.011921670046162);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for lowFreq_noise_time seconds
    TMMarker603();
    delay(lowFreq_noise_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)blue = 2.6 Volts, (Vh-Vl)red = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2151628880310112 Volts
    Pacs_BOLC_SET_VH_G1(2.2151628880310112);
    // Set group 1 bol bias 02 (VL) to -0.3848371119689889 Volts
    Pacs_BOLC_SET_VL_G1(-0.3848371119689889);
    // Set group 1 bol bias 03 (VRL) to 0.41342338183313837 Volts
    Pacs_BOLC_SET_VRL_G1(0.41342338183313837);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0193446104924915 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0193446104924915);
    // Set group 2 bol bias 01 (VH) to 2.1588489399994213 Volts
    Pacs_BOLC_SET_VH_G2(2.1588489399994213);
    // Set group 2 bol bias 02 (VL) to -0.4411510600005787 Volts
    Pacs_BOLC_SET_VL_G2(-0.4411510600005787);
    // Set group 2 bol bias 03 (VRL) to 0.3838811209851186 Volts
    Pacs_BOLC_SET_VRL_G2(0.3838811209851186);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9682559687629309 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9682559687629309);
    // Set group 3 bol bias 01 (VH) to 2.1867239063317037 Volts
    Pacs_BOLC_SET_VH_G3(2.1867239063317037);
    // Set group 3 bol bias 02 (VL) to -0.4132760936682966 Volts
    Pacs_BOLC_SET_VL_G3(-0.4132760936682966);
    // Set group 3 bol bias 03 (VRL) to 0.4136603871411812 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136603871411812);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9973179392427267 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9973179392427267);
    // Set group 4 bol bias 01 (VH) to 2.20827452044462 Volts
    Pacs_BOLC_SET_VH_G4(2.20827452044462);
    // Set group 4 bol bias 02 (VL) to -0.39172547955538 Volts
    Pacs_BOLC_SET_VL_G4(-0.39172547955538);
    // Set group 4 bol bias 03 (VRL) to 0.4039414339062088 Volts
    Pacs_BOLC_SET_VRL_G4(0.4039414339062088);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.011301244644244 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.011301244644244);
    // Set group 5 bol bias 01 (VH) to 1.7079035410760286 Volts
    Pacs_BOLC_SET_VH_G5(1.7079035410760286);
    // Set group 5 bol bias 02 (VL) to -0.29209645892397146 Volts
    Pacs_BOLC_SET_VL_G5(-0.29209645892397146);
    // Set group 5 bol bias 03 (VRL) to 0.405804322083024 Volts
    Pacs_BOLC_SET_VRL_G5(0.405804322083024);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0499861292550787 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0499861292550787);
    // Set group 6 bol bias 01 (VH) to 1.7476622867412348 Volts
    Pacs_BOLC_SET_VH_G6(1.7476622867412348);
    // Set group 6 bol bias 02 (VL) to -0.2523377132587652 Volts
    Pacs_BOLC_SET_VL_G6(-0.2523377132587652);
    // Set group 6 bol bias 03 (VRL) to 0.429562228366719 Volts
    Pacs_BOLC_SET_VRL_G6(0.429562228366719);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.005532468489443 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.005532468489443);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for lowFreq_noise_time seconds
    TMMarker603();
    delay(lowFreq_noise_time);
    TMMarker600();
    //
    //*********************************
    // Apply the old sequencer setting
    //*********************************
    //
    PACS_Phot_Sequencer_Setup();
    //
}

// CVS comments  : $Id: PacsRangeSpecSed.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $
// Missionphase  : Operations
//
// Purpose       : 
//
// CUS author    : DAC
// Script file   : PacsRangeSpecSed.txt 
//
// Input arguments
// type     name      description
// bool     sedRED    perform RED SED, i.e. from 75 to 205 microns
// bool     sedBLU    perform BLU SED, i.e. from 55 to 75 microns
// Return values
// Type                Description
// {string,double,double,double,double,double} []   
// {"SED",blue,red,dummy,dummy,dunmmy}]
//
// Description   : Creates RED or BLU "range" variable for the SED case
//
// Preconditions :
//
// Comments      : This version assumes sedRED and sedBLU to be mutually
//                 exclusive, i.e. either one or the other, not both
// 
// History       : 0.1 21-Jun-2005 DAC
// 1.0 15-sep-2005 Modified for "OBS" version of CUS
// 1.1 11-may-2006 Element {3} of range tuple is now int (the 
//                 repetition count)
// 1.2  7-jun-2006 Introduce sedRED and sedBLU arguments to
//                 generate one or the other range
// 1.3 22-jun-2006 Use new ranges (with lineWidth)
// 2.0 12-apr-2007 Changes for SCR-3050. Input argument
//                 is now selected sed mode. Add "order"=6 for short 
//                 wavelengths at order 2.
// 3.0 25-apr-2007 Defined returned range similar to rangeSPOT
// 4.0 30-nov-2009 VD PHS-1272 + PHS-1274
// 5.0 08-dec-2009 VD PHS-1285: dithering SED!!!!
// 6.0 12-jan-2010 VD PHS-1285 SED dithering... need grat_pos
// 7.0 15-jan-2010 VD PHS-1285 ... grat pos are not equiv to VALID wl pos .... added users info!
// 
{{string,double,double,int,double,double,double,string,string,double}[],{double,double}[]} procedure PacsRangeSpecSed_tmp {
    string orderSel = "sed2" in ["sed2","sed3","sed4","sedb2b","sedb2a","sedb3a"];
    int repeatSed = 1;
}{
    // Return variables
    {string,double,double,int,double,double,double,string,string,double}[] range = [{"SED",0.0,0.0,0,0.0,0.0,0.0,"","",0.0}];
    {double,double}[] gratRangeSed = [{0.0,0.0}];
    // Create ranges defined by ORDER= 4, 5, and 6 (see CAL-U SPEC_BAND_params)
    if(orderSel == "sed2") {
        string keyB = "4";
    }
    if(orderSel == "sed3") {
        keyB = "5";
    }
    if(orderSel == "sed4") {
        keyB = "6";
    }
    if(orderSel == "sedb2b") {
        keyB = "b2b";
        string interp_file_blu = "SPEC_grat_wl_B2B";
        string wl_grat_blu = "SPEC_RSRF_Blue_LW";
    }
    if(orderSel == "sedb2a") {
        keyB = "b2a";
        interp_file_blu = "SPEC_grat_wl_B2A";
        wl_grat_blu = "SPEC_RSRF_Blue_LW";
    }
    if(orderSel == "sedb3a") {
        keyB = "b3a";
        interp_file_blu = "SPEC_grat_wl_B3A";
        wl_grat_blu = "SPEC_RSRF_Blue_SW";
    }
    string wl_grat_red = "SPEC_RSRF_Red";
    string interp_file_red = "SPEC_grat_wl_R1";
    int loop0 = 0;
    double waveBluEdgeB = dlookup("SPEC_BAND_params",keyB,"BLU");
    double waveRedEdgeB = dlookup("SPEC_BAND_params",keyB,"RED");
    int grat_step = ilookup("SPEC_BAND_params",keyB,"MED");
    double user_grat_bluEdgeB_pos = interpolate(wl_grat_blu,"grat_pos",waveBluEdgeB);
    string the_key = "sed" + keyB;
    double ext_grat_blu_pos = dlookup("SPEC_SED_params",the_key,"BLU");
    double ext_grat_red_pos = dlookup("SPEC_SED_params",the_key,"RED");
    range[loop0] = {orderSel,0.0,0.0,0,0.0,0.0,0.0,"","",0.0};
    range[loop0]{1} = waveBluEdgeB;
    range[loop0]{2} = waveRedEdgeB;
    gratRangeSed[loop0]{0} = ext_grat_blu_pos;
    gratRangeSed[loop0]{1} = ext_grat_red_pos;
    if(repeatSed > 1) {
        for(int loopDith = 1 .. repeatSed - 1) {
            debug_print("loopDith: " + loopDith + "/repeatSed: " + repeatSed);
            // the funtion??
            double grat_dither = double(loopDith) * (double(grat_step) / double(repeatSed));
            double ext_grat_bluEdge_shift = ext_grat_blu_pos - grat_dither;
            double user_grat_bluEdge_shift = user_grat_bluEdgeB_pos - grat_dither;
            double waveBluEdgeDitherB = interpolate(interp_file_blu,"wave",user_grat_bluEdge_shift);
            // for the RED "free range .. we don 't ned it here .. just for consitancy
            double waveBluEdgeDitherR = interpolate(interp_file_red,"wave",user_grat_bluEdge_shift);
            //	 double bluWaveDith = bluWave + waveDither;
            range[loopDith] = {orderSel,0.0,0.0,0,0.0,0.0,0.0,"","",0.0};
            range[loopDith]{1} = waveBluEdgeDitherB;
            range[loopDith]{2} = waveRedEdgeB;
            gratRangeSed[loopDith] = {0.0,0.0};
            gratRangeSed[loopDith]{0} = ext_grat_bluEdge_shift;
            gratRangeSed[loopDith]{1} = ext_grat_red_pos;
        }
    }

    return {range,gratRangeSed};
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Missionphase  : PACS FMILT
//
// Purpose       : Configure the phot filter wheel for Redundant Warm
//
// Author        : PR
//
// Arguments     : 
//
// Description   : 
//                 
// Comments      :      
//
// Version       : 0.1 
// History       : 0.1  04-Jul-2007 Initial version
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//
obs PacsEng_CONF_phot_fltw_R_Warm {
    /* No variables to call PacsEng_CONF_phot_fltw_R_Warm                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POSB" */
    /* End of needed variables for PacsEng_CONF_phot_fltw_R_Warm                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_phot_fltw_R_Warm()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_phot_fltw_R_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_CS_SFT_Cold.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : VERIFY FUNCTION of INTERNAL CALIBRATION SOURCES
//
// Author        : H. Dannerbauer
//                 R. Vavrek
//                 H. Feuchtgruber
// CUSification  : DAC
//               
// Arguments     : BB1 & BB2 temperature [muOhms & Volts]
//          	  
//
// Called        : WaitForGo   
//                 waittime
//                 tcsend
//
// Dependences   : tm_switchon
//                 tm_spec_det_setup
//                 tm_spec_spu_setup
//                 tm_spec_mec_setup
//                 
//
// Description   : This script assumes an already set-up PACS instrument. 
//                 This test is based on functional test 0.7.11 and PTD 0.7.12.
// 
// Comments :      None of the detector systems are involved in the BB's
//                 functional check. Nevertheless, in order to generate HK data, 
//                 the DPU-SET-HK-LIST command is set and parametrised for 
//                 spectroscopy and spectrometer setup needed inorder to 
//                 synchronize diagnostic HK on readouts.  
//                 Commanding unit conversions: 1 setpoint unit = 100 micro
//                 Ohms, max temperature ~ 100 K, max setpoint = 32767 
//                 In case if temperature set directly: -32767 = -10 Volts, 
//                 +32767 = +10 Volts.
//                 
// Version       : 1.0
// History       : This script is based on the commanding during
//                 the CQM ILT Test. 15-11-2004.      
procedure PACS_CS_SFT_Cold {
}{
    // Diagnostic HK period (in milliseconds)
    int diag_hk_period = 300;
    // PC160420 "DMC_WRT_DIAG_HK_LIST" WRITE THE LIST OF DIAGNOSTIC HK INTO DMC MEMORY
    // DMC_DATA_LENGTH            PP065420 contains the number of desired HK parameters
    // DMC_4_BYTES_WORDS_DATA     PP067420 contains the desired HK parameters' IDs
    // DMC_CHECKSUM               PP066420
    //
    // Max number of requested diag HK parameters = 16
    // (including the last one, which is always forced to the same value)
    // Chopper specific measures are:
    // 214 DMC_CS2_CTRL_STA  -  CS2 controller status
    // 445 DMC_CS1_RES_VALUE -  CS1 current resistor value
    // 446 DMC_CS1_OUTPUT    -  CS1 controller output voltage
    // 447 DMC_CS2_RES_VALUE -  CS2 current resistor value
    // 448 DMC_CS1_OUTPUT    -  CS2 controller output voltage
    // 459 DMC_CS1_TARGET    -  CS1 target resistor value
    // 460 DMC_CS2_TARGET    -  CS2 target resistor value
    // 526 DMC_CS1_VOLT_SG   -  CS1 small gain sensor voltage
    // 527 DMC_CS1_VOLT_BG   -  CS1 big gain sensor voltage
    // 528 DMC_CS1_CUR_SG    -  CS1 small gain sensor current
    // 529 DMC_CS1_CUR_BG    -  CS1 big gain sensor current
    // 542 DMC_CS2_VOLT_SG   -  CS2 small gain sensor voltage
    // 543 DMC_CS2_VOLT_BG   -  CS2 big gain sensor voltage
    // 544 DMC_CS2_CUR_SG    -  CS2 small gain sensor current
    // 545 DMC_CS2_CUR_BG    -  CS2 big gain sensor current
    int nb_words = 16;
    {int}[] list_tuple = [{214},{445},{446},{447},{448},{459},{460},{526},{527},{528},{529},{542},{543},{544},{545},{0xffff}];
    int[] list_int = [214,445,446,447,448,459,460,526,527,528,529,542,543,544,545,0xffff];
    int chksum = checksum("int",list_int);
    // Send the TC
    Pacs_DMC_WRT_DIAG_HK_LIST(nb_words,list_tuple,chksum);
    delay(1);
    // 
    // PC161420 "DMC_WRT_DIAG_HK_CONF_TAB" WRITE THE CUSTOM HK CONFIGURATION TABLE
    //         PP065420 "DMC_DATA_LENGTH", GroupSize: 1
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // PC146420 "DMC_START_DIAG_HK" START THE ACQUISITION OF THE DIAGNOSTIC HK
    //         PP076420 "DIAG_HK_PERIOD"
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    //
    // Write calibration source controller parameters
    //
    // DMC_WRT_CS1_CONF_PAR
    list_tuple = [{1000000},{5000},{3277},{1857},{327},{0x7fff},{0}];
    list_int = [1000000,5000,3277,1857,327,0x7fff,0];
    chksum = checksum("int",list_int);
    // Send the TC
    Pacs_DMC_WRT_CS1_CONF_PAR(list_tuple,chksum);
    delay(1);
    // DMC_WRT_CS2_CONF_PAR
    //set params [list {PP067420 1000000} {PP067420 5000} {PP067420 3277} \
    //                 {PP067420 1857} {PP067420 327} \
    //                 [list PP067420 [expr 0x7FFF]] {PP067420 0}]
    list_tuple = [{1000000},{5000},{3277},{1857},{327},{0x7fff},{0}];
    list_int = [1000000,5000,3277,1857,327,0x7fff,0];
    chksum = checksum("int",list_int);
    // Send the TC
    Pacs_DMC_WRT_CS2_CONF_PAR(list_tuple,chksum);
    delay(1);
    //
    // Calibration source controller parameters are set
    //
    // Heat-up the CS sources up to 800000 (70.5K;CS1)
    // and 920000 (76.0K;CS2) --- big step
    // Switchon, enable and set CS1 to 800000 (~70.5K)
    // PC138420 "DMC_SWON_BB_1_CONT" SWITCH ON BLACK BODY 1 CONTROLLER
    Pacs_DMC_SWON_BB_1_CONT();
    delay(1);
    // PC206420 "DMC_ENABLE_BB_1_CONT" ENABLE BB1 CONTROLLER
    Pacs_DMC_ENABLE_BB_1_CONT();
    // PC140420 "DMC_SET_TEMP_BB_1" SET THE TEMPERATURE OF THE BLACK BODY 1
    // PP094420 "DMC_BB_TEMP"
    double temp = 80.0;
    Pacs_DMC_SET_TEMP_BB_1(temp);
    delay(1);
    // Switchon, enable and set CS2 to 920000 (~76.0K)
    // PC142420 "DMC_SWON_BB_2_CONT" SWITCH ON BLACK BODY 2 CONTROLLER
    Pacs_DMC_SWON_BB_2_CONT();
    delay(1);
    // PC208420 "DMC_ENABLE_BB_2_CONT" ENABLE BB2 CONTROLLER
    Pacs_DMC_ENABLE_BB_2_CONT();
    delay(1);
    // PC144420 "DMC_SET_TEMP_BB_2" SET THE TEMPERATURE OF THE BLACK BODY 2
    //	PP094420 "DMC_BB_TEMP"
    temp = 92.0;
    Pacs_DMC_SET_TEMP_BB_2(temp);
    // wait a while to allow for HK checking and sufficient diag data collection
    delay(600);
    // PC147420 "DMC_STOP_DIAG_HK" STOP THE ACQUISITION OF THE DIAGNOSTIC HK
    Pacs_DMC_STOP_DIAG_HK();
    delay(1);
    // End of Procedure
}

// CVS comments  : $Id: PacsPhotCommandOBCP7.txt,v 1.5 2007/05/02 08:51:17 dcesarsk Exp $ 
// Purpose       : Execute OBCP#7 with the provided parameters
//
// CUS author    : DAC
// Script file   : PacsPhotCommandOBCP7.txt 
//
// Input arguments
// Type                      Description
// tuple  {double,int,int,  {waveLen,order,gratPos,
//         int,int,int}      gratWidth,nbStep,gratStep}  
//
// Return values
// Type    Name      Default      Description
//
// Description   : Calls OBCP#7 (OBCP_phot_staring) with given
//                 parameters
// Dependencies  : OBCP_phot_staring
//                 DMC_phot_staring
//
// Preconditions : 
//                 
// Comments      : Filter must be positioned before calling this procedure
// since there is no FLTW move here!!
// 
// History       : 
// 0.1 DAC  7-Dec-2005, based on PacsPhotCommandOBCP4
// 0.2 DAC 29-mar-2007 Removed nb_rdouts in call to OBCP; use OBCP in ilt
int[] procedure PacsPhotCommandOBCP7 {
    {int,int,int,int,int,int,int,int,int} confPHOTblu = {0,0,0,0,0,0,0,0,0}; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int} confPHOTred = {0,0,0,0,0,0,0,0,0}; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // OBCP parameters
    bool verbose = false; // Print debug information
}{
    // Create array of durations
    int[] time_array = [0,0,0,0,0];
    if(verbose) {
        debug_print("+++ Starting PhotCommandOBCP7");
        debug_print("OBCP: " + confOBCP);
    }
    // Long sequence to "unpack" contents of tuples
    int gain = confPHOTblu{0};
    // int nb_rdouts_ramp_blu = confPHOTblu{1};
    // int nb_rdouts_subramp_blu = confPHOTblu{2};
    int comp_mode_blu = confPHOTblu{3};
    int glitch_det_blu = confPHOTblu{4};
    // int ramp_fit_alg_blu = confPHOTblu{5};
    int nb_raw_blu = confPHOTblu{6};
    // int bias_r_blu_mV = confPHOTblu{7};
    // int bias_d_blu_mV = confPHOTblu{8};
    gain = confPHOTred{0};
    // int nb_rdouts_ramp_red = confPHOTred{1};
    // int nb_rdouts_subramp_red = confPHOTred{2};
    int comp_mode_red = confPHOTred{3};
    int glitch_det_red = confPHOTred{4};
    // int ramp_fit_alg_red = confPHOTred{5};
    int nb_raw_red = confPHOTred{6};
    // int bias_r_red_mV = confPHOTred{7};
    // int bias_d_red_mV = confPHOTred{8};
    // int nb_cycles_obs_cal = confOBCP{0};
    // int grat_step_up = confOBCP{1};
    // int grat_step_dn = confOBCP{2};
    // Following represent number of DMC internal loops, each loop accumulates
    // nb_rdouts_plateau BOLO readouts (not yet implemented!)
    int nb_SRC = confOBCP{3};
    int nb_rdouts_plateau = confOBCP{4};
    // int nb_CS1_CS2 = confOBCP{5};
    // int nb_grat_step_up = confOBCP{6};
    // int nb_grat_step_dn = confOBCP{7};
    // int grat_start_pos = confOBCP{8};
    // int grat_start_time= confOBCP{ 9};
    // int grat_def_pos   = confOBCP{10};
    // int grat_def_time  = confOBCP{11};
    // int chop_pos_SRC    = confOBCP{12};
    // int chop_pos_REF1     = confOBCP{13};
    // int chop_pos_REF2     = confOBCP{14};
    // int chop_pos_CS1      = confOBCP{15};
    // int chop_pos_CS2      = confOBCP{16};
    // int chop_def          = confOBCP{17};
    // int detector          = confOBCP{18};
    int filterPOS = confOBCP{19};
    // Call OBCP for the current  S/C position
    time_array = OBCP_phot_staring(nb_SRC,comp_mode_blu,comp_mode_red);
    if(verbose) {
        debug_print("CmdOBCP7 returns " + time_array);
    }
    // Add sync()
    sync();

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 1.0 07-Jun-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Flash_SWON {
    /* No variables to call PacsEng_Spec_Flash_SWON                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Flash_SWON                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Flash_SWON()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Flash_SWON();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id: PacsPhotCommandOBCP3.txt,v 1.6 2007/08/10 10:25:10 dcesarsk Exp $ 
// Purpose       : Execute OBCP#3 with the provided parameters
//
// CUS author    : DAC
//
// Input arguments
// Type                      Description
// tuple  {double,int,int,  {waveLen,order,gratPos,
//         int,int,int}      gratWidth,nbStep,gratStep}  
//
// Return values
// Type    Name      Default      Description
//
// Description   : Calls OBCP#3 (OBCP_fixed_fixed_photo) with given
//                 parameters.
//                 OBCP3 (aka fixed_fixed) performs symmetrical choping of
//                 amplitude around
//                 3 positions (called P2, P7, and P8 in the documentation). 
//                 Here, P7 and P8 are computed as 
//                 P7 = P2 + max_dither/2
//                 P8 = P2 - max_dither/2 
//                 max_dither is stored in a CAL-U file read by 
//                 PacsPhotEstimatorOBCPn
//
// Dependencies  : OBCP_fixed_fixed_phot
//                 DMC_fixed_fixed_phot
//
// Preconditions : 
//                 
// Comments      :
// 
// History       : 
// 0.1 DAC 10-aug-2006. Created from PacsPhotCommandOBCP5
// 0.2 DAC 31-aug-2006 Return actual duration (includes TC)
// 0.3 DAC  1-sep-2006 WARNING: the chopper movements must be given as
//                              relative, i.e. a displacement
// 0.4 DAC 12-jan-2007 Use max_dither and max_dither/2
// 0.5 DAC 19-jan-2007 Use symmetrical dithering: + - max_dither/2
//
int[] procedure PacsPhotCommandOBCP3 {
    {int,int,int,int,int,int,int,int,int} confPHOTblu = {0,0,0,0,0,0,0,0,0}; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int} confPHOTred = {0,0,0,0,0,0,0,0,0}; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // OBCP parameters
    bool verbose = true; // Print debug information
}{
    // Register starting time
    int start_time = time();
    // Create array of durations
    int[] time_array = [0,0,0,0,0];
    if(verbose) {
        debug_print("+++ Starting PhotCommandOBCP3");
        debug_print("OBCP3: " + confOBCP);
    }
    // Long sequence to "unpack" contents of tuples
    // (indices are not sequential since confXXXX tuples are inherited from
    //  SPECTRO)
    int gain = confPHOTblu{0};
    int comp_mode_blu = confPHOTblu{3};
    int glitch_det_blu = confPHOTblu{4};
    int nb_raw_blu = confPHOTblu{6};
    gain = confPHOTred{0};
    int comp_mode_red = confPHOTred{3};
    int glitch_det_red = confPHOTred{4};
    int nb_raw_red = confPHOTred{6};
    int nb_main_loops = confOBCP{0};
    int max_dither = confOBCP{1};
    int nb_chop_cycle = confOBCP{2};
    int nb_SRC_REF = confOBCP{3};
    int nb_rdouts_plateau = confOBCP{4};
    int nb_CS1_CS2 = confOBCP{5};
    int chop_pos_SRC = confOBCP{12};
    int chop_pos_REF1 = confOBCP{13};
    int chop_pos_REF2 = confOBCP{14};
    int chop_pos_CS1 = confOBCP{15};
    int chop_pos_CS2 = confOBCP{16};
    int chop_def = confOBCP{17};
    int detector = confOBCP{18};
    int filterPOS = confOBCP{19};
    // Call OBCP for the current  S/C position
    // Chop between SRC and REF1
    // Relative displacement
    int chop_REL = chop_pos_REF1 - chop_pos_SRC;
    if(verbose) {
        debug_print("OBCP3 P#2/P#5: " + chop_pos_SRC + "/" + chop_REL);
    }
    time_array = OBCP_fixed_fixed_photo(nb_main_loops,chop_pos_SRC,nb_rdouts_plateau,nb_chop_cycle,chop_REL,-chop_REL,chop_pos_SRC + max_dither / 2,chop_pos_SRC - max_dither / 2,comp_mode_blu,comp_mode_red);
    // Add sync()
    sync();
    // Return elapsed time
    time_array[0] = time() - start_time;
    if(verbose) {
        debug_print("CmdOBCP3 returns " + time_array);
    }

    return time_array;
}

// CVS comments  : $Id: PacsPhotCommandOBCP4.txt,v 1.3 2007/04/25 15:14:04 dcesarsk Exp $ 
// Purpose       : Execute OBCP#4 with the provided parameters
//
// CUS author    : DAC
// Script file   : PacsPhotCommandOBCP4.txt 
//
// Input arguments
// Type                      Description
// tuple  {double,int,int,  {waveLen,order,gratPos,
//         int,int,int}      gratWidth,nbStep,gratStep}  
//
// Return values
// Type    Name      Default      Description
//
// Description   : Calls OBCP#4 (OBCP_chopped_photometry) with given
//                 parameters
// Dependencies  : OBCP_chopped_photometry
//                 DMC_phot_2_3_chop
//
// Preconditions : 
//                 
// Comments      : Filter must be positioned before calling this procedure
// since there is no FLTW move here!! This insures that (eventual) nods have 
// same duration. PacsPhotSlewCal moves filter to needed position and leaves
// it there.
// 
// History       : 
// 0.1 DAC 24-nov-2005
// 0.2 DAC 31-aug-2006 - Return elapsed time
//                     - Editorial cleanup (remove SPECTRO from confXXX)
//
int[] procedure PacsPhotCommandOBCP4 {
    {int,int,int,int,int,int,int,int,int} confPHOTblu = {0,0,0,0,0,0,0,0,0}; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int} confPHOTred = {0,0,0,0,0,0,0,0,0}; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // OBCP parameters
    bool verbose = true; // Print debug information
}{
    // Register start time
    int start_time = time();
    // Create array of durations
    int[] time_array = [0,0,0,0,0];
    if(verbose) {
        debug_print("+++ Starting PhotCommandOBCP4");
        debug_print("OBCP: " + confOBCP);
    }
    // Long sequence to "unpack" contents of tuples
    // (indices are not sequential since confXXX are inherited from SPECTRO)
    int gain = confPHOTblu{0};
    int comp_mode_blu = confPHOTblu{3};
    int glitch_det_blu = confPHOTblu{4};
    int nb_raw_blu = confPHOTblu{6};
    gain = confPHOTred{0};
    int comp_mode_red = confPHOTred{3};
    int glitch_det_red = confPHOTred{4};
    int nb_raw_red = confPHOTred{6};
    int nb_cycles_obs_cal = confOBCP{0};
    int nb_SRC_REF = confOBCP{3};
    int nb_rdouts_plateau = confOBCP{4};
    int nb_CS1_CS2 = confOBCP{5};
    int chop_pos_SRC = confOBCP{12};
    int chop_pos_REF1 = confOBCP{13};
    int chop_pos_REF2 = confOBCP{14};
    int chop_pos_CS1 = confOBCP{15};
    int chop_pos_CS2 = confOBCP{16};
    int chop_def = confOBCP{17};
    int detector = confOBCP{18};
    int filterPOS = confOBCP{19};
    // Call OBCP for the current  S/C position
    // Chop SRC-REF1-SRC-REF2
    time_array = OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
    // Add sync()
    sync();
    // Return elapsed time
    time_array[0] = time() - start_time;
    if(verbose) {
        debug_print("CmdOBCP4 returns " + time_array);
    }

    return time_array;
}

// File          : PACS_Spec_Dark_CS_SimultaneousWarmUp
// Missionphase  : PACS FM IST   SOVT2
//
// Purpose       : Dark Current Measurement / Assessment of straylight, PACS Spectro.
//
// Author        : Pierre Royer
// CUS script	 : PR
// CVS file	 :
//
// Arguments     : 
//
// Description   :   Visit grating positions of Low RSRF for the dark
//	     Estimate Straylight contribution from visiting High RSRF positions & placing the FW outside of any regular filter position.
//	     Do it for both filters
//	Specific to the SOVT2 version of this test:     
//	     Warm up the CSs (both simultaneously) and chop between them every 3 minutes 
//	     There should be transients > 3 minutes at the beginning (low flux), but this should at least give an idea, and several samples over the warm up time
//
// Dependencies  :
//
// Comments      : !!! It is supposed that PacsEng_Spec_setup has been run before this script, with current to both CSs == 0. !!!
//
// Version      : 1.1
// History       : 1.0 / 22-Oct-2008 
//	 1.1 / 23-Jul-2009 Update biases & SPU mode to slope fitting (SPRs PACS-1798 & 1858)
//                             29-07-2009 Update history to reflect last modification (SCR  PHS-1128)
//
procedure PACS_Spec_Dark_CS_SimultaneousWarmUp {
    int obs_time = 540; // observing time in seconds per CS/FW/Grat setting
    int chop_time = 180; // duration of chopper plateau during rise of CS temp (0 = no chopping)
}{
    //
    // Declare the set of variables specific to this test
    // ===========================
    //
    string[] chopPos = ["pos_CS1","pos_CS2"];
    int choppos = 0;
    //
    // Define the combinations of Grating & FW positions to be tested on each CS
    string[] filterPos = ["POS B","POS B","POS A","POS A"];
    int[] gratingPos = [50000,740000,675000,800000];
    int n_settings = length(gratingPos);
    if(length(filterPos) != n_settings) {
        debug_print("Inconsistent number of grating and filter wheel positions specified");
    }
    //
    // Declare the CS Temps (48, 58 Ohms, copied from the SPEC_setup block (in 
    // ============= 
    double temp_CS1 = 48.0;
    //  Temperature 55K for the PACS calibration source 1 
    double temp_CS2 = 58.0;
    //  Temperature 60K for the PACS calibration source 2
    //
    // Declare the set of CRE variables
    // ===================
    double bias_d_blue = 0.1;
    double bias_d_red = 0.042;
    double bias_res_blue = 0.01;
    double bias_res_red = 0.01;
    int ramp_blue = 64;
    int ramp_red = 64;
    int capacity_blue = 0;
    int capacity_red = 0;
    // 
    // Declare the set of SPU variables
    // ===================
    //
    // Compression mode blue channel : Nominal
    int comp_mode_blu = 16;
    // Compression mode red channel : Nominal
    int comp_mode_red = 16;
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_blu = 64;
    // Nb of red samples per sub-ramp
    int nb_samp_subramp_red = 64;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUL
    int nb_raw_spu_red = 3;
    // Glitch detection; 0=on; 1=off
    int glitch_det = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    int ramp_fit_alg = 0;
    // Start SPU or not [true,false]
    bool startSPU = true;
    //
    // SETUP CRE & SPU
    // ==========
    // Setup CREs
    SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red);
    //
    // Setup SPU
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //
    // PART 1 : CS OFF, VISIT LOW & HIGH RSRF POSITIONS IN BOTH FILTERS
    //
    for(int cs = 0 .. length(chopPos) - 1) {
        //
        // Position the chopper
        // ============
        choppos = ilookup("CHOPPERCSparams","SPEC",chopPos[cs]);
        PACS_Chop_Move_Abs(choppos);
        //
        for(int n = 0 .. n_settings - 1) {
            debug_print("choppos " + choppos + " n " + n + " filterPos[n] " + filterPos[n] + " gratingPos[n] " + gratingPos[n]);
            //
            // ==FW POS ==
            SPEC_fltw_move(filterPos[n]);
            //
            // ==GRAT POS ==
            Pacs_DMC_MOVE_GRAT_ABS(gratingPos[n]);
            //
            // == OBS TIME ==
            delay(obs_time);
            //
            // == FW --> 90 DEGREES == 
            SPEC_fltw_move_90degrees();
            //
            // ==GRAT POS ==
            Pacs_DMC_MOVE_GRAT_ABS(gratingPos[n]);
            //
            // == OBS TIME ==
            delay(obs_time);
            //
        }
    }
    //
    // PART 2 :  RISING CS TEMPs, CHOP SLOWLY BETWEEN BOTH CS
    //
    // ==FW POS ==
    SPEC_fltw_move("POS B");
    //
    // ==GRAT POS ==
    Pacs_DMC_MOVE_GRAT_ABS(50000);
    //
    debug_print("Grating reset to 50000, FW set to POS B, CS switched on and warmed up");
    //
    // PACS CALIBRATION SOURCES
    CONF_cs("Both");
    CS_on_off("CS1","ON");
    CS_temp("CS1",temp_CS1);
    CS_on_off("CS2","ON");
    CS_temp("CS2",temp_CS2);
    //
    delay(chop_time);
    if(chop_time > 0) {
        //
        int nchop = iround(2200.0 / double(chop_time));
        debug_print("Chopping every " + chop_time + " seconds");
        debug_print("nchop x chop_time = " + nchop + " x " + chop_time + " = " + nchop * chop_time);
        //
        if(nchop >= 2) {
            //
            for(int i = 0 .. nchop - 2) {
                choppos = ilookup("CHOPPERCSparams","SPEC",chopPos[i % 2]);
                PACS_Chop_Move_Abs(choppos);
                debug_print("choppos " + choppos);
                delay(chop_time);
            }
        }
    } else {
        choppos = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
        PACS_Chop_Move_Abs(choppos);
        debug_print("No chopping: chopper position " + choppos);
        delay(2100);
    }
    //
    // FINALISATION
    //
    // Return Chopper & grating to default
    // ===================================
    Pacs_DMC_MOVE_GRAT_ABS(500000);
    delay(1);
    PACS_Chop_Move_Abs(0);
    delay(10);
    //
    // SYNC
    //= = =
    sync();
    //
    // End of Script
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 1.0 07-Jun-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Flash_SWOF {
    /* No variables to call PacsEng_Spec_Flash_SWOF                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Flash_SWOF                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Flash_SWOF()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Flash_SWOF();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Filename	: Pacs_Spec_spu_data_rate
//
// Purpose	: SPU data rate check (spectroscopy)
//
// Author	: Roland Vavrek
// CUS script	: RV
// CVS file	: 
//
// Arguments	: No interactive parameters
//                         
//                 
//		   
// Description	: Four junks of test blocks are executed, each contains 2x120 sec measurement, 
//                        the first is configured with sub-slope fitting the second uses sub-means for 2
//                        chopper positions
//  
//                  
// Dependencies :  - SPEC_heater
//                          - Chop_mov_abs
//                          - SPEC_Gra_move_abs_raw
//                          - SPEC_SPU_reset
//                          - SPEC_CRE_setup
//                          - SPEC_SPU_setup
//
//
// Preconditions : - PACS is switched on
//                         - Setup spectroscopy  (e.g. SPEC_orbit_prologue_eqm_imt block has been executed)
//	      - Mechanics and CS controllers are SWON and ENABLED (e.g. SetupSpectroscopyEQMIMT)
//                         - CS2 temperature is raising but not yet stabilized
//
// Comments	: Blue heater2 is switched on
//
// Version	: 2.1
//               
// History	: 2.0 25-mar-2008 VDP Adjusted to match PV phase syntax 
// 		  1.5 09-Apr-2007 RV: Reduced duration (60 sec delay, only 1 loop on chop zero pos), capa_blu = 0, bias_d_blu = 0.198
//                 2.1 07-Apr-2008 Changed bias values to in-flight default, heater to 0.78mA
//                1.4 05-Apr-2007 RV: Extended for 2 chopper positions (CS2 and chopper zero) and FM/ILT constants applied 
//                1.3 10-Apr-2006 HF: adapted to one blue heater only
//                1.2 27-Apr-2005 Creation by RV, Nominal SPU setup, SPU reset at the end
//                1.1 22-Apr-2005 Creation by RV, 4 junks organized in a loop
//                1.0 17-Apr-2005 Creation by RV  
//                        
//                                
//
procedure Pacs_Spec_spu_data_rate {
}{
    // 
    // 1 Nominal detector parameters
    //
    // Red  CRE register (capa_red=0)
    int cre_ctrl_red = 386;
    // Blue CRE register (capa_blu=0)
    int cre_ctrl_blu = 386;
    // Red  ramp length
    int ramp_len_red = 64;
    // Blue ramp length
    int ramp_len_blu = 64;
    // BIAS_R for red spectro  (0-1V)
    double bias_r_red = 0.01;
    // BIAS_R for blue spectro (0-1V)
    double bias_r_blu = 0.01;
    // BIAS_D for red spectro  (0-1V)
    double bias_d_red = 0.03;
    // BIAS_D for blue spectro (0-1V)      
    double bias_d_blu = 0.08;
    // Capacitor red  (0=100fF,4=300fF,8=1pf,12=3pF)
    int capa_red = 12;
    // Capacitor blue (0=100fF,4=300fF,8=1pf,12=3pF)
    int capa_blu = 0;
    // Set BLUE heater parameters (uA)
    double heater_blu = 0.78;
    // Stimulate blue heater
    SPEC_heater(heater_blu);
    //
    // 2 Mechanics parameters
    //
    // chopper in zero position
    int chop_def_zero = 664;
    // chopper on CS2
    int chop_CS2_pos = 21200;
    // grating on a key wavelength
    int grat_key_lambda = 535000;
    // 
    // 3 SPU parameters
    //
    // Compression mode blue channel : Nominal
    int comp_mode_blu = 16;
    // Compression mode red channel : Nominal
    int comp_mode_red = 16;
    // Nb of blue samples per sub-ramp 
    int nb_samp_subramp_blu = 64;
    // Nb of red samples per sub-ramp 
    int nb_samp_subramp_red = 64;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUL
    int nb_raw_spu_red = 3;
    // Glitch detection; 0=on; 1=off
    int glitch_det = 1;
    // Start SPU or not [true,false]
    bool startSPU = true;
    // Ramp fitting algorithm
    int ramp_fit_alg = 0;
    //
    // 4 Start 4 junks of subramp fitting/subramp averaging pairs on CS2
    //
    // Position chopper on CS2
    Chop_mov_abs(chop_CS2_pos);
    // Move grating to a key wavelength
    SPEC_Gra_move_abs_raw(grat_key_lambda);
    // Stop SPU    
    SPEC_spu_reset();
    // Write detector parameters     
    SPEC_CRE_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,heater_blu);
    // Start 4 junks of subramp fitting - subramp averaging pairs    
    for(int junks = 1 .. 4) {
        // Ramp fit algorithm [0=LstSq;1=mean value]
        ramp_fit_alg = 0;
        // Start SPU
        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
        // Staring measurement for 2min
        delay(60);
        // Stop SPU
        // SPEC_spu_reset_block();
        SPEC_spu_reset();
        // Ramp fit algorithm [0=LstSq;1=mean value]
        ramp_fit_alg = 1;
        // Start SPU
        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
        // Staring measurement for 2min
        delay(60);
        // Stop SPU    
        SPEC_spu_reset();
    }
    //
    // 5 Move chopper to zero position
    //
    // Position chopper on zero position
    Chop_mov_abs(chop_def_zero);
    //
    // 6 Start 4 junks of subramp fitting/subramp averaging pairs on zero chopper position
    //
    // Position chopper on zero position
    Chop_mov_abs(chop_def_zero);
    // Move grating to a key wavelength
    SPEC_Gra_move_abs_raw(grat_key_lambda);
    // Stop SPU    
    SPEC_spu_reset();
    // Start 4 junks of subramp fitting - subramp averaging pairs    
    for(int junkstwo = 1 .. 1) {
        // Ramp fit algorithm [0=LstSq;1=mean value]
        ramp_fit_alg = 0;
        // Start SPU
        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
        // Staring measurement for 2min
        delay(60);
        // Stop SPU
        SPEC_spu_reset();
        // Ramp fit algorithm [0=LstSq;1=mean value]
        ramp_fit_alg = 1;
        // Start SPU
        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
        // Staring measurement for 2min
        delay(60);
        // Stop SPU    
        SPEC_spu_reset();
    }
    //
    // 7 Move chopper to zero position
    //
    // Position chopper on zero position
    Chop_mov_abs(chop_def_zero);
}

// Missionphase  : FMIST
//
// Purpose       : SWOF Grat
//
// Author        : PR
// Arguments     : 
//
// Version       : 1.0 
// History       : 1.0 29-Jul-2007 PR
//
procedure PACS_Spec_Gra_IST_SWOF {
}{
    Pacs_DMC_SWOF_GRAT_CONT();
    delay(1);
}

// File          : PACS_Phot_Fil_Diaghk_Setup.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Switch on diagnostic hk relevant to photometer filterwheel  
//
// Author        : P.Royer, B.Vandenbussche, T. Mueller
// CUSification  : DAC
// Arguments     :
//
// Description   : Photometer filter wheel diagnostic housekeeping ON
//               :
// Comments      : Code of this building block has been taken out of PTP 0.7.7
//                 by PR.
//                 
//
// Version       : 1.7
// History       : 1.0 / 25-Nov-2003 initial version by BV 
//                 1.1 / 06-Jan-2004 syntax checked 
//                 1.2 / 12-Jan-2003 checksum on actual parameters only - BV
//                 1.3 / 13-Jan-2003 bug fix in list syntax
//                 1.4 / 31-May-2004 Added hall sensor readouts
//                 1.5 / 07-Jul-2004 modified for photometer FW by TM
//                 1.6 / 19-Jul-2004 Added IMOTA and IMOTB [BV]
//                 1.7 / 17-Nov-2004 modified for EQM test, diag_hk_period set to 5 
procedure PACS_Phot_Fil_Diaghk_Setup {
}{
    // diag_hk_period  integer Diagnostic HK period : 4=synch on detect, >4=ms, 0=1KHz (not recommended)
    int diag_hk_period = 5;
    // Default time for one 'standard' command execution (sec)
    // set command_time    0.5
    // DMC_WRT_DIAG_HK_LIST
    // DMC_DATA_LENGTH            PP065420 contains the number of desired HK parameters
    // DMC_4_BYTES_WORDS_DATA     PP067420 contains the desired HK parameters' IDs
    // DMC_CHECKSUM               PP066420
    //
    //     DMC_FW_PHOT_CTRL        211
    //     DMC_FWGRAT_HALLA        256
    //     DMC_FWGRAT_HALLB        257
    //     DMC_FWPH_CUR_POS        260
    //     DMC_FW_PHOT_TEMP        406
    //     DMC_FWPHOT_POS_A        563
    //     DMC_FWPHOT_POS_B        569
    //     DMC_FPU_T_SEN_ST        404
    //     DMC_FW_GR_IMOTA         560
    //     DMC_FW_GR_IMOTB         567
    //     DMC_FW_GR_VMOTA         556
    //     DMC_FW_GR_VMOTB         564
    //
    //set hk_list [list {PP067420 211} {PP067420 256} {PP067420 257} {PP067420 260} \
    //                  {PP067420 406} {PP067420 563} {PP067420 569} {PP067420 404} \
    //                  {PP067420 560} {PP067420 567} {PP067420 556} {PP067420 564} \
    //            [list PP067420 [expr 0xFFFF]]]
    //
    // set chksum [getChkSum -d -32 $hk_list]
    int nb_words = 13;
    {int}[] list_tuple = [{211},{256},{257},{260},{406},{563},{569},{404},{560},{567},{556},{564},{0xffff}];
    int[] list_int = [211,256,257,260,406,563,569,404,560,567,556,564,0xffff];
    int chksum = checksum("int",list_int);
    // eval tcsend PC160420 \{PP065420 13\} $hk_list \{PP066420 $chksum\}
    // waittime $command_time
    // Send the TC
    Pacs_DMC_WRT_DIAG_HK_LIST(nb_words,list_tuple,chksum);
    delay(1);
    //DMC_START_DIAG_HK
    // DIAG_HK_PERIOD             PP076420
    // tcsend PC146420 [list PP076420 $diag_hk_period]
    // waittime $command_time
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    //------------------
    // End of procedure
    //------------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Purpose       : Wavelength calibration and instrumental profile
// Author        : HF
//
// Arguments     :
// string fltPOS            Filter wheel position (0="POS A", 1="POS B")
// int grat_start           Grating start position for scan
// int grat_stepsize        Grating step size
// int grat_numsteps        Number of grating steps in one direction
// int grat_numramps        Number of ramps per grating position
// int chop_def             Chopper position during grating scan
// int nb_rdout_ramp        Number of readouts per ramp
// int num_updown           Number of grating updown scans
// int grat_def             Position of grating after the scan
// int capa_red             Red capacitor
// int capa_blu             Blue capacitor
// double bias_r_blu        Bias "r" blue
// double bias_r_red        Bias "r" red
// double bias_d_blu        Bias "d" blue
// double bias_d_red        Bias "d" red
// int nb_samp_subramp_blu  Nb of blue samples per sub-ramp
// int nb_samp_subramp_red  Nb of red samples per sub-ramp
//
// Prerequisite  : PACS must be on and configured for spectroscopy
//
// Description   : Uses OBCP28 for executing a parameterized scan of any length,
//                 stepsize etc. Represents a generic non-chopped grating scan               :
// Comments      :
//
// Version       : 2.0
// History       : 0.1 10-sep-2007 Converted into Eng OBS by DAC
//                 0.2 14-jan-2008 DAC Added bias_r... input variables
//                 0.3 15-jan-2008 Renamed WaveCalProc to WaveCalNoChop
//                                 Renamed this module to PacsEng_WaveCalNoChop 
//                 1.0 15-feb-2008 DAC Use FinePointing mode instead of dummy
//                                     Renamed to PacsCal_xxxx
//                 1.1 DAC Will have to add SPEC_aot_epilogue to "final hold"
//                         and PacsSpecSlewCal to "slew" phase.           
//                 2.0 26-sep-2008 VDP: implemented PacsSpecSlewCal
//		       	    	   added SPEC_aot_epilogue to final_hold
//			    	   transfered WriteOBSID and WriteEndID from Procedure back 
//			    	   main module and added to Slew and final_hold
//				   Implemented: within WriteOBSID and Prologues/Epilogues data_rate()
//		   3.0 17-dec-2008: VD fix VERY important BUG: get PacsSpecDefaults to
//		       		    run properly PacsSpecSlewCal (to set
//				    properly detector/comp_mode and Chop_def
//		   4.0 22-apr-2009 VD SPR 5447
//		   5.0 23-apr-2009 VD SPR 6482
//                                            6.0 22-jun-2009 HF SCR 7157
//		   7.0 23-jul-2009 BV SPR 1798 : default biases
//		   8.0 14-sep-2009 VD SCR PHS-1173
//
obs PacsCal_WaveCalNoChop {
    /* Needed variables to call WaveCalNoChop */
    string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B"
    int order = 2; // Order selection
    int grat_start = 500000; // grating start position for scan
    int grat_stepsize = 200; // grating step size
    int grat_numsteps = 50; // number of grating steps in one direction
    int grat_numramps = 3; // number of ramps per grating position
    int chop_def = 648; // chopper position during grating scan
    int nb_rdout_ramp = 64; // number of readouts per ramp
    int num_updown = 1; // number of grating updown scans
    int grat_def = 496000; // position of grating after the scan
    int capa_red = 12; // Red capacitor
    int capa_blu = 12; // Blue capacitor
    double bias_r_blu = 0.0101; // Bias "r" blue
    double bias_r_red = 0.0101; // Bias "r" red
    double bias_d_blu = 0.10001; // Bias "d" blue
    double bias_d_red = 0.04201; // Bias "d" red
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp    
    int comp_mode_blu = 16; // compression mode for blue detector
    int comp_mode_red = 16; // compression mode for red detector
    int nb_raw_red = 3; // number of red pixels
    int nb_raw_blu = 3; // number of blue pixels
    int naifid = 0; // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    double yoffset = 0.0; // yoffset [arcsec]
    double xoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    bool verbose = true;
}{
    // compiting time for slw / calibration during slew time and others
    // Set OBSID
    int tobsid = duration(WriteOBSID($OBSID));
    // SPEC parameters for BLU and RED               
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    string throwUsage = "small";
    string extraConf = "normal";
    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // frstLstGratPos is the last position for the grating after the Cals done
    // during Slew time... must be same as observations start position: grat_pos   
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    // "N/A" in string because of indexing 0,1,2,3
    string[] choix = ["N/A","order1","order2","order3","sed4"];
    string order_str = "order" + order;
    //    if(choix[order] != "order1") {
    //        double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    // have to introduce the logic for KeyWL as fucntion of order + filter
    double[] keyWAVE = [150.0];
    if(choix[order] == "order3" && fltPOS == "POS B") {
        error("Filter B and order3 are not compatible");
    }
    if(choix[order] == "order1" && fltPOS == "POS A") {
        keyWAVE = [180.0];
    }
    if(choix[order] == "order1" && fltPOS == "POS B") {
        keyWAVE = [150.0];
    }
    if(choix[order] == "order2" && fltPOS == "POS B") {
        keyWAVE = [75.0];
    }
    if(choix[order] == "order3" && fltPOS == "POS A") {
        keyWAVE = [60.0];
    }
    // this is for extended Blue
    if(choix[order] == "order2" && fltPOS == "POS A") {
        keyWAVE = [60.0];
        choix[order] = "sed4";
    }
    // no need for SpecKeyWave!
    //    double keyWL = PacsSpecKeyWaves(order_str);
    //    double[] keyWAVE = [keyWL];
    int tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]));
    int tOBSID = duration(WriteOBSID($OBSID));
    int tepilogue = duration(SPEC_aot_epilogue(grat_start,grat_def,verbose));
    int tEndID = duration(WriteEndID());
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    //Minimum slew time
    int tslewmin = tOBSID + tpacsSlewCal;
    //Initial hold
    int tih = 0;
    //Final hold
    int tfh = tepilogue + tEndID;
    //Duration of "stable" pointing
    int tp = duration(WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_def,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red));
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            int tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]);
        } else {
            if(state[0] == 3) {
                //      Call the WaveCal procedure
                WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_def,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red);
            } else {
                if(state[0] == 5) {
                    SPEC_aot_epilogue(grat_start,grat_def,verbose);
                    WriteEndID();
                }
            }
        }
    }
}

// Script        : Pacs_Chopper_AutoOpt.txt
// Missionphase  : Commissioning
//
// Purpose	: Check a series of different chopper controller settings by
//                chopping between +/- 12000 units (~4 deg)
//                  
// Author	: Markus Nielbock/Helmut Dannerbauer
// CUS author 	: MN/HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-12000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions: PACS switched on and Chopper switched off.
//                 
// Comments	: This script is based on the commanding script
//                PACS_Chopper_uk_move_12000_OBS.cus
//
// Version	: 1.1
// 
// History 	: 1.0 20-Nov-2007 (MN) Script to do simple chopper cycle 
//         	  1.1 10-Mar-2008 (MN) adopted extended CUS naming conventions
//
// Initialise input parameters:
// Defines control parameter range, loops run from k(p,i,c,f)min to
// k(p,i,c,f)max defining the inverse of the ratio of parameter change w.r.t.
// the default value.
procedure Pacs_Chopper_AutoOpt {
    int kpmin = 0 in [-3,3];
    int kpmax = 0 in [-3,3];
    int kimin = 0 in [-3,3];
    int kimax = 0 in [-3,3];
    int kcmin = 0 in [-3,3];
    int kcmax = 0 in [-3,3];
    int kfmin = 0 in [-3,3];
    int kfmax = 0 in [-3,3];
}{
    // PACS instrument code for BBID
    int instrument = 0x40000000;
    // chopper position (approx. +/- 4 deg in FPU)
    int chop_pos = 12000;
    // number of chop cycles
    int cycle = 10;
    // length of plateau time in seconds
    int plateau_time = 2;
    // Initialise variables for conversion from int to string and double
    string sU = "+0";
    string sV = "+0";
    string sW = "+0";
    string sX = "+0";
    double dU = 0.0;
    double dV = 0.0;
    double dW = 0.0;
    double dX = 0.0;
    int bU = 0x4000;
    int bV = 0x400;
    int bW = 0x40;
    int bX = 0x4;
    // CALU table file to be accessed
    string fileU = "PacsTable_CONFChopper_auto";
    // Start diag. HK
    SPEC_Chopper_dhk_5hk_1khz_bb();
    // Cycle through calibration table columns 
    if(kpmax < kpmin) {
        kpmax = kpmin;
    }
    if(kimax < kimin) {
        kimax = kimin;
    }
    if(kcmax < kcmin) {
        kcmax = kcmin;
    }
    if(kfmax < kfmin) {
        kfmax = kfmin;
    }
    for(int u = kpmin .. kpmax) {
        for(int v = kimin .. kimax) {
            for(int w = kcmin .. kcmax) {
                for(int x = kfmin .. kfmax) {
                    // calculate inverse -> ratio of changes
                    if(u != 0) {
                        dU = 1.0 / double(u);
                    } else {
                        dU = 0.0;
                    }
                    if(v != 0) {
                        dV = 1.0 / double(v);
                    } else {
                        dV = 0.0;
                    }
                    if(w != 0) {
                        dW = 1.0 / double(w);
                    } else {
                        dW = 0.0;
                    }
                    if(x != 0) {
                        dX = 1.0 / double(x);
                    } else {
                        dX = 0.0;
                    }
                    if(abs(dU + dV + dW + dX) < 0.01) {
                        // convert int to string variables
                        // and determine BBID for column recovery
                        // BBID is a 32 bit word with:
                        // 2 bits: Instrument (PACS = 01)
                        // 14 bits: block number (not used here)
                        // 16 bits: a counter, used here as follows:
                        //          4 bits for every PID parameter (P, I, C, F)
                        //          of this: 2 bits for the sign (01 = +, 10 = -)
                        //                   2 bits for the number (01, 10, 11 = 1, 2, 3)
                        if(u >= 0) {
                            sU = "+" + u;
                            bU = 16384 + 4096 * u;
                        } else {
                            sU = "" + u;
                            bU = 32768 - 4096 * u;
                        }
                        if(v >= 0) {
                            sV = "+" + v;
                            bV = 1024 + 256 * v;
                        } else {
                            sV = "" + v;
                            bV = 2048 - 256 * v;
                        }
                        if(w >= 0) {
                            sW = "+" + w;
                            bW = 64 + 16 * w;
                        } else {
                            sW = "" + w;
                            bW = 128 - 16 * w;
                        }
                        if(x >= 0) {
                            sX = "+" + x;
                            bX = 4 + x;
                        } else {
                            sX = "" + x;
                            bX = 8 - x;
                        }
                        // construct column identifier
                        string calUcol = "P" + sU + "I" + sV + "C" + sW + "F" + sX;
                        debug_print("CALU column is " + calUcol);
                        int bbid = instrument + bU + bV + bW + bX;
                        WriteBBID(bbid);
                        // Upload Chopper Controller Parameter
                        CONF_chopper(fileU,calUcol);
                        delay(2);
                        // Switch on and enable chopper controller 
                        PACS_Chopper_SWON_SWOF_only("ON");
                        delay(2);
                        EnDis_chopper("ON");
                        delay(5);
                        // move chopper to zero
                        PACS_Chopper_mov_abs_fm_bb(0);
                        delay(1);
                        // chop cycle
                        int i = 1;
                        while(i <= cycle) {
                            PACS_Chopper_mov_abs_fm_bb(chop_pos);
                            delay(plateau_time);
                            PACS_Chopper_mov_abs_fm_bb(-chop_pos);
                            delay(plateau_time);
                            i = i + 1;
                        }
                        // move chopper to zero
                        PACS_Chopper_mov_abs_fm_bb(0);
                        delay(1);
                        // Disable and switch off chopper controller 
                        EnDis_chopper("OFF");
                        delay(2);
                        PACS_Chopper_SWON_SWOF_only("OFF");
                        delay(5);
                    }
                }
            }
        }
    }
    // Stop diagnostic housekeeping
    PACS_stop_dhk_fm_bb();
    sync();
}

// CVS comments  : $Id: WriteOBSID.txt,v 1.7 2007/11/06 08:39:25 dcesarsk Exp $ 
// Missionphase  : 
//
// Purpose       : Set the OBSID via DEC/MEC; show decoded OBSID on
//                 user screen 
//
// CUS script    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
// Original TCL  : N/A
// CVS file      : WriteOBSID.txt
//
// Input arguments
// Type  Name     DefVal  Description
// int   iOBSID   N/A     OBSID obtained from environment
//
// Description   : Obtain OBSID from run environment and send TC to DMC
//                 Write decoded OBSID to log file
//
// Dependencies  : Pacs_DMC_SET_OBSID
//                 DecodeOBSID
//                 
// Comments      : 
//
// Version       : 2.0
//   		   0.1 23-Sep-2004 First creation
// History       : 0.2 28-Sep-2004 Remove set_unset; write
//                                 decoded OBSID to output log
//                 0.3  7-Oct-2004 Renamed to WriteOBSID to match to names of
//                                 related procedures
//                 0.4 12-Oct-2004 Added write to EGSE environment (need
//                                 to add write to IST environment ??)
//                 0.5 21-Oct-2004 Added write to CDMS
//                 1.0  9-May-2005 DAC Removed write to EGSE and CDMS (not
//                                 needed at Astrium)
//                 1.1 20-oct-2005 Added sync() as I will need the "true"
//                                 duration
//                 1.2  5-nov-2007 Added delay(1) before first TC to wait
//                                 for completion of bus_configure
//		   2.0 23-sep-2008 SCR4431 hk_data_rate
//
procedure WriteOBSID {
    int iOBSID = 0x20000000; // Observation ID  
}{
    // Wait 1 second to allow for bus_configure
    delay(1);
    // Write OBSID to DEC/MEC and decode to output log
    Pacs_DMC_SET_OBSID(iOBSID);
    ess_hk_data_rate(0.31);
    non_ess_hk_data_rate(4.0);
    // sync the bus
    sync();
    // Inform CUS debugger
    //   DecodeOBSID(iOBSID);
}

// Missionphase  : FMIST
//
// Purpose       : SWON Grat
//
// Author        : PR
// Arguments     : 
//
// Version       : 1.0 
// History       : 1.0 29-Jul-2007 PR
//
procedure PACS_Spec_Gra_IST_SWON {
}{
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
}

// File          : PACS_Spec_Fil_Testseq.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Position sequence test of spectrometer filterwheel  
//
// Author        : BV, modifications by TM
// CUSification  : DAC 
// Arguments     :
//
// Description   : Moves the Spectrometer filter wheel <num_turns> times
//                 to position 2 and back to position 1 using absolute position
//                 commands. 
//
// Comments      : Prerequisite : spec_mec_setup has been executed 
//
// Version       : 1.6
// History       : 1.0 / 26-Jan-2006 DAC Adpated from PACS_Phot_Fil_Testseq
//                       Added DMC_SWON_GRAT_CONT as in original Spec tcl
// 1.1 / 12-May-2006 procedure -> building block + simplified code & comments
// 1.2 17-may-2006 DAC Recast as procedure (already in registry as procedure)
//
procedure PACS_Spec_Fil_Testseq {
}{
    debug_print("Start PACS_Spec_Fil_Testseq");
    int fw_start = 1;
    // initial filter wheel position (0=A; 1=B)
    int num_turns = 3;
    // number of 360 deg turns
    int time_on_fw_pos = 20;
    // time spent on each FW stop position (sec)
    string[] fltPOS = ["POS A","POS B"];
    int slew_time = 15;
    // Minimum time between two filter wheel movements (sec)
    // SWON FW CONTROLLER
    Pacs_DMC_SWON_FW_SPEC();
    delay(1);
    Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    // Move num_turns to position 0 and back to position 1 using absolute location commands
    for(int loop0 = 1 .. num_turns) {
        int i = (fw_start + 1) % 2;
        Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[i]);
        delay(slew_time);
        delay(time_on_fw_pos);
        i = (fw_start + 2) % 2;
        Pacs_DMC_MOVE_SPEC_FW_LOC(fltPOS[i]);
        delay(slew_time);
        delay(time_on_fw_pos);
    }
    // RE-SWON GRAT CONTROLLER
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    //------------------
    // End of procedure
    //------------------
}

//$Id$
//
// Purpose 
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//- Test of internal calibration recipes including different chopper
//  frequencies photometry including time constants for flux changes
//  (just between the 2 CSs)
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//                  
//                 
//
// TCL author    : TM
// TCL file      : TM
// CUS author    : TM
// Script file   : PHOT_timeconst_fluxchange_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version	 : 1.0
// History       : 0.1 27-apr-2005 DAC
//                 0.4 26-apr-2005 DAC Use PACS_spu_reset
//                 0.5  4-nov-2005 DAC Added 1 sec to the wait after DMC load (from 2 to 3 sec)
//                 0.6 11-apr-2007 update by TM (OBCPs, 40Hz, ....)
//		   1.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
procedure Pacs_Phot_timeconst_fluxchange {
}{
    // Register with environment
    // Start SPU
    int comp_mode_blu = 0;
    int comp_mode_red = 0;
    int nraw_blu = 0;
    int nraw_red = 0;
    //
    PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,true);
    //
    // Position the filter wheel at POS A
    //
    PHOT_fltw_move("POS A");
    //
    // Perform OBCP_chopped_photometry (128sec)
    //
    OBCP_chopped_photometry(0,0,599,0,0,1,4,648,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,79,0,0,1,30,648,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,19,0,0,1,120,648,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,4,0,0,1,240,648,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    // Position the filter wheel at POS B
    //
    PHOT_fltw_move("POS B");
    //
    OBCP_chopped_photometry(0,0,599,0,0,1,4,648,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,79,0,0,1,30,648,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,19,0,0,1,120,648,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,4,0,0,1,240,648,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    // Position the filter wheel at POS A
    PHOT_fltw_move("POS A");
    //
    // Stop SPU
    PHOT_spu_reset();
    //
    // Leave environment
}

// Missionphase  : FM ILT
//
// Purpose	: Grating health check + reproducibility aspects
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: n_homes : nb of times that the homing+Grating_Healthcheck is repeated
//
// Description	: Homes the grating and performs moves to Min->Max->Min positions (= Grating Health Check)
//	  Repeats this a "n_home" times
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on
//	    The grating controller is SWON and ENABLED
//	    (e.g. SetupSpectroscopyEQMIMT takes care for it)
//
// Comments	: The grating health check only makes sense with high frequency diag HK
//	  The first homing is always done with parameter 0 ("POSITIVE"), then it alternates
//
// Version	: 2.0
//               
// History	: 1.0 14-Jun-2006 Creation, based on SPEC_Gra_Healthcheck_obs
// 		  2.0 13-Feb-2008 Major Modifications: name changed to 
//		      		   PACS_Spec_Gra_Healthcheck
//		      		  Made into a procedure
//		      		   to be called by PacsEng_Spec_Gra_Healthcheck
//				  Block PACS_Spec_Gra_Healthcheck
//				   name changed to  PACS_Spec_Gra_Healthcheck_BB
//
procedure PACS_Spec_Gra_Healthcheck {
    int n_homes = 1; // Number of Homings & "Grating Health Checks" to be performed
}{
    int n = 0;
    while(n < n_homes) {
        //    double homing_mode = double(n % 2);
        string home_mode = "NEGATIVE";
        if(n % 2 == 1) {
            home_mode = "POSITIVE";
        }
        PACS_Spec_Gra_Healthcheck_BB(home_mode);
        n = n + 1;
    }
}

// CVS comments  : $Id: SPEC_get_grat_info.txt,v 1.6 2008/05/28 13:53:57 vanessad Exp $ 
// Purpose       : Estimate grating parameters by referring to the U-CAL SPEC_BAND_params and 
//                 grating calibration file mentioned therein
//
// CUS author    : DAC
// Script file   : SPEC_get_grat_info.txt 
//
// Input arguments
// type    name         description
// double  waveLen      Desired wavelength [microns]
//
// Return values
// Type                           Description
// tuple  {double,int,int,        {waveLen,order,gratPos,
//         int,int}                nbSteps,stepSize}  
//
// Description   : Access the table SPEC_BAND_params. Verify that the given
// wavelength is within range; obtain order and the name of the GratCal
// grat vs. wavelength table. Get nominal grating position from GratCal table.
// Returns the grating position such that nominal grating position will be
// acchieved after nbSteps/2 steps
//
// Dependencies  :
//
// Preconditions :
//                 
// Comments      : With current version of lookup, first column has to be of
// type string
// 
// History       : 0.1 25-aug-2005 DAC
// 0.2  8-may-2006 Return grating position such that line falls
//                 in the middle of array after n_steps/2
// 0.3 30-may-2006 Access SPEC_BAND_params using module SPEC_BAND_read;
//                 Return central pixel gratPos if switching = true
// 0.4 22-nov-2006 "Verbosed" debug_print
// 0.5 14-feb-2007 Verbose in calling argument
// 0.6 14-mar-2007 extraConf in calling argument
// 0.6  7-may-2007 Amended for SCR-3164: introduction of "L" lines in
//                 SPEC_BAND_params
// 0.7  8-may-2007 Case of overlapping bands; orderSel defines the order
// 1.0 10-oct-2007 SCR3632. Dedicated key wave parameters. K lines will
//                 be recognized because "resol" will be KHI, KMED, or KLOW
{double,int,int,int,int} procedure SPEC_get_grat_info_PV_FLEX {
    double waveLen = 54.0 in [54.0,210.0]; // Sought wavelength
    string resol = "HI" in ["HI","MED","LOW","KHI","KMED","KLOW"]; // Desired resolution
    bool switching = true; // Return central pixel if true
    string extraConf = "normal" in ["normal","bright"];
    string orderSel = "order2";
    bool verbose = false;
}{
    bool special = false;
    // PacsRangeSpec may call with sedN instead of orderSelN; use
    // "conversion" table for sedN => orderSelN 
    if(orderSel == "sed2") {
        orderSel = "order2";
    }
    if(orderSel == "sed3") {
        orderSel = "order3";
    }
    if(orderSel == "sed4") {
        orderSel = "order2";
        special = true;
    }
    if(verbose) {
        debug_print("SPEC_get_grat: order " + orderSel);
    }
    // Open and read SPEC_BAND_params table. Table indexed by ORDER
    // Try two possible ORDERs: order 1 and order indicated by orderSel
    // Start with order = 1
    int order = 1;
    if(special) {
        order = 23;
    }
    bool found = false;
    int nbSRCH = 0;
    while(!found && nbSRCH < 2) {
        //   SCR-3164. Deal with "L" lines
        string key = "L" + order;
        //   SCR-3632 Deal with key wavelengths
        if(resol == "KHI" || resol == "KMED" || resol == "KLOW") {
            key = "K" + order;
        }
        //   read BLU and RED edges of the SPEC bands
        double blu = dlookup("SPEC_BAND_params",key,"BLU");
        double red = dlookup("SPEC_BAND_params",key,"RED");
        found = blu <= waveLen && red >= waveLen;
        if(verbose) {
            debug_print("SPEC_get_grat: Switching is " + switching);
            debug_print("SPEC_get_grat: Wave " + waveLen);
            debug_print("SPEC_get_grat: FOUND " + found);
            debug_print("SPEC_get_grat: key " + key);
            debug_print("SPEC_get_grat: nbSRC " + nbSRCH);
        }
        //   If not yet found search in order indicated by orderSel
        if(!found) {
            if(orderSel == "order2") {
                order = 2;
            } else {
                if(orderSel == "order3") {
                    order = 3;
                }
            }
            nbSRCH = nbSRCH + 1;
        }
    }
    // If given wavelength not found there is a problem
    if(!found) {
        error("Wavelength " + waveLen + " is not within " + orderSel);
    }
    // Found the ORDER. Get now the name of position vs. wavelength gratPosTab
    string gratPosTab = slookup("SPEC_BAND_params",key,"CAL_FILE");
    // Read the step size and the number of steps for this ORDER and resolution
    // Recast "resol" as it was before SCR3632
    if(resol == "KHI") {
        resol = "HI";
    }
    if(resol == "KMED") {
        resol = "MED";
    }
    if(resol == "KLOW") {
        resol = "LOW";
    }
    // Special case for "bright" source
    if(extraConf == "normal") {
        int stepSize = ilookup("SPEC_BAND_params",key,resol);
        int nbSteps = ilookup("SPEC_BAND_params",key,"NSTEPS");
    }
    if(extraConf == "bright") {
        stepSize = ilookup("SPEC_BAND_params",key,resol);
        nbSteps = ilookup("SPEC_BAND_params",key,"FASTSTEP");
    }
    // Get from gratPosTab the grating position corresponding to waveLen
    double gratPosDble = interpolate(gratPosTab,"grat_pos",waveLen);
    // gratPos will place waveLen in the middle of the array
    int gratPos = iround(gratPosDble);
    if(verbose) {
        debug_print("SPEC_get_grat Nominal wavelen: " + waveLen);
        debug_print("SPEC_get_grat Nominal grating: " + gratPos);
    }
    // Grating is scanned with a negative step size (increasing wavelength) 
    // The grating start position should then be such that after nbSteps/2 we
    // are at nominal position: 
    //              gratPos = gratStartPos - stepSize*nbSteps/2
    // hence:
    int gratStartPos = iround(gratPosDble + double(stepSize) * double(nbSteps) / 2.0);
    // and will scan by decreasing grating angle, i.e. negative step size:
    stepSize = -stepSize;
    // If frequency switch return return gratPos (central pixel)
    if(switching) {
        gratStartPos = gratPos;
    }
    if(verbose) {
        debug_print("SPEC_get_grat: reads SPEC_BANDS");
        debug_print("SPEC_get_grat: WAVE/order/gratNOMINAL/gratSTRT: " + waveLen + "/" + order + "/" + gratPos + "/" + gratStartPos);
        debug_print("SPEC_get_grat: nbSteps/stepSize: " + nbSteps + "/" + stepSize);
    }

    return {waveLen,order,gratStartPos,nbSteps,stepSize};
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Missionphase  : PACS FMILT
//
// Purpose       : Configure the spec filter wheel
//
// Author        : PR
//
// Arguments     : 
//
// Description   : 
//                 
// Comments      :      
//
// Version       : 0.1 
// History       : 0.1  12-Jun-2007 Initial version
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//
obs PacsEng_CONF_spec_fltw {
    /* No variables to call PacsEng_CONF_spec_fltw                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POSB" */
    /* End of needed variables for PacsEng_CONF_spec_fltw                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_spec_fltw()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_spec_fltw();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Filemane	: Pacs_Spec_fov_scan_imt409
// Purpose	:  FOV Scan 
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do a FOV scan in spectroscopy mode.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, and setup spectroscopy. 
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 2.1
// 
// History 	: 1.0 06-04-07 HD. IST update.
//                1.1 09-04-07 BV - corrected bias blue + commented out Diag hk
//                                to stay within allowed datarate
//                1.2 09-04-07 HF, added scan on filter B
//		  2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//                2.1 changed biases to in-flight defaults
//           
procedure Pacs_Spec_fov_scan_imt409 {
}{
    // Start Chopper specific diagnostic Housekeeping
    // SPEC_Chopper_dhk_imt_bb();
    // Move chopper to default position 
    PACS_Chopper_mov_abs_fm_bb(0);
    // Move Filter Wheel to Position A
    SPEC_fltw_move("POS A");
    // CRE setup
    int ramp_len_red = 64;
    int ramp_len_blu = 64;
    double bias_d_red = 0.03;
    double bias_r_red = 0.01;
    double bias_d_blu = 0.08;
    double bias_r_blu = 0.01;
    int capa_red = 0;
    int capa_blu = 0;
    SPEC_CRE_No_Heater_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // Set up Chopper Scan
    int nb_up_dn = 1;
    // P#1  number of up-down seqs.
    int nb_ramps = 4;
    // P#2  number of ramps on step
    int nb_steps_up = 310;
    // P#3  number of steps up
    int nb_steps_dn = 310;
    // P#4  number of steps down
    int step_up = 150;
    // P#5  relative move up
    int step_dn = -150;
    // P#6  relative move down
    int detector = 1;
    // Detector to SYNCH on
    int grat_pos = 535000;
    // Grating position
    int chop_start_pos = -23500;
    // Chopper start position
    int grat_time = 20000;
    // Grating time
    int comp_mode_blu = 16;
    // "Blue" compression
    int comp_mode_red = 16;
    // number of raw channels
    int nraw_blu = 3;
    int nraw_red = 3;
    // "Red" compression
    int grat_def = 535000;
    // Grating default
    int grat_def_time = 40000;
    // Grating default time
    int chop_def = 0;
    // Chopper default position
    int nb_rdouts_ramp = 64;
    // Ramp length
    //
    // Setup the spu
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,64,64,nraw_blu,nraw_red,1,0,true);
    //
    OBCP_chop_scan_spec(nb_up_dn,nb_ramps,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,grat_pos,chop_start_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,chop_def,nb_rdouts_ramp);
    // Move Filter Wheel to Position B
    SPEC_fltw_move("POS B");
    // 
    OBCP_chop_scan_spec(nb_up_dn,nb_ramps,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,grat_pos,chop_start_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,chop_def,nb_rdouts_ramp);
    // Move chopper to default position 
    PACS_Chopper_mov_abs_fm_bb(0);
    // Move grating to a key wavelength
    SPEC_Gra_move_abs_raw(496000);
    delay(40);
    // reset the SPU
    SPEC_spu_reset();
    // Stop diagnostic Housekeeping
    // PACS_stop_dhk_fm_bb();
    // CRE setup to default values
    SPEC_CRE_No_Heater_setup(64,64,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,12,12);
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 1.0 07-Jun-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Heat_SWOF {
    /* No variables to call PacsEng_Spec_Heat_SWOF                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Heat_SWOF                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Heat_SWOF()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Heat_SWOF();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 1.0 07-Jun-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Heat_SWON {
    /* No variables to call PacsEng_Spec_Heat_SWON                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Heat_SWON                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Heat_SWON()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Heat_SWON();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//                 to enable AF15 at the end of PHOT orbit prologue
//
// CUS author    : TM
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : enable AF15 (to watch 12 VSS currents)
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 07-Jul-2009 initial version
//
obs PacsEng_AF15_Test_Setup {
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_AF15_Test_Setup()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_AF15_Test_Setup();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsLineSpecEstimatorOBCP32.txt,v 1.1 2007/10/25 12:16:47 dcesarsk Exp $ 
// Purpose       : Estimate several PACS parameters for each spectral
//                 line specified by the HSPOT user
//
// CUS author    : DAC
//
// Input arguments
// type           name            Description
// tuple          lines           spectral line info from HSPOT
// tuple          waveTuple       grating info associated to "lines"
// tuple          paramsSPECdef   confSPECblu & confSPECred & confOBCP
//
// Return values
// Type             Description
// tuple            Derived values for paramsSPECdef
//
// Description   : Fill the PACS state descriptors confSPECx & confOBCP, per
//                 HSPOT defined wavelength, with values obtained from
//                 OBCP32params (a CAL-U file). This procedure is called once 
//                 per spectral line. The repFactor is implemented as the
//                 number of nb_obs_cal parameter in OBCP freq switch.
//
// Dependencies  : 
//
// Preconditions :
//
// Comments      : Several confOBCP elements differ from non switched OBCPs
//                 Code keeps old confOBCP commented out for reference.
//                 NOTE.Several confOBCP elements are redefined here!!
// 
// History       : 0.1 18-oct-2007 DAC Based on PacsLineSpecEstimatorOBCP22
// 		 : 1.0 9-feb-2009 VD: modification based on new
//		       		      implementation of OBCP32 ABBA mode
//
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsLineSpecEstimatorOBCP32_PV {
    {string,double,int,double,double,double,string,string} lines = {"NONE",60.2,1,0.0,0.0,0.0,"bla","bla"}; // linesTuple HSPOT
    {double,int,int,int,int} waveTuple = {100.0,1,500000,0,0}; // waveTuple          
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; // Default values
    int p3dither = 300;
    int p5 = 0;
    int p7move = 700;
    bool verbose = true; // print debug information
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    // ORDER of the current line
    int order = waveTuple{1};
    double waveLEN = waveTuple{0};
    // User desired repetition factor for current line
    int userREPfactor = lines{2};
    // Get the "quantum" OBS time for the current order.
    // Grating info pertaining to the current wavelength is in waveTuple
    int grat_pos_LINE = waveTuple{2};
    // Get "duration" and switch parameters from OBCP22params U-CAL table
    // There is a row per order; it lists main OBCP parameters
    string calNAME = "OBCP32params";
    // The acces key is the grating order
    // Use 1st alternate method
    string key = "" + order;
    int nb_up_dn = ilookup(calNAME,key,"P1UpDn");
    int nb_ramps_grat = ilookup(calNAME,key,"P6ramps");
    int ditherCount = ilookup(calNAME,key,"P2shifts");
    int ditherSize = p3dither;
    int p5start = p5;
    int jumpAtoB = p7move;
    int nbABBA = ilookup(calNAME,key,"P4ABBA");
    // NOTE: nb_up_dn above is multiplied by userREPfactor
    nb_up_dn = nb_up_dn * userREPfactor;
    // Still to compute offline: offset to grat_pos_LINE so line is centered at 1/2
    // dithering cycle
    int offLine = 0;
    int grat_pos_LINEoff = grat_pos_LINE + offLine;
    if(verbose) {
        debug_print("Estim.OBCP32:gratLINE/graLINE+offset: " + grat_pos_LINE + "/" + grat_pos_LINEoff);
    }
    // Estimate the OBS time for this rangeInfo; estimation is for ONE nod only.
    // Get nb_rdouts_ramp from confSPECred
    int nbRdOutsRamp = confSPECred{1};
    //DACOBCP32
    //       int[] dureeOBCP32 = PacsDureeOBCP32(ditherCount,nb_up_dn,nbABBA,nb_ramps_grat,nbRdOutsRamp);
    int[] dureeOBCP32 = [0,0,0,0,0];
    //DACOBCP32  
    // Use SRC/REF duration to compute quantumOBStime (was total time)
    int quantumOBStime = dureeOBCP32[1] + dureeOBCP32[2];
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + waveLEN + " [&micro;m] with line repeated " + userREPfactor + " time(s)</p>";
    lineCnt = lineCnt + 1;
    if(verbose) {
        debug_print("Estim.OBCP32:jumpAtoB/gratLINE/nbABBA/ditherSize: " + jumpAtoB + "/" + grat_pos_LINE + "/" + nbABBA + "/" + ditherSize);
    }
    // Pack information into proper tuples
    // confOBCP { 0}  =   nb_up_down      ;
    // confOBCP { 0}  =   nb_obs_cal       ;
    confOBCP{0} = nb_up_dn;
    // confOBCP { 1}  =   grat_step_up     ;
    confOBCP{1} = jumpAtoB;
    // confOBCP { 2}  =   grat_step_dn     ;
    confOBCP{2} = nbABBA;
    // confOBCP { 3}  =   nb_SRC_OFF       ;
    // confOBCP { 3}  =   nb_SRC           ;
    confOBCP{4} = nb_ramps_grat;
    // confOBCP { 5}  =   nb_CS1           ;
    // confOBCP { 6}  =   nb_grat_step_up  ;
    // confOBCP { 6}  =   nb_CS2           ;
    // confOBCP { 7}  =   nb_grat_step_dn  ;
    confOBCP{7} = ditherCount;
    // confOBCP { 8}  =   grat_start_pos   ;
    confOBCP{8} = grat_pos_LINEoff;
    //    confOBCP { 9}  =   grat_start_time  ;
    confOBCP{9} = ditherSize;
    //    confOBCP{10} = jumpREF3;
    //    confOBCP{11} = jumpREF4;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    //    confSPECred{0} = capa_red;
    //   confSPECred{ 1} =  nb_rdouts_ramp_red;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    //    int comp_mode_red = 16;
    //    confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    //    confSPECblu{0} = capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts_ramp_blu;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    //    int comp_mode_blu = 16;
    //    confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    string msgLabel = "Observing time for " + lines{0};
    PacsMessageCenter(msgLabel,lineCnt,msgLine);
    int nb_nods = 0;
    int aux3 = 0;

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,ditherCount,quantumOBStime,aux3}};
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	:  FOV Scan 
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do a FOV scan in spectroscopy mode.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, and setup spectroscopy. 
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 2.0
// 
// History 	: 1.0 06-04-07 HD. IST update.
//                1.1 09-04-07 BV - corrected bias blue + commented out Diag hk
//                                to stay within allowed datarate
//                1.2 09-04-07 HF, added scan on filter B
//		  2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//           
obs PacsEng_Spec_fov_scan_imt409 {
    /* Needed variables to call PacsEng_Spec_fov_scan_imt409                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_fov_scan_imt409                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_fov_scan_imt409()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_fov_scan_imt409();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsPhotEstimatorOBCPn.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $ 
// Missionphase  : Operations
//
// Purpose       : Estimate OBCP parameters for the PointMode and filter
//                 specified by the HSPOT user
//
// CUS author    : DAC
// Script file   : PacsPhotEstimatorOBCPn.txt 
//
// Input arguments
// type           name       Description
//
// Return values
// Type    Description
// tuple  {confPHOTblu,confPHOTred,confOBCP,{extension}}
//
// Description   : 
//
// Dependencies  : 
//
// Preconditions :
//
// Comments      : 
// 
// History       : 0.1  7-Dec-2005 DAC Based on PacsRangeSpecEstimatorOBCP27
// 0.2 15-Dec-2005 Added pos_CS1 and pos_CS2
// 0.3 10-aug-2006 Point source now observed with OBCP3; others with OBCP4
// 1.0 30-aug-2006 - editorial clean up
//                 - use repFactor instead of integrationTime
// 1.1 12-jan-2007 - Improved messages (w/Roland Vavrek)
//                 - added boolean dither to input list
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsPhotEstimatorOBCPn {
    int pointCase = 11; // Internal code for the pointing mode (see main)
    string filter = "blue1" in ["blue1","blue2"]; // filter from HSPOT
    int repFactor = 1; //Repeat factor, i.e. number of nod cycles
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOTdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; // Default values
    bool noddingSel = false; // Nodding allowed or not
    bool dither = true; // With/without dithering
    bool verbose = true; // Print bla-bla
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confPHOTblu = clone(paramsPHOTdef{0});
    {int,int,int,int,int,int,int,int,int} confPHOTred = clone(paramsPHOTdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsPHOTdef{2});
    // OBCP tuples use several variables, some of them are dedicated to one or
    // another OBCP. Here define all the tuple variables. Later, they may be 
    // updated according to used OBCP
    int nb_main_loops = 0;
    int nb_cycles_obs_cal = 0;
    int nb_rdouts_plateau = 0;
    int nb_chop_cycle = 0;
    int max_dither = 0;
    int nhold = 0;
    int nb_SRC_OFF = 0;
    int nb_CS1_CS2 = 0;
    int pos_CS1 = 0;
    int pos_CS2 = 0;
    // Update corresponding elements of confOBCP
    // Get "duration related" parameters from corresponding OBCPnparams U-CAL table
    if(pointCase == 11 || pointCase == 12) {
        string calNAME = "OBCP3params";
        //  The acces key is the chosen filter: blue1 or blue2
        //  There is a row per filter; it lists main OBCP parameters
        nb_main_loops = ilookup(calNAME,filter,"nb_main_loops");
        //  OBCPconf uses nb_cycles_obs_cal as variable name
        nb_cycles_obs_cal = nb_main_loops;
        nb_rdouts_plateau = ilookup(calNAME,filter,"nb_rdouts_plateau");
        nb_chop_cycle = ilookup(calNAME,filter,"nb_chop_cycle");
        max_dither = ilookup(calNAME,filter,"max_dither");
        nhold = ilookup(calNAME,filter,"nhold");
    }
    if(pointCase == 22 || pointCase == 31) {
        calNAME = "OBCP4params";
        nb_cycles_obs_cal = ilookup(calNAME,filter,"nb_cycles_obs_cal");
        nb_SRC_OFF = ilookup(calNAME,filter,"nb_SRC_REF");
        nb_rdouts_plateau = ilookup(calNAME,filter,"nb_rdouts_plateau");
        nb_CS1_CS2 = ilookup(calNAME,filter,"nb_CS1_CS2");
        nhold = ilookup(calNAME,filter,"nhold");
        //      CS1 and CS2 from dedicated CAL-U file
        pos_CS1 = ilookup("CHOPPERCSparams","PHOT","pos_CS1");
        pos_CS2 = ilookup("CHOPPERCSparams","PHOT","pos_CS2");
    }
    if(pointCase == 33) {
        calNAME = "No CAL file yet";
    }
    if(verbose) {
        debug_print("++PhotEstimator reads CAL-U: " + calNAME);
    }
    // Compute the OBS time for this pointCase and filter
    // Line Scan is not associated to an OBCP yet
    if(pointCase == 33) {
        int[] dureeOBCPn = [1,1,0,0,0];
    }
    // Point source
    if(pointCase == 11 || pointCase == 12) {
        dureeOBCPn = PacsDureeOBCP3(nb_main_loops,nb_rdouts_plateau,nb_chop_cycle);
    }
    // For small and large source use OBCP4
    if(pointCase == 22 || pointCase == 31) {
        dureeOBCPn = PacsDureeOBCP4(nb_SRC_OFF,nb_rdouts_plateau,nb_cycles_obs_cal,nb_CS1_CS2);
    }
    if(verbose) {
        debug_print("++PhotEstimator: dureeOBCP4: " + dureeOBCPn);
    }
    double quantumOBStime = double(dureeOBCPn[1] + dureeOBCPn[2]);
    // Get the "quantum" OBS time for the current order. U-CAL time doubles if 
    // nodding is allowed
    double nodFactor = 1.0;
    if(noddingSel) {
        nodFactor = 2.0;
    } else {
        int nb_nods = 0;
    }
    quantumOBStime = nodFactor * quantumOBStime;
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    if(noddingSel) {
        msgLine[lineCnt] = "<p>Shortest SKY time (no overheads) for filter " + filter + ": " + quantumOBStime + " [sec], includes an A=>B nod cycle</p>";
    } else {
        msgLine[lineCnt] = "<p>Shortest SKY time (no overheads) for filter " + filter + ": " + quantumOBStime + " [sec], no nodding demanded</p>";
    }
    lineCnt = lineCnt + 1;
    // Deal with repFactor. In case of noddingSel = false, the repFactor
    // gives the PointReq nrepeat count
    //
    // Re-use the previous logic based on userOBStime...
    // Repeat factor given for current filter.
    // Observing time can be increased by (integer) factor:
    int obsFactor = repFactor;
    double newOBStime = double(obsFactor) * quantumOBStime;
    if(verbose) {
        debug_print("++PhotEstimator: obsFactor: " + obsFactor + "; filter: " + filter);
    }
    // Common part of nodding/no nodding message
    if(repFactor == 1) {
        msgLine[lineCnt] = "<p>You may increase the sensitivity for the current filter by setting";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = " the RepetitionFactor = 2,3,.. to obtain OBStime = repFactor*" + quantumOBStime + "</p>";
        lineCnt = lineCnt + 1;
    }
    // If no nodding then we repeat the raster pattern
    if(!noddingSel) {
        int repeat_factor = 1;
        nb_nods = 0;
        if(obsFactor > 1) {
            msgLine[lineCnt] = "<p>You entered repFactor > 1 </p>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "Since no nodding was requested, we shall repeat";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "the raster pattern " + obsFactor + " times, leading to a total dwell time of " + newOBStime + " [sec]</p>";
            lineCnt = lineCnt + 1;
            repeat_factor = obsFactor;
        }
    } else {
        //    Nodding selected, here we increase newOBStime by increasing the
        //    number of nod cycles
        repeat_factor = 1;
        nb_nods = obsFactor;
        if(obsFactor > 1) {
            msgLine[lineCnt] = "<p>You entered repFactor > 1 </p>";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = "Since nodding is allowed, we set the number";
            lineCnt = lineCnt + 1;
            msgLine[lineCnt] = " of nods to " + obsFactor + " cycles; leading to an accumulated dwell time of " + newOBStime + " [sec]</p>";
            lineCnt = lineCnt + 1;
        }
    }
    // Some more Pointing parameters (auxN just in case I need more...)
    int aux2 = 0;
    int aux3 = 0;
    // Pack information into proper tuples
    confOBCP{0} = nb_cycles_obs_cal;
    confOBCP{1} = max_dither;
    if(!dither) {
        confOBCP{1} = 0;
    }
    // Use confOBCP{2} to convey nb_chop_cycle
    confOBCP{2} = nb_chop_cycle;
    confOBCP{3} = nb_SRC_OFF;
    confOBCP{4} = nb_rdouts_plateau;
    confOBCP{5} = nb_CS1_CS2;
    confOBCP{15} = pos_CS1;
    confOBCP{16} = pos_CS2;
    // All these leftovers from SPECTRO code
    //   confOBCP { 6}  =   nb_grat_step_up  ;
    //   confOBCP { 7}  =   nb_grat_step_dn  ;
    //   confOBCP { 8}  =   grat_start_pos   ;
    //   confOBCP { 9}  =   grat_start_time  ;
    //   confOBCP {10}  =   grat_def_pos     ;
    //   confOBCP {11}  =   grat_def_time    ;
    //   confOBCP {12}  =   chop_pos_SRC     ;
    //   confOBCP {13}  =   chop_pos_REF1    ;
    //   confOBCP {14}  =   chop_pos_REF2    ;
    //   confOBCP {17}  =   chop_def         ;
    //   confOBCP {19}  =   order ;
    //   confPHOTred{ 0} =  capa_red;
    //   confPHOTred{ 1} =  nb_rdouts_ramp_red;
    //   confPHOTred{ 2} =  nb_rdouts_subramp_red;
    //   confPHOTred{ 3} =  comp_mode_red;
    //   confPHOTred{ 4} =  glitch_det_red;
    //   confPHOTred{ 5} =  ramp_fit_alg_red;
    //   confPHOTred{ 6  =  nb_raw_red;
    //   confPHOTred{ 7} =  bias_r_red;
    //   confPHOTred{ 8} =  bias_d_red;
    //   confPHOTblu{ 0} =  capa_blu;
    //   confPHOTblu{ 1} =  nb_rdouts_ramp_blu;
    //   confPHOTblu{ 2} =  nb_rdouts_subramp_blu;
    //   confPHOTblu{ 3} =  comp_mode_blu;
    //   confPHOTblu{ 4} =  glitch_det_blu;
    //   confPHOTblu{ 5} =  ramp_fit_alg_blu;
    //   confPHOTblu{ 6  =  nb_raw_blu;
    //   confPHOTblu{ 7} =  bias_r_blu;
    //   confPHOTblu{ 8} =  bias_d_blu;
    if(verbose) {
        debug_print("++PhotEstimator: OBCP: " + confOBCP);
    }
    // Pass messages to user (not in scan mode)
    if(pointCase != 33) {
        PacsMessageCenter("Observing time information",lineCnt,msgLine);
    }

    return {confPHOTblu,confPHOTred,confOBCP,{nb_nods,repeat_factor,nhold,0}};
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowGainBiasDirect1
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   + Set the biases group by group
//   + Set the blue filter 100um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + Set the blue filter 70um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//            New version
//
// Version : Fri Apr 24 19:29:34 EST 2009
//
procedure Phot_lowGainBiasDirect1 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
}{
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //************************************************
    // Set the biases and start SPU, then set the gain
    //************************************************
    //
    PHOT_set_biases(startBiasTable,"DIRECT","LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position -21350
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(-21350);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS1 at 48.0 Ohm
    // corresponding to 1.20pW on the green and 5.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.2387937986138855 Volts
    Pacs_BOLC_SET_VH_G1(1.2387937986138855);
    // Set group 1 bol bias 02 (VL) to -0.01120620138611441 Volts
    Pacs_BOLC_SET_VL_G1(-0.01120620138611441);
    // Set group 1 bol bias 03 (VRL) to 0.39273766758961587 Volts
    Pacs_BOLC_SET_VRL_G1(0.39273766758961587);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1512820863099917 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1512820863099917);
    // Set group 2 bol bias 01 (VH) to 1.2273390654384582 Volts
    Pacs_BOLC_SET_VH_G2(1.2273390654384582);
    // Set group 2 bol bias 02 (VL) to -0.022660934561541744 Volts
    Pacs_BOLC_SET_VL_G2(-0.022660934561541744);
    // Set group 2 bol bias 03 (VRL) to 0.38921788688528014 Volts
    Pacs_BOLC_SET_VRL_G2(0.38921788688528014);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.147146340755748 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.147146340755748);
    // Set group 3 bol bias 01 (VH) to 1.2296951151089281 Volts
    Pacs_BOLC_SET_VH_G3(1.2296951151089281);
    // Set group 3 bol bias 02 (VL) to -0.020304884891071927 Volts
    Pacs_BOLC_SET_VL_G3(-0.020304884891071927);
    // Set group 3 bol bias 03 (VRL) to 0.3894736881379893 Volts
    Pacs_BOLC_SET_VRL_G3(0.3894736881379893);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.143754288741119 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.143754288741119);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.38519980225961764 Volts
    Pacs_BOLC_SET_VRL_G4(0.38519980225961764);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.141162817635055 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.141162817635055);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3228584222642352 Volts
    Pacs_BOLC_SET_VRL_G5(0.3228584222642352);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.067428073283575 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.067428073283575);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3146600782399116 Volts
    Pacs_BOLC_SET_VRL_G6(0.3146600782399116);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.057234963490994 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.057234963490994);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.457556831416261 Volts
    Pacs_BOLC_SET_VH_G1(1.457556831416261);
    // Set group 1 bol bias 02 (VL) to -0.14244316858373907 Volts
    Pacs_BOLC_SET_VL_G1(-0.14244316858373907);
    // Set group 1 bol bias 03 (VRL) to 0.39289728144635716 Volts
    Pacs_BOLC_SET_VRL_G1(0.39289728144635716);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151471417543995 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151471417543995);
    // Set group 2 bol bias 01 (VH) to 1.444087138537561 Volts
    Pacs_BOLC_SET_VH_G2(1.444087138537561);
    // Set group 2 bol bias 02 (VL) to -0.1559128614624391 Volts
    Pacs_BOLC_SET_VL_G2(-0.1559128614624391);
    // Set group 2 bol bias 03 (VRL) to 0.3888592125442133 Volts
    Pacs_BOLC_SET_VRL_G2(0.3888592125442133);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1467299681244416 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1467299681244416);
    // Set group 3 bol bias 01 (VH) to 1.4461276964721905 Volts
    Pacs_BOLC_SET_VH_G3(1.4461276964721905);
    // Set group 3 bol bias 02 (VL) to -0.15387230352780956 Volts
    Pacs_BOLC_SET_VL_G3(-0.15387230352780956);
    // Set group 3 bol bias 03 (VRL) to 0.389702653261631 Volts
    Pacs_BOLC_SET_VRL_G3(0.389702653261631);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1440068212666743 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1440068212666743);
    // Set group 4 bol bias 01 (VH) to 1.461535092163816 Volts
    Pacs_BOLC_SET_VH_G4(1.461535092163816);
    // Set group 4 bol bias 02 (VL) to -0.13846490783618415 Volts
    Pacs_BOLC_SET_VL_G4(-0.13846490783618415);
    // Set group 4 bol bias 03 (VRL) to 0.38666891513104484 Volts
    Pacs_BOLC_SET_VRL_G4(0.38666891513104484);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1428402830030913 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1428402830030913);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.393205233420548 Volts
    Pacs_BOLC_SET_VRL_G5(0.393205233420548);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.144845482323282 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.144845482323282);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3832953489422562 Volts
    Pacs_BOLC_SET_VRL_G6(0.3832953489422562);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.130607584787264 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.130607584787264);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.585769661368119 Volts
    Pacs_BOLC_SET_VH_G1(1.585769661368119);
    // Set group 1 bol bias 02 (VL) to -0.214230338631881 Volts
    Pacs_BOLC_SET_VL_G1(-0.214230338631881);
    // Set group 1 bol bias 03 (VRL) to 0.39304515064751266 Volts
    Pacs_BOLC_SET_VRL_G1(0.39304515064751266);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151646819089764 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151646819089764);
    // Set group 2 bol bias 01 (VH) to 1.571162518585341 Volts
    Pacs_BOLC_SET_VH_G2(1.571162518585341);
    // Set group 2 bol bias 02 (VL) to -0.22883748141465898 Volts
    Pacs_BOLC_SET_VL_G2(-0.22883748141465898);
    // Set group 2 bol bias 03 (VRL) to 0.3888194923923588 Volts
    Pacs_BOLC_SET_VRL_G2(0.3888194923923588);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1466838588402206 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1466838588402206);
    // Set group 3 bol bias 01 (VH) to 1.5728976206374763 Volts
    Pacs_BOLC_SET_VH_G3(1.5728976206374763);
    // Set group 3 bol bias 02 (VL) to -0.22710237936252387 Volts
    Pacs_BOLC_SET_VL_G3(-0.22710237936252387);
    // Set group 3 bol bias 03 (VRL) to 0.39016220909623334 Volts
    Pacs_BOLC_SET_VRL_G3(0.39016220909623334);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144513683272569 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144513683272569);
    // Set group 4 bol bias 01 (VH) to 1.5905884509492139 Volts
    Pacs_BOLC_SET_VH_G4(1.5905884509492139);
    // Set group 4 bol bias 02 (VL) to -0.2094115490507863 Volts
    Pacs_BOLC_SET_VL_G4(-0.2094115490507863);
    // Set group 4 bol bias 03 (VRL) to 0.38773283476462383 Volts
    Pacs_BOLC_SET_VRL_G4(0.38773283476462383);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440552130411823 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440552130411823);
    // Set group 5 bol bias 01 (VH) to 1.3241923646302258 Volts
    Pacs_BOLC_SET_VH_G5(1.3241923646302258);
    // Set group 5 bol bias 02 (VL) to -0.07580763536977406 Volts
    Pacs_BOLC_SET_VL_G5(-0.07580763536977406);
    // Set group 5 bol bias 03 (VRL) to 0.40046001102514184 Volts
    Pacs_BOLC_SET_VRL_G5(0.40046001102514184);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.153546375049013 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.153546375049013);
    // Set group 6 bol bias 01 (VH) to 1.37098688511416 Volts
    Pacs_BOLC_SET_VH_G6(1.37098688511416);
    // Set group 6 bol bias 02 (VL) to -0.02901311488583999 Volts
    Pacs_BOLC_SET_VL_G6(-0.02901311488583999);
    // Set group 6 bol bias 03 (VRL) to 0.43611847195239406 Volts
    Pacs_BOLC_SET_VRL_G6(0.43611847195239406);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1943115490461103 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1943115490461103);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7183370767248043 Volts
    Pacs_BOLC_SET_VH_G1(1.7183370767248043);
    // Set group 1 bol bias 02 (VL) to -0.2816629232751957 Volts
    Pacs_BOLC_SET_VL_G1(-0.2816629232751957);
    // Set group 1 bol bias 03 (VRL) to 0.39272615099525776 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272615099525776);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151268425592528 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151268425592528);
    // Set group 2 bol bias 01 (VH) to 1.7019559750109217 Volts
    Pacs_BOLC_SET_VH_G2(1.7019559750109217);
    // Set group 2 bol bias 02 (VL) to -0.29804402498907834 Volts
    Pacs_BOLC_SET_VL_G2(-0.29804402498907834);
    // Set group 2 bol bias 03 (VRL) to 0.388357028089395 Volts
    Pacs_BOLC_SET_VRL_G2(0.388357028089395);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461470122884805 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461470122884805);
    // Set group 3 bol bias 01 (VH) to 1.714454188425701 Volts
    Pacs_BOLC_SET_VH_G3(1.714454188425701);
    // Set group 3 bol bias 02 (VL) to -0.2855458115742991 Volts
    Pacs_BOLC_SET_VL_G3(-0.2855458115742991);
    // Set group 3 bol bias 03 (VRL) to 0.401550404399907 Volts
    Pacs_BOLC_SET_VRL_G3(0.401550404399907);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.15707892246005 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.15707892246005);
    // Set group 4 bol bias 01 (VH) to 1.7242793470756728 Volts
    Pacs_BOLC_SET_VH_G4(1.7242793470756728);
    // Set group 4 bol bias 02 (VL) to -0.27572065292432724 Volts
    Pacs_BOLC_SET_VL_G4(-0.27572065292432724);
    // Set group 4 bol bias 03 (VRL) to 0.3889940535267571 Volts
    Pacs_BOLC_SET_VRL_G4(0.3889940535267571);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454955805079967 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454955805079967);
    // Set group 5 bol bias 01 (VH) to 1.4496153041151667 Volts
    Pacs_BOLC_SET_VH_G5(1.4496153041151667);
    // Set group 5 bol bias 02 (VL) to -0.15038469588483347 Volts
    Pacs_BOLC_SET_VL_G5(-0.15038469588483347);
    // Set group 5 bol bias 03 (VRL) to 0.39905723488551603 Volts
    Pacs_BOLC_SET_VRL_G5(0.39905723488551603);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.15186471364944 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.15186471364944);
    // Set group 6 bol bias 01 (VH) to 1.4970241024935167 Volts
    Pacs_BOLC_SET_VH_G6(1.4970241024935167);
    // Set group 6 bol bias 02 (VL) to -0.10297589750648331 Volts
    Pacs_BOLC_SET_VL_G6(-0.10297589750648331);
    // Set group 6 bol bias 03 (VRL) to 0.43401661473441144 Volts
    Pacs_BOLC_SET_VRL_G6(0.43401661473441144);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1918048548715423 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1918048548715423);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8585362347937342 Volts
    Pacs_BOLC_SET_VH_G1(1.8585362347937342);
    // Set group 1 bol bias 02 (VL) to -0.34146376520626587 Volts
    Pacs_BOLC_SET_VL_G1(-0.34146376520626587);
    // Set group 1 bol bias 03 (VRL) to 0.3925990888065586 Volts
    Pacs_BOLC_SET_VRL_G1(0.3925990888065586);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1511177079955788 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1511177079955788);
    // Set group 2 bol bias 01 (VH) to 1.838716500789082 Volts
    Pacs_BOLC_SET_VH_G2(1.838716500789082);
    // Set group 2 bol bias 02 (VL) to -0.3612834992109183 Volts
    Pacs_BOLC_SET_VL_G2(-0.3612834992109183);
    // Set group 2 bol bias 03 (VRL) to 0.38744902130448367 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744902130448367);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1450929993071512 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1450929993071512);
    // Set group 3 bol bias 01 (VH) to 1.85163190367321 Volts
    Pacs_BOLC_SET_VH_G3(1.85163190367321);
    // Set group 3 bol bias 02 (VL) to -0.34836809632679006 Volts
    Pacs_BOLC_SET_VL_G3(-0.34836809632679006);
    // Set group 3 bol bias 03 (VRL) to 0.4020826639883897 Volts
    Pacs_BOLC_SET_VRL_G3(0.4020826639883897);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157667831933953 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157667831933953);
    // Set group 4 bol bias 01 (VH) to 1.8658389594227858 Volts
    Pacs_BOLC_SET_VH_G4(1.8658389594227858);
    // Set group 4 bol bias 02 (VL) to -0.3341610405772144 Volts
    Pacs_BOLC_SET_VL_G4(-0.3341610405772144);
    // Set group 4 bol bias 03 (VRL) to 0.39087822103495706 Volts
    Pacs_BOLC_SET_VRL_G4(0.39087822103495706);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1476476539739764 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1476476539739764);
    // Set group 5 bol bias 01 (VH) to 1.5144117466818523 Volts
    Pacs_BOLC_SET_VH_G5(1.5144117466818523);
    // Set group 5 bol bias 02 (VL) to -0.18558825331814774 Volts
    Pacs_BOLC_SET_VL_G5(-0.18558825331814774);
    // Set group 5 bol bias 03 (VRL) to 0.39841417525779244 Volts
    Pacs_BOLC_SET_VRL_G5(0.39841417525779244);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151093482383656 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151093482383656);
    // Set group 6 bol bias 01 (VH) to 1.5622243148794812 Volts
    Pacs_BOLC_SET_VH_G6(1.5622243148794812);
    // Set group 6 bol bias 02 (VL) to -0.13777568512051877 Volts
    Pacs_BOLC_SET_VL_G6(-0.13777568512051877);
    // Set group 6 bol bias 03 (VRL) to 0.43327546525989336 Volts
    Pacs_BOLC_SET_VRL_G6(0.43327546525989336);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1909210235812204 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1909210235812204);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0202028596068895 Volts
    Pacs_BOLC_SET_VH_G1(2.0202028596068895);
    // Set group 1 bol bias 02 (VL) to -0.3797971403931106 Volts
    Pacs_BOLC_SET_VL_G1(-0.3797971403931106);
    // Set group 1 bol bias 03 (VRL) to 0.4031554178502121 Volts
    Pacs_BOLC_SET_VRL_G1(0.4031554178502121);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163634915975391 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163634915975391);
    // Set group 2 bol bias 01 (VH) to 1.9845954458032045 Volts
    Pacs_BOLC_SET_VH_G2(1.9845954458032045);
    // Set group 2 bol bias 02 (VL) to -0.41540455419679545 Volts
    Pacs_BOLC_SET_VL_G2(-0.41540455419679545);
    // Set group 2 bol bias 03 (VRL) to 0.38611513204716796 Volts
    Pacs_BOLC_SET_VRL_G2(0.38611513204716796);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1435447105412555 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1435447105412555);
    // Set group 3 bol bias 01 (VH) to 2.0091673911193446 Volts
    Pacs_BOLC_SET_VH_G3(2.0091673911193446);
    // Set group 3 bol bias 02 (VL) to -0.39083260888065513 Volts
    Pacs_BOLC_SET_VL_G3(-0.39083260888065513);
    // Set group 3 bol bias 03 (VRL) to 0.4135751200095534 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135751200095534);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170378532407885 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170378532407885);
    // Set group 4 bol bias 01 (VH) to 2.0158037297874873 Volts
    Pacs_BOLC_SET_VH_G4(2.0158037297874873);
    // Set group 4 bol bias 02 (VL) to -0.3841962702125128 Volts
    Pacs_BOLC_SET_VL_G4(-0.3841962702125128);
    // Set group 4 bol bias 03 (VRL) to 0.3915724280149063 Volts
    Pacs_BOLC_SET_VRL_G4(0.3915724280149063);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1484406507127387 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1484406507127387);
    // Set group 5 bol bias 01 (VH) to 1.5900913542685013 Volts
    Pacs_BOLC_SET_VH_G5(1.5900913542685013);
    // Set group 5 bol bias 02 (VL) to -0.20990864573149876 Volts
    Pacs_BOLC_SET_VL_G5(-0.20990864573149876);
    // Set group 5 bol bias 03 (VRL) to 0.40844955554354584 Volts
    Pacs_BOLC_SET_VRL_G5(0.40844955554354584);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.163093126853995 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.163093126853995);
    // Set group 6 bol bias 01 (VH) to 1.6276124853923464 Volts
    Pacs_BOLC_SET_VH_G6(1.6276124853923464);
    // Set group 6 bol bias 02 (VL) to -0.17238751460765359 Volts
    Pacs_BOLC_SET_VL_G6(-0.17238751460765359);
    // Set group 6 bol bias 03 (VRL) to 0.43216415132235575 Volts
    Pacs_BOLC_SET_VRL_G6(0.43216415132235575);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1895819441738285 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1895819441738285);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.1116098904579044 Volts
    Pacs_BOLC_SET_VH_G1(2.1116098904579044);
    // Set group 1 bol bias 02 (VL) to -0.3883901095420957 Volts
    Pacs_BOLC_SET_VL_G1(-0.3883901095420957);
    // Set group 1 bol bias 03 (VRL) to 0.4140062165204889 Volts
    Pacs_BOLC_SET_VRL_G1(0.4140062165204889);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764790937594767 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764790937594767);
    // Set group 2 bol bias 01 (VH) to 2.0619437696054 Volts
    Pacs_BOLC_SET_VH_G2(2.0619437696054);
    // Set group 2 bol bias 02 (VL) to -0.43805623039459973 Volts
    Pacs_BOLC_SET_VL_G2(-0.43805623039459973);
    // Set group 2 bol bias 03 (VRL) to 0.38550512685952865 Volts
    Pacs_BOLC_SET_VRL_G2(0.38550512685952865);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1428366925092326 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1428366925092326);
    // Set group 3 bol bias 01 (VH) to 2.0871836925661524 Volts
    Pacs_BOLC_SET_VH_G3(2.0871836925661524);
    // Set group 3 bol bias 02 (VL) to -0.4128163074338474 Volts
    Pacs_BOLC_SET_VL_G3(-0.4128163074338474);
    // Set group 3 bol bias 03 (VRL) to 0.41367957243777737 Volts
    Pacs_BOLC_SET_VRL_G3(0.41367957243777737);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704940139980216 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704940139980216);
    // Set group 4 bol bias 01 (VH) to 2.095481525504912 Volts
    Pacs_BOLC_SET_VH_G4(2.095481525504912);
    // Set group 4 bol bias 02 (VL) to -0.40451847449508793 Volts
    Pacs_BOLC_SET_VL_G4(-0.40451847449508793);
    // Set group 4 bol bias 03 (VRL) to 0.3918611768543646 Volts
    Pacs_BOLC_SET_VRL_G4(0.3918611768543646);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.148770503204217 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.148770503204217);
    // Set group 5 bol bias 01 (VH) to 1.6549108970361488 Volts
    Pacs_BOLC_SET_VH_G5(1.6549108970361488);
    // Set group 5 bol bias 02 (VL) to -0.24508910296385117 Volts
    Pacs_BOLC_SET_VL_G5(-0.24508910296385117);
    // Set group 5 bol bias 03 (VRL) to 0.4072430925044988 Volts
    Pacs_BOLC_SET_VRL_G5(0.4072430925044988);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161651131887083 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161651131887083);
    // Set group 6 bol bias 01 (VH) to 1.6931168196610022 Volts
    Pacs_BOLC_SET_VH_G6(1.6931168196610022);
    // Set group 6 bol bias 02 (VL) to -0.20688318033899758 Volts
    Pacs_BOLC_SET_VL_G6(-0.20688318033899758);
    // Set group 6 bol bias 03 (VRL) to 0.4307551048853343 Volts
    Pacs_BOLC_SET_VRL_G6(0.4307551048853343);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187881524411063 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187881524411063);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.196006753214598 Volts
    Pacs_BOLC_SET_VH_G1(2.196006753214598);
    // Set group 1 bol bias 02 (VL) to -0.4039932467854021 Volts
    Pacs_BOLC_SET_VL_G1(-0.4039932467854021);
    // Set group 1 bol bias 03 (VRL) to 0.41357184702417576 Volts
    Pacs_BOLC_SET_VRL_G1(0.41357184702417576);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1759648938728384 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1759648938728384);
    // Set group 2 bol bias 01 (VH) to 2.1433243650504217 Volts
    Pacs_BOLC_SET_VH_G2(2.1433243650504217);
    // Set group 2 bol bias 02 (VL) to -0.45667563494957836 Volts
    Pacs_BOLC_SET_VL_G2(-0.45667563494957836);
    // Set group 2 bol bias 03 (VRL) to 0.3850880425693594 Volts
    Pacs_BOLC_SET_VRL_G2(0.3850880425693594);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14235260562423 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14235260562423);
    // Set group 3 bol bias 01 (VH) to 2.1686669393324536 Volts
    Pacs_BOLC_SET_VH_G3(2.1686669393324536);
    // Set group 3 bol bias 02 (VL) to -0.43133306066754634 Volts
    Pacs_BOLC_SET_VL_G3(-0.43133306066754634);
    // Set group 3 bol bias 03 (VRL) to 0.41346974712361556 Volts
    Pacs_BOLC_SET_VRL_G3(0.41346974712361556);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.17026203238048 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.17026203238048);
    // Set group 4 bol bias 01 (VH) to 2.1793962970285237 Volts
    Pacs_BOLC_SET_VH_G4(2.1793962970285237);
    // Set group 4 bol bias 02 (VL) to -0.42060370297147653 Volts
    Pacs_BOLC_SET_VL_G4(-0.42060370297147653);
    // Set group 4 bol bias 03 (VRL) to 0.39239244557899233 Volts
    Pacs_BOLC_SET_VRL_G4(0.39239244557899233);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.149377418431709 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.149377418431709);
    // Set group 5 bol bias 01 (VH) to 1.7225616727109463 Volts
    Pacs_BOLC_SET_VH_G5(1.7225616727109463);
    // Set group 5 bol bias 02 (VL) to -0.27743832728905365 Volts
    Pacs_BOLC_SET_VL_G5(-0.27743832728905365);
    // Set group 5 bol bias 03 (VRL) to 0.40580736393386424 Volts
    Pacs_BOLC_SET_VRL_G5(0.40580736393386424);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.159935285624683 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.159935285624683);
    // Set group 6 bol bias 01 (VH) to 1.7622827443723812 Volts
    Pacs_BOLC_SET_VH_G6(1.7622827443723812);
    // Set group 6 bol bias 02 (VL) to -0.23771725562761872 Volts
    Pacs_BOLC_SET_VL_G6(-0.23771725562761872);
    // Set group 6 bol bias 03 (VRL) to 0.4298269773716583 Volts
    Pacs_BOLC_SET_VRL_G6(0.4298269773716583);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1867614355291423 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1867614355291423);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2848572542958143 Volts
    Pacs_BOLC_SET_VH_G1(2.2848572542958143);
    // Set group 1 bol bias 02 (VL) to -0.4151427457041857 Volts
    Pacs_BOLC_SET_VL_G1(-0.4151427457041857);
    // Set group 1 bol bias 03 (VRL) to 0.4131612503913013 Volts
    Pacs_BOLC_SET_VRL_G1(0.4131612503913013);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175478838481054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175478838481054);
    // Set group 2 bol bias 01 (VH) to 2.227445675456437 Volts
    Pacs_BOLC_SET_VH_G2(2.227445675456437);
    // Set group 2 bol bias 02 (VL) to -0.47255432454356333 Volts
    Pacs_BOLC_SET_VL_G2(-0.47255432454356333);
    // Set group 2 bol bias 03 (VRL) to 0.38358395077791313 Volts
    Pacs_BOLC_SET_VRL_G2(0.38358395077791313);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1406069736852453 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1406069736852453);
    // Set group 3 bol bias 01 (VH) to 2.2541010275551834 Volts
    Pacs_BOLC_SET_VH_G3(2.2541010275551834);
    // Set group 3 bol bias 02 (VL) to -0.4458989724448167 Volts
    Pacs_BOLC_SET_VL_G3(-0.4458989724448167);
    // Set group 3 bol bias 03 (VRL) to 0.4127976284436742 Volts
    Pacs_BOLC_SET_VRL_G3(0.4127976284436742);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1695189208400576 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1695189208400576);
    // Set group 4 bol bias 01 (VH) to 2.2792127013060117 Volts
    Pacs_BOLC_SET_VH_G4(2.2792127013060117);
    // Set group 4 bol bias 02 (VL) to -0.4207872986939883 Volts
    Pacs_BOLC_SET_VL_G4(-0.4207872986939883);
    // Set group 4 bol bias 03 (VRL) to 0.4047407291500576 Volts
    Pacs_BOLC_SET_VRL_G4(0.4047407291500576);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1634937911711 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1634937911711);
    // Set group 5 bol bias 01 (VH) to 1.8021521044604545 Volts
    Pacs_BOLC_SET_VH_G5(1.8021521044604545);
    // Set group 5 bol bias 02 (VL) to -0.2978478955395457 Volts
    Pacs_BOLC_SET_VL_G5(-0.2978478955395457);
    // Set group 5 bol bias 03 (VRL) to 0.4159065601971136 Volts
    Pacs_BOLC_SET_VRL_G5(0.4159065601971136);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.17200886747967 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.17200886747967);
    // Set group 6 bol bias 01 (VH) to 1.8316635864270032 Volts
    Pacs_BOLC_SET_VH_G6(1.8316635864270032);
    // Set group 6 bol bias 02 (VL) to -0.26833641357299687 Volts
    Pacs_BOLC_SET_VL_G6(-0.26833641357299687);
    // Set group 6 bol bias 03 (VRL) to 0.4288145963722081 Volts
    Pacs_BOLC_SET_VRL_G6(0.4288145963722081);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.185539634602432 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.185539634602432);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3796037366573897 Volts
    Pacs_BOLC_SET_VH_G1(2.3796037366573897);
    // Set group 1 bol bias 02 (VL) to -0.4203962633426101 Volts
    Pacs_BOLC_SET_VL_G1(-0.4203962633426101);
    // Set group 1 bol bias 03 (VRL) to 0.4129099400989898 Volts
    Pacs_BOLC_SET_VRL_G1(0.4129099400989898);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175181344026924 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175181344026924);
    // Set group 2 bol bias 01 (VH) to 2.315754480139234 Volts
    Pacs_BOLC_SET_VH_G2(2.315754480139234);
    // Set group 2 bol bias 02 (VL) to -0.4842455198607661 Volts
    Pacs_BOLC_SET_VL_G2(-0.4842455198607661);
    // Set group 2 bol bias 03 (VRL) to 0.38156757008948644 Volts
    Pacs_BOLC_SET_VRL_G2(0.38156757008948644);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.138266993828065 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.138266993828065);
    // Set group 3 bol bias 01 (VH) to 2.3449665772192874 Volts
    Pacs_BOLC_SET_VH_G3(2.3449665772192874);
    // Set group 3 bol bias 02 (VL) to -0.45503342278071257 Volts
    Pacs_BOLC_SET_VL_G3(-0.45503342278071257);
    // Set group 3 bol bias 03 (VRL) to 0.4122322683327103 Volts
    Pacs_BOLC_SET_VRL_G3(0.4122322683327103);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1688938193526224 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1688938193526224);
    // Set group 4 bol bias 01 (VH) to 2.360152158437928 Volts
    Pacs_BOLC_SET_VH_G4(2.360152158437928);
    // Set group 4 bol bias 02 (VL) to -0.4398478415620719 Volts
    Pacs_BOLC_SET_VL_G4(-0.4398478415620719);
    // Set group 4 bol bias 03 (VRL) to 0.39354738531821554 Volts
    Pacs_BOLC_SET_VRL_G4(0.39354738531821554);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150696897295742 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150696897295742);
    // Set group 5 bol bias 01 (VH) to 1.8624422796333608 Volts
    Pacs_BOLC_SET_VH_G5(1.8624422796333608);
    // Set group 5 bol bias 02 (VL) to -0.3375577203666393 Volts
    Pacs_BOLC_SET_VL_G5(-0.3375577203666393);
    // Set group 5 bol bias 03 (VRL) to 0.4028017551941114 Volts
    Pacs_BOLC_SET_VRL_G5(0.4028017551941114);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.156343875220547 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.156343875220547);
    // Set group 6 bol bias 01 (VH) to 1.9050654119965236 Volts
    Pacs_BOLC_SET_VH_G6(1.9050654119965236);
    // Set group 6 bol bias 02 (VL) to -0.2949345880034766 Volts
    Pacs_BOLC_SET_VL_G6(-0.2949345880034766);
    // Set group 6 bol bias 03 (VRL) to 0.42788441761189455 Volts
    Pacs_BOLC_SET_VRL_G6(0.42788441761189455);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1844170100895375 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1844170100895375);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6080079699591967 Volts
    Pacs_BOLC_SET_VH_G1(2.6080079699591967);
    // Set group 1 bol bias 02 (VL) to -0.39199203004080335 Volts
    Pacs_BOLC_SET_VL_G1(-0.39199203004080335);
    // Set group 1 bol bias 03 (VRL) to 0.4353039674693117 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353039674693117);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2016826896367014 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2016826896367014);
    // Set group 2 bol bias 01 (VH) to 2.5212704911688184 Volts
    Pacs_BOLC_SET_VH_G2(2.5212704911688184);
    // Set group 2 bol bias 02 (VL) to -0.4787295088311815 Volts
    Pacs_BOLC_SET_VL_G2(-0.4787295088311815);
    // Set group 2 bol bias 03 (VRL) to 0.39184175711517744 Volts
    Pacs_BOLC_SET_VRL_G2(0.39184175711517744);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150192531202592 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150192531202592);
    // Set group 3 bol bias 01 (VH) to 2.5446946302676037 Volts
    Pacs_BOLC_SET_VH_G3(2.5446946302676037);
    // Set group 3 bol bias 02 (VL) to -0.4553053697323962 Volts
    Pacs_BOLC_SET_VL_G3(-0.4553053697323962);
    // Set group 3 bol bias 03 (VRL) to 0.41118382754245053 Volts
    Pacs_BOLC_SET_VRL_G3(0.41118382754245053);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1677345299207764 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1677345299207764);
    // Set group 4 bol bias 01 (VH) to 2.582263974911207 Volts
    Pacs_BOLC_SET_VH_G4(2.582263974911207);
    // Set group 4 bol bias 02 (VL) to -0.4177360250887929 Volts
    Pacs_BOLC_SET_VL_G4(-0.4177360250887929);
    // Set group 4 bol bias 03 (VRL) to 0.4155747259799741 Volts
    Pacs_BOLC_SET_VRL_G4(0.4155747259799741);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1758807093660604 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1758807093660604);
    // Set group 5 bol bias 01 (VH) to 2.0139550919820626 Volts
    Pacs_BOLC_SET_VH_G5(2.0139550919820626);
    // Set group 5 bol bias 02 (VL) to -0.38604490801793717 Volts
    Pacs_BOLC_SET_VL_G5(-0.38604490801793717);
    // Set group 5 bol bias 03 (VRL) to 0.39874967908065667 Volts
    Pacs_BOLC_SET_VRL_G5(0.39874967908065667);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151495860090233 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151495860090233);
    // Set group 6 bol bias 01 (VH) to 2.0603593375586526 Volts
    Pacs_BOLC_SET_VH_G6(2.0603593375586526);
    // Set group 6 bol bias 02 (VL) to -0.3396406624413473 Volts
    Pacs_BOLC_SET_VL_G6(-0.3396406624413473);
    // Set group 6 bol bias 03 (VRL) to 0.4254561262075288 Volts
    Pacs_BOLC_SET_VRL_G6(0.4254561262075288);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1814861909041072 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1814861909041072);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.958669888952511 Volts
    Pacs_BOLC_SET_VH_G1(2.958669888952511);
    // Set group 1 bol bias 02 (VL) to -0.3413301110474886 Volts
    Pacs_BOLC_SET_VL_G1(-0.3413301110474886);
    // Set group 1 bol bias 03 (VRL) to 0.43496400697889964 Volts
    Pacs_BOLC_SET_VRL_G1(0.43496400697889964);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201282516353445 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201282516353445);
    // Set group 2 bol bias 01 (VH) to 2.877259199990068 Volts
    Pacs_BOLC_SET_VH_G2(2.877259199990068);
    // Set group 2 bol bias 02 (VL) to -0.4227408000099317 Volts
    Pacs_BOLC_SET_VL_G2(-0.4227408000099317);
    // Set group 2 bol bias 03 (VRL) to 0.41471523343174815 Volts
    Pacs_BOLC_SET_VRL_G2(0.41471523343174815);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1767077990321737 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1767077990321737);
    // Set group 3 bol bias 01 (VH) to 2.917604872367548 Volts
    Pacs_BOLC_SET_VH_G3(2.917604872367548);
    // Set group 3 bol bias 02 (VL) to -0.38239512763245215 Volts
    Pacs_BOLC_SET_VL_G3(-0.38239512763245215);
    // Set group 3 bol bias 03 (VRL) to 0.43322793583509106 Volts
    Pacs_BOLC_SET_VRL_G3(0.43322793583509106);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1920928084003948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1920928084003948);
    // Set group 4 bol bias 01 (VH) to 2.9326607124177055 Volts
    Pacs_BOLC_SET_VH_G4(2.9326607124177055);
    // Set group 4 bol bias 02 (VL) to -0.36733928758229417 Volts
    Pacs_BOLC_SET_VL_G4(-0.36733928758229417);
    // Set group 4 bol bias 03 (VRL) to 0.4248388375312061 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248388375312061);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.186464990521523 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.186464990521523);
    // Set group 5 bol bias 01 (VH) to 2.2123399887514554 Volts
    Pacs_BOLC_SET_VH_G5(2.2123399887514554);
    // Set group 5 bol bias 02 (VL) to -0.38766001124854466 Volts
    Pacs_BOLC_SET_VL_G5(-0.38766001124854466);
    // Set group 5 bol bias 03 (VRL) to 0.4257278403385899 Volts
    Pacs_BOLC_SET_VRL_G5(0.4257278403385899);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1837591130416554 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1837591130416554);
    // Set group 6 bol bias 01 (VH) to 2.2318001783201304 Volts
    Pacs_BOLC_SET_VH_G6(2.2318001783201304);
    // Set group 6 bol bias 02 (VL) to -0.36819982167986975 Volts
    Pacs_BOLC_SET_VL_G6(-0.36819982167986975);
    // Set group 6 bol bias 03 (VRL) to 0.423759377774352 Volts
    Pacs_BOLC_SET_VRL_G6(0.423759377774352);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1794381888209813 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1794381888209813);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    // sync the bus
    sync();
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowGainBiasDirect2
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   + Set the biases group by group
//   + Set the blue filter 100um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + Set the blue filter 70um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//            New version
//
// Version : Fri Apr 24 19:29:50 EST 2009
//
procedure Phot_lowGainBiasDirect2 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
}{
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //************************************************
    // Set the biases and start SPU, then set the gain
    //************************************************
    //
    PHOT_set_biases(startBiasTable,"DIRECT","LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position 21200
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(21200);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS2 at 58.0 Ohm
    // corresponding to 1.55pW on the green and 6.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38123347242944194 Volts
    Pacs_BOLC_SET_VRL_G1(0.38123347242944194);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1376407910122737 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1376407910122737);
    // Set group 2 bol bias 01 (VH) to 1.2387003199108486 Volts
    Pacs_BOLC_SET_VH_G2(1.2387003199108486);
    // Set group 2 bol bias 02 (VL) to -0.011299680089151297 Volts
    Pacs_BOLC_SET_VL_G2(-0.011299680089151297);
    // Set group 2 bol bias 03 (VRL) to 0.3885454558920056 Volts
    Pacs_BOLC_SET_VRL_G2(0.3885454558920056);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146365745091845 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146365745091845);
    // Set group 3 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G3(1.24);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.38773615773066705 Volts
    Pacs_BOLC_SET_VRL_G3(0.38773615773066705);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.141837957849939 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.141837957849939);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3746747870084728 Volts
    Pacs_BOLC_SET_VRL_G4(0.3746747870084728);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1291508925975227 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1291508925975227);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.30644740182478597 Volts
    Pacs_BOLC_SET_VRL_G5(0.30644740182478597);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051135159732571 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051135159732571);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.29823090263814045 Volts
    Pacs_BOLC_SET_VRL_G6(0.29823090263814045);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0409569182979173 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0409569182979173);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4721285832931112 Volts
    Pacs_BOLC_SET_VH_G1(1.4721285832931112);
    // Set group 1 bol bias 02 (VL) to -0.12787141670688873 Volts
    Pacs_BOLC_SET_VL_G1(-0.12787141670688873);
    // Set group 1 bol bias 03 (VRL) to 0.3926297476827718 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926297476827718);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151154074587398 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151154074587398);
    // Set group 2 bol bias 01 (VH) to 1.4563242224495716 Volts
    Pacs_BOLC_SET_VH_G2(1.4563242224495716);
    // Set group 2 bol bias 02 (VL) to -0.14367577755042849 Volts
    Pacs_BOLC_SET_VL_G2(-0.14367577755042849);
    // Set group 2 bol bias 03 (VRL) to 0.3881765529411487 Volts
    Pacs_BOLC_SET_VRL_G2(0.3881765529411487);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.145937513130471 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.145937513130471);
    // Set group 3 bol bias 01 (VH) to 1.45972772124239 Volts
    Pacs_BOLC_SET_VH_G3(1.45972772124239);
    // Set group 3 bol bias 02 (VL) to -0.14027227875761006 Volts
    Pacs_BOLC_SET_VL_G3(-0.14027227875761006);
    // Set group 3 bol bias 03 (VRL) to 0.38988919840997094 Volts
    Pacs_BOLC_SET_VRL_G3(0.38988919840997094);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1442125685158864 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1442125685158864);
    // Set group 4 bol bias 01 (VH) to 1.4747276174033868 Volts
    Pacs_BOLC_SET_VH_G4(1.4747276174033868);
    // Set group 4 bol bias 02 (VL) to -0.12527238259661322 Volts
    Pacs_BOLC_SET_VL_G4(-0.12527238259661322);
    // Set group 4 bol bias 03 (VRL) to 0.38624222870786595 Volts
    Pacs_BOLC_SET_VRL_G4(0.38624222870786595);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1423530627314813 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1423530627314813);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3734713392363535 Volts
    Pacs_BOLC_SET_VRL_G5(0.3734713392363535);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1211616404276756 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1211616404276756);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3640870527167945 Volts
    Pacs_BOLC_SET_VRL_G6(0.3640870527167945);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1074512769294307 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1074512769294307);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6005646067625168 Volts
    Pacs_BOLC_SET_VH_G1(1.6005646067625168);
    // Set group 1 bol bias 02 (VL) to -0.19943539323748327 Volts
    Pacs_BOLC_SET_VL_G1(-0.19943539323748327);
    // Set group 1 bol bias 03 (VRL) to 0.3927137250656313 Volts
    Pacs_BOLC_SET_VRL_G1(0.3927137250656313);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1512536862532445 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1512536862532445);
    // Set group 2 bol bias 01 (VH) to 1.5835245401299414 Volts
    Pacs_BOLC_SET_VH_G2(1.5835245401299414);
    // Set group 2 bol bias 02 (VL) to -0.21647545987005867 Volts
    Pacs_BOLC_SET_VL_G2(-0.21647545987005867);
    // Set group 2 bol bias 03 (VRL) to 0.3880497715778095 Volts
    Pacs_BOLC_SET_VRL_G2(0.3880497715778095);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1457903439369534 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1457903439369534);
    // Set group 3 bol bias 01 (VH) to 1.5867464604266623 Volts
    Pacs_BOLC_SET_VH_G3(1.5867464604266623);
    // Set group 3 bol bias 02 (VL) to -0.2132535395733377 Volts
    Pacs_BOLC_SET_VL_G3(-0.2132535395733377);
    // Set group 3 bol bias 03 (VRL) to 0.3903025295231384 Volts
    Pacs_BOLC_SET_VRL_G3(0.3903025295231384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144668449205875 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144668449205875);
    // Set group 4 bol bias 01 (VH) to 1.6044364991789073 Volts
    Pacs_BOLC_SET_VH_G4(1.6044364991789073);
    // Set group 4 bol bias 02 (VL) to -0.19556350082109264 Volts
    Pacs_BOLC_SET_VL_G4(-0.19556350082109264);
    // Set group 4 bol bias 03 (VRL) to 0.387662053519384 Volts
    Pacs_BOLC_SET_VRL_G4(0.387662053519384);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1439743820479262 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1439743820479262);
    // Set group 5 bol bias 01 (VH) to 1.3451907640885556 Volts
    Pacs_BOLC_SET_VH_G5(1.3451907640885556);
    // Set group 5 bol bias 02 (VL) to -0.054809235911444244 Volts
    Pacs_BOLC_SET_VL_G5(-0.054809235911444244);
    // Set group 5 bol bias 03 (VRL) to 0.40021084689056974 Volts
    Pacs_BOLC_SET_VRL_G5(0.40021084689056974);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1532482013507512 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1532482013507512);
    // Set group 6 bol bias 01 (VH) to 1.39 Volts
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.4344512926668127 Volts
    Pacs_BOLC_SET_VRL_G6(0.4344512926668127);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.192323231555507 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.192323231555507);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7330644465100378 Volts
    Pacs_BOLC_SET_VH_G1(1.7330644465100378);
    // Set group 1 bol bias 02 (VL) to -0.26693555348996223 Volts
    Pacs_BOLC_SET_VL_G1(-0.26693555348996223);
    // Set group 1 bol bias 03 (VRL) to 0.3923254235050375 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923254235050375);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1507930978184753 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1507930978184753);
    // Set group 2 bol bias 01 (VH) to 1.714453661934205 Volts
    Pacs_BOLC_SET_VH_G2(1.714453661934205);
    // Set group 2 bol bias 02 (VL) to -0.2855463380657951 Volts
    Pacs_BOLC_SET_VL_G2(-0.2855463380657951);
    // Set group 2 bol bias 03 (VRL) to 0.38771628761093724 Volts
    Pacs_BOLC_SET_VRL_G2(0.38771628761093724);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1454032366160996 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1454032366160996);
    // Set group 3 bol bias 01 (VH) to 1.7283831876482196 Volts
    Pacs_BOLC_SET_VH_G3(1.7283831876482196);
    // Set group 3 bol bias 02 (VL) to -0.2716168123517804 Volts
    Pacs_BOLC_SET_VL_G3(-0.2716168123517804);
    // Set group 3 bol bias 03 (VRL) to 0.40171045250948384 Volts
    Pacs_BOLC_SET_VRL_G3(0.40171045250948384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157256007066197 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157256007066197);
    // Set group 4 bol bias 01 (VH) to 1.7381239240265867 Volts
    Pacs_BOLC_SET_VH_G4(1.7381239240265867);
    // Set group 4 bol bias 02 (VL) to -0.26187607597341334 Volts
    Pacs_BOLC_SET_VL_G4(-0.26187607597341334);
    // Set group 4 bol bias 03 (VRL) to 0.38896138623469356 Volts
    Pacs_BOLC_SET_VRL_G4(0.38896138623469356);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454582711839105 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454582711839105);
    // Set group 5 bol bias 01 (VH) to 1.4703496551390403 Volts
    Pacs_BOLC_SET_VH_G5(1.4703496551390403);
    // Set group 5 bol bias 02 (VL) to -0.12965034486095992 Volts
    Pacs_BOLC_SET_VL_G5(-0.12965034486095992);
    // Set group 5 bol bias 03 (VRL) to 0.39904033450461596 Volts
    Pacs_BOLC_SET_VRL_G5(0.39904033450461596);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151844445053932 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151844445053932);
    // Set group 6 bol bias 01 (VH) to 1.5181165758982518 Volts
    Pacs_BOLC_SET_VH_G6(1.5181165758982518);
    // Set group 6 bol bias 02 (VL) to -0.08188342410174834 Volts
    Pacs_BOLC_SET_VL_G6(-0.08188342410174834);
    // Set group 6 bol bias 03 (VRL) to 0.4343226272779045 Volts
    Pacs_BOLC_SET_VRL_G6(0.4343226272779045);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1921697898825356 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1921697898825356);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8730534488812565 Volts
    Pacs_BOLC_SET_VH_G1(1.8730534488812565);
    // Set group 1 bol bias 02 (VL) to -0.3269465511187437 Volts
    Pacs_BOLC_SET_VL_G1(-0.3269465511187437);
    // Set group 1 bol bias 03 (VRL) to 0.3922166883004623 Volts
    Pacs_BOLC_SET_VRL_G1(0.3922166883004623);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1506641222123926 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1506641222123926);
    // Set group 2 bol bias 01 (VH) to 1.8512060220322217 Volts
    Pacs_BOLC_SET_VH_G2(1.8512060220322217);
    // Set group 2 bol bias 02 (VL) to -0.34879397796777845 Volts
    Pacs_BOLC_SET_VL_G2(-0.34879397796777845);
    // Set group 2 bol bias 03 (VRL) to 0.3869592141320811 Volts
    Pacs_BOLC_SET_VRL_G2(0.3869592141320811);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1445244519836626 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1445244519836626);
    // Set group 3 bol bias 01 (VH) to 1.8654619469621685 Volts
    Pacs_BOLC_SET_VH_G3(1.8654619469621685);
    // Set group 3 bol bias 02 (VL) to -0.33453805303783174 Volts
    Pacs_BOLC_SET_VL_G3(-0.33453805303783174);
    // Set group 3 bol bias 03 (VRL) to 0.40224166318840543 Volts
    Pacs_BOLC_SET_VRL_G3(0.40224166318840543);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1578437499437477 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1578437499437477);
    // Set group 4 bol bias 01 (VH) to 1.8790483325189686 Volts
    Pacs_BOLC_SET_VH_G4(1.8790483325189686);
    // Set group 4 bol bias 02 (VL) to -0.32095166748103154 Volts
    Pacs_BOLC_SET_VL_G4(-0.32095166748103154);
    // Set group 4 bol bias 03 (VRL) to 0.39052544771082365 Volts
    Pacs_BOLC_SET_VRL_G4(0.39052544771082365);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1472446958154223 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1472446958154223);
    // Set group 5 bol bias 01 (VH) to 1.5346700184984832 Volts
    Pacs_BOLC_SET_VH_G5(1.5346700184984832);
    // Set group 5 bol bias 02 (VL) to -0.16532998150151687 Volts
    Pacs_BOLC_SET_VL_G5(-0.16532998150151687);
    // Set group 5 bol bias 03 (VRL) to 0.39828926215052507 Volts
    Pacs_BOLC_SET_VRL_G5(0.39828926215052507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1509436695484125 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1509436695484125);
    // Set group 6 bol bias 01 (VH) to 1.5825303056022821 Volts
    Pacs_BOLC_SET_VH_G6(1.5825303056022821);
    // Set group 6 bol bias 02 (VL) to -0.11746969439771773 Volts
    Pacs_BOLC_SET_VL_G6(-0.11746969439771773);
    // Set group 6 bol bias 03 (VRL) to 0.43350337388623417 Volts
    Pacs_BOLC_SET_VRL_G6(0.43350337388623417);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191192803954044 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191192803954044);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.034145377320728 Volts
    Pacs_BOLC_SET_VH_G1(2.034145377320728);
    // Set group 1 bol bias 02 (VL) to -0.36585462267927166 Volts
    Pacs_BOLC_SET_VL_G1(-0.36585462267927166);
    // Set group 1 bol bias 03 (VRL) to 0.4026842358176688 Volts
    Pacs_BOLC_SET_VRL_G1(0.4026842358176688);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163077213168135 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163077213168135);
    // Set group 2 bol bias 01 (VH) to 1.9964246373780308 Volts
    Pacs_BOLC_SET_VH_G2(1.9964246373780308);
    // Set group 2 bol bias 02 (VL) to -0.40357536262196914 Volts
    Pacs_BOLC_SET_VL_G2(-0.40357536262196914);
    // Set group 2 bol bias 03 (VRL) to 0.38543545754038677 Volts
    Pacs_BOLC_SET_VRL_G2(0.38543545754038677);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1427558304354366 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1427558304354366);
    // Set group 3 bol bias 01 (VH) to 2.0225756539924595 Volts
    Pacs_BOLC_SET_VH_G3(2.0225756539924595);
    // Set group 3 bol bias 02 (VL) to -0.37742434600754043 Volts
    Pacs_BOLC_SET_VL_G3(-0.37742434600754043);
    // Set group 3 bol bias 03 (VRL) to 0.41362905220735763 Volts
    Pacs_BOLC_SET_VRL_G3(0.41362905220735763);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704381594190805 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704381594190805);
    // Set group 4 bol bias 01 (VH) to 2.0286801589025623 Volts
    Pacs_BOLC_SET_VH_G4(2.0286801589025623);
    // Set group 4 bol bias 02 (VL) to -0.37131984109743765 Volts
    Pacs_BOLC_SET_VL_G4(-0.37131984109743765);
    // Set group 4 bol bias 03 (VRL) to 0.39131683434261844 Volts
    Pacs_BOLC_SET_VRL_G4(0.39131683434261844);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.14814867942076 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.14814867942076);
    // Set group 5 bol bias 01 (VH) to 1.5997463742933684 Volts
    Pacs_BOLC_SET_VH_G5(1.5997463742933684);
    // Set group 5 bol bias 02 (VL) to -0.2002536257066316 Volts
    Pacs_BOLC_SET_VL_G5(-0.2002536257066316);
    // Set group 5 bol bias 03 (VRL) to 0.3972802806465645 Volts
    Pacs_BOLC_SET_VRL_G5(0.3972802806465645);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1497335299275955 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1497335299275955);
    // Set group 6 bol bias 01 (VH) to 1.64826517003746 Volts
    Pacs_BOLC_SET_VH_G6(1.64826517003746);
    // Set group 6 bol bias 02 (VL) to -0.1517348299625401 Volts
    Pacs_BOLC_SET_VL_G6(-0.1517348299625401);
    // Set group 6 bol bias 03 (VRL) to 0.43238698345346915 Volts
    Pacs_BOLC_SET_VRL_G6(0.43238698345346915);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.189850849172478 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.189850849172478);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.1252730205231707 Volts
    Pacs_BOLC_SET_VH_G1(2.1252730205231707);
    // Set group 1 bol bias 02 (VL) to -0.3747269794768295 Volts
    Pacs_BOLC_SET_VL_G1(-0.3747269794768295);
    // Set group 1 bol bias 03 (VRL) to 0.4136487083795371 Volts
    Pacs_BOLC_SET_VRL_G1(0.4136487083795371);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.176055880953933 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.176055880953933);
    // Set group 2 bol bias 01 (VH) to 2.0735703522054516 Volts
    Pacs_BOLC_SET_VH_G2(2.0735703522054516);
    // Set group 2 bol bias 02 (VL) to -0.4264296477945484 Volts
    Pacs_BOLC_SET_VL_G2(-0.4264296477945484);
    // Set group 2 bol bias 03 (VRL) to 0.38501518126647505 Volts
    Pacs_BOLC_SET_VRL_G2(0.38501518126647505);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1422680405518997 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1422680405518997);
    // Set group 3 bol bias 01 (VH) to 2.1002048058798914 Volts
    Pacs_BOLC_SET_VH_G3(2.1002048058798914);
    // Set group 3 bol bias 02 (VL) to -0.3997951941201084 Volts
    Pacs_BOLC_SET_VL_G3(-0.3997951941201084);
    // Set group 3 bol bias 03 (VRL) to 0.41374892649754597 Volts
    Pacs_BOLC_SET_VRL_G3(0.41374892649754597);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170570690743195 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170570690743195);
    // Set group 4 bol bias 01 (VH) to 2.1080881836667413 Volts
    Pacs_BOLC_SET_VH_G4(2.1080881836667413);
    // Set group 4 bol bias 02 (VL) to -0.39191181633325867 Volts
    Pacs_BOLC_SET_VL_G4(-0.39191181633325867);
    // Set group 4 bol bias 03 (VRL) to 0.39179349399255325 Volts
    Pacs_BOLC_SET_VRL_G4(0.39179349399255325);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1486931849427977 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1486931849427977);
    // Set group 5 bol bias 01 (VH) to 1.6757782637240437 Volts
    Pacs_BOLC_SET_VH_G5(1.6757782637240437);
    // Set group 5 bol bias 02 (VL) to -0.22422173627595626 Volts
    Pacs_BOLC_SET_VL_G5(-0.22422173627595626);
    // Set group 5 bol bias 03 (VRL) to 0.40729645571050493 Volts
    Pacs_BOLC_SET_VRL_G5(0.40729645571050493);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1617149101325723 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1617149101325723);
    // Set group 6 bol bias 01 (VH) to 1.7136503402053438 Volts
    Pacs_BOLC_SET_VH_G6(1.7136503402053438);
    // Set group 6 bol bias 02 (VL) to -0.18634965979465615 Volts
    Pacs_BOLC_SET_VL_G6(-0.18634965979465615);
    // Set group 6 bol bias 03 (VRL) to 0.43098263818668947 Volts
    Pacs_BOLC_SET_VRL_G6(0.43098263818668947);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1881561132520857 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1881561132520857);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.209416047586087 Volts
    Pacs_BOLC_SET_VH_G1(2.209416047586087);
    // Set group 1 bol bias 02 (VL) to -0.3905839524139128 Volts
    Pacs_BOLC_SET_VL_G1(-0.3905839524139128);
    // Set group 1 bol bias 03 (VRL) to 0.4134679213904496 Volts
    Pacs_BOLC_SET_VRL_G1(0.4134679213904496);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758418687268812 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758418687268812);
    // Set group 2 bol bias 01 (VH) to 2.1541915675147214 Volts
    Pacs_BOLC_SET_VH_G2(2.1541915675147214);
    // Set group 2 bol bias 02 (VL) to -0.44580843248527846 Volts
    Pacs_BOLC_SET_VL_G2(-0.44580843248527846);
    // Set group 2 bol bias 03 (VRL) to 0.38424319746039115 Volts
    Pacs_BOLC_SET_VRL_G2(0.38424319746039115);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1413720715536493 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1413720715536493);
    // Set group 3 bol bias 01 (VH) to 2.1813068162319285 Volts
    Pacs_BOLC_SET_VH_G3(2.1813068162319285);
    // Set group 3 bol bias 02 (VL) to -0.4186931837680716 Volts
    Pacs_BOLC_SET_VL_G3(-0.4186931837680716);
    // Set group 3 bol bias 03 (VRL) to 0.41360319513591143 Volts
    Pacs_BOLC_SET_VRL_G3(0.41360319513591143);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704095720713417 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704095720713417);
    // Set group 4 bol bias 01 (VH) to 2.202944386753124 Volts
    Pacs_BOLC_SET_VH_G4(2.202944386753124);
    // Set group 4 bol bias 02 (VL) to -0.3970556132468757 Volts
    Pacs_BOLC_SET_VL_G4(-0.3970556132468757);
    // Set group 4 bol bias 03 (VRL) to 0.40381007074137704 Volts
    Pacs_BOLC_SET_VRL_G4(0.40381007074137704);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1624292794462514 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1624292794462514);
    // Set group 5 bol bias 01 (VH) to 1.7436864671540049 Volts
    Pacs_BOLC_SET_VH_G5(1.7436864671540049);
    // Set group 5 bol bias 02 (VL) to -0.2563135328459952 Volts
    Pacs_BOLC_SET_VL_G5(-0.2563135328459952);
    // Set group 5 bol bias 03 (VRL) to 0.4060804936984878 Volts
    Pacs_BOLC_SET_VRL_G5(0.4060804936984878);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1602616898977316 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1602616898977316);
    // Set group 6 bol bias 01 (VH) to 1.7834132365202005 Volts
    Pacs_BOLC_SET_VH_G6(1.7834132365202005);
    // Set group 6 bol bias 02 (VL) to -0.21658676347979958 Volts
    Pacs_BOLC_SET_VL_G6(-0.21658676347979958);
    // Set group 6 bol bias 03 (VRL) to 0.43021242094743417 Volts
    Pacs_BOLC_SET_VRL_G6(0.43021242094743417);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1872266025341247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1872266025341247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.297951276717203 Volts
    Pacs_BOLC_SET_VH_G1(2.297951276717203);
    // Set group 1 bol bias 02 (VL) to -0.4020487232827972 Volts
    Pacs_BOLC_SET_VL_G1(-0.4020487232827972);
    // Set group 1 bol bias 03 (VRL) to 0.41346783054780994 Volts
    Pacs_BOLC_SET_VRL_G1(0.41346783054780994);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175841761189199 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175841761189199);
    // Set group 2 bol bias 01 (VH) to 2.237764444765691 Volts
    Pacs_BOLC_SET_VH_G2(2.237764444765691);
    // Set group 2 bol bias 02 (VL) to -0.46223555523430954 Volts
    Pacs_BOLC_SET_VL_G2(-0.46223555523430954);
    // Set group 2 bol bias 03 (VRL) to 0.3829355076340157 Volts
    Pacs_BOLC_SET_VRL_G2(0.3829355076340157);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.13985443895415 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.13985443895415);
    // Set group 3 bol bias 01 (VH) to 2.2663898962449944 Volts
    Pacs_BOLC_SET_VH_G3(2.2663898962449944);
    // Set group 3 bol bias 02 (VL) to -0.43361010375500575 Volts
    Pacs_BOLC_SET_VL_G3(-0.43361010375500575);
    // Set group 3 bol bias 03 (VRL) to 0.4131238530516411 Volts
    Pacs_BOLC_SET_VRL_G3(0.4131238530516411);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1698796071025357 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1698796071025357);
    // Set group 4 bol bias 01 (VH) to 2.279673221041111 Volts
    Pacs_BOLC_SET_VH_G4(2.279673221041111);
    // Set group 4 bol bias 02 (VL) to -0.42032677895888915 Volts
    Pacs_BOLC_SET_VL_G4(-0.42032677895888915);
    // Set group 4 bol bias 03 (VRL) to 0.39361613583982535 Volts
    Pacs_BOLC_SET_VRL_G4(0.39361613583982535);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.15077544624775 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.15077544624775);
    // Set group 5 bol bias 01 (VH) to 1.809656711096493 Volts
    Pacs_BOLC_SET_VH_G5(1.809656711096493);
    // Set group 5 bol bias 02 (VL) to -0.2903432889035071 Volts
    Pacs_BOLC_SET_VL_G5(-0.2903432889035071);
    // Set group 5 bol bias 03 (VRL) to 0.4049518544441218 Volts
    Pacs_BOLC_SET_VRL_G5(0.4049518544441218);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1589129512261658 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1589129512261658);
    // Set group 6 bol bias 01 (VH) to 1.852468907894238 Volts
    Pacs_BOLC_SET_VH_G6(1.852468907894238);
    // Set group 6 bol bias 02 (VL) to -0.247531092105762 Volts
    Pacs_BOLC_SET_VL_G6(-0.247531092105762);
    // Set group 6 bol bias 03 (VRL) to 0.4292993417752352 Volts
    Pacs_BOLC_SET_VRL_G6(0.4292993417752352);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1861246581200136 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1861246581200136);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3806926938420414 Volts
    Pacs_BOLC_SET_VH_G1(2.3806926938420414);
    // Set group 1 bol bias 02 (VL) to -0.41930730615795847 Volts
    Pacs_BOLC_SET_VL_G1(-0.41930730615795847);
    // Set group 1 bol bias 03 (VRL) to 0.4020155079485436 Volts
    Pacs_BOLC_SET_VRL_G1(0.4020155079485436);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162285695776181 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162285695776181);
    // Set group 2 bol bias 01 (VH) to 2.3371282046100963 Volts
    Pacs_BOLC_SET_VH_G2(2.3371282046100963);
    // Set group 2 bol bias 02 (VL) to -0.46287179538990364 Volts
    Pacs_BOLC_SET_VL_G2(-0.46287179538990364);
    // Set group 2 bol bias 03 (VRL) to 0.3923402298587034 Volts
    Pacs_BOLC_SET_VRL_G2(0.3923402298587034);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1507712805161225 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1507712805161225);
    // Set group 3 bol bias 01 (VH) to 2.356604953923699 Volts
    Pacs_BOLC_SET_VH_G3(2.356604953923699);
    // Set group 3 bol bias 02 (VL) to -0.44339504607630065 Volts
    Pacs_BOLC_SET_VL_G3(-0.44339504607630065);
    // Set group 3 bol bias 03 (VRL) to 0.4124662568673877 Volts
    Pacs_BOLC_SET_VRL_G3(0.4124662568673877);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.169152536126319 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.169152536126319);
    // Set group 4 bol bias 01 (VH) to 2.3825039100730487 Volts
    Pacs_BOLC_SET_VH_G4(2.3825039100730487);
    // Set group 4 bol bias 02 (VL) to -0.4174960899269509 Volts
    Pacs_BOLC_SET_VL_G4(-0.4174960899269509);
    // Set group 4 bol bias 03 (VRL) to 0.40493410269973024 Volts
    Pacs_BOLC_SET_VRL_G4(0.40493410269973024);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1637149679245193 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1637149679245193);
    // Set group 5 bol bias 01 (VH) to 1.883738472848583 Volts
    Pacs_BOLC_SET_VH_G5(1.883738472848583);
    // Set group 5 bol bias 02 (VL) to -0.31626152715141714 Volts
    Pacs_BOLC_SET_VL_G5(-0.31626152715141714);
    // Set group 5 bol bias 03 (VRL) to 0.4028494691164935 Volts
    Pacs_BOLC_SET_VRL_G5(0.4028494691164935);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.156400882301432 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.156400882301432);
    // Set group 6 bol bias 01 (VH) to 1.9235912310846244 Volts
    Pacs_BOLC_SET_VH_G6(1.9235912310846244);
    // Set group 6 bol bias 02 (VL) to -0.2764087689153759 Volts
    Pacs_BOLC_SET_VL_G6(-0.2764087689153759);
    // Set group 6 bol bias 03 (VRL) to 0.4280070912945936 Volts
    Pacs_BOLC_SET_VRL_G6(0.4280070912945936);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1845650655206446 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1845650655206446);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6181566702818313 Volts
    Pacs_BOLC_SET_VH_G1(2.6181566702818313);
    // Set group 1 bol bias 02 (VL) to -0.38184332971816887 Volts
    Pacs_BOLC_SET_VL_G1(-0.38184332971816887);
    // Set group 1 bol bias 03 (VRL) to 0.43545225816479755 Volts
    Pacs_BOLC_SET_VRL_G1(0.43545225816479755);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2018572484354544 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2018572484354544);
    // Set group 2 bol bias 01 (VH) to 2.5300933623498008 Volts
    Pacs_BOLC_SET_VH_G2(2.5300933623498008);
    // Set group 2 bol bias 02 (VL) to -0.469906637650199 Volts
    Pacs_BOLC_SET_VL_G2(-0.469906637650199);
    // Set group 2 bol bias 03 (VRL) to 0.3917176926734228 Volts
    Pacs_BOLC_SET_VRL_G2(0.3917176926734228);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1500484890692286 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1500484890692286);
    // Set group 3 bol bias 01 (VH) to 2.5545115967606167 Volts
    Pacs_BOLC_SET_VH_G3(2.5545115967606167);
    // Set group 3 bol bias 02 (VL) to -0.4454884032393832 Volts
    Pacs_BOLC_SET_VL_G3(-0.4454884032393832);
    // Set group 3 bol bias 03 (VRL) to 0.41136249367186684 Volts
    Pacs_BOLC_SET_VRL_G3(0.41136249367186684);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1679320914489204 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1679320914489204);
    // Set group 4 bol bias 01 (VH) to 2.591852678092942 Volts
    Pacs_BOLC_SET_VH_G4(2.591852678092942);
    // Set group 4 bol bias 02 (VL) to -0.408147321907058 Volts
    Pacs_BOLC_SET_VL_G4(-0.408147321907058);
    // Set group 4 bol bias 03 (VRL) to 0.4158848845694993 Volts
    Pacs_BOLC_SET_VRL_G4(0.4158848845694993);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176235181901646 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176235181901646);
    // Set group 5 bol bias 01 (VH) to 2.0340896725156363 Volts
    Pacs_BOLC_SET_VH_G5(2.0340896725156363);
    // Set group 5 bol bias 02 (VL) to -0.3659103274843634 Volts
    Pacs_BOLC_SET_VL_G5(-0.3659103274843634);
    // Set group 5 bol bias 03 (VRL) to 0.3987896988621052 Volts
    Pacs_BOLC_SET_VRL_G5(0.3987896988621052);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1515438563527702 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1515438563527702);
    // Set group 6 bol bias 01 (VH) to 2.080247845760918 Volts
    Pacs_BOLC_SET_VH_G6(2.080247845760918);
    // Set group 6 bol bias 02 (VL) to -0.31975215423908154 Volts
    Pacs_BOLC_SET_VL_G6(-0.31975215423908154);
    // Set group 6 bol bias 03 (VRL) to 0.42577779561759777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42577779561759777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1818744401374954 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1818744401374954);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.9648806825465286 Volts
    Pacs_BOLC_SET_VH_G1(2.9648806825465286);
    // Set group 1 bol bias 02 (VL) to -0.3351193174534714 Volts
    Pacs_BOLC_SET_VL_G1(-0.3351193174534714);
    // Set group 1 bol bias 03 (VRL) to 0.4345971818834749 Volts
    Pacs_BOLC_SET_VRL_G1(0.4345971818834749);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2008507320864905 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2008507320864905);
    // Set group 2 bol bias 01 (VH) to 2.8835722707263107 Volts
    Pacs_BOLC_SET_VH_G2(2.8835722707263107);
    // Set group 2 bol bias 02 (VL) to -0.4164277292736889 Volts
    Pacs_BOLC_SET_VL_G2(-0.4164277292736889);
    // Set group 2 bol bias 03 (VRL) to 0.4147637133976726 Volts
    Pacs_BOLC_SET_VRL_G2(0.4147637133976726);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176763943185141 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176763943185141);
    // Set group 3 bol bias 01 (VH) to 2.924290179534832 Volts
    Pacs_BOLC_SET_VH_G3(2.924290179534832);
    // Set group 3 bol bias 02 (VL) to -0.37570982046516804 Volts
    Pacs_BOLC_SET_VL_G3(-0.37570982046516804);
    // Set group 3 bol bias 03 (VRL) to 0.4333518026225201 Volts
    Pacs_BOLC_SET_VRL_G3(0.4333518026225201);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.19222958084261 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.19222958084261);
    // Set group 4 bol bias 01 (VH) to 2.938948180111503 Volts
    Pacs_BOLC_SET_VH_G4(2.938948180111503);
    // Set group 4 bol bias 02 (VL) to -0.3610518198884969 Volts
    Pacs_BOLC_SET_VL_G4(-0.3610518198884969);
    // Set group 4 bol bias 03 (VRL) to 0.4248831336064878 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248831336064878);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1865155818476714 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1865155818476714);
    // Set group 5 bol bias 01 (VH) to 2.231303538712061 Volts
    Pacs_BOLC_SET_VH_G5(2.231303538712061);
    // Set group 5 bol bias 02 (VL) to -0.36869646128793887 Volts
    Pacs_BOLC_SET_VL_G5(-0.36869646128793887);
    // Set group 5 bol bias 03 (VRL) to 0.4261159129370585 Volts
    Pacs_BOLC_SET_VRL_G5(0.4261159129370585);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1842235863263286 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1842235863263286);
    // Set group 6 bol bias 01 (VH) to 2.2493043049150576 Volts
    Pacs_BOLC_SET_VH_G6(2.2493043049150576);
    // Set group 6 bol bias 02 (VL) to -0.3506956950849426 Volts
    Pacs_BOLC_SET_VL_G6(-0.3506956950849426);
    // Set group 6 bol bias 03 (VRL) to 0.4237159708307814 Volts
    Pacs_BOLC_SET_VRL_G6(0.4237159708307814);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.179385794698645 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.179385794698645);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    // sync the bus
    sync();
}

// CVS comments  : $Id: PacsSpecDefaults.txt,v 1.12 2007/10/25 12:15:42 dcesarsk Exp $ 
// Purpose       : Fill index=0 of OBCP and SPECxxx tuples with known
//                 sensible default values
//                 Starting with version 2.0, "sensible" values will be read
//                 from CAL-U files
//
// CUS author    : DAC
// Script file   : PacsSpecDefaults.txt 
//
// Input arguments
// type           name     Description
// string         throw    HSPOT defined chopper amplitude
//
// Return values
// Type    Name                  Description
// tuple   confSPECx & confOBCP  electronics and OBCP default parameters
//
// Description   : Give default values to tuples OBCP and SPEC. May
// use more information from yet to be created CAL-U files. So far
// only "throw" (HSPOT defined) appears necessary as a call argument
// Getting more SPU-like information from CAL-U is hampered by the "finite"
// size of the confSPEC tuples. May have to read CAL-U elsewhere to get
// more SPU information (SPEC_spu_setup perhaps?)
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Returns       : {{confSPECblu},{confSPECred},{confOBCP}}  
//
// confSPEC{0 -> 8} contains:
//   capa       nb_rdouts_ramp nb_rdouts_subramp  comp_mode
//   glitch_det ramp_fit_alg   nb_raw             bias_r      bias_d
//
// confOBCP{0 -> 19} contains:
// nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
// nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
// grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
// chop_pos_SRC     chop_pos_REF1    chop_pos_REF2
// chop_pos_CS1     chop_pos_CS2     chop_def
// detector         order
//
// version       : 2.0
// History       : 
// 0.1 19-may-2005 First coding
// 1.0 31-May-2005 All elements of confSPEC are now "int"
// 1.1  7-Jun-2005 Ditto for confOBCP
// 1.2 14-jun-2005 Added chopper throw in calling list
// 1.3 21-jun-2005 Renamed PacsSpecDefaults from PacsLineSpecDefaults (no
//                 difference whether LineSpec or RangeSpec)
// 1.4 24-jan-2006 Read CHOP parameters in [arcsec]; convert to ENG
// 1.5 12-apr-2006 No longer FLTW default position; new code for confOBCP{19}:
//       1=don't care/don't know; 1, 2, 3 : grating order. NOTE: no filter is
//       necessary for order = 1
// 1.6 25-apr-2006 Added comp_mode defaults
// 2.0 16-feb-2007 Access CAL-U files
//                 Moved verbose into call arguments
//                 Added yetTBD argument for future choice of CAL-U entries
// 2.1  4-mar-2007 Use special "throw" for raster w/OFF
// 2.2 14-mar-2007 Use extraConf for bright lines
// 2.3 26-mar-2007 Read most parameters from CONF_SPEC_params CAL-U file
// 2.4  4-oct-2007 SPR-3619 Missing chopper throws for CS1 and CS2
// 2.5 20-mar-2009 SCR 6353 de-hardcode nb_SRC_OFF et ...
// 3.0 17-jun-2009 DAC Adapted for new CONF_SPEC_param (without s!) table
//                 - remove "normal/bright" constraints in extraConf
//                 - new logic to read "row" table CONF_SPEC_param
// 3.1 10-jul-2009 VD add detector sync based on stopUnUsedChannelSPU bool
// 4.0 27-oct-2009 VD PHS-1226 enable both SPU channels, disable PHS-1118 
//                    Keep sync on Blue channel
//
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} procedure PacsSpecDefaults {
    /* Chopper throw; needed for OBCP                                       */
    string throw = "large" in ["large","medium","small","offraster"];
    /* Spectro configuration scheme; needed for confSPEC tuple              */
    /* May take TBD values other than normal/bright                         */
    string extraConf = "normal";
    /* add detector sync */
    /*    int detector = 1 ; */
    /* bla bla                                                              */
    bool verbose = false;
}{
    // Define variables to be used here
    {int,int,int,int,int,int,int,int,int} confSPECblu = {0,0,0,0,0,0,0,0,0};
    {int,int,int,int,int,int,int,int,int} confSPECred = {0,0,0,0,0,0,0,0,0};
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    // Fill confSPECxxx from CAL-U file
    // NOTE: The new file CONF_SPEC_param (no final s!) is indexed by row name
    // Apart from several extra elements, its contents is that of CONF_SPEC_params
    string calU = "CONF_SPEC_param";
    // Which row of the CAL-U file?
    string confROW = "Normal0";
    if(extraConf == "bright") {
        confROW = "Fast0";
    }
    // Identify RED and BLU rows    
    string rowRED = "" + confROW + "RED";
    string rowBLU = "" + confROW + "BLU";
    if(verbose) {
        debug_print("SpecDef reads Table/ROWs: " + calU + " / " + rowRED + " and " + rowBLU);
    }
    // for the momewnt order is NOT passed on:
    string order = "2";
    // Read all red and blu rows
    int capa_red = ilookup(calU,rowRED,"capa");
    confSPECred{0} = capa_red;
    int capa_blu = ilookup(calU,rowBLU,"capa");
    confSPECblu{0} = capa_blu;
    int nb_rdouts_ramp_red = ilookup(calU,rowRED,"nb_rd");
    confSPECred{1} = nb_rdouts_ramp_red;
    int nb_rdouts_ramp_blu = ilookup(calU,rowBLU,"nb_rd");
    confSPECblu{1} = nb_rdouts_ramp_blu;
    int nb_rd_sub_red = ilookup(calU,rowRED,"nb_sub");
    confSPECred{2} = nb_rd_sub_red;
    int nb_rd_sub_blu = ilookup(calU,rowBLU,"nb_sub");
    confSPECblu{2} = nb_rd_sub_blu;
    int comp_mode_red = ilookup(calU,rowRED,"cmp_mde");
    confSPECred{3} = comp_mode_red;
    int comp_mode_blu = ilookup(calU,rowBLU,"cmp_mde");
    confSPECblu{3} = comp_mode_blu;
    int glitch_det_red = ilookup(calU,rowRED,"gltch_d");
    confSPECred{4} = glitch_det_red;
    int glitch_det_blu = ilookup(calU,rowBLU,"gltch_d");
    confSPECblu{4} = glitch_det_red;
    int ramp_fit_red = ilookup(calU,rowRED,"rmp_f");
    confSPECred{5} = ramp_fit_red;
    int ramp_fit_blu = ilookup(calU,rowBLU,"rmp_f");
    confSPECblu{5} = ramp_fit_red;
    int nb_raw_red = ilookup(calU,rowRED,"nb_r");
    confSPECred{6} = nb_raw_red;
    int nb_raw_blu = ilookup(calU,rowBLU,"nb_r");
    confSPECblu{6} = nb_raw_blu;
    int bias_r_red_mV = ilookup(calU,rowRED,"bias_r");
    confSPECred{7} = bias_r_red_mV;
    int bias_r_blu_mV = ilookup(calU,rowBLU,"bias_r");
    confSPECblu{7} = bias_r_blu_mV;
    int bias_d_red_mV = ilookup(calU,rowRED,"bias_d");
    confSPECred{8} = bias_d_red_mV;
    int bias_d_blu_mV = ilookup(calU,rowBLU,"bias_d");
    confSPECblu{8} = bias_d_blu_mV;
    // Fill now confOBCP tuple
    int grat_start_pos = 500000;
    confOBCP{8} = grat_start_pos;
    // Chopper and grating expected at their default positions
    int chop_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    int grat_def_pos = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    confOBCP{10} = grat_def_pos;
    confOBCP{17} = chop_def;
    // Position filter wheel at default position
    //   int fw_pos       = ilookup("SPEC_MEC_Defaults","Spectroscopy","FW");
    // Initialize to don't care/don't know
    int fw_pos = 1;
    confOBCP{19} = fw_pos;
    // initialise defaults OBCPs parameters
    calU = "OBCPDefault";
    if(extraConf == "bright") {
        order = "B" + order;
    }
    int nb_up_down = ilookup(calU,order,"nb_up_down");
    confOBCP{0} = nb_up_down;
    int nb_SRC_OFF = ilookup(calU,order,"nb_SRC_OFF");
    confOBCP{3} = nb_SRC_OFF;
    int nb_ramps_plateau = ilookup(calU,order,"nb_ramps_plateau");
    confOBCP{4} = nb_ramps_plateau;
    int nb_CS1_CS2 = ilookup(calU,order,"nb_CS1_CS2");
    confOBCP{5} = nb_CS1_CS2;
    // Read chopper positions [arcsec] and convert to ENG units
    // Chopper angles
    calU = "SPEC_CHOP_params";
    // Read angles
    double auxSRC = dlookup(calU,throw,"SRC");
    double auxREF1 = dlookup(calU,throw,"REF1");
    double auxREF2 = dlookup(calU,throw,"REF2");
    // Convert into ENG values
    string convU = "SPEC_CHOP_sky";
    int onSRC = PacsReadChopSky(convU,auxSRC);
    int onREF1 = PacsReadChopSky(convU,auxREF1);
    int onREF2 = PacsReadChopSky(convU,auxREF2);
    // Special logic for raster with OFF: we chop between SRC and CS1   
    if(throw == "offraster") {
        // If raster w/OFF, lookup chopper CS1 position (already in ENG)
        calU = "CHOPPERCSparams";
        onREF1 = ilookup(calU,"SPEC","pos_CS1");
        onREF2 = onREF1;
    }
    if(verbose) {
        debug_print("SpecDef:chopSRC  " + auxSRC + " [arcsec] -> " + onSRC + " [ENG]");
        debug_print("SpecDef:chopREF1 " + auxREF1 + " [arcsec] -> " + onREF1 + " [ENG]");
        debug_print("SpecDef:chopREF2 " + auxREF2 + " [arcsec] -> " + onREF2 + " [ENG]");
    }
    confOBCP{12} = onSRC;
    confOBCP{13} = onREF1;
    confOBCP{14} = onREF2;
    // SPR-3619. Chopper position for CS1 and CS2
    // Read table CHOPPERCSparams
    calU = "CHOPPERCSparams";
    int chop_pos_CS1 = ilookup(calU,"SPEC","pos_CS1");
    int chop_pos_CS2 = ilookup(calU,"SPEC","pos_CS2");
    confOBCP{15} = chop_pos_CS1;
    confOBCP{16} = chop_pos_CS2;
    int detector = 1;
    confOBCP{18} = detector;

    return {confSPECblu,confSPECred,confOBCP};
}

// Missionphase : 
//
// Purpose	:  Starts the diagnostic housekeeping
//                  
// Author	: 
// CUS author 	: 
//
// Description	: 
//
// Dependencies : 
//
// Preconditions   : PACS switched-on
//                 
// Comments	: 
//
// Version	: 3.0	
// 
// History 	: 0.1 04-05-06 creation by SC
//                1.0 24-07-06 SC. test script.
//                2.0 24-07-06 SC. name updated.
//                3.0 25-07-06 SC. script works.
//
block SPEC_DiagHK_DynRange_block_start PACS 403 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //-------------------------------------------- 
    // Setup and start diagnostic HK
    // 305: DMC_DECB_VBI_R_4
    // 326: DMC_DECB_BR_CM_4
    // 327: DMC_DECB_ZB_CM_4
    // 338: DMC_DECR_V0BIAS1
    // 339: DMC_DECR_VBI_R_1
    // 359: DMC_DECR_CR_ST_1 (bit 2-3 is for the capacitor value)
    // 360: DMC_DECR_BR_CM_1
    // 361: DMC_DECR_ZB_CM_1
    // 372: DMC_DECR_V0BIAS2
    // 373: DMC_DECR_VBI_R_2
    // 394: DMC_DECR_BR_CM_2
    // 395: DMC_DECR_ZB_CM_2
    //-------------------------------------------- 
    int cs_diag_hk_length = 13;
    {int}[] parlist = [{305},{326},{327},{338},{339},{359},{360},{361},{372},{373},{394},{395},{0xffff}];
    int[] aux = [305,326,327,338,339,359,360,361,372,373,394,395,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(cs_diag_hk_length,parlist,check_sum);
    // Diagnostic HK period 
    int diag_hk_period = 100;
    // Diagnostic HK period (in milliseconds)
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark End of Block
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	: Ge:Ga detector bias scan
//
// Author	: Helmut Dannerbauer &Roland Vavrek
// CUS script	: HD
// CVS file	: 
//
// Arguments	: - Bias_d blue parameters from 1 to 8
//                     - Bias_d red  parameters from 1 to 8
//                 
//		   
// Description	: Loop over 8 different bias values while chopper stairs on CS2. Each bias setting
//                        is followed by a 120 sec measurement.
//                  
// Dependencies :  - PACS_Spec_Heat_Setup
//                 - PACS_Chopper_mov_abs_fm_bb
//                 - SPEC_Gra_move_abs_raw
//                 - SPEC_spu_reset
//                 - SPEC_cre_setup
//                 - SPEC_spu_setup
//
//
// Preconditions : - PACS is switched on
//                        - Setup spectroscopy
//	     - Mechanics and CS controllers are SWON and ENABLED (e.g. SetupSpectroscopyEQMIMT)
//                        - CS2 temperature has been staibilized already
//
// Comments	: Blue heater heaters are kept on constant temperature. 
//
// Version	: 2.0
//               
// History	: 1.0 HD. IST update.
// 		  2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
obs PacsEng_Spec_detector_imt509 {
    /* Needed variables to call PacsEng_Spec_detector_imt509                        */
    double bias_d_blue1 = 0.0801; //Blue bias #1
    double bias_d_blue2 = 0.1101; //Blue bias #2
    double bias_d_blue3 = 0.1401; //Blue bias #3
    double bias_d_blue4 = 0.1701; //Blue bias #4
    double bias_d_blue5 = 0.2001; //Blue bias #5
    double bias_d_blue6 = 0.2301; //Blue bias #6
    double bias_d_blue7 = 0.2601; //Blue bias #7
    double bias_d_blue8 = 0.2901; //Blue bias #8
    double bias_d_red1 = 0.0201; //Red bias #1
    double bias_d_red2 = 0.0301; //Red bias #2
    double bias_d_red3 = 0.0401; //Red bias #3
    double bias_d_red4 = 0.0501; //Red bias #4
    double bias_d_red5 = 0.0601; //Red bias #5
    double bias_d_red6 = 0.0701; //Red bias #6
    double bias_d_red7 = 0.0801; //Red bias #7
    double bias_d_red8 = 0.0901; //Red bias #8
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_detector_imt509                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_detector_imt509(bias_d_blue1,bias_d_blue2,bias_d_blue3,bias_d_blue4,bias_d_blue5,bias_d_blue6,bias_d_blue7,bias_d_blue8,bias_d_red1,bias_d_red2,bias_d_red3,bias_d_red4,bias_d_red5,bias_d_red6,bias_d_red7,bias_d_red8)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_detector_imt509(bias_d_blue1,bias_d_blue2,bias_d_blue3,bias_d_blue4,bias_d_blue5,bias_d_blue6,bias_d_blue7,bias_d_blue8,bias_d_red1,bias_d_red2,bias_d_red3,bias_d_red4,bias_d_red5,bias_d_red6,bias_d_red7,bias_d_red8);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

//
// $Id: PacsCal_Spec_Dark_CS_SimultaneousWarmUp.txt,v 1.1 2008/11/12 16:46:30 pierre Exp $
// Missionphase  : PACS FM IST SOVT2 & PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : PACS Dark Measurement
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version	: 1.0
// History       : 1.0  12-Nov-2008  PR
//
obs PacsCal_Spec_Dark_CS_SimultaneousWarmUp {
    /* Needed variables to call PacsCal_Spec_CS_SimultaneousWarmUp */
    int obs_time = 540; // Observing time per CS/FW/Grating setting
    int chop_time = 180; // Chopper plateau [sec] during CS temp rise time (0 = no chopping)
    /* POINTING PARAMETERS */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    /* End of needed variables for PacsEng_Spec_CS_SimultaneousWarmUp */                     */
}{
    debug_print("obs PacsCal_Spec_Dark_CS_SimultaneousWarmUp. Version 1.0. 20081112");
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    int tslewmin = 0;
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Dark_CS_SimultaneousWarmUp(obs_time,chop_time)));
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    debug_print("ts: " + ts);
    //
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Dark_CS_SimultaneousWarmUp(obs_time,chop_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Script file   : OBCP_chop_scan_spec.txt
// Missionphase  :
//
// Purpose       : Chopper Up-Down Scan Spectroscopy (OBCP 18, DMC Seq. 16)
//                 This procedure is required to execute chopper scans across
//                 the PACS field of view at a given grating position. The 
//                 filter wheel is commanded 
//                 outside this OBCP. This procedure calls the sequence 
//                 described in sec. 4.2.9
//
// OBCP author   : HF
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Chop increasingly away from start position; then increasingly
// closer to start position. Whole operation may be repeated nb_up_dn times
//
// Dependencies  :
//
// Preconditions :
//
// Comments      :
// Version      : 0.3
//
// History       : 0.1 28-jun-2006 DAC
//                    0.2 08-sep-2006 TM: DMC sequence corrected
//                    0.3 08-sep-2006 TM: DMC sequence parameters corrected
//                    0.4 08-sep-2008 DAC: Use OBCP number instead of name
//
int[] block OBCP_chop_scan_spec PACS 18 {
    int nb_up_dn = 1; // P#1  number of up-down seqs.
    int nb_ramps = 1; // P#2  number of ramps on step
    int nb_steps_up = 10; // P#3  number of steps up
    int nb_steps_dn = 10; // P#4  number of steps down
    int step_up = 300; // P#5  relative move up
    int step_dn = -300; // P#6  relative move down
    int detector = 1; // Detector to SYNCH on
    int grat_pos = 535000; // Grating position
    int chop_start_pos = 0; // Chopper start position
    int grat_time = 20000; // Grating time
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression
    int grat_def = 535000; // Grating default
    int grat_def_time = 40000; // Grating default time
    int chop_def = 0; // Chopper default position
    int nb_rdouts_ramp = 64; // Ramp length  
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain system parameter from PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duree_msec [msec] as it goes)
    // Begin
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    // Here and elsewhere it is assumed that OBCP "internal" TCs take t_cmd
    // [msec] to be executed
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_pos)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_start_pos)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM)
    // (all parameters filled by DPU based on seq parameter)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHKSUM)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_time)
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    // DMC_START_SEQUENCE
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Call DEC/MEC sequence just to know the seq time
    int[] duree1 = DMC_chop_scan_spec(nb_up_dn,nb_ramps,nb_steps_up,nb_steps_dn);
    debug_print("Duration DMC_chop_scan_spec [ramps] " + duree1);
    // Convert duration [readouts] into [msec]; add dmc_margin
    int seq_time = ifloor(double(duree1[0]) * ramp_time) + dmc_margin;
    // Tally durations
    duree_msec = duree_msec + seq_time;
    // Convert other times as well into msec
    duree_SRC = ifloor(double(duree1[1]) * ramp_time);
    duree_REF = ifloor(double(duree1[2]) * ramp_time);
    duree_CAL = ifloor(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + ifloor(double(duree1[4]) * ramp_time) + dmc_margin;
    // Check execution status of the sequence and in case of
    // failure stop OBCP and issue TM(1,8) + event
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_def)
    duree_msec = duree_msec + grat_def_time;
    duree_OVR = duree_OVR + grat_def_time;
    // DMC_MOVE_CHOP_ABS(chop_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Issue TM(1,7)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // End
    // Duration: 10 x 200ms + grat_def_time + grat_time + seq_time + 0.5s
    // Now trigger execution of OBCP
    // This OBCP is number 18, requires 17 parameters and lasts seq_time [msec]
    // It calls DMC sequence 16
    string obcp_ID = "CHOP_UPDOWN_SPEC";
    int obcp_par_nber = 17;
    int seq_DMC = 16;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_dn},{4,nb_ramps},{5,nb_steps_up},{6,nb_steps_dn},{7,step_up},{8,step_dn},{9,detector},{10,grat_pos},{11,chop_start_pos},{12,grat_time},{13,comp_mode_blu},{14,comp_mode_red},{15,grat_def},{16,grat_def_time},{17,chop_def}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nber,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Return total duration [sec] to calling program
    // Create return time array; convert into [sec]
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // Set delay()
    delay(time_array[0]);
    // Ending time
    int time_elapsed = time() - time_start;
    time_array[0] = time_elapsed;
    // Return

    return time_array;
}

// CVS comments  : $Id: 
// Purpose       : Invoke a PACS calibration OBCP during slew to source
// 		   using ABBA chopper scheme;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsSpecSlewCal.txt 
//
// Input arguments
// Type                     Name          Description
// bool                     verbose       Debug_print or not 
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECblu   BLUE SPU parameters
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECred   RED  SPU parameters
// {int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int}[]  confOBCP      OBCP parameters
//  bool                    doPROLOG      Perform/don't AOT prologue
//  double []               keyWAVE       One or several key wavelengths
//  int                     filter        Where to move FltW (as order)
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per key line
//
// Description   : Perform AOT prologue and then OBCP #35.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 0.1 DAC 10-may-2006 
// 		 : 1.0 13-mar-2009 VD OBCP35
//                 1.1  3-jun-2009 DAC Original PacsPacsSpecSlewCal35 from
//                                 VD renamed PacsSpecSlewCal
//                 1.2 18-jun-2009 DAC Enter into OBCP35params with K-orders
//                                 to schedule KeyWave calibrations
//                 1.3 20-jul-2009 VD introduces the faintLines (extraConf == bright for calU CAL block     
//                 1.4 14-sep-2009 VD PHS-1174, grat_keyWAVE instead of keyWAVE                        
//
int[][] procedure PacsSpecSlewCal_grat {
    /* verbose debug print                          */
    bool verbose = false;
    /* SPEC parameters for BLU and RED              */
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,64,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,64,0,0,0,0,0,0,0}];
    /* OBCP parameters                               */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* Perform/don't AOT prologue                    */
    bool doPROLOG = true;
    /* One or several key wavelengths                */
    /* PHS-1174  */
    int[] grat_keyWAVE = [497500];
    double[] keyWAVE = [62.5];
    /* Where to leave FltW (as order)                */
    int filter = 2;
    /* Where to leave grating at end of CAL          */
    int frstLstGratPos = 535000;
    /* User defined grating order                    */
    string orderSel = "order3";
}{
    // Debug only
    if(verbose) {
        debug_print("PacsSpecSlew called with:");
        debug_print("confSPECblu: " + confSPECblu[0]);
        debug_print("confSPECred: " + confSPECred[0]);
        debug_print("confOBCP: " + confOBCP[0]);
        debug_print("doPROLOG: " + doPROLOG);
        debug_print("grat_keyWAVE: " + grat_keyWAVE);
        debug_print("filter: " + filter);
        debug_print("frstLstGrat: " + frstLstGratPos);
        debug_print("orderSel: " + orderSel);
    }
    // Array to collect OBCP times per line
    // NOTE: time variables in units of either number of ramps (SPEC) or
    // number of readouts (BOLO) or plain seconds. The calling program 
    // must convert, if applicable, this information into actual duration 
    // in true time units [seconds].
    // SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky), CAL source, 
    // and overheads (wait for something). Total duration is given by duree_num. 
    // If no error, this duration must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    int[][] dureeCalKey = [[0,0,0,0,0]];
    // Long sequence to "unpack" default values from tuples
    int capa_blu = confSPECblu[0]{0};
    int nb_rdouts_ramp_blu = confSPECblu[0]{1};
    int nb_rdouts_subramp_blu = confSPECblu[0]{2};
    int comp_mode_blu = confSPECblu[0]{3};
    int glitch_det_blu = confSPECblu[0]{4};
    int ramp_fit_alg_blu = confSPECblu[0]{5};
    int nb_raw_blu = confSPECblu[0]{6};
    int bias_r_blu_mV = confSPECblu[0]{7};
    int bias_d_blu_mV = confSPECblu[0]{8};
    int capa_red = confSPECred[0]{0};
    int nb_rdouts_ramp_red = confSPECred[0]{1};
    int nb_rdouts_subramp_red = confSPECred[0]{2};
    int comp_mode_red = confSPECred[0]{3};
    int glitch_det_red = confSPECred[0]{4};
    int ramp_fit_alg_red = confSPECred[0]{5};
    int nb_raw_red = confSPECred[0]{6};
    int bias_r_red_mV = confSPECred[0]{7};
    int bias_d_red_mV = confSPECred[0]{8};
    int nb_up_down = confOBCP[0]{0};
    int grat_step_up = confOBCP[0]{1};
    int grat_step_dn = confOBCP[0]{2};
    int nb_SRC_OFF = confOBCP[0]{3};
    int nb_ramps_plateau = confOBCP[0]{4};
    int nb_CS1_CS2 = confOBCP[0]{5};
    int nb_grat_step_up = confOBCP[0]{6};
    int nb_grat_step_dn = confOBCP[0]{7};
    int grat_start_pos = confOBCP[0]{8};
    int grat_start_time = confOBCP[0]{9};
    int grat_def_pos = confOBCP[0]{10};
    int grat_def_time = confOBCP[0]{11};
    int chop_pos_SRC = confOBCP[0]{12};
    int chop_pos_REF1 = confOBCP[0]{13};
    int chop_pos_REF2 = confOBCP[0]{14};
    int chop_pos_CS1 = confOBCP[0]{15};
    int chop_pos_CS2 = confOBCP[0]{16};
    int chop_def = confOBCP[0]{17};
    int detector = confOBCP[0]{18};
    int filterPOS = confOBCP[0]{19};
    // Bias voltages (needed by SPEC_aot_prologue) are commanded in (double) volts
    double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
    double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
    double bias_r_red = double(bias_r_red_mV) / 1000.0;
    double bias_d_red = double(bias_d_red_mV) / 1000.0;
    if(verbose) {
        debug_print("confSPEC: capa_blu: " + capa_blu);
        debug_print("confSPEC: nb_rdouts_ramp_blu: " + nb_rdouts_ramp_blu);
        debug_print("confSPEC: nb_rdouts_subramp_blu: " + nb_rdouts_subramp_blu);
        debug_print("confSPEC: comp_mode_blu: " + comp_mode_blu);
        debug_print("confSPEC: glitch_det_blu: " + glitch_det_blu);
        debug_print("confSPEC: ramp_fit_alg_blu: " + ramp_fit_alg_blu);
        debug_print("confSPEC: nb_raw_blu: " + nb_raw_blu);
        debug_print("confSPEC: bias_r_blu_mV: " + bias_r_blu_mV);
        debug_print("confSPEC: bias_d_blu_mV: " + bias_d_blu_mV);
    }
    // Issue SPEC_aot_prologue if demanded
    if(doPROLOG) {
        totalDUREE = SPEC_aot_prologue(nb_rdouts_ramp_red,nb_rdouts_ramp_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,comp_mode_blu,comp_mode_red,nb_rdouts_subramp_blu,nb_rdouts_subramp_red,nb_raw_blu,nb_raw_red,glitch_det_red,ramp_fit_alg_red,filter,verbose);
    }
    // NOTE: Grating starts at grat_start_pos determined by SPEC_get_grat. At end of
    // SlewCal grating should park. Park position is generally grat_def_pos:
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // AOT_prologue is supposed to have left grating at park position
    grat_def_pos = grat_park;
    // NOTE for version 1.0 and later. Upon execution of SpecSlew, grating is
    //      indeed where SPEC_orbit_prologue left it (the default park position);
    //      this fact remains unchanged. What is new is that SpecSlew will leave
    //      the grating not at the default park position but already at the
    //      position needed by the 1st line that will be observed. There are two
    //      advantages:
    //      1- the new logic in the OBCP incurs in less grating movements when
    //         the OBCP is repeated within a NOD or the next raster point, and
    //      2- the detector will see the illumination corresponding to the line
    //         wavelength before the actual observation starts.
    // Observe now each key wavelength
    int nbKEY = length(grat_keyWAVE);
    {double,int,int,int,int}[] gratTuple = [{0.0,0,0,0,0}];
    for(int loopKEY = 0 .. nbKEY - 1) {
        //     We may perform the loop starting with high ORDER
        int keyWaveLoop1 = nbKEY - 1 - loopKEY;
        // or not....
        keyWaveLoop1 = loopKEY;
        //       
        //     Get grating start position (CAL is performeed with HI resolution)
        //     (frequency switch boolean is set to false)
        bool switching = false;
        // dirty trick to get extraConf bright or normal back!!!
        if(nb_rdouts_ramp_blu != 64) {
            string extraConf = "bright";
        } else {
            extraConf = "normal";
        }
        //        string extraConf = "normal";
        //      Seek K rows in CAL-U, i.e. key wavelength parameters	
        gratTuple[keyWaveLoop1] = SPEC_get_grat_info(keyWAVE[keyWaveLoop1],"KHI",switching,extraConf,orderSel,verbose);
        //      Issue now OBCP#35 for each of the given key wavelengths
        int order = gratTuple[keyWaveLoop1]{1};
        // grat_start_pos is grat_keyWAVE
        //        grat_start_pos = gratTuple[keyWaveLoop1]{2};
        grat_start_pos = grat_keyWAVE[keyWaveLoop1];
        int nb_grat_steps = gratTuple[keyWaveLoop1]{3};
        nb_grat_step_up = nb_grat_steps;
        nb_grat_step_dn = nb_grat_steps;
        int grat_step_up_fine = gratTuple[keyWaveLoop1]{4};
        int grat_step_dn_fine = -grat_step_up_fine;
        //
        // Read K-lines of table OBCP35params
        // add B if bright mode
        if(extraConf == "bright") {
            string key = "BK" + order;
        } else {
            key = "K" + order;
        }
        if(verbose) {
            debug_print("PacsSlewCal: key " + key);
        }
        string calU = "OBCP35params";
        nb_up_down = ilookup(calU,key,"nb_up_down");
        nb_CS1_CS2 = ilookup(calU,key,"nb_CS1_CS2");
        // SRC_OFF == 0;
        nb_SRC_OFF = 0;
        int chop_pos_OFF = chop_pos_REF2;
        nb_ramps_plateau = ilookup(calU,key,"nb_ramps_plateau");
        int grat_step_coarse = 0;
        //      Lookup chopper CS1 and CS2 positions
        calU = "CHOPPERCSparams";
        chop_pos_CS1 = ilookup(calU,"SPEC","pos_CS1");
        chop_pos_CS2 = ilookup(calU,"SPEC","pos_CS2");
        int nb_rdouts_ramp = nb_rdouts_ramp_red;
        //     Grating logic (OBCP is up/down ==> grating ends where it started)
        //     Leave the grating where it is, i.e. end-of-DMC value
        int new_grat_def_pos = grat_start_pos;
        //     But the last line should leave grating at frstLstGratPos
        if(keyWaveLoop1 == nbKEY - 1) {
            new_grat_def_pos = frstLstGratPos;
        }
        //     Number of steps to start position for current line
        int steps_start = grat_def_pos - grat_start_pos;
        int grat_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("OBCPcal:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + ";  time: " + grat_time);
        }
        //
        int steps_end = grat_start_pos - new_grat_def_pos;
        grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("OBCPcal:GratEnd from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
        }
        int[] dureeOBCP = OBCP_grat_line_scan_chop_3_cal(nb_up_down,nb_grat_step_up,grat_step_up_fine,nb_SRC_OFF,chop_pos_SRC,nb_ramps_plateau,chop_pos_OFF,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_dn_fine,detector,grat_start_pos,grat_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
        if(verbose) {
            debug_print("SlewCal performed grat_KeyWave: " + grat_keyWAVE[keyWaveLoop1] + " [mic] requires " + dureeOBCP[0] + " [sec]");
        }
        //     Update dureeCalKey
        dureeCalKey[keyWaveLoop1] = [0,0,0,0,0];
        for(int loop1 = 0 .. 4) {
            dureeCalKey[keyWaveLoop1][loop1] = dureeOBCP[loop1];
        }
        //     Prepare the grating to be ready for the next wavelength
        grat_def_pos = new_grat_def_pos;
    }
    // Add after the KeyWaves in dureeCalKey the duration from AOT_prologue
    dureeCalKey[nbKEY] = [0,0,0,0,0];
    dureeCalKey[nbKEY][4] = totalDUREE[4];
    if(verbose) {
        debug_print("End SlewCal with dureeCalKey: " + dureeCalKey);
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return dureeCalKey;
}

// $Id: 
// Purpose        : Obs to run the FPGA fixes memry dumps
//                 
//
// CUS author     : VD + HF
//
// Input arguments: see after module identification
//
// Return values: none
// N/A
//
// Comments      : only run it once
//
// History: 1.0 created
//          21-oct-2010 create
//
//
obs PacsEng_PacsFPGAMemoryDump {
    /* no need for inputs this Eng will only be done once!! */
}{
    int t_DPU_update = duration(PacsFPGAMemoryDump());
    // Add needed time to set/unset OBSID
    int tset = duration(PacsBbWriteOBSID($OBSID));
    int tunset = duration(PacsBbWriteEndID());
    int tp = t_DPU_update;
    // Issue PointReq
    int[] ts = no_pointing(true,tset,tunset,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            PacsBbWriteOBSID($OBSID);
        }
        if(state[0] == 3) {
            PacsFPGAMemoryDump();
        }
        if(state[0] == 5) {
            PacsBbWriteEndID();
        }
    }
}

//$Id$
//
// Purpose 
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//- Test of internal calibration recipes including different chopper
//  frequencies photometry including time constants for flux changes
//  (just between the 2 CSs)
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//                  
//                 
//
// TCL author    : TM
// TCL file      : TM
// CUS author    : TM
// Script file   : PHOT_cal_recipes_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version	 : 1.0
// History       : 0.1 27-apr-2005 DAC
//                 0.4 26-apr-2005 DAC Use PACS_spu_reset
//                 0.5  4-nov-2005 DAC Added 1 sec to the wait after DMC load (from 2 to 3 sec)
//                 0.6 11-apr-2007 update by TM (OBCPs, 40Hz, ....)
//		   1.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
procedure Pacs_Phot_cal_recipes {
}{
    // Register with environment
    // Start SPU
    int comp_mode_blu = 0;
    int comp_mode_red = 0;
    int nraw_blu = 0;
    int nraw_red = 0;
    //
    PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,true);
    //
    // Position the filter wheel at POS A
    //
    PHOT_fltw_move("POS A");
    //
    // Perform OBCP_chopped_photometry (128sec)
    //
    OBCP_chopped_photometry(0,0,599,0,0,1,4,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,159,0,0,1,15,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,79,0,0,1,30,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,39,0,0,1,60,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,19,0,0,1,120,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,9,0,0,1,240,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,4,0,0,1,240,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    // Position the filter wheel at POS B
    //
    PHOT_fltw_move("POS B");
    //
    OBCP_chopped_photometry(0,0,599,0,0,1,4,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,159,0,0,1,15,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,79,0,0,1,30,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,39,0,0,1,60,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,19,0,0,1,120,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,9,0,0,1,240,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    OBCP_chopped_photometry(0,0,4,0,0,1,240,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    //
    // Position the filter wheel at POS A
    PHOT_fltw_move("POS A");
    //
    // Stop SPU
    PHOT_spu_reset();
    //
    // Leave environment
}

// CVS comments  : $Id: PacsSpecSlewCal35_Flex.txt,v 1.13 2008/02/07 16:17:14 dcesarsk Exp $ 
// Purpose       : Invoke a PACS calibration OBCP during slew to source;
//                 leave PACS ready to start observations once in source
//
// CUS author    : PR adapted from DAC code for non Flex version
// Script file   : PacsSpecSlewCal35_Flex.txt 
//
// Input arguments
// Type                     Name          Description
// bool                     verbose       Debug_print or not 
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECblu   BLUE SPU parameters
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECred   RED  SPU parameters
// {int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int}[]  confOBCP      OBCP parameters
//  bool                    doPROLOG      Perform/don't AOT prologue
//  double []               keyWAVE       One or several key wavelengths
//  int                     filter        Where to move FltW (as order)
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per key line
//
// Description   : Perform AOT prologue and then OBCP #35, DMC Seq 19.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 1.0 12-Feb-2009 Creation, from PacsSpecSlewCal_Flex
// 		   1.1 07-May-2009 PR Match FSILT database: call alt. OBCP (with BBID 350)
//    		   1.2 23-Jul-2009 Possibility for initial_delay (transients observed in OD 64 at the start of the cal. blocks)
//		       		   + Position chopper on CS1 ahead of that initial_delay
//		   1.3 24-Jul-2009 Change call to OBCP 35 with BBID 350 for OBCP 35 with BBID 351 (PACS SPR 1860)
//                                                  29-Jul-2009 Update history mention SPRs PACS-1857 & PHS-1128 affecting this code
//
int[][] procedure PacsSpecSlewCal35_Flex {
    /* verbose debug print                          */
    bool verbose = false;
    /* SPEC parameters for BLU and RED              */
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{12,64,16,16,1,1,3,80,30}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{12,64,16,16,1,1,3,80,30}];
    /* OBCP parameters                               */
    {int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{1,16,133,1,-21200,1,21350,0,1,664}];
    /* Fixed, initial Delay for signal drifts, after pre-positioning the mechanisms [seconds] */
    int initial_delay = 30;
    /* Perform/don't AOT prologue                    */
    bool doPROLOG = true;
    /* One or several key wavelengths                */
    double[] waves = [60.0];
    /* Where to leave FltW (as order)                */
    string fltPOS = "POS A";
    /* User defined grating order                    */
    int order = 2;
}{
    // Pass the Initial Delay in Milliseconds (expected by the OBCP)
    initial_delay = initial_delay * 1000;
    // Position the chopper on CS1 before the initial_delay (for signal drifts)
    int choppos = ilookup("CHOPPERCSparams","SPEC","pos_CS1");
    debug_print("Chopper will be pre-positioned at" + choppos);
    // Array to collect OBCP times per line
    // NOTE: time variables in units of either number of ramps (SPEC) or
    // number of readouts (BOLO) or plain seconds. The calling program 
    // must convert, if applicable, this information into actual duration 
    // in true time units [seconds].
    // SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky), CAL source, 
    // and overheads (wait for something). Total duration is given by duree_num. 
    // If no error, this duration must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    int[][] dureeCalKey = [[0,0,0,0,0]];
    // Long sequence to "unpack" default values from tuples
    //
    // UNPACK confSPEC blu & red
    //
    int capa_blu = confSPECblu[0]{0};
    int nb_rdouts_ramp_blu = confSPECblu[0]{1};
    int nb_rdouts_subramp_blu = confSPECblu[0]{2};
    int comp_mode_blu = confSPECblu[0]{3};
    int glitch_det_blu = confSPECblu[0]{4};
    int ramp_fit_alg_blu = confSPECblu[0]{5};
    int nb_raw_blu = confSPECblu[0]{6};
    int bias_r_blu_mV = confSPECblu[0]{7};
    int bias_d_blu_mV = confSPECblu[0]{8};
    int capa_red = confSPECred[0]{0};
    int nb_rdouts_ramp_red = confSPECred[0]{1};
    int nb_rdouts_subramp_red = confSPECred[0]{2};
    int comp_mode_red = confSPECred[0]{3};
    int glitch_det_red = confSPECred[0]{4};
    int ramp_fit_alg_red = confSPECred[0]{5};
    int nb_raw_red = confSPECred[0]{6};
    int bias_r_red_mV = confSPECred[0]{7};
    int bias_d_red_mV = confSPECred[0]{8};
    //
    // UNPACK confOBCP
    //
    int nb_up_dn = confOBCP[0]{0};
    int nb_grat_steps = confOBCP[0]{1};
    int grat_step_up = confOBCP[0]{2};
    int nb_cycles_grat = confOBCP[0]{3};
    int chop_pos_CS1 = confOBCP[0]{4};
    int nb_ramps_grat_pos = confOBCP[0]{5};
    int chop_pos_CS2 = confOBCP[0]{6};
    int nb_cycles_cal = confOBCP[0]{7};
    int detector = confOBCP[0]{8};
    int chop_def = confOBCP[0]{9};
    // We will scan by decreasing grating angle, i.e. negative step size:
    // OBCP 19 P#11 
    int grat_step_dn = -grat_step_up;
    string order_str = "" + order;
    // PARAMETERS STILL TO BE CHECKED
    // double[] keyWAVE = [65.0];
    //string orderSel = "order"+order_str;
    // END PARAMETERS STILL TO BE CHECKED
    // Bias voltages (needed by SPEC_aot_prologue) are commanded in (double) volts
    double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
    double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
    double bias_r_red = double(bias_r_red_mV) / 1000.0;
    double bias_d_red = double(bias_d_red_mV) / 1000.0;
    if(verbose) {
        debug_print(" ");
        debug_print("confSPEC: capa_blu              " + capa_blu);
        debug_print("confSPEC: nb_rdouts_ramp_blu    " + nb_rdouts_ramp_blu);
        debug_print("confSPEC: nb_rdouts_subramp_blu " + nb_rdouts_subramp_blu);
        debug_print("confSPEC: comp_mode_blu         " + comp_mode_blu);
        debug_print("confSPEC: glitch_det_blu        " + glitch_det_blu);
        debug_print("confSPEC: ramp_fit_alg_blu      " + ramp_fit_alg_blu);
        debug_print("confSPEC: nb_raw_blu            " + nb_raw_blu);
        debug_print("confSPEC: bias_r_blu_mV         " + bias_r_blu_mV);
        debug_print("confSPEC: bias_d_blu_mV         " + bias_d_blu_mV);
        debug_print(" ");
        debug_print("confSPEC: capa_red              " + capa_red);
        debug_print("confSPEC: nb_rdouts_ramp_red    " + nb_rdouts_ramp_red);
        debug_print("confSPEC: nb_rdouts_subramp_red " + nb_rdouts_subramp_red);
        debug_print("confSPEC: comp_mode_red         " + comp_mode_red);
        debug_print("confSPEC: glitch_det_red        " + glitch_det_red);
        debug_print("confSPEC: ramp_fit_alg_blu      " + ramp_fit_alg_red);
        debug_print("confSPEC: nb_raw_red            " + nb_raw_red);
        debug_print("confSPEC: bias_r_red_mV         " + bias_r_red_mV);
        debug_print("confSPEC: bias_d_red_mV         " + bias_d_red_mV);
        debug_print(" ");
        debug_print("confOBCP: P#1  nb_up_dn         " + nb_up_dn);
        debug_print("confOBCP: P#2  nb_grat_steps    " + nb_grat_steps);
        debug_print("confOBCP: P#3  grat_step_up     " + grat_step_up);
        debug_print("confOBCP: P#11 grat_step_dn     " + grat_step_dn);
        debug_print("confOBCP: P#4  nb_cycles_grat   " + nb_cycles_grat);
        debug_print("confOBCP: P#5  chop_pos_CS1     " + chop_pos_CS1);
        debug_print("confOBCP: P#7  chop_pos_CS2     " + chop_pos_CS2);
        debug_print("confOBCP: P#6  nb_ramps_grat_pos" + nb_ramps_grat_pos);
        debug_print("confOBCP: P#8  nb_cycles_cal    " + nb_cycles_cal);
        debug_print("confOBCP: detector              " + detector);
        debug_print("confOBCP: chop_def              " + chop_def);
    }
    // Issue SPEC_aot_prologue if demanded
    if(doPROLOG) {
        int filter = 2;
        //aotprologue: string[] fltPOS = ["N/A","NoFilter","POS B","POS A"];
        if(fltPOS == "POS A") {
            filter = 3;
        }
        totalDUREE = SPEC_aot_prologue(nb_rdouts_ramp_red,nb_rdouts_ramp_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,comp_mode_blu,comp_mode_red,nb_rdouts_subramp_blu,nb_rdouts_subramp_red,nb_raw_blu,nb_raw_red,glitch_det_red,ramp_fit_alg_red,filter,verbose);
    }
    // NOTE: Grating starts at grat_start_pos determined by SPEC_get_grat. At end of
    // SlewCal grating should park. Park position is generally grat_def_pos:
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // AOT_prologue is supposed to have left grating at park position
    int grat_def_pos = grat_park;
    // NOTE for version 1.0 and later. Upon execution of SpecSlew, grating is
    //      indeed where SPEC_orbit_prologue left it (the default park position);
    //      this fact remains unchanged. What is new is that SpecSlew will leave
    //      the grating not at the default park position but already at the
    //      position needed by the 1st line that will be observed. There are two
    //      advantages:
    //      1- the new logic in the OBCP incurs in less grating movements when
    //         the OBCP is repeated within a NOD or the next raster point, and
    //      2- the detector will see the illumination corresponding to the line
    //         wavelength before the actual observation starts.
    // Observe now each key wavelength
    int nbWaves = length(waves);
    for(int loopWaves = 0 .. nbWaves - 1) {
        Pacs_DMC_MOVE_CHOP_ABS_RAW(choppos);
        delay(1);
        //
        // RSRF PCSS
        // R1  :  32000 - 1056000
        // B2A : 620000 - 1056000
        // B2B :  32000 - 1056000
        // B3A :  32000 -  670000
        //
        //     Get grating start position (CAL is performeed with HI resolution)
        string waveCalTable = slookup("SPEC_BAND_params",order_str,"CAL_FILE");
        double wave_grat_pos = interpolate(waveCalTable,"grat_pos",waves[loopWaves]);
        int grat_start_pos = iround(wave_grat_pos + double(grat_step_up) * double(nb_grat_steps) / 2.0);
        //     Number of steps to start position for current line
        int steps_start = grat_def_pos - grat_start_pos;
        int move_time = SPEC_grat_time(steps_start);
        int grat_time = move_time + initial_delay;
        if(verbose) {
            debug_print("OBCPcal:Initial Delay + GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_time);
        }
        //
        //     After the OBCP, leave the grating where it is, i.e. end-of-DMC value
        //     But the last line should leave grating at default from CALU
        grat_def_pos = grat_start_pos;
        if(loopWaves == nbWaves - 1) {
            grat_def_pos = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
        }
        //
        int steps_end = grat_start_pos - grat_def_pos;
        int grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print(" ");
            debug_print("OBCPcal:GratEnd from/to: " + grat_start_pos + "/" + grat_def_pos + "; time: " + grat_def_time);
            debug_print(" ");
            debug_print("confOBCP: P#3  grat_step_up  " + grat_step_up);
            debug_print("confOBCP: P#11 grat_step_dn  " + grat_step_dn);
            debug_print("confOBCP: wavelength -> grat pos " + waves[loopWaves] + " " + wave_grat_pos);
            debug_print("confOBCP: grat_start_pos         " + grat_start_pos);
        }
        //       int[] dureeOBCP = OBCP_grat_line_scan_chop_3_cal_unfckdup_yet(nb_up_dn,nb_grat_steps,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,nb_cycles_cal,chop_pos_CS1,chop_pos_CS2,grat_step_up,grat_step_dn,detector,grat_start_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
        int[] dureeOBCP = OBCP_grat_line_scan_chop_3_cal_unfckdup_yet(nb_up_dn,nb_grat_steps,grat_step_up,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,nb_cycles_cal,chop_pos_CS1,chop_pos_CS2,grat_step_dn,detector,grat_start_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
        if(verbose) {
            debug_print("SlewCal performed wavelength: " + waves[loopWaves] + " [mic] requires " + dureeOBCP[0] + " [sec]");
        }
        //     Update dureeCalKey
        dureeCalKey[loopWaves] = [0,0,0,0,0];
        for(int loop1 = 0 .. 4) {
            dureeCalKey[loopWaves][loop1] = dureeOBCP[loop1];
        }
    }
    // Add after the KeyWaves in dureeCalKey the duration from AOT_prologue
    dureeCalKey[nbWaves] = [0,0,0,0,0];
    dureeCalKey[nbWaves][4] = totalDUREE[4];
    if(verbose) {
        debug_print("End SlewCal with dureeCalKey: " + dureeCalKey);
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return dureeCalKey;
}

// File          : PACS_Phot_SFT_Cooler_Warm.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Performing a cooler short functional test at room
//                 temperature
//
// Author        : T. Mueller
//
// Arguments     : none
//
// Description   : Question:
//                 How can we check under warm conditions (room
//                 temperature) the functioning of the cooler?
//                 Something like commanding some heater currents
//                 (HSE, SP, HSP) for a very short time period?
//                 Answer:
//                 Compared to Eric's previous proposition, he
//                 recommend now to be on the safe side and to use
//                 values as following:
// 
//                  Set SP to 1mA
//                  See HK to check if the link is valid
//                  Reset SP
//                  Set HSE to 30uA
//                  See HK to check if the link is valid
//                  Reset HSE
//                  Set HSP to 30uA
//                  See HK to check if the link is valid
//                  Reset HSP
//
// Comments      :  Based on Email by Koryo Okumura 14/Sep/2005
//
// Duration      :  6 min
// Version       :  1.2
// History       :  1.0 / 27-Nov-2005 initial version by TM
//                  1.1    7-mar-2006 SEND_COMMAND_TO_BOLC renamed
//                  1.2   22-apr-2007 AF 21 handling
//
procedure PACS_Phot_SFT_Cooler_Warm {
}{
    // disable AF 21 (to check if the absolute value of the HSP current is below 2*10^(-5)A)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_SP1","DISABLE");
    //-------------------------------
    // Set HK list to PHOT
    //-------------------------------
    // DPU_SET_HK_LIST (PHOT HK_PACKT_ID=2;
    //           SPU_ARRAY: 1 for both channels, 2 for blue chan, 3: for red chan)
    // PC003380 "DPU_SET_HK_LIST" SET THE PREDIFINED LIST OF HK VALUES
    //                            FOR THE HK PACKET
    //         PP005380 "HK_PACKT_ID"
    //         PP025380 "SPU_ARRAY"
    // tcsend PC003380 {PP005380 2} {PP025380 1}
    // waittime 0.5
    Pacs_DPU_SET_HK_LIST("PHOT","BOTH Array");
    //----------------------------------------------------------------
    // Short function test of cooler at room temperature
    //----------------------------------------------------------------
    // Set SP heater current to  to 0.001 amperes (1mA)
    // P 07 01 005D
    // tcsend PC103420 {PP071420 0x0701005D LO}; waittime 0.5
    // waittime 60.0   
    int operand = 0x701005d;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(60);
    // Set SP heater current to  to 0mA
    // P 07 01 0000
    // tcsend PC103420 {PP071420 0x07010000 LO}; waittime 0.5
    // waittime 60.0
    operand = 0x7010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(60);
    // Set HSE heater current to  to 0.00003 amperes (0.03mA=30uA)
    // P 07 03 004C
    // tcsend PC103420 {PP071420 0x0703004C LO}; waittime 0.5
    // waittime 60.0
    operand = 0x703004c;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(60);
    // Set HSE heater current to  to 0mA
    // P 07 03 0000
    // tcsend PC103420 {PP071420 0x07030000 LO}; waittime 0.5
    // waittime 60.0
    operand = 0x7030000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(60);
    // Set HSP heater current to  to 0.00003 amperes (0.03mA=30uA)
    // P 07 02 004C
    // tcsend PC103420 {PP071420 0x0702004C LO}; waittime 0.5
    // waittime 60.0
    operand = 0x702004c;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(60);
    // Set HSP heater current to  to 0mA
    // P 07 02 0000
    // tcsend PC103420 {PP071420 0x07020000 LO}; waittime 0.5
    // waittime 60.0
    operand = 0x7020000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(60);
    // enable AF 21 (to check if the absolute value of the HSP current is below 2*10^(-5)A)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_SP1","ENABLE");
    //-----------------------
    // end of procedure
    //-----------------------
}

// CVS comments  : $Id: 
// Script file   : PacsLineSpecEstimatorOBCP35.txt 
// Purpose       : Estimate several PACS parameters for each spectral
//                 line specified by the HSPOT user
//
// CUS author    : DAC
//
// Input arguments
// type           name          Description
// tuple          lines         spectral line info from HSPOT
// tuple          waveTuple     grating info associated to "lines"
// tuple          paramsSPECdef confSPECblu & confSPECred & confOBCP
// bool           noddingSel    nodding demanded?
//
// Return values
// Type             Description
// tuple            Derived values for paramsSPECdef
//
// Description   : Fill the PACS state descriptors confSPECx & confOBCP, per
// HSPOT defined wavelength, with values obtained from several CAL-U files.
// This procedure is called once per spectral line. For each line - identified
// here by its order since this is the index into the durations CAL-U file -
// the user gives a desired observing time. The OBCP35params table lists the
// minimum duration per order, without nodding. If nodding is requested, the
// tabulated duration is increased by a factor two; this new duration becomes
// the "observing quantum". Any longer time is accomodated by increasing the
// number of nods. If no nodding is desired, a longer OBS time is accomodated
// by increasing the number of up/down cycles. ABBA chopper pattern
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-may-2005 DAC OBCP27
// 		 : 1.0 11-mar-2009 VD created OBCP35
// 		 : 1.2 20-jul-2009 introduce NEW bright mode in OBCP35params
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsLineSpecEstimatorOBCP35 {
    {string,double,int,double,double,double,string,string} lines = {"NONE",60.2,0,0.0,0.0,0.0,"bla","bla"}; // linesTuple HSPOT
    {double,int,int,int,int} waveTuple = {0.0,0,0,0,0}; // waveTuple          
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; // Default values
    bool noddingSel = false; // Nodding requested?
    bool faintLines = true; // Fast OBCP if false 
    bool verbose = false; // print debug information
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    //////////////// Logic to obtain desired OBS time ///////////////////////////
    //
    // ORDER of the current line
    int order = waveTuple{1};
    double waveLEN = waveTuple{0};
    // User desired repetition factor for current line
    int userREPfactor = lines{2};
    // Get the "quantum" OBS time for the current order. U-CAL time doubles if 
    // nodding is allowed
    int nodFactor = 1;
    if(noddingSel) {
        nodFactor = 2;
        int nb_nods = 1;
    } else {
        nb_nods = 0;
    }
    // Grating info pertaining to the current wavelength is in waveTuple
    int nb_grat_step_up = waveTuple{3};
    int nb_grat_step_dn = waveTuple{3};
    int grat_step_up = waveTuple{4};
    int grat_step_dn = -grat_step_up;
    int grat_start_pos = waveTuple{2};
    // Get "duration related" parameters from OBCP35params U-CAL table
    string calNAME = "OBCP35params";
    // The acces key is the grating order
    // if faintline is false then NEW Keys
    if(!faintLines) {
        string key = "B" + order;
    } else {
        key = "" + order;
    }
    if(verbose) {
        debug_print("OBCP35params key: " + key);
    }
    // There is a row per order; it lists main OBCP parameters
    //Now user input int nb_up_down = ilookup(calNAME,key,"nb_up_down");
    int nb_up_down = userREPfactor;
    int nb_SRC_OFF = ilookup(calNAME,key,"nb_SRC_OFF");
    int nb_ramps_plateau = ilookup(calNAME,key,"nb_ramps_plateau");
    int nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    // Estimate the OBS time for this rangeInfo; estimation is for ONE nod only.
    int nb_rdouts_ramp = confSPECred{1};
    int[] dureeOBCP35 = PacsDureeOBCP35(nb_up_down,nb_grat_step_up,nb_ramps_plateau,nb_CS1_CS2,nb_SRC_OFF,nb_rdouts_ramp);
    // Use SRC/REF time alone (used to be total duration)
    int quantumOBStime = nodFactor * (dureeOBCP35[1] + dureeOBCP35[2]);
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + waveLEN + " [&micro;m] with line repeated " + userREPfactor + " time(s)</p>";
    lineCnt = lineCnt + 1;
    // This is complete fantasy; just to check the code
    //============== React on LINE/CONT fluxes ========================
    // Line and continuum flux from HSPOT
    double lineFLUX = lines{3};
    double contFLUX = lines{4};
    // next LINES are obsolete
    // Low flux use large integrating capacitor
    //    int capa_red = 0;
    //   int capa_blu = 0;
    //    if(lineFLUX <= 400.0) {
    //        capa_red = 4;
    //        capa_blu = 8;
    //    }
    //    if(lineFLUX <= 100.0) {
    //        capa_red = 12;
    //        capa_blu = 4;
    //    }
    // Pack information into proper tuples
    confOBCP{0} = nb_up_down;
    confOBCP{1} = grat_step_up;
    confOBCP{2} = grat_step_dn;
    confOBCP{3} = nb_SRC_OFF;
    confOBCP{4} = nb_ramps_plateau;
    confOBCP{5} = nb_CS1_CS2;
    confOBCP{6} = nb_grat_step_up;
    confOBCP{7} = nb_grat_step_dn;
    confOBCP{8} = grat_start_pos;
    //    confOBCP { 9}  =   grat_start_time  ;
    //    confOBCP {10}  =   grat_def_pos     ;
    //    confOBCP {11}  =   grat_def_time    ;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    //  confSPECred{0} = capa_red;
    //   confSPECred{ 1} =  nb_rdouts_ramp_red;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    //int comp_mode_red = 16;
    //confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    // confSPECblu{0} = capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts_ramp_blu;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    //int comp_mode_blu = 16;
    //confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    string msgLabel = "Observing time for " + lines{0};
    PacsMessageCenter(msgLabel,lineCnt,msgLine);
    // Debug info
    if(verbose) {
        debug_print("EstimatorOBCP35 duration*nod: " + quantumOBStime);
    }
    int aux3 = 0;

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,nb_up_down,quantumOBStime,aux3}};
}

// copy of SPEC_CRE_setup but without heater setup
// History : 27-02-2007 BV & PR First version
//              08-04-2009 PR comment 3 delay(1) statements to fasten the process (for Pacs_Spec_GeGa_Loop_Comm)
//              BV 27-07-2009 SPR 1798 corrected biases
procedure SPEC_CRE_No_Heater_setup {
    int ramp_len_red = 64; // Red  ramp length
    int ramp_len_blu = 64; // Blue ramp length
    double bias_d_red = 0.042 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_red = 0.01 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.1 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_r_blu = 0.01 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    int capa_red = 0; // Capacitor red  (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_blu = 0; // Capacitor blue (0=100fF,4=400fF,8=0.2pf,12=1pF)
}{
    // Red  CRE register (capa_red=0)
    int cre_ctrl_red = 386;
    // Blue CRE register (capa_blu=0)
    int cre_ctrl_blu = 386;
    // Blue CRE register (capa_blu=0)
    // Write the blue spectrometer parameters
    int blu_cre_ctrl = capa_blu + cre_ctrl_blu;
    // Bias values have been given in ENG units. Have to convert to RAW in
    // order to compute check-sums
    int i_blu_bias_r = convert_to_raw("pacs_DMC_BIAS_R",bias_r_blu);
    int i_blu_bias_d = convert_to_raw("pacs_DMC_BIAS_D",bias_d_blu);
    int clks_rdout = 32;
    int simul_reg = 60000;
    int[] aux = [clks_rdout,ramp_len_blu,blu_cre_ctrl,i_blu_bias_r,i_blu_bias_d,simul_reg];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_B_SPEC_PAR(clks_rdout,ramp_len_blu,blu_cre_ctrl,bias_r_blu,bias_d_blu,simul_reg,check_sum);
    // Same for RED parameters
    int red_cre_ctrl = capa_red + cre_ctrl_red;
    int i_bias_r_red = convert_to_raw("pacs_DMC_BIAS_R",bias_r_red);
    int i_bias_d_red = convert_to_raw("pacs_DMC_BIAS_D",bias_d_red);
    aux = [clks_rdout,ramp_len_red,red_cre_ctrl,i_bias_r_red,i_bias_d_red,simul_reg];
    check_sum = checksum("int",aux);
    Pacs_DMC_WRT_R_SPEC_PAR(clks_rdout,ramp_len_red,red_cre_ctrl,bias_r_red,bias_d_red,simul_reg,check_sum);
    // Send complete parameters table to both DECS
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    // Switchon and set blue detector heater
    // Pacs_DMC_SWON_BD_HEATER();
    // delay(1);
    // Pacs_DMC_SET_B_SPEC_HEAT_C(blue_heat_current);
    // DMC_SYNCHRONIZE_ON_DET(1)
    Pacs_DMC_SYNCHRONIZE_ON_DET(1);
    //delay(1);
    // DMC_WRT_B_DEC_REC_OPT" WRITE THE BLUE DEC RECEIVER OPTIONS
    {int}[] argTuple = [{0}];
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,0x84c0);
    //delay(1);
    // DMC_WRT_R_DEC_REC_OPT" WRITE THE RED DEC RECEIVER OPTIONS
    argTuple = [{0}];
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,0x84c0);
    //delay(1);
    // DMC_VAL_SCI_DATA_BOTH" VALIDATE SCIENCE DATA FROM BOTH CHANNELS
    Pacs_DMC_VAL_SCI_DATA_BOTH();
    //delay(1);
}

// Mission phase : Space
//
// Purpose       : OBCP for chopped photometry
//                 using one blue filter after the other
//
// CUS author    : TM/KO
// Script file   : Pacs_OBCP_chopped_photometry2.txt 
//
// Description   : Execute OBCP for chopped photometry for 2 filters
//                  
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : Modified Pacs_OBCP_chopped_photometry
// 
// Version      0.1
// History      0.1 10-Jul-2008 KO : First version 
//
procedure Pacs_OBCP_chopped_photometry2 {
    int nb_SRC_REF = 30; // p01 Number of observations in OBS loop
    int chop_pos_SRC = 664; // p02 Chopper position for SRCE
    int nb_rdouts_plateau = 15; // p03 Number of readouts per chopper position 
    int chop_pos_REF1 = -21350; // p04 Chopper position for BKG1
    int chop_pos_REF2 = 21200; // p05 Chopper position for BB2
    int nb_cycles_obs_cal = 1; // p06 Number of obs/cal cycles
    int nb_CS1_CS2 = 0; // p07 Number of observations in CAL loop
    int chop_pos_CS1 = 0; // p08 Chopper position for CS1
    int chop_pos_CS2 = 0; // p09 Chopper position for CS2
    int comp_mode_blu = 0; // Compression mode BLUE channel
    int comp_mode_red = 0; // Compression mode RED channel
    int chop_def = 664; // Chopper default position
    string leaveFilterAt = "blue70um" in ["blue70um","green100um"]; // Leave with this filter
    bool initSPU = false; // Start SPU first
    string gain = "LOW" in ["LOW","HIGH"]; // Gain
    int nraw_blu = 3; // Number of raw channels transmitted in the blue SPU
    int nraw_red = 3; // Number of raw channels transmitted in the red SPU
    bool stopSPU = false; // Stop SPU at the end
}{
    if(initSPU) {
        // Register with environment
        // Start SPU
        PHOT_spu_gain_setup(gain,comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,true);
    }
    //
    // Position the filter wheel at POS A
    //
    PHOT_fltw_move("POS A");
    //
    // Perform OBCP_chopped_photometry with default parameters
    debug_print("Start OBCP_chopped_photometry with filter A");
    int[] duree = OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
    delay(2);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    //
    // Position the filter wheel at POS B and repeat everything
    //
    PHOT_fltw_move("POS B");
    // Perform OBCP_chopped_photometry with default parameters
    debug_print("Start OBCP_chopped_photometry with filter B");
    duree = OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rdouts_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
    delay(2);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    if(leaveFilterAt == "green100um") {
        //
        // Position the filter wheel at POS A
        //
        PHOT_fltw_move("POS A");
    }
    if(stopSPU) {
        //
        // Stop SPU 
        //
        PACS_spu_reset();
    }
    sync();
}

// CVS comments  : $Id: PacsLineSpecEstimatorOBCP32.txt,v 1.1 2007/10/25 12:16:47 dcesarsk Exp $ 
// Purpose       : Estimate several PACS parameters for each spectral
//                 line specified by the HSPOT user
//
// CUS author    : DAC
//
// Input arguments
// type           name            Description
// tuple          lines           spectral line info from HSPOT
// tuple          waveTuple       grating info associated to "lines"
// tuple          paramsSPECdef   confSPECblu & confSPECred & confOBCP
//
// Return values
// Type             Description
// tuple            Derived values for paramsSPECdef
//
// Description   : Fill the PACS state descriptors confSPECx & confOBCP, per
//                 HSPOT defined wavelength, with values obtained from
//                 OBCP32params (a CAL-U file). This procedure is called once 
//                 per spectral line. The repFactor is implemented as the
//                 number of nb_obs_cal parameter in OBCP freq switch.
//
// Dependencies  : 
//
// Preconditions :
//
// Comments      : Several confOBCP elements differ from non switched OBCPs
//                 Code keeps old confOBCP commented out for reference.
//                 NOTE.Several confOBCP elements are redefined here!!
// 
// History       : 0.1 18-oct-2007 DAC Based on PacsLineSpecEstimatorOBCP22
//                 0.2 25-mar-2009 DAC Removed references to "React on flux"
//                 1.0 26-mar-2009 DAC Adapted for "ABBA" line switch: added jumpREF3, jumpREF4 to
//                                 OBCP32params; renamed all jumpREFx to paramX as per DMC
//                                 description.
//                 2.0  3-jun-2009 DAC This version geared to latest OBCP32
//    
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsLineSpecEstimatorOBCP32 {
    {string,double,int,double,double,double,string,string} lines = {"NONE",60.2,1,0.0,0.0,0.0,"bla","bla"}; // linesTuple HSPOT
    {double,int,int,int,int} waveTuple = {100.0,1,500000,0,0}; // waveTuple          
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; // Default values
    bool verbose = true; // print debug information
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    // ORDER of the current line
    int order = waveTuple{1};
    double waveLEN = waveTuple{0};
    // User desired repetition factor for current line
    int userREPfactor = lines{2};
    // Get the "quantum" OBS time for the current order.
    // Grating info pertaining to the current wavelength is in waveTuple
    int grat_pos_LINE = waveTuple{2};
    // Get "duration" and switch parameters from OBCP22params U-CAL table
    // There is a row per order; it lists main OBCP parameters
    string calNAME = "OBCP32params";
    // The acces key is the grating order
    // Grab OBCP parameters from CALU file
    string key = "" + order;
    int nb_ramps_grat = ilookup(calNAME,key,"P6ramps");
    int nb_up_dn = ilookup(calNAME,key,"P1UpDn");
    int ditherCount = ilookup(calNAME,key,"P2shifts");
    int ditherSize = ilookup(calNAME,key,"P3dither");
    int jumpAtoB = ilookup(calNAME,key,"P7move");
    int nbABBA = ilookup(calNAME,key,"P4ABBA");
    // NOTE: nb_up_dn above is multiplied by userREPfactor
    nb_up_dn = nb_up_dn * userREPfactor;
    // Still to compute offline: offset to grat_pos_LINE so line is centered at 1/2
    // dithering cycle
    int offLine = 0;
    int grat_pos_LINEoff = grat_pos_LINE + offLine;
    if(verbose) {
        debug_print("Estim.OBCP32:gratLINE/graLINE+offset: " + grat_pos_LINE + "/" + grat_pos_LINEoff);
    }
    // Estimate the OBS time for this rangeInfo; estimation is for ONE nod only.
    // Get nb_rdouts_ramp from confSPECred
    int nbRdOutsRamp = confSPECred{1};
    int[] dureeOBCP32 = PacsDureeOBCP32(ditherCount,nb_up_dn,nbABBA,nb_ramps_grat,nbRdOutsRamp);
    // Use SRC/REF duration to compute quantumOBStime
    int quantumOBStime = dureeOBCP32[1] + dureeOBCP32[2];
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + waveLEN + " [&micro;m] with line repeated " + userREPfactor + " time(s)</p>";
    lineCnt = lineCnt + 1;
    if(verbose) {
        debug_print("Estim.OBCP32:jumpAtoB/gratLINE/nbABBA/ditherSize: " + jumpAtoB + "/" + grat_pos_LINEoff + "/" + nbABBA + "/" + ditherSize);
    }
    // Pack information into proper tuples
    // confOBCP { 0}  =   nb_up_down      ;
    // confOBCP { 0}  =   nb_obs_cal       ;
    confOBCP{0} = nb_up_dn;
    // confOBCP { 1}  =   grat_step_up     ;
    confOBCP{1} = jumpAtoB;
    // confOBCP { 2}  =   grat_step_dn     ;
    confOBCP{2} = nbABBA;
    // confOBCP { 3}  =   nb_SRC_OFF       ;
    // confOBCP { 3}  =   nb_SRC           ;
    confOBCP{4} = nb_ramps_grat;
    // confOBCP { 5}  =   nb_CS1           ;
    // confOBCP { 6}  =   nb_grat_step_up  ;
    // confOBCP { 6}  =   nb_CS2           ;
    // confOBCP { 7}  =   nb_grat_step_dn  ;
    confOBCP{7} = ditherCount;
    // confOBCP { 8}  =   grat_start_pos   ;
    confOBCP{8} = grat_pos_LINEoff;
    //    confOBCP { 9}  =   grat_start_time  ;
    confOBCP{9} = ditherSize;
    //    confOBCP {10}  =   grat_def_pos     ;
    //    confOBCP {11}  =   grat_def_time    ;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    //   confSPECred{0} = capa_red;
    //   confSPECred{ 1} =  nb_rdouts_ramp_red;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    // int comp_mode_red = 16;
    //   confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    //   confSPECblu{0} = capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts_ramp_blu;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    // int comp_mode_blu = 16;
    //   confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    string msgLabel = "Observing time for " + lines{0};
    PacsMessageCenter(msgLabel,lineCnt,msgLine);
    int nb_nods = 0;
    int aux3 = 0;

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,ditherCount,quantumOBStime,aux3}};
}

// $Id: PacsEng_PHOT_orbit_prologue.txt,v 1.8 2008/11/12 11:40:20 vanessad Exp $
// Purpose        : Bring PACS from switched off condition to standby
//                  for PHOT observations
//
// CUS author     : Composed from various ILT modules
//
// Input arguments: see after module identification
//
// Return values
// N/A
//
// Comments      :
//
// History: 
// 0.1  25-jun-2007  Created from ILT modules
// 0.2   9-aug-2007  Conformed to JonBr's mail (07/26/07)
// 1.0  21-aug-2007  Renamed from PACS_PHOT_orbit_prologue
//                                Use new "no_pointing" pointing request and
//                                StateMachine logic
// 1.1 20-may-2008  KO, Debugged for the pointing timing logic
// 1.2 24-jun-2008 KO, calUfile, temp_CS1 and temp_CS2 put in the argument
// 1.3 25-jun-2008 KO, CSs stabilisation time tSET put in the argument and the default calUfile changed to ILT
// 1.4 11-nov-2008 VD&KO&TM tSet chnaged to 2100s to allow for stabilisation
// 1.5 12-nov-2008 KO gotoDirect option added
// 1.6 10-apr-2009 KO VRL and 40Hz option added during the stabilization waiting time
// 1.7 04-may-2009 KO,NB choise corrected to choice!!!
// 1.8 11-jun-2009 KO Default choice is set to justWait
//
obs PacsEng_PHOT_orbit_prologue {
    string calUfile = "BOLObias_ILT_standard_low"; // Bias table
    double set_CS1 = 48.0; // CS1 settings (ohms)
    double set_CS2 = 58.0; // CS2 settings (ohms)
    int waitTime = 2100; // CSs stabilisation time in seconds > 200
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
    string choice = "justWait" in ["VRL","40Hz","justWait"]; // What to do during stabilization
    string waitBias = "BOLObias_standard_high"; // Bias used during CSs stabilization
}{
    // Settling time for CS
    string fltPOS = "POS A";
    bool execute = true;
    // Initial hold
    int tih = imax(1,duration(WriteOBSID($OBSID)));
    // Final hold
    int tfh = imax(1,duration(WriteEndID()));
    // Duration of "stable" pointing
    int tp = duration(PHOT_setup(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect));
    // Wait for CS to stabilize
    if(choice == "VRL") {
        // Vrl measurement during the stabilization
        tp = tp + duration(Phot_lowFreq_Vrl_filler(waitTime - 200,waitBias,calUfile,gotoDirect));
    } else {
        if(choice == "40Hz") {
            // sky measurement at 40Hz during the stabilization
            tp = tp + duration(Phot_SPU40Hz_filler(waitTime - 200,waitBias,calUfile,gotoDirect));
        } else {
            tp = tp + waitTime;
        }
    }
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //     Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //     Call the PHOT setup script
            PHOT_setup(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect);
            //     Wait for CS to stabilize
            if(choice == "VRL") {
                // Vrl measurement during the stabilization
                Phot_lowFreq_Vrl_filler(waitTime - 200,waitBias,calUfile,gotoDirect);
            } else {
                if(choice == "40Hz") {
                    // sky measurement at 40Hz during the stabilization
                    Phot_SPU40Hz_filler(waitTime - 200,waitBias,calUfile,gotoDirect);
                } else {
                    delay(waitTime);
                }
            }
        }
        if(state[0] == 5) {
            //     Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// Mission phase : Routine Phase
//
// Purpose : PCD req.1.1.10 Explore the time constant after flux change for
//                          a flux levels using a CS and the background
//
// Author : Koryo Okumura
//
// Version : Fri Jul 02 14:41:47 EDT 2010
//
// CUS script : procedure RPPhot_bandpassDirect
//
// Argument :
//   string biasTable = "BOLObias_orbit_standard" : Bias table file name containing the initial values
//   string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
//   int sideField = 7134 : Chopper angle for the FOV next to BB2
//   int chop_pos_CS2 = 21196 : Chopper angle for BB2
//   string biasChoice = "Nominal" in ["Low","Nominal","High"]; // Detector bias setting
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description :
//   + All the biases are set group by group
//     except for VH, VL, VRL and VHBLIND
//   + Loop over 7 PACS chopper frequencies
//   +   Loop over 3 different biases (set group by group)
//   + The 4 biases are set to a safe value for caution
//   Signal plateau length provided by PACS chopper movement : [40, 2, 3, 4, 6, 8, 16] readouts
//
// Dependencies : Previously obtaind data at high gain (PCD req.1.1.1bis)
//
// Comments : generated by IA script : cus_RP_bandpass()
// Comments : This implements SCR:PACS-2841
//
procedure RPPhot_bandpassDirect {
    string biasTable = "BOLObias_orbit_standard"; // Bias table file name containing the initial values
    string gain = "LOW" in ["LOW","HIGH"]; // gain used during the measurements
    int sideField = 7134; // Chopper angle for the FOV next to BB2
    int chop_pos_CS2 = 21196; // Chopper angle for BB2
    string biasChoice = "Nominal" in ["Low","Nominal","High"]; // Detector bias setting
}{
    //
    //**********************************************
    // Flux is 0.9pW on the bleu
    //     and 3.5pW on the red detector
    //**********************************************
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    PHOT_fltw_move("POS A");
    //
    //*******************************
    // Bias setting of the detectors
    //*******************************
    //
    PHOT_change_biases(biasTable,"DIRECT",gain);
    //
    // Set the PACS chopper at the central position
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //************************
    // Set DPU for Burst mode
    //************************
    Pacs_DPU_SET_BUS_LIST("ENABLE");
    //
    // Set the bias according to the choice given in the argument
    if(biasChoice == "Low") {
        //
        //***********************************************************
        // Low bias : (Vh-Vl)bleu = 1.8 volts (Vh-Vl)rouge = 1.4 volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 1.699977366109517 volts)
        Pacs_BOLC_SET_VH_G1(1.699977366109517);
        // Set group 1 bol bias 02 (VL) to -0.10002263389048316 volts)
        Pacs_BOLC_SET_VL_G1(-0.10002263389048316);
        // Set group 1 bol bias 03 (VRL) to 0.5227638720140898 volts)
        Pacs_BOLC_SET_VRL_G1(0.5227638720140898);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0706697887658105 volts)
        Pacs_BOLC_SET_VH_BLIND_G1(2.0706697887658105);
        // Set group 2 bol bias 01 (VH) to 1.694322724447177 volts)
        Pacs_BOLC_SET_VH_G2(1.694322724447177);
        // Set group 2 bol bias 02 (VL) to -0.10567727555282314 volts)
        Pacs_BOLC_SET_VL_G2(-0.10567727555282314);
        // Set group 2 bol bias 03 (VRL) to 0.5251089977098412 volts)
        Pacs_BOLC_SET_VRL_G2(0.5251089977098412);
        // Set group 2 bol bias 20 (VH_BLIND) to 2.0709826344743063 volts)
        Pacs_BOLC_SET_VH_BLIND_G2(2.0709826344743063);
        // Set group 3 bol bias 01 (VH) to 1.6890436951935621 volts)
        Pacs_BOLC_SET_VH_G3(1.6890436951935621);
        // Set group 3 bol bias 02 (VL) to -0.11095630480643803 volts)
        Pacs_BOLC_SET_VL_G3(-0.11095630480643803);
        // Set group 3 bol bias 03 (VRL) to 0.5200220090565421 volts)
        Pacs_BOLC_SET_VRL_G3(0.5200220090565421);
        // Set group 3 bol bias 20 (VH_BLIND) to 2.0708593494137775 volts)
        Pacs_BOLC_SET_VH_BLIND_G3(2.0708593494137775);
        // Set group 4 bol bias 01 (VH) to 1.6842510121883625 volts)
        Pacs_BOLC_SET_VH_G4(1.6842510121883625);
        // Set group 4 bol bias 02 (VL) to -0.11574898781163756 volts)
        Pacs_BOLC_SET_VL_G4(-0.11574898781163756);
        // Set group 4 bol bias 03 (VRL) to 0.4958346380324382 volts)
        Pacs_BOLC_SET_VRL_G4(0.4958346380324382);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0717512456998515 volts)
        Pacs_BOLC_SET_VH_BLIND_G4(2.0717512456998515);
        // Set group 5 bol bias 01 (VH) to 1.39 volts)
        Pacs_BOLC_SET_VH_G5(1.39);
        // Set group 5 bol bias 02 (VL) to -0.01 volts)
        Pacs_BOLC_SET_VL_G5(-0.01);
        // Set group 5 bol bias 03 (VRL) to 0.527733857793978 volts)
        Pacs_BOLC_SET_VRL_G5(0.527733857793978);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.070809645129791 volts)
        Pacs_BOLC_SET_VH_BLIND_G5(2.070809645129791);
        // Set group 6 bol bias 01 (VH) to 1.39 volts)
        Pacs_BOLC_SET_VH_G6(1.39);
        // Set group 6 bol bias 02 (VL) to -0.01 volts)
        Pacs_BOLC_SET_VL_G6(-0.01);
        // Set group 6 bol bias 03 (VRL) to 0.5163841345790784 volts)
        Pacs_BOLC_SET_VRL_G6(0.5163841345790784);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.063738443985182 volts)
        Pacs_BOLC_SET_VH_BLIND_G6(2.063738443985182);
    }
    if(biasChoice == "Nominal") {
        //
        //***********************************************************
        // Nominal bias : (Vh-Vl)bleu = 2.6 volts (Vh-Vl)rouge = 2.0 volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.2744056387119684 volts)
        Pacs_BOLC_SET_VH_G1(2.2744056387119684);
        // Set group 1 bol bias 02 (VL) to -0.3255943612880319 volts)
        Pacs_BOLC_SET_VL_G1(-0.3255943612880319);
        // Set group 1 bol bias 03 (VRL) to 0.505268071621468 volts)
        Pacs_BOLC_SET_VRL_G1(0.505268071621468);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0706697887658105 volts)
        Pacs_BOLC_SET_VH_BLIND_G1(2.0706697887658105);
        // Set group 2 bol bias 01 (VH) to 2.2443135499153017 volts)
        Pacs_BOLC_SET_VH_G2(2.2443135499153017);
        // Set group 2 bol bias 02 (VL) to -0.3556864500846981 volts)
        Pacs_BOLC_SET_VL_G2(-0.3556864500846981);
        // Set group 2 bol bias 03 (VRL) to 0.496944385464941 volts)
        Pacs_BOLC_SET_VRL_G2(0.496944385464941);
        // Set group 2 bol bias 20 (VH_BLIND) to 2.0709826344743063 volts)
        Pacs_BOLC_SET_VH_BLIND_G2(2.0709826344743063);
        // Set group 3 bol bias 01 (VH) to 2.2471730056969896 volts)
        Pacs_BOLC_SET_VH_G3(2.2471730056969896);
        // Set group 3 bol bias 02 (VL) to -0.35282699430301034 volts)
        Pacs_BOLC_SET_VL_G3(-0.35282699430301034);
        // Set group 3 bol bias 03 (VRL) to 0.5037730599107967 volts)
        Pacs_BOLC_SET_VRL_G3(0.5037730599107967);
        // Set group 3 bol bias 20 (VH_BLIND) to 2.0708593494137775 volts)
        Pacs_BOLC_SET_VH_BLIND_G3(2.0708593494137775);
        // Set group 4 bol bias 01 (VH) to 2.2359339852940416 volts)
        Pacs_BOLC_SET_VH_G4(2.2359339852940416);
        // Set group 4 bol bias 02 (VL) to -0.36406601470595834 volts)
        Pacs_BOLC_SET_VL_G4(-0.36406601470595834);
        // Set group 4 bol bias 03 (VRL) to 0.46102401601058407 volts)
        Pacs_BOLC_SET_VRL_G4(0.46102401601058407);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0717512456998515 volts)
        Pacs_BOLC_SET_VH_BLIND_G4(2.0717512456998515);
        // Set group 5 bol bias 01 (VH) to 1.8231637043954927 volts)
        Pacs_BOLC_SET_VH_G5(1.8231637043954927);
        // Set group 5 bol bias 02 (VL) to -0.17683629560450742 volts)
        Pacs_BOLC_SET_VL_G5(-0.17683629560450742);
        // Set group 5 bol bias 03 (VRL) to 0.5678749793257466 volts)
        Pacs_BOLC_SET_VRL_G5(0.5678749793257466);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.070809645129791 volts)
        Pacs_BOLC_SET_VH_BLIND_G5(2.070809645129791);
        // Set group 6 bol bias 01 (VH) to 1.8079983636236845 volts)
        Pacs_BOLC_SET_VH_G6(1.8079983636236845);
        // Set group 6 bol bias 02 (VL) to -0.1920016363763155 volts)
        Pacs_BOLC_SET_VL_G6(-0.1920016363763155);
        // Set group 6 bol bias 03 (VRL) to 0.5356949665637106 volts)
        Pacs_BOLC_SET_VRL_G6(0.5356949665637106);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.063738443985182 volts)
        Pacs_BOLC_SET_VH_BLIND_G6(2.063738443985182);
    }
    if(biasChoice == "High") {
        //
        //***********************************************************
        // High bias : (Vh-Vl)bleu = 3.2 volts (Vh-Vl)rouge = 2.5 volts
        //***********************************************************
        // Set group 1 bol bias 01 (VH) to 2.8113635996603827 volts)
        Pacs_BOLC_SET_VH_G1(2.8113635996603827);
        // Set group 1 bol bias 02 (VL) to -0.3886364003396172 volts)
        Pacs_BOLC_SET_VL_G1(-0.3886364003396172);
        // Set group 1 bol bias 03 (VRL) to 0.4182108075785951 volts)
        Pacs_BOLC_SET_VRL_G1(0.4182108075785951);
        // Set group 1 bol bias 20 (VH_BLIND) to 2.0706697887658105 volts)
        Pacs_BOLC_SET_VH_BLIND_G1(2.0706697887658105);
        // Set group 2 bol bias 01 (VH) to 2.779141750838863 volts)
        Pacs_BOLC_SET_VH_G2(2.779141750838863);
        // Set group 2 bol bias 02 (VL) to -0.4208582491611368 volts)
        Pacs_BOLC_SET_VL_G2(-0.4208582491611368);
        // Set group 2 bol bias 03 (VRL) to 0.43968676216541636 volts)
        Pacs_BOLC_SET_VRL_G2(0.43968676216541636);
        // Set group 2 bol bias 20 (VH_BLIND) to 2.0709826344743063 volts)
        Pacs_BOLC_SET_VH_BLIND_G2(2.0709826344743063);
        // Set group 3 bol bias 01 (VH) to 2.7946957041823066 volts)
        Pacs_BOLC_SET_VH_G3(2.7946957041823066);
        // Set group 3 bol bias 02 (VL) to -0.40530429581769367 volts)
        Pacs_BOLC_SET_VL_G3(-0.40530429581769367);
        // Set group 3 bol bias 03 (VRL) to 0.44165862879434936 volts)
        Pacs_BOLC_SET_VRL_G3(0.44165862879434936);
        // Set group 3 bol bias 20 (VH_BLIND) to 2.0708593494137775 volts)
        Pacs_BOLC_SET_VH_BLIND_G3(2.0708593494137775);
        // Set group 4 bol bias 01 (VH) to 2.7956831889495497 volts)
        Pacs_BOLC_SET_VH_G4(2.7956831889495497);
        // Set group 4 bol bias 02 (VL) to -0.40431681105045025 volts)
        Pacs_BOLC_SET_VL_G4(-0.40431681105045025);
        // Set group 4 bol bias 03 (VRL) to 0.415279081268361 volts)
        Pacs_BOLC_SET_VRL_G4(0.415279081268361);
        // Set group 4 bol bias 20 (VH_BLIND) to 2.0717512456998515 volts)
        Pacs_BOLC_SET_VH_BLIND_G4(2.0717512456998515);
        // Set group 5 bol bias 01 (VH) to 2.1982838445941164 volts)
        Pacs_BOLC_SET_VH_G5(2.1982838445941164);
        // Set group 5 bol bias 02 (VL) to -0.3017161554058836 volts)
        Pacs_BOLC_SET_VL_G5(-0.3017161554058836);
        // Set group 5 bol bias 03 (VRL) to 0.5551703013217963 volts)
        Pacs_BOLC_SET_VRL_G5(0.5551703013217963);
        // Set group 5 bol bias 20 (VH_BLIND) to 2.070809645129791 volts)
        Pacs_BOLC_SET_VH_BLIND_G5(2.070809645129791);
        // Set group 6 bol bias 01 (VH) to 2.1614506990768874 volts)
        Pacs_BOLC_SET_VH_G6(2.1614506990768874);
        // Set group 6 bol bias 02 (VL) to -0.33854930092311264 volts)
        Pacs_BOLC_SET_VL_G6(-0.33854930092311264);
        // Set group 6 bol bias 03 (VRL) to 0.4957816605825063 volts)
        Pacs_BOLC_SET_VRL_G6(0.4957816605825063);
        // Set group 6 bol bias 20 (VH_BLIND) to 2.063738443985182 volts)
        Pacs_BOLC_SET_VH_BLIND_G6(2.063738443985182);
    }
    //
    //*****************************************************
    // PACS chopper cycle with 40 readouts per plateau
    //*****************************************************
    //
    // Set SPU to the buffer transmission mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,39,0,0,211,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 2 readouts per plateau
    //*****************************************************
    //
    // Set SPU to the buffer transmission mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,1,0,0,4220,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 3 readouts per plateau
    //*****************************************************
    //
    // Set SPU to the buffer transmission mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,2,0,0,2814,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 4 readouts per plateau
    //*****************************************************
    //
    // Set SPU to the buffer transmission mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,3,0,0,2110,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 6 readouts per plateau
    //*****************************************************
    //
    // Set SPU to the buffer transmission mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,5,0,0,1407,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 8 readouts per plateau
    //*****************************************************
    //
    // Set SPU to the buffer transmission mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,7,0,0,1055,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //
    //*****************************************************
    // PACS chopper cycle with 16 readouts per plateau
    //*****************************************************
    //
    // Set SPU to the buffer transmission mode
    PHOT_spu_setup(9,9,0,0,true);
    OBCP_chopped_photometry(0,0,15,0,0,528,1,sideField,chop_pos_CS2,9,9,0);
    //
    // Stop SPU
    PHOT_spu_setup(0,0,0,0,true);
    //***************************
    // Set DPU out of Burst mode
    //***************************
    Pacs_DPU_SET_BUS_LIST("DISABLE");
    //
    //
    // Sychronize
    //
    sync();
}

// Missionphase  : CP/PV 
//
// Purpose	 : Test of Chopper Movement
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : Move chopper in open-loop mode. All 3 coils are
//                 operative (nominal setting). The chopper is commanded
//                 between the two internal calibration sources in small
//                 equidistant steps.
//                  
// Dependencies  : 
//
// Preconditions : PACS switched-on in safe mode
//                 
// Comments	 :
//
// Version	 : 1.0
// 
// History 	 : 1.0 12-Jun-08 creation by MN
procedure Pacs_ChopperOpenLoop_FullRange {
}{
    // Set fixed parameters for chopper movement
    double chop_max_ma = 42.0;
    // chopper maximal drive current in mA
    double chop_step_ma = 3.0;
    // chopper movement step size in mA
    int chop_damptime = 15;
    // chopper timescale in seconds allowing for initial oscillation damping in open-loop mode
    // Start diagnostic HK
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_dHK_BB("ON");
    delay(10);
    // Set Chopper Controller Parameters: CONFChopper -> OLoop_cold_nom (low rate param)
    CONF_chopper("CONFChopper","OLoop_cold_nom");
    delay(2);
    // SWON chopper
    PACS_Chopper_SWON_SWOF_only("ON");
    delay(30);
    // Set open-loop mode
    PACS_SPEC_Chopper_SetOpenLoop_BB("ON");
    delay(2);
    // Enable chopper controller
    EnDis_chopper("ON");
    delay(30);
    // Translate mA into ROU
    double chop_max_rou = chop_max_ma * 32767.0 / 133.0;
    double chop_step_rou = chop_step_ma * 32767.0 / 133.0;
    // Create tables of chopper positions
    double chop_pos = 0.0;
    //Starting position
    int ichop_pos = 0;
    //Starting position (integer)
    int[] chop_steps = [];
    //Array of chopper positions
    int i = 0;
    //Running variable
    while(chop_pos < chop_max_rou + chop_step_rou) {
        chop_steps[i] = ichop_pos;
        i = i + 1;
        chop_pos = chop_pos + chop_step_rou;
        ichop_pos = iround(chop_pos);
    }
    int len = length(chop_steps);
    //Length of array
    // Loop from 0 to max value
    for(int k1 = 0 .. len - 1) {
        PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(chop_steps[k1]);
        delay(chop_damptime);
    }
    // Loop from max-1 value to 0
    for(int k2 = 1 .. len - 1) {
        PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(chop_steps[len - 1 - k2]);
        delay(chop_damptime);
    }
    // Loop from step -1 to min value
    for(int k3 = 1 .. len - 1) {
        PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(-chop_steps[k3]);
        delay(chop_damptime);
    }
    // Loop from min+1 value to 0
    for(int k4 = 1 .. len - 1) {
        PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(-chop_steps[len - 1 - k4]);
        delay(chop_damptime);
    }
    // Switch off open-loop mode
    EnDis_chopper("OFF");
    delay(30);
    PACS_Chopper_SWON_SWOF_only("OFF");
    delay(30);
    CONF_chopper("CONFChopper","nom_sky");
    delay(2);
    PACS_SPEC_Chopper_SetOpenLoop_BB("OFF");
    delay(2);
    // Final ZP check
    PACS_Chopper_SWON_SWOF_only("ON");
    delay(30);
    EnDis_chopper("ON");
    delay(30);
    EnDis_chopper("OFF");
    delay(30);
    PACS_Chopper_SWON_SWOF_only("OFF");
    delay(30);
    // Stop diagnostic HK
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_dHK_BB("OFF");
    sync();
}

// Missionphase  : EQM IMT
//
// Purpose	: Setup SPU for photometry data flow
//
// Author	: Bart Vandenbussche
//
// Arguments	: 
//
// Description	: Configures photometry compression /reduction mode and (optionally) starts 
//                     reduction/compression
//                  
// Dependencies : 
//
// Comments	:
//
// Version	: 1.4.4
//               
// History	: 1.0 18-Apr-2005 BV - first version after Thomas' tcl script\
//                                and Diego's SPEC_spu_setup
//                     1.1 19-apr-2005 DAC Use Array2grp_1 to generate TC operands
//                     1.2 09-aug-2006 TM update of WRT_DET_CST_PHOT parameters
//                     1.3 23-aug-2006 TM update for SPU HLSW UM, issue 12.8
//                     1.4 28-mar-2007 DAC Update for SPUv13.x
//                     1.4.1 29-mar-2007 Set scm = 1 (new compression scheme)
//                     1.4.2  4-apr-2007 SCM back to zero
//                     1.4.3 10-apr-2007 SCM back to 1
//                     1.4.4 11-apr-2007 SCM back to 0
//                     1.4.5 16-jun-2007 SCM back to 1
//                     1.4.6 23-feb-2008 TM: update for new SPU OBSW (shift 1, option to do bit rounding)
//                     1.4.7 24-mar-2009 DAC Rename spr1&spr2 per SPU UM 13.95a
//
int procedure PHOT_spu_setup {
    int comp_mode_blu = 0; //  Compression blue: default=0, double=1, half=2, lossless=4, transp=7, buffer=9
    int comp_mode_red = 0; //  Compression blue: default=0, double=1, half=2, lossless=4, transp=7, buffer=9
    int nraw_blu = 3; // Number of raw channels transmitted in the blue SPU
    int nraw_red = 3; // Number of raw channels transmitted in the red SPU
    bool startSPU = true; // Start SPU or not [true,false]
}{
    // Duration accumulator (accumulated time expressed in milliseconds)
    // (no longer used)
    int duration_msec = 0;
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    // Set the SPU compression modes
    int[] aux = [comp_mode_blu,comp_mode_red];
    int check_sum = checksum("int",aux);
    // Issue the TC
    {int}[] comp_par = Array2grp_1(aux);
    Pacs_DMC_WRT_SPU_TRAN_MODE(comp_par,check_sum);
    // Setting of start index of raw channels for SPUS and SPUL
    string spus_obs_mode = "PHOT";
    string spul_obs_mode = "PHOT";
    int spus_startraw = 1;
    int spul_startraw = 1;
    Pacs_SPUS_RAW_CHAN_TRAN_MODE(spus_obs_mode,nraw_blu,spus_startraw);
    Pacs_SPUL_RAW_CHAN_TRAN_MODE(spul_obs_mode,nraw_red,spul_startraw);
    // Photo "Ottensamer" block ("S" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    int ppf = 0;
    // PPP: Pre-Processing Parameter
    int ppp = 0;
    // Threshold for glitch detection in photometry
    int tfp = 1000;
    // Threshold for chopper position deviation in photometry
    int tcp = 100;
    // Glitch detection for photometry (1: no glitch detection)
    int gdfp = 1;
    // Override samples to average
    int navg = 0;
    // resolution reduction parameter 2 (rnd: number of bits for optional rounding:
    // low gain: 0, high gain: 1-2, RO's recommendation: 2 in high gain)
    int rnd = 0;
    // resolution reduction parameter 3 (rnds: rounding strategy: best option 0)
    int rnds = 0;
    // Lossless scheme
    int scm = 1;
    // lossless compression algorithm (0,1,2,3,4)
    int lcal = 4;
    // PACS Codec Order (3,4)
    int pcod = 3;
    // dpre: delete pre (number of readouts to be discarded in group at beginning)
    int dpre = 0;
    // dpost: delete post (number of readouts to be discarded at the end of a group)
    int dpost = 0;
    // syncd: synchronisation delay: number of readouts delayed to start averaging 
    int syncd = 1;
    // Spare elements: 10 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfp,tcp,gdfp,navg,rnd,rnds,scm,lcal,pcod,dpre,dpost,syncd,0,0,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    {int}[] spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUS_WRT_DET_CST_PHOT(spu_par,check_sum);
    delay(1);
    // Photo "Ottensamer" block ("L" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    ppf = 0;
    // PPP: Pre-Processing Parameter
    ppp = 0;
    // Threshold for glitch detection in photometry
    tfp = 1000;
    // Threshold for chopper position deviation in photometry
    tcp = 100;
    // Glitch detection for photometry (1: no glitch detection)
    gdfp = 1;
    // Override samples to average
    navg = 0;
    // resolution reduction parameter 2 (rnd: number of bits for optional rounding:
    // low gain: 0, high gain: 1-2, RO's recommendation: 2 in high gain)
    rnd = 0;
    // resolution reduction parameter 3 (rnds: rounding strategy: best option 0)
    rnds = 0;
    // Lossless compression scheme
    scm = 1;
    // lossless compression algoithm (0,1,2,3,4)
    lcal = 4;
    // PACS Codec Order (3,4)
    pcod = 3;
    // dpre: delete pre (number of readouts to be discarded in group at beginning)
    dpre = 0;
    // dpost: delete post (number of readouts to be discarded at the end of a group)
    dpost = 0;
    // syncd: synchronisation delay: number of readouts delayed to start averaging 
    syncd = 1;
    // Spare elements: 10 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfp,tcp,gdfp,navg,rnd,rnds,scm,lcal,pcod,dpre,dpost,syncd,0,0,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUL_WRT_DET_CST_PHOT(spu_par,check_sum);
    delay(1);
    // Send time stamps
    // DMC_WRT_TIME: Write the time sent by the DPU into the DMC buffer
    // (No action on this one?)
    // DPU sends the time to DEC/MEC
    Pacs_DPU_SEND_TIME();
    // DMC_SET_TIME: Set the time previously written by the write time command
    Pacs_DMC_SET_TIME();
    // Start reduction/compression if commanded to do so
    if(startSPU) {
        Pacs_SPUS_START_REDUCT_COMPR();
        Pacs_SPUL_START_REDUCT_COMPR();
    }
    // sync the bus
    sync();

    return duration_msec;
}

// $Id$
// Missionphase  : PV phase
//
// Purpose       :  Wavelength calibration and instrumental profile
//
// TCL author    : HF
// TCL file      :
// CUS author    : HF
// Script file   : WaveCalNoChop.txt
//
//
// Description   :  Uses OBCP28 for executing a parameterized scan of any length, stepsize etc.
//                       Represents a generic non-chopped grating scan
//
// Dependencies  : SPEC_heater, SPEC_cre_setup
//
// Preconditions : PACS must be on and configured for spectroscopy
//
// Comments      : Can be run for wavelength calibration, instrumental profile and ghost search
// Version       : 0.6
// History
// 0.1 21-sep-2007 DAC adapted from IST's Wave_Cal (converted from "mode" to
//                 "procedure")
// 0.2 14-jan-2008 DAC Added bias_r... input variables; read CS positions as
//                 for AOTs, viz. from CHOPPERCSparams; removed "duree" code
// 0.3 15-jan-2008 Renamed to WaveCalNoChop (in preparation for WaveCalChop)
// 0.4 22-jun-2009 HF SCR 7157
// 0.5 27-jul-2009 BV SPR PACS-1798: default bias settings
// 0.6 22-Sep-2009 HF moved reset SPU to the begin
//
procedure WaveCalNoChop {
    string fltPOS = "POS A"; // Filter wheel position (0="POS A", 1="POS B")
    int grat_start = 500000; // grating start position for scan\
    int grat_stepsize = 200; // grating step size
    int grat_numsteps = 50; // number of grating steps in one direction
    int grat_numramps = 3; // number of ramps per grating position
    int chop_def = 648; // chopper position during grating scan
    int nb_rdout_ramp = 64; // number of readouts per ramp
    int num_updown = 1; // number of grating updown scans
    int grat_def = 496000; // position of grating after the scan
    int capa_red = 0; // Red capacitor
    int capa_blu = 0; // Blue capacitor
    double bias_r_blu = 0.01; // Bias "r" blue
    double bias_r_red = 0.01; // Bias "r" red
    double bias_d_blu = 0.1; // Bias "d" blue
    double bias_d_red = 0.042; // Bias "d" red
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp
    int nb_raw_blu = 0; // Nb of raw channels blue
    int nb_raw_red = 0; // Nb of raw channels red
}{
    //
    // Reset SPU
    SPEC_spu_reset();
    // Condition the CREs and detectors
    int ramp_len_blu = nb_rdout_ramp;
    int ramp_len_red = nb_rdout_ramp;
    // Set up the blue and red CRE subsystem
    // cre_ctrl is a bit field:
    // 256=sync width=2, 128=T sensor on, 2=enable, 1=power on
    // Do not enable yet
    int cre_ctrl_red = 256 + 128 + 2 + 1;
    int cre_ctrl_blu = 256 + 128 + 2 + 1;
    SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // Set BLUE heater parameters (mA)
    double heater_blu = 0.78;
    SPEC_heater_setup(heater_blu);
    //
    // SPU parameters
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    // Re-start SPU in default mode
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red,glitch_det,ramp_fit_alg,startSPU);
    // Move the filter wheel
    SPEC_fltw_move(fltPOS);
    // Get CSn positions from dedicated CAL-U file
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","SPEC","pos_CS1");
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    // Synchronize on this detector 1:Blue 2:Red
    int detector = 1;
    int nb_CS1_CS2 = 0;
    // number of cycles on calsources, 0=don't use them
    int nb_ramps_CS = 3;
    // number of ramps on CSs
    int grat_start_time = 31000;
    // time for grating to start [ms]
    int grat_def_time = 11000;
    // time for grating to go to default [ms]
    // Now call OBCP 28 with all its parameters
    int[] duree3 = OBCP_grat_scan_nochop(num_updown,grat_numsteps,grat_stepsize,-grat_stepsize,grat_numramps,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,nb_ramps_CS,grat_numsteps,chop_def,detector,grat_start,grat_start_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,nb_rdout_ramp);
    // Reset SPU
    SPEC_spu_reset();
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowGainBiasDirect5
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   + Set the biases group by group
//   + Set the blue filter 100um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + Set the blue filter 70um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//            New version
//
// Version : Fri Apr 24 19:30:21 EST 2009
//
procedure Phot_lowGainBiasDirect5 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
}{
    //*******************************
    // Select Filter B (70 microns)
    //*******************************
    //
    PHOT_fltw_move("POS B");
    //
    //************************************************
    // Set the biases and start SPU, then set the gain
    //************************************************
    //
    PHOT_set_biases(startBiasTable,"DIRECT","LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position 21200
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(21200);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS2 at 58.0 Ohm
    // corresponding to 1.25pW on the blue and 6.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    // sync the bus
    sync();
}

// Tests Pacs_Spec_AleFakeOBCP.txt
// cus: rem: block 5000 in pacs5
// author: VD
// history: 
// 	    05-mar-2009 VD creation
//	    10-mar-2009 VD AC changed chop pattern to AB
//	    10-mar-2009 or ABBA?
//	    		carefull verification* block ID 1000
//			pacs5 block ID is 5000			
block Pacs_Spec_AleFakeOBCP PACS 1000 {
    int nb_SRC_REF = 1;
    int time_ramps_plateau = 1;
    int chop_pos_SRC = -5000;
    int chop_pos_REF1 = 6000;
    int chop_pos_def = 664;
}{
    int time2_ramps_plateau = 2 * time_ramps_plateau;
    // looping over nb_SRC/2 such that we implement ABBA
    // modfied to have only AB
    for(int t = 1 .. nb_SRC_REF) {
        Pacs_DMC_MOVE_CHOP_ABS(chop_pos_SRC);
        delay(time_ramps_plateau);
        Pacs_DMC_MOVE_CHOP_ABS(chop_pos_REF1);
        //     delay(time2_ramps_plateau);       
        //     Pacs_DMC_MOVE_CHOP_ABS(chop_pos_SRC);
        delay(time_ramps_plateau);
    }
    // bus sync
    sync();
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowGainBiasDirect6
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   + Set the biases group by group
//   + Set the blue filter 100um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + Set the blue filter 70um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//            New version
//
// Version : Fri Apr 24 19:30:21 EST 2009
//
procedure Phot_lowGainBiasDirect6 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
}{
    //*******************************
    // Select Filter B (70 microns)
    //*******************************
    //
    PHOT_fltw_move("POS B");
    //
    //************************************************
    // Set the biases and start SPU, then set the gain
    //************************************************
    //
    PHOT_set_biases(startBiasTable,"DIRECT","LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position 664
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //
    //**********************************************************************
    //                       Measurement
    // PACS photometer central field-of-view
    // corresponding to 2.53pW on the blue and 2.30pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    // sync the bus
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       : Perform Check for saturation according to TM's input:
//- Bolometers: Check for saturation for low-high gain settings at
//              PACS calibration sources and background level for
//              both filters
// -----> Assume PHOT_setup_OBS has been run before.
//        (check list should be correct...)
//  Check before executing:
//      o  is the gain still "high"?
//      o  is the filter position still at "1"?
//      o  is the sequence mode "Sbolo-Sref"?
//      o  is the data mode "Bolo & HK"?
//      o  are the photometry science packets still generated?
//
//  Description:
//      o  move the chopper to various positions, with 2 sec per plateau:
//         CUS script Chop_scan_both_ways <-25000,5000,10,2> --> 48 sec
//      o  switch to gain "low"               (PACS_Phot_Gain_low.tcl)
//      o  repeat chopper sequence
//         CUS script Chop_scan_both_ways <-25000,5000,10,2> --> 48 sec
//      o  switch filter to position "0"      (tm_phot_fil_switch.tcl)
//      o  repeat chopper sequence
//         CUS script Chop_scan_both_ways <-25000,5000,10,2> --> 48 sec
//      o  switch to gain "high"              (PACS_Phot_Gain_high.tcl)
//      o  repeat chopper sequence
//         CUS script Chop_scan_both_ways <-25000,5000,10,2> --> 48 sec
//      o  switch filter back to position "1" (tm_phot_fil_switch.tcl)
//      o  repeat chopper sequence
//         CUS script Chop_scan_both_ways <-25000,5000,10,2> --> 48 sec
//  Scripts:
//      o  PACS_Phot_Gain_low.tcl
//      o  PACS_Phot_Gain_high.tcl
//      o  tm_phot_fil_switch.tcl
//      o  CUS script "Chop_scan_both_ways"
//      
//  Expected Results:
//      o  check signal patterns in QLA
//      o  in case of saturation: note the gain-filter-chopper
//         combinations and avoid these settings later on
//
// CUS author    : DAC
// Script file   : PHOT_saturation_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version	 : 1.0
// History       : 0.1 22-apr-2005 DAC
//                 0.2 25-apr-2005 DAC
//                 0.3 26-apr-2005 DAC Start/stop SPU
//                 0.4 20-oct-2005 DAC Added SPEC_Chop_move_abs_raw
//                 0.5 10-apr-2007 TM updated
//		   1.0 25-mar-2008 VDP Tanslated from IST to PV phase syntax
obs PacsEng_Phot_saturation {
    /* Needed variables to call PacsEng_Phot_saturation                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_saturation                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Phot_saturation()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Phot_saturation();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowGainBiasDirect3
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   + Set the biases group by group
//   + Set the blue filter 100um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + Set the blue filter 70um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//            New version
//
// Version : Fri Apr 24 19:30:06 EST 2009
//
procedure Phot_lowGainBiasDirect3 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
}{
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //************************************************
    // Set the biases and start SPU, then set the gain
    //************************************************
    //
    PHOT_set_biases(startBiasTable,"DIRECT","LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position 664
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //
    //**********************************************************************
    //                       Measurement
    // PACS photometer central field-of-view
    // corresponding to 1.42pW on the green and 2.30pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    // sync the bus
    sync();
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowGainBiasDirect4
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   + Set the biases group by group
//   + Set the blue filter 100um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + Set the blue filter 70um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//            New version
//
// Version : Fri Apr 24 19:30:21 EST 2009
//
procedure Phot_lowGainBiasDirect4 {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
}{
    //*******************************
    // Select Filter B (70 microns)
    //*******************************
    //
    PHOT_fltw_move("POS B");
    //
    //************************************************
    // Set the biases and start SPU, then set the gain
    //************************************************
    //
    PHOT_set_biases(startBiasTable,"DIRECT","LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position -21350
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(-21350);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS1 at 48.0 Ohm
    // corresponding to 0.90pW on the blue and 5.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //
    // sync the bus
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	:  Short performance test of Chopper in IMT
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do rectangular chopping for four frequencies with OBCP27 and its
//                corresponding DMC-sequence 12.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy
//                 
//
// Version	: 3.0	
// 
// History 	: 1.0 04-04-07 HD. IST tuned.
//		  2.0 05-07-07 HD. IST Chopper Day.
//		  3.0 25-mar-2008 VDP Translated from IST to PV phase syntax
obs PacsEng_Spec_Chopper_imt504_ast {
    /* Needed variables to call PacsEng_Spec_Chopper_imt504_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Chopper_imt504_ast                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Chopper_imt504_ast()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Chopper_imt504_ast();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id: WriteEndBB.txt,v 1.2 2007/08/22 10:21:52 dcesarsk Exp $ 
// Purpose       : Set BBID to its default value to indicate the end
//                 of current BB execution (see FIRST-FSC-DOC-0200) 
//
// CUS script    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
//
// Input arguments N/A
//
// Description   : BBID will be set to its LEG value
//
// Comments      : Needed for SCR-3507
//
// Version       : 0.1 21-aug-2007 First creation
// 		 : 1.0 derived from ...made it a block
//
block PacsBbWriteEndBB PACS 1101 {
}{
    int iBBID = 0x40000000;
    // Write BBID to DEC/MEC
    Pacs_DMC_SET_BBID(iBBID);
    // bus sync
    sync();
}

// $Id$
// Filename      : Pacs_Phot_all_aots
// Purpose       : Exercise all available OBCPs for photometry
//                  
//                 
//
// TCL author    : N/A
// TCL file      : tN/A
// CUS author    : DAC
// Script file   : PHOT_all_aots_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Exercise all available OBCPs for PHOT
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version      2.0
// History      0.1 20-apr-2005 DAC
//                 0.2 25-apr-2005 DAC Added moe to POS A at the end
//                 0.3 25-apr-2005 DAC Start and stop SPU with user given
//                                     compression parameters
//                 0.4 26-apr-2005 DAC Use PACS_spu_reset at end
//                 0.5 30-sep-2005 Correct typo phot_cal_III (-46145)
//                 0.6  9-nov-2005 comp_mode_xx were hardcoded in OBCP calls
//                 0.7 16-jun-2006 DAC Added 2 sec delay between OBCPs
//                 0.8  3-aug-2006 DAC Corrected OBCP freeze frame
//                 0.9  9-aug-2006 TM 2 new OBCPs have been added + some cosmetics
//                 0.95 9-aug-2006 TM, new parameters for chop_scan OBCP
//                 0.96 9-aug-2006 TM, compression mode hard-coded
//                 1.0 14-nov-2006 TM: update of chopper positions
//                 1.1 17-nov-2006 Remove freeze frame
//                 1.2 11-apr-2007 TM: take out the raw channels
//		   2.0 VDP adusted to match PV phase syntax
//
procedure Pacs_Phot_all_aots {
}{
    // Register with environment
    // Start SPU
    int comp_mode_blu = 0;
    int comp_mode_red = 0;
    int nraw_blu = 0;
    int nraw_red = 0;
    PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,true);
    //
    // Position the filter wheel at POS A
    //
    PHOT_fltw_move("POS A");
    //
    // Perform OBCP_fixed_fixed_photo  with default parameters
    debug_print("Start OBCP_fixed_fixed_photo");
    int[] duree = OBCP_fixed_fixed_photo(2,-1700,79,3,3000,-3000,-1500,-1300,comp_mode_blu,comp_mode_red);
    delay(2);
    debug_print("Duration from OBCP_fixed_fixed_photo" + duree);
    // Perform OBCP_chopped_photometry with default parameters
    debug_print("Start OBCP_chopped_photometry");
    duree = OBCP_chopped_photometry(8,1000,39,-2000,5000,2,2,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    // Perform OBCP_chopped_photometry_dither with default parameters
    debug_print("Start OBCP_chopped_photometry_dither");
    duree = OBCP_chopped_photometry_dither(8,1000,39,-2000,5000,2,2,-21350,+21200,comp_mode_blu,comp_mode_red,0,200);
    delay(2);
    debug_print("Duration from OBCP_chopped_photometry_dither: " + duree);
    // Perform OBCP_phot_freezeframe with default parameters
    ///    debug_print("Start OBCP_phot_freezeframe");
    ///    duree = OBCP_phot_freezeframe(2,-1997,210,33,comp_mode_blu,comp_mode_red,0);
    ///    delay(2);
    ///    debug_print("Duration from OBCP_phot_freezeframe: " + duree);
    // Perform OBCP_phot_staring with default parameters
    debug_print("Start OBCP_phot_starting");
    duree = OBCP_phot_staring(60,comp_mode_blu,comp_mode_red);
    delay(2);
    debug_print("Duration from OBCP_phot_staring: " + duree);
    // Perform OBCP_phot_cal_I with default parameters
    debug_print("Start OBCP_phot_cal_I");
    duree = OBCP_phot_cal_I(2,-22000,39,8,42000,-41750,comp_mode_blu,comp_mode_red,0);
    delay(2);
    debug_print("Duration from OBCP_phot_cal_I: " + duree);
    // Perform OBCP_phot_cal_II with default parameters
    debug_print("Start OBCP_phot_cal_II");
    duree = OBCP_phot_cal_II(2,-22500,79,65,129,44000,44250,44500,44750,45000,comp_mode_blu,comp_mode_red,0);
    delay(2);
    debug_print("Duration from OBCP_phot_cal_II: " + duree);
    // Perform OBCP_phot_cal_III with default parameters
    debug_print("Start OBCP_phot_cal_III");
    duree = OBCP_phot_cal_III(2,-22500,39,1,44000,-43950,100,6,comp_mode_blu,comp_mode_red,0);
    delay(2);
    debug_print("Duration from OBCP_phot_cal_III: " + duree);
    // Perform OBCP_chop_scan_phot with default parameters
    debug_print("Start OBCP_chop_scan_phot");
    duree = OBCP_chop_scan_phot(1,19,100,100,200,-200,4,comp_mode_blu,comp_mode_red,-10000,0);
    delay(2);
    debug_print("Duration from OBCP_chop_scan_phot:" + duree);
    //
    // Position the filter wheel at POS B and repeat everything
    //
    PHOT_fltw_move("POS B");
    //
    // Perform OBCP_fixed_fixed_photo  with default parameters
    debug_print("Start OBCP_fixed_fixed_photo");
    duree = OBCP_fixed_fixed_photo(2,-1700,79,3,3000,-3000,-1500,-1300,comp_mode_blu,comp_mode_red);
    delay(2);
    debug_print("Duration from OBCP_fixed_fixed_photo" + duree);
    // Perform OBCP_chopped_photometry with default parameters
    debug_print("Start OBCP_chopped_photometry");
    duree = OBCP_chopped_photometry(8,1000,39,-2000,5000,2,2,-21350,+21200,comp_mode_blu,comp_mode_red,0);
    delay(2);
    debug_print("Duration from OBCP_chopped_photometry: " + duree);
    // Perform OBCP_chopped_photometry_dither with default parameters
    debug_print("Start OBCP_chopped_photometry_dither");
    duree = OBCP_chopped_photometry_dither(8,1000,39,-2000,5000,2,2,-21350,+21200,comp_mode_blu,comp_mode_red,0,200);
    delay(2);
    debug_print("Duration from OBCP_chopped_photometry_dither: " + duree);
    // Perform OBCP_phot_freezeframe with default parameters
    ///    debug_print("Start OBCP_phot_freezeframe");
    ///    duree = OBCP_phot_freezeframe(2,-1997,210,33,comp_mode_blu,comp_mode_red,0);
    ///    delay(2);
    ///    debug_print("Duration from OBCP_phot_freezeframe: " + duree);
    // Perform OBCP_phot_staring with default parameters
    debug_print("Start OBCP_phot_starting");
    duree = OBCP_phot_staring(60,comp_mode_blu,comp_mode_red);
    delay(2);
    debug_print("Duration from OBCP_phot_staring: " + duree);
    // Perform OBCP_phot_cal_I with default parameters
    debug_print("Start OBCP_phot_cal_I");
    duree = OBCP_phot_cal_I(2,-22000,39,8,42000,-41750,comp_mode_blu,comp_mode_red,0);
    delay(2);
    debug_print("Duration from OBCP_phot_cal_I: " + duree);
    // Perform OBCP_phot_cal_II with default parameters
    debug_print("Start OBCP_phot_cal_II");
    duree = OBCP_phot_cal_II(2,-22500,79,65,129,44000,44250,44500,44750,45000,comp_mode_blu,comp_mode_red,0);
    delay(2);
    debug_print("Duration from OBCP_phot_cal_II: " + duree);
    // Perform OBCP_phot_cal_III with default parameters
    debug_print("Start OBCP_phot_cal_III");
    duree = OBCP_phot_cal_III(2,-22500,39,1,44000,-43950,100,6,comp_mode_blu,comp_mode_red,0);
    delay(2);
    debug_print("Duration from OBCP_phot_cal_III: " + duree);
    // Perform OBCP_chop_scan_phot with default parameters
    debug_print("Start OBCP_chop_scan_phot");
    duree = OBCP_chop_scan_phot(1,19,100,100,200,-200,4,comp_mode_blu,comp_mode_red,-10000,0);
    delay(2);
    debug_print("Duration from OBCP_chop_scan_phot:" + duree);
    //
    // Position the filter wheel at POS A
    //
    PHOT_fltw_move("POS A");
    //
    // Stop SPU 
    //
    PACS_spu_reset();
    // Leave environment
}

// CVS file      : TMMarker600.txt
// Missionphase  : 
//
// Purpose       : Mark the telemetry with BuildBlock identification. 
//                 The 600- series of BBIDs are "did nothing" BBs. Call
//                 this block whenever you want to define subsequent TM as
//                 belonging to block 600. Each call to this BB will, of
//                 course, increment the BB=600 activation counter
//
// Author        : DAC
// Comments      : Block name meant to suggest TeleMetryMarker with BBID=600
// Version       : 0.1 28-jun-2006
// History       : 0.2 17-jul-2008 DAC Removed spurious WriteEndBB 
//
block TMMarker600 PACS 600 {
}{
    // Set BBID
    WriteBBID($BBID);
    sync();
}

// CVS file      : TMMarker602.txt
// Missionphase  : 
//
// Purpose       : Mark the telemetry with BuildBlock identification. 
//                 The 600- series of BBIDs are "did nothing" BBs. Call
//                 this block whenever you want to define subsequent TM as
//                 belonging to block 602. Each call to this BB will, of
//                 course, increment the BB=602 activation counter
//
// Author        : DAC
// Comments      : Block name suggests TeleMetryMarker with BBID=602
// Version       : 0.1 28-jun-2006
// History       : 0.2 17-jul-2008 DAC Removed spurious WriteEndBB 
//
block TMMarker602 PACS 602 {
}{
    // Set BBID
    WriteBBID($BBID);
    sync();
}

// CVS file      : TMMarker601.txt
// Missionphase  : 
//
// Purpose       : Mark the telemetry with BuildBlock identification. 
//                 The 600- series of BBIDs are "did nothing" BBs. Call
//                 this block whenever you want to define subsequent TM as
//                 belonging to block 601. Each call to this BB will, of
//                 course, increment the BB=601 activation counter
//
// Author        : DAC
// Comments      : Block name meant to suggest TeleMetryMarker with BBID=601
// Version       : 0.1 28-jun-2006
// History       : 0.2 17-jul-2008 DAC Removed spurious WriteEndBB 
// History       : 
//
block TMMarker601 PACS 601 {
}{
    // Set BBID
    WriteBBID($BBID);
    sync();
}

// CVS file      : TMMarker603.txt
// Missionphase  : 
//
// Purpose       : Mark the telemetry with BuildBlock identification. 
//                 The 600- series of BBIDs are "did nothing" BBs. Call
//                 this block whenever you want to define subsequent TM as
//                 belonging to block 603. Each call to this BB will, of
//                 course, increment the BB=603 activation counter
//
// Author        : DAC
// Comments      : Block name suggests TeleMetryMarker with BBID=603
// Version       : 0.1 28-jun-2006
// History       : 0.2 17-jul-2008 DAC Removed spurious WriteEndBB 
//
block TMMarker603 PACS 603 {
}{
    // Set BBID
    WriteBBID($BBID);
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 1.0 6-nov-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_GeGa_SFT_Init_Cold_He2 {
    /* No variables to call PacsEng_GeGa_SFT_Init_Cold_He2                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_GeGa_SFT_Init_Cold_He2                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_GeGa_SFT_Init_Cold_He2()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_GeGa_SFT_Init_Cold_He2();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS file	: PHOT_spu_reset.cus
// Missionphase  : FM IMT
//
// Purpose	: Reset SPU after photometry data flow
//
// Author	: Bart Vandenbussche
//
// Arguments	: none
// Description	: Stops SPU
//                  
// Dependencies : 
// Comments	: 
// Version	: 1.0               
// History	: 1.0 18-Apr-2005 BV - copied from SPEC_spu_reset -
//
procedure PHOT_spu_reset {
}{
    // Stop both "blue" (Long) and "red" (Short) SPU
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Deep staring observations for GeGa ramp linearization
//                  
// Author	 : Helmut Dannerbauer, Jeroen Bouwman, Ulrich Klaas,
//                 Markus Nielbock
// CUS author    : HD, MN
//
// Input arguments 
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Deep staring observations for GeGa Ramp linearization
//		    on astronomical Sources.
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                 
// Comments      : 
// Version	 : 3.2
// History	 : 2.0 11-dec-2008 HD
//		   including PR comments
//                 3.0 10-Feb-2009 MN: - included detector selection tables
//                                       prepared by J. Bouwman
//                                     - killed bugs and defused traps
//                 3.1 08-Jul-2009 MN: - adjusted default detector bias settings
//                                       blue: 42 mV, red: 100mV
//                 3.2 10-Sep-2009 MN: - reading yz pixel offsets from CALU table
//                                       PacsTable_Spec_YZPixOffsets
obs PacsCal_Spec_Star_Lin_Source {
    /* Needed variables to call PacsCal_Spec_Star_Lin_Source */
    string filter_pos = "POS B" in ["POS A","POS B"]; // Filter (A: 3rd order, B: 2nd order)
    int chopposition = 664 in [-21350,+21200]; // Chopper position (opt. zero: 664)
    int[] gratingposition = [335000,535000,730000,794000,900000]; // List of grating positions
    int[] ramp_len = [32,64]; // List of number of readouts per ramp (blue and red)
    string observing_mode = "llc" in ["llc","btm"]; // Lossless compression or buffer transmission
    string detsel_table = "PACSDetSel_10000" in ["PACSDetSel_10000","PACSDetSel_20001","PACSDetSel_20002","PACSDetSel_20003","PACSDetSel_20004","PACSDetSel_20005","PACSDetSel_20006","PACSDetSel_20007","PACSDetSel_20008","PACSDetSel_20009","PACSDetSel_20010","PACSDetSel_20011","PACSDetSel_20012","PACSDetSel_20013","PACSDetSel_20014","PACSDetSel_20015","PACSDetSel_20016","PACSDetSel_20017","PACSDetSel_20018","PACSDetSel_20019","PACSDetSel_20020","PACSDetSel_20021","PACSDetSel_20022","PACSDetSel_20023","PACSDetSel_20024","PACSDetSel_20025"]; // Detector selection table (default: 10000, module of pixel xx: 200xx)
    int ramps = 80; // Number of ramps per observation
    int[] capa_list = [0,8,4,12]; // Blue and red capacitances (0: 0.14pF, 4:0.45pF, 8: 0.24pF, 12:1.15pF) 
    double bias_d_red = 0.042 in [0.02,0.06]; // BIAS_D for red spectro  (0.02-0.06 V, default: 0.042 V)
    double bias_r_red = 0.01 in [0.0,1.0]; // BIAS_R for red spectro  (0-1 V, default: 0.01 V)
    double bias_d_blu = 0.1 in [0.06,0.12]; // BIAS_D for blue spectro (0.06-0.12 V, default: 0.100 V)
    double bias_r_blu = 0.01 in [0.0,1.0]; // BIAS_R for blue spectro (0-1 V, default: 0.01 V)
    int stab_time = 420; // Stabilisation time in seconds for the CRE setup
    /* Pointing Parameters */
    int npix = 13 in [1,25]; // Number of spatial pixel (lower left: 1,...,central: 13,...,upper right: 25)
    int naifid = 0; // NAIFID, if fast tracking is required (Fixed target: 0, Solar system object: >0)
    double ra = 0.0 in [0.0,360.0]; // RA [deg]
    double dec = 0.0 in [-90.0,+90.0]; // DEC [deg]
    /* End of needed variables for PacsCal_Spec_Star_Lin_Source */
}{
    //
    busconfig (7);
    // BURST MODE :     4:PACS PRIME  -  7:BURST MODE  - 8:PARALLEL MODE
    // Compute the time 
    //  Execute the pointing request
    bool execute = true;
    //  Slew
    int tslewmin = 0;
    //    Write OBSID during slew    
    int tOBSID = duration(WriteOBSID($OBSID));
    // no initial hold
    int tih = tOBSID;
    //  Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Star_Lin_Source(filter_pos,chopposition,gratingposition,ramp_len,observing_mode,detsel_table,ramps,capa_list,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,stab_time)));
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int column = (npix - 1) % 5;
    int row = (npix - 1) / 5;
    string pixnum = dformat(double(npix) - 1.0,0);
    debug_print("Detector column: " + column);
    debug_print("Detector row: " + row);
    double yoffset = dlookup("PacsTable_Spec_YZPixOffsets",pixnum,"delta_y");
    double zoffset = dlookup("PacsTable_Spec_YZPixOffsets",pixnum,"delta_z");
    debug_print("yoffset [arcsec]: " + yoffset);
    debug_print("zoffset [arcsec]: " + zoffset);
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(300.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Star_Lin_Source(filter_pos,chopposition,gratingposition,ramp_len,observing_mode,detsel_table,ramps,capa_list,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,stab_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// $Id: 
// Purpose       : Get wavelength at hisghest sensitivity as function of blue/red rage edges
//
// CUS author    : 
// Script file   : PacsSpecGetRefWave
//
// Input arguments
//
//
// Return values
//
// Version       : 0.1
// History       : 26-jan-2010 0.1  creation VD
//
double procedure PacsSpecGetRefWave {
    double bluWaveHspot = 0.0;
    double redWaveHspot = 0.0;
    string orderSel = "order2";
}{
    double[] rmsNoiseC = [0.0];
    double[] rmsNoiseL = [0.0];
    bool verbose = false;
    double[] wave = PacsSpecWaveArray(bluWaveHspot,redWaveHspot,verbose);
    // Integration time related variables
    // intTime is SRC/REF for chopping !!Each one, not the sum!!
    // For FreqSwitch, intTime is the total time LINE+REF  (assume we switch by a 
    // few pixels)
    // In either case, the "line" is the result of a subtraction (either SRC-REF 
    // or SRC - shiftedSRC). When both "SRC" and "REF" have the same rms, the RMS
    // increase introduced by the subtraction operation is sqrt(2). 
    // In raster/OFF, each raster point has a noise ONrms. However, the OFF position
    // is performed nbOFF times; its rms is OFFrms = ONrms/sqrt(nbOFF). The rms
    // of the difference is then sqrt(1 + 1/nbOFF) larger. Ignore for raster
    // for time being
    double difRMSfactor = sqrt(2.0);
    // Establish which sensitivity table shall be used
    // PHS-198 in parts: waveRef MUST be entered in order 1 parallel bands
    string sensTable = "TBD";
    string sensTablePar = "TBD";
    //    if(orderSel == "order1" || waveRef >= 103.1) {
    if(orderSel == "order1") {
        sensTable = "SPECContLine1";
        sensTablePar = "SPECContLine1";
    }
    if(orderSel == "order2" && bluWaveHspot < 102.0) {
        sensTable = "SPECContLine2";
        sensTablePar = "SPECContLine2";
    } else {
        if(orderSel == "order2" && bluWaveHspot >= 102.0) {
            sensTable = "SPECContLine2";
            sensTablePar = "SPECContLine1";
        }
    }
    if(orderSel == "order3" && bluWaveHspot < 102.0) {
        sensTable = "SPECContLine3";
        sensTablePar = "SPECContLine3";
    } else {
        if(orderSel == "order3" && bluWaveHspot >= 102.0) {
            sensTable = "SPECContLine3";
            sensTablePar = "SPECContLine1";
        }
    }
    if(orderSel == "order23" && bluWaveHspot < 102.0) {
        sensTable = "SPECContLine23";
        sensTablePar = "SPECContLine23";
    } else {
        if(orderSel == "order23" && bluWaveHspot >= 102.0) {
            sensTable = "SPECContLine23";
            sensTablePar = "SPECContLine1";
        }
    }
    if(verbose) {
        debug_print("AuxRMS in Nom band will use table " + sensTable);
        debug_print("AuxRMS in Par band will use table " + sensTablePar);
    }
    if(sensTable == "TBD") {
        error("Internal error: did not find proper sensitivity table");
    }
    // Get rms/sec from SPECcontline, a value per wavelength
    // Create CONT and LINE noise arrays; wave array already exists
    ///   if (verbose) {debug_print("AuxRMS:Wave Interpol From/To]: " 
    ///                          + wave[0] + "/" + wave[nbWaves-1]);}
    int nbWaves = length(wave);
    for(int loop0 = 0 .. nbWaves - 1) {
        //     Current wavelength
        double waveNow = wave[loop0];
        //     Get CONT and LINE rms values
        //     Use scale factor to convert into observed noise     
        rmsNoiseC[loop0] = interpolate(sensTable,"contRMS",waveNow);
        rmsNoiseL[loop0] = interpolate(sensTable,"lineRMS",waveNow);
    }
    // Find min and max of rmsNoiseC
    int[] minmax = PacsArrayMinMax(rmsNoiseC,verbose);
    //    double noiseCmin = rmsNoiseC[minmax[0]];
    double waveCmin = wave[minmax[0]];
    //    double noiseCmax = rmsNoiseC[minmax[1]];
    double waveCmax = wave[minmax[1]];
    // Find min and max of rmsNoiseL
    minmax = PacsArrayMinMax(rmsNoiseL,verbose);
    //  double noiseLmin = rmsNoiseL[minmax[0]];
    double waveLmin = wave[minmax[0]];
    //  double noiseLmax = rmsNoiseL[minmax[1]];
    double waveLmax = wave[minmax[1]];

    return waveLmax;
}

// Mission phase : Performance Verification Phase
//
// Purpose : PCD req.1.1.1 for the Performance Verification Phase
//           Check the bias/signal relationship using CSs and the central FOV
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowGainBias_direct
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   + Set the biases group by group
//   + Set the blue filter 100um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + Set the blue filter 70um
//   + Loop on CSs
//   +   Set the chopper on a CS
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +     Acquisition
//   + Set the chopper on the central FOV
//   + Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   +   Acquisition
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_PVph_lowGainBias(1, "LOW")
//            New version
//
// Version : Mon Jun 30 21:38:09 CEST 2008
//
procedure Phot_lowGainBias_direct {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_lowCSs"; // Bias table containing the final values
}{
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //***********************************************
    //***********************************************
    //
    // Bias setting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(startBiasTable,1);
    PHOT_set_bias_volt(startBiasTable,2);
    PHOT_set_bias_volt(startBiasTable,3);
    PHOT_set_bias_volt(startBiasTable,4);
    PHOT_set_bias_volt(startBiasTable,5);
    PHOT_set_bias_volt(startBiasTable,6);
    //
    //********************************************************
    // Sequence mode : blocking on VDEC_X for the direct mode
    //********************************************************
    //
    // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
    // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
    //
    //**************************
    // Sequence mode : Sref_only
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
    //# P 09 01 00 01
    int operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // Set gain low
    Pacs_BOLC_SET_GAIN("LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position -21350
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(-21350);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS1 at 48.0 K
    // corresponding to 1.20pW on the green and 5.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.2387937986138855 Volts
    Pacs_BOLC_SET_VH_G1(1.2387937986138855);
    // Set group 1 bol bias 02 (VL) to -0.01120620138611441 Volts
    Pacs_BOLC_SET_VL_G1(-0.01120620138611441);
    // Set group 1 bol bias 03 (VRL) to 0.39273766758961587 Volts
    Pacs_BOLC_SET_VRL_G1(0.39273766758961587);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1512820863099917 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1512820863099917);
    // Set group 2 bol bias 01 (VH) to 1.2273390654384582 Volts
    Pacs_BOLC_SET_VH_G2(1.2273390654384582);
    // Set group 2 bol bias 02 (VL) to -0.022660934561541744 Volts
    Pacs_BOLC_SET_VL_G2(-0.022660934561541744);
    // Set group 2 bol bias 03 (VRL) to 0.38921788688528014 Volts
    Pacs_BOLC_SET_VRL_G2(0.38921788688528014);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.147146340755748 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.147146340755748);
    // Set group 3 bol bias 01 (VH) to 1.2296951151089281 Volts
    Pacs_BOLC_SET_VH_G3(1.2296951151089281);
    // Set group 3 bol bias 02 (VL) to -0.020304884891071927 Volts
    Pacs_BOLC_SET_VL_G3(-0.020304884891071927);
    // Set group 3 bol bias 03 (VRL) to 0.3894736881379893 Volts
    Pacs_BOLC_SET_VRL_G3(0.3894736881379893);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.143754288741119 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.143754288741119);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.38519980225961764 Volts
    Pacs_BOLC_SET_VRL_G4(0.38519980225961764);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.141162817635055 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.141162817635055);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3228584222642352 Volts
    Pacs_BOLC_SET_VRL_G5(0.3228584222642352);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.067428073283575 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.067428073283575);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3146600782399116 Volts
    Pacs_BOLC_SET_VRL_G6(0.3146600782399116);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.057234963490994 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.057234963490994);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.457556831416261 Volts
    Pacs_BOLC_SET_VH_G1(1.457556831416261);
    // Set group 1 bol bias 02 (VL) to -0.14244316858373907 Volts
    Pacs_BOLC_SET_VL_G1(-0.14244316858373907);
    // Set group 1 bol bias 03 (VRL) to 0.39289728144635716 Volts
    Pacs_BOLC_SET_VRL_G1(0.39289728144635716);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151471417543995 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151471417543995);
    // Set group 2 bol bias 01 (VH) to 1.444087138537561 Volts
    Pacs_BOLC_SET_VH_G2(1.444087138537561);
    // Set group 2 bol bias 02 (VL) to -0.1559128614624391 Volts
    Pacs_BOLC_SET_VL_G2(-0.1559128614624391);
    // Set group 2 bol bias 03 (VRL) to 0.3888592125442133 Volts
    Pacs_BOLC_SET_VRL_G2(0.3888592125442133);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1467299681244416 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1467299681244416);
    // Set group 3 bol bias 01 (VH) to 1.4461276964721905 Volts
    Pacs_BOLC_SET_VH_G3(1.4461276964721905);
    // Set group 3 bol bias 02 (VL) to -0.15387230352780956 Volts
    Pacs_BOLC_SET_VL_G3(-0.15387230352780956);
    // Set group 3 bol bias 03 (VRL) to 0.389702653261631 Volts
    Pacs_BOLC_SET_VRL_G3(0.389702653261631);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1440068212666743 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1440068212666743);
    // Set group 4 bol bias 01 (VH) to 1.461535092163816 Volts
    Pacs_BOLC_SET_VH_G4(1.461535092163816);
    // Set group 4 bol bias 02 (VL) to -0.13846490783618415 Volts
    Pacs_BOLC_SET_VL_G4(-0.13846490783618415);
    // Set group 4 bol bias 03 (VRL) to 0.38666891513104484 Volts
    Pacs_BOLC_SET_VRL_G4(0.38666891513104484);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1428402830030913 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1428402830030913);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.393205233420548 Volts
    Pacs_BOLC_SET_VRL_G5(0.393205233420548);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.144845482323282 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.144845482323282);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3832953489422562 Volts
    Pacs_BOLC_SET_VRL_G6(0.3832953489422562);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.130607584787264 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.130607584787264);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.585769661368119 Volts
    Pacs_BOLC_SET_VH_G1(1.585769661368119);
    // Set group 1 bol bias 02 (VL) to -0.214230338631881 Volts
    Pacs_BOLC_SET_VL_G1(-0.214230338631881);
    // Set group 1 bol bias 03 (VRL) to 0.39304515064751266 Volts
    Pacs_BOLC_SET_VRL_G1(0.39304515064751266);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151646819089764 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151646819089764);
    // Set group 2 bol bias 01 (VH) to 1.571162518585341 Volts
    Pacs_BOLC_SET_VH_G2(1.571162518585341);
    // Set group 2 bol bias 02 (VL) to -0.22883748141465898 Volts
    Pacs_BOLC_SET_VL_G2(-0.22883748141465898);
    // Set group 2 bol bias 03 (VRL) to 0.3888194923923588 Volts
    Pacs_BOLC_SET_VRL_G2(0.3888194923923588);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1466838588402206 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1466838588402206);
    // Set group 3 bol bias 01 (VH) to 1.5728976206374763 Volts
    Pacs_BOLC_SET_VH_G3(1.5728976206374763);
    // Set group 3 bol bias 02 (VL) to -0.22710237936252387 Volts
    Pacs_BOLC_SET_VL_G3(-0.22710237936252387);
    // Set group 3 bol bias 03 (VRL) to 0.39016220909623334 Volts
    Pacs_BOLC_SET_VRL_G3(0.39016220909623334);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144513683272569 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144513683272569);
    // Set group 4 bol bias 01 (VH) to 1.5905884509492139 Volts
    Pacs_BOLC_SET_VH_G4(1.5905884509492139);
    // Set group 4 bol bias 02 (VL) to -0.2094115490507863 Volts
    Pacs_BOLC_SET_VL_G4(-0.2094115490507863);
    // Set group 4 bol bias 03 (VRL) to 0.38773283476462383 Volts
    Pacs_BOLC_SET_VRL_G4(0.38773283476462383);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440552130411823 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440552130411823);
    // Set group 5 bol bias 01 (VH) to 1.3241923646302258 Volts
    Pacs_BOLC_SET_VH_G5(1.3241923646302258);
    // Set group 5 bol bias 02 (VL) to -0.07580763536977406 Volts
    Pacs_BOLC_SET_VL_G5(-0.07580763536977406);
    // Set group 5 bol bias 03 (VRL) to 0.40046001102514184 Volts
    Pacs_BOLC_SET_VRL_G5(0.40046001102514184);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.153546375049013 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.153546375049013);
    // Set group 6 bol bias 01 (VH) to 1.37098688511416 Volts
    Pacs_BOLC_SET_VH_G6(1.37098688511416);
    // Set group 6 bol bias 02 (VL) to -0.02901311488583999 Volts
    Pacs_BOLC_SET_VL_G6(-0.02901311488583999);
    // Set group 6 bol bias 03 (VRL) to 0.43611847195239406 Volts
    Pacs_BOLC_SET_VRL_G6(0.43611847195239406);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1943115490461103 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1943115490461103);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7183370767248043 Volts
    Pacs_BOLC_SET_VH_G1(1.7183370767248043);
    // Set group 1 bol bias 02 (VL) to -0.2816629232751957 Volts
    Pacs_BOLC_SET_VL_G1(-0.2816629232751957);
    // Set group 1 bol bias 03 (VRL) to 0.39272615099525776 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272615099525776);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151268425592528 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151268425592528);
    // Set group 2 bol bias 01 (VH) to 1.7019559750109217 Volts
    Pacs_BOLC_SET_VH_G2(1.7019559750109217);
    // Set group 2 bol bias 02 (VL) to -0.29804402498907834 Volts
    Pacs_BOLC_SET_VL_G2(-0.29804402498907834);
    // Set group 2 bol bias 03 (VRL) to 0.388357028089395 Volts
    Pacs_BOLC_SET_VRL_G2(0.388357028089395);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461470122884805 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461470122884805);
    // Set group 3 bol bias 01 (VH) to 1.714454188425701 Volts
    Pacs_BOLC_SET_VH_G3(1.714454188425701);
    // Set group 3 bol bias 02 (VL) to -0.2855458115742991 Volts
    Pacs_BOLC_SET_VL_G3(-0.2855458115742991);
    // Set group 3 bol bias 03 (VRL) to 0.401550404399907 Volts
    Pacs_BOLC_SET_VRL_G3(0.401550404399907);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.15707892246005 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.15707892246005);
    // Set group 4 bol bias 01 (VH) to 1.7242793470756728 Volts
    Pacs_BOLC_SET_VH_G4(1.7242793470756728);
    // Set group 4 bol bias 02 (VL) to -0.27572065292432724 Volts
    Pacs_BOLC_SET_VL_G4(-0.27572065292432724);
    // Set group 4 bol bias 03 (VRL) to 0.3889940535267571 Volts
    Pacs_BOLC_SET_VRL_G4(0.3889940535267571);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454955805079967 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454955805079967);
    // Set group 5 bol bias 01 (VH) to 1.4496153041151667 Volts
    Pacs_BOLC_SET_VH_G5(1.4496153041151667);
    // Set group 5 bol bias 02 (VL) to -0.15038469588483347 Volts
    Pacs_BOLC_SET_VL_G5(-0.15038469588483347);
    // Set group 5 bol bias 03 (VRL) to 0.39905723488551603 Volts
    Pacs_BOLC_SET_VRL_G5(0.39905723488551603);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.15186471364944 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.15186471364944);
    // Set group 6 bol bias 01 (VH) to 1.4970241024935167 Volts
    Pacs_BOLC_SET_VH_G6(1.4970241024935167);
    // Set group 6 bol bias 02 (VL) to -0.10297589750648331 Volts
    Pacs_BOLC_SET_VL_G6(-0.10297589750648331);
    // Set group 6 bol bias 03 (VRL) to 0.43401661473441144 Volts
    Pacs_BOLC_SET_VRL_G6(0.43401661473441144);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1918048548715423 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1918048548715423);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8585362347937342 Volts
    Pacs_BOLC_SET_VH_G1(1.8585362347937342);
    // Set group 1 bol bias 02 (VL) to -0.34146376520626587 Volts
    Pacs_BOLC_SET_VL_G1(-0.34146376520626587);
    // Set group 1 bol bias 03 (VRL) to 0.3925990888065586 Volts
    Pacs_BOLC_SET_VRL_G1(0.3925990888065586);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1511177079955788 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1511177079955788);
    // Set group 2 bol bias 01 (VH) to 1.838716500789082 Volts
    Pacs_BOLC_SET_VH_G2(1.838716500789082);
    // Set group 2 bol bias 02 (VL) to -0.3612834992109183 Volts
    Pacs_BOLC_SET_VL_G2(-0.3612834992109183);
    // Set group 2 bol bias 03 (VRL) to 0.38744902130448367 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744902130448367);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1450929993071512 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1450929993071512);
    // Set group 3 bol bias 01 (VH) to 1.85163190367321 Volts
    Pacs_BOLC_SET_VH_G3(1.85163190367321);
    // Set group 3 bol bias 02 (VL) to -0.34836809632679006 Volts
    Pacs_BOLC_SET_VL_G3(-0.34836809632679006);
    // Set group 3 bol bias 03 (VRL) to 0.4020826639883897 Volts
    Pacs_BOLC_SET_VRL_G3(0.4020826639883897);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157667831933953 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157667831933953);
    // Set group 4 bol bias 01 (VH) to 1.8658389594227858 Volts
    Pacs_BOLC_SET_VH_G4(1.8658389594227858);
    // Set group 4 bol bias 02 (VL) to -0.3341610405772144 Volts
    Pacs_BOLC_SET_VL_G4(-0.3341610405772144);
    // Set group 4 bol bias 03 (VRL) to 0.39087822103495706 Volts
    Pacs_BOLC_SET_VRL_G4(0.39087822103495706);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1476476539739764 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1476476539739764);
    // Set group 5 bol bias 01 (VH) to 1.5144117466818523 Volts
    Pacs_BOLC_SET_VH_G5(1.5144117466818523);
    // Set group 5 bol bias 02 (VL) to -0.18558825331814774 Volts
    Pacs_BOLC_SET_VL_G5(-0.18558825331814774);
    // Set group 5 bol bias 03 (VRL) to 0.39841417525779244 Volts
    Pacs_BOLC_SET_VRL_G5(0.39841417525779244);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151093482383656 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151093482383656);
    // Set group 6 bol bias 01 (VH) to 1.5622243148794812 Volts
    Pacs_BOLC_SET_VH_G6(1.5622243148794812);
    // Set group 6 bol bias 02 (VL) to -0.13777568512051877 Volts
    Pacs_BOLC_SET_VL_G6(-0.13777568512051877);
    // Set group 6 bol bias 03 (VRL) to 0.43327546525989336 Volts
    Pacs_BOLC_SET_VRL_G6(0.43327546525989336);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1909210235812204 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1909210235812204);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0202028596068895 Volts
    Pacs_BOLC_SET_VH_G1(2.0202028596068895);
    // Set group 1 bol bias 02 (VL) to -0.3797971403931106 Volts
    Pacs_BOLC_SET_VL_G1(-0.3797971403931106);
    // Set group 1 bol bias 03 (VRL) to 0.4031554178502121 Volts
    Pacs_BOLC_SET_VRL_G1(0.4031554178502121);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163634915975391 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163634915975391);
    // Set group 2 bol bias 01 (VH) to 1.9845954458032045 Volts
    Pacs_BOLC_SET_VH_G2(1.9845954458032045);
    // Set group 2 bol bias 02 (VL) to -0.41540455419679545 Volts
    Pacs_BOLC_SET_VL_G2(-0.41540455419679545);
    // Set group 2 bol bias 03 (VRL) to 0.38611513204716796 Volts
    Pacs_BOLC_SET_VRL_G2(0.38611513204716796);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1435447105412555 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1435447105412555);
    // Set group 3 bol bias 01 (VH) to 2.0091673911193446 Volts
    Pacs_BOLC_SET_VH_G3(2.0091673911193446);
    // Set group 3 bol bias 02 (VL) to -0.39083260888065513 Volts
    Pacs_BOLC_SET_VL_G3(-0.39083260888065513);
    // Set group 3 bol bias 03 (VRL) to 0.4135751200095534 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135751200095534);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170378532407885 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170378532407885);
    // Set group 4 bol bias 01 (VH) to 2.0158037297874873 Volts
    Pacs_BOLC_SET_VH_G4(2.0158037297874873);
    // Set group 4 bol bias 02 (VL) to -0.3841962702125128 Volts
    Pacs_BOLC_SET_VL_G4(-0.3841962702125128);
    // Set group 4 bol bias 03 (VRL) to 0.3915724280149063 Volts
    Pacs_BOLC_SET_VRL_G4(0.3915724280149063);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1484406507127387 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1484406507127387);
    // Set group 5 bol bias 01 (VH) to 1.5900913542685013 Volts
    Pacs_BOLC_SET_VH_G5(1.5900913542685013);
    // Set group 5 bol bias 02 (VL) to -0.20990864573149876 Volts
    Pacs_BOLC_SET_VL_G5(-0.20990864573149876);
    // Set group 5 bol bias 03 (VRL) to 0.40844955554354584 Volts
    Pacs_BOLC_SET_VRL_G5(0.40844955554354584);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.163093126853995 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.163093126853995);
    // Set group 6 bol bias 01 (VH) to 1.6276124853923464 Volts
    Pacs_BOLC_SET_VH_G6(1.6276124853923464);
    // Set group 6 bol bias 02 (VL) to -0.17238751460765359 Volts
    Pacs_BOLC_SET_VL_G6(-0.17238751460765359);
    // Set group 6 bol bias 03 (VRL) to 0.43216415132235575 Volts
    Pacs_BOLC_SET_VRL_G6(0.43216415132235575);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1895819441738285 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1895819441738285);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.1116098904579044 Volts
    Pacs_BOLC_SET_VH_G1(2.1116098904579044);
    // Set group 1 bol bias 02 (VL) to -0.3883901095420957 Volts
    Pacs_BOLC_SET_VL_G1(-0.3883901095420957);
    // Set group 1 bol bias 03 (VRL) to 0.4140062165204889 Volts
    Pacs_BOLC_SET_VRL_G1(0.4140062165204889);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1764790937594767 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1764790937594767);
    // Set group 2 bol bias 01 (VH) to 2.0619437696054 Volts
    Pacs_BOLC_SET_VH_G2(2.0619437696054);
    // Set group 2 bol bias 02 (VL) to -0.43805623039459973 Volts
    Pacs_BOLC_SET_VL_G2(-0.43805623039459973);
    // Set group 2 bol bias 03 (VRL) to 0.38550512685952865 Volts
    Pacs_BOLC_SET_VRL_G2(0.38550512685952865);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1428366925092326 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1428366925092326);
    // Set group 3 bol bias 01 (VH) to 2.0871836925661524 Volts
    Pacs_BOLC_SET_VH_G3(2.0871836925661524);
    // Set group 3 bol bias 02 (VL) to -0.4128163074338474 Volts
    Pacs_BOLC_SET_VL_G3(-0.4128163074338474);
    // Set group 3 bol bias 03 (VRL) to 0.41367957243777737 Volts
    Pacs_BOLC_SET_VRL_G3(0.41367957243777737);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704940139980216 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704940139980216);
    // Set group 4 bol bias 01 (VH) to 2.095481525504912 Volts
    Pacs_BOLC_SET_VH_G4(2.095481525504912);
    // Set group 4 bol bias 02 (VL) to -0.40451847449508793 Volts
    Pacs_BOLC_SET_VL_G4(-0.40451847449508793);
    // Set group 4 bol bias 03 (VRL) to 0.3918611768543646 Volts
    Pacs_BOLC_SET_VRL_G4(0.3918611768543646);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.148770503204217 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.148770503204217);
    // Set group 5 bol bias 01 (VH) to 1.6549108970361488 Volts
    Pacs_BOLC_SET_VH_G5(1.6549108970361488);
    // Set group 5 bol bias 02 (VL) to -0.24508910296385117 Volts
    Pacs_BOLC_SET_VL_G5(-0.24508910296385117);
    // Set group 5 bol bias 03 (VRL) to 0.4072430925044988 Volts
    Pacs_BOLC_SET_VRL_G5(0.4072430925044988);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161651131887083 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161651131887083);
    // Set group 6 bol bias 01 (VH) to 1.6931168196610022 Volts
    Pacs_BOLC_SET_VH_G6(1.6931168196610022);
    // Set group 6 bol bias 02 (VL) to -0.20688318033899758 Volts
    Pacs_BOLC_SET_VL_G6(-0.20688318033899758);
    // Set group 6 bol bias 03 (VRL) to 0.4307551048853343 Volts
    Pacs_BOLC_SET_VRL_G6(0.4307551048853343);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187881524411063 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187881524411063);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.196006753214598 Volts
    Pacs_BOLC_SET_VH_G1(2.196006753214598);
    // Set group 1 bol bias 02 (VL) to -0.4039932467854021 Volts
    Pacs_BOLC_SET_VL_G1(-0.4039932467854021);
    // Set group 1 bol bias 03 (VRL) to 0.41357184702417576 Volts
    Pacs_BOLC_SET_VRL_G1(0.41357184702417576);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1759648938728384 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1759648938728384);
    // Set group 2 bol bias 01 (VH) to 2.1433243650504217 Volts
    Pacs_BOLC_SET_VH_G2(2.1433243650504217);
    // Set group 2 bol bias 02 (VL) to -0.45667563494957836 Volts
    Pacs_BOLC_SET_VL_G2(-0.45667563494957836);
    // Set group 2 bol bias 03 (VRL) to 0.3850880425693594 Volts
    Pacs_BOLC_SET_VRL_G2(0.3850880425693594);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14235260562423 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14235260562423);
    // Set group 3 bol bias 01 (VH) to 2.1686669393324536 Volts
    Pacs_BOLC_SET_VH_G3(2.1686669393324536);
    // Set group 3 bol bias 02 (VL) to -0.43133306066754634 Volts
    Pacs_BOLC_SET_VL_G3(-0.43133306066754634);
    // Set group 3 bol bias 03 (VRL) to 0.41346974712361556 Volts
    Pacs_BOLC_SET_VRL_G3(0.41346974712361556);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.17026203238048 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.17026203238048);
    // Set group 4 bol bias 01 (VH) to 2.1793962970285237 Volts
    Pacs_BOLC_SET_VH_G4(2.1793962970285237);
    // Set group 4 bol bias 02 (VL) to -0.42060370297147653 Volts
    Pacs_BOLC_SET_VL_G4(-0.42060370297147653);
    // Set group 4 bol bias 03 (VRL) to 0.39239244557899233 Volts
    Pacs_BOLC_SET_VRL_G4(0.39239244557899233);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.149377418431709 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.149377418431709);
    // Set group 5 bol bias 01 (VH) to 1.7225616727109463 Volts
    Pacs_BOLC_SET_VH_G5(1.7225616727109463);
    // Set group 5 bol bias 02 (VL) to -0.27743832728905365 Volts
    Pacs_BOLC_SET_VL_G5(-0.27743832728905365);
    // Set group 5 bol bias 03 (VRL) to 0.40580736393386424 Volts
    Pacs_BOLC_SET_VRL_G5(0.40580736393386424);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.159935285624683 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.159935285624683);
    // Set group 6 bol bias 01 (VH) to 1.7622827443723812 Volts
    Pacs_BOLC_SET_VH_G6(1.7622827443723812);
    // Set group 6 bol bias 02 (VL) to -0.23771725562761872 Volts
    Pacs_BOLC_SET_VL_G6(-0.23771725562761872);
    // Set group 6 bol bias 03 (VRL) to 0.4298269773716583 Volts
    Pacs_BOLC_SET_VRL_G6(0.4298269773716583);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1867614355291423 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1867614355291423);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2848572542958143 Volts
    Pacs_BOLC_SET_VH_G1(2.2848572542958143);
    // Set group 1 bol bias 02 (VL) to -0.4151427457041857 Volts
    Pacs_BOLC_SET_VL_G1(-0.4151427457041857);
    // Set group 1 bol bias 03 (VRL) to 0.4131612503913013 Volts
    Pacs_BOLC_SET_VRL_G1(0.4131612503913013);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175478838481054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175478838481054);
    // Set group 2 bol bias 01 (VH) to 2.227445675456437 Volts
    Pacs_BOLC_SET_VH_G2(2.227445675456437);
    // Set group 2 bol bias 02 (VL) to -0.47255432454356333 Volts
    Pacs_BOLC_SET_VL_G2(-0.47255432454356333);
    // Set group 2 bol bias 03 (VRL) to 0.38358395077791313 Volts
    Pacs_BOLC_SET_VRL_G2(0.38358395077791313);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1406069736852453 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1406069736852453);
    // Set group 3 bol bias 01 (VH) to 2.2541010275551834 Volts
    Pacs_BOLC_SET_VH_G3(2.2541010275551834);
    // Set group 3 bol bias 02 (VL) to -0.4458989724448167 Volts
    Pacs_BOLC_SET_VL_G3(-0.4458989724448167);
    // Set group 3 bol bias 03 (VRL) to 0.4127976284436742 Volts
    Pacs_BOLC_SET_VRL_G3(0.4127976284436742);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1695189208400576 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1695189208400576);
    // Set group 4 bol bias 01 (VH) to 2.2792127013060117 Volts
    Pacs_BOLC_SET_VH_G4(2.2792127013060117);
    // Set group 4 bol bias 02 (VL) to -0.4207872986939883 Volts
    Pacs_BOLC_SET_VL_G4(-0.4207872986939883);
    // Set group 4 bol bias 03 (VRL) to 0.4047407291500576 Volts
    Pacs_BOLC_SET_VRL_G4(0.4047407291500576);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1634937911711 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1634937911711);
    // Set group 5 bol bias 01 (VH) to 1.8021521044604545 Volts
    Pacs_BOLC_SET_VH_G5(1.8021521044604545);
    // Set group 5 bol bias 02 (VL) to -0.2978478955395457 Volts
    Pacs_BOLC_SET_VL_G5(-0.2978478955395457);
    // Set group 5 bol bias 03 (VRL) to 0.4159065601971136 Volts
    Pacs_BOLC_SET_VRL_G5(0.4159065601971136);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.17200886747967 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.17200886747967);
    // Set group 6 bol bias 01 (VH) to 1.8316635864270032 Volts
    Pacs_BOLC_SET_VH_G6(1.8316635864270032);
    // Set group 6 bol bias 02 (VL) to -0.26833641357299687 Volts
    Pacs_BOLC_SET_VL_G6(-0.26833641357299687);
    // Set group 6 bol bias 03 (VRL) to 0.4288145963722081 Volts
    Pacs_BOLC_SET_VRL_G6(0.4288145963722081);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.185539634602432 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.185539634602432);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3796037366573897 Volts
    Pacs_BOLC_SET_VH_G1(2.3796037366573897);
    // Set group 1 bol bias 02 (VL) to -0.4203962633426101 Volts
    Pacs_BOLC_SET_VL_G1(-0.4203962633426101);
    // Set group 1 bol bias 03 (VRL) to 0.4129099400989898 Volts
    Pacs_BOLC_SET_VRL_G1(0.4129099400989898);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175181344026924 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175181344026924);
    // Set group 2 bol bias 01 (VH) to 2.315754480139234 Volts
    Pacs_BOLC_SET_VH_G2(2.315754480139234);
    // Set group 2 bol bias 02 (VL) to -0.4842455198607661 Volts
    Pacs_BOLC_SET_VL_G2(-0.4842455198607661);
    // Set group 2 bol bias 03 (VRL) to 0.38156757008948644 Volts
    Pacs_BOLC_SET_VRL_G2(0.38156757008948644);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.138266993828065 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.138266993828065);
    // Set group 3 bol bias 01 (VH) to 2.3449665772192874 Volts
    Pacs_BOLC_SET_VH_G3(2.3449665772192874);
    // Set group 3 bol bias 02 (VL) to -0.45503342278071257 Volts
    Pacs_BOLC_SET_VL_G3(-0.45503342278071257);
    // Set group 3 bol bias 03 (VRL) to 0.4122322683327103 Volts
    Pacs_BOLC_SET_VRL_G3(0.4122322683327103);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1688938193526224 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1688938193526224);
    // Set group 4 bol bias 01 (VH) to 2.360152158437928 Volts
    Pacs_BOLC_SET_VH_G4(2.360152158437928);
    // Set group 4 bol bias 02 (VL) to -0.4398478415620719 Volts
    Pacs_BOLC_SET_VL_G4(-0.4398478415620719);
    // Set group 4 bol bias 03 (VRL) to 0.39354738531821554 Volts
    Pacs_BOLC_SET_VRL_G4(0.39354738531821554);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150696897295742 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150696897295742);
    // Set group 5 bol bias 01 (VH) to 1.8624422796333608 Volts
    Pacs_BOLC_SET_VH_G5(1.8624422796333608);
    // Set group 5 bol bias 02 (VL) to -0.3375577203666393 Volts
    Pacs_BOLC_SET_VL_G5(-0.3375577203666393);
    // Set group 5 bol bias 03 (VRL) to 0.4028017551941114 Volts
    Pacs_BOLC_SET_VRL_G5(0.4028017551941114);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.156343875220547 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.156343875220547);
    // Set group 6 bol bias 01 (VH) to 1.9050654119965236 Volts
    Pacs_BOLC_SET_VH_G6(1.9050654119965236);
    // Set group 6 bol bias 02 (VL) to -0.2949345880034766 Volts
    Pacs_BOLC_SET_VL_G6(-0.2949345880034766);
    // Set group 6 bol bias 03 (VRL) to 0.42788441761189455 Volts
    Pacs_BOLC_SET_VRL_G6(0.42788441761189455);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1844170100895375 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1844170100895375);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6080079699591967 Volts
    Pacs_BOLC_SET_VH_G1(2.6080079699591967);
    // Set group 1 bol bias 02 (VL) to -0.39199203004080335 Volts
    Pacs_BOLC_SET_VL_G1(-0.39199203004080335);
    // Set group 1 bol bias 03 (VRL) to 0.4353039674693117 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353039674693117);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2016826896367014 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2016826896367014);
    // Set group 2 bol bias 01 (VH) to 2.5212704911688184 Volts
    Pacs_BOLC_SET_VH_G2(2.5212704911688184);
    // Set group 2 bol bias 02 (VL) to -0.4787295088311815 Volts
    Pacs_BOLC_SET_VL_G2(-0.4787295088311815);
    // Set group 2 bol bias 03 (VRL) to 0.39184175711517744 Volts
    Pacs_BOLC_SET_VRL_G2(0.39184175711517744);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150192531202592 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150192531202592);
    // Set group 3 bol bias 01 (VH) to 2.5446946302676037 Volts
    Pacs_BOLC_SET_VH_G3(2.5446946302676037);
    // Set group 3 bol bias 02 (VL) to -0.4553053697323962 Volts
    Pacs_BOLC_SET_VL_G3(-0.4553053697323962);
    // Set group 3 bol bias 03 (VRL) to 0.41118382754245053 Volts
    Pacs_BOLC_SET_VRL_G3(0.41118382754245053);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1677345299207764 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1677345299207764);
    // Set group 4 bol bias 01 (VH) to 2.582263974911207 Volts
    Pacs_BOLC_SET_VH_G4(2.582263974911207);
    // Set group 4 bol bias 02 (VL) to -0.4177360250887929 Volts
    Pacs_BOLC_SET_VL_G4(-0.4177360250887929);
    // Set group 4 bol bias 03 (VRL) to 0.4155747259799741 Volts
    Pacs_BOLC_SET_VRL_G4(0.4155747259799741);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1758807093660604 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1758807093660604);
    // Set group 5 bol bias 01 (VH) to 2.0139550919820626 Volts
    Pacs_BOLC_SET_VH_G5(2.0139550919820626);
    // Set group 5 bol bias 02 (VL) to -0.38604490801793717 Volts
    Pacs_BOLC_SET_VL_G5(-0.38604490801793717);
    // Set group 5 bol bias 03 (VRL) to 0.39874967908065667 Volts
    Pacs_BOLC_SET_VRL_G5(0.39874967908065667);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151495860090233 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151495860090233);
    // Set group 6 bol bias 01 (VH) to 2.0603593375586526 Volts
    Pacs_BOLC_SET_VH_G6(2.0603593375586526);
    // Set group 6 bol bias 02 (VL) to -0.3396406624413473 Volts
    Pacs_BOLC_SET_VL_G6(-0.3396406624413473);
    // Set group 6 bol bias 03 (VRL) to 0.4254561262075288 Volts
    Pacs_BOLC_SET_VRL_G6(0.4254561262075288);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1814861909041072 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1814861909041072);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.958669888952511 Volts
    Pacs_BOLC_SET_VH_G1(2.958669888952511);
    // Set group 1 bol bias 02 (VL) to -0.3413301110474886 Volts
    Pacs_BOLC_SET_VL_G1(-0.3413301110474886);
    // Set group 1 bol bias 03 (VRL) to 0.43496400697889964 Volts
    Pacs_BOLC_SET_VRL_G1(0.43496400697889964);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201282516353445 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201282516353445);
    // Set group 2 bol bias 01 (VH) to 2.877259199990068 Volts
    Pacs_BOLC_SET_VH_G2(2.877259199990068);
    // Set group 2 bol bias 02 (VL) to -0.4227408000099317 Volts
    Pacs_BOLC_SET_VL_G2(-0.4227408000099317);
    // Set group 2 bol bias 03 (VRL) to 0.41471523343174815 Volts
    Pacs_BOLC_SET_VRL_G2(0.41471523343174815);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1767077990321737 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1767077990321737);
    // Set group 3 bol bias 01 (VH) to 2.917604872367548 Volts
    Pacs_BOLC_SET_VH_G3(2.917604872367548);
    // Set group 3 bol bias 02 (VL) to -0.38239512763245215 Volts
    Pacs_BOLC_SET_VL_G3(-0.38239512763245215);
    // Set group 3 bol bias 03 (VRL) to 0.43322793583509106 Volts
    Pacs_BOLC_SET_VRL_G3(0.43322793583509106);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1920928084003948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1920928084003948);
    // Set group 4 bol bias 01 (VH) to 2.9326607124177055 Volts
    Pacs_BOLC_SET_VH_G4(2.9326607124177055);
    // Set group 4 bol bias 02 (VL) to -0.36733928758229417 Volts
    Pacs_BOLC_SET_VL_G4(-0.36733928758229417);
    // Set group 4 bol bias 03 (VRL) to 0.4248388375312061 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248388375312061);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.186464990521523 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.186464990521523);
    // Set group 5 bol bias 01 (VH) to 2.2123399887514554 Volts
    Pacs_BOLC_SET_VH_G5(2.2123399887514554);
    // Set group 5 bol bias 02 (VL) to -0.38766001124854466 Volts
    Pacs_BOLC_SET_VL_G5(-0.38766001124854466);
    // Set group 5 bol bias 03 (VRL) to 0.4257278403385899 Volts
    Pacs_BOLC_SET_VRL_G5(0.4257278403385899);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1837591130416554 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1837591130416554);
    // Set group 6 bol bias 01 (VH) to 2.2318001783201304 Volts
    Pacs_BOLC_SET_VH_G6(2.2318001783201304);
    // Set group 6 bol bias 02 (VL) to -0.36819982167986975 Volts
    Pacs_BOLC_SET_VL_G6(-0.36819982167986975);
    // Set group 6 bol bias 03 (VRL) to 0.423759377774352 Volts
    Pacs_BOLC_SET_VRL_G6(0.423759377774352);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1794381888209813 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1794381888209813);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //**********************************************
    // Set the PACS chopper at the position 21200
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(21200);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS2 at 58.0 K
    // corresponding to 1.55pW on the green and 6.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38123347242944194 Volts
    Pacs_BOLC_SET_VRL_G1(0.38123347242944194);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1376407910122737 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1376407910122737);
    // Set group 2 bol bias 01 (VH) to 1.2387003199108486 Volts
    Pacs_BOLC_SET_VH_G2(1.2387003199108486);
    // Set group 2 bol bias 02 (VL) to -0.011299680089151297 Volts
    Pacs_BOLC_SET_VL_G2(-0.011299680089151297);
    // Set group 2 bol bias 03 (VRL) to 0.3885454558920056 Volts
    Pacs_BOLC_SET_VRL_G2(0.3885454558920056);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146365745091845 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146365745091845);
    // Set group 3 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G3(1.24);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.38773615773066705 Volts
    Pacs_BOLC_SET_VRL_G3(0.38773615773066705);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.141837957849939 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.141837957849939);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3746747870084728 Volts
    Pacs_BOLC_SET_VRL_G4(0.3746747870084728);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1291508925975227 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1291508925975227);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.30644740182478597 Volts
    Pacs_BOLC_SET_VRL_G5(0.30644740182478597);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051135159732571 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051135159732571);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.29823090263814045 Volts
    Pacs_BOLC_SET_VRL_G6(0.29823090263814045);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0409569182979173 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0409569182979173);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4721285832931112 Volts
    Pacs_BOLC_SET_VH_G1(1.4721285832931112);
    // Set group 1 bol bias 02 (VL) to -0.12787141670688873 Volts
    Pacs_BOLC_SET_VL_G1(-0.12787141670688873);
    // Set group 1 bol bias 03 (VRL) to 0.3926297476827718 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926297476827718);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151154074587398 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151154074587398);
    // Set group 2 bol bias 01 (VH) to 1.4563242224495716 Volts
    Pacs_BOLC_SET_VH_G2(1.4563242224495716);
    // Set group 2 bol bias 02 (VL) to -0.14367577755042849 Volts
    Pacs_BOLC_SET_VL_G2(-0.14367577755042849);
    // Set group 2 bol bias 03 (VRL) to 0.3881765529411487 Volts
    Pacs_BOLC_SET_VRL_G2(0.3881765529411487);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.145937513130471 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.145937513130471);
    // Set group 3 bol bias 01 (VH) to 1.45972772124239 Volts
    Pacs_BOLC_SET_VH_G3(1.45972772124239);
    // Set group 3 bol bias 02 (VL) to -0.14027227875761006 Volts
    Pacs_BOLC_SET_VL_G3(-0.14027227875761006);
    // Set group 3 bol bias 03 (VRL) to 0.38988919840997094 Volts
    Pacs_BOLC_SET_VRL_G3(0.38988919840997094);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1442125685158864 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1442125685158864);
    // Set group 4 bol bias 01 (VH) to 1.4747276174033868 Volts
    Pacs_BOLC_SET_VH_G4(1.4747276174033868);
    // Set group 4 bol bias 02 (VL) to -0.12527238259661322 Volts
    Pacs_BOLC_SET_VL_G4(-0.12527238259661322);
    // Set group 4 bol bias 03 (VRL) to 0.38624222870786595 Volts
    Pacs_BOLC_SET_VRL_G4(0.38624222870786595);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1423530627314813 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1423530627314813);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3734713392363535 Volts
    Pacs_BOLC_SET_VRL_G5(0.3734713392363535);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1211616404276756 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1211616404276756);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3640870527167945 Volts
    Pacs_BOLC_SET_VRL_G6(0.3640870527167945);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1074512769294307 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1074512769294307);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.6005646067625168 Volts
    Pacs_BOLC_SET_VH_G1(1.6005646067625168);
    // Set group 1 bol bias 02 (VL) to -0.19943539323748327 Volts
    Pacs_BOLC_SET_VL_G1(-0.19943539323748327);
    // Set group 1 bol bias 03 (VRL) to 0.3927137250656313 Volts
    Pacs_BOLC_SET_VRL_G1(0.3927137250656313);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1512536862532445 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1512536862532445);
    // Set group 2 bol bias 01 (VH) to 1.5835245401299414 Volts
    Pacs_BOLC_SET_VH_G2(1.5835245401299414);
    // Set group 2 bol bias 02 (VL) to -0.21647545987005867 Volts
    Pacs_BOLC_SET_VL_G2(-0.21647545987005867);
    // Set group 2 bol bias 03 (VRL) to 0.3880497715778095 Volts
    Pacs_BOLC_SET_VRL_G2(0.3880497715778095);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1457903439369534 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1457903439369534);
    // Set group 3 bol bias 01 (VH) to 1.5867464604266623 Volts
    Pacs_BOLC_SET_VH_G3(1.5867464604266623);
    // Set group 3 bol bias 02 (VL) to -0.2132535395733377 Volts
    Pacs_BOLC_SET_VL_G3(-0.2132535395733377);
    // Set group 3 bol bias 03 (VRL) to 0.3903025295231384 Volts
    Pacs_BOLC_SET_VRL_G3(0.3903025295231384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144668449205875 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144668449205875);
    // Set group 4 bol bias 01 (VH) to 1.6044364991789073 Volts
    Pacs_BOLC_SET_VH_G4(1.6044364991789073);
    // Set group 4 bol bias 02 (VL) to -0.19556350082109264 Volts
    Pacs_BOLC_SET_VL_G4(-0.19556350082109264);
    // Set group 4 bol bias 03 (VRL) to 0.387662053519384 Volts
    Pacs_BOLC_SET_VRL_G4(0.387662053519384);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1439743820479262 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1439743820479262);
    // Set group 5 bol bias 01 (VH) to 1.3451907640885556 Volts
    Pacs_BOLC_SET_VH_G5(1.3451907640885556);
    // Set group 5 bol bias 02 (VL) to -0.054809235911444244 Volts
    Pacs_BOLC_SET_VL_G5(-0.054809235911444244);
    // Set group 5 bol bias 03 (VRL) to 0.40021084689056974 Volts
    Pacs_BOLC_SET_VRL_G5(0.40021084689056974);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1532482013507512 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1532482013507512);
    // Set group 6 bol bias 01 (VH) to 1.39 Volts
    Pacs_BOLC_SET_VH_G6(1.39);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.4344512926668127 Volts
    Pacs_BOLC_SET_VRL_G6(0.4344512926668127);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.192323231555507 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.192323231555507);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7330644465100378 Volts
    Pacs_BOLC_SET_VH_G1(1.7330644465100378);
    // Set group 1 bol bias 02 (VL) to -0.26693555348996223 Volts
    Pacs_BOLC_SET_VL_G1(-0.26693555348996223);
    // Set group 1 bol bias 03 (VRL) to 0.3923254235050375 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923254235050375);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1507930978184753 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1507930978184753);
    // Set group 2 bol bias 01 (VH) to 1.714453661934205 Volts
    Pacs_BOLC_SET_VH_G2(1.714453661934205);
    // Set group 2 bol bias 02 (VL) to -0.2855463380657951 Volts
    Pacs_BOLC_SET_VL_G2(-0.2855463380657951);
    // Set group 2 bol bias 03 (VRL) to 0.38771628761093724 Volts
    Pacs_BOLC_SET_VRL_G2(0.38771628761093724);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1454032366160996 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1454032366160996);
    // Set group 3 bol bias 01 (VH) to 1.7283831876482196 Volts
    Pacs_BOLC_SET_VH_G3(1.7283831876482196);
    // Set group 3 bol bias 02 (VL) to -0.2716168123517804 Volts
    Pacs_BOLC_SET_VL_G3(-0.2716168123517804);
    // Set group 3 bol bias 03 (VRL) to 0.40171045250948384 Volts
    Pacs_BOLC_SET_VRL_G3(0.40171045250948384);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157256007066197 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157256007066197);
    // Set group 4 bol bias 01 (VH) to 1.7381239240265867 Volts
    Pacs_BOLC_SET_VH_G4(1.7381239240265867);
    // Set group 4 bol bias 02 (VL) to -0.26187607597341334 Volts
    Pacs_BOLC_SET_VL_G4(-0.26187607597341334);
    // Set group 4 bol bias 03 (VRL) to 0.38896138623469356 Volts
    Pacs_BOLC_SET_VRL_G4(0.38896138623469356);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454582711839105 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454582711839105);
    // Set group 5 bol bias 01 (VH) to 1.4703496551390403 Volts
    Pacs_BOLC_SET_VH_G5(1.4703496551390403);
    // Set group 5 bol bias 02 (VL) to -0.12965034486095992 Volts
    Pacs_BOLC_SET_VL_G5(-0.12965034486095992);
    // Set group 5 bol bias 03 (VRL) to 0.39904033450461596 Volts
    Pacs_BOLC_SET_VRL_G5(0.39904033450461596);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.151844445053932 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.151844445053932);
    // Set group 6 bol bias 01 (VH) to 1.5181165758982518 Volts
    Pacs_BOLC_SET_VH_G6(1.5181165758982518);
    // Set group 6 bol bias 02 (VL) to -0.08188342410174834 Volts
    Pacs_BOLC_SET_VL_G6(-0.08188342410174834);
    // Set group 6 bol bias 03 (VRL) to 0.4343226272779045 Volts
    Pacs_BOLC_SET_VRL_G6(0.4343226272779045);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1921697898825356 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1921697898825356);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8730534488812565 Volts
    Pacs_BOLC_SET_VH_G1(1.8730534488812565);
    // Set group 1 bol bias 02 (VL) to -0.3269465511187437 Volts
    Pacs_BOLC_SET_VL_G1(-0.3269465511187437);
    // Set group 1 bol bias 03 (VRL) to 0.3922166883004623 Volts
    Pacs_BOLC_SET_VRL_G1(0.3922166883004623);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1506641222123926 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1506641222123926);
    // Set group 2 bol bias 01 (VH) to 1.8512060220322217 Volts
    Pacs_BOLC_SET_VH_G2(1.8512060220322217);
    // Set group 2 bol bias 02 (VL) to -0.34879397796777845 Volts
    Pacs_BOLC_SET_VL_G2(-0.34879397796777845);
    // Set group 2 bol bias 03 (VRL) to 0.3869592141320811 Volts
    Pacs_BOLC_SET_VRL_G2(0.3869592141320811);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1445244519836626 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1445244519836626);
    // Set group 3 bol bias 01 (VH) to 1.8654619469621685 Volts
    Pacs_BOLC_SET_VH_G3(1.8654619469621685);
    // Set group 3 bol bias 02 (VL) to -0.33453805303783174 Volts
    Pacs_BOLC_SET_VL_G3(-0.33453805303783174);
    // Set group 3 bol bias 03 (VRL) to 0.40224166318840543 Volts
    Pacs_BOLC_SET_VRL_G3(0.40224166318840543);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1578437499437477 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1578437499437477);
    // Set group 4 bol bias 01 (VH) to 1.8790483325189686 Volts
    Pacs_BOLC_SET_VH_G4(1.8790483325189686);
    // Set group 4 bol bias 02 (VL) to -0.32095166748103154 Volts
    Pacs_BOLC_SET_VL_G4(-0.32095166748103154);
    // Set group 4 bol bias 03 (VRL) to 0.39052544771082365 Volts
    Pacs_BOLC_SET_VRL_G4(0.39052544771082365);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1472446958154223 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1472446958154223);
    // Set group 5 bol bias 01 (VH) to 1.5346700184984832 Volts
    Pacs_BOLC_SET_VH_G5(1.5346700184984832);
    // Set group 5 bol bias 02 (VL) to -0.16532998150151687 Volts
    Pacs_BOLC_SET_VL_G5(-0.16532998150151687);
    // Set group 5 bol bias 03 (VRL) to 0.39828926215052507 Volts
    Pacs_BOLC_SET_VRL_G5(0.39828926215052507);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1509436695484125 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1509436695484125);
    // Set group 6 bol bias 01 (VH) to 1.5825303056022821 Volts
    Pacs_BOLC_SET_VH_G6(1.5825303056022821);
    // Set group 6 bol bias 02 (VL) to -0.11746969439771773 Volts
    Pacs_BOLC_SET_VL_G6(-0.11746969439771773);
    // Set group 6 bol bias 03 (VRL) to 0.43350337388623417 Volts
    Pacs_BOLC_SET_VRL_G6(0.43350337388623417);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191192803954044 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191192803954044);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.034145377320728 Volts
    Pacs_BOLC_SET_VH_G1(2.034145377320728);
    // Set group 1 bol bias 02 (VL) to -0.36585462267927166 Volts
    Pacs_BOLC_SET_VL_G1(-0.36585462267927166);
    // Set group 1 bol bias 03 (VRL) to 0.4026842358176688 Volts
    Pacs_BOLC_SET_VRL_G1(0.4026842358176688);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163077213168135 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163077213168135);
    // Set group 2 bol bias 01 (VH) to 1.9964246373780308 Volts
    Pacs_BOLC_SET_VH_G2(1.9964246373780308);
    // Set group 2 bol bias 02 (VL) to -0.40357536262196914 Volts
    Pacs_BOLC_SET_VL_G2(-0.40357536262196914);
    // Set group 2 bol bias 03 (VRL) to 0.38543545754038677 Volts
    Pacs_BOLC_SET_VRL_G2(0.38543545754038677);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1427558304354366 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1427558304354366);
    // Set group 3 bol bias 01 (VH) to 2.0225756539924595 Volts
    Pacs_BOLC_SET_VH_G3(2.0225756539924595);
    // Set group 3 bol bias 02 (VL) to -0.37742434600754043 Volts
    Pacs_BOLC_SET_VL_G3(-0.37742434600754043);
    // Set group 3 bol bias 03 (VRL) to 0.41362905220735763 Volts
    Pacs_BOLC_SET_VRL_G3(0.41362905220735763);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704381594190805 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704381594190805);
    // Set group 4 bol bias 01 (VH) to 2.0286801589025623 Volts
    Pacs_BOLC_SET_VH_G4(2.0286801589025623);
    // Set group 4 bol bias 02 (VL) to -0.37131984109743765 Volts
    Pacs_BOLC_SET_VL_G4(-0.37131984109743765);
    // Set group 4 bol bias 03 (VRL) to 0.39131683434261844 Volts
    Pacs_BOLC_SET_VRL_G4(0.39131683434261844);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.14814867942076 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.14814867942076);
    // Set group 5 bol bias 01 (VH) to 1.5997463742933684 Volts
    Pacs_BOLC_SET_VH_G5(1.5997463742933684);
    // Set group 5 bol bias 02 (VL) to -0.2002536257066316 Volts
    Pacs_BOLC_SET_VL_G5(-0.2002536257066316);
    // Set group 5 bol bias 03 (VRL) to 0.3972802806465645 Volts
    Pacs_BOLC_SET_VRL_G5(0.3972802806465645);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1497335299275955 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1497335299275955);
    // Set group 6 bol bias 01 (VH) to 1.64826517003746 Volts
    Pacs_BOLC_SET_VH_G6(1.64826517003746);
    // Set group 6 bol bias 02 (VL) to -0.1517348299625401 Volts
    Pacs_BOLC_SET_VL_G6(-0.1517348299625401);
    // Set group 6 bol bias 03 (VRL) to 0.43238698345346915 Volts
    Pacs_BOLC_SET_VRL_G6(0.43238698345346915);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.189850849172478 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.189850849172478);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.1252730205231707 Volts
    Pacs_BOLC_SET_VH_G1(2.1252730205231707);
    // Set group 1 bol bias 02 (VL) to -0.3747269794768295 Volts
    Pacs_BOLC_SET_VL_G1(-0.3747269794768295);
    // Set group 1 bol bias 03 (VRL) to 0.4136487083795371 Volts
    Pacs_BOLC_SET_VRL_G1(0.4136487083795371);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.176055880953933 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.176055880953933);
    // Set group 2 bol bias 01 (VH) to 2.0735703522054516 Volts
    Pacs_BOLC_SET_VH_G2(2.0735703522054516);
    // Set group 2 bol bias 02 (VL) to -0.4264296477945484 Volts
    Pacs_BOLC_SET_VL_G2(-0.4264296477945484);
    // Set group 2 bol bias 03 (VRL) to 0.38501518126647505 Volts
    Pacs_BOLC_SET_VRL_G2(0.38501518126647505);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1422680405518997 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1422680405518997);
    // Set group 3 bol bias 01 (VH) to 2.1002048058798914 Volts
    Pacs_BOLC_SET_VH_G3(2.1002048058798914);
    // Set group 3 bol bias 02 (VL) to -0.3997951941201084 Volts
    Pacs_BOLC_SET_VL_G3(-0.3997951941201084);
    // Set group 3 bol bias 03 (VRL) to 0.41374892649754597 Volts
    Pacs_BOLC_SET_VRL_G3(0.41374892649754597);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170570690743195 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170570690743195);
    // Set group 4 bol bias 01 (VH) to 2.1080881836667413 Volts
    Pacs_BOLC_SET_VH_G4(2.1080881836667413);
    // Set group 4 bol bias 02 (VL) to -0.39191181633325867 Volts
    Pacs_BOLC_SET_VL_G4(-0.39191181633325867);
    // Set group 4 bol bias 03 (VRL) to 0.39179349399255325 Volts
    Pacs_BOLC_SET_VRL_G4(0.39179349399255325);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1486931849427977 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1486931849427977);
    // Set group 5 bol bias 01 (VH) to 1.6757782637240437 Volts
    Pacs_BOLC_SET_VH_G5(1.6757782637240437);
    // Set group 5 bol bias 02 (VL) to -0.22422173627595626 Volts
    Pacs_BOLC_SET_VL_G5(-0.22422173627595626);
    // Set group 5 bol bias 03 (VRL) to 0.40729645571050493 Volts
    Pacs_BOLC_SET_VRL_G5(0.40729645571050493);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1617149101325723 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1617149101325723);
    // Set group 6 bol bias 01 (VH) to 1.7136503402053438 Volts
    Pacs_BOLC_SET_VH_G6(1.7136503402053438);
    // Set group 6 bol bias 02 (VL) to -0.18634965979465615 Volts
    Pacs_BOLC_SET_VL_G6(-0.18634965979465615);
    // Set group 6 bol bias 03 (VRL) to 0.43098263818668947 Volts
    Pacs_BOLC_SET_VRL_G6(0.43098263818668947);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1881561132520857 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1881561132520857);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.209416047586087 Volts
    Pacs_BOLC_SET_VH_G1(2.209416047586087);
    // Set group 1 bol bias 02 (VL) to -0.3905839524139128 Volts
    Pacs_BOLC_SET_VL_G1(-0.3905839524139128);
    // Set group 1 bol bias 03 (VRL) to 0.4134679213904496 Volts
    Pacs_BOLC_SET_VRL_G1(0.4134679213904496);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758418687268812 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758418687268812);
    // Set group 2 bol bias 01 (VH) to 2.1541915675147214 Volts
    Pacs_BOLC_SET_VH_G2(2.1541915675147214);
    // Set group 2 bol bias 02 (VL) to -0.44580843248527846 Volts
    Pacs_BOLC_SET_VL_G2(-0.44580843248527846);
    // Set group 2 bol bias 03 (VRL) to 0.38424319746039115 Volts
    Pacs_BOLC_SET_VRL_G2(0.38424319746039115);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1413720715536493 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1413720715536493);
    // Set group 3 bol bias 01 (VH) to 2.1813068162319285 Volts
    Pacs_BOLC_SET_VH_G3(2.1813068162319285);
    // Set group 3 bol bias 02 (VL) to -0.4186931837680716 Volts
    Pacs_BOLC_SET_VL_G3(-0.4186931837680716);
    // Set group 3 bol bias 03 (VRL) to 0.41360319513591143 Volts
    Pacs_BOLC_SET_VRL_G3(0.41360319513591143);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704095720713417 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704095720713417);
    // Set group 4 bol bias 01 (VH) to 2.202944386753124 Volts
    Pacs_BOLC_SET_VH_G4(2.202944386753124);
    // Set group 4 bol bias 02 (VL) to -0.3970556132468757 Volts
    Pacs_BOLC_SET_VL_G4(-0.3970556132468757);
    // Set group 4 bol bias 03 (VRL) to 0.40381007074137704 Volts
    Pacs_BOLC_SET_VRL_G4(0.40381007074137704);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1624292794462514 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1624292794462514);
    // Set group 5 bol bias 01 (VH) to 1.7436864671540049 Volts
    Pacs_BOLC_SET_VH_G5(1.7436864671540049);
    // Set group 5 bol bias 02 (VL) to -0.2563135328459952 Volts
    Pacs_BOLC_SET_VL_G5(-0.2563135328459952);
    // Set group 5 bol bias 03 (VRL) to 0.4060804936984878 Volts
    Pacs_BOLC_SET_VRL_G5(0.4060804936984878);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1602616898977316 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1602616898977316);
    // Set group 6 bol bias 01 (VH) to 1.7834132365202005 Volts
    Pacs_BOLC_SET_VH_G6(1.7834132365202005);
    // Set group 6 bol bias 02 (VL) to -0.21658676347979958 Volts
    Pacs_BOLC_SET_VL_G6(-0.21658676347979958);
    // Set group 6 bol bias 03 (VRL) to 0.43021242094743417 Volts
    Pacs_BOLC_SET_VRL_G6(0.43021242094743417);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1872266025341247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1872266025341247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.297951276717203 Volts
    Pacs_BOLC_SET_VH_G1(2.297951276717203);
    // Set group 1 bol bias 02 (VL) to -0.4020487232827972 Volts
    Pacs_BOLC_SET_VL_G1(-0.4020487232827972);
    // Set group 1 bol bias 03 (VRL) to 0.41346783054780994 Volts
    Pacs_BOLC_SET_VRL_G1(0.41346783054780994);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175841761189199 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175841761189199);
    // Set group 2 bol bias 01 (VH) to 2.237764444765691 Volts
    Pacs_BOLC_SET_VH_G2(2.237764444765691);
    // Set group 2 bol bias 02 (VL) to -0.46223555523430954 Volts
    Pacs_BOLC_SET_VL_G2(-0.46223555523430954);
    // Set group 2 bol bias 03 (VRL) to 0.3829355076340157 Volts
    Pacs_BOLC_SET_VRL_G2(0.3829355076340157);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.13985443895415 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.13985443895415);
    // Set group 3 bol bias 01 (VH) to 2.2663898962449944 Volts
    Pacs_BOLC_SET_VH_G3(2.2663898962449944);
    // Set group 3 bol bias 02 (VL) to -0.43361010375500575 Volts
    Pacs_BOLC_SET_VL_G3(-0.43361010375500575);
    // Set group 3 bol bias 03 (VRL) to 0.4131238530516411 Volts
    Pacs_BOLC_SET_VRL_G3(0.4131238530516411);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1698796071025357 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1698796071025357);
    // Set group 4 bol bias 01 (VH) to 2.279673221041111 Volts
    Pacs_BOLC_SET_VH_G4(2.279673221041111);
    // Set group 4 bol bias 02 (VL) to -0.42032677895888915 Volts
    Pacs_BOLC_SET_VL_G4(-0.42032677895888915);
    // Set group 4 bol bias 03 (VRL) to 0.39361613583982535 Volts
    Pacs_BOLC_SET_VRL_G4(0.39361613583982535);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.15077544624775 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.15077544624775);
    // Set group 5 bol bias 01 (VH) to 1.809656711096493 Volts
    Pacs_BOLC_SET_VH_G5(1.809656711096493);
    // Set group 5 bol bias 02 (VL) to -0.2903432889035071 Volts
    Pacs_BOLC_SET_VL_G5(-0.2903432889035071);
    // Set group 5 bol bias 03 (VRL) to 0.4049518544441218 Volts
    Pacs_BOLC_SET_VRL_G5(0.4049518544441218);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1589129512261658 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1589129512261658);
    // Set group 6 bol bias 01 (VH) to 1.852468907894238 Volts
    Pacs_BOLC_SET_VH_G6(1.852468907894238);
    // Set group 6 bol bias 02 (VL) to -0.247531092105762 Volts
    Pacs_BOLC_SET_VL_G6(-0.247531092105762);
    // Set group 6 bol bias 03 (VRL) to 0.4292993417752352 Volts
    Pacs_BOLC_SET_VRL_G6(0.4292993417752352);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1861246581200136 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1861246581200136);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3806926938420414 Volts
    Pacs_BOLC_SET_VH_G1(2.3806926938420414);
    // Set group 1 bol bias 02 (VL) to -0.41930730615795847 Volts
    Pacs_BOLC_SET_VL_G1(-0.41930730615795847);
    // Set group 1 bol bias 03 (VRL) to 0.4020155079485436 Volts
    Pacs_BOLC_SET_VRL_G1(0.4020155079485436);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162285695776181 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162285695776181);
    // Set group 2 bol bias 01 (VH) to 2.3371282046100963 Volts
    Pacs_BOLC_SET_VH_G2(2.3371282046100963);
    // Set group 2 bol bias 02 (VL) to -0.46287179538990364 Volts
    Pacs_BOLC_SET_VL_G2(-0.46287179538990364);
    // Set group 2 bol bias 03 (VRL) to 0.3923402298587034 Volts
    Pacs_BOLC_SET_VRL_G2(0.3923402298587034);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1507712805161225 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1507712805161225);
    // Set group 3 bol bias 01 (VH) to 2.356604953923699 Volts
    Pacs_BOLC_SET_VH_G3(2.356604953923699);
    // Set group 3 bol bias 02 (VL) to -0.44339504607630065 Volts
    Pacs_BOLC_SET_VL_G3(-0.44339504607630065);
    // Set group 3 bol bias 03 (VRL) to 0.4124662568673877 Volts
    Pacs_BOLC_SET_VRL_G3(0.4124662568673877);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.169152536126319 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.169152536126319);
    // Set group 4 bol bias 01 (VH) to 2.3825039100730487 Volts
    Pacs_BOLC_SET_VH_G4(2.3825039100730487);
    // Set group 4 bol bias 02 (VL) to -0.4174960899269509 Volts
    Pacs_BOLC_SET_VL_G4(-0.4174960899269509);
    // Set group 4 bol bias 03 (VRL) to 0.40493410269973024 Volts
    Pacs_BOLC_SET_VRL_G4(0.40493410269973024);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1637149679245193 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1637149679245193);
    // Set group 5 bol bias 01 (VH) to 1.883738472848583 Volts
    Pacs_BOLC_SET_VH_G5(1.883738472848583);
    // Set group 5 bol bias 02 (VL) to -0.31626152715141714 Volts
    Pacs_BOLC_SET_VL_G5(-0.31626152715141714);
    // Set group 5 bol bias 03 (VRL) to 0.4028494691164935 Volts
    Pacs_BOLC_SET_VRL_G5(0.4028494691164935);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.156400882301432 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.156400882301432);
    // Set group 6 bol bias 01 (VH) to 1.9235912310846244 Volts
    Pacs_BOLC_SET_VH_G6(1.9235912310846244);
    // Set group 6 bol bias 02 (VL) to -0.2764087689153759 Volts
    Pacs_BOLC_SET_VL_G6(-0.2764087689153759);
    // Set group 6 bol bias 03 (VRL) to 0.4280070912945936 Volts
    Pacs_BOLC_SET_VRL_G6(0.4280070912945936);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1845650655206446 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1845650655206446);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6181566702818313 Volts
    Pacs_BOLC_SET_VH_G1(2.6181566702818313);
    // Set group 1 bol bias 02 (VL) to -0.38184332971816887 Volts
    Pacs_BOLC_SET_VL_G1(-0.38184332971816887);
    // Set group 1 bol bias 03 (VRL) to 0.43545225816479755 Volts
    Pacs_BOLC_SET_VRL_G1(0.43545225816479755);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2018572484354544 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2018572484354544);
    // Set group 2 bol bias 01 (VH) to 2.5300933623498008 Volts
    Pacs_BOLC_SET_VH_G2(2.5300933623498008);
    // Set group 2 bol bias 02 (VL) to -0.469906637650199 Volts
    Pacs_BOLC_SET_VL_G2(-0.469906637650199);
    // Set group 2 bol bias 03 (VRL) to 0.3917176926734228 Volts
    Pacs_BOLC_SET_VRL_G2(0.3917176926734228);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1500484890692286 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1500484890692286);
    // Set group 3 bol bias 01 (VH) to 2.5545115967606167 Volts
    Pacs_BOLC_SET_VH_G3(2.5545115967606167);
    // Set group 3 bol bias 02 (VL) to -0.4454884032393832 Volts
    Pacs_BOLC_SET_VL_G3(-0.4454884032393832);
    // Set group 3 bol bias 03 (VRL) to 0.41136249367186684 Volts
    Pacs_BOLC_SET_VRL_G3(0.41136249367186684);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1679320914489204 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1679320914489204);
    // Set group 4 bol bias 01 (VH) to 2.591852678092942 Volts
    Pacs_BOLC_SET_VH_G4(2.591852678092942);
    // Set group 4 bol bias 02 (VL) to -0.408147321907058 Volts
    Pacs_BOLC_SET_VL_G4(-0.408147321907058);
    // Set group 4 bol bias 03 (VRL) to 0.4158848845694993 Volts
    Pacs_BOLC_SET_VRL_G4(0.4158848845694993);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176235181901646 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176235181901646);
    // Set group 5 bol bias 01 (VH) to 2.0340896725156363 Volts
    Pacs_BOLC_SET_VH_G5(2.0340896725156363);
    // Set group 5 bol bias 02 (VL) to -0.3659103274843634 Volts
    Pacs_BOLC_SET_VL_G5(-0.3659103274843634);
    // Set group 5 bol bias 03 (VRL) to 0.3987896988621052 Volts
    Pacs_BOLC_SET_VRL_G5(0.3987896988621052);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1515438563527702 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1515438563527702);
    // Set group 6 bol bias 01 (VH) to 2.080247845760918 Volts
    Pacs_BOLC_SET_VH_G6(2.080247845760918);
    // Set group 6 bol bias 02 (VL) to -0.31975215423908154 Volts
    Pacs_BOLC_SET_VL_G6(-0.31975215423908154);
    // Set group 6 bol bias 03 (VRL) to 0.42577779561759777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42577779561759777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1818744401374954 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1818744401374954);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.9648806825465286 Volts
    Pacs_BOLC_SET_VH_G1(2.9648806825465286);
    // Set group 1 bol bias 02 (VL) to -0.3351193174534714 Volts
    Pacs_BOLC_SET_VL_G1(-0.3351193174534714);
    // Set group 1 bol bias 03 (VRL) to 0.4345971818834749 Volts
    Pacs_BOLC_SET_VRL_G1(0.4345971818834749);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2008507320864905 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2008507320864905);
    // Set group 2 bol bias 01 (VH) to 2.8835722707263107 Volts
    Pacs_BOLC_SET_VH_G2(2.8835722707263107);
    // Set group 2 bol bias 02 (VL) to -0.4164277292736889 Volts
    Pacs_BOLC_SET_VL_G2(-0.4164277292736889);
    // Set group 2 bol bias 03 (VRL) to 0.4147637133976726 Volts
    Pacs_BOLC_SET_VRL_G2(0.4147637133976726);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176763943185141 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176763943185141);
    // Set group 3 bol bias 01 (VH) to 2.924290179534832 Volts
    Pacs_BOLC_SET_VH_G3(2.924290179534832);
    // Set group 3 bol bias 02 (VL) to -0.37570982046516804 Volts
    Pacs_BOLC_SET_VL_G3(-0.37570982046516804);
    // Set group 3 bol bias 03 (VRL) to 0.4333518026225201 Volts
    Pacs_BOLC_SET_VRL_G3(0.4333518026225201);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.19222958084261 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.19222958084261);
    // Set group 4 bol bias 01 (VH) to 2.938948180111503 Volts
    Pacs_BOLC_SET_VH_G4(2.938948180111503);
    // Set group 4 bol bias 02 (VL) to -0.3610518198884969 Volts
    Pacs_BOLC_SET_VL_G4(-0.3610518198884969);
    // Set group 4 bol bias 03 (VRL) to 0.4248831336064878 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248831336064878);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1865155818476714 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1865155818476714);
    // Set group 5 bol bias 01 (VH) to 2.231303538712061 Volts
    Pacs_BOLC_SET_VH_G5(2.231303538712061);
    // Set group 5 bol bias 02 (VL) to -0.36869646128793887 Volts
    Pacs_BOLC_SET_VL_G5(-0.36869646128793887);
    // Set group 5 bol bias 03 (VRL) to 0.4261159129370585 Volts
    Pacs_BOLC_SET_VRL_G5(0.4261159129370585);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1842235863263286 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1842235863263286);
    // Set group 6 bol bias 01 (VH) to 2.2493043049150576 Volts
    Pacs_BOLC_SET_VH_G6(2.2493043049150576);
    // Set group 6 bol bias 02 (VL) to -0.3506956950849426 Volts
    Pacs_BOLC_SET_VL_G6(-0.3506956950849426);
    // Set group 6 bol bias 03 (VRL) to 0.4237159708307814 Volts
    Pacs_BOLC_SET_VRL_G6(0.4237159708307814);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.179385794698645 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.179385794698645);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //**********************************************
    // Set the PACS chopper at the position 664
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //
    //**********************************************************************
    //                       Measurement
    // PACS photometer central field-of-view
    // corresponding to 1.42pW on the green and 2.30pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //*******************************
    // Select Filter B (70 microns)
    //*******************************
    //
    PHOT_fltw_move("POS B");
    //
    //**********************************************
    // Set the PACS chopper at the position -21350
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(-21350);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS1 at 48.0 K
    // corresponding to 0.90pW on the blue and 5.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //**********************************************
    // Set the PACS chopper at the position 21200
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(21200);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Temperature of the CS2 at 58.0 K
    // corresponding to 1.25pW on the blue and 6.90pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //**********************************************
    // Set the PACS chopper at the position 664
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //
    //**********************************************************************
    //                       Measurement
    // PACS photometer central field-of-view
    // corresponding to 2.53pW on the blue and 2.30pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38595447686092044 Volts
    Pacs_BOLC_SET_VRL_G1(0.38595447686092044);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.14323766073377 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.14323766073377);
    // Set group 2 bol bias 01 (VH) to 1.2344804253925323 Volts
    Pacs_BOLC_SET_VH_G2(1.2344804253925323);
    // Set group 2 bol bias 02 (VL) to -0.015519574607467744 Volts
    Pacs_BOLC_SET_VL_G2(-0.015519574607467744);
    // Set group 2 bol bias 03 (VRL) to 0.3887952159752219 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887952159752219);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146655677517905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146655677517905);
    // Set group 3 bol bias 01 (VH) to 1.2373594133510515 Volts
    Pacs_BOLC_SET_VH_G3(1.2373594133510515);
    // Set group 3 bol bias 02 (VL) to -0.01264058664894848 Volts
    Pacs_BOLC_SET_VL_G3(-0.01264058664894848);
    // Set group 3 bol bias 03 (VRL) to 0.3895684681925507 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895684681925507);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438588243530847 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438588243530847);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3785840783874695 Volts
    Pacs_BOLC_SET_VRL_G4(0.3785840783874695);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1336112832841145 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1336112832841145);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4069787801604593 Volts
    Pacs_BOLC_SET_VRL_G5(0.4069787801604593);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.161335236817835 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.161335236817835);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3975388237702142 Volts
    Pacs_BOLC_SET_VRL_G6(0.3975388237702142);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.147783429778294 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.147783429778294);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4667162183102813 Volts
    Pacs_BOLC_SET_VH_G1(1.4667162183102813);
    // Set group 1 bol bias 02 (VL) to -0.13328378168971888 Volts
    Pacs_BOLC_SET_VL_G1(-0.13328378168971888);
    // Set group 1 bol bias 03 (VRL) to 0.39272911736638916 Volts
    Pacs_BOLC_SET_VRL_G1(0.39272911736638916);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151271944232348 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151271944232348);
    // Set group 2 bol bias 01 (VH) to 1.451779019853682 Volts
    Pacs_BOLC_SET_VH_G2(1.451779019853682);
    // Set group 2 bol bias 02 (VL) to -0.14822098014631813 Volts
    Pacs_BOLC_SET_VL_G2(-0.14822098014631813);
    // Set group 2 bol bias 03 (VRL) to 0.38843011222228696 Volts
    Pacs_BOLC_SET_VRL_G2(0.38843011222228696);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146231850355425 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146231850355425);
    // Set group 3 bol bias 01 (VH) to 1.4546762834706017 Volts
    Pacs_BOLC_SET_VH_G3(1.4546762834706017);
    // Set group 3 bol bias 02 (VL) to -0.14532371652939846 Volts
    Pacs_BOLC_SET_VL_G3(-0.14532371652939846);
    // Set group 3 bol bias 03 (VRL) to 0.38981991021201623 Volts
    Pacs_BOLC_SET_VRL_G3(0.38981991021201623);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1441361480051575 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1441361480051575);
    // Set group 4 bol bias 01 (VH) to 1.4698275366001177 Volts
    Pacs_BOLC_SET_VH_G4(1.4698275366001177);
    // Set group 4 bol bias 02 (VL) to -0.13017246339988242 Volts
    Pacs_BOLC_SET_VL_G4(-0.13017246339988242);
    // Set group 4 bol bias 03 (VRL) to 0.3864007122364753 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864007122364753);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1425340283175576 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1425340283175576);
    // Set group 5 bol bias 01 (VH) to 1.1496335124630621 Volts
    Pacs_BOLC_SET_VH_G5(1.1496335124630621);
    // Set group 5 bol bias 02 (VL) to -0.05036648753693776 Volts
    Pacs_BOLC_SET_VL_G5(-0.05036648753693776);
    // Set group 5 bol bias 03 (VRL) to 0.4461257136718766 Volts
    Pacs_BOLC_SET_VRL_G5(0.4461257136718766);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.208158207140394 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.208158207140394);
    // Set group 6 bol bias 01 (VH) to 1.1511962364500339 Volts
    Pacs_BOLC_SET_VH_G6(1.1511962364500339);
    // Set group 6 bol bias 02 (VL) to -0.048803763549966156 Volts
    Pacs_BOLC_SET_VL_G6(-0.048803763549966156);
    // Set group 6 bol bias 03 (VRL) to 0.43621063055258624 Volts
    Pacs_BOLC_SET_VRL_G6(0.43621063055258624);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1944214649896465 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1944214649896465);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5950693413303119 Volts
    Pacs_BOLC_SET_VH_G1(1.5950693413303119);
    // Set group 1 bol bias 02 (VL) to -0.20493065866968818 Volts
    Pacs_BOLC_SET_VL_G1(-0.20493065866968818);
    // Set group 1 bol bias 03 (VRL) to 0.3928368259960443 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928368259960443);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151399706106312 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151399706106312);
    // Set group 2 bol bias 01 (VH) to 1.5789329321276613 Volts
    Pacs_BOLC_SET_VH_G2(1.5789329321276613);
    // Set group 2 bol bias 02 (VL) to -0.22106706787233876 Volts
    Pacs_BOLC_SET_VL_G2(-0.22106706787233876);
    // Set group 2 bol bias 03 (VRL) to 0.38833566788035645 Volts
    Pacs_BOLC_SET_VRL_G2(0.38833566788035645);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461222168310456 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461222168310456);
    // Set group 3 bol bias 01 (VH) to 1.5816026056478218 Volts
    Pacs_BOLC_SET_VH_G3(1.5816026056478218);
    // Set group 3 bol bias 02 (VL) to -0.2183973943521783 Volts
    Pacs_BOLC_SET_VL_G3(-0.2183973943521783);
    // Set group 3 bol bias 03 (VRL) to 0.3902504105074307 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902504105074307);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144610964657584 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144610964657584);
    // Set group 4 bol bias 01 (VH) to 1.5992929384078782 Volts
    Pacs_BOLC_SET_VH_G4(1.5992929384078782);
    // Set group 4 bol bias 02 (VL) to -0.2007070615921217 Volts
    Pacs_BOLC_SET_VL_G4(-0.2007070615921217);
    // Set group 4 bol bias 03 (VRL) to 0.38768834369618743 Volts
    Pacs_BOLC_SET_VRL_G4(0.38768834369618743);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440044049347926 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440044049347926);
    // Set group 5 bol bias 01 (VH) to 1.2705558944311914 Volts
    Pacs_BOLC_SET_VH_G5(1.2705558944311914);
    // Set group 5 bol bias 02 (VL) to -0.1294441055688085 Volts
    Pacs_BOLC_SET_VL_G5(-0.1294441055688085);
    // Set group 5 bol bias 03 (VRL) to 0.4447953841197819 Volts
    Pacs_BOLC_SET_VRL_G5(0.4447953841197819);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2065679073017006 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2065679073017006);
    // Set group 6 bol bias 01 (VH) to 1.2715954484835785 Volts
    Pacs_BOLC_SET_VH_G6(1.2715954484835785);
    // Set group 6 bol bias 02 (VL) to -0.1284045515164213 Volts
    Pacs_BOLC_SET_VL_G6(-0.1284045515164213);
    // Set group 6 bol bias 03 (VRL) to 0.43379109580051334 Volts
    Pacs_BOLC_SET_VRL_G6(0.43379109580051334);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.191535916452247 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.191535916452247);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7275942805898081 Volts
    Pacs_BOLC_SET_VH_G1(1.7275942805898081);
    // Set group 1 bol bias 02 (VL) to -0.27240571941019187 Volts
    Pacs_BOLC_SET_VL_G1(-0.27240571941019187);
    // Set group 1 bol bias 03 (VRL) to 0.3924742651442621 Volts
    Pacs_BOLC_SET_VRL_G1(0.3924742651442621);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150969646797248 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150969646797248);
    // Set group 2 bol bias 01 (VH) to 1.7098116639341283 Volts
    Pacs_BOLC_SET_VH_G2(1.7098116639341283);
    // Set group 2 bol bias 02 (VL) to -0.2901883360658717 Volts
    Pacs_BOLC_SET_VL_G2(-0.2901883360658717);
    // Set group 2 bol bias 03 (VRL) to 0.3879542769315073 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879542769315073);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1456794933313743 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1456794933313743);
    // Set group 3 bol bias 01 (VH) to 1.7232095593655699 Volts
    Pacs_BOLC_SET_VH_G3(1.7232095593655699);
    // Set group 3 bol bias 02 (VL) to -0.2767904406344302 Volts
    Pacs_BOLC_SET_VL_G3(-0.2767904406344302);
    // Set group 3 bol bias 03 (VRL) to 0.40165100606878396 Volts
    Pacs_BOLC_SET_VRL_G3(0.40165100606878396);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157190232997346 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157190232997346);
    // Set group 4 bol bias 01 (VH) to 1.7329816525876758 Volts
    Pacs_BOLC_SET_VH_G4(1.7329816525876758);
    // Set group 4 bol bias 02 (VL) to -0.2670183474123242 Volts
    Pacs_BOLC_SET_VL_G4(-0.2670183474123242);
    // Set group 4 bol bias 03 (VRL) to 0.38897351980031714 Volts
    Pacs_BOLC_SET_VRL_G4(0.38897351980031714);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145472128921462 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145472128921462);
    // Set group 5 bol bias 01 (VH) to 1.396627362417312 Volts
    Pacs_BOLC_SET_VH_G5(1.396627362417312);
    // Set group 5 bol bias 02 (VL) to -0.203372637582688 Volts
    Pacs_BOLC_SET_VL_G5(-0.203372637582688);
    // Set group 5 bol bias 03 (VRL) to 0.44313690044797827 Volts
    Pacs_BOLC_SET_VRL_G5(0.44313690044797827);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.204585287551011 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.204585287551011);
    // Set group 6 bol bias 01 (VH) to 1.3996511062189962 Volts
    Pacs_BOLC_SET_VH_G6(1.3996511062189962);
    // Set group 6 bol bias 02 (VL) to -0.20034889378100387 Volts
    Pacs_BOLC_SET_VL_G6(-0.20034889378100387);
    // Set group 6 bol bias 03 (VRL) to 0.4318754462891581 Volts
    Pacs_BOLC_SET_VRL_G6(0.4318754462891581);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1892335439050843 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1892335439050843);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8676613407916054 Volts
    Pacs_BOLC_SET_VH_G1(1.8676613407916054);
    // Set group 1 bol bias 02 (VL) to -0.3323386592083948 Volts
    Pacs_BOLC_SET_VL_G1(-0.3323386592083948);
    // Set group 1 bol bias 03 (VRL) to 0.3923587227741554 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923587227741554);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1508325957140952 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1508325957140952);
    // Set group 2 bol bias 01 (VH) to 1.8465670569990555 Volts
    Pacs_BOLC_SET_VH_G2(1.8465670569990555);
    // Set group 2 bol bias 02 (VL) to -0.35343294300094463 Volts
    Pacs_BOLC_SET_VL_G2(-0.35343294300094463);
    // Set group 2 bol bias 03 (VRL) to 0.387141142510402 Volts
    Pacs_BOLC_SET_VRL_G2(0.387141142510402);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.144735625055897 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.144735625055897);
    // Set group 3 bol bias 01 (VH) to 1.8603250737405554 Volts
    Pacs_BOLC_SET_VH_G3(1.8603250737405554);
    // Set group 3 bol bias 02 (VL) to -0.3396749262594447 Volts
    Pacs_BOLC_SET_VL_G3(-0.3396749262594447);
    // Set group 3 bol bias 03 (VRL) to 0.4021826063426856 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021826063426856);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1577784091793144 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1577784091793144);
    // Set group 4 bol bias 01 (VH) to 1.8741419939403863 Volts
    Pacs_BOLC_SET_VH_G4(1.8741419939403863);
    // Set group 4 bol bias 02 (VL) to -0.3258580060596139 Volts
    Pacs_BOLC_SET_VL_G4(-0.3258580060596139);
    // Set group 4 bol bias 03 (VRL) to 0.39065647780264456 Volts
    Pacs_BOLC_SET_VRL_G4(0.39065647780264456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1473943646595135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1473943646595135);
    // Set group 5 bol bias 01 (VH) to 1.4601021275466064 Volts
    Pacs_BOLC_SET_VH_G5(1.4601021275466064);
    // Set group 5 bol bias 02 (VL) to -0.23989787245339347 Volts
    Pacs_BOLC_SET_VL_G5(-0.23989787245339347);
    // Set group 5 bol bias 03 (VRL) to 0.4422158972297393 Volts
    Pacs_BOLC_SET_VRL_G5(0.4422158972297393);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.2034842638437366 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.2034842638437366);
    // Set group 6 bol bias 01 (VH) to 1.4634348828715236 Volts
    Pacs_BOLC_SET_VH_G6(1.4634348828715236);
    // Set group 6 bol bias 02 (VL) to -0.23656511712847642 Volts
    Pacs_BOLC_SET_VL_G6(-0.23656511712847642);
    // Set group 6 bol bias 03 (VRL) to 0.4305103617042648 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305103617042648);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.187586164637993 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.187586164637993);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0289667278841597 Volts
    Pacs_BOLC_SET_VH_G1(2.0289667278841597);
    // Set group 1 bol bias 02 (VL) to -0.3710332721158404 Volts
    Pacs_BOLC_SET_VL_G1(-0.3710332721158404);
    // Set group 1 bol bias 03 (VRL) to 0.4028592462868991 Volts
    Pacs_BOLC_SET_VRL_G1(0.4028592462868991);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1632843595446576 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1632843595446576);
    // Set group 2 bol bias 01 (VH) to 1.9920309376502383 Volts
    Pacs_BOLC_SET_VH_G2(1.9920309376502383);
    // Set group 2 bol bias 02 (VL) to -0.4079690623497616 Volts
    Pacs_BOLC_SET_VL_G2(-0.4079690623497616);
    // Set group 2 bol bias 03 (VRL) to 0.385687908071477 Volts
    Pacs_BOLC_SET_VRL_G2(0.385687908071477);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14304883987339 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14304883987339);
    // Set group 3 bol bias 01 (VH) to 2.01759544206816 Volts
    Pacs_BOLC_SET_VH_G3(2.01759544206816);
    // Set group 3 bol bias 02 (VL) to -0.3824045579318402 Volts
    Pacs_BOLC_SET_VL_G3(-0.3824045579318402);
    // Set group 3 bol bias 03 (VRL) to 0.4136090202481733 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136090202481733);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704160122677014 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704160122677014);
    // Set group 4 bol bias 01 (VH) to 2.023897485231249 Volts
    Pacs_BOLC_SET_VH_G4(2.023897485231249);
    // Set group 4 bol bias 02 (VL) to -0.37610251476875123 Volts
    Pacs_BOLC_SET_VL_G4(-0.37610251476875123);
    // Set group 4 bol bias 03 (VRL) to 0.3914117691351826 Volts
    Pacs_BOLC_SET_VRL_G4(0.3914117691351826);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482571252028864 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482571252028864);
    // Set group 5 bol bias 01 (VH) to 1.5134052163163956 Volts
    Pacs_BOLC_SET_VH_G5(1.5134052163163956);
    // Set group 5 bol bias 02 (VL) to -0.2865947836836044 Volts
    Pacs_BOLC_SET_VL_G5(-0.2865947836836044);
    // Set group 5 bol bias 03 (VRL) to 0.43009652443311003 Volts
    Pacs_BOLC_SET_VRL_G5(0.43009652443311003);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1889886625725254 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1889886625725254);
    // Set group 6 bol bias 01 (VH) to 1.5291293141365392 Volts
    Pacs_BOLC_SET_VH_G6(1.5291293141365392);
    // Set group 6 bol bias 02 (VL) to -0.27087068586346075 Volts
    Pacs_BOLC_SET_VL_G6(-0.27087068586346075);
    // Set group 6 bol bias 03 (VRL) to 0.4294139806416023 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294139806416023);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186263010908741 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186263010908741);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.120198143641786 Volts
    Pacs_BOLC_SET_VH_G1(2.120198143641786);
    // Set group 1 bol bias 02 (VL) to -0.3798018563582141 Volts
    Pacs_BOLC_SET_VL_G1(-0.3798018563582141);
    // Set group 1 bol bias 03 (VRL) to 0.413781497117605 Volts
    Pacs_BOLC_SET_VRL_G1(0.413781497117605);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762130740626335 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762130740626335);
    // Set group 2 bol bias 01 (VH) to 2.0692519072397184 Volts
    Pacs_BOLC_SET_VH_G2(2.0692519072397184);
    // Set group 2 bol bias 02 (VL) to -0.4307480927602818 Volts
    Pacs_BOLC_SET_VL_G2(-0.4307480927602818);
    // Set group 2 bol bias 03 (VRL) to 0.3851971610581806 Volts
    Pacs_BOLC_SET_VRL_G2(0.3851971610581806);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1424792524874454 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1424792524874454);
    // Set group 3 bol bias 01 (VH) to 2.0953683923633597 Volts
    Pacs_BOLC_SET_VH_G3(2.0953683923633597);
    // Set group 3 bol bias 02 (VL) to -0.40463160763664013 Volts
    Pacs_BOLC_SET_VL_G3(-0.40463160763664013);
    // Set group 3 bol bias 03 (VRL) to 0.4137231664182032 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137231664182032);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705422108493044 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705422108493044);
    // Set group 4 bol bias 01 (VH) to 2.103405710635205 Volts
    Pacs_BOLC_SET_VH_G4(2.103405710635205);
    // Set group 4 bol bias 02 (VL) to -0.39659428936479524 Volts
    Pacs_BOLC_SET_VL_G4(-0.39659428936479524);
    // Set group 4 bol bias 03 (VRL) to 0.391818633341226 Volts
    Pacs_BOLC_SET_VRL_G4(0.391818633341226);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1487219031052516 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1487219031052516);
    // Set group 5 bol bias 01 (VH) to 1.5788283910749448 Volts
    Pacs_BOLC_SET_VH_G5(1.5788283910749448);
    // Set group 5 bol bias 02 (VL) to -0.3211716089250552 Volts
    Pacs_BOLC_SET_VL_G5(-0.3211716089250552);
    // Set group 5 bol bias 03 (VRL) to 0.4289629359876455 Volts
    Pacs_BOLC_SET_VRL_G5(0.4289629359876455);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1876315290176143 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1876315290176143);
    // Set group 6 bol bias 01 (VH) to 1.5951809874920229 Volts
    Pacs_BOLC_SET_VH_G6(1.5951809874920229);
    // Set group 6 bol bias 02 (VL) to -0.30481901250797716 Volts
    Pacs_BOLC_SET_VL_G6(-0.30481901250797716);
    // Set group 6 bol bias 03 (VRL) to 0.4281733490721523 Volts
    Pacs_BOLC_SET_VRL_G6(0.4281733490721523);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.184765721996255 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.184765721996255);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.20443545253382 Volts
    Pacs_BOLC_SET_VH_G1(2.20443545253382);
    // Set group 1 bol bias 02 (VL) to -0.39556454746618036 Volts
    Pacs_BOLC_SET_VL_G1(-0.39556454746618036);
    // Set group 1 bol bias 03 (VRL) to 0.41350652234011925 Volts
    Pacs_BOLC_SET_VRL_G1(0.41350652234011925);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1758875637625814 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1758875637625814);
    // Set group 2 bol bias 01 (VH) to 2.1501551780279815 Volts
    Pacs_BOLC_SET_VH_G2(2.1501551780279815);
    // Set group 2 bol bias 02 (VL) to -0.44984482197201847 Volts
    Pacs_BOLC_SET_VL_G2(-0.44984482197201847);
    // Set group 2 bol bias 03 (VRL) to 0.3845569970722936 Volts
    Pacs_BOLC_SET_VRL_G2(0.3845569970722936);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.141736265020926 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.141736265020926);
    // Set group 3 bol bias 01 (VH) to 2.1766120048121236 Volts
    Pacs_BOLC_SET_VH_G3(2.1766120048121236);
    // Set group 3 bol bias 02 (VL) to -0.42338799518787656 Volts
    Pacs_BOLC_SET_VL_G3(-0.42338799518787656);
    // Set group 3 bol bias 03 (VRL) to 0.4135536287313443 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135536287313443);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170354771762948 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170354771762948);
    // Set group 4 bol bias 01 (VH) to 2.1983249375538283 Volts
    Pacs_BOLC_SET_VH_G4(2.1983249375538283);
    // Set group 4 bol bias 02 (VL) to -0.40167506244617174 Volts
    Pacs_BOLC_SET_VL_G4(-0.40167506244617174);
    // Set group 4 bol bias 03 (VRL) to 0.40369622266518995 Volts
    Pacs_BOLC_SET_VRL_G4(0.40369622266518995);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622990520613876 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622990520613876);
    // Set group 5 bol bias 01 (VH) to 1.646164041300917 Volts
    Pacs_BOLC_SET_VH_G5(1.646164041300917);
    // Set group 5 bol bias 02 (VL) to -0.35383595869908285 Volts
    Pacs_BOLC_SET_VL_G5(-0.35383595869908285);
    // Set group 5 bol bias 03 (VRL) to 0.42769455060298694 Volts
    Pacs_BOLC_SET_VRL_G5(0.42769455060298694);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.186113155384117 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.186113155384117);
    // Set group 6 bol bias 01 (VH) to 1.66375611253317 Volts
    Pacs_BOLC_SET_VH_G6(1.66375611253317);
    // Set group 6 bol bias 02 (VL) to -0.3362438874668301 Volts
    Pacs_BOLC_SET_VL_G6(-0.3362438874668301);
    // Set group 6 bol bias 03 (VRL) to 0.42698080716071063 Volts
    Pacs_BOLC_SET_VRL_G6(0.42698080716071063);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.183326423045683 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.183326423045683);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.293087782674973 Volts
    Pacs_BOLC_SET_VH_G1(2.293087782674973);
    // Set group 1 bol bias 02 (VL) to -0.4069122173250272 Volts
    Pacs_BOLC_SET_VL_G1(-0.4069122173250272);
    // Set group 1 bol bias 03 (VRL) to 0.4133539579182495 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133539579182495);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1757069611650715 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1757069611650715);
    // Set group 2 bol bias 01 (VH) to 2.2339317590222536 Volts
    Pacs_BOLC_SET_VH_G2(2.2339317590222536);
    // Set group 2 bol bias 02 (VL) to -0.46606824097774663 Volts
    Pacs_BOLC_SET_VL_G2(-0.46606824097774663);
    // Set group 2 bol bias 03 (VRL) to 0.3831763579446064 Volts
    Pacs_BOLC_SET_VRL_G2(0.3831763579446064);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1401339489669264 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1401339489669264);
    // Set group 3 bol bias 01 (VH) to 2.261825459303065 Volts
    Pacs_BOLC_SET_VH_G3(2.261825459303065);
    // Set group 3 bol bias 02 (VL) to -0.4381745406969354 Volts
    Pacs_BOLC_SET_VL_G3(-0.4381745406969354);
    // Set group 3 bol bias 03 (VRL) to 0.41300268391153927 Volts
    Pacs_BOLC_SET_VRL_G3(0.41300268391153927);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.16974563880509 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.16974563880509);
    // Set group 4 bol bias 01 (VH) to 2.275375186726804 Volts
    Pacs_BOLC_SET_VH_G4(2.275375186726804);
    // Set group 4 bol bias 02 (VL) to -0.4246248132731959 Volts
    Pacs_BOLC_SET_VL_G4(-0.4246248132731959);
    // Set group 4 bol bias 03 (VRL) to 0.3936211435137845 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936211435137845);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150781167640029 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150781167640029);
    // Set group 5 bol bias 01 (VH) to 1.7150330107912974 Volts
    Pacs_BOLC_SET_VH_G5(1.7150330107912974);
    // Set group 5 bol bias 02 (VL) to -0.3849669892087026 Volts
    Pacs_BOLC_SET_VL_G5(-0.3849669892087026);
    // Set group 5 bol bias 03 (VRL) to 0.4262539713331918 Volts
    Pacs_BOLC_SET_VRL_G5(0.4262539713331918);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.184388827888219 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.184388827888219);
    // Set group 6 bol bias 01 (VH) to 1.7344239048768655 Volts
    Pacs_BOLC_SET_VH_G6(1.7344239048768655);
    // Set group 6 bol bias 02 (VL) to -0.3655760951231346 Volts
    Pacs_BOLC_SET_VL_G6(-0.3655760951231346);
    // Set group 6 bol bias 03 (VRL) to 0.4259440956195557 Volts
    Pacs_BOLC_SET_VRL_G6(0.4259440956195557);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182075159918788 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182075159918788);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.376161239903615 Volts
    Pacs_BOLC_SET_VH_G1(2.376161239903615);
    // Set group 1 bol bias 02 (VL) to -0.4238387600963847 Volts
    Pacs_BOLC_SET_VL_G1(-0.4238387600963847);
    // Set group 1 bol bias 03 (VRL) to 0.4019350271917251 Volts
    Pacs_BOLC_SET_VRL_G1(0.4019350271917251);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.162190437860791 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.162190437860791);
    // Set group 2 bol bias 01 (VH) to 2.33331637679076 Volts
    Pacs_BOLC_SET_VH_G2(2.33331637679076);
    // Set group 2 bol bias 02 (VL) to -0.46668362320923984 Volts
    Pacs_BOLC_SET_VL_G2(-0.46668362320923984);
    // Set group 2 bol bias 03 (VRL) to 0.39246594035712123 Volts
    Pacs_BOLC_SET_VRL_G2(0.39246594035712123);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150917238378006 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150917238378006);
    // Set group 3 bol bias 01 (VH) to 2.352282128290632 Volts
    Pacs_BOLC_SET_VH_G3(2.352282128290632);
    // Set group 3 bol bias 02 (VL) to -0.44771787170936794 Volts
    Pacs_BOLC_SET_VL_G3(-0.44771787170936794);
    // Set group 3 bol bias 03 (VRL) to 0.4123793468402218 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123793468402218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1690564417803797 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1690564417803797);
    // Set group 4 bol bias 01 (VH) to 2.3672177039101623 Volts
    Pacs_BOLC_SET_VH_G4(2.3672177039101623);
    // Set group 4 bol bias 02 (VL) to -0.4327822960898373 Volts
    Pacs_BOLC_SET_VL_G4(-0.4327822960898373);
    // Set group 4 bol bias 03 (VRL) to 0.3937206235453262 Volts
    Pacs_BOLC_SET_VRL_G4(0.3937206235453262);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508948265305405 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508948265305405);
    // Set group 5 bol bias 01 (VH) to 1.7869405382956105 Volts
    Pacs_BOLC_SET_VH_G5(1.7869405382956105);
    // Set group 5 bol bias 02 (VL) to -0.4130594617043897 Volts
    Pacs_BOLC_SET_VL_G5(-0.4130594617043897);
    // Set group 5 bol bias 03 (VRL) to 0.42444963237426925 Volts
    Pacs_BOLC_SET_VRL_G5(0.42444963237426925);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.182229358657508 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.182229358657508);
    // Set group 6 bol bias 01 (VH) to 1.8079220843886952 Volts
    Pacs_BOLC_SET_VH_G6(1.8079220843886952);
    // Set group 6 bol bias 02 (VL) to -0.3920779156113049 Volts
    Pacs_BOLC_SET_VL_G6(-0.3920779156113049);
    // Set group 6 bol bias 03 (VRL) to 0.4246642692362136 Volts
    Pacs_BOLC_SET_VRL_G6(0.4246642692362136);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.180530418999196 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.180530418999196);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6143871530191385 Volts
    Pacs_BOLC_SET_VH_G1(2.6143871530191385);
    // Set group 1 bol bias 02 (VL) to -0.3856128469808617 Volts
    Pacs_BOLC_SET_VL_G1(-0.3856128469808617);
    // Set group 1 bol bias 03 (VRL) to 0.4353971787636171 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353971787636171);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.2017924120765193 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.2017924120765193);
    // Set group 2 bol bias 01 (VH) to 2.5268162959111504 Volts
    Pacs_BOLC_SET_VH_G2(2.5268162959111504);
    // Set group 2 bol bias 02 (VL) to -0.4731837040888497 Volts
    Pacs_BOLC_SET_VL_G2(-0.4731837040888497);
    // Set group 2 bol bias 03 (VRL) to 0.39176377375178884 Volts
    Pacs_BOLC_SET_VRL_G2(0.39176377375178884);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501019903272867 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501019903272867);
    // Set group 3 bol bias 01 (VH) to 2.5508652949203547 Volts
    Pacs_BOLC_SET_VH_G3(2.5508652949203547);
    // Set group 3 bol bias 02 (VL) to -0.44913470507964515 Volts
    Pacs_BOLC_SET_VL_G3(-0.44913470507964515);
    // Set group 3 bol bias 03 (VRL) to 0.41129613196665515 Volts
    Pacs_BOLC_SET_VRL_G3(0.41129613196665515);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678587117184813 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678587117184813);
    // Set group 4 bol bias 01 (VH) to 2.5882911597682976 Volts
    Pacs_BOLC_SET_VH_G4(2.5882911597682976);
    // Set group 4 bol bias 02 (VL) to -0.41170884023170246 Volts
    Pacs_BOLC_SET_VL_G4(-0.41170884023170246);
    // Set group 4 bol bias 03 (VRL) to 0.4157696828076755 Volts
    Pacs_BOLC_SET_VRL_G4(0.4157696828076755);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.176103521606246 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.176103521606246);
    // Set group 5 bol bias 01 (VH) to 1.943787827895409 Volts
    Pacs_BOLC_SET_VH_G5(1.943787827895409);
    // Set group 5 bol bias 02 (VL) to -0.456212172104591 Volts
    Pacs_BOLC_SET_VL_G5(-0.456212172104591);
    // Set group 5 bol bias 03 (VRL) to 0.4197436307675042 Volts
    Pacs_BOLC_SET_VRL_G5(0.4197436307675042);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1765985179562617 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1765985179562617);
    // Set group 6 bol bias 01 (VH) to 1.9668712183445327 Volts
    Pacs_BOLC_SET_VH_G6(1.9668712183445327);
    // Set group 6 bol bias 02 (VL) to -0.4331287816554672 Volts
    Pacs_BOLC_SET_VL_G6(-0.4331287816554672);
    // Set group 6 bol bias 03 (VRL) to 0.4215254429444202 Volts
    Pacs_BOLC_SET_VRL_G6(0.4215254429444202);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176741648076014 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176741648076014);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.962573816354465 Volts
    Pacs_BOLC_SET_VH_G1(2.962573816354465);
    // Set group 1 bol bias 02 (VL) to -0.33742618364553495 Volts
    Pacs_BOLC_SET_VL_G1(-0.33742618364553495);
    // Set group 1 bol bias 03 (VRL) to 0.43473343120463254 Volts
    Pacs_BOLC_SET_VRL_G1(0.43473343120463254);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201011107670087 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201011107670087);
    // Set group 2 bol bias 01 (VH) to 2.881227415881421 Volts
    Pacs_BOLC_SET_VH_G2(2.881227415881421);
    // Set group 2 bol bias 02 (VL) to -0.41877258411857887 Volts
    Pacs_BOLC_SET_VL_G2(-0.41877258411857887);
    // Set group 2 bol bias 03 (VRL) to 0.41474570655318654 Volts
    Pacs_BOLC_SET_VRL_G2(0.41474570655318654);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176743089640317 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176743089640317);
    // Set group 3 bol bias 01 (VH) to 2.9218070654441264 Volts
    Pacs_BOLC_SET_VH_G3(2.9218070654441264);
    // Set group 3 bol bias 02 (VL) to -0.3781929345558735 Volts
    Pacs_BOLC_SET_VL_G3(-0.3781929345558735);
    // Set group 3 bol bias 03 (VRL) to 0.43330579495861793 Volts
    Pacs_BOLC_SET_VRL_G3(0.43330579495861793);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.192178779777237 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.192178779777237);
    // Set group 4 bol bias 01 (VH) to 2.9366128349680927 Volts
    Pacs_BOLC_SET_VH_G4(2.9366128349680927);
    // Set group 4 bol bias 02 (VL) to -0.36338716503190727 Volts
    Pacs_BOLC_SET_VL_G4(-0.36338716503190727);
    // Set group 4 bol bias 03 (VRL) to 0.4248666807785261 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248666807785261);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864967908026665 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864967908026665);
    // Set group 5 bol bias 01 (VH) to 2.128392507736531 Volts
    Pacs_BOLC_SET_VH_G5(2.128392507736531);
    // Set group 5 bol bias 02 (VL) to -0.47160749226346943 Volts
    Pacs_BOLC_SET_VL_G5(-0.47160749226346943);
    // Set group 5 bol bias 03 (VRL) to 0.4241232938294539 Volts
    Pacs_BOLC_SET_VRL_G5(0.4241232938294539);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1818388218172275 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1818388218172275);
    // Set group 6 bol bias 01 (VH) to 2.1480917942872066 Volts
    Pacs_BOLC_SET_VH_G6(2.1480917942872066);
    // Set group 6 bol bias 02 (VL) to -0.45190820571279333 Volts
    Pacs_BOLC_SET_VL_G6(-0.45190820571279333);
    // Set group 6 bol bias 03 (VRL) to 0.42139379769185026 Volts
    Pacs_BOLC_SET_VRL_G6(0.42139379769185026);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.176582736379955 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.176582736379955);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //********************************
    // Epilogue : Set the safe biases
    //********************************
    PHOT_set_bias_volt(endBiasTable,1);
    PHOT_set_bias_volt(endBiasTable,2);
    PHOT_set_bias_volt(endBiasTable,3);
    PHOT_set_bias_volt(endBiasTable,4);
    PHOT_set_bias_volt(endBiasTable,5);
    PHOT_set_bias_volt(endBiasTable,6);
    //
    // sync the bus
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Open_Launch_Lock {
    /* No variables to call PacsEng_Open_Launch_Lock                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Open_Launch_Lock                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Open_Launch_Lock()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Open_Launch_Lock();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : IST level
//
// Purpose : EMC preparation in DDCS mode
//
// Author : Koryo Okumura / Thomas Mueller
//
// CUS script : procedure Phot_prepareEMC_DDCS
//
// Argument : None
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + CSs are cold
//
// Description :
//
// Dependencies : None
//
// Comments : 
//
// Version : Mon Jun 18 2007
//
procedure Phot_prepareEMC_DDCS {
}{
    string biasFile = "BOLObias_ILT_dark_high";
    // Bias table file containing the initial values
    //
    //***********************************************
    //***********************************************
    //
    //	Bias setting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(biasFile,1);
    PHOT_set_bias_volt(biasFile,2);
    PHOT_set_bias_volt(biasFile,3);
    PHOT_set_bias_volt(biasFile,4);
    PHOT_set_bias_volt(biasFile,5);
    PHOT_set_bias_volt(biasFile,6);
    //
    //**************************
    // Sequence mode : Sb_Sref
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sb_Sref (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sb_Sref");
    //# P 09 01 00 00
    int operand = 0x9010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // Set gain high
    Pacs_BOLC_SET_GAIN("HIGH");
    //
    //**********************************************
    // Set the PACS chopper to CS1
    //**********************************************
    Pacs_DMC_MOVE_CHOP_ABS(-21350);
    //
    //*******************************
    // Select Filter A (110 microns)
    //*******************************
    PHOT_fltw_move("POS A");
    //
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : PACS Spectrometer FoV Scan on the cryo cover
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version	: 1.0
// History       : 1.0  11-Mar-2008  Converted into PV script by PR
//
obs PacsCal_Spec_Fov_Scan {
    /* Needed variables to call PacsCal_Spec_FoV_Scan                        */
    int grat_pos = 535000; // Grating position (grating is fixed)
    string filter_pos = "POS A" in ["POS A","POS B"];
    int chop_start_pos = -23500; // Chopper start position
    int nb_steps_up = 310; // P#3  number of steps up
    int step_up = 150; // P#5  step_up:  relative move up
    int nb_up_dn = 1; // P#1  number of up-down seqs.
    int nb_ramps = 2; // P#2  number of ramps on step
    int nb_rdouts_ramp = 64; // Ramp length used in computation of OBCP duration only
    int nb_samp_subramp_blu = 64; // Red Subramp length  (directly connected to ramp_fit_alg)
    int nb_samp_subramp_red = 64; // Blue Subramp length
    int ramp_fit_alg = 0 in [0,1]; // Ramp fit algorithm [0=LstSq;1=mean value]
    /* POINTING PARAMETERS */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    /* End of needed variables for PacsEng_Spec_FoV_Scan                     */
}{
    // Fixed Parameters
    int nb_steps_dn = nb_steps_up;
    // P#4  number of steps down
    int step_dn = -step_up;
    // P#6  relative move down
    int grat_time = 15000;
    // Grating time
    int grat_def_time = 15000;
    // Grating default time
    int chop_def = 650;
    // Chopper default position
    int detector = 1;
    // Detector to SYNCH on
    int grat_def = 500000;
    // Grating default
    int comp_mode_blu = 16;
    // "Blue" compression
    int comp_mode_red = 16;
    // "Red" compression
    //
    bool verbose = true;
    //
    //
    int chop_limit_dn = ilookup("SPEC_MEC_Limits","Nominal","chop_min");
    int chop_limit_up = ilookup("SPEC_MEC_Limits","Nominal","chop_max");
    int chop_max_pos = chop_start_pos + nb_steps_up * step_up;
    if(chop_start_pos < chop_limit_dn) {
        error("ERROR! chop_start_pos " + chop_start_pos + " is beyond the max allowed negative chopper throw " + chop_limit_dn);
    }
    if(chop_max_pos > chop_limit_up) {
        error("ERROR! chop_max_pos " + chop_max_pos + " is beyond the max allowed positive chopper throw " + chop_limit_up);
    }
    //
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    int tslewmin = 0;
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Fov_Scan(nb_samp_subramp_blu,nb_samp_subramp_red,ramp_fit_alg,filter_pos,nb_up_dn,nb_ramps,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,grat_pos,chop_start_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,chop_def,nb_rdouts_ramp)));
    if(verbose) {
        debug_print("Duration of PacsSpecSlewCal_Flex" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    debug_print("ts: " + ts);
    //
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Fov_Scan(nb_samp_subramp_blu,nb_samp_subramp_red,ramp_fit_alg,filter_pos,nb_up_dn,nb_ramps,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,grat_pos,chop_start_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,chop_def,nb_rdouts_ramp);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsRangeSpecSed.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $
// Missionphase  : Operations
//
// Purpose       : 
//
// CUS author    : DAC
// Script file   : PacsRangeSpecSed.txt 
//
// Input arguments
// type     name      description
// bool     sedRED    perform RED SED, i.e. from 75 to 205 microns
// bool     sedBLU    perform BLU SED, i.e. from 55 to 75 microns
// Return values
// Type                Description
// {string,double,double,double,double,double} []   
// {"SED",blue,red,dummy,dummy,dunmmy}]
//
// Description   : Creates RED or BLU "range" variable for the SED case
//
// Preconditions :
//
// Comments      : This version assumes sedRED and sedBLU to be mutually
//                 exclusive, i.e. either one or the other, not both
// 
// History       : 0.1 21-Jun-2005 DAC
// 1.0 15-sep-2005 Modified for "OBS" version of CUS
// 1.1 11-may-2006 Element {3} of range tuple is now int (the 
//                 repetition count)
// 1.2  7-jun-2006 Introduce sedRED and sedBLU arguments to
//                 generate one or the other range
// 1.3 22-jun-2006 Use new ranges (with lineWidth)
// 2.0 12-apr-2007 Changes for SCR-3050. Input argument
//                 is now selected sed mode. Add "order"=6 for short 
//                 wavelengths at order 2.
// 3.0 25-apr-2007 Defined returned range similar to rangeSPOT
// 4.0 30-nov-2009 VD PHS-1272 + PHS-1274
// 5.0 08-dec-2009 VD PHS-1285: dithering SED!!!!
// 
{string,double,double,int,double,double,double,string,string,double}[] procedure PacsRangeSpecSed {
    string orderSel = "sed2" in ["sed2","sed3","sed4","sedb2b","sedb2a","sedb3a"];
    int repeatSed = 1;
}{
    // Return variable
    {string,double,double,int,double,double,double,string,string,double}[] range = [{"SED",0.0,0.0,0,0.0,0.0,0.0,"","",0.0}];
    // Create ranges defined by ORDER= 4, 5, and 6 (see CAL-U SPEC_BAND_params)
    if(orderSel == "sed2") {
        string key = "4";
    }
    if(orderSel == "sed3") {
        key = "5";
    }
    if(orderSel == "sed4") {
        key = "6";
    }
    if(orderSel == "sedb2b") {
        key = "b2b";
    }
    if(orderSel == "sedb2a") {
        key = "b2a";
    }
    if(orderSel == "sedb3a") {
        key = "b3a";
    }
    int loop0 = 0;
    double bluWave = dlookup("SPEC_BAND_params",key,"BLU");
    double redWave = dlookup("SPEC_BAND_params",key,"RED");
    range[loop0] = {orderSel,0.0,0.0,0,0.0,0.0,0.0,"","",0.0};
    range[loop0]{1} = bluWave;
    range[loop0]{2} = redWave;
    if(repeatSed > 1) {
        for(int loopDith = 1 .. repeatSed - 1) {
            // the funtion??
            double waveDither = double(loopDith) * (0.1 / double(repeatSed)) + 0.01;
            double bluWaveDith = bluWave + waveDither;
            range[loopDith] = {orderSel,0.0,0.0,0,0.0,0.0,0.0,"","",0.0};
            range[loopDith]{1} = bluWaveDith;
            range[loopDith]{2} = redWave;
            // That's it...     
        }
    }

    return range;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Fil_Testseq {
    /* No variables to call PacsEng_Spec_Fil_Testseq                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Fil_Testseq                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Fil_Testseq()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Fil_Testseq();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Gra_SFT_Warm {
    /* No variables to call PacsEng_Spec_Gra_SFT_Warm                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_SFT_Warm                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_SFT_Warm()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_SFT_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Spec_Dark_CS_SequentialWarmUp
// Missionphase  : PACS FM IST   SOVT2
//
// Purpose       : Dark Current Measurement / Assessment of straylight, PACS Spectro.
//
// Author        : Pierre Royer
// CUS script	 : PR
// CVS file	 :
//
// Arguments     : 
//
// Description   :   Visit grating positions of Low RSRF for the dark
//	     Estimate Straylight contribution from visiting High RSRF positions & placing the FW outside of any regular filter position.
//	     Do it for both filters
//	     Part 2 : chop between CS1, CS2, and chopper pos = 0 during the warm up of CS1 & CS2 (happening sequentially).
//	     There should be transients > 3 minutes at the beginning (low flux), but this should at least give an idea, and several samples over the warm up time
//
// Dependencies  :
//
// Comments      : !!! It is supposed that PacsEng_Spec_setup has been run before this script, with current to both CSs == 0. !!!
// 		   !!! The CRE settings (incl. BIAS) are HARDCODED in here => Modify them if necessary !!!
//
// Version       : 1.1
// History       : 1.0 / 17-Nov-2008 
//	 1.1   23-Jul-2009 Modified SPU parameters -> slope fit + flight biases
//	 1.1 / 23-Jul-2009 Update biases & SPU mode to slope fitting
//                             29-07-2009 Update history to reflect the corresponding SPRs: PACS-1798 & 1858, PHS-1128
//
procedure PACS_Spec_Dark_CS_SequentialWarmUp {
    int obs_time = 540; // observing time in seconds per CS/FW/Grat setting
    int chop_time = 180; // duration of chopper plateau during rise of CS temp (0 = no chopping)
}{
    //
    // Declare the set of variables specific to this test
    // ===========================
    //
    // Standard duration of CS warm up
    double cswarmup_time = 2200.0;
    //
    // chopper positions
    string[] chopPos = ["pos_CS1","pos_CS2"];
    int choppos = 0;
    //
    // Define the combinations of Grating & FW positions to be tested on each CS
    string[] filterPos = ["POS B","POS B","POS A","POS A"];
    int[] gratingPos = [50000,740000,675000,800000];
    int n_settings = length(gratingPos);
    if(length(filterPos) != n_settings) {
        debug_print("Inconsistent number of grating and filter wheel positions specified");
    }
    //
    // Declare the CS Temps (48, 58 Ohms, copied from the SPEC_setup block (in 
    // ============= 
    double temp_CS1 = 48.0;
    //  Temperature 55K for the PACS calibration source 1 
    double temp_CS2 = 58.0;
    //  Temperature 60K for the PACS calibration source 2
    //
    // Declare the set of CRE variables
    // ===================
    double bias_d_blue = 0.01;
    double bias_d_red = 0.042;
    double bias_res_blue = 0.01;
    double bias_res_red = 0.01;
    int ramp_blue = 64;
    int ramp_red = 64;
    int capacity_blue = 0;
    int capacity_red = 0;
    // 
    // Declare the set of SPU variables
    // ===================
    //
    // Compression mode blue channel : Nominal
    int comp_mode_blu = 16;
    // Compression mode red channel : Nominal
    int comp_mode_red = 16;
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_blu = 64;
    // Nb of red samples per sub-ramp
    int nb_samp_subramp_red = 64;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUL
    int nb_raw_spu_red = 3;
    // Glitch detection; 0=on; 1=off
    int glitch_det = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    int ramp_fit_alg = 0;
    // Start SPU or not [true,false]
    bool startSPU = true;
    //
    // SETUP CRE & SPU
    // ==========
    // Setup CREs
    SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red);
    //
    // Setup SPU
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //
    // PART 1 : CS OFF, VISIT LOW & HIGH RSRF POSITIONS IN BOTH FILTERS
    //
    for(int cs = 0 .. length(chopPos) - 1) {
        //
        // Position the chopper
        // ============
        choppos = ilookup("CHOPPERCSparams","SPEC",chopPos[cs]);
        PACS_Chop_Move_Abs(choppos);
        //
        for(int n = 0 .. n_settings - 1) {
            debug_print("choppos " + choppos + " n " + n + " filterPos[n] " + filterPos[n] + " gratingPos[n] " + gratingPos[n]);
            //
            // ==FW POS ==
            SPEC_fltw_move(filterPos[n]);
            //
            // ==GRAT POS ==
            Pacs_DMC_MOVE_GRAT_ABS(gratingPos[n]);
            //
            // == OBS TIME ==
            delay(obs_time);
            //
            // == FW --> 90 DEGREES == 
            SPEC_fltw_move_90degrees();
            //
            // ==GRAT POS ==
            Pacs_DMC_MOVE_GRAT_ABS(gratingPos[n]);
            //
            // == OBS TIME ==
            delay(obs_time);
            //
        }
    }
    //
    // PART 2 :  RISING CS TEMPs, CHOP SLOWLY BETWEEN BOTH CS
    //
    // ==FW POS ==
    SPEC_fltw_move("POS B");
    //
    // ==GRAT POS ==
    Pacs_DMC_MOVE_GRAT_ABS(50000);
    //
    debug_print("Grating reset to 50000, FW set to POS B, CS switched on and warmed up");
    //
    // PACS CALIBRATION SOURCES
    CONF_cs("Both");
    CS_on_off("CS1","ON");
    CS_temp("CS1",temp_CS1);
    //
    // == CS1 ==
    choppos = ilookup("CHOPPERCSparams","SPEC","pos_CS1");
    PACS_Chop_Move_Abs(choppos);
    delay(chop_time);
    int[] choplist = [0,ilookup("CHOPPERCSparams","SPEC","pos_CS2"),ilookup("CHOPPERCSparams","SPEC","pos_CS1")];
    int npos = length(choplist);
    if(chop_time > 0) {
        //
        // Chop CS1 - center - CS2 for the warm up duration,  + 1 final visit of each position
        int nchop = iround(cswarmup_time / double(chop_time)) + 3;
        debug_print("Chopping every " + chop_time + " seconds");
        debug_print("nchop x chop_time = " + nchop + " x " + chop_time + " = " + nchop * chop_time);
        //
        if(nchop >= 2) {
            //
            for(int i2 = 0 .. nchop - 2) {
                choppos = choplist[i2 % npos];
                PACS_Chop_Move_Abs(choppos);
                debug_print("choppos " + choppos);
                delay(chop_time);
            }
        }
    } else {
        choppos = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
        PACS_Chop_Move_Abs(choppos);
        debug_print("No chopping: chopper position " + choppos);
        delay(iround(cswarmup_time));
    }
    //
    // == CS2 ==
    CS_on_off("CS2","ON");
    CS_temp("CS2",temp_CS2);
    choppos = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    PACS_Chop_Move_Abs(choppos);
    delay(chop_time);
    choplist = [0,ilookup("CHOPPERCSparams","SPEC","pos_CS1"),ilookup("CHOPPERCSparams","SPEC","pos_CS2")];
    npos = length(choplist);
    if(chop_time > 0) {
        //
        // Chop CS1 - center - CS2 for the warm up duration,  + 1 final visit of each position
        int nchop2 = iround(cswarmup_time / double(chop_time)) + 3;
        debug_print("Chopping every " + chop_time + " seconds");
        debug_print("nchop2 x chop_time = " + nchop2 + " x " + chop_time + " = " + nchop2 * chop_time);
        //
        if(nchop2 >= 2) {
            //
            for(int i = 0 .. nchop2 - 2) {
                choppos = choplist[i % npos];
                PACS_Chop_Move_Abs(choppos);
                debug_print("choppos " + choppos);
                delay(chop_time);
            }
        }
    } else {
        choppos = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
        PACS_Chop_Move_Abs(choppos);
        debug_print("No chopping: chopper position " + choppos);
        delay(iround(cswarmup_time));
    }
    //
    // FINALISATION
    //
    // Return Chopper & grating to default
    // ===================================
    Pacs_DMC_MOVE_GRAT_ABS(500000);
    delay(1);
    PACS_Chop_Move_Abs(0);
    delay(10);
    //
    // SYNC
    //= = =
    sync();
    //
    // End of Script
}

// Filename	: Pacs_Spec_detector_imt509
//
// Purpose	: Ge:Ga detector bias scan
//
// Author	: Helmut Dannerbauer &Roland Vavrek
// CUS script	: HD
// CVS file	: 
//
// Arguments	: - Bias_d blue parameters from 1 to 8
//                     - Bias_d red  parameters from 1 to 8
//                 
//		   
// Description	: Loop over 8 different bias values while chopper stairs on CS2. Each bias setting
//                        is followed by a 120 sec measurement.
//                  
// Dependencies :  - PACS_Spec_Heat_Setup
//                 - PACS_Chopper_mov_abs_fm_bb
//                 - SPEC_Gra_move_abs_raw
//                 - SPEC_spu_reset
//                 - SPEC_cre_setup
//                 - SPEC_spu_setup
//
//
// Preconditions : - PACS is switched on
//                        - Setup spectroscopy
//	     - Mechanics and CS controllers are SWON and ENABLED (e.g. SetupSpectroscopyEQMIMT)
//                        - CS2 temperature has been staibilized already
//
// Comments	: Blue heater heaters are kept on constant temperature. 
//
// Version	: 2.1
//               
// History	: 1.0 HD. IST update.
// 		  2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//                      2.1 8-Apr-2008 HF changed default biases for in-flight
//
procedure Pacs_Spec_detector_imt509 {
    double bias_d_blue1 = 0.08; //Blue bias #1
    double bias_d_blue2 = 0.11; //Blue bias #2
    double bias_d_blue3 = 0.14; //Blue bias #3
    double bias_d_blue4 = 0.17; //Blue bias #4
    double bias_d_blue5 = 0.2; //Blue bias #5
    double bias_d_blue6 = 0.23; //Blue bias #6
    double bias_d_blue7 = 0.26; //Blue bias #7
    double bias_d_blue8 = 0.29; //Blue bias #8
    double bias_d_red1 = 0.02; //Red bias #1
    double bias_d_red2 = 0.03; //Red bias #2
    double bias_d_red3 = 0.04; //Red bias #3
    double bias_d_red4 = 0.05; //Red bias #4
    double bias_d_red5 = 0.06; //Red bias #5
    double bias_d_red6 = 0.07; //Red bias #6
    double bias_d_red7 = 0.08; //Red bias #7
    double bias_d_red8 = 0.09; //Red bias #8
}{
    //
    // 1 Parameter definitions
    //
    // 1.1 Mechanics
    //
    // chopper in zero position
    int chop_def_zero = 0;
    // chopper on CS2
    int chop_CS2_pos = 21200;
    // grating on a key wavelength
    int grat_key_lambda = 535000;
    //
    // 1.2 Ge:Ga detectors
    //
    // Add values to the bias lists
    double[] bias_d_blue_list = [bias_d_blue1,bias_d_blue2,bias_d_blue3,bias_d_blue4,bias_d_blue5,bias_d_blue6,bias_d_blue7,bias_d_blue8];
    double[] bias_d_red_list = [bias_d_red1,bias_d_red2,bias_d_red3,bias_d_red4,bias_d_red5,bias_d_red6,bias_d_red7,bias_d_red8];
    // Red  ramp length
    int ramp_len_red = 128;
    // Blue ramp length
    int ramp_len_blu = 128;
    // BIAS_R for red spectro  (0-1V)
    double bias_r_red = 0.01;
    // BIAS_R for blue spectro (0-1V)
    double bias_r_blu = 0.01;
    // BIAS_D nominal for red spectro (0-1V)
    double bias_d_red = 0.069;
    // BIAS_D nominal for blue spectro (0-1V)
    double bias_d_blu = 0.168;
    // Capacitor red  (0=100fF,8=300fF,4=1pf,12=3pF)
    int capa_red = 0;
    // Capacitor blue (0=100fF,8=300fF,4=1pf,12=3pF)
    int capa_blu = 0;
    //
    // 1.3 SPU
    //
    // Compression mode blue channel : Nominal
    int comp_mode_blu = 16;
    // Compression mode red channel : Nominal
    int comp_mode_red = 16;
    // Nb of blue samples per sub-ramp 
    int nb_samp_subramp_blu = 32;
    // Nb of red samples per sub-ramp 
    int nb_samp_subramp_red = 32;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUL
    int nb_raw_spu_red = 3;
    // Glitch detection; 0=on; 1=off
    int glitch_det = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    int ramp_fit_alg = 1;
    // Start SPU or not [true,false]
    bool startSPU = true;
    //
    // 2 Prepare to start the test
    //  
    // Position chopper on CS2
    PACS_Chopper_mov_abs_fm_bb(chop_CS2_pos);
    // Move grating to a key wavelength
    SPEC_Gra_move_abs_raw(grat_key_lambda);
    delay(40);
    int n = 0;
    //
    // 3 Bias loop start
    //
    while(n < length(bias_d_blue_list)) {
        // BIAS_D for red spectro  (0-1V)
        bias_d_red = bias_d_red_list[n];
        // BIAS_D for blue spectro (0-1V)
        bias_d_blu = bias_d_blue_list[n];
        // Setup CREs       
        SPEC_CRE_No_Heater_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
        // Setup SPU
        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
        //observing time 120 seconds
        delay(120);
        // Stop SPU, rewrite bias_d values
        SPEC_spu_reset();
        n = n + 1;
    }
    //
    // 4 Reset the detectors with nominal settings
    //
    // Position chopper on zero position
    PACS_Chopper_mov_abs_fm_bb(chop_def_zero);
    //CRE default
    // Red  ramp length
    ramp_len_red = 64;
    // Blue ramp length
    ramp_len_blu = 64;
    // BIAS_R for red spectro  (0-1V)
    bias_r_red = 0.01;
    // BIAS_R for blue spectro (0-1V)
    bias_r_blu = 0.01;
    // BIAS_D nominal for red spectro (0-1V)
    bias_d_red = 0.03;
    // BIAS_D nominal for blue spectro (0-1V)
    bias_d_blu = 0.08;
    // Capacitor red  (0=100fF,8=300fF,4=1pf,12=3pF)
    capa_red = 0;
    // Capacitor blue (0=100fF,8=300fF,4=1pf,12=3pF)
    capa_blu = 0;
    // Setup CREs in nominal configuration       
    SPEC_CRE_No_Heater_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,12,12);
    // Default Grating Position
    SPEC_Gra_move_abs_raw(496000);
    delay(40);
}

// $Id: PacsEng_PHOT_orbit_prologue01.txt,v 1.8 2008/11/12 11:40:20 vanessad Exp $
// Purpose        : Bring PACS from switched off condition to standby
//                  for PHOT observations
//
// CUS author     : Composed from various ILT modules
//
// Input arguments: see after module identification
//
// Return values
// N/A
//
// Comments      : SCR PACS-1866
//
// History: 
// 0.1  25-jun-2007  Created from ILT modules
// 0.2   9-aug-2007  Conformed to JonBr's mail (07/26/07)
// 1.0  21-aug-2007  Renamed from PACS_PHOT_orbit_prologue
//                                Use new "no_pointing" pointing request and
//                                StateMachine logic
// 1.1 20-may-2008  KO, Debugged for the pointing timing logic
// 1.2 24-jun-2008 KO, calUfile, temp_CS1 and temp_CS2 put in the argument
// 1.3 25-jun-2008 KO, CSs stabilisation time tSET put in the argument and the default calUfile changed to ILT
// 1.4 11-nov-2008 VD&KO&TM tSet chnaged to 2100s to allow for stabilisation
// 1.5 12-nov-2008 KO gotoDirect option added
// 1.6 10-apr-2009 KO VRL and 40Hz option added during the stabilization waiting time
// 1.7 04-may-2009 KO,NB choise corrected to choice!!!
// 1.8 11-jun-2009 KO Default choice is set to justWait
//
obs PacsEng_PHOT_orbit_prologue01 {
    string calUfile = "BOLObias_ILT_standard_low"; // Bias table
    double set_CS1 = 48.0; // CS1 settings (ohms)
    double set_CS2 = 58.0; // CS2 settings (ohms)
    int waitTime = 2100; // CSs stabilisation time in seconds > 200
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
    string choice = "justWait" in ["VRL","40Hz","justWait"]; // What to do during stabilization
    string waitBias = "BOLObias_standard_high"; // Bias used during CSs stabilization
}{
    // Settling time for CS
    string fltPOS = "POS A";
    bool execute = true;
    // Initial hold
    int tih = imax(1,duration(WriteOBSID($OBSID)));
    // Final hold
    int tfh = imax(1,duration(WriteEndID()));
    // Duration of "stable" pointing
    int tp = duration(PHOT_setup12346(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect));
    // Wait for CS to stabilize
    if(choice == "VRL") {
        // Vrl measurement during the stabilization
        tp = tp + duration(Phot_lowFreq_Vrl_filler(waitTime - 200,waitBias,calUfile,gotoDirect));
    } else {
        if(choice == "40Hz") {
            // sky measurement at 40Hz during the stabilization
            tp = tp + duration(Phot_SPU40Hz_filler(waitTime - 200,waitBias,calUfile,gotoDirect));
        } else {
            tp = tp + waitTime;
        }
    }
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //     Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //     Call the PHOT setup script
            PHOT_setup12346(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect);
            //     Wait for CS to stabilize
            if(choice == "VRL") {
                // Vrl measurement during the stabilization
                Phot_lowFreq_Vrl_filler(waitTime - 200,waitBias,calUfile,gotoDirect);
            } else {
                if(choice == "40Hz") {
                    // sky measurement at 40Hz during the stabilization
                    Phot_SPU40Hz_filler(waitTime - 200,waitBias,calUfile,gotoDirect);
                } else {
                    delay(waitTime);
                }
            }
        }
        if(state[0] == 5) {
            //     Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// $Id: PacsEng_PHOT_orbit_prologue00.txt,v 1.8 2008/11/12 11:40:20 vanessad Exp $
// Purpose        : Bring PACS from switched off condition to standby
//                  for PHOT observations
//
// CUS author     : Composed from various ILT modules
//
// Input arguments: see after module identification
//
// Return values
// N/A
//
// Comments      : SCR PACS-1866
//
// History: 
// 0.1  25-jun-2007  Created from ILT modules
// 0.2   9-aug-2007  Conformed to JonBr's mail (07/26/07)
// 1.0  21-aug-2007  Renamed from PACS_PHOT_orbit_prologue
//                                Use new "no_pointing" pointing request and
//                                StateMachine logic
// 1.1 20-may-2008  KO, Debugged for the pointing timing logic
// 1.2 24-jun-2008 KO, calUfile, temp_CS1 and temp_CS2 put in the argument
// 1.3 25-jun-2008 KO, CSs stabilisation time tSET put in the argument and the default calUfile changed to ILT
// 1.4 11-nov-2008 VD&KO&TM tSet chnaged to 2100s to allow for stabilisation
// 1.5 12-nov-2008 KO gotoDirect option added
// 1.6 10-apr-2009 KO VRL and 40Hz option added during the stabilization waiting time
// 1.7 04-may-2009 KO,NB choise corrected to choice!!!
// 1.8 11-jun-2009 KO Default choice is set to justWait
//
obs PacsEng_PHOT_orbit_prologue00 {
    string calUfile = "BOLObias_ILT_standard_low"; // Bias table
    double set_CS1 = 48.0; // CS1 settings (ohms)
    double set_CS2 = 58.0; // CS2 settings (ohms)
    int waitTime = 2100; // CSs stabilisation time in seconds > 200
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
    string choice = "justWait" in ["VRL","40Hz","justWait"]; // What to do during stabilization
    string waitBias = "BOLObias_standard_high"; // Bias used during CSs stabilization
}{
    // Settling time for CS
    string fltPOS = "POS A";
    bool execute = true;
    // Initial hold
    int tih = imax(1,duration(WriteOBSID($OBSID)));
    // Final hold
    int tfh = imax(1,duration(WriteEndID()));
    // Duration of "stable" pointing
    int tp = duration(PHOT_setup1234(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect));
    // Wait for CS to stabilize
    if(choice == "VRL") {
        // Vrl measurement during the stabilization
        tp = tp + duration(Phot_lowFreq_Vrl_filler(waitTime - 200,waitBias,calUfile,gotoDirect));
    } else {
        if(choice == "40Hz") {
            // sky measurement at 40Hz during the stabilization
            tp = tp + duration(Phot_SPU40Hz_filler(waitTime - 200,waitBias,calUfile,gotoDirect));
        } else {
            tp = tp + waitTime;
        }
    }
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //     Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //     Call the PHOT setup script
            PHOT_setup1234(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect);
            //     Wait for CS to stabilize
            if(choice == "VRL") {
                // Vrl measurement during the stabilization
                Phot_lowFreq_Vrl_filler(waitTime - 200,waitBias,calUfile,gotoDirect);
            } else {
                if(choice == "40Hz") {
                    // sky measurement at 40Hz during the stabilization
                    Phot_SPU40Hz_filler(waitTime - 200,waitBias,calUfile,gotoDirect);
                } else {
                    delay(waitTime);
                }
            }
        }
        if(state[0] == 5) {
            //     Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// CVS comments  : $Id: SortProc.txt,v 1.2 2007/04/25 15:14:05 dcesarsk Exp $ 
// Purpose       : Sort (from smallest to largest) an input "double" array
// Returns array of sorted indices (and not the sorted array). This feature 
// allows sorting sets of data, f.i. a tuple [wavelength,range,flux]. The
// sorted index array (sorted = SortProc(wavelength)) can be used to sort
// the tuple: [wavelength[sort], range[sort], flux[sort]]
//
// TCL author    : N/A
// TCL file      : N/A
// CUS author    : DAC
// Script file   : SortProc.txt 
//
// Input arguments
// type    name         Description
// double  inArray      Any double array to be sorted from smallest to largest
//
// Return values
// Type    Name         Description
// int     sorted       The indexes to sort inArray (inArray[sort] is sorted)
//
// Description   :"Bubble" sort algorithm. Returns array of "sorted" indices.
// The algorithm finds and places the largest element at the end of the
// input array and proceeds to do the same with the [size-1] remaining elements,
// until all elements are moved to the (shrinking) last place. 
// As an example: the default inArray:
//       double[] inArray = [0.0, 3.0, 2.0, 4.0, -1.0]
// will return:
//       sorted = [4,0,2,1,3]
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : Wikipedia C code:
//
//     void bubbleSort(int *array, int length)
//     {
//       int i, j;
//       int dblSwap;
//       for(i = length - 1; i > 0; i--)
//         for(j = 0; j < i; j++)
//           if(array[j] > array[j+1]) /* compare neighboring elements */
//           {
//             dblSwap = array[j];    /* swap array[j] and array[j+1] */
//             array[j] = array[j+1];
//             array[j+1] = dblSwap;
//           }
//     }
// 
// History       : 0.1  2-may-2005 DAC
//                 1.0 26-aug-2005 DAC Introduced "verbose" 
int[] procedure SortProc {
    bool verbose = false; // Print debugging info
    double[] inArray = [0.0]; // Input array
}{
    double dblSwap = 0.0;
    int intSwap = 0;
    int sizeArray = length(inArray);
    int[] sorted = [0];
    // Initialize sorted array
    for(int aux = 0 .. sizeArray - 1) {
        sorted[aux] = aux;
    }
    // Sort if more than one element
    if(sizeArray > 1) {
        //   CUS loops do not have negative increment (loop increasing and compute
        //   decreasing index)
        for(int loop = 0 .. sizeArray - 1) {
            int i = sizeArray - 1 - loop;
            for(int j = 0 .. i - 1) {
                if(inArray[j] > inArray[j + 1]) {
                    //                swap inArray[j] and inArray[j+1]
                    dblSwap = inArray[j];
                    inArray[j] = inArray[j + 1];
                    inArray[j + 1] = dblSwap;
                    intSwap = sorted[j];
                    sorted[j] = sorted[j + 1];
                    sorted[j + 1] = intSwap;
                }
            }
        }
    }
    if(verbose) {
        debug_print("Sorted indices: " + sorted);
    }

    return sorted;
}

// Missionphase  : 
//
// Purpose       : Compute execution time of DMC #12: 
//                 Grating Line Scan with Two position chopping
//
// TCL author    : N/A Pseudo code by HF
// TCL file      : N/A
// CUS author    : DAC
// Script file   : DMC_12_grat_line_scan_with_2_chop.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Similar to 4.2.1 but with only two chopping positions. 
//                 It is meant to allow for faster execution once only two
//                 chopping positions are used on bright targets.
//                 Of the 11 Parameters: 
//                    # of "up-down" sequences (P#1); 
//                    2 chopper positions (P#4, P#6); 
//                    # of readouts per chopper position (P#5); 
//                    # of cycles per grating position (P#3); 
//                    size of relative grating move up (P#10); 
//                    size of relative grating move down (P#11); 
//                    # of cycles on the internal calibration sources (P#7); 
//                    position of BB1 (P#8); 
//                    position of BB2 (P#9);
//                    # of grating steps (P#2)
//                  only those involved in time estimation are used here.
//                  
// Dependencies  : 
//
// Preconditions : None.
//                 
// Comments      : No TC are generated; only times are computed
// 
// History       : 0.1 14-apr-2005 DAC
//                 0.2 23-mar-2007 chopper WAIT=1 is a good readout
// 
int[] procedure DMC_12_grat_line_scan {
    int nb_up_down = 1; // Seq P#1 : Nb of sequences: up down up ...
    int nb_grat_steps = 1; // Seq P#2 : Nb of grating steps (up/down scans)
    int nb_ramps_plateau = 1; // Seq P#5 : Nb of ramps per chopper position
    int nb_CS1_CS2 = 1; // Seq P#7 Nb of cycles on CS, per grating position
    int nb_cycles_grat_pos = 1; // Seq P#3 : Nb of cycles per grating position
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    // WAIT 1                                             ; have a defined start
    duree_OVR = duree_OVR + 1;
    duree_num = duree_num + 1;
    // LABEL 0                                            ; set Label to 0 
    // LOOP P#1                                           ; main loop measurement
    for(int up_down = 1 .. nb_up_down) {
        //LOOP P#2 ; grating loop up
        for(int up = 1 .. nb_grat_steps) {
            // WAIT 1                                      ; sync. for grating 
            duree_OVR = duree_OVR + 1;
            duree_num = duree_num + 1;
            // MOVE_GRATING_RELATIVE P#10                  ; increment grating position 
            // LOOP P#3 ; chop readout cycle
            for(int chop_cycle_1 = 1 .. nb_cycles_grat_pos) {
                // WAIT 1                                   ; sync. for chopper   
                duree_SRC = duree_SRC + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#4                ; chopper to P#4 
                // LABEL 3                                  ; first chopper pos. 
                // WAIT P#5                                 ; take P#5 ramps 
                // *Assume* P#4 is the SRC position... 
                duree_SRC = duree_SRC + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // WAIT 1                                   ; sync. for chopper
                //           *Assume* P#5 is the REF position... 
                duree_REF = duree_REF + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#6                ; chopper to P#6 
                // LABEL 5                                  ; next chopper pos. 
                // WAIT P#5                                 ; take P#5 ramps 
                // *Assume* P#6 is the REF position... 
                duree_REF = duree_REF + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                 ; chop readout cycle done
            }
            // LOOP P#7                                    ; calibration loop
            for(int cal_loop_1 = 1 .. nb_CS1_CS2) {
                // WAIT 1                                   ; sync. for chopper 
                duree_CAL = duree_CAL + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#8                ; chop to BB1 
                // LABEL 65                                 ; BB1 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // WAIT 1                                   ; sync. for chopper 
                duree_CAL = duree_CAL + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#9                ; chop to BB2 
                // LABEL 129                                ; BB2 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                    ; calibration done
            }
            // END_LOOP                                      ; grating scan up done
        }
        // LOOP P#2                                      ; grating loop down
        for(int down = 1 .. nb_grat_steps) {
            // WAIT 1 ; sync. for grating 
            duree_OVR = duree_OVR + 1;
            duree_num = duree_num + 1;
            // MOVE_GRATING_RELATIVE P#11                 ; decrement grating position 
            // LOOP P#3 ; chop readout cycle
            for(int chop_cycle_2 = 1 .. nb_cycles_grat_pos) {
                // WAIT 1                                  ; sync. for chopper 
                duree_SRC = duree_SRC + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#4               ; chopper to P#4 
                // LABEL 19                                ; first chopper pos. 
                // WAIT P#5                                ; take P#5 ramps 
                duree_SRC = duree_SRC + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // WAIT 1                                  ; sync. for chopper 
                duree_REF = duree_REF + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#6               ; chopper to P#6 
                // LABEL 21                                ; next chopper pos. 
                // WAIT P#5                                ; take P#5 ramps 
                duree_REF = duree_REF + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                   ; chop readout cycle done
            }
            // LOOP P#7                                    ; calibration loop
            for(int cal_loop_2 = 1 .. nb_CS1_CS2) {
                // WAIT 1                                   ; sync. for chopper 
                duree_CAL = duree_CAL + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#8                ; chop to BB1 
                // LABEL 81                                 ; BB1 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // WAIT 1                                   ; sync. for chopper 
                duree_CAL = duree_CAL + 1;
                duree_num = duree_num + 1;
                // MOVE_CHOPPER_ABSOLUTE P#9                ; chop to BB2 
                // LABEL 145                                ; BB2 
                // WAIT P#5                                 ; take P#5 ramps 
                duree_CAL = duree_CAL + nb_ramps_plateau;
                duree_num = duree_num + nb_ramps_plateau;
                // END_LOOP                                    ; calibration done
            }
            // END_LOOP                                      ; grating scan down done
        }
        // END_LOOP                                        ; main loop done
    }
    // WAIT 1                                             ; complete last plateau 
    duree_OVR = duree_OVR + 1;
    duree_num = duree_num + 1;
    // LABEL 0                                            ; reset LABEL to 0 
    // END_SEQUENCE 
    // duration, in ramps : 2 + P#1 * 2 * P#2 * {1 + (P#3 + P#7) * (1 + P#5)}
    int duree = 2 + nb_up_down * 2 * nb_grat_steps * (1 + (nb_cycles_grat_pos + nb_CS1_CS2) * 2 * (1 + nb_ramps_plateau));
    debug_print("Formula  duration DMC: " + duree + " [ramps]");
    debug_print("Computed duration DMC: " + duree_num + " [ramps]");
    // Time spent
    int duree_TCs = time() - time_start;
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	: SPU data rate check (spectroscopy)
//
// Author	: Roland Vavrek
// CUS script	: RV
// CVS file	: 
//
// Arguments	: No interactive parameters
//                         
//                 
//		   
// Description	: Four junks of test blocks are executed, each contains 2x120 sec measurement, 
//                        the first is configured with sub-slope fitting the second uses sub-means for 2
//                        chopper positions
//  
//                  
// Dependencies :  - SPEC_heater
//                          - Chop_mov_abs
//                          - SPEC_Gra_move_abs_raw
//                          - SPEC_SPU_reset
//                          - SPEC_CRE_setup
//                          - SPEC_SPU_setup
//
//
// Preconditions : - PACS is switched on
//                         - Setup spectroscopy  (e.g. SPEC_orbit_prologue_eqm_imt block has been executed)
//	      - Mechanics and CS controllers are SWON and ENABLED (e.g. SetupSpectroscopyEQMIMT)
//                         - CS2 temperature is raising but not yet stabilized
//
// Comments	: Blue heater2 is switched on
//
// Version	: 2.0
//               
// History	: 2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
// 		  1.5 09-Apr-2007 RV: Reduced duration (60 sec delay, only 1 loop on chop zero pos), capa_blu = 0, bias_d_blu = 0.198
//                1.4 05-Apr-2007 RV: Extended for 2 chopper positions (CS2 and chopper zero) and FM/ILT constants applied 
//                1.3 10-Apr-2006 HF: adapted to one blue heater only
//                1.2 27-Apr-2005 Creation by RV, Nominal SPU setup, SPU reset at the end
//                1.1 22-Apr-2005 Creation by RV, 4 junks organized in a loop
//                1.0 17-Apr-2005 Creation by RV         
//                                
//
obs PacsEng_Spec_spu_data_rate {
    /* Needed variables to call PacsEng_Spec_spu_data_rate                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_spu_data_rate                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_spu_data_rate()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_spu_data_rate();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS file      : CONF_phot_fltw.txt
// Missionphase  : FMILT_3 & Later
//
// Purpose       : CONFigure the PHOT filter wheel servo loop
//                  
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      :
//
// Version       : 1.0
// History       : 0.1  4-jul-2006 DAC
//                    1.0 11-Jun-2007 PR New scheme due to new format of configuration command
//                                               (DMC UM v.4.3)
//               :
procedure CONF_phot_fltw {
}{
    string calUname = "CONFFWPHOT";
    // FWPHOT CALIBRATION TABLE
    string calUrow = "FMILT";
    // INSTRUMENT VERSION
    int rate = ilookup(calUname,calUrow,"Rate");
    int current = ilookup(calUname,calUrow,"Drive_current");
    int threshold_A = ilookup(calUname,calUrow,"Threshold_A");
    int threshold_B = ilookup(calUname,calUrow,"Threshold_B");
    int status_A = ilookup(calUname,calUrow,"Status_A");
    int status_B = ilookup(calUname,calUrow,"Status_B");
    {int}[] parlist = [{rate},{current},{threshold_A},{threshold_B},{status_A},{status_B}];
    int[] aux = [rate,current,threshold_A,threshold_B,status_A,status_B];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_FWPHOT_CONF_PAR(parlist,check_sum);
}

// File          : PHOT_switchoff_groups.cus
// Missionphase  : PACS FM Test
//
// Purpose       : switch-off groups
//
// Author        : T. Mueller
//
// Arguments     : none
//
//
// Description   : Once we are satisfied with the tests, it is time to switch
//                 off the instrument by setting all biases to zero and switch
//                 off of the groups
//
// Comments      :  Coded based on PhFPU UM, draft 5, chapter 4.2.6
//
// Version       : 1.7
// History       : 1.0 / 02-Jul-2004 initial version by TM
//                 1.1    7-mar-2006 SEND_COMMAND_TO_BOLC renamed
//                 1.2   11-aug-2006 TM: updated for PhFPU UM, draft 5, chapter 4.2.6
//                 1.3   08-nov-2006 TM: groups off in the end
//                 1.4   08-nov-2006 TM: autonomy function disabled
//                 1.4.1 14-nov-2006 Autonomy function temporarily removed
//                 1.5 17-nov-2006 AF back again
//                 1.6 05-mar-2007 time delay of 2min between protections off and
//                                            group switch off
//                 1.7 09-apr-2007 new AFs
procedure PHOT_switchoff_groups {
}{
    //***********************************
    // disable AFs
    //***********************************
    // disable AF 12 (to check for the protection biases)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_BIAS","DISABLE");
    // disable AF 15 (to check for the VSS currents of groups and BUs)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","DISABLE");
    // autonomy function 17 "generate_event_pwr" checks the
    // HK entries: PC_PWR_ANA_P_#, PC_PWR_ANA_N_# and PC_PWR_DIG_#,
    // with # = [1,2,3,4,5,6,7]
    Pacs_DPU_SET_FUNCT("EVENT_BOL_V_PWR","DISABLE");
    delay(2);
    //
    //
    //***********************************
    //*
    //* Switch-off procedure for BOLC
    //* Part 1: switching off the detectors
    //*
    //* creation date : 15/09/05
    //*
    //*
    //***********************************
    // Switch off of all biases in the correct order
    //
    // Set all groups bol bias 02 (VL) to 0.00000000 Volt (0)
    //# P 00 02 0000
    int operand = 0x20000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 05 (VCH) to 0.00000000 Volt (0)
    //# P 00 05 0000
    operand = 0x50000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 01 (VH) to 0.00000000 Volt (0)
    //# P 00 01 0000
    operand = 0x10000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 03 (VRL) to 0.00000000 Volt (0)
    //# P 00 03 0000
    operand = 0x30000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 04 (VINJ) to 0.00000000 Volt (0)
    //# P 00 04 0000
    operand = 0x40000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 06 (VDL) to 0.00000000 Volt (0)
    //# P 00 06 0000
    operand = 0x60000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 08 (VGL) to 0.00000000 Volt (0)
    //# P 00 08 0000
    operand = 0x80000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 07 (VSS) to 0.00000000 Volt (0)
    //# P 00 07 0000
    operand = 0x70000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 16 (VDD) to 0.00000000 Volt (0)
    //# P 00 10 0000
    operand = 0x100000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 15 (VGG) to 0.00000000 Volt (0)
    //# P 00 0F 0000
    operand = 0xf0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 09 (CKRLH) to 0.00000000 Volt (0)
    //# P 00 09 0000
    operand = 0x90000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 10 (CKRLL) to 0.00000000 Volt (0)
    //# P 00 0A 0000
    operand = 0xa0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 11 (VDECX-H) to 0.00000000 Volt (0)
    //# P 00 0B 0000
    operand = 0xb0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 12 (VDECX-L) to 0.00000000 Volt (0)
    //# P 00 0C 0000
    operand = 0xc0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 13 (VSMS-H) to 0.00000000 Volt (0)
    //# P 00 0D 0000
    operand = 0xd0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 14 (VSMS-L) to 0.00000000 Volt (0)
    //# P 00 0E 0000
    operand = 0xe0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 18 (VDL-BU) to 0.00000000 Volt (0)
    //# P 00 12 0000
    operand = 0x120000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 20 (VH_BLIND) to 0.00000000 Volt (0)
    //# P 00 14 0000
    operand = 0x140000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 19 (VGL-BU) to 0.00000000 Volt (0)
    //# P 00 13 0000
    operand = 0x130000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 17 (VSS-BU) to 0.00000000 Volt (0)
    //# P 00 11 0000
    operand = 0x110000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(5);
    //
    //
    // Wait 100 ms
    //# S 01 000064
    //
    // Switch-off of the protection biases
    //
    // Set all groups bol bias 21 (VDD-PROT-CL) OFF (0)
    //# P 00 15 0000
    operand = 0x150000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 22 (VDD-PROT-BU) OFF (0)
    //# P 00 16 0000
    operand = 0x160000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 23 (GND-BU) OFF (0)
    //# P 00 17 0000
    operand = 0x170000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(5);
    //
    //***********************************
    //*
    //* Switch-off procedure for BOLC
    //* Part 2: switching off BOLC groups
    //*
    //* creation date : 15/09/05
    //*
    //*
    //***********************************
    // Switch off all groups
    // Set group on/off 00 hexa
    //# P 0A 00 00 00
    operand = 0xa000000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

// $Id: PacsEng_PHOT_orbit_prologue10.txt,v 1.8 2008/11/12 11:40:20 vanessad Exp $
// Purpose        : Bring PACS from switched off condition to standby
//                  for PHOT observations
//
// CUS author     : Composed from various ILT modules
//
// Input arguments: see after module identification
//
// Return values
// N/A
//
// Comments      : SCR PACS-1866
//
// History: 
// 0.1  25-jun-2007  Created from ILT modules
// 0.2   9-aug-2007  Conformed to JonBr's mail (07/26/07)
// 1.0  21-aug-2007  Renamed from PACS_PHOT_orbit_prologue
//                                Use new "no_pointing" pointing request and
//                                StateMachine logic
// 1.1 20-may-2008  KO, Debugged for the pointing timing logic
// 1.2 24-jun-2008 KO, calUfile, temp_CS1 and temp_CS2 put in the argument
// 1.3 25-jun-2008 KO, CSs stabilisation time tSET put in the argument and the default calUfile changed to ILT
// 1.4 11-nov-2008 VD&KO&TM tSet chnaged to 2100s to allow for stabilisation
// 1.5 12-nov-2008 KO gotoDirect option added
// 1.6 10-apr-2009 KO VRL and 40Hz option added during the stabilization waiting time
// 1.7 04-may-2009 KO,NB choise corrected to choice!!!
// 1.8 11-jun-2009 KO Default choice is set to justWait
//
obs PacsEng_PHOT_orbit_prologue10 {
    string calUfile = "BOLObias_ILT_standard_low"; // Bias table
    double set_CS1 = 48.0; // CS1 settings (ohms)
    double set_CS2 = 58.0; // CS2 settings (ohms)
    int waitTime = 2100; // CSs stabilisation time in seconds > 200
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
    string choice = "justWait" in ["VRL","40Hz","justWait"]; // What to do during stabilization
    string waitBias = "BOLObias_standard_high"; // Bias used during CSs stabilization
}{
    // Settling time for CS
    string fltPOS = "POS A";
    bool execute = true;
    // Initial hold
    int tih = imax(1,duration(WriteOBSID($OBSID)));
    // Final hold
    int tfh = imax(1,duration(WriteEndID()));
    // Duration of "stable" pointing
    int tp = duration(PHOT_setup12345(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect));
    // Wait for CS to stabilize
    if(choice == "VRL") {
        // Vrl measurement during the stabilization
        tp = tp + duration(Phot_lowFreq_Vrl_filler(waitTime - 200,waitBias,calUfile,gotoDirect));
    } else {
        if(choice == "40Hz") {
            // sky measurement at 40Hz during the stabilization
            tp = tp + duration(Phot_SPU40Hz_filler(waitTime - 200,waitBias,calUfile,gotoDirect));
        } else {
            tp = tp + waitTime;
        }
    }
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //     Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //     Call the PHOT setup script
            PHOT_setup12345(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect);
            //     Wait for CS to stabilize
            if(choice == "VRL") {
                // Vrl measurement during the stabilization
                Phot_lowFreq_Vrl_filler(waitTime - 200,waitBias,calUfile,gotoDirect);
            } else {
                if(choice == "40Hz") {
                    // sky measurement at 40Hz during the stabilization
                    Phot_SPU40Hz_filler(waitTime - 200,waitBias,calUfile,gotoDirect);
                } else {
                    delay(waitTime);
                }
            }
        }
        if(state[0] == 5) {
            //     Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// Mission phase : Commissioning and Performance Verification phases
//
// Purpose : New filler during CSs stabilization: sky at 40Hz with a few pixels
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_SPU40Hz_filler
//
// Argument :
//   measureTime : response measure time in seconds [3600s=1h]
//   biasFile    : Bias table file containing the initial values ["BOLObias_ILT_standard_high"]
//
// Check before executing :
//   + Cooler is recycled
//   + PHOT_setpup has already set the bolometer biases
//
// Description : 
//
// Dependencies : None
//
// Comments :
//
// Version :
//   2009 Apr 29 : Now use a detector selection table for the lossless compression mode and then come back
//   2009 Apr 30 : Default bias tables updated. The high gain is used because of the simplicity of
//                 the implementation with Phot_lowFreq_Vrl_filler
//
procedure Phot_SPU40Hz_filler {
    int measureTime = 2100; // noise measure time in seconds
    string biasFile = "BOLObias_standard_high"; // Bias table file containing the initial values
    string endBias = "BOLObias_ILT_standard_low"; // Bias table file containing the final values
    bool gotoDirect = true in [true,false]; // End setting
}{
    //
    //***********************************************
    //	Bias setting of the detectors for high gain
    //***********************************************
    //
    PHOT_change_biases(biasFile,"DIRECT","HIGH");
    //
    //**********************************************
    // Set the PACS chopper at the position 664
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //**************************************************
    // Stop SPU and load a new Detector selection table
    //**************************************************
    //
    PHOT_spu_setup(4,4,0,0,false);
    string detsel_table = "PACSDetSel_20090429";
    PACS_Det_Sel(detsel_table);
    //
    //****************************************************************
    // Special SPU setup to downlink 40Hz science data of some pixels
    //****************************************************************
    PHOT_spu_setup(4,4,0,0,true);
    //
    //********************
    // Let all stabilized
    //********************
    delay(120);
    //
    //**************************************
    // Noise measurement during measureTime
    //**************************************
    TMMarker601();
    delay(measureTime);
    TMMarker600();
    //
    //*************************************
    //	End bias setting of the detectors
    //*************************************
    //
    string setting = "DIRECT";
    if(gotoDirect) {
        setting = "DIRECT";
    } else {
        setting = "DDCS";
    }
    PHOT_change_biases(endBias,setting,"LOW");
    //****************************
    // Stop science data downlink
    //****************************
    PHOT_spu_setup(0,0,3,3,false);
    //
    //****************************************
    // Stop SPU and load default DetSel Table
    //****************************************
    PACS_Det_Sel("PACSDetSel_20081203");
    //
    // sync the bus
    sync();
}

// $Id: PacsEng_PHOT_orbit_prologue11.txt,v 1.8 2008/11/12 11:40:20 vanessad Exp $
// Purpose        : Bring PACS from switched off condition to standby
//                  for PHOT observations
//
// CUS author     : Composed from various ILT modules
//
// Input arguments: see after module identification
//
// Return values
// N/A
//
// Comments      : SCR PACS-1866
//
// History: 
// 0.1  25-jun-2007  Created from ILT modules
// 0.2   9-aug-2007  Conformed to JonBr's mail (07/26/07)
// 1.0  21-aug-2007  Renamed from PACS_PHOT_orbit_prologue
//                                Use new "no_pointing" pointing request and
//                                StateMachine logic
// 1.1 20-may-2008  KO, Debugged for the pointing timing logic
// 1.2 24-jun-2008 KO, calUfile, temp_CS1 and temp_CS2 put in the argument
// 1.3 25-jun-2008 KO, CSs stabilisation time tSET put in the argument and the default calUfile changed to ILT
// 1.4 11-nov-2008 VD&KO&TM tSet chnaged to 2100s to allow for stabilisation
// 1.5 12-nov-2008 KO gotoDirect option added
// 1.6 10-apr-2009 KO VRL and 40Hz option added during the stabilization waiting time
// 1.7 04-may-2009 KO,NB choise corrected to choice!!!
// 1.8 11-jun-2009 KO Default choice is set to justWait
//
obs PacsEng_PHOT_orbit_prologue11 {
    string calUfile = "BOLObias_ILT_standard_low"; // Bias table
    double set_CS1 = 48.0; // CS1 settings (ohms)
    double set_CS2 = 58.0; // CS2 settings (ohms)
    int waitTime = 2100; // CSs stabilisation time in seconds > 200
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
    string choice = "justWait" in ["VRL","40Hz","justWait"]; // What to do during stabilization
    string waitBias = "BOLObias_standard_high"; // Bias used during CSs stabilization
}{
    // Settling time for CS
    string fltPOS = "POS A";
    bool execute = true;
    // Initial hold
    int tih = imax(1,duration(WriteOBSID($OBSID)));
    // Final hold
    int tfh = imax(1,duration(WriteEndID()));
    // Duration of "stable" pointing
    int tp = duration(PHOT_setup123456(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect));
    // Wait for CS to stabilize
    if(choice == "VRL") {
        // Vrl measurement during the stabilization
        tp = tp + duration(Phot_lowFreq_Vrl_filler(waitTime - 200,waitBias,calUfile,gotoDirect));
    } else {
        if(choice == "40Hz") {
            // sky measurement at 40Hz during the stabilization
            tp = tp + duration(Phot_SPU40Hz_filler(waitTime - 200,waitBias,calUfile,gotoDirect));
        } else {
            tp = tp + waitTime;
        }
    }
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //     Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //     Call the PHOT setup script
            PHOT_setup123456(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect);
            //     Wait for CS to stabilize
            if(choice == "VRL") {
                // Vrl measurement during the stabilization
                Phot_lowFreq_Vrl_filler(waitTime - 200,waitBias,calUfile,gotoDirect);
            } else {
                if(choice == "40Hz") {
                    // sky measurement at 40Hz during the stabilization
                    Phot_SPU40Hz_filler(waitTime - 200,waitBias,calUfile,gotoDirect);
                } else {
                    delay(waitTime);
                }
            }
        }
        if(state[0] == 5) {
            //     Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req.1.1.1 for the Commissioning Phase
//           Check the bias/signal relationship using telescope background
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowGainBias2_direct
//
// Argument :
//   int measure_time = 300; // measure time in seconds
//   string startBiasTable = "BOLObias_ILT_low_OD46"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_low_OD46"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   + Set the blue filter 100um
//   + Set the biases group by group
//   + Set the chopper on the optical center
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   + Set the blue filter 70um
//   +   Loop over 12 sets of 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group
//   + At the end, the biases are set following a given bias table
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_CommPh_lowGainBias2(1, "LOW")
//            New version
//
// Version : Wed Jun 24 12:56:14 EDT 2009
//
procedure Phot_lowGainBias2_direct {
    int measure_time = 300; // measure time in seconds
    string startBiasTable = "BOLObias_ILT_low_OD46"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_low_OD46"; // Bias table containing the final values
}{
    //
    //*******************************
    // Select Filter A (100 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //*************************************************
    // Set the biases and start SPU, then set the gain
    //*************************************************
    //
    PHOT_set_biases(startBiasTable,"DIRECT","LOW");
    //
    //**********************************************
    // Set the PACS chopper at the position 664
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(664);
    //
    //
    //**********************************************************************
    //                       Measurement
    // Fluxes 1.00pW on the green and 3.50pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.2315755542156994 Volts
    Pacs_BOLC_SET_VH_G1(1.2315755542156994);
    // Set group 1 bol bias 02 (VL) to -0.0184244457843006 Volts
    Pacs_BOLC_SET_VL_G1(-0.0184244457843006);
    // Set group 1 bol bias 03 (VRL) to 0.3927827053939294 Volts
    Pacs_BOLC_SET_VRL_G1(0.3927827053939294);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.151335509201095 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.151335509201095);
    // Set group 2 bol bias 01 (VH) to 1.2208467789469029 Volts
    Pacs_BOLC_SET_VH_G2(1.2208467789469029);
    // Set group 2 bol bias 02 (VL) to -0.02915322105309711 Volts
    Pacs_BOLC_SET_VL_G2(-0.02915322105309711);
    // Set group 2 bol bias 03 (VRL) to 0.3896021555156297 Volts
    Pacs_BOLC_SET_VRL_G2(0.3896021555156297);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1475924333125 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1475924333125);
    // Set group 3 bol bias 01 (VH) to 1.222727439090301 Volts
    Pacs_BOLC_SET_VH_G3(1.222727439090301);
    // Set group 3 bol bias 02 (VL) to -0.02727256090969917 Volts
    Pacs_BOLC_SET_VL_G3(-0.02727256090969917);
    // Set group 3 bol bias 03 (VRL) to 0.3893875478842172 Volts
    Pacs_BOLC_SET_VRL_G3(0.3893875478842172);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1436592824098937 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1436592824098937);
    // Set group 4 bol bias 01 (VH) to 1.2342106887897224 Volts
    Pacs_BOLC_SET_VH_G4(1.2342106887897224);
    // Set group 4 bol bias 02 (VL) to -0.015789311210277622 Volts
    Pacs_BOLC_SET_VL_G4(-0.015789311210277622);
    // Set group 4 bol bias 03 (VRL) to 0.3854250451943223 Volts
    Pacs_BOLC_SET_VRL_G4(0.3854250451943223);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.141419992160213 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.141419992160213);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3747664602557065 Volts
    Pacs_BOLC_SET_VRL_G5(0.3747664602557065);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1227166495195537 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1227166495195537);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3658432804212911 Volts
    Pacs_BOLC_SET_VRL_G6(0.3658432804212911);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.109568791597369 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.109568791597369);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4492299432346567 Volts
    Pacs_BOLC_SET_VH_G1(1.4492299432346567);
    // Set group 1 bol bias 02 (VL) to -0.15077005676534339 Volts
    Pacs_BOLC_SET_VL_G1(-0.15077005676534339);
    // Set group 1 bol bias 03 (VRL) to 0.3930501646743051 Volts
    Pacs_BOLC_SET_VRL_G1(0.3930501646743051);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.15165276672515 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.15165276672515);
    // Set group 2 bol bias 01 (VH) to 1.4370943699429737 Volts
    Pacs_BOLC_SET_VH_G2(1.4370943699429737);
    // Set group 2 bol bias 02 (VL) to -0.16290563005702652 Volts
    Pacs_BOLC_SET_VL_G2(-0.16290563005702652);
    // Set group 2 bol bias 03 (VRL) to 0.3892493082303189 Volts
    Pacs_BOLC_SET_VRL_G2(0.3892493082303189);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.147182817068602 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.147182817068602);
    // Set group 3 bol bias 01 (VH) to 1.4383561258596647 Volts
    Pacs_BOLC_SET_VH_G3(1.4383561258596647);
    // Set group 3 bol bias 02 (VL) to -0.16164387414033532 Volts
    Pacs_BOLC_SET_VL_G3(-0.16164387414033532);
    // Set group 3 bol bias 03 (VRL) to 0.38959607176340416 Volts
    Pacs_BOLC_SET_VRL_G3(0.38959607176340416);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1438892691579414 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1438892691579414);
    // Set group 4 bol bias 01 (VH) to 1.4539963471231871 Volts
    Pacs_BOLC_SET_VH_G4(1.4539963471231871);
    // Set group 4 bol bias 02 (VL) to -0.14600365287681283 Volts
    Pacs_BOLC_SET_VL_G4(-0.14600365287681283);
    // Set group 4 bol bias 03 (VRL) to 0.3869127816455791 Volts
    Pacs_BOLC_SET_VRL_G4(0.3869127816455791);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1431187542483814 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1431187542483814);
    // Set group 5 bol bias 01 (VH) to 1.17383991574692 Volts
    Pacs_BOLC_SET_VH_G5(1.17383991574692);
    // Set group 5 bol bias 02 (VL) to -0.02616008425308 Volts
    Pacs_BOLC_SET_VL_G5(-0.02616008425308);
    // Set group 5 bol bias 03 (VRL) to 0.43476802245017643 Volts
    Pacs_BOLC_SET_VRL_G5(0.43476802245017643);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1945801325409864 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1945801325409864);
    // Set group 6 bol bias 01 (VH) to 1.1864799253248077 Volts
    Pacs_BOLC_SET_VH_G6(1.1864799253248077);
    // Set group 6 bol bias 02 (VL) to -0.013520074675192215 Volts
    Pacs_BOLC_SET_VL_G6(-0.013520074675192215);
    // Set group 6 bol bias 03 (VRL) to 0.43690432497388915 Volts
    Pacs_BOLC_SET_VRL_G6(0.43690432497388915);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1952488403472232 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1952488403472232);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.577315223489331 Volts
    Pacs_BOLC_SET_VH_G1(1.577315223489331);
    // Set group 1 bol bias 02 (VL) to -0.22268477651066898 Volts
    Pacs_BOLC_SET_VL_G1(-0.22268477651066898);
    // Set group 1 bol bias 03 (VRL) to 0.39323453655078966 Volts
    Pacs_BOLC_SET_VRL_G1(0.39323453655078966);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1518714697731176 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1518714697731176);
    // Set group 2 bol bias 01 (VH) to 1.5640983579555297 Volts
    Pacs_BOLC_SET_VH_G2(1.5640983579555297);
    // Set group 2 bol bias 02 (VL) to -0.2359016420444704 Volts
    Pacs_BOLC_SET_VL_G2(-0.2359016420444704);
    // Set group 2 bol bias 03 (VRL) to 0.38925931939157776 Volts
    Pacs_BOLC_SET_VRL_G2(0.38925931939157776);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14719443880641 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14719443880641);
    // Set group 3 bol bias 01 (VH) to 1.564983863867001 Volts
    Pacs_BOLC_SET_VH_G3(1.564983863867001);
    // Set group 3 bol bias 02 (VL) to -0.235016136132999 Volts
    Pacs_BOLC_SET_VL_G3(-0.235016136132999);
    // Set group 3 bol bias 03 (VRL) to 0.39008203329503377 Volts
    Pacs_BOLC_SET_VRL_G3(0.39008203329503377);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144425253873819 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144425253873819);
    // Set group 4 bol bias 01 (VH) to 1.5826751441318931 Volts
    Pacs_BOLC_SET_VH_G4(1.5826751441318931);
    // Set group 4 bol bias 02 (VL) to -0.2173248558681068 Volts
    Pacs_BOLC_SET_VL_G4(-0.2173248558681068);
    // Set group 4 bol bias 03 (VRL) to 0.3877733253699098 Volts
    Pacs_BOLC_SET_VRL_G4(0.3877733253699098);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1441014528383815 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1441014528383815);
    // Set group 5 bol bias 01 (VH) to 1.295861500105004 Volts
    Pacs_BOLC_SET_VH_G5(1.295861500105004);
    // Set group 5 bol bias 02 (VL) to -0.10413849989499598 Volts
    Pacs_BOLC_SET_VL_G5(-0.10413849989499598);
    // Set group 5 bol bias 03 (VRL) to 0.433595357898982 Volts
    Pacs_BOLC_SET_VRL_G5(0.433595357898982);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1931781023528045 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1931781023528045);
    // Set group 6 bol bias 01 (VH) to 1.3087380679890719 Volts
    Pacs_BOLC_SET_VH_G6(1.3087380679890719);
    // Set group 6 bol bias 02 (VL) to -0.09126193201092794 Volts
    Pacs_BOLC_SET_VL_G6(-0.09126193201092794);
    // Set group 6 bol bias 03 (VRL) to 0.4351222025681505 Volts
    Pacs_BOLC_SET_VRL_G6(0.4351222025681505);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1931233522674587 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1931233522674587);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7099212599700127 Volts
    Pacs_BOLC_SET_VH_G1(1.7099212599700127);
    // Set group 1 bol bias 02 (VL) to -0.29007874002998724 Volts
    Pacs_BOLC_SET_VL_G1(-0.29007874002998724);
    // Set group 1 bol bias 03 (VRL) to 0.3929551392135957 Volts
    Pacs_BOLC_SET_VRL_G1(0.3929551392135957);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1515400478893216 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1515400478893216);
    // Set group 2 bol bias 01 (VH) to 1.6948143095298716 Volts
    Pacs_BOLC_SET_VH_G2(1.6948143095298716);
    // Set group 2 bol bias 02 (VL) to -0.30518569047012856 Volts
    Pacs_BOLC_SET_VL_G2(-0.30518569047012856);
    // Set group 2 bol bias 03 (VRL) to 0.3887231498027256 Volts
    Pacs_BOLC_SET_VRL_G2(0.3887231498027256);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.146572019576776 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.146572019576776);
    // Set group 3 bol bias 01 (VH) to 1.706494631229345 Volts
    Pacs_BOLC_SET_VH_G3(1.706494631229345);
    // Set group 3 bol bias 02 (VL) to -0.293505368770655 Volts
    Pacs_BOLC_SET_VL_G3(-0.293505368770655);
    // Set group 3 bol bias 03 (VRL) to 0.40145895003126647 Volts
    Pacs_BOLC_SET_VRL_G3(0.40145895003126647);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1569777323099513 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1569777323099513);
    // Set group 4 bol bias 01 (VH) to 1.716368036262283 Volts
    Pacs_BOLC_SET_VH_G4(1.716368036262283);
    // Set group 4 bol bias 02 (VL) to -0.28363196373771693 Volts
    Pacs_BOLC_SET_VL_G4(-0.28363196373771693);
    // Set group 4 bol bias 03 (VRL) to 0.38901275254233414 Volts
    Pacs_BOLC_SET_VRL_G4(0.38901275254233414);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.145516936703236 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.145516936703236);
    // Set group 5 bol bias 01 (VH) to 1.411267790421653 Volts
    Pacs_BOLC_SET_VH_G5(1.411267790421653);
    // Set group 5 bol bias 02 (VL) to -0.18873220957834702 Volts
    Pacs_BOLC_SET_VL_G5(-0.18873220957834702);
    // Set group 5 bol bias 03 (VRL) to 0.42107692260771856 Volts
    Pacs_BOLC_SET_VRL_G5(0.42107692260771856);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1781936277623863 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1781936277623863);
    // Set group 6 bol bias 01 (VH) to 1.436583641174852 Volts
    Pacs_BOLC_SET_VH_G6(1.436583641174852);
    // Set group 6 bol bias 02 (VL) to -0.16341635882514807 Volts
    Pacs_BOLC_SET_VL_G6(-0.16341635882514807);
    // Set group 6 bol bias 03 (VRL) to 0.433116085800085 Volts
    Pacs_BOLC_SET_VRL_G6(0.433116085800085);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1907305406171096 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1907305406171096);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8502405264446637 Volts
    Pacs_BOLC_SET_VH_G1(1.8502405264446637);
    // Set group 1 bol bias 02 (VL) to -0.3497594735553363 Volts
    Pacs_BOLC_SET_VL_G1(-0.3497594735553363);
    // Set group 1 bol bias 03 (VRL) to 0.3928176022649842 Volts
    Pacs_BOLC_SET_VRL_G1(0.3928176022649842);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1513769032311103 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1513769032311103);
    // Set group 2 bol bias 01 (VH) to 1.8315795337686485 Volts
    Pacs_BOLC_SET_VH_G2(1.8315795337686485);
    // Set group 2 bol bias 02 (VL) to -0.3684204662313517 Volts
    Pacs_BOLC_SET_VL_G2(-0.3684204662313517);
    // Set group 2 bol bias 03 (VRL) to 0.3877289063530741 Volts
    Pacs_BOLC_SET_VRL_G2(0.3877289063530741);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1454178843000036 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1454178843000036);
    // Set group 3 bol bias 01 (VH) to 1.8437289087077704 Volts
    Pacs_BOLC_SET_VH_G3(1.8437289087077704);
    // Set group 3 bol bias 02 (VL) to -0.35627109129222984 Volts
    Pacs_BOLC_SET_VL_G3(-0.35627109129222984);
    // Set group 3 bol bias 03 (VRL) to 0.40199180357571035 Volts
    Pacs_BOLC_SET_VRL_G3(0.40199180357571035);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1575673024232147 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1575673024232147);
    // Set group 4 bol bias 01 (VH) to 1.8582906106359456 Volts
    Pacs_BOLC_SET_VH_G4(1.8582906106359456);
    // Set group 4 bol bias 02 (VL) to -0.3417093893640547 Volts
    Pacs_BOLC_SET_VL_G4(-0.3417093893640547);
    // Set group 4 bol bias 03 (VRL) to 0.3910798140892293 Volts
    Pacs_BOLC_SET_VRL_G4(0.3910798140892293);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.147877930369135 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.147877930369135);
    // Set group 5 bol bias 01 (VH) to 1.474653839775916 Volts
    Pacs_BOLC_SET_VH_G5(1.474653839775916);
    // Set group 5 bol bias 02 (VL) to -0.22534616022408405 Volts
    Pacs_BOLC_SET_VL_G5(-0.22534616022408405);
    // Set group 5 bol bias 03 (VRL) to 0.4201505271824174 Volts
    Pacs_BOLC_SET_VRL_G5(0.4201505271824174);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1770852992715035 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1770852992715035);
    // Set group 6 bol bias 01 (VH) to 1.500693203446836 Volts
    Pacs_BOLC_SET_VH_G6(1.500693203446836);
    // Set group 6 bol bias 02 (VL) to -0.19930679655316377 Volts
    Pacs_BOLC_SET_VL_G6(-0.19930679655316377);
    // Set group 6 bol bias 03 (VRL) to 0.43196086785086785 Volts
    Pacs_BOLC_SET_VRL_G6(0.43196086785086785);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.189336628282171 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.189336628282171);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.012235568840326 Volts
    Pacs_BOLC_SET_VH_G1(2.012235568840326);
    // Set group 1 bol bias 02 (VL) to -0.387764431159674 Volts
    Pacs_BOLC_SET_VL_G1(-0.387764431159674);
    // Set group 1 bol bias 03 (VRL) to 0.40342466321839016 Volts
    Pacs_BOLC_SET_VRL_G1(0.40342466321839016);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1639536029727306 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1639536029727306);
    // Set group 2 bol bias 01 (VH) to 1.9778358306108168 Volts
    Pacs_BOLC_SET_VH_G2(1.9778358306108168);
    // Set group 2 bol bias 02 (VL) to -0.4221641693891831 Volts
    Pacs_BOLC_SET_VL_G2(-0.4221641693891831);
    // Set group 2 bol bias 03 (VRL) to 0.3865035130157216 Volts
    Pacs_BOLC_SET_VRL_G2(0.3865035130157216);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.14399550619509 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.14399550619509);
    // Set group 3 bol bias 01 (VH) to 2.0015054267216925 Volts
    Pacs_BOLC_SET_VH_G3(2.0015054267216925);
    // Set group 3 bol bias 02 (VL) to -0.39849457327830745 Volts
    Pacs_BOLC_SET_VL_G3(-0.39849457327830745);
    // Set group 3 bol bias 03 (VRL) to 0.41354429373027596 Volts
    Pacs_BOLC_SET_VRL_G3(0.41354429373027596);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170344451024266 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170344451024266);
    // Set group 4 bol bias 01 (VH) to 2.0084456536967403 Volts
    Pacs_BOLC_SET_VH_G4(2.0084456536967403);
    // Set group 4 bol bias 02 (VL) to -0.3915543463032596 Volts
    Pacs_BOLC_SET_VL_G4(-0.3915543463032596);
    // Set group 4 bol bias 03 (VRL) to 0.3917184948141249 Volts
    Pacs_BOLC_SET_VRL_G4(0.3917184948141249);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.148607509296212 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.148607509296212);
    // Set group 5 bol bias 01 (VH) to 1.538531208741738 Volts
    Pacs_BOLC_SET_VH_G5(1.538531208741738);
    // Set group 5 bol bias 02 (VL) to -0.26146879125826195 Volts
    Pacs_BOLC_SET_VL_G5(-0.26146879125826195);
    // Set group 5 bol bias 03 (VRL) to 0.41899816344351815 Volts
    Pacs_BOLC_SET_VRL_G5(0.41899816344351815);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.175706734147529 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.175706734147529);
    // Set group 6 bol bias 01 (VH) to 1.565420545490553 Volts
    Pacs_BOLC_SET_VH_G6(1.565420545490553);
    // Set group 6 bol bias 02 (VL) to -0.23457945450944698 Volts
    Pacs_BOLC_SET_VL_G6(-0.23457945450944698);
    // Set group 6 bol bias 03 (VRL) to 0.4306941180515982 Volts
    Pacs_BOLC_SET_VRL_G6(0.4306941180515982);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1878079247641415 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1878079247641415);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.10380226404523 Volts
    Pacs_BOLC_SET_VH_G1(2.10380226404523);
    // Set group 1 bol bias 02 (VL) to -0.39619773595476976 Volts
    Pacs_BOLC_SET_VL_G1(-0.39619773595476976);
    // Set group 1 bol bias 03 (VRL) to 0.41421051415236704 Volts
    Pacs_BOLC_SET_VRL_G1(0.41421051415236704);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.176720939091924 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.176720939091924);
    // Set group 2 bol bias 01 (VH) to 2.055299936851624 Volts
    Pacs_BOLC_SET_VH_G2(2.055299936851624);
    // Set group 2 bol bias 02 (VL) to -0.44470006314837585 Volts
    Pacs_BOLC_SET_VL_G2(-0.44470006314837585);
    // Set group 2 bol bias 03 (VRL) to 0.3857850922575742 Volts
    Pacs_BOLC_SET_VRL_G2(0.3857850922575742);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1431616387491377 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1431616387491377);
    // Set group 3 bol bias 01 (VH) to 2.079742961143483 Volts
    Pacs_BOLC_SET_VH_G3(2.079742961143483);
    // Set group 3 bol bias 02 (VL) to -0.42025703885651683 Volts
    Pacs_BOLC_SET_VL_G3(-0.42025703885651683);
    // Set group 3 bol bias 03 (VRL) to 0.41363993199234167 Volts
    Pacs_BOLC_SET_VRL_G3(0.41363993199234167);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.170450187998145 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.170450187998145);
    // Set group 4 bol bias 01 (VH) to 2.088277611801227 Volts
    Pacs_BOLC_SET_VH_G4(2.088277611801227);
    // Set group 4 bol bias 02 (VL) to -0.41172238819877294 Volts
    Pacs_BOLC_SET_VL_G4(-0.41172238819877294);
    // Set group 4 bol bias 03 (VRL) to 0.39189987119500125 Volts
    Pacs_BOLC_SET_VRL_G4(0.39189987119500125);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.148814706298036 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.148814706298036);
    // Set group 5 bol bias 01 (VH) to 1.6043700903162197 Volts
    Pacs_BOLC_SET_VH_G5(1.6043700903162197);
    // Set group 5 bol bias 02 (VL) to -0.29562990968378033 Volts
    Pacs_BOLC_SET_VL_G5(-0.29562990968378033);
    // Set group 5 bol bias 03 (VRL) to 0.4179972717442382 Volts
    Pacs_BOLC_SET_VRL_G5(0.4179972717442382);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.174509472234708 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.174509472234708);
    // Set group 6 bol bias 01 (VH) to 1.631792337309164 Volts
    Pacs_BOLC_SET_VH_G6(1.631792337309164);
    // Set group 6 bol bias 02 (VL) to -0.26820766269083596 Volts
    Pacs_BOLC_SET_VL_G6(-0.26820766269083596);
    // Set group 6 bol bias 03 (VRL) to 0.4294097753204019 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294097753204019);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186257935692563 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186257935692563);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.1883441857120878 Volts
    Pacs_BOLC_SET_VH_G1(2.1883441857120878);
    // Set group 1 bol bias 02 (VL) to -0.4116558142879125 Volts
    Pacs_BOLC_SET_VL_G1(-0.4116558142879125);
    // Set group 1 bol bias 03 (VRL) to 0.413631242936739 Volts
    Pacs_BOLC_SET_VRL_G1(0.413631242936739);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.176035205671301 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.176035205671301);
    // Set group 2 bol bias 01 (VH) to 2.1371144619855875 Volts
    Pacs_BOLC_SET_VH_G2(2.1371144619855875);
    // Set group 2 bol bias 02 (VL) to -0.4628855380144125 Volts
    Pacs_BOLC_SET_VL_G2(-0.4628855380144125);
    // Set group 2 bol bias 03 (VRL) to 0.38557079773438524 Volts
    Pacs_BOLC_SET_VRL_G2(0.38557079773438524);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1429129140284013 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1429129140284013);
    // Set group 3 bol bias 01 (VH) to 2.1614440683243608 Volts
    Pacs_BOLC_SET_VH_G3(2.1614440683243608);
    // Set group 3 bol bias 02 (VL) to -0.4385559316756391 Volts
    Pacs_BOLC_SET_VL_G3(-0.4385559316756391);
    // Set group 3 bol bias 03 (VRL) to 0.4133934844609841 Volts
    Pacs_BOLC_SET_VRL_G3(0.4133934844609841);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.17017771605717 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.17017771605717);
    // Set group 4 bol bias 01 (VH) to 2.1722893506674232 Volts
    Pacs_BOLC_SET_VH_G4(2.1722893506674232);
    // Set group 4 bol bias 02 (VL) to -0.42771064933257685 Volts
    Pacs_BOLC_SET_VL_G4(-0.42771064933257685);
    // Set group 4 bol bias 03 (VRL) to 0.39221731535280246 Volts
    Pacs_BOLC_SET_VRL_G4(0.39221731535280246);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.149177348839517 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.149177348839517);
    // Set group 5 bol bias 01 (VH) to 1.672350642991268 Volts
    Pacs_BOLC_SET_VH_G5(1.672350642991268);
    // Set group 5 bol bias 02 (VL) to -0.3276493570087321 Volts
    Pacs_BOLC_SET_VL_G5(-0.3276493570087321);
    // Set group 5 bol bias 03 (VRL) to 0.4170619179215219 Volts
    Pacs_BOLC_SET_VRL_G5(0.4170619179215219);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1733906889405676 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1733906889405676);
    // Set group 6 bol bias 01 (VH) to 1.7008912172749073 Volts
    Pacs_BOLC_SET_VH_G6(1.7008912172749073);
    // Set group 6 bol bias 02 (VL) to -0.29910878272509256 Volts
    Pacs_BOLC_SET_VL_G6(-0.29910878272509256);
    // Set group 6 bol bias 03 (VRL) to 0.4285878202149336 Volts
    Pacs_BOLC_SET_VRL_G6(0.4285878202149336);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.185265943121115 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.185265943121115);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.277374851838026 Volts
    Pacs_BOLC_SET_VH_G1(2.277374851838026);
    // Set group 1 bol bias 02 (VL) to -0.42262514816197444 Volts
    Pacs_BOLC_SET_VL_G1(-0.42262514816197444);
    // Set group 1 bol bias 03 (VRL) to 0.412986079770471 Volts
    Pacs_BOLC_SET_VRL_G1(0.412986079770471);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.17527147605132 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.17527147605132);
    // Set group 2 bol bias 01 (VH) to 2.2215491790076847 Volts
    Pacs_BOLC_SET_VH_G2(2.2215491790076847);
    // Set group 2 bol bias 02 (VL) to -0.47845082099231534 Volts
    Pacs_BOLC_SET_VL_G2(-0.47845082099231534);
    // Set group 2 bol bias 03 (VRL) to 0.3839544928701459 Volts
    Pacs_BOLC_SET_VRL_G2(0.3839544928701459);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1410370082960855 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1410370082960855);
    // Set group 3 bol bias 01 (VH) to 2.2470787404279506 Volts
    Pacs_BOLC_SET_VH_G3(2.2470787404279506);
    // Set group 3 bol bias 02 (VL) to -0.45292125957204954 Volts
    Pacs_BOLC_SET_VL_G3(-0.45292125957204954);
    // Set group 3 bol bias 03 (VRL) to 0.4126112124132568 Volts
    Pacs_BOLC_SET_VRL_G3(0.4126112124132568);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1693128088208002 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1693128088208002);
    // Set group 4 bol bias 01 (VH) to 2.2726002220999186 Volts
    Pacs_BOLC_SET_VH_G4(2.2726002220999186);
    // Set group 4 bol bias 02 (VL) to -0.4273997779000817 Volts
    Pacs_BOLC_SET_VL_G4(-0.4273997779000817);
    // Set group 4 bol bias 03 (VRL) to 0.4047484369681677 Volts
    Pacs_BOLC_SET_VRL_G4(0.4047484369681677);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1635026072769583 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1635026072769583);
    // Set group 5 bol bias 01 (VH) to 1.741672362484853 Volts
    Pacs_BOLC_SET_VH_G5(1.741672362484853);
    // Set group 5 bol bias 02 (VL) to -0.3583276375151472 Volts
    Pacs_BOLC_SET_VL_G5(-0.3583276375151472);
    // Set group 5 bol bias 03 (VRL) to 0.41560596154523743 Volts
    Pacs_BOLC_SET_VRL_G5(0.41560596154523743);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.171649367885339 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.171649367885339);
    // Set group 6 bol bias 01 (VH) to 1.7713375354827958 Volts
    Pacs_BOLC_SET_VH_G6(1.7713375354827958);
    // Set group 6 bol bias 02 (VL) to -0.32866246451720427 Volts
    Pacs_BOLC_SET_VL_G6(-0.32866246451720427);
    // Set group 6 bol bias 03 (VRL) to 0.4273785641397081 Volts
    Pacs_BOLC_SET_VRL_G6(0.4273785641397081);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1838064879170065 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1838064879170065);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.3726321543483597 Volts
    Pacs_BOLC_SET_VH_G1(2.3726321543483597);
    // Set group 1 bol bias 02 (VL) to -0.42736784565164027 Volts
    Pacs_BOLC_SET_VL_G1(-0.42736784565164027);
    // Set group 1 bol bias 03 (VRL) to 0.41278613469743136 Volts
    Pacs_BOLC_SET_VRL_G1(0.41278613469743136);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175034786819366 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175034786819366);
    // Set group 2 bol bias 01 (VH) to 2.3098900899290933 Volts
    Pacs_BOLC_SET_VH_G2(2.3098900899290933);
    // Set group 2 bol bias 02 (VL) to -0.4901099100709065 Volts
    Pacs_BOLC_SET_VL_G2(-0.4901099100709065);
    // Set group 2 bol bias 03 (VRL) to 0.38176098160337385 Volts
    Pacs_BOLC_SET_VRL_G2(0.38176098160337385);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.138491434649418 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.138491434649418);
    // Set group 3 bol bias 01 (VH) to 2.3383160006315378 Volts
    Pacs_BOLC_SET_VH_G3(2.3383160006315378);
    // Set group 3 bol bias 02 (VL) to -0.46168399936846216 Volts
    Pacs_BOLC_SET_VL_G3(-0.46168399936846216);
    // Set group 3 bol bias 03 (VRL) to 0.4120985537665002 Volts
    Pacs_BOLC_SET_VRL_G3(0.4120985537665002);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.168745971889183 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.168745971889183);
    // Set group 4 bol bias 01 (VH) to 2.353728832549639 Volts
    Pacs_BOLC_SET_VH_G4(2.353728832549639);
    // Set group 4 bol bias 02 (VL) to -0.4462711674503611 Volts
    Pacs_BOLC_SET_VL_G4(-0.4462711674503611);
    // Set group 4 bol bias 03 (VRL) to 0.3933899185168154 Volts
    Pacs_BOLC_SET_VRL_G4(0.3933899185168154);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150516989712913 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150516989712913);
    // Set group 5 bol bias 01 (VH) to 1.824428254554781 Volts
    Pacs_BOLC_SET_VH_G5(1.824428254554781);
    // Set group 5 bol bias 02 (VL) to -0.37557174544521915 Volts
    Pacs_BOLC_SET_VL_G5(-0.37557174544521915);
    // Set group 5 bol bias 03 (VRL) to 0.42479162256165287 Volts
    Pacs_BOLC_SET_VRL_G5(0.42479162256165287);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1826386366003407 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1826386366003407);
    // Set group 6 bol bias 01 (VH) to 1.8448086017559384 Volts
    Pacs_BOLC_SET_VH_G6(1.8448086017559384);
    // Set group 6 bol bias 02 (VL) to -0.35519139824406176 Volts
    Pacs_BOLC_SET_VL_G6(-0.35519139824406176);
    // Set group 6 bol bias 03 (VRL) to 0.42616082648842024 Volts
    Pacs_BOLC_SET_VRL_G6(0.42616082648842024);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182336747063833 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182336747063833);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6022085953557523 Volts
    Pacs_BOLC_SET_VH_G1(2.6022085953557523);
    // Set group 1 bol bias 02 (VL) to -0.39779140464424784 Volts
    Pacs_BOLC_SET_VL_G1(-0.39779140464424784);
    // Set group 1 bol bias 03 (VRL) to 0.43521923623240194 Volts
    Pacs_BOLC_SET_VRL_G1(0.43521923623240194);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.20158295007033 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.20158295007033);
    // Set group 2 bol bias 01 (VH) to 2.5162287990597294 Volts
    Pacs_BOLC_SET_VH_G2(2.5162287990597294);
    // Set group 2 bol bias 02 (VL) to -0.4837712009402705 Volts
    Pacs_BOLC_SET_VL_G2(-0.4837712009402705);
    // Set group 2 bol bias 03 (VRL) to 0.391912650835165 Volts
    Pacs_BOLC_SET_VRL_G2(0.391912650835165);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1502748411134047 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1502748411134047);
    // Set group 3 bol bias 01 (VH) to 2.5390848578205745 Volts
    Pacs_BOLC_SET_VH_G3(2.5390848578205745);
    // Set group 3 bol bias 02 (VL) to -0.46091514217942564 Volts
    Pacs_BOLC_SET_VL_G3(-0.46091514217942564);
    // Set group 3 bol bias 03 (VRL) to 0.41108173068219134 Volts
    Pacs_BOLC_SET_VRL_G3(0.41108173068219134);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.167621634463724 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.167621634463724);
    // Set group 4 bol bias 01 (VH) to 2.5545623915738194 Volts
    Pacs_BOLC_SET_VH_G4(2.5545623915738194);
    // Set group 4 bol bias 02 (VL) to -0.44543760842618074 Volts
    Pacs_BOLC_SET_VL_G4(-0.44543760842618074);
    // Set group 4 bol bias 03 (VRL) to 0.39317530313609783 Volts
    Pacs_BOLC_SET_VRL_G4(0.39317530313609783);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.150271792892682 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.150271792892682);
    // Set group 5 bol bias 01 (VH) to 1.9662748243550656 Volts
    Pacs_BOLC_SET_VH_G5(1.9662748243550656);
    // Set group 5 bol bias 02 (VL) to -0.43372517564493435 Volts
    Pacs_BOLC_SET_VL_G5(-0.43372517564493435);
    // Set group 5 bol bias 03 (VRL) to 0.4093129041436175 Volts
    Pacs_BOLC_SET_VRL_G5(0.4093129041436175);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.164125104146648 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.164125104146648);
    // Set group 6 bol bias 01 (VH) to 2.0014259793731695 Volts
    Pacs_BOLC_SET_VH_G6(2.0014259793731695);
    // Set group 6 bol bias 02 (VL) to -0.3985740206268302 Volts
    Pacs_BOLC_SET_VL_G6(-0.3985740206268302);
    // Set group 6 bol bias 03 (VRL) to 0.42301507758845813 Volts
    Pacs_BOLC_SET_VRL_G6(0.42301507758845813);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.178539776519565 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.178539776519565);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.9551207474233574 Volts
    Pacs_BOLC_SET_VH_G1(2.9551207474233574);
    // Set group 1 bol bias 02 (VL) to -0.3448792525766426 Volts
    Pacs_BOLC_SET_VL_G1(-0.3448792525766426);
    // Set group 1 bol bias 03 (VRL) to 0.4351736078784852 Volts
    Pacs_BOLC_SET_VRL_G1(0.4351736078784852);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201529239898494 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201529239898494);
    // Set group 2 bol bias 01 (VH) to 2.873651677916379 Volts
    Pacs_BOLC_SET_VH_G2(2.873651677916379);
    // Set group 2 bol bias 02 (VL) to -0.4263483220836208 Volts
    Pacs_BOLC_SET_VL_G2(-0.4263483220836208);
    // Set group 2 bol bias 03 (VRL) to 0.4146875402998553 Volts
    Pacs_BOLC_SET_VRL_G2(0.4146875402998553);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.176675727908029 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.176675727908029);
    // Set group 3 bol bias 01 (VH) to 2.913784614063545 Volts
    Pacs_BOLC_SET_VH_G3(2.913784614063545);
    // Set group 3 bol bias 02 (VL) to -0.3862153859364546 Volts
    Pacs_BOLC_SET_VL_G3(-0.3862153859364546);
    // Set group 3 bol bias 03 (VRL) to 0.43315715258744586 Volts
    Pacs_BOLC_SET_VRL_G3(0.43315715258744586);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1920146497707034 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1920146497707034);
    // Set group 4 bol bias 01 (VH) to 2.929067751322499 Volts
    Pacs_BOLC_SET_VH_G4(2.929067751322499);
    // Set group 4 bol bias 02 (VL) to -0.3709322486775005 Volts
    Pacs_BOLC_SET_VL_G4(-0.3709322486775005);
    // Set group 4 bol bias 03 (VRL) to 0.4248135618287161 Volts
    Pacs_BOLC_SET_VRL_G4(0.4248135618287161);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.186436122624544 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.186436122624544);
    // Set group 5 bol bias 01 (VH) to 2.1600578049697337 Volts
    Pacs_BOLC_SET_VH_G5(2.1600578049697337);
    // Set group 5 bol bias 02 (VL) to -0.4399421950302663 Volts
    Pacs_BOLC_SET_VL_G5(-0.4399421950302663);
    // Set group 5 bol bias 03 (VRL) to 0.4247099644649015 Volts
    Pacs_BOLC_SET_VRL_G5(0.4247099644649015);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1825409110204914 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1825409110204914);
    // Set group 6 bol bias 01 (VH) to 2.181098334973619 Volts
    Pacs_BOLC_SET_VH_G6(2.181098334973619);
    // Set group 6 bol bias 02 (VL) to -0.41890166502638126 Volts
    Pacs_BOLC_SET_VL_G6(-0.41890166502638126);
    // Set group 6 bol bias 03 (VRL) to 0.4228321180850223 Volts
    Pacs_BOLC_SET_VRL_G6(0.4228321180850223);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1783189312552813 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1783189312552813);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //*******************************
    // Select Filter B (70 microns)
    //*******************************
    //
    PHOT_fltw_move("POS B");
    //
    //
    //**********************************************************************
    //                       Measurement
    // Fluxes 1.40pW on the blue and 3.50pW on the red
    //**********************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)bleu = 1.25 Volts, (Vh-Vl)rouge = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G1(1.24);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.38668078523499405 Volts
    Pacs_BOLC_SET_VRL_G1(0.38668078523499405);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1440988586390484 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1440988586390484);
    // Set group 2 bol bias 01 (VH) to 1.2338312108512528 Volts
    Pacs_BOLC_SET_VH_G2(1.2338312108512528);
    // Set group 2 bol bias 02 (VL) to -0.016168789148747163 Volts
    Pacs_BOLC_SET_VL_G2(-0.016168789148747163);
    // Set group 2 bol bias 03 (VRL) to 0.388833640603409 Volts
    Pacs_BOLC_SET_VRL_G2(0.388833640603409);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1467002828323563 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1467002828323563);
    // Set group 3 bol bias 01 (VH) to 1.236662658965404 Volts
    Pacs_BOLC_SET_VH_G3(1.236662658965404);
    // Set group 3 bol bias 02 (VL) to -0.013337341034596016 Volts
    Pacs_BOLC_SET_VL_G3(-0.013337341034596016);
    // Set group 3 bol bias 03 (VRL) to 0.3895598518239543 Volts
    Pacs_BOLC_SET_VRL_G3(0.3895598518239543);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.143849321106141 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.143849321106141);
    // Set group 4 bol bias 01 (VH) to 1.24 Volts
    Pacs_BOLC_SET_VH_G4(1.24);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3791855078303921 Volts
    Pacs_BOLC_SET_VRL_G4(0.3791855078303921);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1342976211365037 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1342976211365037);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3747664602557065 Volts
    Pacs_BOLC_SET_VRL_G5(0.3747664602557065);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1227166495195537 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1227166495195537);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.3658432804212911 Volts
    Pacs_BOLC_SET_VRL_G6(0.3658432804212911);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.109568791597369 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.109568791597369);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)bleu = 1.6 Volts, (Vh-Vl)rouge = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.465883546774461 Volts
    Pacs_BOLC_SET_VH_G1(1.465883546774461);
    // Set group 1 bol bias 02 (VL) to -0.1341164532255389 Volts
    Pacs_BOLC_SET_VL_G1(-0.1341164532255389);
    // Set group 1 bol bias 03 (VRL) to 0.3927444050100226 Volts
    Pacs_BOLC_SET_VRL_G1(0.3927444050100226);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1512900780864035 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1512900780864035);
    // Set group 2 bol bias 01 (VH) to 1.4510797579158528 Volts
    Pacs_BOLC_SET_VH_G2(1.4510797579158528);
    // Set group 2 bol bias 02 (VL) to -0.14892024208414734 Volts
    Pacs_BOLC_SET_VL_G2(-0.14892024208414734);
    // Set group 2 bol bias 03 (VRL) to 0.38846912134246203 Volts
    Pacs_BOLC_SET_VRL_G2(0.38846912134246203);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1462771333412234 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1462771333412234);
    // Set group 3 bol bias 01 (VH) to 1.4538991391980187 Volts
    Pacs_BOLC_SET_VH_G3(1.4538991391980187);
    // Set group 3 bol bias 02 (VL) to -0.14610086080198126 Volts
    Pacs_BOLC_SET_VL_G3(-0.14610086080198126);
    // Set group 3 bol bias 03 (VRL) to 0.38980925048925386 Volts
    Pacs_BOLC_SET_VRL_G3(0.38980925048925386);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.144124391014403 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.144124391014403);
    // Set group 4 bol bias 01 (VH) to 1.4690736780149993 Volts
    Pacs_BOLC_SET_VH_G4(1.4690736780149993);
    // Set group 4 bol bias 02 (VL) to -0.13092632198500076 Volts
    Pacs_BOLC_SET_VL_G4(-0.13092632198500076);
    // Set group 4 bol bias 03 (VRL) to 0.3864250943177998 Volts
    Pacs_BOLC_SET_VRL_G4(0.3864250943177998);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.142561869380803 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.142561869380803);
    // Set group 5 bol bias 01 (VH) to 1.17383991574692 Volts
    Pacs_BOLC_SET_VH_G5(1.17383991574692);
    // Set group 5 bol bias 02 (VL) to -0.02616008425308 Volts
    Pacs_BOLC_SET_VL_G5(-0.02616008425308);
    // Set group 5 bol bias 03 (VRL) to 0.43476802245017643 Volts
    Pacs_BOLC_SET_VRL_G5(0.43476802245017643);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1945801325409864 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1945801325409864);
    // Set group 6 bol bias 01 (VH) to 1.1864799253248077 Volts
    Pacs_BOLC_SET_VH_G6(1.1864799253248077);
    // Set group 6 bol bias 02 (VL) to -0.013520074675192215 Volts
    Pacs_BOLC_SET_VL_G6(-0.013520074675192215);
    // Set group 6 bol bias 03 (VRL) to 0.43690432497388915 Volts
    Pacs_BOLC_SET_VRL_G6(0.43690432497388915);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1952488403472232 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1952488403472232);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)bleu = 1.8 Volts, (Vh-Vl)rouge = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.5942239158792035 Volts
    Pacs_BOLC_SET_VH_G1(1.5942239158792035);
    // Set group 1 bol bias 02 (VL) to -0.20577608412079662 Volts
    Pacs_BOLC_SET_VL_G1(-0.20577608412079662);
    // Set group 1 bol bias 03 (VRL) to 0.39285576460072325 Volts
    Pacs_BOLC_SET_VRL_G1(0.39285576460072325);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1514221707950476 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1514221707950476);
    // Set group 2 bol bias 01 (VH) to 1.5782265308965413 Volts
    Pacs_BOLC_SET_VH_G2(1.5782265308965413);
    // Set group 2 bol bias 02 (VL) to -0.22177346910345885 Volts
    Pacs_BOLC_SET_VL_G2(-0.22177346910345885);
    // Set group 2 bol bias 03 (VRL) to 0.38837965192690205 Volts
    Pacs_BOLC_SET_VRL_G2(0.38837965192690205);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1461732746262836 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1461732746262836);
    // Set group 3 bol bias 01 (VH) to 1.580811243374154 Volts
    Pacs_BOLC_SET_VH_G3(1.580811243374154);
    // Set group 3 bol bias 02 (VL) to -0.21918875662584614 Volts
    Pacs_BOLC_SET_VL_G3(-0.21918875662584614);
    // Set group 3 bol bias 03 (VRL) to 0.3902423921973218 Volts
    Pacs_BOLC_SET_VRL_G3(0.3902423921973218);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1446021208870896 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1446021208870896);
    // Set group 4 bol bias 01 (VH) to 1.5985016213661813 Volts
    Pacs_BOLC_SET_VH_G4(1.5985016213661813);
    // Set group 4 bol bias 02 (VL) to -0.2014983786338186 Volts
    Pacs_BOLC_SET_VL_G4(-0.2014983786338186);
    // Set group 4 bol bias 03 (VRL) to 0.3876923883387724 Volts
    Pacs_BOLC_SET_VRL_G4(0.3876923883387724);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1440090238460745 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1440090238460745);
    // Set group 5 bol bias 01 (VH) to 1.295861500105004 Volts
    Pacs_BOLC_SET_VH_G5(1.295861500105004);
    // Set group 5 bol bias 02 (VL) to -0.10413849989499598 Volts
    Pacs_BOLC_SET_VL_G5(-0.10413849989499598);
    // Set group 5 bol bias 03 (VRL) to 0.433595357898982 Volts
    Pacs_BOLC_SET_VRL_G5(0.433595357898982);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1931781023528045 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1931781023528045);
    // Set group 6 bol bias 01 (VH) to 1.3087380679890719 Volts
    Pacs_BOLC_SET_VH_G6(1.3087380679890719);
    // Set group 6 bol bias 02 (VL) to -0.09126193201092794 Volts
    Pacs_BOLC_SET_VL_G6(-0.09126193201092794);
    // Set group 6 bol bias 03 (VRL) to 0.4351222025681505 Volts
    Pacs_BOLC_SET_VRL_G6(0.4351222025681505);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1931233522674587 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1931233522674587);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)bleu = 2.0 Volts, (Vh-Vl)rouge = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.7267527166020806 Volts
    Pacs_BOLC_SET_VH_G1(1.7267527166020806);
    // Set group 1 bol bias 02 (VL) to -0.2732472833979195 Volts
    Pacs_BOLC_SET_VL_G1(-0.2732472833979195);
    // Set group 1 bol bias 03 (VRL) to 0.39249716385798894 Volts
    Pacs_BOLC_SET_VRL_G1(0.39249716385798894);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1509968083188733 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1509968083188733);
    // Set group 2 bol bias 01 (VH) to 1.709097510395655 Volts
    Pacs_BOLC_SET_VH_G2(1.709097510395655);
    // Set group 2 bol bias 02 (VL) to -0.29090248960434506 Volts
    Pacs_BOLC_SET_VL_G2(-0.29090248960434506);
    // Set group 2 bol bias 03 (VRL) to 0.3879908906731334 Volts
    Pacs_BOLC_SET_VRL_G2(0.3879908906731334);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1457219946603137 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1457219946603137);
    // Set group 3 bol bias 01 (VH) to 1.7224136165528545 Volts
    Pacs_BOLC_SET_VH_G3(1.7224136165528545);
    // Set group 3 bol bias 02 (VL) to -0.27758638344714553 Volts
    Pacs_BOLC_SET_VL_G3(-0.27758638344714553);
    // Set group 3 bol bias 03 (VRL) to 0.4016418604625224 Volts
    Pacs_BOLC_SET_VRL_G3(0.4016418604625224);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1571801138874425 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1571801138874425);
    // Set group 4 bol bias 01 (VH) to 1.7321905339047663 Volts
    Pacs_BOLC_SET_VH_G4(1.7321905339047663);
    // Set group 4 bol bias 02 (VL) to -0.2678094660952336 Volts
    Pacs_BOLC_SET_VL_G4(-0.2678094660952336);
    // Set group 4 bol bias 03 (VRL) to 0.3889753865027208 Volts
    Pacs_BOLC_SET_VRL_G4(0.3889753865027208);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1454742608822808 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1454742608822808);
    // Set group 5 bol bias 01 (VH) to 1.411267790421653 Volts
    Pacs_BOLC_SET_VH_G5(1.411267790421653);
    // Set group 5 bol bias 02 (VL) to -0.18873220957834702 Volts
    Pacs_BOLC_SET_VL_G5(-0.18873220957834702);
    // Set group 5 bol bias 03 (VRL) to 0.42107692260771856 Volts
    Pacs_BOLC_SET_VRL_G5(0.42107692260771856);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1781936277623863 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1781936277623863);
    // Set group 6 bol bias 01 (VH) to 1.436583641174852 Volts
    Pacs_BOLC_SET_VH_G6(1.436583641174852);
    // Set group 6 bol bias 02 (VL) to -0.16341635882514807 Volts
    Pacs_BOLC_SET_VL_G6(-0.16341635882514807);
    // Set group 6 bol bias 03 (VRL) to 0.433116085800085 Volts
    Pacs_BOLC_SET_VRL_G6(0.433116085800085);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1907305406171096 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1907305406171096);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)bleu = 2.2 Volts, (Vh-Vl)rouge = 1.7 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.8668317857008898 Volts
    Pacs_BOLC_SET_VH_G1(1.8668317857008898);
    // Set group 1 bol bias 02 (VL) to -0.33316821429911037 Volts
    Pacs_BOLC_SET_VL_G1(-0.33316821429911037);
    // Set group 1 bol bias 03 (VRL) to 0.3923805742316465 Volts
    Pacs_BOLC_SET_VRL_G1(0.3923805742316465);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.150858514842094 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.150858514842094);
    // Set group 2 bol bias 01 (VH) to 1.845853370070876 Volts
    Pacs_BOLC_SET_VH_G2(1.845853370070876);
    // Set group 2 bol bias 02 (VL) to -0.35414662992912427 Volts
    Pacs_BOLC_SET_VL_G2(-0.35414662992912427);
    // Set group 2 bol bias 03 (VRL) to 0.3871691314916821 Volts
    Pacs_BOLC_SET_VRL_G2(0.3871691314916821);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1447681133937135 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1447681133937135);
    // Set group 3 bol bias 01 (VH) to 1.8595347855526148 Volts
    Pacs_BOLC_SET_VH_G3(1.8595347855526148);
    // Set group 3 bol bias 02 (VL) to -0.34046521444738537 Volts
    Pacs_BOLC_SET_VL_G3(-0.34046521444738537);
    // Set group 3 bol bias 03 (VRL) to 0.4021735206741129 Volts
    Pacs_BOLC_SET_VRL_G3(0.4021735206741129);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.157768356731922 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.157768356731922);
    // Set group 4 bol bias 01 (VH) to 1.8733871726206046 Volts
    Pacs_BOLC_SET_VH_G4(1.8733871726206046);
    // Set group 4 bol bias 02 (VL) to -0.3266128273793957 Volts
    Pacs_BOLC_SET_VL_G4(-0.3266128273793957);
    // Set group 4 bol bias 03 (VRL) to 0.3906766362783094 Volts
    Pacs_BOLC_SET_VRL_G4(0.3906766362783094);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.147417390774941 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.147417390774941);
    // Set group 5 bol bias 01 (VH) to 1.474653839775916 Volts
    Pacs_BOLC_SET_VH_G5(1.474653839775916);
    // Set group 5 bol bias 02 (VL) to -0.22534616022408405 Volts
    Pacs_BOLC_SET_VL_G5(-0.22534616022408405);
    // Set group 5 bol bias 03 (VRL) to 0.4201505271824174 Volts
    Pacs_BOLC_SET_VRL_G5(0.4201505271824174);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1770852992715035 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1770852992715035);
    // Set group 6 bol bias 01 (VH) to 1.500693203446836 Volts
    Pacs_BOLC_SET_VH_G6(1.500693203446836);
    // Set group 6 bol bias 02 (VL) to -0.19930679655316377 Volts
    Pacs_BOLC_SET_VL_G6(-0.19930679655316377);
    // Set group 6 bol bias 03 (VRL) to 0.43196086785086785 Volts
    Pacs_BOLC_SET_VRL_G6(0.43196086785086785);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.189336628282171 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.189336628282171);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)bleu = 2.4 Volts, (Vh-Vl)rouge = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.0281700125862256 Volts
    Pacs_BOLC_SET_VH_G1(2.0281700125862256);
    // Set group 1 bol bias 02 (VL) to -0.3718299874137741 Volts
    Pacs_BOLC_SET_VL_G1(-0.3718299874137741);
    // Set group 1 bol bias 03 (VRL) to 0.40288617097447316 Volts
    Pacs_BOLC_SET_VRL_G1(0.40288617097447316);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.163316228257877 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.163316228257877);
    // Set group 2 bol bias 01 (VH) to 1.9913549838459623 Volts
    Pacs_BOLC_SET_VH_G2(1.9913549838459623);
    // Set group 2 bol bias 02 (VL) to -0.4086450161540375 Volts
    Pacs_BOLC_SET_VL_G2(-0.4086450161540375);
    // Set group 2 bol bias 03 (VRL) to 0.3857267466147216 Volts
    Pacs_BOLC_SET_VRL_G2(0.3857267466147216);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.143093918581265 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.143093918581265);
    // Set group 3 bol bias 01 (VH) to 2.0168292556182674 Volts
    Pacs_BOLC_SET_VH_G3(2.0168292556182674);
    // Set group 3 bol bias 02 (VL) to -0.38317074438173243 Volts
    Pacs_BOLC_SET_VL_G3(-0.38317074438173243);
    // Set group 3 bol bias 03 (VRL) to 0.4136059384082988 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136059384082988);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1704126050111037 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1704126050111037);
    // Set group 4 bol bias 01 (VH) to 2.023161689281816 Volts
    Pacs_BOLC_SET_VH_G4(2.023161689281816);
    // Set group 4 bol bias 02 (VL) to -0.37683831071818397 Volts
    Pacs_BOLC_SET_VL_G4(-0.37683831071818397);
    // Set group 4 bol bias 03 (VRL) to 0.39142637448788486 Volts
    Pacs_BOLC_SET_VRL_G4(0.39142637448788486);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1482738092425575 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1482738092425575);
    // Set group 5 bol bias 01 (VH) to 1.538531208741738 Volts
    Pacs_BOLC_SET_VH_G5(1.538531208741738);
    // Set group 5 bol bias 02 (VL) to -0.26146879125826195 Volts
    Pacs_BOLC_SET_VL_G5(-0.26146879125826195);
    // Set group 5 bol bias 03 (VRL) to 0.41899816344351815 Volts
    Pacs_BOLC_SET_VRL_G5(0.41899816344351815);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.175706734147529 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.175706734147529);
    // Set group 6 bol bias 01 (VH) to 1.565420545490553 Volts
    Pacs_BOLC_SET_VH_G6(1.565420545490553);
    // Set group 6 bol bias 02 (VL) to -0.23457945450944698 Volts
    Pacs_BOLC_SET_VL_G6(-0.23457945450944698);
    // Set group 6 bol bias 03 (VRL) to 0.4306941180515982 Volts
    Pacs_BOLC_SET_VRL_G6(0.4306941180515982);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1878079247641415 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1878079247641415);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)bleu = 2.5 Volts, (Vh-Vl)rouge = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.119417393352342 Volts
    Pacs_BOLC_SET_VH_G1(2.119417393352342);
    // Set group 1 bol bias 02 (VL) to -0.3805826066476578 Volts
    Pacs_BOLC_SET_VL_G1(-0.3805826066476578);
    // Set group 1 bol bias 03 (VRL) to 0.4138019261542308 Volts
    Pacs_BOLC_SET_VRL_G1(0.4138019261542308);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1762372576407976 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1762372576407976);
    // Set group 2 bol bias 01 (VH) to 2.068587531091144 Volts
    Pacs_BOLC_SET_VH_G2(2.068587531091144);
    // Set group 2 bol bias 02 (VL) to -0.4314124689088562 Volts
    Pacs_BOLC_SET_VL_G2(-0.4314124689088562);
    // Set group 2 bol bias 03 (VRL) to 0.3852251579492122 Volts
    Pacs_BOLC_SET_VRL_G2(0.3852251579492122);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1425117468043053 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1425117468043053);
    // Set group 3 bol bias 01 (VH) to 2.094624328745432 Volts
    Pacs_BOLC_SET_VH_G3(2.094624328745432);
    // Set group 3 bol bias 02 (VL) to -0.405375671254568 Volts
    Pacs_BOLC_SET_VL_G3(-0.405375671254568);
    // Set group 3 bol bias 03 (VRL) to 0.4137192033290737 Volts
    Pacs_BOLC_SET_VRL_G3(0.4137192033290737);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1705378293229685 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1705378293229685);
    // Set group 4 bol bias 01 (VH) to 2.1026853301688146 Volts
    Pacs_BOLC_SET_VH_G4(2.1026853301688146);
    // Set group 4 bol bias 02 (VL) to -0.39731466983118546 Volts
    Pacs_BOLC_SET_VL_G4(-0.39731466983118546);
    // Set group 4 bol bias 03 (VRL) to 0.3918225009333296 Volts
    Pacs_BOLC_SET_VRL_G4(0.3918225009333296);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.148726321289223 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.148726321289223);
    // Set group 5 bol bias 01 (VH) to 1.6043700903162197 Volts
    Pacs_BOLC_SET_VH_G5(1.6043700903162197);
    // Set group 5 bol bias 02 (VL) to -0.29562990968378033 Volts
    Pacs_BOLC_SET_VL_G5(-0.29562990968378033);
    // Set group 5 bol bias 03 (VRL) to 0.4179972717442382 Volts
    Pacs_BOLC_SET_VRL_G5(0.4179972717442382);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.174509472234708 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.174509472234708);
    // Set group 6 bol bias 01 (VH) to 1.631792337309164 Volts
    Pacs_BOLC_SET_VH_G6(1.631792337309164);
    // Set group 6 bol bias 02 (VL) to -0.26820766269083596 Volts
    Pacs_BOLC_SET_VL_G6(-0.26820766269083596);
    // Set group 6 bol bias 03 (VRL) to 0.4294097753204019 Volts
    Pacs_BOLC_SET_VRL_G6(0.4294097753204019);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.186257935692563 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.186257935692563);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)bleu = 2.6 Volts, (Vh-Vl)rouge = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.203669207141163 Volts
    Pacs_BOLC_SET_VH_G1(2.203669207141163);
    // Set group 1 bol bias 02 (VL) to -0.39633079285883693 Volts
    Pacs_BOLC_SET_VL_G1(-0.39633079285883693);
    // Set group 1 bol bias 03 (VRL) to 0.4135124609477607 Volts
    Pacs_BOLC_SET_VRL_G1(0.4135124609477607);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.175894593770016 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.175894593770016);
    // Set group 2 bol bias 01 (VH) to 2.1495341950300215 Volts
    Pacs_BOLC_SET_VH_G2(2.1495341950300215);
    // Set group 2 bol bias 02 (VL) to -0.45046580496997846 Volts
    Pacs_BOLC_SET_VL_G2(-0.45046580496997846);
    // Set group 2 bol bias 03 (VRL) to 0.38460527393566324 Volts
    Pacs_BOLC_SET_VRL_G2(0.38460527393566324);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1417922952992905 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1417922952992905);
    // Set group 3 bol bias 01 (VH) to 2.1758897261321537 Volts
    Pacs_BOLC_SET_VH_G3(2.1758897261321537);
    // Set group 3 bol bias 02 (VL) to -0.42411027386784644 Volts
    Pacs_BOLC_SET_VL_G3(-0.42411027386784644);
    // Set group 3 bol bias 03 (VRL) to 0.4135460031306419 Volts
    Pacs_BOLC_SET_VRL_G3(0.4135460031306419);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1703463409307253 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1703463409307253);
    // Set group 4 bol bias 01 (VH) to 2.1976142530616287 Volts
    Pacs_BOLC_SET_VH_G4(2.1976142530616287);
    // Set group 4 bol bias 02 (VL) to -0.4023857469383713 Volts
    Pacs_BOLC_SET_VL_G4(-0.4023857469383713);
    // Set group 4 bol bias 03 (VRL) to 0.4036787075765456 Volts
    Pacs_BOLC_SET_VRL_G4(0.4036787075765456);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1622790169834865 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1622790169834865);
    // Set group 5 bol bias 01 (VH) to 1.672350642991268 Volts
    Pacs_BOLC_SET_VH_G5(1.672350642991268);
    // Set group 5 bol bias 02 (VL) to -0.3276493570087321 Volts
    Pacs_BOLC_SET_VL_G5(-0.3276493570087321);
    // Set group 5 bol bias 03 (VRL) to 0.4170619179215219 Volts
    Pacs_BOLC_SET_VRL_G5(0.4170619179215219);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1733906889405676 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1733906889405676);
    // Set group 6 bol bias 01 (VH) to 1.7008912172749073 Volts
    Pacs_BOLC_SET_VH_G6(1.7008912172749073);
    // Set group 6 bol bias 02 (VL) to -0.29910878272509256 Volts
    Pacs_BOLC_SET_VL_G6(-0.29910878272509256);
    // Set group 6 bol bias 03 (VRL) to 0.4285878202149336 Volts
    Pacs_BOLC_SET_VRL_G6(0.4285878202149336);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.185265943121115 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.185265943121115);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)bleu = 2.7 Volts, (Vh-Vl)rouge = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2923395528223223 Volts
    Pacs_BOLC_SET_VH_G1(2.2923395528223223);
    // Set group 1 bol bias 02 (VL) to -0.4076604471776781 Volts
    Pacs_BOLC_SET_VL_G1(-0.4076604471776781);
    // Set group 1 bol bias 03 (VRL) to 0.4133364390521634 Volts
    Pacs_BOLC_SET_VRL_G1(0.4133364390521634);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.17568622271672 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.17568622271672);
    // Set group 2 bol bias 01 (VH) to 2.233342115061725 Volts
    Pacs_BOLC_SET_VH_G2(2.233342115061725);
    // Set group 2 bol bias 02 (VL) to -0.46665788493827537 Volts
    Pacs_BOLC_SET_VL_G2(-0.46665788493827537);
    // Set group 2 bol bias 03 (VRL) to 0.38321341183854335 Volts
    Pacs_BOLC_SET_VRL_G2(0.38321341183854335);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.140176950810219 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.140176950810219);
    // Set group 3 bol bias 01 (VH) to 2.2611232382350757 Volts
    Pacs_BOLC_SET_VH_G3(2.2611232382350757);
    // Set group 3 bol bias 02 (VL) to -0.4388767617649245 Volts
    Pacs_BOLC_SET_VL_G3(-0.4388767617649245);
    // Set group 3 bol bias 03 (VRL) to 0.4129840425053698 Volts
    Pacs_BOLC_SET_VRL_G3(0.4129840425053698);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1697250282048794 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1697250282048794);
    // Set group 4 bol bias 01 (VH) to 2.2747139506784495 Volts
    Pacs_BOLC_SET_VH_G4(2.2747139506784495);
    // Set group 4 bol bias 02 (VL) to -0.4252860493215507 Volts
    Pacs_BOLC_SET_VL_G4(-0.4252860493215507);
    // Set group 4 bol bias 03 (VRL) to 0.3936219139251631 Volts
    Pacs_BOLC_SET_VRL_G4(0.3936219139251631);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1507820478544297 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1507820478544297);
    // Set group 5 bol bias 01 (VH) to 1.741672362484853 Volts
    Pacs_BOLC_SET_VH_G5(1.741672362484853);
    // Set group 5 bol bias 02 (VL) to -0.3583276375151472 Volts
    Pacs_BOLC_SET_VL_G5(-0.3583276375151472);
    // Set group 5 bol bias 03 (VRL) to 0.41560596154523743 Volts
    Pacs_BOLC_SET_VRL_G5(0.41560596154523743);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.171649367885339 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.171649367885339);
    // Set group 6 bol bias 01 (VH) to 1.7713375354827958 Volts
    Pacs_BOLC_SET_VH_G6(1.7713375354827958);
    // Set group 6 bol bias 02 (VL) to -0.32866246451720427 Volts
    Pacs_BOLC_SET_VL_G6(-0.32866246451720427);
    // Set group 6 bol bias 03 (VRL) to 0.4273785641397081 Volts
    Pacs_BOLC_SET_VRL_G6(0.4273785641397081);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1838064879170065 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1838064879170065);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)bleu = 2.8 Volts, (Vh-Vl)rouge = 2.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.375464093143857 Volts
    Pacs_BOLC_SET_VH_G1(2.375464093143857);
    // Set group 1 bol bias 02 (VL) to -0.42453590685614256 Volts
    Pacs_BOLC_SET_VL_G1(-0.42453590685614256);
    // Set group 1 bol bias 03 (VRL) to 0.40192264553682994 Volts
    Pacs_BOLC_SET_VRL_G1(0.40192264553682994);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.1621757828053245 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.1621757828053245);
    // Set group 2 bol bias 01 (VH) to 2.3327299417416314 Volts
    Pacs_BOLC_SET_VH_G2(2.3327299417416314);
    // Set group 2 bol bias 02 (VL) to -0.46727005825836854 Volts
    Pacs_BOLC_SET_VL_G2(-0.46727005825836854);
    // Set group 2 bol bias 03 (VRL) to 0.3924852804338007 Volts
    Pacs_BOLC_SET_VRL_G2(0.3924852804338007);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.150939693516247 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.150939693516247);
    // Set group 3 bol bias 01 (VH) to 2.351617078193237 Volts
    Pacs_BOLC_SET_VH_G3(2.351617078193237);
    // Set group 3 bol bias 02 (VL) to -0.44838292180676287 Volts
    Pacs_BOLC_SET_VL_G3(-0.44838292180676287);
    // Set group 3 bol bias 03 (VRL) to 0.4123659760668116 Volts
    Pacs_BOLC_SET_VRL_G3(0.4123659760668116);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.169041657987048 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.169041657987048);
    // Set group 4 bol bias 01 (VH) to 2.366575381594505 Volts
    Pacs_BOLC_SET_VH_G4(2.366575381594505);
    // Set group 4 bol bias 02 (VL) to -0.43342461840549484 Volts
    Pacs_BOLC_SET_VL_G4(-0.43342461840549484);
    // Set group 4 bol bias 03 (VRL) to 0.393704874615589 Volts
    Pacs_BOLC_SET_VRL_G4(0.393704874615589);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1508768328502423 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1508768328502423);
    // Set group 5 bol bias 01 (VH) to 1.824428254554781 Volts
    Pacs_BOLC_SET_VH_G5(1.824428254554781);
    // Set group 5 bol bias 02 (VL) to -0.37557174544521915 Volts
    Pacs_BOLC_SET_VL_G5(-0.37557174544521915);
    // Set group 5 bol bias 03 (VRL) to 0.42479162256165287 Volts
    Pacs_BOLC_SET_VRL_G5(0.42479162256165287);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1826386366003407 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1826386366003407);
    // Set group 6 bol bias 01 (VH) to 1.8448086017559384 Volts
    Pacs_BOLC_SET_VH_G6(1.8448086017559384);
    // Set group 6 bol bias 02 (VL) to -0.35519139824406176 Volts
    Pacs_BOLC_SET_VL_G6(-0.35519139824406176);
    // Set group 6 bol bias 03 (VRL) to 0.42616082648842024 Volts
    Pacs_BOLC_SET_VRL_G6(0.42616082648842024);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.182336747063833 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.182336747063833);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)bleu = 3.0 Volts, (Vh-Vl)rouge = 2.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.6138072272864163 Volts
    Pacs_BOLC_SET_VH_G1(2.6138072272864163);
    // Set group 1 bol bias 02 (VL) to -0.3861927727135836 Volts
    Pacs_BOLC_SET_VL_G1(-0.3861927727135836);
    // Set group 1 bol bias 03 (VRL) to 0.4353887050095893 Volts
    Pacs_BOLC_SET_VRL_G1(0.4353887050095893);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.20178243727658 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.20178243727658);
    // Set group 2 bol bias 01 (VH) to 2.5263121318436657 Volts
    Pacs_BOLC_SET_VH_G2(2.5263121318436657);
    // Set group 2 bol bias 02 (VL) to -0.47368786815633424 Volts
    Pacs_BOLC_SET_VL_G2(-0.47368786815633424);
    // Set group 2 bol bias 03 (VRL) to 0.39177086314846077 Volts
    Pacs_BOLC_SET_VRL_G2(0.39177086314846077);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1501102213011594 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1501102213011594);
    // Set group 3 bol bias 01 (VH) to 2.5503043254064686 Volts
    Pacs_BOLC_SET_VH_G3(2.5503043254064686);
    // Set group 3 bol bias 02 (VL) to -0.44969567459353166 Volts
    Pacs_BOLC_SET_VL_G3(-0.44969567459353166);
    // Set group 3 bol bias 03 (VRL) to 0.41128592247354556 Volts
    Pacs_BOLC_SET_VRL_G3(0.41128592247354556);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1678474225013096 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1678474225013096);
    // Set group 4 bol bias 01 (VH) to 2.5877432338721986 Volts
    Pacs_BOLC_SET_VH_G4(2.5877432338721986);
    // Set group 4 bol bias 02 (VL) to -0.41225676612780143 Volts
    Pacs_BOLC_SET_VL_G4(-0.41225676612780143);
    // Set group 4 bol bias 03 (VRL) to 0.41575195945970284 Volts
    Pacs_BOLC_SET_VRL_G4(0.41575195945970284);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1760832660784124 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1760832660784124);
    // Set group 5 bol bias 01 (VH) to 1.9662748243550656 Volts
    Pacs_BOLC_SET_VH_G5(1.9662748243550656);
    // Set group 5 bol bias 02 (VL) to -0.43372517564493435 Volts
    Pacs_BOLC_SET_VL_G5(-0.43372517564493435);
    // Set group 5 bol bias 03 (VRL) to 0.4093129041436175 Volts
    Pacs_BOLC_SET_VRL_G5(0.4093129041436175);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.164125104146648 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.164125104146648);
    // Set group 6 bol bias 01 (VH) to 2.0014259793731695 Volts
    Pacs_BOLC_SET_VH_G6(2.0014259793731695);
    // Set group 6 bol bias 02 (VL) to -0.3985740206268302 Volts
    Pacs_BOLC_SET_VL_G6(-0.3985740206268302);
    // Set group 6 bol bias 03 (VRL) to 0.42301507758845813 Volts
    Pacs_BOLC_SET_VRL_G6(0.42301507758845813);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.178539776519565 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.178539776519565);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 12 (Vh-Vl)bleu = 3.3 Volts, (Vh-Vl)rouge = 2.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.9622189138633783 Volts
    Pacs_BOLC_SET_VH_G1(2.9622189138633783);
    // Set group 1 bol bias 02 (VL) to -0.33778108613662167 Volts
    Pacs_BOLC_SET_VL_G1(-0.33778108613662167);
    // Set group 1 bol bias 03 (VRL) to 0.43475439263865684 Volts
    Pacs_BOLC_SET_VRL_G1(0.43475439263865684);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.201035780986776 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.201035780986776);
    // Set group 2 bol bias 01 (VH) to 2.880866668982207 Volts
    Pacs_BOLC_SET_VH_G2(2.880866668982207);
    // Set group 2 bol bias 02 (VL) to -0.4191333310177928 Volts
    Pacs_BOLC_SET_VL_G2(-0.4191333310177928);
    // Set group 2 bol bias 03 (VRL) to 0.4147429362694195 Volts
    Pacs_BOLC_SET_VRL_G2(0.4147429362694195);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.1767398814028924 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.1767398814028924);
    // Set group 3 bol bias 01 (VH) to 2.92142504789171 Volts
    Pacs_BOLC_SET_VH_G3(2.92142504789171);
    // Set group 3 bol bias 02 (VL) to -0.3785749521082898 Volts
    Pacs_BOLC_SET_VL_G3(-0.3785749521082898);
    // Set group 3 bol bias 03 (VRL) to 0.4332987168564791 Volts
    Pacs_BOLC_SET_VRL_G3(0.4332987168564791);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.1921709642153493 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.1921709642153493);
    // Set group 4 bol bias 01 (VH) to 2.9362535510998757 Volts
    Pacs_BOLC_SET_VH_G4(2.9362535510998757);
    // Set group 4 bol bias 02 (VL) to -0.3637464489001242 Volts
    Pacs_BOLC_SET_VL_G4(-0.3637464489001242);
    // Set group 4 bol bias 03 (VRL) to 0.42486414957422436 Volts
    Pacs_BOLC_SET_VRL_G4(0.42486414957422436);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.1864938998706736 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.1864938998706736);
    // Set group 5 bol bias 01 (VH) to 2.1600578049697337 Volts
    Pacs_BOLC_SET_VH_G5(2.1600578049697337);
    // Set group 5 bol bias 02 (VL) to -0.4399421950302663 Volts
    Pacs_BOLC_SET_VL_G5(-0.4399421950302663);
    // Set group 5 bol bias 03 (VRL) to 0.4247099644649015 Volts
    Pacs_BOLC_SET_VRL_G5(0.4247099644649015);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.1825409110204914 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.1825409110204914);
    // Set group 6 bol bias 01 (VH) to 2.181098334973619 Volts
    Pacs_BOLC_SET_VH_G6(2.181098334973619);
    // Set group 6 bol bias 02 (VL) to -0.41890166502638126 Volts
    Pacs_BOLC_SET_VL_G6(-0.41890166502638126);
    // Set group 6 bol bias 03 (VRL) to 0.4228321180850223 Volts
    Pacs_BOLC_SET_VRL_G6(0.4228321180850223);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.1783189312552813 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.1783189312552813);
    // Wait for 60 s for stabilization
    delay(60);
    // Measurement during measure_time (s)
    TMMarker601();
    delay(measure_time);
    TMMarker600();
    //********************************
    // Epilogue : Set the safe biases
    //********************************
    PHOT_set_bias_volt(endBiasTable,1);
    PHOT_set_bias_volt(endBiasTable,2);
    PHOT_set_bias_volt(endBiasTable,3);
    PHOT_set_bias_volt(endBiasTable,4);
    PHOT_set_bias_volt(endBiasTable,5);
    PHOT_set_bias_volt(endBiasTable,6);
    //
    // sync the bus
    sync();
}

// Missionphase  : 
//
// Purpose       : Perform Setup Photometry according to TM's input:
//                 Scripts:
//      a) tm_phot_dpu_dmc_setup.tcl  <phot_hk 1, syn_source 4>
//      b) tm_phot_mec_setup.tcl      <phot_filter_wheel_id 1,
//                                     chop_def_pos 0, temp_bb1 800000
//                                     temp_bb2 920000 >
//      c) tm_phot_sequencer_setup.tcl
//      d) tm_phot_polar_bestM7_setup.tcl
//         (Setting of optimal polarisations in the cold 0.3K)
//      e) tm_phot_change_datamode.tcl  <"Bolo & HK">
//      f) tm_phot_change_seq_mode.tcl  <"Sbolo-Sref">
//      g) PACS_Phot_Gain_high.tcl
//         (gain setting  <"high">)
//      h) tm_phot_spu_setup.tcl   <comp_mode_blue 0, comp_mode_red 0
//                                  spus_nraw 3, spul_nraw 3>
//
//
// CUS author    : DAC
// Script file   : PHOT_setup.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 3.0
// History:
// 0.1 DAC 22-apr-2005
// 0.2 DAC 25-apr-2005 New default: Do not start SPU
// 1.0 TM  12-apr-2006, update for FM with new settings
// 1.1 TM  08-aug-2006, new procedure to read bias tables in [V]
// 1.2 TM  10-oct-2006, autonomy function added
// 2.0 DAC 17-oct-2006 Use BIAS tables in volts, eliminate useless
//                     timing calculation, call with BIAS table name and
//                     initial filter position, initial CS temperatures
// 2.1 TM 08-Nov-2006 add the switch on of the groups
// 2.2 TM 08-Nov-2006 autonomy function 17 added
// 2.3 TM 08-Nov-2006 autonomy functions modified again (moved to PHOT_switchon_groups)
// 2.4 TM 10-Nov-2006 default bias table changed, low gain
// 2.5 13-nov-2006 Use RAW bias tables
// 2.6 15-nov-2006 Using volts again
// 2.7  8-dec-2006 Add temperature autonomy function
// 2.8  5-mar-2007 update for chopper, CSs
// 2.9  4-apr-2007 TM: number of raw channels set to zero
// 3.0  9-apr-2007 TM & KO: update of AFs
// 3.1  9-apr-2007 TM & KO: AF 15 taken out again
// 3.2 21-aug-2007 SRC-3507 Indicate end of BB
//                 Sync bus at end of script
// 3.3 06-oct-2008 TM & VDP: PHOT_change_seq_mode set to Sref_only 
// 3.4 12-nov-2008 KO: gotoDirect option added
// 4.0 28-jul-2009 VD & TM: SCR PACS-1805
//
int[] block PHOT_setup PACS 200 {
    string calUfile = "BOLObias_preILT_standard_low"; //BIAS table name
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double set_CS1 = 48.0; // CS1 settings (ohms)
    double set_CS2 = 58.0; // CS2 settings (ohms)
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
}{
    // Register BBID with environment
    WriteBBID($BBID);
    // Define variables to communicate various durations to HSPOT.
    int time_start = time();
    PHOT_dpu_dmc_setup("BOTH Array",4);
    // Place filter wheel
    PHOT_dmc_setup(fltPOS,0,set_CS1,set_CS2);
    // switch on groups and enable AF 17
    PHOT_switchon_groups();
    // Set polarisations
    PHOT_set_bias_volt(calUfile,1);
    PHOT_set_bias_volt(calUfile,2);
    PHOT_set_bias_volt(calUfile,3);
    PHOT_set_bias_volt(calUfile,4);
    PHOT_set_bias_volt(calUfile,5);
    PHOT_set_bias_volt(calUfile,6);
    // Set sequencer
    PHOT_seq_setup();
    // Set data mode
    PHOT_change_data_mode("Bolo_HK");
    //  PHOT_change_seq_mode("Sb_Sref"); New setup post-SOVT1
    // Now we set the direct mode post-SOVT1
    int operand = 0;
    if(gotoDirect) {
        //*********************************************************
        // Sequence mode : blocking on VDEC_X for the direct mode
        //*********************************************************
        //
        // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
        Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
        // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
        Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
        // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
        //# P 09 01 00 01
        operand = 0x9010001;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
    } else {
        // Set seq mode Sb_Sref (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sb_Sref");
        //# P 09 01 00 00
        operand = 0x9010000;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
    }
    // Set gain LOW
    PHOT_set_gain("LOW");
    // Set SPU but do not start it yet
    PHOT_spu_setup(0,0,0,0,false);
    // Time spent
    int duree_TCs = time() - time_start;
    int duree_num = duree_TCs;
    // Return the array of times
    int[] time_array = [duree_num,0,0,0,0];
    //
    // enable AF 12 (to check for the protection biases)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_BIAS","ENABLE");
    // enable AF 14 to check for TEMP_EV < 0.3 K
    Pacs_DPU_SET_FUNCT("EVENT_BOL_T_FPU","ENABLE");
    // enable AF 15 (to check for the VSS currents of groups and BUs)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","ENABLE");
    // Mark end of BB
    WriteEndBB();
    // Sync bus
    sync();

    return time_array;
}

// CVS comments  : $Id: SPEC_get_grat_info.txt,v 1.12 2007/10/25 12:15:43 dcesarsk Exp $ 
// Purpose       : Estimate grating parameters by referring to the U-CAL SPEC_BAND_params_PV and 
//                 grating calibration file mentioned therein
//
// CUS author    : DAC
// Script file   : SPEC_get_grat_info_PV.txt 
//
// Input arguments
// type    name         description
// double  waveLen      Desired wavelength [microns]
//
// Return values
// Type                           Description
// tuple  {double,int,int,        {waveLen,order,gratPos,
//         int,int}                nbSteps,stepSize}  
//
// Description   : Access the table SPEC_BAND_params_PV. Verify that the given
// wavelength is within range; obtain order and the name of the GratCal
// grat vs. wavelength table. Get nominal grating position from GratCal table.
// Returns the grating position such that nominal grating position will be
// acchieved after nbSteps/2 steps
//
// Dependencies  :
//
// Preconditions :
//                 
// Comments      : With current version of lookup, first column has to be of
// type string
// 
// History       : 0.1 22-may-2008 DAC As SPEC_get_grat_info but reading
//                                     SPEC_BAND_params_PV
{double,int,int,int,int} procedure SPEC_get_grat_info_PV {
    double waveLen = 54.0 in [54.0,210.0]; // Sought wavelength
    string resol = "HI" in ["HI","MED","LOW","KHI","KMED","KLOW"]; // Desired resolution
    bool switching = true; // Return central pixel if true
    string extraConf = "normal" in ["normal","bright"];
    string orderSel = "order2";
    bool verbose = false;
}{
    // PacsRangeSpec may call with sedN instead of orderSelN; use
    // "conversion" table for sedN => orderSelN 
    if(orderSel == "sed2") {
        orderSel = "order2";
    }
    if(orderSel == "sed3") {
        orderSel = "order3";
    }
    if(orderSel == "sed4") {
        orderSel = "order2";
    }
    if(verbose) {
        debug_print("SPEC_get_grat_PV: order " + orderSel);
    }
    // Open and read SPEC_BAND_params_PV table. Table indexed by ORDER
    // Try two possible ORDERs: order 1 and order indicated by orderSel
    // Start with order = 1
    int order = 1;
    bool found = false;
    int nbSRCH = 0;
    while(!found && nbSRCH < 2) {
        //   SCR-3164. Deal with "L" lines
        string key = "L" + order;
        //   SCR-3632 Deal with key wavelengths
        if(resol == "KHI" || resol == "KMED" || resol == "KLOW") {
            key = "K" + order;
        }
        //   read BLU and RED edges of the SPEC bands
        double blu = dlookup("SPEC_BAND_params_PV",key,"BLU");
        double red = dlookup("SPEC_BAND_params_PV",key,"RED");
        found = blu <= waveLen && red >= waveLen;
        if(verbose) {
            debug_print("SPEC_get_grat: Switching is " + switching);
            debug_print("SPEC_get_grat: Wave " + waveLen);
            debug_print("SPEC_get_grat: FOUND " + found);
            debug_print("SPEC_get_grat: key " + key);
            debug_print("SPEC_get_grat: nbSRC " + nbSRCH);
        }
        //   If not yet found search in order indicated by orderSel
        if(!found) {
            if(orderSel == "order2") {
                order = 2;
            }
            if(orderSel == "order3") {
                order = 3;
            }
            nbSRCH = nbSRCH + 1;
        }
    }
    // If given wavelength not found there is a problem
    if(!found) {
        error("Wavelength " + waveLen + " is not within " + orderSel);
    }
    // Found the ORDER. Get now the name of position vs. wavelength gratPosTab
    string gratPosTab = slookup("SPEC_BAND_params_PV",key,"CAL_FILE");
    // Read the step size and the number of steps for this ORDER and resolution
    // Recast "resol" as it was before SCR3632
    if(resol == "KHI") {
        resol = "HI";
    }
    if(resol == "KMED") {
        resol = "MED";
    }
    if(resol == "KLOW") {
        resol = "LOW";
    }
    // Special case for "bright" source
    if(extraConf == "normal") {
        int stepSize = ilookup("SPEC_BAND_params_PV",key,resol);
        int nbSteps = ilookup("SPEC_BAND_params_PV",key,"NSTEPS");
    }
    if(extraConf == "bright") {
        stepSize = ilookup("SPEC_BAND_params_PV",key,resol);
        nbSteps = ilookup("SPEC_BAND_params_PV",key,"FASTSTEP");
    }
    // Get from gratPosTab the grating position corresponding to waveLen
    double gratPosDble = interpolate(gratPosTab,"grat_pos",waveLen);
    // gratPos will place waveLen in the middle of the array
    int gratPos = iround(gratPosDble);
    if(verbose) {
        debug_print("SPEC_get_grat Nominal wavelen: " + waveLen);
        debug_print("SPEC_get_grat Nominal grating: " + gratPos);
    }
    // Grating is scanned with a negative step size (increasing wavelength) 
    // The grating start position should then be such that after nbSteps/2 we
    // are at nominal position: 
    //              gratPos = gratStartPos - stepSize*nbSteps/2
    // hence:
    int gratStartPos = iround(gratPosDble + double(stepSize) * double(nbSteps) / 2.0);
    // and will scan by decreasing grating angle, i.e. negative step size:
    stepSize = -stepSize;
    // If frequency switch return return gratPos (central pixel)
    if(switching) {
        gratStartPos = gratPos;
    }
    if(verbose) {
        debug_print("SPEC_get_grat_PV: reads SPEC_BANDS_PV");
        debug_print("SPEC_get_grat_PV: WAVE/order/gratNOMINAL/gratSTRT: " + waveLen + "/" + order + "/" + gratPos + "/" + gratStartPos);
        debug_print("SPEC_get_grat: nbSteps/stepSize: " + nbSteps + "/" + stepSize);
    }

    return {waveLen,order,gratStartPos,nbSteps,stepSize};
}

// CVS comments  : $Id: DMC_chop_grat_scan_cal.txt,v 1.3 2007/04/25 15:14:03 dcesarsk Exp $ 
// Missionphase  : EQM IMT
//
// Purpose	: Compute duration of DMC Sequence 11 : Chopped grating scan
//                calibration (OBCP #13)
//
// Author	: DAC
// CUS script	: DAC
// CVS file	: 
//
// Arguments	: 
//
// Description	: Detailed calibration sequence on the internal sources. The 
//                nominal use of this sequence may be to move the grating at 
//                rough (few micron) step sizes through the PACS spectral 
//                ranges and perform small, chopped up-down scans at fine 
//                grating step sizes on the internal calibration sources. 
//                Note that the spectroscopy field of view fits ~3 times 
//                into the calibration sources field of view. Therefore this 
//                sequence may be called with different absolute chopper 
//                positions for the two internal PACS calibration sources in 
//                order to obtain averaging of possible inhomogeneities of the 
//                calibration sources field of views.
//                For more details see PACS-ME-LI-005, section 4.2.7
//                  
// Dependencies : None
//
// Preconditions: N/A
//                 
// Comments     : No single command is executed here, only the duration is 
//                computed here. Hence, not all parameters of the actual DMC
//                Seq. are relevant here!
//
// Version      : 1.0
//               
// History      : 1.0 25-Apr-2005 Creation by DAC
//                1.1 14-feb-2007 WAIT=1 for chopper is now considered a
//                                useful observation
//
//
int[] procedure DMC_chop_grat_scan_cal {
    int nb_up_dn = 1; // Seq P#1  Nb of sequences: up down up ...
    int nb_grat_steps = 16; // Seq P#3  Nb of grating  steps
    int nb_cycles_grat = 2; // Seq P#5  Nb cycles/grating position
    int nb_ramps_grat_pos = 3; // Seq P#7  Nb of ramps per grating position    
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Start of pseudo code
    //
    // WAIT 1                                              ; have a defined start 
    duree_num = duree_num + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0                                             ; set Label to 0 
    // LOOP P#1 ; main loop 
    for(int loop1 = 1 .. nb_up_dn) {
        // WAIT 1 ; wait for grating 
        duree_num = duree_num + 1;
        duree_OVR = duree_OVR + 1;
        // MOVE_GRATING_RELATIVE P#2                        ; incr. grating rough 
        // LOOP P#3                                         ; grating loop up
        for(int loop2 = 1 .. nb_grat_steps) {
            // WAIT 1                                       ; sync. for grating 
            duree_num = duree_num + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_RELATIVE P#4                   ; incr. grating fine 
            // LOOP P#5 ; chop readout cycle
            for(int loop3 = 1 .. nb_cycles_grat) {
                // WAIT 1                                   ; sync. for chopper 
                duree_num = duree_num + 1;
                duree_CAL = duree_CAL + 1;
                // MOVE_CHOPPER_ABSOLUTE P#6                ; chopper to BB1 
                // LABEL 65                                 ; indicate BB1 
                // WAIT P#7                                 ; take P#7 ramps 
                duree_num = duree_num + nb_ramps_grat_pos;
                duree_CAL = duree_CAL + nb_ramps_grat_pos;
                // WAIT 1                                   ; sync. for chopper 
                duree_num = duree_num + 1;
                duree_CAL = duree_CAL + 1;
                // MOVE_CHOPPER_ABSOLUTE P#8                ; chopper to BB2 
                // LABEL 129 ; indicate BB2 
                // WAIT P#7                                 ; take P#7 ramps 
                duree_num = duree_num + nb_ramps_grat_pos;
                duree_CAL = duree_CAL + nb_ramps_grat_pos;
                // END_LOOP ; chop readout cycle done
            }
            // END_LOOP ; grating scan up done 
        }
        // LOOP P#3 ; grating loop down 
        for(int loop4 = 1 .. nb_grat_steps) {
            // WAIT 1 ; sync. for grating 
            duree_num = duree_num + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_GRATING_RELATIVE P#9 ; decr. grating fine 
            // LOOP P#5 ; chop readout cycle
            for(int lopp5 = 1 .. nb_cycles_grat) {
                // WAIT 1 ; sync. for chopper 
                duree_num = duree_num + 1;
                duree_CAL = duree_CAL + 1;
                // MOVE_CHOPPER_ABSOLUTE P#6 ; chopper to BB1 
                // LABEL 65 ; indicate BB1 
                // WAIT P#7 ; take P#7 ramps 
                duree_num = duree_num + nb_ramps_grat_pos;
                duree_CAL = duree_CAL + nb_ramps_grat_pos;
                // WAIT 1 ; sync. for chopper 
                duree_num = duree_num + 1;
                duree_CAL = duree_CAL + 1;
                // MOVE_CHOPPER_ABSOLUTE P#8 ; chopper to BB2 
                // LABEL 129 ; indicate BB2 
                // WAIT P#7 ; take P#7 ramps 
                duree_num = duree_num + nb_ramps_grat_pos;
                duree_CAL = duree_CAL + nb_ramps_grat_pos;
                // END_LOOP ; chop readout cycle done
            }
            // END_LOOP ; grating scan down done
        }
        // END_LOOP ; main loop done
    }
    // WAIT 1 ; complete last plateau 
    duree_num = duree_num + 1;
    duree_CAL = duree_CAL + 1;
    // LABEL 0 ; no sequence anymore 
    // END_SEQUENCE 
    // 9 Parameters: 
    // nb of "up-down" sequences (P#1); 
    // rough grating step size (P#2); 
    // 2 chopper positions for internal calibration sources (P#6, P#8); 
    // nb of readouts per chopper position (P#7); 
    // nb of chopper cycles per grating position (P#5); 
    // size of relative grating move up (P#4); 
    // size of relative grating move down (P#9); 
    // nb of grating steps fine (P#3) 
    // Note: Usually P#4 = -P#9 (P#3 is unique for loops up and down. 
    // Hence, P#4 ==/ P#9 corresponds not to cover the same wavelength range 
    // during up- and down-scans)
    // Sequence duration, in ramps : 
    // 2 + P#1 * { 1+ 2 * P#3 * [1+ 2 * P#5 * (1+ P#7)]}
    // "Theoretical" duration"
    //   int duree_DMC = 2 + nb_up_dn*(1+2*nb_grat_steps*
    //                  (1+2*nb_cycles_grat*(1+nb_ramps_grat_pos)));
    // Create time_array
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    //   debug_print("+++ DMC(13) reports: " + duree_DMC + " [ramps]");

    return time_array;
}

// Mission phase : Commissioning and Performance Verification phases
//
// Purpose : PCD req.1.1.11
//           Low frequency noise measurement on VRL
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowFreq_Vrl_filler
//
// Argument :
//   measureTime : response measure time in seconds [3600s=1h]
//   biasFile    : Bias table file containing the initial values ["BOLObias_ILT_standard_high"]
//
// Check before executing :
//   + Cooler is recycled
//   + PHOT_setpup has already set the bolometer biases
//
// Description : 
//
// Dependencies : None
//
// Comments : 
//
// Version :
//   2009 Apr 29 : SPU default mode debugged
//   2009 Apr 30 : default bias tables updated
//   2009 Jun 11 : PHOT_change_biases is replaced by PHOT_set_biases
//                 to come back correctly to the bias setting before filler
//
procedure Phot_lowFreq_Vrl_filler {
    int measureTime = 2100; // noise measure time in seconds
    string biasFile = "BOLObias_standard_high"; // Bias table file containing the initial values
    string endBias = "BOLObias_ILT_standard_low"; // Bias table file containing the final values
    bool gotoDirect = true in [true,false]; // End setting
}{
    //
    //***********************************************
    // Bias setting of the detectors for high gain
    //***********************************************
    //
    PHOT_change_biases(biasFile,"DIRECT","HIGH");
    //
    //****************************************************************
    // Sequence mode : blocking on CKRL for the mode non-hache on VRL
    //****************************************************************
    //
    // Set all groups bol bias 09 (CKRLH) to 2.0 volts
    Pacs_BOLC_SET_CKRLH_ALL(2.0);
    // Set all groups bol bias 10 (CKRLL) to 2.0 volts
    Pacs_BOLC_SET_CKRLL_ALL(2.0);
    // Set all groups bol bias 12 (VDECX-L) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc0000);
    // Set all groups bol bias 11 (VDECX-H) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0xb0000);
    //
    //********************
    // Let all stabilized
    //********************
    delay(120);
    //
    //*******************
    // Set VRL to 0.45 V
    //*******************
    //
    // Set all groups bol bias 03 (VRL) to 0.45 volts
    Pacs_BOLC_SET_VRL_ALL(0.45);
    //
    //**************************************
    // Noise measurement during measureTime
    //**************************************
    TMMarker601();
    delay(measureTime);
    TMMarker600();
    //
    //*************************************
    // End bias setting of the detectors
    //*************************************
    //
    string setting = "DIRECT";
    if(gotoDirect) {
        setting = "DIRECT";
    } else {
        setting = "DDCS";
    }
    PHOT_set_biases(endBias,setting,"LOW");
    //****************************
    // Stop science data downlink
    //****************************
    PHOT_spu_setup(0,0,3,3,false);
    //
    // sync the bus
    sync();
}

// Missionphase  : 
//
// Purpose       : Generic PACS spectroscopy AOT setup                 
//
// Author        : Diego A. Cesarsky, HF
// CUS script    : Diego A. Cesarsky
// CVS file      : SPEC_aot_prologue.txt
//
// Arguments     :
// type    Name         DefVal   Description 
// int     ramp_len_red    64    Red ramps' length
// int     ramp_len_blu    64    Blue ramps' length
// double  bias_d_red     0.07   BIAS_D for red spectro  (0-1V)
// double  bias_r_red     0.011  BIAS_R for red spectro  (0-1V)
// double  bias_d_blu     0.21   BIAS_D for blue spectro (0-1V)
// double  bias_r_blu     0.011  BIAS_R for blue spectro (0-1V)
// int     capa_red         8    Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
// int     capa_blu         8    Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
// int     comp_mode_blu   16    Compression mode blue channel
// int     comp_mode_red   16    Compression mode red channel
// int     nb_samp_subramp_blu 64   Number of blue samples per sub-ramp
// int     nb_samp_subramp_red 64   Number of red samples per sub-ramp
// int     nb_raw_spu_blu  1     Number of raw channels transmitted by SPUS
// int     nb_raw_spu_red  1     Number of raw channels transmitted by SPUL
// int     glitch_det      1     Glitch detection; 0=on; 1=off
// int     ramp_fit_alg    1     Ramp fit algorithm [0=LstSq;1=mean value]
// int     filter          0     Desired FLTW position (0: ignore FLTW)
//                 
//
// Description   : Calls successively:                
//                - SPEC_cre_setup: generic setup of detectors for AOT
//                - SPEC_spu_setup: generic AOT setup of SPU  
//                - SPEC_fltw_move: Move FWSPEC to default position
//                - SPEC_MOV_CHOP_and_GRAT: Move chopper and grating to 
//                  default position
//
// Dependencies  : SPEC_fltw_move 
//                 SPEC_cre_setup
//                 SPEC_spu_setup
//                 SPEC_MOV_CHOP_and_GRAT
//
// Preconditions : 
//                 
// Comments      : This BB belongs to the 100 series (spectro)       
//
// Version       : 0.1  7-Oct-2004 Creation by DAC
// History       : 0.2 12-Oct-2004 Revised after revision of the used
//                 1.0  7-jun-2005 Adapted for SPEC_MEC_defalut table giving
//                                 filter position as {int}
//                 1.1 29-aug-2005 Added "whoCalledMe" to SpecSlewCal
//                 1.2  1-sep-2005 Added verbose
// procedures
//                 0.3 18-Oct-2004 Was SPEC_prologue; normalized variable names
//                 0.4 22-Oct-2004 Use new SPEC_cre_setup; cre_ctrl default
// is for capa_xx = 0, heater no longer handled by SPEC_cre_setup
// 1.0 22-Apr-2005 HF introduce mechanisms to default and 
//                 removed duplicate stop SPUs
// 1.1 10-May-2005 DAC Renamed HF's tables without ".txt"
//                 Removed spurious "delay()" at end of block (each called 
//                 module sets it own delay)
// 1.2 12-apr-2006 No longer moves FLTW
// 1.3  1-jun-2006 Reinstated FLTW using passed value (null means ignore
//                 FLTW logic)
// 1.4  6-dec-2006 Adapted for SPEC_fltw_move from ILT
// 1.5 27-jul-2009 BV SPR 1798 corrected biases
//              :
int[] block SPEC_aot_prologue_DataRates PACS 112 {
    int ramp_len_red = 64; // Red ramps' length
    int ramp_len_blu = 64; // Blue ramps' length
    double bias_d_red = 0.042 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_red = 0.011 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.1 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_r_blu = 0.011 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    int capa_red = 0; // Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
    int capa_blu = 0; // Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 64; // Number of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Number of red samples per sub-ramp
    int nb_raw_spu_blu = 1; // Number of raw channels transmitted by SPUS
    int nb_raw_spu_red = 1; // Number of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0; // Ramp fit algorithm [0:LstSq;1:MeanVal]
    int filter = 0; // Desired FLTW position (0: ignore filter)
    bool verbose = true;
}{
    // Register start of BB
    WriteBBID($BBID);
    // before SPU started: set data_rate
    data_rate(120.0);
    // Define the elements of time_array
    int duree_sec = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    // Accumulated duree [milliseconds]
    int duree_msec = 0;
    // Perform SPEC_cre_setup.
    // NOTE: capa_xxx is added to cre_ctrl_xx within SPEC_cre_setup
    int cre_ctrl_red = 386;
    int cre_ctrl_blu = 386;
    int duree2 = SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    duree_msec = duree_msec + duree2;
    if(verbose) {
        debug_print("duree of SPEC_cre_setup: " + duree2);
    }
    // Perform SPEC_spu_setup, starting SPU
    bool startSPU = true;
    int duree3 = 0;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    duree_msec = duree_msec + duree3;
    // Position filter wheel at desired position
    // Look up table order <=> telecommand ENG parameter
    string[] fltPOS = ["N/A","NoFilter","POS B","POS A"];
    // Command only for filter 2 or 3
    if(filter == 2 || filter == 3) {
        string fw_posENG = fltPOS[filter];
        int duree4 = SPEC_fltw_move(fw_posENG);
        //    WARNING! SPEC_fltw_move returns its duration in [sec]   
        duree_msec = duree_msec + 1000 * duree4;
        if(verbose) {
            debug_print("SPEC_aot_prologue turns FLTW to " + fw_posENG);
        }
    }
    // Position chopper and grating at their default positions
    int chop_pos = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    int grat_pos = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    if(verbose) {
        debug_print("Moving CHOP and GRAT to positions: " + chop_pos + ", " + grat_pos);
    }
    int[] duree5 = SPEC_MOV_CHOP_and_GRAT(chop_pos,grat_pos);
    duree_msec = duree_msec + duree5[0];
    // Total time is now computed including TC rate
    duree_sec = time() - time_start;
    // All the time spent here is OVR
    duree_OVR = duree_sec;
    // Define time_array 
    int[] time_array = [duree_sec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // Report duration
    if(verbose) {
        debug_print("+++++ SPEC_aot_prologue: " + time_array);
    }
    // Return the array of times
    //Reset Block ID
    WriteEndBB();
    //Return time_array

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Missionphase  : PACS IST Chopper Day
//
// Purpose       : Switch-on/switch-off and enanle/disable test of chopper
//
// Author        : MN/HD
// CUSification  : MN/HD
// Arguments     :
//
// Description   : This script allows to insert a duration in seconds during
//                 which the chopper is switched-on and enabled. This is used
//                 to evaluate the
//                 stability of the chopper while selecting various chopper
//                 control parameters.
//
// Comments      :
//
// Version       : 4.0
// History       : 1.0 20-Mar-2007 initial version
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//		   2.0 05-Jul-2007 IST Chopper Day
//		   3.0 12-Nov-2007 edited for SVT/PV conformance
//		   4.0 -4-mar-2008 translated into PV script VDP
//
obs PacsEng_Chopper_EnDis_Test_ast300 {
    /* Needed variables to call PacsEng_Chopper_EnDis_Test_ast300                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Chopper_EnDis_Test_ast300                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Chopper_EnDis_Test_NoConf_ast300()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Chopper_EnDis_Test_NoConf_ast300();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

//
// $Id: PacsCal_Spec_Dark_CS_SequentialWarmUp.txt,v 1.1 2008/11/12 16:46:30 pierre Exp $
// Missionphase  : PACS FM IST SOVT2 & PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : PACS Dark Measurement
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version	: 1.0
// History       : 1.0  16-Nov-2008  PR
//	 1.1   23-Jul-2009 Modified SPU parameters -> slope fit + flight biases
//
obs PacsCal_Spec_Dark_CS_SequentialWarmUp {
    /* Needed variables to call PacsCal_Spec_CS_SequentialWarmUp */
    int obs_time = 540; // Observing time per CS/FW/Grating setting
    int chop_time = 180; // Chopper plateau [sec] during CS temp rise time (0 = no chopping)
    /* POINTING PARAMETERS */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    /* End of needed variables for PacsEng_Spec_CS_SequentialWarmUp */
}{
    debug_print("obs PacsCal_Spec_Dark_CS_SequentialWarmUp. Version 1.0. 20081116");
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    int tslewmin = 0;
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Dark_CS_SequentialWarmUp(obs_time,chop_time)));
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    debug_print("ts: " + ts);
    //
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Dark_CS_SequentialWarmUp(obs_time,chop_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsSpecRMS.txt,v 1.30 2007/10/26 15:40:39 dcesarsk Exp $
// Purpose       : 
//
// CUS author    : 
// Script file   : PacsSpecRMS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// tuple bigTuple 
//{{string,double[],double[],double[],double[]},
// {string,double[],double[],double[],double[]},
// {string,double[],double[],double[],double[]}}[]
//
// Each bigTuple's line is of the form "noiseArray"
//  {IDstring, noise array, wave array, CONT noise array, LINE noise array} 
//
// Description   : Computes expected RMS fluctuations given observing
// parameters, described by infoArray. For LineSpec use wave (in infoArray)
// at face value. For RangeSpec create a RMS vs Wave table from waveStart
// to waveEnd, sampled every sampRate [mic] and report max and min RMS in
// the interval. It is assumed that waveXX in infoArray is compatible with
// the wave range of table SPECnoise
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1  2-Sep-2005 DAC
// 0.2 28-sep-2005 Added one more element to infoArray 
// 0.3 26-apr-2006 Use new table from AlPog
//                 Get max/min parameters for CONT and LINE
//                 Array noiseWave contains CONT and LINE information
// 0.4 11-may-2006   - stepSize may be negative; use abs()
// 0.4.1 12-sep-2006 - reduced RMS step size to reduce size of interpolation
//                     table (reduced run time from 8 sec to less than 2 sec)
//                     (SPR-2324)
// 0.5   22-nov-2006 Removed debug_print
// 1.0   22-jan-2007 Fixed SPR-2521 (too low initial rmsC,rmsL)
// 2.0   26-jan-2007 After much discussions, count the WAIT=1 as a
//                   bonafide SKY readout (this is done in PacsLineSpec
//                   and PacsRangeSpec)
//                   Correct handling of FreqSwitch (I hope...)
//                   Dithering count per SPR-2841 (smallSrcDither)
// 2.1   14-feb-2007 Logic to deal with waveRef; added rangesEXT containing
//                   refWave; added aotID
//                   Solved SPR-2838 (use min(6800/stepSize,nbSteps)
//                   Use grating width as per order
//                   Generate messages explaining data obtained in order
//                   other than demanded order
// 2.2 26-feb-2007 Added orderSel from HSPOT
// 2.3 10-mar-2007 OrderSel includes now sed mode
// 3.0 13-mar-2007 Use bigTuple to convey plot data to HSPOT
// 3.1 16-apr-2007 Modify to access the correspondig SPECcontline table
// 4.0 25-apr-2007 Redefine ranges as defined by HSPOT
// 4.1  8-may-2007 SPR-3182: bound "free" data to band limits
// 4.2 10-may-2007 SPR-3186: Raster/wOFF repeat count
// 5.0 30-may-2007 SPR-3251: Simplified "extra" data logic
// 5.1 13-jun-2007 SPR-3307 Fewer decimals for "Info for line"
// 6.0 21-aug-2007 SPR-3505 Out-of-range interpolation (more on extra data
//                          logic)
// 6.1 23-oct-2007 Added obsType in call to PacsSpecAuxRMS 
// 6.2 24-oct-2007 Get nbOBS and nbOFF from caller
//                 Added above to PacsSpecAuxRMS
// 6.3  4-jun-2009 DAC Adapted FreqSwitch message to ABBA case
// 6.3.1 5-jun-2009 DAC Finer tuning due to changed confOBCP contents
// 7.0 01-dec-2009 VD SCR PHS-1272
// 8.0 07-dec-2009 VD PHS-1282
// 9.0 18-jan-2010 VD PHS-1285 SED only!
// 10.0 21-jan-2010 VD PHS-1302
// 11.0 08-feb-2010 VD PHS-1308 WS needs nbNods to be taken into account
// 12.0 09-feb-2010 VD PHS-1320 !! SED infoArray size == 1 BUT nbRanges >= 1
// 13.0 19-mar-2010 VD PHS-1369 !! R1 range vs ref Wave in B's !!
//                              modify input Params in SpecAuxRMS_tmp to accpet orderSel as indicator for filter A 
// 14.0 21-apr-2010 VD PHS-1385 : it is NOT WS.... it is chopNod without NOD
// 15.0 28-apr-2010 VD PHS-1388 rasterNoOff instead of rasterOff 
// 16.0 03-may-2010 VD PHS-1393 order23 indeed
// 17.0 05-may-2010 VD PHS-1385 cont'd
// 
{{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] procedure PacsSpecRMS_4unchop {
    /* aotID                                                                  */
    string aotID = "RANGE" in ["RANGE","LINE"];
    /* orderSel                                                               */
    string orderSel = "order2";
    /* infoArray tuple (for SLEW,OBS,AOT and per wavelength)                  */
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}]; // Tuple from Obs module
    /* rangeSPOT (the sorted version)                                         */
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [{"",0.0,0.0,0,0.0,0.0,0.0,"","",0.0}];
    /* Grating dithering */
    {double,double}[] infoRangeSed = [{0.0,0.0}];
    /* confOBCP (per wavelength)                                              */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* nbOBS and nbOFF                                                         */
    int nbOBS = 1;
    int nbOFF = 0;
    int[] gratScanObsTime = [1];
    bool verbose = false;
}{
    // Data used here is to be found in
    // infoArray[1]{0}{0}   : PointReq information (ex. SmSrcDither, RasterOFF)
    // infoArray[1]{0}{3}   : Number of lines to be observed
    // infoArray[1]{0}{1}   : Integration time per plateau
    // infoArray[1]{0}{4}   : Number of nod cycles
    // infoArray[1]{1}[]{0} : Starting wave for line []
    // infoArray[1]{1}[]{1} : Ending wave for line []
    // infoArray[1]{1}[]{2} : Grating order for line []
    // infoArray[1]{1}[]{3} : Grating step for line []
    // infoArray[1]{1}[]{4} : Number of grating steps for line []
    // infoArray[2]{0}{0}   : OBCP information (ex. FreqSwitch)
    // infoArray[2]{0}{3}   : Raster "m" size
    // infoArray[2]{0}{4}   : Raster "n" size
    // infoArray[2]{0}{5}   : Raster repeat factor in raster/wOFF
    // confOBCP[]{0}        : Number up/down, nb SRC/CS in FreqSwitch for line []
    // confOBCP[]{3}        : Number SRC/REF for line []
    // confOBCP[]{4}        : Number readouts-ramps/plateau for line []
    // confOBCP[]{7}        : Dither count (FreqSwitch) for line []
    // Define return array
    // Array noiseWave[nbLines][8] used to contain: 
    //    noiseWave[lineNb][BwlC,BrC,WwlC,WrC,BwlL,BrL,WwlL,WrL]
    // where B: best, W: worst, wl: wavelength, r: RMS, C: continuum, L: line
    // Will add three more elements refWave, rmsCont, rmsLine (RANGE)
    // NOTE: NoiseWave is no longer used; its content is now in 1st
    //       array of tuple noiseArrayx 
    // Define tuples to be used below
    // Each noiseArray contains
    // - string arrayID
    // - double[] "noiseWave" (the "historical" noiseWave)
    // - double[] wave array
    // - double[] CONT noise
    // - double[] LINE noise
    {string,double[],double[],double[],double[]} noiseArray0 = {"undefined",[0.0],[0.0],[0.0],[0.0]};
    {string,double[],double[],double[],double[]} noiseArray1 = {"undefined",[0.0],[0.0],[0.0],[0.0]};
    {string,double[],double[],double[],double[]} noiseArray2 = {"undefined",[0.0],[0.0],[0.0],[0.0]};
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = [{noiseArray0,noiseArray1,noiseArray2}];
    // Number of lines observed
    if(orderSel == "sedb2b" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        int nbLines = 1;
    } else {
        nbLines = infoArray[1]{0}{3};
    }
    // The logic to estimate the data one gets for free (there are two arrays)
    // needs to know whether the current observations are performed with filter
    // "POS A" or "POS B" (fltPos=3 or fltPos=2). Only HSPOT knows this...
    int fltPos = 0;
    if(orderSel == "order2" || orderSel == "sed2" || orderSel == "sedb2b") {
        fltPos = 2;
    }
    if(orderSel == "order3" || orderSel == "order23" || orderSel == "sed3" || orderSel == "sed4" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        fltPos = 3;
    }
    ///////////////// Per line loop //////////////////////////////
    for(int loop0 = 0 .. nbLines - 1) {
        //   Just for checks during script development
        if(verbose) {
            debug_print("RMS:PointReq: " + infoArray[1]{0}{0});
            debug_print("RMS:OBCP    : " + infoArray[2]{0}{0});
            debug_print("RMS:Wave from:to " + infoArray[1]{1}[loop0]{0} + ":" + infoArray[1]{1}[loop0]{1} + " [mic]");
            debug_print("RMS:Grat Order/StepSize/NbSteps " + infoArray[1]{1}[loop0]{2} + "/" + infoArray[1]{1}[loop0]{3} + "/" + infoArray[1]{1}[loop0]{4});
        }
        // Next section deals with estimating the "on-sky" time per resolution element
        // and per (same) sky area
        // Spectral lines can be seen several times as they move across the 
        // "wavelength" pixels
        // How many times a line feature has been seen
        // Get actual grating width (i.e. nbSteps = 16 pixels)
        string key = "" + infoArray[1]{1}[loop0]{2};
        double gratWidth = double(ilookup("SPEC_BAND_params",key,"GRAT_WDTH"));
        if(verbose) {
            debug_print("RMS:GratWdth: " + gratWidth + " steps");
        }
        // In FreqSwitch mode the parameters are somehow different 
        // Useful variable for freqSwitch
        bool freqSwitch = false;
        bool stare = false;
        debug_print("infoArray: " + infoArray[2]{0}{0});
        if(infoArray[2]{0}{0} == "FreqSwitch" || infoArray[2]{0}{0} == "GratScanNoChop") {
            freqSwitch = true;
        }
        if(infoArray[2]{0}{0} == "RangeSpec") {
            if(infoArray[1]{0}{0} == "RasterNoOFF") {
                stare = true;
            }
        } else {
            if(!freqSwitch && infoArray[2]{0}{0} == "GratScanNoChop") {
                stare = true;
            }
        }
        //      howMany is the number of times the given wavelength is seen by other pixels other
        // //no stare
        if(freqSwitch) {
            double howMany = 1.0;
        } else {
            //          Case of step size=0 (PV single grating AOT)
            howMany = gratWidth / (0.01 + abs(double(infoArray[1]{1}[loop0]{3})));
            //          SPR-2838: howMany cannot be larger than the number of grating steps
            if(howMany > double(infoArray[1]{1}[loop0]{4})) {
                howMany = double(infoArray[1]{1}[loop0]{4});
                if(verbose) {
                    debug_print("RMS:Reduced howMany to NbSteps");
                }
            }
        }
        // Integration time not considering spatial redundancy - i.e. seeing again the source during
        // a scan - nor wavelength redundancy - i.e. the same wavelength seen by other pixels at any grating
        // position) 
        //      intTimePlateau x NbSrcRef x howMany x nbNods x 2*up_dn x dithCount x Nbrepeat
        //      Number of nods (OBS)
        int nbNodCycles = infoArray[1]{0}{4};
        //      Nb of "pointings" for nbNodCycles
        int nbNods = 2 * nbNodCycles;
        if(nbNods == 0) {
            nbNods = 1;
        }
        int nbUpDn = 2 * confOBCP[loop0 + 1]{0};
        //      In FreqSwtch, below counts the number of SRC-CS cycles  
        int nbSRC_REF = confOBCP[loop0 + 1]{3};
        //      dithCntFreqSwtch introduced for FreqSwitch, otherwise is unity
        int dithCntFreqSwtch = 1;
        //      dithCntSmSrc introduced for small source w/dithering, otherwise is unity
        int dithCntSmSrc = 1;
        if(infoArray[1]{0}{0} == "SmSrcDither") {
            //          The source is seen at each of the m X n raster points
            int m = infoArray[2]{0}{3};
            int n = infoArray[2]{0}{4};
            dithCntSmSrc = m * n;
        }
        //      In FreqSwitch mode the parameters are somehow different
        // no stare
        if(freqSwitch) {
            //          confOBCP{0} counts the number of Up/Dn ABBA-ABBA cycles (P1UpDn)
            nbUpDn = confOBCP[loop0 + 1]{0};
            //          confOBCP{2} counts the number of ABBA setings (P4ABBA)
            int nbABBA = confOBCP[loop0 + 1]{2};
            //          The line is always in sight (Line Ref Ref Line) since Ref is Line displaced
            //          by a few pixels. Hence line is seen 4 times (see singleIntTime below)
            //          The ABBA loop is repeated dithCntFreqSwtch times
            dithCntFreqSwtch = confOBCP[loop0 + 1]{7};
            if(verbose) {
                debug_print("dithCntFreqSwitch: " + dithCntFreqSwtch);
            }
        }
        //      If Raster/w OFF, take into account the number of repetions
        int nbRepeat = 1;
        if(infoArray[1]{0}{0} == "RasterNoOFF" || stare) {
            nbRepeat = infoArray[2]{0}{5};
        } else {
            if(orderSel == "sedb2b" || orderSel == "sedb2a" || orderSel == "sedb3a") {
                nbRepeat = length(infoRangeSed);
            }
        }
        //      infoArray[1]{0}{1} is the integration time per plateau
        double singleIntTime = double(nbSRC_REF * nbNods * nbUpDn * nbRepeat) * infoArray[1]{0}{1};
        if(stare) {
            singleIntTime = double(nbUpDn * nbNods * nbRepeat) * infoArray[1]{0}{1};
            if(verbose) {
                debug_print("I am  here:");
                debug_print("nbUpDn: " + nbUpDn);
                debug_print("nbNods: " + nbNods);
                debug_print("nbRepeat: " + nbRepeat);
            }
        }
        //      Another special case
        // added nbNodCycles (no nods) as needs PHS-1308
        // //no stare
        if(freqSwitch) {
            singleIntTime = double(2 * nbUpDn * dithCntFreqSwtch * nbABBA * 4 * nbNodCycles) * infoArray[1]{0}{1};
            if(verbose) {
                debug_print("nbUpDn: " + nbUpDn + " / nbABBA: " + nbABBA + " / infoArray: " + infoArray[1]{0}{1});
                debug_print("singleIntTime switch: " + singleIntTime);
            }
        }
        double intTime = double(dithCntSmSrc) * howMany * singleIntTime;
        // Another exception for scan mode
        if(infoArray[1]{0}{0} == "ScanChopNoNod") {
            intTime = infoArray[1]{0}{1};
        }
        //   Wavelength span (needed below, but useful here for message)
        double span = abs(infoArray[1]{1}[loop0]{0} - infoArray[1]{1}[loop0]{1});
        //   Logic to show "extra" data, i.e. at different order than demanded
        //   - If observing in order=1 (with 2), the user gets for free order=2 data 
        //   - If observing in order=1 (with 3), the user gets for free some order=3 
        //     data if lambda>167 microns AND the short  wavelength part of order=2 
        //     (which falls inside POS B bandpass) if lambda < 142. For lambda 
        //     167 < lambda < 142, there is no "free" data
        //   - If observing at order=2 or order=3, user gets for free order=1
        //
        //   Try to code all this.. Current logic is as follows:
        //   For each Order/Filter combination see if the expected extra data is
        //   entirely out of filter bandpass. If yes, then there is no extra data; else
        //   place extra data within filter bandpass
        //   Current line is being observed at order
        int currOrder = infoArray[1]{1}[loop0]{2};
        //   Code currOrder as orderN
        string orderCurr = "order" + currOrder;
        // "sed4" is a special case
        if(orderSel == "sed4" || orderSel == "sedb2a") {
            orderCurr = "order23";
        }
        //   Nominal and extra data will be labeled with arrayID
        string arrayID = "ToBeFilledBelow";
        //   Order 1 needs no filter... so we always see data in order 1. What other
        //   order do we see (where is filter?)
        //
        //   Useful variables: low and high user defined range
        double loLam = infoArray[1]{1}[loop0]{0};
        double hiLam = infoArray[1]{1}[loop0]{1};
        // Get boundaries of filters
        double loLam1 = dlookup("SPEC_BAND_params","1","BLU");
        double hiLam1 = dlookup("SPEC_BAND_params","1","RED");
        double loLam2 = dlookup("SPEC_BAND_params","2","BLU");
        double hiLam2 = dlookup("SPEC_BAND_params","2","RED");
        double loLam23 = dlookup("SPEC_BAND_params","23","BLU");
        double hiLam23 = dlookup("SPEC_BAND_params","23","RED");
        double loLam3 = dlookup("SPEC_BAND_params","3","BLU");
        double hiLam3 = dlookup("SPEC_BAND_params","3","RED");
        // SPR-3251 Completely new logic
        //
        // Define "cross over" wavelengths, i.e. wavelength in order1 such that 2nd 
        // order falls outside filter B into filter A
        double wave1into2 = 2.0 * loLam2;
        // and 1st order grating position corresponds to in-band 3rd order
        double wave1into3 = 3.0 * loLam3;
        // Following logic creates "extra" data, i.e. data user gets for "free"
        // Data labeled xSomething is regular order seen with tje corresponding
        // filter (i.e. 2nd with filter B; 3rd with filter A)
        // Data labeled xxSomething is short wavelength 2nd order seen with 3rd
        // order filter; the so called "extended" emission 
        // Null arrays imply there is no "free" data
        double xWaveLO = 0.0;
        double xWaveHI = 0.0;
        double xxWaveLO = 0.0;
        double xxWaveHI = 0.0;
        // Order 1 scanning is the most complex since the "free" data depends on filter
        // position
        if(currOrder == 1) {
            // Filter at POS B
            if(fltPos == 2) {
                arrayID = "order2";
                // When filter is at order 2 (POS B), all order=1 grating steps
                // map to visible order=2 wavelengths, except 
                //  - hiLam shorter than wave1into2 (range is too "blue")
                //  - loLam greater than 2*hiLam2   (range is too "red")
                if(hiLam <= wave1into2 || loLam >= 2.0 * hiLam2) {
                    //               Whole band is outside filter B
                    xWaveLO = 0.0;
                    xWaveHI = 0.0;
                } else {
                    arrayID = "order2";
                    //               A priori we see 1/2 wavelength
                    xWaveLO = loLam / 2.0;
                    xWaveHI = hiLam / 2.0;
                    //               But within bandpass limits
                    if(xWaveHI > hiLam2) {
                        xWaveHI = hiLam2;
                    }
                    if(xWaveLO < loLam2) {
                        xWaveLO = loLam2;
                    }
                }
            }
            // Filter at POS A
            //       This is the most complex case since we may also see order 2 light
            if(fltPos == 3) {
                if(orderCurr == "order23") {
                    arrayID = "order23";
                } else {
                    arrayID = "order3";
                }
                // Short wave filter (order 3, POS A), some order=1 grating steps
                // map to "visible" order=2 wavelengths, except 
                // - hiLam shorter than 2*loLam23 (range is too "blue")
                // - loLam greater than 2*hiLam23 (range is too "red")
                if(hiLam <= 2.0 * loLam23 || loLam >= 2.0 * hiLam23) {
                    // Whole band is outside filter A bandpass
                    xxWaveLO = 0.0;
                    xxWaveHI = 0.0;
                } else {
                    // Short wave second order
                    xxWaveLO = loLam / 2.0;
                    xxWaveHI = hiLam / 2.0;
                    // But within "extended" bandpass limits 
                    // SPR-3505: corrected band boundaries:xxLam3 should be xxLam23
                    if(xxWaveHI > hiLam23) {
                        xxWaveHI = hiLam23;
                    }
                    if(xxWaveLO < loLam23) {
                        xxWaveLO = loLam23;
                    }
                }
                // Some order=1 grating steps map to "visible" order=3 wavelengths, except 
                // - hiLam shorter than wave1into3 (range is too "blue")
                // - loLam greater than 3*hiLam3   (range is too "red")
                if(hiLam <= 3.0 * loLam3 || loLam >= 3.0 * hiLam3) {
                    // Whole band is outside filter A
                    xWaveLO = 0.0;
                    xWaveHI = 0.0;
                } else {
                    // Short wave 3rd order
                    xWaveLO = loLam / 3.0;
                    xWaveHI = hiLam / 3.0;
                    // But within bandpass limits
                    if(xWaveHI > hiLam3) {
                        xWaveHI = hiLam3;
                    }
                    if(xWaveLO < loLam3) {
                        xWaveLO = loLam3;
                    }
                }
            }
        }
        //   When grating scans within order 2 and 3 ranges, all steps map to visible
        //   lines at order 1
        //   If we are in order=2 we see order=1 for free
        // PHS-1285 Here comes in infoRangeSed and grating positions to "dither red free range"
        string xRan = "";
        if(currOrder == 2) {
            arrayID = "order1";
            if(orderSel == "sedb2b") {
                // keeping xRan for history
                xRan = "b2bLR1";
                xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                // xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
            } else {
                if(orderSel == "sedb2a") {
                    xRan = "b2aSR1";
                    xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                    //	       xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                    xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                } else {
                    if(orderSel == "sedb3a") {
                        xRan = "b3aLR1";
                        xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                        //		  xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                        xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                    } else {
                        xWaveLO = 2.0 * loLam;
                        xWaveHI = 2.0 * hiLam;
                    }
                }
            }
            //      It may fall completely outside bandpass	
            if(xWaveLO >= hiLam1) {
                xWaveLO = 0.0;
                xWaveHI = 0.0;
            } else {
                //          Within filter boundaries
                if(xWaveHI > hiLam1) {
                    xWaveHI = hiLam1;
                }
                if(xWaveLO < loLam1) {
                    xWaveLO = loLam1;
                }
            }
        }
        //   If we are in order=3 we alse see order=1 for free
        if(currOrder == 3) {
            arrayID = "order1";
            if(orderSel == "sedb2b") {
                xRan = "b2bLR1";
                xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                //	    xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
            } else {
                if(orderSel == "sedb2a") {
                    xRan = "b2aSR1";
                    xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                    //	       xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                    xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                } else {
                    if(orderSel == "sedb3a") {
                        xRan = "b3aLR1";
                        xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                        //		  xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                        xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                    } else {
                        xWaveLO = 3.0 * loLam;
                        xWaveHI = 3.0 * hiLam;
                    }
                }
            }
            //      It may fall completely outside bandpass	
            if(xWaveLO >= hiLam1) {
                xWaveLO = 0.0;
                xWaveHI = 0.0;
            } else {
                //          Within filter boundaries
                if(xWaveHI > hiLam1) {
                    xWaveHI = hiLam1;
                }
                if(xWaveLO < loLam1) {
                    xWaveLO = loLam1;
                }
            }
        }
        if(currOrder == 23) {
            arrayID = "order1";
            if(orderSel == "sedb2b") {
                xRan = "b2bLR1";
                xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                //	    xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
            } else {
                if(orderSel == "sedb2a") {
                    xRan = "b2aSR1";
                    xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                    //	       xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                    xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                } else {
                    if(orderSel == "sedb3a") {
                        xRan = "b3aLR1";
                        xWaveLO = interpolate("SPEC_grat_wl_R1","wave",infoRangeSed[loop0]{0});
                        //		  xWaveLO = dlookup("SPEC_BAND_params",xRan,"BLU");
                        xWaveHI = dlookup("SPEC_BAND_params",xRan,"RED");
                    } else {
                        xWaveLO = 2.0 * loLam;
                        xWaveHI = 2.0 * hiLam;
                    }
                }
            }
            //      It may fall completely outside bandpass	
            if(xWaveLO >= hiLam1) {
                xWaveLO = 0.0;
                xWaveHI = 0.0;
            } else {
                //          Within filter boundaries
                if(xWaveHI > hiLam1) {
                    xWaveHI = hiLam1;
                }
                if(xWaveLO < loLam1) {
                    xWaveLO = loLam1;
                }
            }
        }
        if(verbose) {
            debug_print("RMS:current order: " + currOrder);
            debug_print("RMS:fltPos: " + fltPos);
            debug_print("RMS:LoLam: " + loLam);
            debug_print("RMS:HiLam: " + hiLam);
            debug_print("RMS:ExtraLoLam: " + xWaveLO);
            debug_print("RMS:ExtraHiLam: " + xWaveHI);
            debug_print("RMS:ExxtraLoLam: " + xxWaveLO);
            debug_print("RMS:ExxtraHiLam: " + xxWaveHI);
            debug_print("RMS:Integration/plateau: " + infoArray[1]{0}{1} + " [sec]");
            debug_print("RMS:NbSRC_REF: " + nbSRC_REF + " times");
            debug_print("RMS:ditherCount (freqSwitch): " + dithCntFreqSwtch + " times");
            debug_print("RMS:ditherCount (small srce): " + dithCntSmSrc + " times");
            debug_print("RMS:NbUpDn/NbNods: " + nbUpDn + "/" + nbNods);
            debug_print("RMS:NbRepeat: " + nbRepeat);
            debug_print("RMS:intTime (one freq. switch, no dither) " + singleIntTime + " [sec]");
            debug_print("RMS:Wavelength span: " + dformat(span,2) + " [mic]");
            debug_print("RMS:Feature seen  " + howMany + " times");
            debug_print("RMS:Time for RMS estimate: " + intTime + " [sec]");
            debug_print("RMS:SRC/REF " + infoArray[1]{1}[loop0]{6} + "/" + infoArray[1]{1}[loop0]{7} + " [sec]");
        }
        bool superbla = true;
        if(superbla) {
            if(aotID == "RANGE") {
                message("<h3> Info for range " + infoArray[1]{1}[loop0]{0} + "/" + infoArray[1]{1}[loop0]{1} + " [&micro;m]</h3>");
            } else {
                message("<h3> Info for line " + dformat(infoArray[1]{1}[loop0]{0},2) + " [&micro;m]</h3>");
            }
            message("<ul><li>PointReq: " + infoArray[1]{0}{0} + "</li>");
            message("<li>OBCP    : " + infoArray[2]{0}{0} + "</li>");
            //      Next messages only for RANGE
            if(aotID == "RANGE") {
                message("<li>Wave from-to " + infoArray[1]{1}[loop0]{0} + "-" + infoArray[1]{1}[loop0]{1} + " [&micro;m]</li>");
                //         message("<li>Wavelength span: " + dformat(span,2) + " [&micro;m]</li>");
                //         Messages for "free" data
                if(xWaveLO != 0.0) {
                    message("<li><b>Free! </b> Your data will include wavelengths between " + dformat(xWaveLO,2) + " and " + dformat(xWaveHI,2));
                }
                if(xxWaveLO != 0.0) {
                    message("<li><b>Free! </b> Your data will include wavelengths between " + dformat(xxWaveLO,2) + " and " + dformat(xxWaveHI,2));
                }
            }
            if(freqSwitch) {
                message("<li>ABBA freqSwitch at grating order: " + infoArray[1]{1}[loop0]{2} + "</li>");
                message("<li>FreqSwitch dither: " + dithCntFreqSwtch + " wavelength steps</li>");
            } else {
                message("<li>Grat Order/StepSize/NbSteps " + infoArray[1]{1}[loop0]{2} + "/" + infoArray[1]{1}[loop0]{3} + "/" + infoArray[1]{1}[loop0]{4} + "</li>");
                message("<li>NbSRC_REF: " + nbSRC_REF + " times</li>");
                message("<li>Spatial redundancy only for SmallSrc: " + dithCntSmSrc + " time(s)</li>");
            }
            message("<li>Number ramps/plateau (after synch): " + confOBCP[loop0 + 1]{4} + "</li>");
            message("<li>Integration time/plateau: " + dformat(infoArray[1]{0}{1},2) + " [sec]</li>");
            if(freqSwitch) {
                message("<li>Up/Dn ABBA loops/ABBA sets per loop: " + nbUpDn + "/" + nbABBA + "</li>");
            } else {
                message("<li>NbUpDn/NbNods/NbRepeat: " + nbUpDn + "/" + nbNods + "/" + nbRepeat + "</li>");
            }
            message("<li>Integration time per spectral and/or spatial resolution element::  " + dformat(singleIntTime,1) + " [sec]</li>");
            message("<li>Feature seen " + dformat(howMany,1) + " times (due to spatial or wavelength redundancy)</li>");
            message("<li>Integration time used to estimate RMS: " + dformat(intTime,1) + " [sec]</li>");
            message("<li>Global SRC/REF exposure: " + infoArray[1]{1}[loop0]{6} + "/" + infoArray[1]{1}[loop0]{7} + " [sec]</li></ul>");
        }
        //
        // We have now up to three wavelength ranges:
        // - nominal (user defined)        [loLam to hiLam]
        // - one "free" data array         [xWaveLO to xWaveHI]
        // - perhaps a 3rd "free" array    [xxWaveLO to xxWaveHI]
        //
        //   The reference wavelength
        if(aotID == "RANGE") {
            double waveRef = rangeSPOT[loop0]{9};
        }
        if(aotID == "LINE") {
            waveRef = infoArray[1]{1}[loop0]{0};
        }
        //   Create a table RMS vs Wave consisting of nbSamples entries
        //
        //   Create Wave arrays (remember we are inside the nbLines loop!!)
        //   Obs type for AuxRMS
        string obsType = "any";
        if(aotID == "RANGE") {
            // attention function of waveRef
            //	 if(orderSel == "sedb2b" || orderSel == "sedb2a" || orderSel == "sedb3a") {
            //	    if(waveRef >= 103.1) {
            //	       double[] waveArray = PacsSpecWaveArray(xWaveLO,xWaveHI,verbose);
            //	    } else {
            //	       waveArray = PacsSpecWaveArray(loLam,hiLam,verbose);
            //	    }
            //	 } else {
            double[] waveArray = PacsSpecWaveArray(loLam,hiLam,verbose);
            //	 }
            //        Given wavelengths are always "nominal"
            noiseArray0 = PacsSpecAuxRMS_4unchop(aotID,orderCurr,orderSel,waveArray,waveRef,intTime,obsType,nbOBS,nbOFF,gratScanObsTime[loop0],verbose);
            //      Null Wave arrays have xWaveLO = 0.0
            if(xWaveLO > 10.0) {
                waveArray = PacsSpecWaveArray(xWaveLO,xWaveHI,verbose);
                ///        if (verbose){debug_print("RMS:xWaveArray: " + waveArray);}
                //        xWave array comes from arrayID source; define waveRefX
                double waveRefX = (xWaveLO + xWaveHI) / 2.0;
                noiseArray1 = PacsSpecAuxRMS_4unchop(aotID,arrayID,orderSel,waveArray,waveRefX,intTime,obsType,nbOBS,nbOFF,gratScanObsTime[loop0],verbose);
            }
            //      Null Wave arrays have xxWaveLO = 0.0
            if(xxWaveLO > 10.0) {
                //        xxWave array is always 2nd order, but special since it
                //        overlaps with 3rd order. Identify as order23 (order 2 overlapping
                //        with order 3)
                waveArray = PacsSpecWaveArray(xxWaveLO,xxWaveHI,verbose);
                ///          if (verbose){debug_print("RMS:xxWaveArray: " + waveArray);}
                waveRefX = (xxWaveLO + xxWaveHI) / 2.0;
                noiseArray2 = PacsSpecAuxRMS_4unchop(aotID,"order23",orderSel,waveArray,waveRefX,intTime,obsType,nbOBS,nbOFF,gratScanObsTime[loop0],verbose);
            }
        }
        if(aotID == "LINE") {
            waveArray = [infoArray[1]{1}[loop0]{0}];
            //      Identify FreqSwitch
            obsType = infoArray[2]{0}{0};
            noiseArray0 = PacsSpecAuxRMS_4unchop(aotID,orderCurr,orderSel,waveArray,waveRef,intTime,obsType,nbOBS,nbOFF,gratScanObsTime[loop0],verbose);
        }
        // For memory: bigTuple is thus defined
        //  {{string,double[],double[],double[],double[]},
        //   {string,double[],double[],double[],double[]},
        //   {string,double[],double[],double[],double[]}}[]
        //   bigTuple = [{noiseArray0, noiseArray1,noiseArray2}];
        bigTuple[loop0] = {noiseArray0,noiseArray1,noiseArray2};
        // End of nbLines loop
        //   Zero the noiseArrays (a null value is used elsewhere to assert there
        //   are no "free" ranges)
        noiseArray0 = {"",[0.0],[0.0],[0.0],[0.0]};
        noiseArray1 = {"",[0.0],[0.0],[0.0],[0.0]};
        noiseArray2 = {"",[0.0],[0.0],[0.0],[0.0]};
    }

    return bigTuple;
}

// File          : PACS_Spec_CRE_Setup_Cold_HeI.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Configure CRE bias, reset interval and capacitor for 
//                 testing at room temperature
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
// Comments      : Intermediate version
//
// 
// Version       : 1.0
// History       : 1.0 / 24-Nov-2006 IBased on PACS_Spec_CRE_Setup_Cold
//                    1.1    7-mar-2006 SPEC_HEAT_1_C renamed
//                    1.2 10-apr-2006 Modified heater setting for FM 
//                    1.3 06-nov-2006 HF - Changed bias_r to 82
//                    1.4 13-nov-2005 Changed bias_r to 12
procedure PACS_Spec_CRE_Setup_Cold_HeI {
}{
    int red_reset = 64;
    int blue_reset = 64;
    int red_bias_d = 4;
    int red_bias_r = 12;
    int blue_bias_d = 4;
    int blue_bias_r = 12;
    int red_capacitor = 0;
    int blue_capacitor = 0;
    int heater_blue = 0;
    // PC174420 "DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    //         Fixed GroupSize: 1, repetition: 8
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // cre_ctrl: 256=sync width=2, 128=T sensor on, 2=select, 1=power on
    int blue_cre_ctrl = blue_capacitor + 256 + 128 + 2 + 1;
    int[] list_int = [32,blue_reset,blue_cre_ctrl,blue_bias_r,blue_bias_d,0];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,blue_reset,blue_cre_ctrl,blue_bias_r,blue_bias_d,0,chksum);
    delay(1);
    // PC173420 "DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    //         Fixed GroupSize: 1, repetition: 8
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // cre_ctrl: 256=sync width=2, 128=T sensor on, 2=select, 1=power on
    // set red_cre_ctrl [expr $red_capacitor+256+128+2+1]
    // set spec_par_r [list {PP095420 32} \
    //         [list PP096420 $red_reset] \
    //         [list PP097420 $red_cre_ctrl] \
    //         [list PP098420 $red_bias_r] \
    //         [list PP099420 $red_bias_d] {PP100420 0}]
    // set chksum [getChkSum -d -32 $spec_par_r]
    // putlog "ChkSum for spec_par_r: $spec_par_r"
    int red_cre_ctrl = red_capacitor + 256 + 128 + 2 + 1;
    list_int = [32,red_reset,red_cre_ctrl,red_bias_r,red_bias_d,0];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,red_reset,red_cre_ctrl,red_bias_r,red_bias_d,0,chksum);
    delay(1);
    // PC094420 "DMC_SET_PAR_BOTH_SPEC" SEND COMPLETE PARAMETERS TABLE TO BOTH DECS
    // tcsend PC094420 
    // waittime 0.5
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    delay(1);
    // PC094420 "DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    //tcsend PC086420 
    //waittime 0.5
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // PC094420 "DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    //tcsend PC093420 
    //waittime 0.5
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    //  DMC_SET_B_SPE_HEAT_1C(0)
    // eval tcsend PC087420 [list [list PP073420 $heater_blue]]
    // waittime 0.5
    Pacs_DMC_SET_B_SPEC_HEAT_C_RAW(heater_blue);
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

// Missionphase  : FM ILT
//
// Purpose	:  Performance Test of internal PACS calibration sources
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description  : We start with a heat-up of the calibration sources. 
//                After monitoring for some while the behaviour on the desired temperature of
//                both internal PACS calibration sources, we do a smaller heat-up which is followed 
//                by a cooling down. The monitoring is based on diag. HK. 
//                PTD 0.7.11 and 0.7.12 are the basis for this test. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy 
//                 
// Comments	: This script is based on the commanding during the CQM ILT Tests. 
//
// Version	: 1.0	
// 
// History      : 
//		  1.0 09-11-06 HD. Adapted on FM ILT requirements.
//		  2.0 24-02-07 HD. Adapted for FM ILT.
block SPEC_CS_fmilt071112_switchoff_cs_bb PACS 477 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //Switchff and disabling CSs
    Pacs_DMC_DISABLE_BB_1_CONT();
    Pacs_DMC_SWOF_BB_1_CONT();
    Pacs_DMC_DISABLE_BB_2_CONT();
    Pacs_DMC_SWOF_BB_2_CONT();
    // Mark End of Block
    WriteEndBB();
}

// Missionphase  : 
//
// Purpose       : Read a BOLObias calibration table and command bias
//                 voltages for VH, VL, VRL and VH_BLIND group by group
//
// Author        : Koryo Okumura
// CUS script    : Koryo Okumura modified from PHOT_set_bias_volt.txt
// CVS file      : PHOT_change_bias_volt.cus
//
// Arguments     : 
// string  calTableName    The Cal table name, f.i. BOLObias or BOLOsafe
//
// Description   : Read VH, VL, VRL and VH_BLIND from a given Bias U-CAL
//                 tables in volts and command them
//
// Dependencies  : 
//
// Preconditions : The other biases should be alredy set by PHOT_set_bias
//                 or PHOT_set_bias_volt
//
// Comments      : This script is used especially in calibration purpose
//
// Version      : 1.0
// History       :
//  24-aug-2006 KO, First try
//  22-jul-2008 KO, Reformatted for CP, PV and operation phase
//  23-Mar-2009 KO, Debugging : SPU restart is now added in case setting changes
//
procedure PHOT_change_biases {
    string biasTable = "BOLObias_standard_high"; // Bias table [volts]
    string setting = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Readout mode
    string gain = "NO_CHANGE" in ["NO_CHANGE","LOW","HIGH"]; // Gain
}{
    int operand = 0;
    // Bias setting order
    string[] biasOrder = ["VH","VL","VRL","VH-BLIND"];
    // Introduce 1 sec delay after commanding each bias (not used)
    int waitFor = 1;
    for(int groupNb = 1 .. 6) {
        // Construct BiasGR entry
        string biasGR = "BiasGR" + groupNb;
        for(int index = 0 .. 3) {
            // Use lookup function; get BIAS voltage for given group and Bias number
            // For each BIAS defined in table and for the given group
            int biasNb = ilookup(biasTable,biasOrder[index],"Bias");
            double biasVolt = dlookup(biasTable,biasOrder[index],biasGR);
            //    Branch according to group number
            if(groupNb == 1) {
                PHOT_bias_group_1(groupNb,biasNb,biasOrder[index],biasVolt);
            }
            if(groupNb == 2) {
                PHOT_bias_group_2(groupNb,biasNb,biasOrder[index],biasVolt);
            }
            if(groupNb == 3) {
                PHOT_bias_group_3(groupNb,biasNb,biasOrder[index],biasVolt);
            }
            if(groupNb == 4) {
                PHOT_bias_group_4(groupNb,biasNb,biasOrder[index],biasVolt);
            }
            if(groupNb == 5) {
                PHOT_bias_group_5(groupNb,biasNb,biasOrder[index],biasVolt);
            }
            if(groupNb == 6) {
                PHOT_bias_group_6(groupNb,biasNb,biasOrder[index],biasVolt);
            }
        }
    }
    // Set the readout mode
    if(setting == "DIRECT") {
        //*********************************************************
        // Sequence mode : blocking on VDEC_X for the direct mode
        //*********************************************************
        //
        // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
        Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
        // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
        Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
        //
        //**********************************************************
        // Sequence mode : Sref_only (meaning set for the bolometer)
        //**********************************************************
        //
        // Stop SPU
        PACS_Phot_SPU_Reset();
        delay(1);
        // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
        //# P 09 01 00 01
        operand = 0x9010001;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
        // Start SPU with default photometry mode
        PACS_Phot_SPU_Setup();
        delay(1);
    }
    if(setting == "DDCS") {
        //************************************************************
        // Sequence mode : deblocking on VDECX-L for the DDCS mode
        //************************************************************
        //
        string[] paramName = ["VDECX-L","CKRLH"];
        for(int grpNb = 1 .. 6) {
            // Construct BiasGR entry
            biasGR = "BiasGR" + grpNb;
            for(int indx = 0 .. 1) {
                // Use lookup function; get BIAS voltage for given group and Bias number
                // For each BIAS defined in table and for the given group
                biasNb = ilookup(biasTable,paramName[indx],"Bias");
                biasVolt = dlookup(biasTable,paramName[indx],biasGR);
                //    Branch according to group number
                if(grpNb == 1) {
                    PHOT_bias_group_1(grpNb,biasNb,paramName[indx],biasVolt);
                }
                if(grpNb == 2) {
                    PHOT_bias_group_2(grpNb,biasNb,paramName[indx],biasVolt);
                }
                if(grpNb == 3) {
                    PHOT_bias_group_3(grpNb,biasNb,paramName[indx],biasVolt);
                }
                if(grpNb == 4) {
                    PHOT_bias_group_4(grpNb,biasNb,paramName[indx],biasVolt);
                }
                if(grpNb == 5) {
                    PHOT_bias_group_5(grpNb,biasNb,paramName[indx],biasVolt);
                }
                if(grpNb == 6) {
                    PHOT_bias_group_6(grpNb,biasNb,paramName[indx],biasVolt);
                }
            }
        }
        // Stop SPU
        PACS_Phot_SPU_Reset();
        delay(1);
        // Set seq mode Sbolo-Sref (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sbolo-Sref");
        //# P 09 01 00 00
        operand = 0x9010000;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
        // Start SPU with default photometry mode
        PACS_Phot_SPU_Setup();
        delay(1);
    }
    if(gain != "NO_CHANGE") {
        //**************************************
        // Start SPU in the appropriate setting
        // including bits rounding for high gain
        //**************************************
        PHOT_spu_gain_setup(gain,0,0,3,3,true);
        delay(1);
    }
    // to sync the bus
    sync();
}

// Script        : Pacs_Chopper_AutoOpt.txt
// Missionphase  : Commissioning
//
// Purpose	: Check a series of different chopper controller settings by
//                chopping between +/- 12000 units (~4 deg)
//                  
// Author	: Markus Nielbock/Helmut Dannerbauer
// CUS author 	: MN/HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-12000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions: PACS switched on and Chopper switched off.
//                 
// Comments	: This script is based on the commanding script
//                PACS_Chopper_uk_move_12000_OBS.cus
//
// Version	: 1.1
// 
// History 	: 1.0 20-Nov-2007 (MN) Script to do simple chopper cycle 
//         	  1.1 10-Mar-2008 (MN) adopted extended CUS naming conventions
//         	  1.2 19-May-2008 (MN) added +3 to all parameters (XHSPOT bug)
//
// Initialise input parameters:
// Defines control parameter range, loops run from k(p,i,c,f)min to
// k(p,i,c,f)max defining the inverse of the ratio of parameter change w.r.t.
// the default value.
procedure Pacs_Chopper_AutoOpt_bug {
    int kpmin = 3 in [0,6];
    int kpmax = 3 in [0,6];
    int kimin = 3 in [0,6];
    int kimax = 3 in [0,6];
    int kcmin = 3 in [0,6];
    int kcmax = 3 in [0,6];
    int kfmin = 3 in [0,6];
    int kfmax = 0 in [0,6];
}{
    // PACS instrument code for BBID
    int instrument = 0x40000000;
    // chopper position (approx. +/- 4 deg in FPU)
    int chop_pos = 12000;
    // number of chop cycles
    int cycle = 10;
    // length of plateau time in seconds
    int plateau_time = 2;
    // Initialise variables for conversion from int to string and double
    string sU = "+0";
    string sV = "+0";
    string sW = "+0";
    string sX = "+0";
    double dU = 0.0;
    double dV = 0.0;
    double dW = 0.0;
    double dX = 0.0;
    int bU = 0x4000;
    int bV = 0x400;
    int bW = 0x40;
    int bX = 0x4;
    // CALU table file to be accessed
    string fileU = "PacsTable_CONFChopper_auto";
    // Start diag. HK
    SPEC_Chopper_dhk_5hk_1khz_bb();
    // Cycle through calibration table columns 
    if(kpmax < kpmin) {
        kpmax = kpmin;
    }
    if(kimax < kimin) {
        kimax = kimin;
    }
    if(kcmax < kcmin) {
        kcmax = kcmin;
    }
    if(kfmax < kfmin) {
        kfmax = kfmin;
    }
    for(int u = kpmin - 3 .. kpmax - 3) {
        for(int v = kimin - 3 .. kimax - 3) {
            for(int w = kcmin - 3 .. kcmax - 3) {
                for(int x = kfmin - 3 .. kfmax - 3) {
                    // calculate inverse -> ratio of changes
                    if(u != 0) {
                        dU = 1.0 / double(u);
                    } else {
                        dU = 0.0;
                    }
                    if(v != 0) {
                        dV = 1.0 / double(v);
                    } else {
                        dV = 0.0;
                    }
                    if(w != 0) {
                        dW = 1.0 / double(w);
                    } else {
                        dW = 0.0;
                    }
                    if(x != 0) {
                        dX = 1.0 / double(x);
                    } else {
                        dX = 0.0;
                    }
                    if(abs(dU + dV + dW + dX) < 0.01) {
                        // convert int to string variables
                        // and determine BBID for column recovery
                        // BBID is a 32 bit word with:
                        // 2 bits: Instrument (PACS = 01)
                        // 14 bits: block number (not used here)
                        // 16 bits: a counter, used here as follows:
                        //          4 bits for every PID parameter (P, I, C, F)
                        //          of this: 2 bits for the sign (01 = +, 10 = -)
                        //                   2 bits for the number (01, 10, 11 = 1, 2, 3)
                        if(u >= 0) {
                            sU = "+" + u;
                            bU = 16384 + 4096 * u;
                        } else {
                            sU = "" + u;
                            bU = 32768 - 4096 * u;
                        }
                        if(v >= 0) {
                            sV = "+" + v;
                            bV = 1024 + 256 * v;
                        } else {
                            sV = "" + v;
                            bV = 2048 - 256 * v;
                        }
                        if(w >= 0) {
                            sW = "+" + w;
                            bW = 64 + 16 * w;
                        } else {
                            sW = "" + w;
                            bW = 128 - 16 * w;
                        }
                        if(x >= 0) {
                            sX = "+" + x;
                            bX = 4 + x;
                        } else {
                            sX = "" + x;
                            bX = 8 - x;
                        }
                        // construct column identifier
                        string calUcol = "P" + sU + "I" + sV + "C" + sW + "F" + sX;
                        debug_print("CALU column is " + calUcol);
                        int bbid = instrument + bU + bV + bW + bX;
                        WriteBBID(bbid);
                        // Upload Chopper Controller Parameter
                        CONF_chopper(fileU,calUcol);
                        delay(2);
                        // Switch on and enable chopper controller 
                        PACS_Chopper_SWON_SWOF_only("ON");
                        delay(2);
                        EnDis_chopper("ON");
                        delay(5);
                        // move chopper to zero
                        PACS_Chopper_mov_abs_fm_bb(0);
                        delay(1);
                        // chop cycle
                        int i = 1;
                        while(i <= cycle) {
                            PACS_Chopper_mov_abs_fm_bb(chop_pos);
                            delay(plateau_time);
                            PACS_Chopper_mov_abs_fm_bb(-chop_pos);
                            delay(plateau_time);
                            i = i + 1;
                        }
                        // move chopper to zero
                        PACS_Chopper_mov_abs_fm_bb(0);
                        delay(1);
                        // Disable and switch off chopper controller 
                        EnDis_chopper("OFF");
                        delay(2);
                        PACS_Chopper_SWON_SWOF_only("OFF");
                        delay(5);
                    }
                }
            }
        }
    }
    // Stop diagnostic housekeeping
    PACS_stop_dhk_fm_bb();
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Missionphase  : PACS FMILT
//
// Purpose       : Configure the phot filter wheel
//
// Author        : PR
//
// Arguments     : 
//
// Description   : 
//                 
// Comments      :      
//
// Version       : 0.1 
// History       : 0.1  12-Jun-2007 Initial version
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//
obs PacsEng_CONF_phot_fltw {
    /* No variables to call PacsEng_CONF_phot_fltw                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POSB" */
    /* End of needed variables for PacsEng_CONF_phot_fltw                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_phot_fltw()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_phot_fltw();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : CQM
//
// Purpose       : CONFigure the CSs servo loops
//                  
// Author TCL    : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : CONF_cs.txt
//
// Arguments     : This version uses the hardcoded parameters found in the
//                 DEC/MEC User Manual V3.3
//
// type    name     default      Description
// string  whichCS  "CS1"        Which CS is configured 
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : Current version (0.2) uses hardcoded values from DEC/MEC
//                 SUM V3.3
//
// Version       : 0.3
// History       : 0.1 13-Oct-2004 Creation by DAC
//               : 0.2 27-apr-2005 DAC Added missing 7th argument
//               : 0.3 30-sep-2005 CS1 and CS2 were called with same variable
//               :
int procedure CONF_cs {
    string whichCS = "CS1" in ["CS1","CS2","Both"]; // CS to configure
}{
    // Tally total duration [milliseconds]
    int duration_msec = 0;
    // Use HF's version where everything is hardcoded
    // Parameters for CS1
    int[] aux1 = [1000000,5000,3277,1857,327,0x7fff,0];
    int check_sum1 = checksum("int",aux1);
    {int}[] parlist1 = Array2grp_1(aux1);
    // Parameters for CS2
    int[] aux2 = [1000000,5000,3277,1857,327,0x7fff,0];
    int check_sum2 = checksum("int",aux2);
    {int}[] parlist2 = Array2grp_1(aux2);
    if(whichCS == "CS1") {
        Pacs_DMC_WRT_CS1_CONF_PAR(parlist1,check_sum1);
    }
    if(whichCS == "CS2") {
        Pacs_DMC_WRT_CS2_CONF_PAR(parlist2,check_sum2);
    }
    if(whichCS == "Both") {
        Pacs_DMC_WRT_CS1_CONF_PAR(parlist1,check_sum1);
        Pacs_DMC_WRT_CS2_CONF_PAR(parlist2,check_sum2);
    }
    // Set delay
    int duration_sec = Msec2sec(duration_msec);
    delay(duration_sec);

    return duration_msec;
}

// File          : PACS_Close_Launch_Lock.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Close the launch lock
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
// Arguments     : none
//                 
//
// Description   : This script will do what's necessary to close the launch lock
//                              
// Comments      :      
//
// Version       : 1.0
// History       : 1.0 / 17-Nov-2004 initial version
// 1.1  4-apr-2006 Adapted to DMC v6.0.1
// 1.2  6-apr-2006 gratPara must be 0x10 for breadboard (User Manual says 0x12)
// 1.3 18-Jul-2006 added required wait times after disable grating cntr.
procedure PACS_Close_Launch_Lock {
}{
    debug_print("Start PACS_Close_Launch_Lock");
    //DPU_SET_HK_LIST (SPEC for both channels)
    Pacs_DPU_SET_HK_LIST("SPEC","BOTH Array");
    delay(1);
    // Set the mechanisms
    // PC112420 "DMC_MOVE_GRAT_ABS" MOVE GRATING TO Lock position
    //        PP079420 "SET_POINT"
    // tcsend PC112420 {PP079420 496000}
    int gratPos = 496000;
    Pacs_DMC_MOVE_GRAT_ABS(gratPos);
    delay(30);
    // Disable grating contoller
    Pacs_DMC_DISABLE_GRAT_CONT();
    delay(2);
    // "DMC_LOCK_GRATING" Lock the Grating launch lock
    // in open loop mode
    // tcsend PC117420 {PP092420 2}
    int gratPara = 0x12;
    Pacs_DMC_LOCK_GRAT(gratPara);
    delay(12);
    // "DMC_SWOF_GRAT_CONT" Switch off grating controller
    Pacs_DMC_SWOF_GRAT_CONT();
    delay(1);
    // ---------------------
    // End of Procedure
    // ---------------------
}

// Missionphase  : 
//
// Purpose       : Perform Setup Photometry according to TM's input:
//                 Scripts:
//      a) tm_phot_dpu_dmc_setup.tcl  <phot_hk 1, syn_source 4>
//      b) tm_phot_mec_setup.tcl      <phot_filter_wheel_id 1,
//                                     chop_def_pos 0, temp_bb1 800000
//                                     temp_bb2 920000 >
//      c) tm_phot_sequencer_setup.tcl
//      d) tm_phot_polar_bestM7_setup.tcl
//         (Setting of optimal polarisations in the cold 0.3K)
//      e) tm_phot_change_datamode.tcl  <"Bolo & HK">
//      f) tm_phot_change_seq_mode.tcl  <"Sbolo-Sref">
//      g) PACS_Phot_Gain_high.tcl
//         (gain setting  <"high">)
//      h) tm_phot_spu_setup.tcl   <comp_mode_blue 0, comp_mode_red 0
//                                  spus_nraw 3, spul_nraw 3>
//
//
// CUS author    : DAC
// Script file   : PHOT_setup.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : SCR PACS-1866
// 
// Version       : 3.0
// History:
// 0.1 DAC 22-apr-2005
// 0.2 DAC 25-apr-2005 New default: Do not start SPU
// 1.0 TM  12-apr-2006, update for FM with new settings
// 1.1 TM  08-aug-2006, new procedure to read bias tables in [V]
// 1.2 TM  10-oct-2006, autonomy function added
// 2.0 DAC 17-oct-2006 Use BIAS tables in volts, eliminate useless
//                     timing calculation, call with BIAS table name and
//                     initial filter position, initial CS temperatures
// 2.1 TM 08-Nov-2006 add the switch on of the groups
// 2.2 TM 08-Nov-2006 autonomy function 17 added
// 2.3 TM 08-Nov-2006 autonomy functions modified again (moved to PHOT_switchon_groups)
// 2.4 TM 10-Nov-2006 default bias table changed, low gain
// 2.5 13-nov-2006 Use RAW bias tables
// 2.6 15-nov-2006 Using volts again
// 2.7  8-dec-2006 Add temperature autonomy function
// 2.8  5-mar-2007 update for chopper, CSs
// 2.9  4-apr-2007 TM: number of raw channels set to zero
// 3.0  9-apr-2007 TM & KO: update of AFs
// 3.1  9-apr-2007 TM & KO: AF 15 taken out again
// 3.2 21-aug-2007 SRC-3507 Indicate end of BB
//                 Sync bus at end of script
// 3.3 06-oct-2008 TM & VDP: PHOT_change_seq_mode set to Sref_only 
// 3.4 12-nov-2008 KO: gotoDirect option added
// 1.0 22-jul-2009 KO: Copied from PHOT_setup and Group6 stays off
//                     (for red detector tests in PV)
//
int[] block PHOT_setup123456 PACS 215 {
    string calUfile = "BOLObias_preILT_standard_low"; //BIAS table name
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double set_CS1 = 48.0; // CS1 settings (ohms)
    double set_CS2 = 58.0; // CS2 settings (ohms)
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
}{
    // Register BBID with environment
    WriteBBID($BBID);
    // Define variables to communicate various durations to HSPOT.
    int time_start = time();
    PHOT_dpu_dmc_setup("BOTH Array",4);
    // Place filter wheel
    PHOT_dmc_setup(fltPOS,0,set_CS1,set_CS2);
    // switch on groups and enable AF 17
    PHOT_switchon_groups();
    // Set polarisations
    PHOT_set_bias_volt(calUfile,1);
    PHOT_set_bias_volt(calUfile,2);
    PHOT_set_bias_volt(calUfile,3);
    PHOT_set_bias_volt(calUfile,4);
    PHOT_set_bias_volt(calUfile,5);
    PHOT_set_bias_volt(calUfile,6);
    // Set sequencer
    PHOT_seq_setup();
    // Set data mode
    PHOT_change_data_mode("Bolo_HK");
    //  PHOT_change_seq_mode("Sb_Sref"); New setup post-SOVT1
    // Now we set the direct mode post-SOVT1
    int operand = 0;
    if(gotoDirect) {
        //*********************************************************
        // Sequence mode : blocking on VDEC_X for the direct mode
        //*********************************************************
        //
        // Set groups 1234 bol bias 09 (CKRLH) to 0.0 volt (0)
        //Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
        Pacs_BOLC_SET_CKRLH_G1_RAW(0);
        Pacs_BOLC_SET_CKRLH_G2_RAW(0);
        Pacs_BOLC_SET_CKRLH_G3_RAW(0);
        Pacs_BOLC_SET_CKRLH_G4_RAW(0);
        Pacs_BOLC_SET_CKRLH_G5_RAW(0);
        Pacs_BOLC_SET_CKRLH_G6_RAW(0);
        // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
        //Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
        Pacs_BOLC_SET_VDECX_L_G1(2.0);
        Pacs_BOLC_SET_VDECX_L_G2(2.0);
        Pacs_BOLC_SET_VDECX_L_G3(2.0);
        Pacs_BOLC_SET_VDECX_L_G4(2.0);
        Pacs_BOLC_SET_VDECX_L_G5(2.0);
        Pacs_BOLC_SET_VDECX_L_G6(2.0);
        // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
        //# P 09 01 00 01
        operand = 0x9010001;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
    } else {
        // Set seq mode Sb_Sref (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sb_Sref");
        //# P 09 01 00 00
        operand = 0x9010000;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
    }
    // Set gain LOW
    PHOT_set_gain("LOW");
    // Set SPU but do not start it yet
    PHOT_spu_setup(0,0,0,0,false);
    // Time spent
    int duree_TCs = time() - time_start;
    int duree_num = duree_TCs;
    // Return the array of times
    int[] time_array = [duree_num,0,0,0,0];
    //
    // enable AF 12 (to check for the protection biases)
    //Pacs_DPU_SET_FUNCT("EVENT_BOL_BIAS","ENABLE");
    // enable AF 14 to check for TEMP_EV < 0.3 K
    Pacs_DPU_SET_FUNCT("EVENT_BOL_T_FPU","ENABLE");
    // enable AF 15 (to check for the VSS currents of groups and BUs)
    // Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","ENABLE");
    // Mark end of BB
    WriteEndBB();
    // Sync bus
    sync();

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       : Start Autonomy Function 14 as an ObsMode
//                 
//
// Author        : Helmut Feuchtgruber
//
// Arguments     : None
//
// Description   : Simply call Aut_14
//
// Dependencies  : Aut_14
//
// Comments      : 
//
// Version       : 2.0 
// History       : 1.0 26-Mar-2007 initial Version 
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Start_Autonomy_Function_14 {
    /* Needed variables to call PacsEng_Start_Autonomy_Function_14                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Start_Autonomy_Function_14                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Aut_14()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Aut_14();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       : Start Autonomy Function 17 as an ObsMode
//                 
//
// Author        : Helmut Feuchtgruber
//
// Arguments     : None
//
// Description   : Simply call Aut_17
//
// Dependencies  : Aut_17
//
// Comments      : 
//
// Version       : 2.0
// History       : 1.0 26-Mar-2007 initial Version 
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Start_Autonomy_Function_17 {
    /* Needed variables to call PacsEng_Start_Autonomy_Function_17                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Start_Autonomy_Function_17                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Aut_17()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Aut_17();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Purpose       : Wavelength calibration and instrumental profile in Burst mode
// Author        : HF
//
// Arguments     :
// string fltPOS            Filter wheel position (0="POS A", 1="POS B")
// int grat_start           Grating start position for scan
// int grat_stepsize        Grating step size
// int grat_numsteps        Number of grating steps in one direction
// int grat_numramps        Number of ramps per grating position
// int chop_def             Chopper position during grating scan
// int nb_rdout_ramp        Number of readouts per ramp
// int num_updown           Number of grating updown scans
// int grat_def             Position of grating after the scan
// int capa_red             Red capacitor
// int capa_blu             Blue capacitor
// double bias_r_blu        Bias "r" blue
// double bias_r_red        Bias "r" red
// double bias_d_blu        Bias "d" blue
// double bias_d_red        Bias "d" red
// int nb_samp_subramp_blu  Nb of blue samples per sub-ramp
// int nb_samp_subramp_red  Nb of red samples per sub-ramp
//
// Prerequisite  : PACS must be on and configured for spectroscopy
//                 PacsEng_Burstmode_Setup has been executed
// Postrequisite: PacsEng_Burstmode_Reset should be executed
//
// Description   : Uses OBCP28 for executing a parameterized scan of any length,
//                 stepsize etc. Represents a generic non-chopped grating scan               :
// Comments      :
//
// Version       : 1.0
// History       : 1.0 19-oct-2009 VD Cloned from PacsCal_WaveCalNoChop
//               : 1.1 19-Oct-2009 VD PHS-1222 enable Burst mode 
//
obs PacsCal_WaveCalNoChop_Burst {
    /* Needed variables to call WaveCalNoChop */
    string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B"
    int order = 2; // Order selection
    int grat_start = 500000; // grating start position for scan
    int grat_stepsize = 200; // grating step size
    int grat_numsteps = 50; // number of grating steps in one direction
    int grat_numramps = 3; // number of ramps per grating position
    int chop_def = 648; // chopper position during grating scan
    int nb_rdout_ramp = 64; // number of readouts per ramp
    int num_updown = 1; // number of grating updown scans
    int grat_def = 496000; // position of grating after the scan
    int capa_red = 12; // Red capacitor
    int capa_blu = 12; // Blue capacitor
    double bias_r_blu = 0.0101; // Bias "r" blue
    double bias_r_red = 0.0101; // Bias "r" red
    double bias_d_blu = 0.10001; // Bias "d" blue
    double bias_d_red = 0.04201; // Bias "d" red
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp    
    int comp_mode_blu = 16; // compression mode for blue detector
    int comp_mode_red = 16; // compression mode for red detector
    int nb_raw_red = 3; // number of red pixels
    int nb_raw_blu = 3; // number of blue pixels
    int naifid = 0; // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    double yoffset = 0.0; // yoffset [arcsec]
    double xoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    bool verbose = true;
}{
    // PHS-1222
    busconfig (7);
    // BURST MODE :     4:PACS PRIME  -  7:BURST MODE  - 8:PARALLEL MODE
    // compiting time for slw / calibration during slew time and others
    // Set OBSID
    //int tobsid = duration(WriteOBSID($OBSID));
    // SPEC parameters for BLU and RED               
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    string throwUsage = "small";
    string extraConf = "normal";
    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // frstLstGratPos is the last position for the grating after the Cals done
    // during Slew time... must be same as observations start position: grat_pos   
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    // "N/A" in string because of indexing 0,1,2,3
    string[] choix = ["N/A","order1","order2","order3","sed4"];
    string order_str = "order" + order;
    //    if(choix[order] != "order1") {
    //        double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    // have to introduce the logic for KeyWL as fucntion of order + filter
    double[] keyWAVE = [150.0];
    if(choix[order] == "order3" && fltPOS == "POS B") {
        error("Filter B and order3 are not compatible");
    }
    if(choix[order] == "order1" && fltPOS == "POS A") {
        keyWAVE = [180.0];
    }
    if(choix[order] == "order1" && fltPOS == "POS B") {
        keyWAVE = [150.0];
    }
    if(choix[order] == "order2" && fltPOS == "POS B") {
        keyWAVE = [75.0];
    }
    if(choix[order] == "order3" && fltPOS == "POS A") {
        keyWAVE = [60.0];
    }
    // this is for extended Blue
    if(choix[order] == "order2" && fltPOS == "POS A") {
        keyWAVE = [60.0];
        choix[order] = "sed4";
    }
    // no need for SpecKeyWave!
    //    double keyWL = PacsSpecKeyWaves(order_str);
    //    double[] keyWAVE = [keyWL];
    int t_BUS_LIST_enable = imax(2,duration(Burstmode_setup_block()));
    int t_BUS_LIST_disable = imax(2,duration(Burstmode_reset_block()));
    debug_print("BUS_LIST: " + t_BUS_LIST_enable + " / " + t_BUS_LIST_disable);
    int tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]));
    int tOBSID = duration(WriteOBSID($OBSID));
    int tepilogue = duration(SPEC_aot_epilogue(grat_start,grat_def,verbose));
    int tEndID = duration(WriteEndID());
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    //Minimum slew time
    int tslewmin = tOBSID + t_BUS_LIST_enable + tpacsSlewCal;
    //Initial hold
    int tih = 0;
    //Final hold
    int tfh = tepilogue + t_BUS_LIST_disable + tEndID;
    //Duration of "stable" pointing
    int tp = duration(WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_def,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red));
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            WriteOBSID($OBSID);
            Burstmode_setup_block();
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            int tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_start,choix[order]);
            data_rate(300.0);
        } else {
            if(state[0] == 3) {
                //      Call the WaveCal procedure
                WaveCalNoChop(fltPOS,grat_start,grat_stepsize,grat_numsteps,grat_numramps,chop_def,nb_rdout_ramp,num_updown,grat_def,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_blu,nb_raw_red);
            } else {
                if(state[0] == 5) {
                    SPEC_aot_epilogue(grat_start,grat_def,verbose);
                    Burstmode_reset_block();
                    data_rate(0.0);
                    WriteEndID();
                }
            }
        }
    }
}

// Missionphase  : FM
//
// Purpose       :  Time DMC syncing
//                  
//                 
//
// Input arguments none
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  DMC time syncing
//                            
//                           
//                            
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on 
//                             
//                 
// Comments      : 
// 
// History       : 1.0 28-may-2009 creation VD
//
int block OBCP_TimeSynch3 PACS 1024 {
}{
    // Register start of BB
    // special Hexa
    int iBBID = 0xcd2a4a5;
    // Obtain duration of an "internal" command [msec]      
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duration of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Tally duration (NOTE: we use [msec] for the return value)
    int duration_msec = 0;
    // DMC_WRT_TIME()
    duration_msec = duration_msec + t_cmd;
    // DMC_SET_TIME
    duration_msec = duration_msec + t_cmd;
    string obcp_ID = "TIME_SYNC_III";
    int obcp_par = 0;
    //   int seq_DMC=0;
    //    int seq_time = duration_msec;
    {int,int}[] grp = [];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par,grp);
    // Add the "communication jitter"
    duration_msec = duration_msec + obcp_margin;
    // write BB ID to DMC
    Pacs_DMC_SET_BBID(iBBID);
    duration_msec = duration_msec + t_cmd;
    // Return time

    return duration_msec;
}

// CVS comments  : $Id: 
// Purpose       : Invoke a PACS calibration OBCP during slew to source
// 		   using ABBA chopper scheme;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsSpecSlewCal.txt 
//
// Input arguments
// Type                     Name          Description
// bool                     verbose       Debug_print or not 
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECblu   BLUE SPU parameters
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECred   RED  SPU parameters
// {int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int}[]  confOBCP      OBCP parameters
//  bool                    doPROLOG      Perform/don't AOT prologue
//  double []               keyWAVE       One or several key wavelengths
//  int                     filter        Where to move FltW (as order)
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per key line
//
// Description   : Perform AOT prologue and then OBCP #35.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 0.1 DAC 10-may-2006 
// 		 : 1.0 13-mar-2009 VD OBCP35
//                 1.1  3-jun-2009 DAC Original PacsPacsSpecSlewCal35 from
//                                 VD renamed PacsSpecSlewCal
//                 1.2 18-jun-2009 DAC Enter into OBCP35params with K-orders
//                                 to schedule KeyWave calibrations
//                 2.0 06-jul-2009 VD introduces scenario for CONF_SPEC_param                
//                                 
//
int[][] procedure PacsSpecSlewCalSPU {
    /* verbose debug print                          */
    bool verbose = false;
    /* scenario to use */
    string scenario = "none";
    /* SPEC parameters for BLU and RED              */
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    /* OBCP parameters                               */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* Perform/don't AOT prologue                    */
    bool doPROLOG = true;
    /* One or several key wavelengths                */
    double[] keyWAVE = [62.5];
    /* Where to leave FltW (as order)                */
    int filter = 2;
    /* Where to leave grating at end of CAL          */
    int frstLstGratPos = 535000;
    /* User defined grating order                    */
    string orderSel = "order3";
}{
    // Debug only
    if(verbose) {
        debug_print("PacsSpecSlew called with:");
        debug_print("confSPECblu: " + confSPECblu[0]);
        debug_print("confOBCP: " + confOBCP[0]);
        debug_print("doPROLOG: " + doPROLOG);
        debug_print("keyWAVE: " + keyWAVE);
        debug_print("filter: " + filter);
        debug_print("frstLstGrat: " + frstLstGratPos);
        debug_print("orderSel: " + orderSel);
    }
    // Array to collect OBCP times per line
    // NOTE: time variables in units of either number of ramps (SPEC) or
    // number of readouts (BOLO) or plain seconds. The calling program 
    // must convert, if applicable, this information into actual duration 
    // in true time units [seconds].
    // SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky), CAL source, 
    // and overheads (wait for something). Total duration is given by duree_num. 
    // If no error, this duration must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    int[][] dureeCalKey = [[0,0,0,0,0]];
    // Long sequence to "unpack" default values from tuples
    int capa_blu = confSPECblu[0]{0};
    int nb_rdouts_ramp_blu = confSPECblu[0]{1};
    int nb_rdouts_subramp_blu = confSPECblu[0]{2};
    int comp_mode_blu = confSPECblu[0]{3};
    int glitch_det_blu = confSPECblu[0]{4};
    int ramp_fit_alg_blu = confSPECblu[0]{5};
    int nb_raw_blu = confSPECblu[0]{6};
    int bias_r_blu_mV = confSPECblu[0]{7};
    int bias_d_blu_mV = confSPECblu[0]{8};
    int capa_red = confSPECred[0]{0};
    int nb_rdouts_ramp_red = confSPECred[0]{1};
    int nb_rdouts_subramp_red = confSPECred[0]{2};
    int comp_mode_red = confSPECred[0]{3};
    int glitch_det_red = confSPECred[0]{4};
    int ramp_fit_alg_red = confSPECred[0]{5};
    int nb_raw_red = confSPECred[0]{6};
    int bias_r_red_mV = confSPECred[0]{7};
    int bias_d_red_mV = confSPECred[0]{8};
    int nb_up_down = confOBCP[0]{0};
    int grat_step_up = confOBCP[0]{1};
    int grat_step_dn = confOBCP[0]{2};
    int nb_SRC_OFF = confOBCP[0]{3};
    int nb_ramps_plateau = confOBCP[0]{4};
    int nb_CS1_CS2 = confOBCP[0]{5};
    int nb_grat_step_up = confOBCP[0]{6};
    int nb_grat_step_dn = confOBCP[0]{7};
    int grat_start_pos = confOBCP[0]{8};
    int grat_start_time = confOBCP[0]{9};
    int grat_def_pos = confOBCP[0]{10};
    int grat_def_time = confOBCP[0]{11};
    int chop_pos_SRC = confOBCP[0]{12};
    int chop_pos_REF1 = confOBCP[0]{13};
    int chop_pos_REF2 = confOBCP[0]{14};
    int chop_pos_CS1 = confOBCP[0]{15};
    int chop_pos_CS2 = confOBCP[0]{16};
    int chop_def = confOBCP[0]{17};
    int detector = confOBCP[0]{18};
    int filterPOS = confOBCP[0]{19};
    // Bias voltages (needed by SPEC_aot_prologue) are commanded in (double) volts
    double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
    double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
    double bias_r_red = double(bias_r_red_mV) / 1000.0;
    double bias_d_red = double(bias_d_red_mV) / 1000.0;
    if(verbose) {
        debug_print("confSPEC: capa_blu: " + capa_blu);
        debug_print("confSPEC: nb_rdouts_ramp_blu: " + nb_rdouts_ramp_blu);
        debug_print("confSPEC: nb_rdouts_subramp_blu: " + nb_rdouts_subramp_blu);
        debug_print("confSPEC: comp_mode_blu: " + comp_mode_blu);
        debug_print("confSPEC: glitch_det_blu: " + glitch_det_blu);
        debug_print("confSPEC: ramp_fit_alg_blu: " + ramp_fit_alg_blu);
        debug_print("confSPEC: nb_raw_blu: " + nb_raw_blu);
        debug_print("confSPEC: bias_r_blu_mV: " + bias_r_blu_mV);
        debug_print("confSPEC: bias_d_blu_mV: " + bias_d_blu_mV);
    }
    // Issue SPEC_aot_prologue if demanded
    if(doPROLOG && scenario == "none") {
        totalDUREE = SPEC_aot_prologue(nb_rdouts_ramp_red,nb_rdouts_ramp_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,comp_mode_blu,comp_mode_red,nb_rdouts_subramp_blu,nb_rdouts_subramp_red,nb_raw_blu,nb_raw_red,glitch_det_red,ramp_fit_alg_red,filter,verbose);
    } else {
        totalDUREE = SPEC_aot_prologueSPU(scenario,nb_rdouts_ramp_red,nb_rdouts_ramp_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,comp_mode_blu,comp_mode_red,nb_rdouts_subramp_blu,nb_rdouts_subramp_red,nb_raw_blu,nb_raw_red,glitch_det_red,ramp_fit_alg_red,filter,verbose);
    }
    // NOTE: Grating starts at grat_start_pos determined by SPEC_get_grat. At end of
    // SlewCal grating should park. Park position is generally grat_def_pos:
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // AOT_prologue is supposed to have left grating at park position
    grat_def_pos = grat_park;
    // NOTE for version 1.0 and later. Upon execution of SpecSlew, grating is
    //      indeed where SPEC_orbit_prologue left it (the default park position);
    //      this fact remains unchanged. What is new is that SpecSlew will leave
    //      the grating not at the default park position but already at the
    //      position needed by the 1st line that will be observed. There are two
    //      advantages:
    //      1- the new logic in the OBCP incurs in less grating movements when
    //         the OBCP is repeated within a NOD or the next raster point, and
    //      2- the detector will see the illumination corresponding to the line
    //         wavelength before the actual observation starts.
    // Observe now each key wavelength
    int nbKEY = length(keyWAVE);
    {double,int,int,int,int}[] gratTuple = [{0.0,0,0,0,0}];
    for(int loopKEY = 0 .. nbKEY - 1) {
        //     We may perform the loop starting with high ORDER
        int keyWaveLoop1 = nbKEY - 1 - loopKEY;
        // or not....
        keyWaveLoop1 = loopKEY;
        //       
        //     Get grating start position (CAL is performeed with HI resolution)
        //     (frequency switch boolean is set to false)
        bool switching = false;
        string extraConf = "normal";
        //      Seek K rows in CAL-U, i.e. key wavelength parameters	
        gratTuple[keyWaveLoop1] = SPEC_get_grat_info(keyWAVE[keyWaveLoop1],"KHI",switching,extraConf,orderSel,verbose);
        //      Issue now OBCP#35 for each of the given key wavelengths
        int order = gratTuple[keyWaveLoop1]{1};
        grat_start_pos = gratTuple[keyWaveLoop1]{2};
        int nb_grat_steps = gratTuple[keyWaveLoop1]{3};
        nb_grat_step_up = nb_grat_steps;
        nb_grat_step_dn = nb_grat_steps;
        int grat_step_up_fine = gratTuple[keyWaveLoop1]{4};
        int grat_step_dn_fine = -grat_step_up_fine;
        //
        // Read K-lines of table OBCP35params
        string key = "K" + order;
        if(verbose) {
            debug_print("PacsSlewCal: key " + key);
        }
        string calU = "OBCP35params";
        nb_up_down = ilookup(calU,key,"nb_up_down");
        nb_CS1_CS2 = ilookup(calU,key,"nb_CS1_CS2");
        // SRC_OFF == 0;
        nb_SRC_OFF = 0;
        int chop_pos_OFF = chop_pos_REF2;
        nb_ramps_plateau = ilookup(calU,key,"nb_ramps_plateau");
        int grat_step_coarse = 0;
        //      Lookup chopper CS1 and CS2 positions
        calU = "CHOPPERCSparams";
        chop_pos_CS1 = ilookup(calU,"SPEC","pos_CS1");
        chop_pos_CS2 = ilookup(calU,"SPEC","pos_CS2");
        int nb_rdouts_ramp = nb_rdouts_ramp_red;
        //     Grating logic (OBCP is up/down ==> grating ends where it started)
        //     Leave the grating where it is, i.e. end-of-DMC value
        int new_grat_def_pos = grat_start_pos;
        //     But the last line should leave grating at frstLstGratPos
        if(keyWaveLoop1 == nbKEY - 1) {
            new_grat_def_pos = frstLstGratPos;
        }
        //     Number of steps to start position for current line
        int steps_start = grat_def_pos - grat_start_pos;
        int grat_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("OBCPcal:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + ";  time: " + grat_time);
        }
        //
        int steps_end = grat_start_pos - new_grat_def_pos;
        grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("OBCPcal:GratEnd from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
        }
        int[] dureeOBCP = OBCP_grat_line_scan_chop_3_cal(nb_up_down,nb_grat_step_up,grat_step_up_fine,nb_SRC_OFF,chop_pos_SRC,nb_ramps_plateau,chop_pos_OFF,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_dn_fine,detector,grat_start_pos,grat_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
        if(verbose) {
            debug_print("SlewCal performed KeyWave: " + keyWAVE[keyWaveLoop1] + " [mic] requires " + dureeOBCP[0] + " [sec]");
        }
        //     Update dureeCalKey
        dureeCalKey[keyWaveLoop1] = [0,0,0,0,0];
        for(int loop1 = 0 .. 4) {
            dureeCalKey[keyWaveLoop1][loop1] = dureeOBCP[loop1];
        }
        //     Prepare the grating to be ready for the next wavelength
        grat_def_pos = new_grat_def_pos;
    }
    // Add after the KeyWaves in dureeCalKey the duration from AOT_prologue
    dureeCalKey[nbKEY] = [0,0,0,0,0];
    dureeCalKey[nbKEY][4] = totalDUREE[4];
    if(verbose) {
        debug_print("End SlewCal with dureeCalKey: " + dureeCalKey);
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return dureeCalKey;
}

// $Id: PacsEng_Spec_Fltw_mec_Setup.txt,v 1.2 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 05-Jul-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Fltw_mec_Setup_l {
    /* No variables to call PacsEng_Spec_Fltw_mec_Setup_l                        */
    /*  string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Fltw_mec_Setup_l                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_spec_fltw()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_spec_fltw();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : Perform Setup Photometry according to TM's input:
//
// CUS author    : DAC
// Script file   : PHOT_setup_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform PACS setup for photometry according to
//                 TM's "Setup photometry" description in e-mail "Test
//                 descriptions full functional tests", 15-apr-2005
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 DAC 22-apr-2005
//                 0.2 DAC 17-oct-2006 Calls PHOT_setup with BIAS and fltw
//                                   position, tempCS1 and tempCS2
//                 0.3 TM   9-nov-2006 BIAS table is the only input argument
//                 0.4 TM  13-nov-2006 Back to old input arguments
//                 0.5 DAC 15-nov-2006 Using bias in volts again
//		   1.0 18-nov-2008 VD missing: translated PV/CP phase
obs PacsEng_Phot_setup {
    string calUfile = "BOLObias_preILT_standard_low"; //BIAS table name
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double set_CS1 = 48.0; // CS1 setting (ohms)
    double set_CS2 = 58.0; // CS2 setting (ohms)
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
}{
    int tih = imax(1,duration(WriteOBSID($OBSID)));
    int tp = imax(1,duration(PHOT_setup(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect)));
    int tfh = imax(1,duration(WriteEndID()));
    bool execute = true;
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_setup(calUfile,fltPOS,set_CS1,set_CS2,gotoDirect);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
}

//////////////////////////////////////////////////////////////////////////////
/// $Id: PacsCal_SpecFieldDistortChopRast.txt
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Spectro Field Distortion measurements
// 		   using Chopped Raster pointings XY version
//  
//
// CUS author    : VD based on DAC
//
// Input arguments: see after module identification
//
// Return values
// {int,int,int} {totalDuration,slewDuration,obsOverPACSandSC}
//
// Comments      : Cal block at beginning and at the end of the observations
//
// History: 
// 	    04-mar-2009 VD Creation
//	    09-mar-2009 VD remove complications like Planet offsets
//	    NOT USED ANYMORE but updated SPR5447
//
obs PacsCal_SpecFieldDistortChopRast {
    string lineId = "Alessandra lonely line"; //Line ID
    double lWave = 82.0 in [55.0,210.0]; //Rest wavelength [micron]
    string orderSel = "order2" in ["order2","order3"]; //Used to select FILTER
    /* Offsets setup */
    bool refSelected = false; // OFF position needed 
    int noOFF = 0; //0 for noOFF, READ DOCS for noOFF>0
    int offDwellTime = 10; //dwell time at off position
    /* Raster parameters */
    int m = 2 in [2,100]; //Number of points
    int n = 2 in [1,100]; //Number of lines
    double pointStep = 9.4 in [2.0,480.0]; // Raster point step [arcsec]
    double lineStep = 9.4 in [2.0,480.0]; // Raster line  step [arcsec]
    /* Chop parameters */
    bool src_at_OFF = false; // Put the SRC at OFF chopper beam?
    double chopthrow = 180.0; // Chopper throw [arcsec]
    double chopoffset = 0.0; // Chopper offset [arcsec]
    double mapRasterAngle = 0.0 in [0.0,360.0];
    /* other detectors and other stuff */
    bool useChopParam = true; // overwrite some chopper parameters
    int nb_ramps_plateau = 2; // ramps per chopper plateau
    /*    int nb_SRC_REF = 5; // chop cycles per raster position */
    int dwellTimeSRC = 20; // dwell time on SRC in sec
    bool useDetParam = true; // overwrite some detector parameters
    int capa_blu = 0; // capacitance blue in [0,8,4,12]
    int capa_red = 8; // capacitance red in [0,8,4,12]
    int nb_rdouts_ramps = 64; // readouts per ramp
    int nb_rdouts_subramp = 64; // number of readouts per subramps
    string reduction_mode = "ramp fitting" in ["ramp average","ramp fitting"]; // spu reduction mode
    bool useBiasParam = false; // overwrite Bias parameters
    double bias_d_blu = 0.1701 in [0.0,1.0]; // bias_d blue (0-1V)
    double bias_d_red = 0.0601 in [0.0,1.0]; // bias_d red (0-1V)
    double bias_r_blu = 0.0101; // bias_r blue
    double bias_r_red = 0.0101; // bias_r red
    /* pointing */
    bool skyCoord = true; //TRUE for sky coordinates; false for S/C coordinates
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    /* 	   bool useRelativeOffsets = false; // use relative offsets? */
    /*     double relRAoff = 180.0 in [0.0,3600.0]; */
    /* 	   double relDECoff = 180.0 in [0.0,3600.0]; */
    double raoff = 0.0 in [0.0,360.0]; // absolute RA offsets
    double decoff = 0.0 in [-90.0,90.0]; // absolute DEC offsets
    int naifid = 0; // RA,DEC or SSO
    bool verbose = true;
}{
    // still needed for several things though
    //PlanetOffsets: Extra y,z offsets for naifid>0 [arcmin]
    double[] planetOffsets = [0.0,0.0];
    int repeatOBS = 1;
    int repeatOFF = 1;
    double lineFlux = 1.0;
    double contFlux = 2.0;
    double lineWdth = 30.0;
    string fluxUnit = "Jy/m2";
    string wdthUnit = "kms";
    string pmode = "raster";
    //  Formerly as input parameters
    // "lines" is defined as an array; its elements (and hence its dimension) 
    //  are provided by HSPOT in the AOT version. Here they are filled in-situ
    //   {id,redshifted wavelength,repeat factor,line flux,continuum flux, 
    //    line width,line flux unit,line width unit}
    {string,double,int,double,double,double,string,string}[] lines = [];
    int userNODcycles = 1;
    bool faintLines = true;
    bool chopper = true;
    bool nodding = false;
    int obsOverhead = 180;
    lines[0] = {lineId,lWave,repeatOBS,lineFlux,contFlux,lineWdth,fluxUnit,wdthUnit};
    // New variable to start at nodded position
    bool startAtOFF = false;
    // extraConf: whatever affects PACS default configuration 
    // Currently: the option faintLines calls for an extraConf
    string extraConf = "normal";
    // For bright lines
    if(!faintLines) {
        extraConf = "bright";
    }
    // pointing stuff
    int pointCase = 31;
    string pointMode = "raster_pointing";
    string userMode = "Raster, chopper,  no nodding";
    // Establish pointing offsets (index into PACSyzoffsets CAL file)
    string yzoffsetROW = "S" + pointCase;
    // For symmetrical chopping, virtual apertures are dependent on the chopper
    // throw. The chopperthrow will be used to compute yzoffsets
    yzoffsetROW = yzoffsetROW;
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("     PointCase ID: " + pointCase);
        debug_print("     PointMode   : " + pointMode);
        debug_print("     CALU entry  : " + yzoffsetROW);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Define array of wavelengths (will be needed by the SORT procedure)
    double[] lineWave = [55.0];
    // Populate the array of wavelengths (inherited from AOT where several lines
    // are allowed)
    lineWave[0] = lines[0]{1};
    // For each line obtain the grating order and the grating position 
    int[] orders = [0];
    double[] grat_pos = [0.0];
    // Fill the tuple waveTuple {waveLen,order,gratPos,nbStep,gratStep}
    {double,int,int,int,int}[] waveTuple = [{0.0,0,0,0,0}];
    bool switching = false;
    waveTuple[0] = SPEC_get_grat_info_PV(lineWave[0],"HI",switching,extraConf,orderSel,verbose);
    // Create vector of intermediate results
    orders[0] = waveTuple[0]{1};
    grat_pos[0] = double(waveTuple[0]{2});
    int[] grat_step = [0];
    grat_step[0] = waveTuple[0]{3};
    int[] grat_step_size = [0];
    grat_step_size[0] = waveTuple[0]{4};
    // Determine the filter needed with given lines
    // No filter needed, i.e. ORDER=1
    int filter = 1;
    // Determine filter based on HSPOT input
    if(orderSel == "order2") {
        filter = 2;
    }
    if(orderSel == "order3") {
        filter = 3;
    }
    if(verbose) {
        debug_print("ORDER array: " + orders);
    }
    // Filter below will be set by SPEC_aot_prologue via SlewCal
    if(verbose) {
        debug_print("MAIN:The full OBS will be performed with filter " + filter);
    }
    // The tuple arrays confOBCP, confSPECred, and confSPECblu play a major
    // role. They contain the parameters related to commanding different PACS
    // subsystems. They are susceptible of changing with the observing conditions.
    // Hence, they have to be watched for changes since these imply sending one or
    // more TCs (usually invoking a building block)
    // Define confOBCP array
    // confOBCP{0 -> 19} contains:
    // nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
    // nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
    // grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
    // chop_pos_SRC     chop_pos_REF1    chop_pos_REF2    chop_pos_CS1
    // chop_pos_CS2     chop_def         detector         order
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confSPECblu and confSPECred
    // confSPEC contains:
    //   capa,       nb_rdouts_ramp, nb_rdouts_subramp, comp_mode,
    //   glitch_det, ramp_fit_alg,   nb_raw,            bias_r,    bias_d
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // Estimator module returns {confSPECblu,confSPECred,confOBCP}
    // Reunite all three tuples into paramsSPECdef
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    // AOT code uses "throwUsage" as a description of allowed chopper throws
    // Here the throw is user defined. Use "large" to please the script and
    // compute the ENG throw below.
    paramsSPECdef = PacsSpecDefaults("large",extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // Convert chopperthrow into into ENG values
    // Take account of desired chopper offset (all in arcsec)
    double chopSRC = chopoffset + chopthrow / 2.0;
    double chopREF = chopoffset - chopthrow / 2.0;
    string convU = "SPEC_CHOP_sky";
    if(src_at_OFF) {
        confOBCP[0]{12} = PacsReadChopSky(convU,chopREF);
        confOBCP[0]{13} = PacsReadChopSky(convU,chopSRC);
    } else {
        // SRC on REF??? SRC back to where it should be
        confOBCP[0]{13} = PacsReadChopSky(convU,chopREF);
        confOBCP[0]{12} = PacsReadChopSky(convU,chopSRC);
    }
    int chop_pos_SRC = confOBCP[0]{12};
    int chop_pos_REF1 = confOBCP[0]{13};
    int chop_pos_REF2 = confOBCP[0]{13};
    confOBCP[0]{14} = confOBCP[0]{13};
    if(verbose) {
        debug_print("CHOPPER SRC: " + chopSRC + " [arcsec]==> " + confOBCP[0]{12});
        debug_print("CHOPPER REF: " + chopREF + " [arcsec]==> " + confOBCP[0]{13});
    }
    if(verbose) {
        debug_print("MAIN.confOBCP[0]: " + confOBCP[0]);
    }
    // User defined parameters
    if(useChopParam) {
        //            confOBCP[0]{3} = nb_SRC_REF;
        confOBCP[0]{4} = nb_ramps_plateau;
    }
    if(useDetParam) {
        confSPECred[0]{0} = capa_red;
        confSPECblu[0]{0} = capa_blu;
        confSPECblu[0]{1} = nb_rdouts_ramps;
        confSPECred[0]{1} = nb_rdouts_ramps;
        confSPECred[0]{2} = nb_rdouts_subramp;
        confSPECblu[0]{2} = nb_rdouts_subramp;
        if(reduction_mode == "ramp average") {
            confSPECblu[0]{5} = 1;
            confSPECred[0]{5} = 1;
        } else {
            if(reduction_mode == "ramp fitting") {
                confSPECred[0]{5} = 0;
                confSPECblu[0]{5} = 0;
            }
        }
    }
    if(useBiasParam) {
        confSPECred[0]{7} = iround(1000.0 * bias_r_red);
        confSPECblu[0]{7} = iround(1000.0 * bias_r_blu);
        confSPECred[0]{8} = iround(1000.0 * bias_d_red);
        confSPECblu[0]{8} = iround(1000.0 * bias_d_blu);
    }
    if(verbose) {
        debug_print("MAIN.Wavelength  : " + lines[0]{1});
        debug_print("MAIN.confOBCP[" + 0 + "]: " + confOBCP[0]);
        debug_print("MAIN.confSPEC[" + 0 + "]: " + confSPECblu[0]);
        debug_print("MAIN.confSPEC[" + 0 + "]: " + confSPECred[0]);
    }
    // Will call PacsSpecSlewCal to perform AOT prologue and CAL during
    // slew to source. Establish an array of key wavelengths, one per order,
    // commensurate with user given wavelengths
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    double[] refWL = [lWave];
    double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    double[] keyWAVE = [keyWL];
    int nbKeyWAVE = 1;
    int realLstGratPos = confOBCP[0]{8};
    int frstLstGratPos = iround(grat_pos[0]) + grat_step[0] * grat_step_size[0] / 2;
    if(verbose) {
        debug_print("MAIN:waveTuple: " + waveTuple);
        debug_print("MAIN:keyWAVES " + keyWAVE);
        debug_print("MAIN:SlewCal should leave grating at: " + frstLstGratPos);
    }
    // Time WriteOBSID
    int tOBSID = duration(WriteOBSID($OBSID));
    // Time needed to perform these activities during slew (includes AOT
    // prologue)
    bool doAOTprologue = true;
    int timeSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel));
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during slew: " + timeSlewCal);
    }
    // timings for initial HOLD 
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    double ramp_time = double(nb_rdouts_ramps) / spec_sample;
    int time_ramps_plateau = iceil(double(nb_ramps_plateau) * ramp_time);
    debug_print("MAIN: time_ramp: " + time_ramps_plateau);
    int chop_pos_def = 664;
    // OBS timing
    //	computing nb_SRC_REF for dwellTimeSRC
    int nb_SRC_REF = 1;
    int t1 = duration(Pacs_Spec_AleFakeOBCP(nb_SRC_REF,time_ramps_plateau,chop_pos_SRC,chop_pos_REF1,chop_pos_def));
    nb_SRC_REF = 5;
    int t2 = duration(Pacs_Spec_AleFakeOBCP(nb_SRC_REF,time_ramps_plateau,chop_pos_SRC,chop_pos_REF1,chop_pos_def));
    //    Slope per unit nb_SRC_REF, offset  
    double slope = double(t2 - t1) / 4.0;
    double offset = double(t1) - slope;
    //   Compute nb_SRC so that OBCP runs during the whole scan leg
    nb_SRC_REF = iceil((double(dwellTimeSRC) - offset) / slope);
    if(useChopParam) {
        confOBCP[0]{3} = nb_SRC_REF;
    }
    int tOBS = duration(Pacs_Spec_AleFakeOBCP(nb_SRC_REF,time_ramps_plateau,chop_pos_SRC,chop_pos_REF1,chop_pos_def));
    debug_print("nb_SRC_REF: " + nb_SRC_REF);
    debug_print("tOBS: " + tOBS);
    debug_print("dwellTimeSRC: " + dwellTimeSRC);
    // offDwellTime so far No chop just stare
    // Final hold and a calibration
    int tfinalCal = duration(PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,realLstGratPos,orderSel));
    // writeEndID
    int timeEndID = duration(WriteEndID());
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int timeEpilogue = duration(SPEC_aot_epilogue(realLstGratPos,grat_park,verbose));
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Ready to issue a FinePointing mode with/without nodding or
    // a RasterReq with/without nodding. Either one will use time during
    // slew to perform SlewCal.
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    // Virtual aperture
    string ib = "P02_0";
    double yoffset = chopSRC;
    double zoffset = 0.0;
    //  For planets, add user given offsets to y,z offsets 
    if(naifid > 0) {
        yoffset = yoffset + 60.0 * planetOffsets[0];
        zoffset = zoffset + 60.0 * planetOffsets[1];
    }
    double skewCorrec = 0.0;
    if(verbose) {
        debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("#### skewCorrec : " + skewCorrec);
    }
    int tslewmin = tOBSID + timeSlewCal;
    int tinithold = 0;
    int tfinalhold = tfinalCal + timeEndID + timeEpilogue;
    int tp = tOBS;
    double pattnod = 270.0 + skewCorrec;
    int k = noOFF;
    //     RasterMode repeated_raster_with_hold_and_OFF, section 3.5
    //     Raster in sky/instrument coordinates
    bool fixed = skyCoord;
    double d1 = pointStep;
    double d2 = lineStep;
    if(noOFF != 0) {
        int top = offDwellTime;
    } else {
        top = 0;
    }
    int nrepeat = 1;
    int trepeatmin = 0;
    int tloadmin = 0;
    int thold = 0;
    int nhold = 0;
    //     SPR-3237 (map orientation parameter) applies only to raster
    double patt = mapRasterAngle;
    int[] fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
    // Parameters returned by PointReq
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Issue PointRequest now");
        debug_print("Return from PointReq: " + fromPntReq);
    }
    //Info from API (nomenclature from Jon Br)
    tobs = fromPntReq[0];
    tslew = fromPntReq[1];
    // tpp time to slew to next point
    tpp = fromPntReq[2];
    // tll time to slew to next line
    tll = fromPntReq[3];
    // tsop is slew to offset or from offset
    tsop = fromPntReq[5];
    // time to slew back to beginning if nrepeat> 1
    trep = fromPntReq[4];
    // tend time to end state==-1
    int tend = fromPntReq[6];
    ///////////////////////// end of "timing" section //////////////////////////
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + userMode);
        int tNOW = time();
        debug_print("=====Issued PointReq Time_now: " + tNOW);
    }
    // Issue TCs
    int[] stateVar = [0];
    int nbOBS = 0;
    int nbOFF = 0;
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            // Write OBSID (logical part of SlewCal)
            WriteOBSID($OBSID);
            PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel);
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW stops at: " + tNOW);
            }
        }
        if(stateVar[0] == 3) {
            if(verbose) {
                tNOW = time();
                debug_print("=== POINT starts at: " + tNOW);
                debug_print("moving the chopper ONLY");
            }
            Pacs_Spec_AleFakeOBCP(nb_SRC_REF,time_ramps_plateau,chop_pos_SRC,chop_pos_REF1,chop_pos_def);
            if(verbose) {
                tNOW = time();
                debug_print("=== POINT stops at: " + tNOW);
            }
        }
        if(stateVar[0] == 4) {
            if(verbose) {
                tNOW = time();
                debug_print("=== OFF starts at: " + tNOW);
                debug_print("Still just acquire data for the moment: no chopper just dwelling");
            }
            if(verbose) {
                tNOW = time();
                debug_print("=== OFF stops at: " + tNOW);
            }
        }
        if(stateVar[0] == 5) {
            if(verbose) {
                tNOW = time();
                debug_print("=== FinalHOLD  starts at: " + tNOW);
                debug_print("== A calibration to finish?");
            }
            PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,realLstGratPos,orderSel);
            SPEC_aot_epilogue(realLstGratPos,grat_park,verbose);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("=== FinalHOLD  ends at: " + tNOW);
            }
        }
        if(stateVar[0] == -1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== AOT  ends at: " + tNOW);
            }
        }
    }
}

// $Id: PacsEng_Phot_SPU_Reset.txt,v 1.5 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_SPU_Reset_u {
    /* No variables to call PacsEng_Phot_SPU_Reset_u                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_SPU_Reset_u                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_SPU_Reset()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_SPU_Reset();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : DMC sequence 7 for OBCP 12: Photometry Calibration III
//                
//
//
// DMC author    : Helmut Feuchtgruber
// CUS script    : Thomas G. Mueller
// CVS file      : photometry_calibration_III.txt
//
// Arguments used by the calling OBCP
// Type  Name               DMCseq  Description   : 
// int   nb_main_loop       p01     number of times main loop is repeated
// int   chop_pos_1         p02     first chopper position
// int   nb_rdouts_plateau  p03     number of readouts per chopper plateau
// int   nb_CS1_CS2_cycles  p04     chopper cycles per incremental step
// int   chop_step_CS1_CS2  p05     Step to go from CS1 to CS2
// int   chop_step_CS2_CS1  p06     Step to go from CS2 to CS1
// int   chop_step_CS1      p07     relative chopper increment on CS1
// int   nb_steps           p08     number of incremental steps
//
// NOTE: For CUS scripts, only the loop parameters are relevant since they 
//       determine the DMC duration
//
// Description :
//       CUS transcription of 4.1.7 "Chopping on Internal Calibration
//       Sources (fixed-fixed)" Detailed calibration sequence on 
//       the internal sources, version III. Chopping is done to a set of
//       positions on both calibration sources, where the distance 
//       between 2 respective positions stays constant for a while
//       and then the next position is being measured.
//       Note: nb_rdouts_plateau must be defined such that: 
//              (nb_rdouts_plateau + 1) mod 4 = 0. 
//              chop_step_CS1_CS2 = -1 * chop_step_CS2_CS1
//       This procedure returns its duration in number of readouts
//       It is up to the calling program to convert number of readouts into 
//       [sec] (this procedure does not know the duration of each readout)
//
//       This procedure generates no TC; its only purpose is to illustrate
//       inner works of the DMC sequence and to compute its duration. Hence
//       it is called with only the duration relevant parameters
//
int[] procedure DMC_phot_cal_III {
    int nb_main_loop = 2; // p01 Number of times main loop is repeated
    int nb_rdouts_plateau = 39; // p03 Number readouts/plateau (4*n-1)
    int nb_CS1_CS2_cycles = 1; // p04 chopper cycles per incremental step
    int nb_steps = 6; // p08 number of incremental steps
}{
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Start tallying the duration (measured in number of readouts)
    int duration_rdouts = 0;
    //
    // WAIT 1 ; have a defined start 
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; set Label to 0 
    // WAIT 1 ; have a defined start 
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LOOP P#1 ; main loop measurement 
    for(int main_loop = 1 .. nb_main_loop) {
        // WAIT 1 ; sync. for chopper 
        duration_rdouts = duration_rdouts + 1;
        duree_OVR = duree_OVR + 1;
        // MOVE_CHOPPER_ABSOLUTE P#2 ; start pos. chopper on BB1 
        // LABEL 65 ; start quadruple on BB1 
        // WAIT P#3 ; take P#3 images 
        duration_rdouts = duration_rdouts + nb_rdouts_plateau;
        duree_CAL = duree_CAL + nb_rdouts_plateau;
        // LOOP P#8 ; loop through increments 
        for(int inner_loop = 1 .. nb_steps) {
            // LOOP P#4 ; do P#4 chops per step 
            for(int cho_cycle_loop = 1 .. nb_CS1_CS2_cycles) {
                // WAIT 1 ; sync. for chopper 
                duration_rdouts = duration_rdouts + 1;
                duree_OVR = duree_OVR + 1;
                // MOVE_CHOPPER_RELATIVE P#5 ; go to BB2 
                // LABEL 129 ; start quadruple on BB2 
                // WAIT P#3 ; take P#3 images 
                duration_rdouts = duration_rdouts + nb_rdouts_plateau;
                duree_CAL = duree_CAL + nb_rdouts_plateau;
                // WAIT 1 ; sync. for chopper 
                duration_rdouts = duration_rdouts + 1;
                duree_OVR = duree_OVR + 1;
                // MOVE_CHOPPER_RELATIVE P#6 ; go back to BB1 
                // LABEL 65 ; start quadruple on BB1 
                // WAIT P#3 ; take P#3 images 
                duration_rdouts = duration_rdouts + nb_rdouts_plateau;
                duree_CAL = duree_CAL + nb_rdouts_plateau;
                // END_LOOP ; end of chop 
            }
            // WAIT 1 ; sync. for chopper 
            duration_rdouts = duration_rdouts + 1;
            duree_OVR = duree_OVR + 1;
            // MOVE_CHOPPER_RELATIVE P#7 ; incr. chop position on BB1
            // WAIT P#3 ; take P#3 images 
            duration_rdouts = duration_rdouts + nb_rdouts_plateau;
            duree_CAL = duree_CAL + nb_rdouts_plateau;
            // END_LOOP ; end of increments loop 
        }
        // END_LOOP ; end main loop 
    }
    // WAIT 1 ; complete last plateau 
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; no sequence anymore 
    // END_SEQUENCE
    // Define return array
    int[] time_array = [duration_rdouts,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    debug_print("DMC_phot_cal_III duration [readouts]: " + duration_rdouts);
    // Return the array of times

    return time_array;
}

// Missionphase  : 
//
// Purpose       : Reset SPU after spectroscopy data flow
//                  
// Author TCL    : Thomas Mueller
// CUS script    : Diego A. Cesarsky
// CVS file      : SPEC_spu_reset.txt
//
// Arguments     : none
//                 
// Description   : Stops SPU and sets default values for compression mode,
//                 several threshold values (glitch, chopper, grating) 
//                 NOTE: amended version only stops SPUs                  
//
// Dependencies  : Only low level PACS TCs 
//                 
// Comments      : Based on V1.3 of TM's tm_spec_spu_reset.tcl
//
// Version       : 0.1 21-Jan-2004 Creation by DAC
// History       : 0.2  8-Oct-2004 Editorial revision (DAC)
//                                 Return duration [milliseconds]
//                 0.3 12-Oct-2004 Removed operations redundant with spu_setup
//                                 leaving only 2xSPUx_STOP_REDUCT_COMPR
//                                 Removed "wait" between TCs
//                 0.4 27-Oct-2004 Put delay statement
//                 1.0 20-nov-2006 Removed "duree" logic
//               :
procedure SPEC_spu_reset {
}{
    // Stop  "blue" and "red"  SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
}

// Missionphase  : FM
//
// Purpose	:  Setup diagnostic housekeeping for the FM 
//                 chopper tests.
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: Set up 12 housekeeping parameter for diagnostic housekeeping 
//	  of the chopper during the chopper full functional test.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and SPEC_Chop_fft_eqmimt_obs
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 3.0	
// 
// History 	: 1.0 21-07-06 creation by HD. Based on EQM IMT scripts.
//	  2.0 24-07-06 HD. test this script.
//        3.0 24-07-06 HD. script works.	  
block SPEC_Chopper_dhk_imt_bb PACS 353 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //-------------------------------------------- 
    // Setup and start diagnostic HK for Chopper
    //-------------------------------------------- 
    int chop_diag_hk_length = 13;
    {int}[] parlist = [{209},{244},{245},{246},{247},{248},{249},{258},{407},{557},{561},{565},{0xffff}];
    int[] aux = [209,244,245,246,247,248,249,258,407,557,561,565,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(chop_diag_hk_length,parlist,check_sum);
    int diag_hk_period = 1;
    // Synchronize diagnostic HK on blue spectrometer readouts
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark End of Block
    WriteEndBB();
    sync();
}

/////////////////////////////////////////////////////////////////////////////
// $Id
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsLineSpec_FPG AOT
//
// CUS author    : DAC
//
// Input arguments: see after module identification
//
// Return values
// {int,int,int} {totalDuration,slewDuration,obsOverPACSandSC}
//
// Comments      : If this file is called PacsLineSpecObs.def, it is the 
//                 CUSGUI version. To use with HSPOT:
//                 - copy and rename PacsLineSpec.def
//                 - rename obs module to PacsLineSpec
//                 - remove extra code for CUSGUI
//                 - do not forget to set verbose = false !!
//
// History: 
// 09-Oct-2009 1.0 PR Created from PacsCal_PacsLineSpec_PV v31.0 (SPR PHS-1212)
//       "     1.1 PR Renamed nodthrowCALUROW in throwCALUROW in order to avoid HSpot interface change 
// 27-10-2009  1.2 VD PHS-1226: BOTH SPU channel enabled: disable PHS-1118
//
{int,int,int} obs PacsCal_PacsLineSpec_FPG {
    /* "lines" is defined as an array; its elements (and hence its dimension) */
    /*  are provided by HSPOT */
    /* {id,redshifted wavelength,repeat factor,line flux,continuum flux,      */
    /*  line width,line flux unit,line width unit}                            */
    {string,double,int,double,double,double,string,string}[] lines = []; //Filled by HSPOT
    /*------------- following only to use CUS interface -------------------------*/
    string[] lineId = ["My lines"];
    double[] lWave = [82.0]; // line wavelength  in [55.0,210.0]
    int[] repeatLine = [1]; // repeat line in [0,10]
    double[] lineFlux = [111.0]; // Line Flux in [0.0,10000.0]
    double[] lcontFlux = [111.11]; // Continuum flux  in [0.0,10000.0]
    double[] lineWidth = [30.0];
    string[] fluxUnit = ["Jy/m2"];
    string[] widthUnit = ["kms"];
    /*------------- above only to use CUS interface -------------------------*/
    string choppedOBCPxx = "OBCP35" in ["OBCP27","OBCP35"];
    int userNODcycles = 1 in [1,100];
    string orderSel = "order2" in ["order2","order3"];
    bool overrideOBCPparams = false;
    /*     bool useScanParam = false; // Overwrite cal-u values for the scan parameters */
    int nb_SRC_OFF = 1; // scan parameter: (SRC_OFF)chop cycles per grating position
    int nb_ramps_plateau = 2; // scan parameter: ramps per chopper plateau 
    int nb_up_down = 1; // scan parameters: nb_up_down cycle
    /* bool useGratParams */
    bool overrideGratparams = false;
    int grat_step_size = 1200; // scan OBCP parameter: grating step size (to center the line, use negative step size)
    int nb_grat_steps = 148; // scan OBCP parameter: nb of grating steps
    /*    bool useCalblockParam = false; // overwrite cal-u values for the calibration block parameters */
    bool overrideCalBlockOBCP35params = false;
    int cb_nb_up_down = 1; // Cal Block: up_down cycle   
    int cb_nb_ramps_plateau = 2; // Cal Block : number of ramps per chopper plateau
    int cb_nb_CS1_CS2 = 1; // Cal Block: (CS1_CS2) chop cycles per grating position
    /* bool override grating params for calblock */
    bool overrideGratSPEC_BAND_paramsCalBlock = false;
    int cb_nb_grat_step = 16; // cal block : number of grating steps around key wavelength
    int cb_grat_step_size = 168; // cal block : grating step size (to center the line, use negative step size)
    /* bool override SPU in CalBlock */
    bool overrideDefaultsCONF_SPEC_param_SPU = false;
    int nbRdoutRamp_red = 64; // cal block: red readouts per ramp
    int nbRdoutRamp_blu = 64; // cal block: blue readouts per ramp   
    int rdouts_subramp_blu = 16; // detector setting: blue number of readouts per subramp 
    int rdouts_subramp_red = 16; // detector setting: red number of readouts per subramp
    int compression_mode_red = 16; // compression mode in red channel
    int compression_mode_blu = 16; // compression mode is blue channel
    int glitch_det_red = 1; // glitch detection algor. for red channel
    int glitch_det_blu = 1; // glitch detection algo. for the blue channel
    int nb_raw_red = 3; // nb of raw pixels used in red channel
    int nb_raw_blu = 3; // nb of raw pixlels used in blue channel
    string reduction_mode = "ramp average" in ["ramp average","ramp fitting"]; // detector setting: spu reduction mode
    /*    bool useBiasParam = false; // Overwrite the detectors BIAS values */
    bool overrideDefaultsCONF_SPEC_param_CRE = false;
    int capaBlue = 0; // detector setting: capacitance blue  in [0,8,4,12]
    int capaRed = 0; // detector setting: capacitance red  in [0,8,4,12]
    double bias_d_blu = 0.2101 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_d_red = 0.0701 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_blu = 0.0101; // Bias "r" blue
    double bias_r_red = 0.0101; // Bias "b" red
    /* override ALL SPU CRE params */
    bool overrideAll_SPU_CRE_params = false; // do you want allow overriding ALL SPU CRE parameters?
    string scenario = "none"; // scenario name: usage in CONF_SPEC_param rows: scenario_Normal0RED/BLU
    /*    bool useWaveSwitchParam = false; // overwrite cal-u values for wavelength switching */
    bool overrideOBCP32param = false;
    int switch_nb_ramps = 1; // P6 wave switching: number of ramps per grating position
    int switch_nb_up_dn = 1; // P1 wave switching: number of up_dn cycles
    int switch_nbABBA = 3; // P4 wave switching: number of ABBA cyles
    int switch_ditherCount = 11; // P2  wave switching: number of grating dither steps
    int switch_dither_step_size = 300; // P3 wave switching: dithering step size
    int switch_param7 = 700; // P#7
    bool chopNod = true;
    bool faintLines = true;
    int nload = 0; // cal block : repeat calibration block every n nod / raster slews   
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    string throw = "large" in ["large","medium","small"]; // CHOP throw
    string throwCALUROW = "medium"; // NOD throw (line read in CALU SPEC_CHOP_params)
    string yzoffsetCALUROW = "mediumS11"; // yzoffset (line read in CALU PACSyzoffset)
    string source = "point" in ["point","dithered","large","large_b"];
    double mapRasterAngle = 0.0 in [0.0,360.0];
    int m = 3 in [2,32];
    int n = 3 in [1,32];
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    bool refSelected = false;
    double raoff = 0.0 in [0.0,360.0];
    double decoff = 0.0 in [-90.0,90.0];
    int naifid = 0; // RA,DEC or SSO
    double pointStep = 20.0 in [2.0,480.0];
    double lineStep = 20.0 in [2.0,480.0];
    int knod = 1; // knod in [1,m*n] 
    int obsOverhead = 180; // Slew overhead
    bool startAtOFF = false;
    bool verbose = true;
}{
    //*--------- following only when using CUS interface -------------------*/
    int linesIdLength = length(lineId);
    int linesLength = length(lines);
    if(linesLength == 0) {
        for(int lLoop00 = 0 .. linesIdLength - 1) {
            lines[lLoop00] = {lineId[lLoop00],lWave[lLoop00],repeatLine[lLoop00],lineFlux[lLoop00],lcontFlux[lLoop00],lineWidth[lLoop00],fluxUnit[lLoop00],widthUnit[lLoop00]};
        }
    }
    //*--------- above only when using CUS interface -------------------*/
    // starting catching conflicts
    if(overrideDefaultsCONF_SPEC_param_SPU && overrideAll_SPU_CRE_params) {
        error("Attention conflicting overriding parameters, Defaults wil override the scenario's setup, choose either: ALL or Defaults");
    }
    if(overrideDefaultsCONF_SPEC_param_CRE && overrideAll_SPU_CRE_params) {
        error("Attention conflicting overriding parameters, Defaults will override the scenario's setup, choose either: ALL or Defaults");
    }
    // PHS-1226
    bool stopUnUsedChannelSPU = false;
    // stop the unused SPU chanel?   
    //*-----------------------------------------------------------------*/
    // Start of "Pointing" section
    // 
    // extraConf: whatever affects PACS default configuration 
    // Currently: the option faintLines calls for an extraConf
    string extraConf = "normal";
    // For bright lines
    if(!faintLines && chopNod) {
        extraConf = "bright";
    } else {
        extraConf = "normal";
    }
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // Need switching boolean
    bool switching = !chopNod;
    // Switching only allowed with source "large"
    if(switching && source != "large") {
        if(switching && source != "large_b") {
            error("Frequency Switch only in mode raster (large source) with OFF");
        }
    }
    // Decode more HSPOT information
    int nbLines = length(lines);
    int nbLines1 = nbLines - 1;
    // Cannot call with empty "lines"
    if(nbLines == 0) {
        error("STOP!! There are no spectral lines defined!");
    }
    // No more than 10 lines or repetitions
    int nbLinesRep = 0;
    for(int loop00 = 0 .. nbLines - 1) {
        //  Default repetion factor is 1
        int repFactor = lines[loop00]{2};
        if(repFactor == 0) {
            repFactor = 1;
        }
        nbLinesRep = nbLinesRep + repFactor;
    }
    if(verbose) {
        debug_print("Total lines/repeat: " + nbLinesRep);
    }
    if(nbLinesRep > 10) {
        error("STOP!! The number of lines/repetitions exceeds 10");
    }
    // Establish now the applicable Pointing Mode (use same pointCase convention
    // used in PacsPhoto)
    // Pointing mode is undefined. If it remains undefined at the end of
    // the next tests, then there is a problem with the source definition
    int pointCase = 0;
    // FinePointingMode with setup time
    // POINT source, with and without chopNod
    if(source == "point") {
        //    For completiness define a 1x1 raster
        m = 1;
        n = 1;
        //    without nodding
        if(!chopNod) {
            string pointMode = "fine_pointing";
            string userMode = "Point source (no nodding)";
            if(switching) {
                userMode = "Point source (frequency switch, no nodding)";
            }
            pointCase = 11;
            string yzoffsetROW = "S" + pointCase;
        } else {
            //    with nodding      
            pointMode = "composite_nodding";
            userMode = "Point source (nodding)";
            pointCase = 12;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // DITHERED source
    // For source "dithered" use predetermined raster parameters
    if(source == "dithered") {
        m = ilookup("SMALL_SRC_params","SPEC","mRast");
        n = ilookup("SMALL_SRC_params","SPEC","nRast");
        pointStep = dlookup("SMALL_SRC_params","SPEC","pointStep");
        lineStep = dlookup("SMALL_SRC_params","SPEC","lineStep");
        //    Raster mode without noding
        if(!chopNod) {
            pointMode = "repeated_raster_with_hold";
            userMode = "Small source (no nodding)";
            pointCase = 21;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Small source (nodding)";
            pointCase = 22;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For source "large" user given raster parameters
    if(source == "large") {
        //    Raster mode without noding
        if(!chopNod) {
            pointMode = "repeated_raster_with_hold";
            userMode = "Large source (no nodding)";
            pointCase = 31;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Large source (nodding)";
            pointCase = 32;
            yzoffsetROW = "S" + pointCase;
        }
    }
    if(source == "large_b") {
        //    Raster mode without noding
        if(!chopNod) {
            pointMode = "raster_pointing";
            userMode = "Large source (raster w/OFF, no nodding)";
            pointCase = 31;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_of_raster";
            userMode = "Large source (nodding)";
            pointCase = 32;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For symmetrical chopping, virtual apertures are dependent on the chopper
    // throw. Add this information to the CALU key entry
    //yzoffsetROW = throw + "" + yzoffsetROW;
    yzoffsetROW = yzoffsetCALUROW;
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("     PointCase ID: " + pointCase);
        debug_print("     PointMode   : " + pointMode);
        debug_print("     CALU entry  : " + yzoffsetROW);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        for(int iii = 0 .. nbLines1) {
            debug_print("MAIN:Id, Wave, repeat, Lflux, Cflux, etc. " + lines[iii]);
        }
    }
    // Define array of wavelengths (will be needed by the SORT procedure)
    double[] lineWave = [55.0];
    // Populate the array of wavelengths
    for(int loop0 = 0 .. nbLines1) {
        lineWave[loop0] = lines[loop0]{1};
    }
    // For each line obtain the grating order and the grating position 
    int[] orders = [0];
    double[] grat_pos = [0.0];
    // Fill the tuple waveTuple {waveLen,order,gratPos,nbStep,gratStep}
    {double,int,int,int,int}[] waveTuple = [{0.0,0,0,0,0}];
    for(int loop1 = 0 .. nbLines1) {
        waveTuple[loop1] = SPEC_get_grat_info(lineWave[loop1],"HI",switching,extraConf,orderSel,verbose);
        //      Create vector of intermediate results
        orders[loop1] = waveTuple[loop1]{1};
        grat_pos[loop1] = double(waveTuple[loop1]{2});
    }
    // To reject forbidden order combination, count how many orders
    int nORDER1 = 0;
    int nORDER2 = 0;
    int nORDER3 = 0;
    for(int loop2 = 0 .. nbLines1) {
        if(orders[loop2] == 1) {
            nORDER1 = nORDER1 + 1;
        }
        if(orders[loop2] == 2) {
            nORDER2 = nORDER2 + 1;
        }
        if(orders[loop2] == 3) {
            nORDER3 = nORDER3 + 1;
        }
    }
    // Reject mixed orders
    if(nORDER2 != 0 && nORDER3 != 0) {
        //    Report band limits
        double[] band2 = SPEC_BAND_read("L2");
        double[] band3 = SPEC_BAND_read("L3");
        error("Combination of 2nd (" + band2[0] + "-" + band2[1] + " mic) and 3rd (" + band3[0] + "-" + band3[1] + " mic) grating orders is not allowed");
    }
    // Reject lines not belonging to authorized order
    if(nORDER2 != 0 && orderSel == "order3") {
        error("You have chosen " + orderSel + " but have specified one/several order2 lines");
    }
    if(nORDER3 != 0 && orderSel == "order2") {
        error("You have chosen " + orderSel + " but have specified one/several order3 lines");
    }
    // Determine the filter needed with given lines
    // No filter needed, i.e. ORDER=1
    int filter = 1;
    // Determine filter based on HSPOT input
    if(orderSel == "order2") {
        filter = 2;
    }
    if(orderSel == "order3") {
        filter = 3;
    }
    if(verbose) {
        debug_print("ORDER array: " + orders);
    }
    // Filter below will be set by SPEC_aot_prologue via SlewCal
    if(verbose) {
        debug_print("MAIN:The full OBS will be performed with filter " + filter);
    }
    // Sort grat_pos from smallest to largest
    int[] sortIndex = SortProc(verbose,grat_pos);
    // Sort by wavelengths (from blue to red)
    // int sortIndex = SortProc(verbose,lineWave);
    // Recast "lines" and waveTuple according to the ordered grating positions
    {string,double,int,double,double,double,string,string}[] sortLines = [{"empty",0.0,0,0.0,0.0,0.0,"bla","bla"}];
    {double,int,int,int,int}[] sortWaveTuple = [{0.0,0,0,0,0}];
    for(int reSORT = 0 .. nbLines1) {
        //      Reversed sort
        // No reverse SORT (start observations with filter A)
        //        int revSORT         = nbLines1 - reSORT;
        int revSORT = reSORT;
        int sortedIndex = sortIndex[revSORT];
        sortLines[reSORT] = lines[sortedIndex];
        sortWaveTuple[reSORT] = waveTuple[sortedIndex];
        if(verbose) {
            debug_print("Sorted Line: " + sortLines[reSORT]);
        }
    }
    // The tuple arrays confOBCP, confSPECred, and confSPECblu play a major
    // role. They contain the parameters related to commanding different PACS
    // subsystems. They are susceptible of changing with the observing conditions.
    // Hence, they have to be watched for changes since these imply sending one or
    // more TCs (usually invoking a building block)
    // Define confOBCP array
    // confOBCP{0 -> 19} contains:
    // nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
    // nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
    // grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
    // chop_pos_SRC     chop_pos_REF1    chop_pos_REF2    chop_pos_CS1
    // chop_pos_CS2     chop_def         detector         order
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // a very long confSPEC/red/blu/SPU tuple ... 
    // Define confSPECblu and confSPECred
    // confSPEC contians:
    //   capa,       nb_rdouts_ramp, nb_rdouts_subramp, comp_mode,
    //   glitch_det, ramp_fit_alg,   nb_raw,            bias_r,    bias_d
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // Estimator module returns {confSPECblu,confSPECred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    // Obtain default values
    string throwUsage = throw;
    // Frequency switch parameters are as for offraster in PacsRange
    // REF1 is not set to be equal to REF2 (relevant OBCP 32)
    if(switching) {
        throwUsage = "offraster";
    }
    if(verbose) {
        debug_print("PacsLine:Use throw: " + throwUsage);
    }
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    double[] refWL = [sortLines[0]{1}];
    double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    double[] keyWAVE = [keyWL];
    // gniark complicated --- do I update PacsSpecdefaults .. I don't want a LONG tuple ... just a scenario
    //  !!! detecor too
    // IMPORTANT NOTE
    //---------------
    // Logic to stop the "non-prime" channel. This is the channel not used by 
    // the KeyWave, making also sure that detector sync follows
    // 
    // PHS-1226 
    // 
    //    bool stopSPUS = false;
    //    bool stopSPUL = false;
    // Channel selection
    //    if(keyWAVE[0] > 100.0) {
    //        stopSPUS = true;
    //        int detector = 2;
    //    }
    //    if(keyWAVE[0] < 100.0) {
    //        stopSPUL = true;
    //        detector = 1;
    //    }
    if(overrideAll_SPU_CRE_params) {
        //        paramsSPECdef = PacsSpecDefaultsSPU(throwUsage,extraConf,detector,stopUnUsedChannelSPU,scenario,verbose);
        paramsSPECdef = PacsSpecDefaultsSPU(throwUsage,extraConf,scenario,verbose);
    } else {
        //    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,detector,verbose);
        paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    }
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    //    confOBCP[0]{18} = detector;
    // Here comes the module(s) to estimate OBS times as a function of the
    // input given by the HSPOT user.
    //Define tuple to contain the "variable" parameters
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPEC = clone(paramsSPECdef);
    // paramsSPECext (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,nb_up_dn,aux1,aux2}
    // More info: {nb_nods,nb_up_dn,timeOBS,aux2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for each wavelength. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("MAIN.confOBCP[0]: " + confOBCP[0]);
    }
    int nbNods = 0;
    // Accumulator total OBS time
    int totalOBS = 0;
    // For each demanded wavelength compute minimum duration
    for(int waveLOOP = 1 .. nbLines) {
        int waveLOOP1 = waveLOOP - 1;
        //    Different OBCPs if frequency switch or not
        if(chopNod) {
            // Here we perform nodding/chopping
            // SCR-2942: consider case of faintLines = false
            string forDEBUG = "chop/nod";
            if(choppedOBCPxx == "OBCP35") {
                // implement OBCP35 for test indem OBCP27 carefull OBCPconf parameters order
                paramsSPECext = PacsLineSpecEstimatorOBCP35(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,chopNod,faintLines,verbose);
            } else {
                if(choppedOBCPxx == "OBCP27") {
                    paramsSPECext = PacsLineSpecEstimatorOBCP27(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,chopNod,faintLines,verbose);
                }
            }
            //      Copy estimates to respective tuples
            confSPECblu[waveLOOP] = paramsSPECext{0};
            confSPECred[waveLOOP] = paramsSPECext{1};
            confOBCP[waveLOOP] = paramsSPECext{2};
            //            confOBCP[waveLOOP]{18} = detector;
            if(overrideOBCPparams) {
                confOBCP[waveLOOP]{0} = nb_up_down;
                confOBCP[waveLOOP]{3} = nb_SRC_OFF;
                confOBCP[waveLOOP]{4} = nb_ramps_plateau;
            }
            if(overrideGratparams) {
                confOBCP[waveLOOP]{1} = grat_step_size;
                confOBCP[waveLOOP]{2} = -grat_step_size;
                confOBCP[waveLOOP]{6} = nb_grat_steps;
                confOBCP[waveLOOP]{7} = nb_grat_steps;
            }
        } else {
            // Here we perform frequency switching
            forDEBUG = "freq/switch";
            // SPR-2926: Use userNODcycles as overall multiplier for repeatLine
            // No longer true with raster+OFF; repeat raster instead
            paramsSPECext = PacsLineSpecEstimatorOBCP32(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,verbose);
            //      Copy estimates to respective tuples
            confSPECblu[waveLOOP] = paramsSPECext{0};
            confSPECred[waveLOOP] = paramsSPECext{1};
            confOBCP[waveLOOP] = paramsSPECext{2};
            //            confOBCP[waveLOOP]{18} = detector;
            if(overrideOBCP32param) {
                confOBCP[waveLOOP]{1} = switch_param7;
                confOBCP[waveLOOP]{2} = switch_nbABBA;
                confOBCP[waveLOOP]{4} = switch_nb_ramps;
                confOBCP[waveLOOP]{0} = userNODcycles * switch_nb_up_dn;
                confOBCP[waveLOOP]{6} = switch_ditherCount;
                confOBCP[waveLOOP]{7} = switch_ditherCount;
                confOBCP[waveLOOP]{9} = switch_dither_step_size;
            }
        }
        if(overrideCalBlockOBCP35params) {
            confOBCP[0]{0} = cb_nb_up_down;
            confOBCP[0]{5} = cb_nb_CS1_CS2;
            confOBCP[0]{4} = cb_nb_ramps_plateau;
        }
        if(overrideGratSPEC_BAND_paramsCalBlock) {
            confOBCP[0]{6} = cb_nb_grat_step;
            confOBCP[0]{7} = cb_nb_grat_step;
            confOBCP[0]{1} = -cb_grat_step_size;
            confOBCP[0]{2} = cb_grat_step_size;
        }
        // Warning complicated !!!!	   
        if(overrideDefaultsCONF_SPEC_param_SPU) {
            // here comes the SPU and CRE setup: calibration block
            confSPECblu[0]{1} = nbRdoutRamp_blu;
            confSPECred[0]{1} = nbRdoutRamp_red;
            confSPECred[0]{2} = rdouts_subramp_blu;
            confSPECblu[0]{2} = rdouts_subramp_red;
            confSPECred[0]{3} = compression_mode_red;
            confSPECblu[0]{3} = compression_mode_blu;
            confSPECred[0]{4} = glitch_det_red;
            confSPECblu[0]{4} = glitch_det_blu;
            confSPECred[0]{6} = nb_raw_red;
            confSPECblu[0]{6} = nb_raw_blu;
            //            if(nbRdoutRamp_blu >= nbRdoutRamp_red) {
            //                int detector = 1;
            //                confOBCP[0]{18} = detector;
            //            }
            //            if(nbRdoutRamp_blu < nbRdoutRamp_red) {
            //                detector = 2;
            //                confOBCP[0]{18} = detector;
            //            }
            // the same for SCI OBCPs
            confSPECblu[waveLOOP]{1} = nbRdoutRamp_blu;
            confSPECred[waveLOOP]{1} = nbRdoutRamp_red;
            confSPECred[waveLOOP]{2} = rdouts_subramp_blu;
            confSPECblu[waveLOOP]{2} = rdouts_subramp_red;
            confSPECred[waveLOOP]{3} = compression_mode_red;
            confSPECblu[waveLOOP]{3} = compression_mode_blu;
            confSPECred[waveLOOP]{4} = glitch_det_red;
            confSPECblu[waveLOOP]{4} = glitch_det_blu;
            confSPECred[waveLOOP]{6} = nb_raw_red;
            confSPECblu[waveLOOP]{6} = nb_raw_blu;
            //            if(nbRdoutRamp_blu >= nbRdoutRamp_red) {
            //                detector = 1;
            //                confOBCP[waveLOOP]{18} = detector;
            //            }
            //            if(nbRdoutRamp_blu < nbRdoutRamp_red) {
            //                detector = 2;
            //                confOBCP[waveLOOP]{18} = detector;
            //            }
        }
        if(overrideDefaultsCONF_SPEC_param_CRE) {
            // 
            confSPECred[0]{0} = capaRed;
            confSPECblu[0]{0} = capaBlue;
            confSPECred[0]{7} = iround(1000.0 * bias_r_red);
            confSPECblu[0]{7} = iround(1000.0 * bias_r_blu);
            confSPECred[0]{8} = iround(1000.0 * bias_d_red);
            confSPECblu[0]{8} = iround(1000.0 * bias_d_blu);
            if(reduction_mode == "ramp average") {
                confSPECblu[0]{5} = 1;
                confSPECred[0]{5} = 1;
            } else {
                if(reduction_mode == "ramp fitting") {
                    confSPECred[0]{5} = 0;
                    confSPECblu[0]{5} = 0;
                }
            }
            confSPECred[waveLOOP]{0} = capaRed;
            confSPECblu[waveLOOP]{0} = capaBlue;
            confSPECred[waveLOOP]{7} = iround(1000.0 * bias_r_red);
            confSPECblu[waveLOOP]{7} = iround(1000.0 * bias_r_blu);
            confSPECred[waveLOOP]{8} = iround(1000.0 * bias_d_red);
            confSPECblu[waveLOOP]{8} = iround(1000.0 * bias_d_blu);
            if(reduction_mode == "ramp average") {
                confSPECblu[waveLOOP]{5} = 1;
                confSPECred[waveLOOP]{5} = 1;
            } else {
                if(reduction_mode == "ramp fitting") {
                    confSPECred[waveLOOP]{5} = 0;
                    confSPECblu[waveLOOP]{5} = 0;
                }
            }
        }
        //      Accumulate total OBS time
        totalOBS = totalOBS + paramsSPECext{3}{2};
        if(verbose) {
            debug_print("MAIN.confOBCP[0]: " + confOBCP[0]);
            debug_print("MAIN.Obs mode    : " + forDEBUG);
            debug_print("MAIN.Wavelength  : " + sortLines[0]{1});
            debug_print("MAIN.confOBCP[" + waveLOOP + "]: " + confOBCP[waveLOOP]);
            debug_print("MAIN.confSPEC[" + waveLOOP + "]: " + confSPECblu[waveLOOP]);
            debug_print("MAIN.confSPEC[" + waveLOOP + "]: " + confSPECred[waveLOOP]);
        }
    }
    if(verbose) {
        debug_print("MAIN.Minimum required time: " + totalOBS + " [sec]");
    }
    if(chopNod) {
        // Here we perform nodding/chopping
        nbNods = userNODcycles;
        if(verbose) {
            debug_print("MAIN.The PointReq will contain " + nbNods + " nod cycles");
        }
    } else {
        // Here we perform freq switch
        nbNods = 0;
    }
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Minimum required OBStime: " + totalOBS + " [sec]</p>";
    lineCnt = lineCnt + 1;
    int nodTotal = nbNods * totalOBS;
    if(chopNod) {
        msgLine[lineCnt] = "<p>With the specified NOD count, " + nbNods + ", the total OBS time amounts to " + nodTotal + "[sec]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Since no NOD was specified the total OBS time is equal" + " to the minimum required time. The time can be changed" + " by changing the line(s) repeat factor</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("Accumulated SRC+REF time estimation",lineCnt,msgLine);
    // Messages on general Detector/SPU parameters
    lineCnt = 0;
    msgLine[lineCnt] = "<p>Red channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECred[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    int subRamps = confSPECred[0]{1} / confSPECred[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECred[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECred[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Blue channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECblu[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    subRamps = confSPECblu[0]{1} / confSPECblu[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECblu[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECblu[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Selected PACS setup parameters",lineCnt,msgLine);
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source
    // First operation is to set the OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // Will call PacsSpecSlewCal to perform AOT prologue and CAL during
    // slew to source. Establish an array of key wavelengths, one per order,
    // commensurate with user given wavelengths
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    //    int order4key = sortWaveTuple[0]{1};
    //    double[] refWL = [sortLines[0]{1}];
    //    string keyOrder = "order" + order4key;
    //    double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    //    double[] keyWAVE = [keyWL];
    // double[] keyWAVE = PacsLineSpecKeyWaves(sortWaveTuple);
    //    int nbKeyWAVE = length(keyWAVE); == 1 
    int nbKeyWAVE = 1;
    // With current versions of CommandOBCP27 and CommandOBCP32, the grating is
    // supposed to be left by SlewCal at the position needed for the 1st line
    // The OBCPs will leave the grating at that same position
    int frstLstGratPos = confOBCP[1]{8};
    if(verbose) {
        debug_print("MAIN:SortWaveTuple: " + sortWaveTuple);
        debug_print("MAIN:keyWAVES " + keyWAVE);
        debug_print("MAIN:SlewCal should leave grating at: " + frstLstGratPos);
    }
    // To stop unused channel we need
    // PHS-1226
    //    int timeToStop = duration(SPEC_spu_channel_stop(stopSPUS,stopSPUL,verbose));
    // Time needed to perform these activities during slew (includes AOT
    // prologue) ...
    bool doAOTprologue = true;
    if(overrideAll_SPU_CRE_params) {
        int timeSlewCal = duration(PacsSpecSlewCalSPU(verbose,scenario,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel));
    } else {
        timeSlewCal = duration(PacsSpecSlewCal_override(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalBlockOBCP35params));
    }
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during slew: " + timeSlewCal);
    }
    // CAL for HOLD 
    doAOTprologue = false;
    if(overrideAll_SPU_CRE_params) {
        int timeHoldCal = duration(PacsSpecSlewCalSPU(false,scenario,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,0,frstLstGratPos,orderSel));
    } else {
        timeHoldCal = duration(PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,0,frstLstGratPos,orderSel,overrideCalBlockOBCP35params));
    }
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during HOLD: " + timeHoldCal);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsSpecCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsSpecCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // IMPORTANT NOTE: the duration could be different for the first cycle through 
    // all wavelengths than for the following ones owing to differing initial state.
    // However, all steps have been taken so that PACS starts the actual observation
    // in the same state as it would be left at the end of any wavelength cycle
    // Duration of any nod leg or staring observation
    // Different OBCP for wavelength switch
    if(!switching) {
        // Here we perform nodding/chopping
        if(choppedOBCPxx == "OBCP35") {
            int timeOBS = duration(PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,verbose));
            if(verbose) {
                debug_print("Duration OBCP35: " + timeOBS + " [sec] per pointing;  nbNods: " + nbNods);
            }
        }
        if(choppedOBCPxx == "OBCP27") {
            timeOBS = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
            if(verbose) {
                debug_print("Duration OBCP27: " + timeOBS + " [sec] per pointing;  nbNods: " + nbNods);
            }
        }
    } else {
        // Here we perform freq switch
        timeOBS = duration(PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,verbose));
        if(verbose) {
            debug_print("Duration OBCP32: " + timeOBS + " [sec] per pointing");
        }
    }
    // Get duration of module to close AOT operations
    // This includes parking the grating
    // Park position
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // The grating was left by OBCPs at frstLstGratPos
    int timeEpilogue = duration(SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose));
    // WriteEndID will be the last TC; get its duration
    int timeEndID = duration(WriteEndID());
    // Summary of relevant data collected so far
    // timeSlewCal: duration of the leading CAL, including AOT_prologue
    // timeOBS    : duration of a single pointed OBS
    // nb_nods    : number of nods for staring mode or per raster position
    // chopNod : invoke nodding or not (nb_nods = 0 is equivalent to no nod)
    // m, n       : raster nb_points/line, nbLines per RREQ
    // pointStep,lineStep: more raster parameters
    // ra,dec: more pointing parameters
    //
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Ready to issue a FinePointing mode with/without nodding or
    // a RasterReq with/without nodding. Either one will use time during
    // slew to perform SlewCal.
    //
    // The chopper step has been read already (PacsSpecDefaults). However,
    // there are no provisions to carry that information here. Easiest is to
    // read again the relevant CAL-U table. Read chopper position SRC and
    // REF1 [arcsec]
    double chopAngleSrc = dlookup("SPEC_CHOP_params",throwCALUROW,"SRC");
    double chopAngleRef = dlookup("SPEC_CHOP_params",throwCALUROW,"REF1");
    // The total nodThrow = chopperTotalThrow
    double nodThrow = abs(chopAngleSrc - chopAngleRef);
    if(verbose) {
        debug_print("PacsSpecDef: CHOP/NOD params SRC/REF/NOD: " + chopAngleSrc + "/" + chopAngleRef + "/" + nodThrow);
    }
    // Issue pointing request (when possible use JBr's variable names for clarity)
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    // Virtual aperture
    string ib = "P02_0";
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("#### skewCorrec : " + skewCorrec);
    }
    if(stopUnUsedChannelSPU) {
        int tslewmin = timeSetOBSID + timeSlewCal;
    } else {
        tslewmin = timeSetOBSID + timeSlewCal;
    }
    int tinithold = 0;
    int tfinalhold = timeEndID + timeEpilogue;
    int tp = timeOBS;
    double patt = 0.0;
    double pattnod = 270.0 + skewCorrec;
    int k = 0;
    int thold = 0;
    int nhold = 0;
    nload = 0;
    int tloadslewmin = 0;
    bool fixed = true;
    // FinePointingMode with setup time
    if(pointCase == 11) {
        //     FinePointingMode without nodding     
        int[] fromPntReq = basic_fine_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,yoffset,zoffset,tp);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        int tend = fromPntReq[2];
    }
    if(pointCase == 12) {
        //     FinePointingMode without nodding, section 3.4     
        ib = "P02_0";
        //     Nodding is specified wrt spacecraft
        fixed = false;
        //     Nodding is along y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        fromPntReq = nodding_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nbNods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tnod = fromPntReq[2];
        tss = fromPntReq[3];
        tload = fromPntReq[4];
        tend = fromPntReq[5];
    }
    if(pointCase == 21 || pointCase == 31) {
        //     RasterMode repeated_raster_with_hold_and_OFF, section 3.5
        ib = "P02_0";
        //     Raster in instrument coordinates
        fixed = false;
        double d1 = pointStep;
        double d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        k = 0;
        int top = 0;
        if(!switching && pointCase == 21) {
            raoff = 0.0;
            decoff = 0.0;
        }
        int nrepeat = 1;
        //     If switching for "large" source perform OFF observation
        if(switching || pointCase == 31) {
            //        Repeat raster according to userNODcycles
            nrepeat = userNODcycles;
            k = n * m;
            top = tp;
        }
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        //     SPR-3237 (map orientation parameter) applies only to raster
        if(pointCase == 31) {
            fixed = true;
            patt = mapRasterAngle;
        }
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
        // XY-stage variables
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        tsop = fromPntReq[5];
        trep = fromPntReq[4];
        tend = fromPntReq[6];
    }
    if(pointCase == 22 || pointCase == 32 && source != "large_b") {
        //     Raster mode w/nodding, section 3.6
        ib = "P02_0";
        //     Raster in instrument coordinates
        fixed = false;
        //     Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        //     Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        k = 0;
        nrepeat = 1;
        //     New arguments for pointing request; will be dealt with next iteration
        top = 0;
        raoff = 0.0;
        decoff = 0.0;
        trepeatmin = 0;
        tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nbNods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
        tend = fromPntReq[9];
    }
    if(pointCase == 32 && source == "large_b") {
        //    Nodding of Raster, section 3.6
        ib = "P02_0";
        //   Raster in instrument coordinates
        fixed = false;
        //   Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        //   Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        //        k = m * n;
        int ncycles = userNODcycles;
        nrepeat = 1;
        tloadmin = 0;
        fromPntReq = nodding_of_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,pattnod,nodThrow,ncycles,knod,nrepeat,tloadmin,nload);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
        tend = fromPntReq[9];
    }
    // Parameters returned by PointReq
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Issue PointRequest now");
        debug_print("Return from PointReq: " + fromPntReq);
    }
    //Info from API (nomenclature from Jon Br)
    tobs = fromPntReq[0];
    tslew = fromPntReq[1];
    ///////////////////////// end of "timing" section //////////////////////////
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
        int tNOW = time();
        debug_print("=====Issued PointReq Time_now: " + tNOW);
    }
    // Issue TCs
    int[] stateVar = [0];
    int nbOBS = 0;
    int nbOFF = 0;
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            //       Write OBSID (logical part of SlewCal)
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            if(overrideAll_SPU_CRE_params) {
                int[][] calTime = PacsSpecSlewCalSPU(false,scenario,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel);
            } else {
                calTime = PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalBlockOBCP35params);
            }
            //          Stop unused SPU
            // PHS-1226
            //            if(stopUnUsedChannelSPU) {
            //                SPEC_spu_channel_stop(stopSPUS,stopSPUL,verbose);
            //            }
            //       Define accumulated Cal time
            int[][] sumUpCalTime = calTime;
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW ends at: " + tNOW);
                debug_print("    SumUpCalTime: " + sumUpCalTime);
            }
        } else {
            if(stateVar[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== POINT starts at: " + tNOW);
                }
                //       Regular OBCP or frequency switched OBCP?
                if(!switching) {
                    if(choppedOBCPxx == "OBCP35") {
                        int[][] obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                    }
                    if(choppedOBCPxx == "OBCP27") {
                        obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                    }
                } else {
                    obsTime = PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                }
                nbOBS = nbOBS + 1;
                //       Logic to sum up obsTime
                if(nbOBS == 1) {
                    int[][] sumUpObsTime = obsTime;
                }
                if(nbOBS > 1) {
                    sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("    SumUpObsTime: " + sumUpObsTime);
                    debug_print("=== POINT ends at: " + tNOW);
                }
            } else {
                if(stateVar[0] == 4) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF starts at: " + tNOW);
                    }
                    //       Regular OBCP or frequency switched OBCP?
                    if(!switching) {
                        if(choppedOBCPxx == "OBCP35") {
                            PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                        }
                        if(choppedOBCPxx == "OBCP27") {
                            ///            obsTime =  
                            PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                        }
                    } else {
                        ///            obsTime =  
                        PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                    }
                    nbOFF = nbOFF + 1;
                    //       Logic to sum up obsTime
                    ///         if (nbOFF == 1) {sumUpObsTime = obsTime;}
                    ///         if (nbOFF > 1)  {sumUpObsTime = SumFunction(obsTime,sumUpObsTime);}
                    if(verbose) {
                        tNOW = time();
                        ///          debug_print("    SumUpObsTime: " + sumUpObsTime);
                        debug_print("=== OFF ends at: " + tNOW);
                    }
                } else {
                    if(stateVar[0] == 7) {
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== NOD starts at: " + tNOW);
                        }
                        if(choppedOBCPxx == "OBCP35") {
                            obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                        }
                        if(choppedOBCPxx == "OBCP27") {
                            obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                        }
                        nbOBS = nbOBS + 1;
                        //       Logic to sum up obsTime
                        if(nbOBS == 1) {
                            sumUpObsTime = obsTime;
                        }
                        if(nbOBS > 1) {
                            sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                        }
                        if(verbose) {
                            tNOW = time();
                            debug_print("    SumUpObsTime: " + sumUpObsTime);
                            debug_print("=== NOD ends at: " + tNOW);
                        }
                    } else {
                        if(stateVar[0] == 6) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== HOLD starts at: " + tNOW);
                            }
                            if(overrideAll_SPU_CRE_params) {
                                calTime = PacsSpecSlewCalSPU(false,scenario,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel);
                            } else {
                                calTime = PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalBlockOBCP35params);
                            }
                            sumUpCalTime = SumFunction(calTime,sumUpCalTime);
                            if(verbose) {
                                tNOW = time();
                                debug_print("    SumUpCalTime: " + sumUpCalTime);
                                debug_print("=== HOLD ends at: " + tNOW);
                            }
                        } else {
                            if(stateVar[0] == 5) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== FinalHOLD  starts at: " + tNOW);
                                }
                                SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose);
                                WriteEndID();
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== FinalHOLD  ends at: " + tNOW);
                                }
                            } else {
                                if(stateVar[0] == -1) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== AOT  ends at: " + tNOW);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    if(verbose) {
        debug_print("OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("Ending with NbOFF: " + nbOFF);
    }
    // The original concept of returning durations did not take into 
    // account the bandwidth of the TC bus (2 TCs/sec). The "real" 
    // duration is given by the result from the "duration()" function. Hence
    // the true total duration of the SlewCal phase is given by
    ///   calTime[0] = timeSlewCal;
    // as a result, the overheads are now
    ///   calTime[4] = calTime[0]-(calTime[1]+calTime[2]+calTime[3]); 
    if(verbose) {
        debug_print("Slew & HOLD Cal return: " + sumUpCalTime);
    }
    // The same holds true for the OBCP27 phase. However, I cannot make the
    // break-down by wavelength (the OBCP27 duration is given for ALL lines).
    // We may add up the SRC, CAL, and OVR components of OBCP27 duration. For
    // this we need a tuple so we can add the wavelength and other relevant
    // information to the (per wave) duration arrays.
    //
    //  infoArray[] contains a "fixed" global information part
    //  infoArray[0]: {Slew,   intTime,TotDur,nbRanges,nnods,m*n}
    //  infoArray[1]: {Point,  intTime,TotDur,nbRanges,nnods,m*n}
    //  infoArray[2]: {AOTinfo,intTime,TotDur,nbRanges,nnods,m*n}
    //
    // and a per wavelength array:
    //    [waveSTART,waveEND,order,gratStep,nbGratStep,TOT,SRC,REF,CAL,OVR]
    // TotDur as given by duration(); TOT,SRC,REF,CAL,OVR are also in [sec]
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    // Fill 1st dimension of infoArray with data from SlewCal
    // Instead of using timeSlewCal, use tslew time returned by PointReq
    // infoArray[0] = {{"SlewCal",0.0,timeSlewCal,0,0,0},[{0.,0.,0,0,0,0,0,0,0,0}]};
    infoArray[0] = {{"SlewCal",0.0,tslew,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Compute integration time per chopper plateau
    // intTime = nbRamps/plateau x nbRdouts/ramp x sampleInterval 
    // Sampling frequency
    double specSample = dlookup("PACSparams","spec_sample","freq_time");
    // Number of readouts per ramp
    int nbRdoutRamp = confSPECblu[1]{1};
    // NOTE: WAIT=1 are now counted as useful ramps; hence
    int wait1 = 1;
    // but there is no wait in FreqSwitch
    // Count the WAIT=1 for grating as a useful SRC
    if(switching) {
        wait1 = 1;
    }
    int nbRampPlateau = confOBCP[1]{4} + wait1;
    // 
    double intTime = double(nbRampPlateau * nbRdoutRamp) / specSample;
    if(verbose) {
        debug_print("MAIN:AOT          : " + userMode);
        debug_print("MAIN:Rdouts/ramp  : " + nbRdoutRamp);
        debug_print("MAIN:Ramps/plateau: " + nbRampPlateau);
        debug_print("MAIN:IntTime      : " + intTime);
    }
    // Replace timeOBS (per raster and per nod) with tobs from PntReq (matching
    // change in PacsProcessInfoArray)   
    // infoArray[1] = {{userMode,intTime,timeOBS,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    infoArray[1] = {{userMode,intTime,tobs,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    for(int loop3 = 0 .. nbLines1) {
        //     for some reason it has to be "initialized"
        infoArray[1]{1}[loop3] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the START wavelength (for LINE START = END = line wave)
        infoArray[1]{1}[loop3]{0} = sortLines[loop3]{1};
        //     copy the END   wavelength (for LINE START = END = line wave)
        infoArray[1]{1}[loop3]{1} = sortLines[loop3]{1};
        //     copy the grating order
        infoArray[1]{1}[loop3]{2} = sortWaveTuple[loop3]{1};
        //     copy the grating step
        infoArray[1]{1}[loop3]{3} = sortWaveTuple[loop3]{4};
        infoArray[1]{1}[loop3]{3} = (confOBCP[loop3 + 1]{2} - confOBCP[loop3 + 1]{1}) / 2;
        //     copy the number of grating steps
        infoArray[1]{1}[loop3]{4} = confOBCP[loop3 + 1]{6};
        //     copy other data from sumUpObsTime
        infoArray[1]{1}[loop3]{5} = sumUpObsTime[loop3][0];
        infoArray[1]{1}[loop3]{6} = sumUpObsTime[loop3][1];
        infoArray[1]{1}[loop3]{7} = sumUpObsTime[loop3][2];
        infoArray[1]{1}[loop3]{8} = sumUpObsTime[loop3][3];
        infoArray[1]{1}[loop3]{9} = sumUpObsTime[loop3][4];
    }
    // Also data from SlewCal to infoArray
    for(int loop4 = 0 .. nbKeyWAVE - 1) {
        //     for some reason it has to be "initialized"
        infoArray[0]{1}[loop4] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the wavelength
        infoArray[0]{1}[loop4]{0} = keyWAVE[loop4];
        //     copy other data from sumUpCalTimeTime
        infoArray[0]{1}[loop4]{5} = sumUpCalTime[loop4][0];
        infoArray[0]{1}[loop4]{6} = sumUpCalTime[loop4][1];
        infoArray[0]{1}[loop4]{7} = sumUpCalTime[loop4][2];
        infoArray[0]{1}[loop4]{8} = sumUpCalTime[loop4][3];
        infoArray[0]{1}[loop4]{9} = sumUpCalTime[loop4][4];
    }
    // Further update of infoArray: add information from AOT_prologue    
    infoArray[0]{1}[nbKeyWAVE] = {0.0,0.0,0,0,0,0,0,0,0,0};
    //   Copy OVR and TOT times
    infoArray[0]{1}[nbKeyWAVE]{9} = calTime[nbKeyWAVE][4];
    infoArray[0]{1}[nbKeyWAVE]{5} = calTime[nbKeyWAVE][4];
    //   Copy the number of lines observed and the number of key waves used
    infoArray[0]{0}{3} = nbKeyWAVE;
    infoArray[1]{0}{3} = nbLines;
    //   Copy the number of nod cycles and the number of raster points visited
    infoArray[1]{0}{4} = nbNods;
    infoArray[1]{0}{5} = m * n;
    // The duration of the OBS phase is given by timeObsEnd - timeSlewCal
    // Now get it from PntReq: timeObsPhase == tobs
    // int timeObsPhase = timeObsEnd - timeSlewCal;
    // Slew time during the OBS phase is then given by
    int timeSlewObs = tobs - nbOBS * timeOBS;
    if(verbose) {
        debug_print("CalSlew phase lasted [sec]: " + timeSlewCal);
        debug_print("The OBS phase lasted [sec]: " + tobs);
        debug_print("Total slew during OBS [sec]: " + timeSlewObs);
    }
    // Fill 3rd dimension of infoArray with global timing and AOT information
    // timeObsEnd is the total duration of the AOT
    // Pass details of AOT
    // change of OBCP
    // We use OBCP27: OBCP_grat_scan_chop2 or grat_line_scan_chop_3 (unless FreqSwitch)
    if(choppedOBCPxx == "OBCP35") {
        string aotName = "GratLineScanChop3";
    }
    if(choppedOBCPxx == "OBCP27") {
        aotName = "GratScanChop2";
    }
    // Special "sky time"  for FreqSwitch and SmallSourceDither
    if(switching) {
        aotName = "FreqSwitch";
    }
    if(source == "dithered") {
        infoArray[1]{0}{0} = "SmSrcDither";
    }
    infoArray[2] = {{aotName,0.0,timeObsEnd,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Use available entries to convey m,n, and nbNods
    infoArray[2]{0}{3} = m;
    infoArray[2]{0}{4} = n;
    // PointSources are also seen with composite_nodding
    if(pointMode == "fine_pointing" || pointMode == "composite_nodding") {
        infoArray[2]{0}{3} = 1;
        infoArray[2]{0}{4} = 1;
    }
    infoArray[2]{0}{5} = nbNods;
    // If switching 
    if(switching && source == "Large") {
        infoArray[1]{0}{0} = "RasterOFF";
    } else {
        if(switching && source == "Point") {
            infoArray[1]{0}{0} = "Pointed";
        }
        infoArray[2]{0}{5} = userNODcycles;
    }
    // Process the information contained in infoArray (pass also sortLines)
    PacsProcessInfoArrayLine(infoArray,sortLines,confOBCP,obsOverhead,nbOBS,nbOFF,verbose);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    // Compute the total time SRC + REF
    int accumSrceRef = 0;
    for(int loopL = 0 .. nbLines - 1) {
        //   Add up Srce and Ref times (SRC + REF)
        accumSrceRef = accumSrceRef + infoArray[1]{1}[loopL]{6} + infoArray[1]{1}[loopL]{7};
    }
    // Compute overheads as total "sky" time minus SRC+REF time
    int overPACSandSC = fromPntReq[0] - accumSrceRef;
    // Return demanded tuples

    return {accumSrceRef,fromPntReq[1],overPACSandSC};
}

// Missionphase  : FM ILT
//
// Purpose	 : Synchronise on blue spectrometer readout
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : Sets default blue spectrometer readout setting 
//                  
// Dependencies  : Used mostly for chopper SFT
//
// Comments	 : Adapted from PACS_Chopper_SFT_Init_Cold.cus
//
// Version	 : 1.0
// 
// History 	 : 1.0 09-03-07 creation by MN
// Begin Mode description
procedure SPEC_Chopper_SynchBlue {
}{
    {int}[] list_tuple = [{0x0},{0x0},{0x0},{26},{0x95217cb},{0xb}];
    int[] list_int = [0x0,0x0,0x0,26,0x95217cb,0xb];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_TIMING_FPGA_PAR(list_tuple,chksum);
    delay(1);
}

// Missionphase  : FM
//
// Purpose	: Move chopper to absolute position
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  is called.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and chopper enabled.
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 3.0	
// 
// History 	: 1.0 21-07-05 creation by HD. Based on EQM IMT script 
//	                         "Chop_mov_abs.txt"
//                2.0 24-07-06 HD. test this script.
//                3.0 24-07-06 HD. script works.
//                3.1 21-jan-2008 DAC Added WriteEndBB
block PACS_Chopper_mov_abs_fm_bb PACS 355 {
    int chop_abs_pos = 0; // chopper absolute position
}{
    // Register start of BB
    WriteBBID($BBID);
    Pacs_DMC_MOVE_CHOP_ABS(chop_abs_pos);
    // Signal end of BB
    WriteEndBB();
}

// Mission phase : Commissioning Phase
//
// Purpose : First measurement of the telescope background
//           during the Commissioning Phase with variable VH_BLIND
//
// Author : Koryo Okumura
//
// CUS script : obs PacsCal_Phot_telescBack
//
// Argument :
//   double[] dvls = [0.0,-0.5,-1.0]; // VL offset values to explore
//   double[] vhbs = [2.4, 2.25, 2.1, 1.95, 1.8]; // VH_BLIND values to explore
//   int measure_time = 60; // measure time in seconds
//   string startBiasTable = "BOLObias_firstTelescBack"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
//   double ra = 267.292; // RA : 17h49m10.0s
//   double dec = 69.807; // DEC : 69d48m26.0
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description : PacsCal script of Phot_telescBack
//
// Dependencies : PCD req.1.1.1bis ILT data for bias computation
//
// Comments : None
//
// Version :
//   Fri Jun 27 2008 KO, First try
//   Thu Jul 03 2008 KO, Pacs_OBCP_chopped_photometry added before and after
//   Thu Jul 04 2008 KO, Pacs_OBCP_chopped_photometry added also during slew
//   Tue Jul 08 2008 KO, Default pointing set as PV phase plan document
//   Thu Apr 30 2009 KO, New argument dvls added in Phot_telescBack
//   Mon May 04 2009 KO, Unused argument endBiasTable removed
//
obs PacsCal_Phot_telescBack {
    double[] dvls = [0.0,-0.5,-1.0]; // VL offset values to explore
    double[] vhbs = [2.4,2.25,2.1,1.95,1.8]; // VH_BLIND values to explore
    int measure_time = 60; // measure time in seconds
    string startBiasTable = "BOLObias_firstTelescBack"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_ILT_standard_low"; // Bias table containing the final values
    double ra = 267.292; // RA : 17h49m10.0s
    double dec = 69.807; // DEC : 69d48m26.0
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    bool verbose = true;
}{
    // Several arguments needed for "basic_fine_pointing"
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeSetBias = duration(PHOT_set_biases(endBiasTable,"DIRECT","LOW"));
    int timeCal3CPR1 = duration(Pacs_OBCP_chopped_photometry2(nLoops1,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false));
    //Minimum slew time
    int tslewmin = timeOBSID + timeSetBias + timeCal3CPR1;
    if(verbose) {
        debug_print("Tslewmin: " + tslewmin);
    }
    double temp_CS1 = 48.0;
    // CS1 temperature in kelvins
    double temp_CS2 = 58.0;
    // CS1 temperature in kelvins
    //Initial hold
    int tih = timeCal3CPR2;
    //Final hold
    int tfh = timeEndID + timeSetBias + timeCal3CPR5;
    //Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // 0 = Non Solar System source, 0< If fast tracking is required (Solar System Sources)
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // xoffset [arcsec]
    double xoffset = 0.0;
    //Duration of "stable" pointing
    int tp = duration(Phot_telescBack(dvls,vhbs,measure_time,startBiasTable));
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,xoffset,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("SLEW/CAL starts at " + tNOW);
            }
            //     Set OBSID
            WriteOBSID($OBSID);
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops1,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false);
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW/CAL ends at: " + tNOW);
            }
        }
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            //PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //      Call the Phot_telescBack
            Phot_telescBack(dvls,vhbs,measure_time,startBiasTable);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            PHOT_set_biases(endBiasTable,"DIRECT","LOW");
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,39,-21350,21200,1,0,0,0,0,0,644,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// File          : PACS_Phot_Fil_Trapping_DEG_MODE
// Missionphase  : PACS FM ILT
//
// Purpose       : Position sequence test of spectrometer filterwheel, intensively using the relative movements
//
// Author        : PR
//
// Arguments     :
//
// Description   : Operations in 2 phases
//         Phase 1   Open loop movements of increasing size from both FW stop positions
//         Phase 2   Repetition of the same small open loop movements, from positions 45 degrees from the stop positions.
//
// Comments      : Prerequisite : spec_mec_setup has been executed 
//
// Version       : 1.0
// History       : 1.0 / 12-May-2006 Creation
//
block PACS_Phot_Fil_Trapping_DEG_MODE PACS 279 {
    int num_iter = 2; // Number of repetitions of each sub-test block
    int maxkick = 15; // Maximal amplitude of the kicks in each sub-test block (degrees)
}{
    // Register start of BB
    WriteBBID($BBID);
    //
    double deg = 0.0;
    deg = 1536.0 / 360.0;
    // One degree in commanding units of the FW
    num_iter = 2 * num_iter;
    //
    int slew_time = 10;
    // max slew_time for any movement
    int kicktime = 4;
    //
    int fw_start = 0;
    // initial filter wheel position (0=A; 1=B)
    int fw_pos2 = (fw_start + 1) % 2;
    //
    // other filter wheel position
    //
    string[] fltPOS = ["POS A","POS B"];
    // number of iterations in all the test loops
    //
    // SWON FW CONTROLLER
    Pacs_DMC_SWON_FW_PHOTO();
    delay(1);
    //
    // STARTING FROM FW STOP POSITION
    // ==============================
    //
    Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    //
    int step = 0;
    double n = 0.0;
    //
    for(int loop0 = 0 .. num_iter - 1) {
        Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[loop0 % 2]);
        delay(slew_time);
        for(int npos = 1 .. maxkick) {
            n = double(npos);
            Pacs_DMC_MOVE_PHOT_FW_STEP(iround(n * deg));
            delay(kicktime);
        }
    }
    //
    Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    //
    for(int loop1 = 0 .. num_iter - 1) {
        Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[loop1 % 2]);
        delay(slew_time);
        for(int nneg = 1 .. maxkick) {
            n = double(nneg);
            Pacs_DMC_MOVE_PHOT_FW_STEP(-1 * iround(n * deg));
            delay(kicktime);
        }
    }
    //
    // 45 DEGREES FROM POSITION
    // ========================
    Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    //
    for(int loop2 = 0 .. num_iter - 1) {
        for(int npos2 = 1 .. maxkick) {
            n = double(npos2);
            Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[loop2 % 2]);
            delay(slew_time + 5);
            Pacs_DMC_MOVE_PHOT_FW_STEP(iround(45.0 * deg));
            delay(slew_time);
            //
            Pacs_DMC_MOVE_PHOT_FW_STEP(iround(n * deg));
            delay(kicktime);
        }
    }
    //
    Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    //
    for(int loop3 = 0 .. num_iter - 1) {
        for(int nneg2 = 1 .. maxkick) {
            n = double(nneg2);
            Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[loop3 % 2]);
            delay(slew_time + 5);
            Pacs_DMC_MOVE_PHOT_FW_STEP(iround(-45.0 * deg));
            delay(slew_time);
            //
            Pacs_DMC_MOVE_PHOT_FW_STEP(-1 * iround(n * deg));
            delay(kicktime);
        }
    }
    //
    Pacs_DMC_MOVE_PHOT_FW_LOC(fltPOS[fw_start]);
    delay(slew_time);
    //
    // Mark End of Block
    WriteEndBB();
}

// $Id: PacsEng_Spec_spu_reset.txt,v 1.5 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : PACS PV Phase
//
//
//
// Purpose	: Reset SPU after SPECtroscopy observations
//
// Author	: DAC
// CUS script	: DAC
// CVS file	: 
//
// Arguments	: none
//
// Description	: Calls procedure "SPEC_spu_reset". See there for details.
//                  
// Dependencies : Only low level PACS TCs 
//
// Comments	: 
//
// Version	: 1.0
//               
// History	: 0.1 20-nov-2006 DAC
// History      2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_spu_reset_l {
    /* Needed variables to call PacsEng_Spec_spu_reset_l                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_spu_reset_l                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_spu_reset()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_spu_reset();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

///////////////////////////////////////////////////////////////////////////
/// $Id
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsRangeSpec AOT
//
// CUS author    : DAC &VDP
// Script file   : PacsCal_	PacsRangeSpec_PV.txt
//
// Input arguments
// type    name         description
//
// Return values
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : If the file is called PacsRangeSpecObs.def, it is the 
//                 CUSGUI version. To use with HSPOT:
//                 - copy and rename PacsRangeSpec.def
//                 - rename module to PacsRangeSpec
//                 - remove extra code for CUSGUI
//                 - do not forget to set verbose = false
//
// History: 
// For history before 24-apr-2007 see v1.42 in CVS
// 25-apr-2007 14.4 Suppressed history before today (kept in CVS though)
//                  Use rangeSPOT throughtout (i.e. merged ranges & rangeEXT)
//  9-may-2007 14.5 SPR-3186 Use userNODcycles as map repetion for OFF
// 22-may-2007 14.6 SPR-3199 Return SRC time without overheads
// 29-may-2007 14.7 SPR-3237
// 11-jun-2007 14.8 SPR-3277 Use referenceWave (rangeSPOT{9}) for SED mode
// 20-sep-2007 14.9 SPR-3570 RA,DEC offsets may be negative
//                  SCR-3552 Read skewCorrec from PACSyzoffsets; add to pattnod
// 24-sep-2007 15.0 SPR-3581 S/N is not computed in SED mode
// 28-mar-2008 16.0 remove mapRasterRefXXX replaced by raoff,
// 	       	    decoff and refSelected (refSelected is complement to
//		    chopNod hence not used in our logics)
// 29-mar-2008 17.0 Removed section computing ABS or REL offsets: now an HSPOT
//   	       	    functionality
// 28-apr-2008 18.0 raoff and decoff had the wrong range: in dgrees now
// 17-Jul-2008 19.0 PV version: flexibility on parameters  
// 17-nov-2008 20.0 VD SPR 5477 add nb_grat_steps change name grat_step into
// 	       	    grat_step_size
// 17-feb-2009 20.0 VD SPR 6074 added set-up for Bias_r/d
// 12-mar-2009 21.0 VD added ABBA chopper OBCP35
// 18-mar-2009 22.0 BV corrected XY nod dwell time (off raster starr time)
// 26-mar-2009 23.0 From debugged XY version!!
//                  see logfile
//                  calBlock uses 1st line for WL calibration
// 22-apr-2009 24.0 SPR 5447 added keyWL as fnct of order+filter comb.
// 23-apr-2009 VD SPR 6482
// 12-may-2009 VD SED range fix bug
// 16-Jul-2009 VD follow-up on SCR PHS-1116: interface renovation
// 29-jul-2009 VD follow-up SCR PACS-1866  (originally for Line also valid for Range)
// 21-oct-2009 VD rolled back from verification to remove PHS-200 implementation
// 21-oct-2009 VD PHS-1225 NOD and CHOP de-coupled
// 04-dec-2009 VD PHS-1272 and PHS-1274
// 07-dec-2009 25.0 VD PHS-1282
// 09-dec-2009 26.0 VD addapted PHS-1285
// 10-dec-2009 27.0 VD full/semi reverse of NoDChop pattern (full AB = +/- , semi AB -/+ +/-)
//
{int,int,int,{string,double[],double[],double[],string,double[],double[],double[],string,double[],double[],double[]}[]} obs PacsCal_PacsRangeSpec_PV {
    /* "rangeSPOT" is a tuple defined by HSPOT                                 */
    /*  It contains                                                            */
    /* {id, bluEdge, redEdge, repeatFactor, lineFlux, contFlux, lineWidth,     */
    /*  fluxUnitSel, widthUnitSel, refWave}                                    */
    {string,double,double,int,double,double,double,string,string,double}[] rangeSPOT = [];
    /*------------- following only to use CUS interface -------------------------*/
    string[] rangeId = ["Interesting range"];
    double[] bluWave = [55.0]; // blue limit in [51.0,220.0]
    double[] redWave = [60.0]; // red limit in [51.0,220.0]
    int repeatLine = 1 in [0,10];
    double[] lineFlux = [111.0]; // Line Flux in [0.0,10000.0]
    double[] lineWidth = [400.0]; // line width in [0.0,1000.0]
    string[] widthUnit = ["kms"]; // width unit in ["kms","micron"]
    double[] lcontFlux = [111.11]; // continuum flux in [0.0,10000.0]
    double[] refWave = [60.0];
    string orderSel = "order3" in ["order2","order3","sed2","sed3","sed4","sedb2a","sedb2b","sedb3a"];
    /*------------- CUS section for All parameters setup ------------------------------------*/
    /* bool useOBCP35 = false; // use OBCP35 */
    string oBCPxx = "OBCP35" in ["OBCP35","OBCP27"]; // which SCI OBCP to use?
    /*  bool useScanParam = false; // Overwrite cal-u values for the scan parameters*/
    /* bool useCalblockParam = false; // overwrite cal-u values for the calibration block parameters */
    bool overrideCalOBCPparams = false;
    int cb_nb_up_down = 1; // cal block : number of up/down repetitions
    int cb_nb_CS1_CS2 = 1;
    int cb_nb_grat_step = 16; // cal block : number of grating steps around key wavelength
    int cb_grat_step_size = 168; // cal block : grating step size
    int cb_nb_ramps_plateau = 2; // cal block : number of ramps per chopper plateau
    bool overrideScienceOBCPparams = false; // Override the OBCP_params?
    int nb_SRC_OFF = 1; // scan parameter: chop cycles per grating position
    int nb_ramps_plateau = 2; // scan parameter: ramps per chopper plateau 
    int grat_step_size = 1200; // scan parameter: grating step size
    int nb_grat_steps = 148; // scan parameter: Nb of grating steps
    int nb_up_down = 1; // scan parameter: Nb of up/down cycles
    /*     bool useDetParam = false; // overwrite cal-u values for the detector settings */
    bool overrideDefaultsCONF_SPEC_param_SPU = false;
    int det_nbRdoutRamp_blu = 64; // Blue detector setting: readouts per ramp   
    int det_nbRdoutRamp_red = 64; // Red detector setting: readouts per ramp
    int nb_rdouts_subramp_blu = 16; // Blue detector setting: number of readouts per subramp
    int nb_rdouts_subramp_red = 16; // Red detector setting: number of readouts per subramp
    string reduction_mode = "ramp average" in ["ramp average","ramp fitting"]; // detector setting: spu reduction mode
    /*    bool useBiasParam = false; // Overwrite the detectors BIAS values */
    bool overrideDefaultsCONF_SPEC_param_CRE = false;
    int capaBlue = 0; // detector setting: capacitance blue allowed [0,4,8,12]
    int capaRed = 0; // detector setting: capacitance red allowed [0,4,8,12]
    double bias_d_blu = 0.2101 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_d_red = 0.0701 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_blu = 0.0101; // Bias "r" blue
    double bias_r_red = 0.0101; // Bias "b" red
    /*------------- above only to use CUS interface -------------------------*/
    bool overrideChopParam_UnchoppedObs = false; // overwrite cal-u values for unchopped scans 
    int chopperthrow = 0; // unchopped scan: chopperthrow (chopper units) (158 = stay on center fov)
    /* ----*/
    int userNODcycles = 1 in [1,100];
    bool chopNod = true;
    string density = "nyquist" in ["nyquist","high"];
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    string throw = "large" in ["large","medium","small"];
    string source = "point" in ["point","dithered","large","large_b"];
    double mapRasterAngle = 0.0 in [0.0,360.0];
    int m = 2 in [2,32];
    int n = 1 in [1,32];
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    int naifid = 0; // RA,DEC or SSO
    double pointStep = 2.0 in [0.0,480.0];
    double lineStep = 2.0 in [0.0,480.0];
    int knod = 1; // knod in [1,m*n]
    int nload = 0; // extra load time for Calibration
    bool refSelected = false; //OFF Posistion needed
    double raoff = 0.0 in [0.0,360.0]; // units in degrees
    double decoff = 0.0 in [-90.0,90.0]; // units in degrees
    int obsOverhead = 180; // Slew overhead
    bool startAtOFF = false;
    bool verbose = true;
    bool reverseNodChop = false;
    bool fulReverseNodChop = false;
}{
    //*--------- following only when using CUS interface -------------------*/
    int rangeIdLength = length(rangeId);
    int rangeLength = length(rangeSPOT);
    if(rangeLength == 0) {
        for(int rloop00 = 0 .. rangeIdLength - 1) {
            if(orderSel == "sed3" || orderSel == "sed4") {
                if(bluWave[rloop00] == 55.0 && redWave[rloop00] == 60.0) {
                    error("Reference wavelength should be comprised between 51.0 and 73.0");
                }
            } else {
                rangeSPOT[rloop00] = {rangeId[rloop00],bluWave[rloop00],redWave[rloop00],repeatLine,lineFlux[rloop00],lcontFlux[rloop00],lineWidth[rloop00],"",widthUnit[rloop00],refWave[rloop00]};
            }
        }
    }
    //*--------- above only when using CUS interface -------------------*/
    // 
    // Boolean variables "range" and "sedXXX" are mutually exclusive for HSPOT. For 
    // time being I will use them independently of each other
    // Specifying bool sed = true is a special case of predefined ranges.
    // 30-oct-2006
    // Variables "sed" or "range" have disappeared from front end. Define as
    bool range = true;
    bool sed = false;
    if(orderSel == "sed2" || orderSel == "sed3" || orderSel == "sed4" || orderSel == "sedb2a" || orderSel == "sedb2b" || orderSel == "sedb3a") {
        range = false;
        sed = true;
    }
    // Yet to be defined symbol to access CAL-U file info for detector setup
    // May come from HSPOT front-end in the future
    // The future has come!!!
    string confTable = "normal";
    // In SED or nyquist sample, we use the option "bright"   
    if(sed || density == "nyquist") {
        confTable = "bright";
    }
    if(chopNod && overrideChopParam_UnchoppedObs) {
        error("Overriding the unchopped parameters only makes sense when the observation are set with chopnod=false");
    }
    // mapOff no longer an input variable but still used elsewhere 
    bool mapOff = !chopNod;
    // to make sure that noone gets funny idea about refSelected
    refSelected = !chopNod;
    // Variable "grating" has disapeared from the front end. Since it's used by
    // several modules, I keep it with its new (default) definition
    string grating = "nyquist";
    // OFF pointing only when in raster mode
    if(mapOff && source != "large") {
        error("NOD = false only allowed for large sources");
    }
    // Start of "Pointing" section
    // 
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // In "sed" mode, rangeSPOT is filled by module PacsRangeSpecSed
    if(sed) {
        //   Define the RefWave as the mean value of bluWave and redWave
        //   double meanRef = (rangeSPOT[0]{1} + rangeSPOT[0]{2})/2.0;
        // SPR-3277  Save waveRef first!
        // Catch case of rangeSPOT not being defined
        int theLength = length(rangeSPOT);
        if(theLength == 0) {
            error("ERROR! Need a reference wavelength for the SED observation (see UM)");
        }
        // caught! Now extract wavelength
        double waveRef = rangeSPOT[0]{9};
        // SPR-3581. Save information to compute S/N 
        double contFlux = rangeSPOT[0]{5};
        //    Fill rangeSPOT with SED information
        int repeatSed = 0;
        rangeSPOT = PacsRangeSpecSed(orderSel,repeatSed);
        // Insure that user given reference is within order range
        double redRangeBluEdge = 0.0;
        double redRangeRedEdge = 0.0;
        if(orderSel == "sedb2a") {
            redRangeBluEdge = dlookup("SPEC_BAND_params","b2aSR1","BLU");
            redRangeRedEdge = dlookup("SPEC_BAND_params","b2aSR1","RED");
        }
        if(orderSel == "sedb2b") {
            redRangeBluEdge = dlookup("SPEC_BAND_params","b2bLR1","BLU");
            redRangeRedEdge = dlookup("SPEC_BAND_params","b2bLR1","RED");
        }
        if(orderSel == "sedb3a") {
            redRangeBluEdge = dlookup("SPEC_BAND_params","b3aLR1","BLU");
            redRangeRedEdge = dlookup("SPEC_BAND_params","b3aLR1","RED");
        }
        // Insure that user given reference is within order range
        //         if(waveRef < rangeSPOT[0]{1} || waveRef > rangeSPOT[0]{2}) {
        //            error("Reference wave must be comprised between " + rangeSPOT[0]{1} + " and " + rangeSPOT[0]{2} + " for " + orderSel);
        //        }
        debug_print("2 waveRef: " + waveRef);
        if(waveRef < rangeSPOT[0]{1} || waveRef > redRangeRedEdge) {
            error(" OutSide: Reference wave must be comprised between  [" + rangeSPOT[0]{1} + "," + rangeSPOT[0]{2} + "] and [" + redRangeBluEdge + "," + redRangeRedEdge + "] for " + orderSel);
        } else {
            if(waveRef > rangeSPOT[0]{2} && waveRef < redRangeBluEdge) {
                error(" Inside: Reference wave must be comprised between  [" + rangeSPOT[0]{1} + "," + rangeSPOT[0]{2} + "] and [" + redRangeBluEdge + "," + redRangeRedEdge + "] for " + orderSel);
            }
        }
        // 
        // Reference within limits
        rangeSPOT[0]{9} = waveRef;
        // SPR-3581. Add information to compute S/N 
        rangeSPOT[0]{5} = contFlux;
    }
    // Cannot call with empty "rangeSPOT"
    int nbRanges = length(rangeSPOT);
    int nbRanges1 = nbRanges - 1;
    if(nbRanges == 0) {
        error("STOP!! There are no spectral ranges defined!");
    }
    // No more than 10 ranges or repetitions
    int nbRangesRep = 0;
    for(int loop00 = 0 .. nbRanges - 1) {
        //  Default repetion factor is 1
        int repFactor = rangeSPOT[loop00]{3};
        if(repFactor == 0) {
            repFactor = 1;
        }
        nbRangesRep = nbRangesRep + repFactor;
    }
    if(verbose) {
        debug_print("Total ranges/repeat: " + nbRangesRep);
    }
    if(nbRangesRep > 10) {
        error("STOP!! The number of ranges/repetitions exceeds 10");
    }
    // Decode "rangeSPOT" (only if verbose mode)
    if(verbose) {
        for(int iiii = 0 .. nbRanges1) {
            debug_print("RANGE or SED: " + orderSel);
            debug_print("Wave from/to : " + rangeSPOT[iiii]{1} + "/" + rangeSPOT[iiii]{2});
            debug_print("RefWave      : " + rangeSPOT[iiii]{9});
            debug_print("repeat factor: " + rangeSPOT[iiii]{3});
        }
    }
    // Establish now the applicable Pointing Mode (use same pointCase convention
    // used in PacsPhoto and PacsLineSpec)
    // Pointing mode is still undefined
    int pointCase = 0;
    // FinePointingMode with setup time
    if(source == "point") {
        //    For completiness define a 1x1 raster
        m = 1;
        n = 1;
        //    without nodding
        if(!chopNod) {
            string pointMode = "fine_pointing";
            string userMode = "Point source (no nodding";
            pointCase = 11;
            string yzoffsetROW = "S" + pointCase;
        } else {
            //    with nodding      
            pointMode = "composite_nodding";
            userMode = "Point source (nodding)";
            pointCase = 12;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For source "dithered" use predetermined raster parameters
    if(source == "dithered") {
        m = ilookup("SMALL_SRC_params","SPEC","mRast");
        n = ilookup("SMALL_SRC_params","SPEC","nRast");
        pointStep = dlookup("SMALL_SRC_params","SPEC","pointStep");
        lineStep = dlookup("SMALL_SRC_params","SPEC","lineStep");
        //    Raster mode without noding
        if(!chopNod) {
            pointMode = "repeated_raster_with_hold";
            userMode = "Small source (dithering and no nodding)";
            pointCase = 21;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Small source (dithering and nodding)";
            pointCase = 22;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For source "large" user given raster parameters
    if(source == "large") {
        //    Raster mode without noding
        if(mapOff) {
            chopNod = false;
            pointMode = "raster_pointing";
            userMode = "Large source (raster w/OFF, no nodding)";
            pointCase = 30;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Large source (nodding)";
            pointCase = 32;
            yzoffsetROW = "S" + pointCase;
        }
    }
    if(source == "large_b") {
        //    Raster mode without noding
        if(mapOff) {
            chopNod = false;
            pointMode = "raster_pointing";
            userMode = "Large source (raster w/OFF, no nodding)";
            pointCase = 30;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_of_raster";
            userMode = "Large source (nodding)";
            pointCase = 32;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For symmetrical chopping, virtual apertures are dependent on the chopper
    // throw. 
    // Use special throw value in case of raster w/OFF as we chop between SRC and 
    // CS1
    if(mapOff) {
        throw = "offraster";
    }
    // Add this information to the CALU key entry
    yzoffsetROW = throw + "" + yzoffsetROW;
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("     PointCase ID: " + pointCase);
        debug_print("     PointMode   : " + pointMode);
        debug_print("     CALU entry  : " + yzoffsetROW);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Check that rangeSPOT is commensurate with U-CAL SPEC_BAND_params; get
    // grating positions on the fly
    // NOTE: rangeInfo is defined as 
    //       {typeOBS,order,blu_grat,red_grat,gratStep,bluWave,redWave}
    // New: is useScanParam = true, then fill some RangeInfo manually (sort of)
    {string,int,int,int,int,double,double}[] rangeInfo = PacsRangeSpecCheckFillRange(rangeSPOT,density,grating,orderSel,verbose);
    if(verbose) {
        for(int loopA = 0 .. nbRanges1) {
            debug_print("++RangeInfo: " + rangeInfo[loopA]);
        }
    }
    // Reject invalid ranges; abort CUS if invalid ranges are present
    for(int loop000 = 0 .. nbRanges1) {
        if(rangeInfo[loop00]{1} == 0) {
            error("Demanded range " + rangeInfo[loop000]{5} + "-" + rangeInfo[loop000]{6} + " [microns] is out of allowed boundaries");
        }
    }
    // rangeInfo contains all the relevant information. We can sort here, either
    // by wavelength or by start grating position. Create arrays to be sorted
    // Define array of wavelengths and start grating positions; create "order" array
    // in case we want to enforce the no order mixing rule
    double[] rangeWave = [0.0];
    double[] rangeGrat = [0.0];
    int[] orders = [0];
    // order array as float for sort algorithm
    double[] dorder = [0.0];
    // Populate the arrays
    for(int loop0 = 0 .. nbRanges1) {
        rangeWave[loop0] = rangeInfo[loop0]{5};
        //   SORT algorithm requires float input!
        rangeGrat[loop0] = double(rangeInfo[loop0]{2});
        orders[loop0] = rangeInfo[loop0]{1};
        dorder[loop0] = double(rangeInfo[loop0]{1});
    }
    // To reject forbidden order combination, count how many orders
    int nORDER1 = 0;
    int nORDER2 = 0;
    int nORDER3 = 0;
    for(int loop2 = 0 .. nbRanges1) {
        if(orders[loop2] == 1) {
            nORDER1 = nORDER1 + 1;
        }
        if(orders[loop2] == 2) {
            nORDER2 = nORDER2 + 1;
        }
        if(orders[loop2] == 3) {
            nORDER3 = nORDER3 + 1;
        }
    }
    if(nORDER2 != 0 && nORDER3 != 0) {
        //     Report band limits
        double[] band2 = SPEC_BAND_read("2");
        double[] band3 = SPEC_BAND_read("3");
        error("Combination of 2nd (" + band2[0] + "-" + band2[1] + " mic) and 3rd (" + band3[0] + "-" + band3[1] + " mic) grating orders is not allowed");
    }
    // Reject lines not belonging to authorized order
    if(nORDER2 != 0 && orderSel == "order3") {
        error("You have chosen " + orderSel + " but have specified one/several order2 lines");
    }
    if(nORDER3 != 0 && orderSel == "order2") {
        error("You have chosen " + orderSel + " but have specified one/several order3 lines");
    }
    // Determine the filter needed with given lines
    // No filter needed, i.e. ORDER=1
    // This case is history: 
    // HSPOT proposes order 1&2 or 1&3, reported as 2 or 3; filter=1 is no
    // longer possible
    int filter = 1;
    // Determine filter based on HSPUT input
    if(orderSel == "order2" || orderSel == "sed2" || orderSel == "sed4" || orderSel == "sedb2b") {
        filter = 2;
    }
    if(orderSel == "order3" || orderSel == "sed3" || orderSel == "sedb2a" || orderSel == "sedb3a") {
        filter = 3;
    }
    if(verbose) {
        debug_print("ORDER array: " + orders + "; FILTER: " + filter);
        debug_print("The whole OBS will be performed with filter " + filter);
    }
    // Sort by order
    //   int [] sortIndex = SortProc(verbose,dorder);
    // Sort grat_pos from smallest to largest
    int[] sortIndex = SortProc(verbose,rangeGrat);
    // Sort by wavelengths (from blue to red)
    // int sortIndex = SortProc(verbose,rangeWave);
    // Recast "rangeSPOT" and rangeInfo according to the ordered grating 
    // positions
    {string,double,double,int,double,double,double,string,string,double}[] sortRanges = clone(rangeSPOT);
    {string,int,int,int,int,double,double}[] sortRangeInfo = clone(rangeInfo);
    for(int reSORT = 0 .. nbRanges1) {
        //    Reversed sort
        // No reverse SORT (start observations with filter A)
        //    int revSORT           = nbRanges1 - reSORT;
        int revSORT = reSORT;
        int sortedIndex = sortIndex[revSORT];
        sortRanges[reSORT] = rangeSPOT[sortedIndex];
        sortRangeInfo[reSORT] = rangeInfo[sortedIndex];
    }
    // The tuple arrays confOBCP, confSPECred, and confSPECblu play a major
    // role. They contain the parameters related to commanding different PACS
    // subsystems. They are susceptible of changing with the observing conditions.
    // Hence, they have to be watched for changes since these imply sending one or
    // more TCs (usually invoking a building block)
    // Define confOBCP array
    // confOBCP{0 -> 19} contains:
    // nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
    // nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
    // grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
    // chop_pos_SRC     chop_pos_REF1    chop_pos_REF2
    // chop_pos_CS1     chop_pos_CS2     chop_def
    // detector         order
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confSPECblu and confSPECred
    // confSPEC{0 -> 8} contains:
    //   capa       nb_rdouts_ramp nb_rdouts_subramp  comp_mode
    //   glitch_det ramp_fit_alg   nb_raw             bias_r      bias_d
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // Estimator module returns {confSPECblu,confSPECred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    // Obtain default values
    // NEW. Saturation and capacitor/samples choice
    // Most SPEC configuration values are obtained from CONF_SPEC_params (read
    // in PacsSpecDefaults). Have to analyze given fluxes for each reference
    // wavelength. It may happen that a saturation situation will be found
    // Review the reference wavelengths, obtain telescope background, and PSF
    // fraction
    for(int rangeLOOP0 = 1 .. nbRanges) {
        int range1 = rangeLOOP0 - 1;
        waveRef = sortRanges[range1]{9};
        contFlux = sortRanges[range1]{5};
        //    Obtain background and PSF fraction from CALU
        double telBckg = interpolate("SPEC_BCKG_FRAC","BackG",waveRef);
        double psfFrac = interpolate("SPEC_BCKG_FRAC","FracPnt",waveRef);
        debug_print("SATUR. Wave  " + waveRef);
        debug_print("SATUR. Flux  " + contFlux);
        debug_print("SATUR. Backg " + telBckg);
        debug_print("SATUR. PSF   " + psfFrac);
        debug_print("SATUR. Order " + sortRangeInfo[range1]{1});
    }
    paramsSPECdef = PacsSpecDefaults(throw,confTable,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // Here comes the module to estimate PACS parameters as a function of the
    // exposure time given by the user. This is the pilar of the
    // whole AOT logic.
    //Define tuple to contain the "variable" parameters
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPEC = clone(paramsSPECdef);
    // paramsSPECext (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,nb_up_dn,aux1,aux2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for each wavelength. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("confOBCP[0]: " + confOBCP[0]);
    }
    int nbNods = 0;
    double waveMAXnods = 0.0;
    // Accumulated total OBS time
    int totalOBS = 0;
    for(int rangeLOOP = 1 .. nbRanges) {
        range1 = rangeLOOP - 1;
        if(oBCPxx == "OBCP35") {
            paramsSPECext = PacsRangeSpecEstimatorOBCP35(sortRanges[range1],sortRangeInfo[range1],paramsSPEC,chopNod,verbose);
        }
        if(oBCPxx == "OBCP27") {
            paramsSPECext = PacsRangeSpecEstimatorOBCP27(sortRanges[range1],sortRangeInfo[range1],paramsSPEC,chopNod,verbose);
        }
        //    Copy estimates to respective tuples
        confSPECblu[rangeLOOP] = paramsSPECext{0};
        confSPECred[rangeLOOP] = paramsSPECext{1};
        confOBCP[rangeLOOP] = paramsSPECext{2};
        //PHS-1290
        if(fulReverseNodChop) {
            int save_chop = confOBCP[rangeLOOP]{12};
            confOBCP[rangeLOOP]{12} = confOBCP[rangeLOOP]{13};
            confOBCP[rangeLOOP]{13} = save_chop;
        }
        /////// !!!!!
        if(overrideCalOBCPparams) {
            confOBCP[0]{0} = cb_nb_up_down;
            confOBCP[0]{1} = -cb_grat_step_size;
            confOBCP[0]{2} = cb_grat_step_size;
            confOBCP[0]{4} = cb_nb_ramps_plateau;
            confOBCP[0]{5} = cb_nb_CS1_CS2;
            confOBCP[0]{6} = cb_nb_grat_step;
            confOBCP[0]{7} = cb_nb_grat_step;
        }
        if(overrideScienceOBCPparams) {
            confOBCP[rangeLOOP]{1} = -grat_step_size;
            confOBCP[rangeLOOP]{2} = grat_step_size;
            confOBCP[rangeLOOP]{3} = nb_SRC_OFF;
            confOBCP[rangeLOOP]{4} = nb_ramps_plateau;
            confOBCP[rangeLOOP]{6} = nb_grat_steps;
            confOBCP[rangeLOOP]{7} = nb_grat_steps;
        }
        if(overrideDefaultsCONF_SPEC_param_SPU) {
            confSPECblu[0]{1} = det_nbRdoutRamp_blu;
            confSPECred[0]{1} = det_nbRdoutRamp_red;
            confSPECred[0]{2} = nb_rdouts_subramp_red;
            confSPECblu[0]{2} = nb_rdouts_subramp_blu;
            if(reduction_mode == "ramp average") {
                confSPECblu[0]{5} = 1;
                confSPECred[0]{5} = 1;
            } else {
                if(reduction_mode == "ramp fitting") {
                    confSPECred[0]{5} = 0;
                    confSPECblu[0]{5} = 0;
                }
            }
            confSPECblu[rangeLOOP]{1} = det_nbRdoutRamp_blu;
            confSPECred[rangeLOOP]{1} = det_nbRdoutRamp_red;
            confSPECred[rangeLOOP]{2} = nb_rdouts_subramp_red;
            confSPECblu[rangeLOOP]{2} = nb_rdouts_subramp_blu;
            if(reduction_mode == "ramp average") {
                confSPECblu[rangeLOOP]{5} = 1;
                confSPECred[rangeLOOP]{5} = 1;
            } else {
                if(reduction_mode == "ramp fitting") {
                    confSPECred[rangeLOOP]{5} = 0;
                    confSPECblu[rangeLOOP]{5} = 0;
                }
            }
        }
        if(overrideDefaultsCONF_SPEC_param_CRE) {
            confSPECred[rangeLOOP]{0} = capaRed;
            confSPECblu[rangeLOOP]{0} = capaBlue;
            confSPECred[rangeLOOP]{7} = iround(1000.0 * bias_r_red);
            confSPECblu[rangeLOOP]{7} = iround(1000.0 * bias_r_blu);
            confSPECred[rangeLOOP]{8} = iround(1000.0 * bias_d_red);
            confSPECblu[rangeLOOP]{8} = iround(1000.0 * bias_d_blu);
        }
        if(overrideChopParam_UnchoppedObs) {
            //SRC REF1 REF1 or REF1 SRC SRC REF2
            confOBCP[rangeLOOP]{12} = -chopperthrow;
            confOBCP[rangeLOOP]{13} = chopperthrow;
            confOBCP[rangeLOOP]{14} = chopperthrow;
        }
    }
    //    nb_nods below is the quantity used by Estimator to compute its duration
    int nb_nods = paramsSPECext{3}{0};
    //     
    if(verbose) {
        debug_print("confOBCP[0]: " + confOBCP[0]);
        debug_print("confOBCP[" + rangeLOOP + "]: " + confOBCP[rangeLOOP]);
    }
    //    Accumulated time
    totalOBS = totalOBS + paramsSPECext{3}{2};
    if(verbose) {
        debug_print("Minimum required time: " + totalOBS + " [sec] for " + nb_nods + " nod cycles");
    }
    if(chopNod) {
        nbNods = userNODcycles;
        if(verbose) {
            debug_print("The PointReq will contain " + nbNods + " nod cycles");
        }
    } else {
        nbNods = 0;
    }
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Estimated total OBStime (SRC+REF) for requested ranges: " + totalOBS + "[sec]</p>";
    lineCnt = lineCnt + 1;
    int nodTotal = nbNods * totalOBS;
    if(chopNod) {
        msgLine[lineCnt] = "<p>With the specified NOD count, " + nbNods + ", the total OBS time amounts to " + nodTotal + "[sec]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Since no NOD was specified the total OBS time is equal" + " to the estimated SRC+REF time. OBS times can be changed" + " by specifying the line(s) repeat factor</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("Accumulated SRC+REF time estimation",lineCnt,msgLine);
    // Messages on general Detector/SPU parameters
    lineCnt = 0;
    msgLine[lineCnt] = "<p>Red channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECred[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    int subRamps = confSPECred[0]{1} / confSPECred[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECred[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECred[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Blue channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECblu[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    subRamps = confSPECblu[0]{1} / confSPECblu[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECblu[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECblu[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Selected PACS setup parameters",lineCnt,msgLine);
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source
    // First operation is to set the OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    if(verbose) {
        debug_print("Duration WriteOBSID: " + timeSetOBSID);
    }
    // Will call PacsSpecSlewCal to perform AOT prologue and CAL during
    // slew to source. Establish an array of key wavelengths, one per order,
    // commensurate with user given wavelengths
    double[] refWL = [waveRef];
    // BV 02/11/2009 SCR 1239: take key wavelength specified in gratpos
    //
    // double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    {double,int} keys = PacsSpecKeyWaves_grat(orderSel,refWL);
    double keyWL = keys{0};
    int grat_keyWL = keys{1};
    double[] keyWAVE = [keyWL];
    int[] grat_keyWAVE = [grat_keyWL];
    // double keyWL = PacsSpecKeyWaves(orderSel,refWave);
    //double[] keyWAVE = [keyWL];
    //   double [] keyWAVE = PacsRangeSpecKeyWaves(sortRangeInfo);
    int nbKeyWAVE = 1;
    //   int nbKeyWAVE = length(keyWAVE);
    if(verbose) {
        debug_print("keyWAVES " + keyWAVE);
    }
    // With latest versions of CommandOBCP27/35 the grating is
    // supposed to be left by SlewCal at the position needed for the 1st line
    // The OBCPs will leave the grating at that same position
    int frstLstGratPos = confOBCP[1]{8};
    if(verbose) {
        debug_print("MAIN:keyWAVES " + keyWAVE);
        debug_print("MAIN:SlewCal should leave grating at: " + frstLstGratPos);
    }
    // Time needed to perform these activities during slew (includes AOTprologue)
    bool doAOTprologue = true;
    if(overrideCalOBCPparams) {
        int timeSlewCal = duration(PacsSpecSlewCal_override(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalOBCPparams));
    } else {
        timeSlewCal = duration(PacsSpecSlewCal_grat(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,grat_keyWAVE,keyWAVE,filter,frstLstGratPos,orderSel));
    }
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during slew: " + timeSlewCal);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsSpecCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsSpecCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // IMPORTANT NOTE: the duration may be different for the first cycle through 
    // all wavelengths than for the following ones owing to differing initial state.
    // However, all steps have been taken so that PACS starts the actual observation
    // in the same state as it would be left at the end of any wavelength cycle
    // Duration of any nod leg or staring observation
    if(oBCPxx == "OBCP35") {
        int timeOBS = duration(PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,verbose));
    }
    if(oBCPxx == "OBCP27") {
        timeOBS = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
    }
    if(verbose) {
        debug_print("Duration " + oBCPxx + ":" + timeOBS + " [sec] per nod;  nb_nods: " + nb_nods);
    }
    // Get duration of module to close AOT operations
    // This includes parking the grating
    // Park position
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // The grating was left by OBCPs at frstLstGratPos
    int timeEpilogue = duration(SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose));
    // WriteEndID will be the last TC; get its duration
    int timeEndID = duration(WriteEndID());
    if(verbose) {
        debug_print("Duration WriteEndID: " + timeEndID);
    }
    // Summary of relevant data collected so far
    // timeSlewCal: duration of the leading CAL, including AOT_prologue
    // timeOBS    : duration of a single pointed OBS
    // nb_nods    : number of nods for staring mode or per raster position
    // chopNod : invoke nodding or not (nb_nods = 0 is equivalent to no nod)
    // m, n       : raster nb_points/line, nbRanges per RREQ
    // pointStep,lineStep: more raster parameters
    // ra,dec: more pointing parameters
    //
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Ready to issue a FinePointing mode with/without nodding or
    // a RasterReq with/without nodding. Either one needs some time during
    // slew to perform leading CAL.
    // Make sure that the Preq is possible (possible reason for failure: too short
    // dwell time - currently 10 sec
    int minTdwell = 10;
    if(timeOBS < minTdwell) {
        error("Estimated dwell time is too short. Perhaps your range span is too small");
    }
    //
    // The chopper throws have been read already (PacsSpecDefaults) and angles
    // have been converted into ENG units (OBCPconf). Here,angles are needed in 
    // [arcsec]; easiest is to read again the relevant CAL-U table. 
    // Read chopper position SRC and REF1 [arcsec]
    if(overrideChopParam_UnchoppedObs) {
        double engChopRef = -1.0 * double(chopperthrow);
        double engChopSrc = 1.0 * double(chopperthrow);
        double chopAngleSrc = interpolate("SPEC_SKY_chop","SKY",engChopSrc);
        double chopAngleRef = interpolate("SPEC_SKY_chop","SKY",engChopRef);
        // PHS-1225
        double nodThrow = abs(chopAngleSrc - chopAngleRef);
    } else {
        chopAngleSrc = dlookup("SPEC_CHOP_params",throw,"SRC");
        chopAngleRef = dlookup("SPEC_CHOP_params",throw,"REF1");
        // PHS-1225
        double nodAngleSrc = dlookup("SPEC_NOD_params",throw,"SRC");
        double nodAngleRef = dlookup("SPEC_NOD_params",throw,"REF1");
        nodThrow = abs(nodAngleSrc - nodAngleRef);
    }
    if(verbose) {
        debug_print("MAIN:CHOP/NOD params SRC/REF/NOD: " + chopAngleSrc + "/" + chopAngleRef + "/" + nodThrow);
    }
    // Issue pointing request (when possible use JBr's variable names for clarity)
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    // Virtual aperture
    string ib = "P02_0";
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("#### skewCorrec : " + skewCorrec);
    }
    int tslewmin = timeSetOBSID + timeSlewCal;
    int tinithold = 0;
    int tfinalhold = timeEndID + timeEpilogue;
    int tp = timeOBS;
    double patt = 0.0;
    double pattnod = 270.0 + skewCorrec;
    int k = 0;
    int thold = 0;
    int nhold = 0;
    //    int nload = 0;
    int tloadslewmin = 0;
    bool fixed = true;
    if(pointCase == 11) {
        //   FinePointingMode without nodding
        int[] fromPntReq = basic_fine_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,yoffset,zoffset,tp);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        int tend = fromPntReq[2];
    }
    if(pointCase == 12) {
        //   FinePointingMode with nodding, section 3.4
        ib = "P02_0";
        //   Nodding angle is specified wrt spacecraft
        fixed = false;
        //   Nodding is along y axis, opposite chop
        pattnod = 270.0 + skewCorrec;
        fromPntReq = nodding_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nbNods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tnod = fromPntReq[2];
        tss = fromPntReq[3];
        tload = fromPntReq[4];
        tend = fromPntReq[5];
    }
    if(pointCase == 21 || pointCase == 31) {
        //   RasterMode without nodding, section 3.5
        ib = "P02_0";
        //   Raster in instrument coordinates
        fixed = false;
        double d1 = pointStep;
        double d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        k = 0;
        int ncover = 1;
        //   New arguments for pointing request; will be dealt with next iteration
        int top = 0;
        raoff = 0.0;
        decoff = 0.0;
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,ncover,thold,nhold,k,top,raoff,decoff);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        trep = fromPntReq[4];
        tsop = fromPntReq[5];
        tend = fromPntReq[6];
    }
    if(pointCase == 30) {
        //   RasterMode with no nodding and OFF, section 3.5
        ib = "P02_0";
        //   SPR-3237: fix is true, patt is inherited from HSPOT
        fixed = true;
        patt = mapRasterAngle;
        //   Raster steps
        d1 = pointStep;
        d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        // OFF periodicity (here at beginning and at end of raster)
        k = m * n;
        //   The number of repetions is given in this case by the NOD count SPR-3186
        int nrepeat = userNODcycles;
        if(nrepeat == 0) {
            nrepeat = 1;
        }
        //   Same Tobs during OFF that during "SRC"
        top = tp;
        trepeatmin = 0;
        tloadmin = 0;
        nload = 0;
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        trep = fromPntReq[4];
        tsop = fromPntReq[5];
        tend = fromPntReq[6];
    }
    if(pointCase == 22 || pointCase == 32 && source != "large_b") {
        //   RasterMode with nodding, section 3.6
        ib = "P02_0";
        //   Raster in instrument coordinates
        fixed = false;
        //   Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        //   Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        k = 0;
        nrepeat = 1;
        //   New arguments for pointing request; will be dealt with next iteration
        top = 0;
        raoff = 0.0;
        decoff = 0.0;
        trepeatmin = 0;
        tloadmin = 0;
        //        nload = 0;	
        fromPntReq = nodding_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nbNods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
        tend = fromPntReq[9];
    }
    if(pointCase == 32 && source == "large_b") {
        //    Nodding of Raster, section 3.6
        debug_print("toto");
        ib = "P02_0";
        //   Raster in instrument coordinates
        fixed = false;
        //   Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        //   Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        //        k = m * n;
        int ncycles = userNODcycles;
        nrepeat = 1;
        nload = 0;
        tloadmin = 0;
        fromPntReq = nodding_of_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,pattnod,nodThrow,ncycles,knod,nrepeat,tloadmin,nload);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
        tend = fromPntReq[9];
    }
    // Parameters returned by PointReq
    if(verbose) {
        debug_print("=====> Return from " + pointMode + ": " + fromPntReq);
    }
    //Info from API (nomenclature from Jon Br)
    tobs = fromPntReq[0];
    tslew = fromPntReq[1];
    ///////////////////////// end of "timing" section //////////////////////////
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
    }
    if(verbose) {
        int tNOW = time();
        debug_print("=== Issued PointReq Time_now: " + tNOW);
    }
    // Issue TCs
    int[] stateVar = [0];
    int nbOBS = 0;
    int nbOFF = 0;
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            //       Write OBSID (logical part of SlewCal)
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            if(overrideCalOBCPparams) {
                int[][] calTime = PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalOBCPparams);
            } else {
                calTime = PacsSpecSlewCal_grat(false,confSPECblu,confSPECred,confOBCP,true,grat_keyWAVE,keyWAVE,filter,frstLstGratPos,orderSel);
            }
            //       Define accumulated Cal time
            int[][] sumUpCalTime = calTime;
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW ends at: " + tNOW);
                debug_print("    SumUpCalTime: " + sumUpCalTime);
            }
        } else {
            if(stateVar[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== POINT starts at: " + tNOW);
                }
                if(oBCPxx == "OBCP35") {
                    int[][] obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                }
                if(oBCPxx == "OBCP27") {
                    obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                }
                nbOBS = nbOBS + 1;
                //       Logic to sum up obsTime
                if(nbOBS == 1) {
                    int[][] sumUpObsTime = obsTime;
                }
                if(nbOBS > 1) {
                    sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("    SumUpObsTime: " + sumUpObsTime);
                    debug_print("=== POINT ends at: " + tNOW);
                }
            } else {
                if(stateVar[0] == 4) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF starts at: " + tNOW);
                    }
                    if(oBCPxx == "OBCP35") {
                        obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                    }
                    if(oBCPxx == "OBCP27") {
                        obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                    }
                    nbOFF = nbOFF + 1;
                    //       Logic to sum up obsTime
                    if(nbOFF == 1) {
                        int[][] sumUpOffTime = obsTime;
                    }
                    if(nbOFF > 1) {
                        sumUpOffTime = SumFunction(obsTime,sumUpOffTime);
                    }
                    if(verbose) {
                        tNOW = time();
                        debug_print("    SumUpOffTime: " + sumUpOffTime);
                        debug_print("=== OFF ends at: " + tNOW);
                    }
                } else {
                    if(stateVar[0] == 7) {
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== NOD started at: " + tNOW);
                        }
                        //PHS-1290
                        if(reverseNodChop) {
                            for(int loopXY = 1 .. nbRanges) {
                                save_chop = confOBCP[loopXY]{12};
                                confOBCP[loopXY]{12} = confOBCP[loopXY]{13};
                                confOBCP[loopXY]{13} = save_chop;
                            }
                        }
                        if(oBCPxx == "OBCP35") {
                            obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                        }
                        if(oBCPxx == "OBCP37") {
                            obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                        }
                        if(reverseNodChop) {
                            for(int loopXZ = 1 .. nbRanges) {
                                save_chop = confOBCP[loopXZ]{12};
                                confOBCP[loopXZ]{12} = confOBCP[loopXZ]{13};
                                confOBCP[loopXZ]{13} = save_chop;
                            }
                        }
                        nbOBS = nbOBS + 1;
                        //       Logic to sum up obsTime
                        if(nbOBS == 1) {
                            sumUpObsTime = obsTime;
                        }
                        if(nbOBS > 1) {
                            sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                        }
                        if(verbose) {
                            tNOW = time();
                            debug_print("    SumUpObsTime: " + sumUpObsTime);
                            debug_print("=== NOD ends at: " + tNOW);
                        }
                    } else {
                        if(stateVar[0] == 6) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== HOLD starts at: " + tNOW);
                            }
                            if(overrideCalOBCPparams) {
                                calTime = PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalOBCPparams);
                            } else {
                                calTime = PacsSpecSlewCal_grat(false,confSPECblu,confSPECred,confOBCP,true,grat_keyWAVE,keyWAVE,filter,frstLstGratPos,orderSel);
                            }
                            sumUpCalTime = SumFunction(calTime,sumUpCalTime);
                            if(verbose) {
                                tNOW = time();
                                debug_print("    SumUpCalTime: " + sumUpCalTime);
                                debug_print("=== HOLD ends at: " + tNOW);
                            }
                        } else {
                            if(stateVar[0] == 5) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== FinalHOLD  starts at: " + tNOW);
                                }
                                SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose);
                                WriteEndID();
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== FinalHOLD  ends at: " + tNOW);
                                }
                            } else {
                                if(stateVar[0] == -1) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== AOT ends at: " + tNOW);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    if(verbose) {
        debug_print("OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
    }
    // The original concept of returning durations did not take into 
    // account the bandwidth of the TC bus (2 TCs/sec). The "real" 
    // duration is given by the result from the "duration()" function. Hence
    // the true total duration of the SlewCal phase is given by
    ///   calTime[0] = timeSlewCal;
    // as a result, the overheads are now
    ///   calTime[4] = calTime[0]-(calTime[1]+calTime[2]+calTime[3]); 
    if(verbose) {
        debug_print("Slew & HOLD Cal return: " + sumUpCalTime);
    }
    // The same holds true for the OBCP27/OBCP35 phase. However, I cannot make the
    // break-down by wavelength (the OBCP27/35 duration is given for ALL ranges).
    // We may add up the SRC, CAL, and OVR components of OBCP27/35 duration. For
    // this we need a tuple so we can add the wavelength and other relevant
    // information to the (per wave) duration arrays.
    //
    //    infoArray[] contains a "fixed" global information part
    //    infoArray[0]: {Slew,   intTime,TotDur,nbRanges,nnods,m*n}
    //    infoArray[1]: {Point,  intTime,TotDur,nbRanges,nnods,m*n}
    //    infoArray[2]: {AOTinfo,intTime,TotDur,nbRanges,nnods,m*n}
    // and per wavelength array(s):
    //    [waveSTART,waveEND,order,gratStep,nbGratSteps,TOT,SRC,REF,CAL,OVR]
    // TotDur as given by duration(); TOT,SRC,REF,CAL,OVR are also in [sec]
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    // Fill infoArray with data from SlewCal
    // Instead of using timeSlewCal, use tslew time returned by PointReq
    // infoArray[0] = {{"SlewCal",0.0,timeSlewCal,0,0,0},[{0.,0.,0,0,0,0,0,0,0,0}]};
    infoArray[0] = {{"SlewCal",0.0,tslew,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Fill infoArray with data from OBCP27/35
    // Compute integration time per chopper plateau
    // intTime = nbRamps/plateau x nbRdouts/ramp x sampleInterval 
    // Sampling frequency
    double specSample = dlookup("PACSparams","spec_sample","freq_time");
    // Number of readouts per ramp
    int nbRdoutRamp = confSPECblu[1]{1};
    // NOTE: WAIT=1 are now counted as useful ramps; hence
    int nbRampPlateau = confOBCP[1]{4} + 1;
    // 
    double intTime = double(nbRampPlateau * nbRdoutRamp) / specSample;
    if(verbose) {
        debug_print("MAIN:AOT          : " + userMode);
        debug_print("MAIN:Rdouts/ramp  : " + nbRdoutRamp);
        debug_print("MAIN:Ramps/plateau: " + nbRampPlateau);
        debug_print("MAIN:IntTime (incl. WAIT=1): " + intTime);
    }
    // Replace timeOBS (per raster and per nod) with tobs from PntReq (matching
    // change in PacsProcessInfoArray)   
    // infoArray[1] = {{userMode,intTime,timeOBS,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    infoArray[1] = {{userMode,intTime,tobs,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    for(int loop3 = 0 .. nbRanges1) {
        //     Create element [loop3]
        infoArray[1]{1}[loop3] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy from/to wavelengths
        infoArray[1]{1}[loop3]{0} = sortRanges[loop3]{1};
        infoArray[1]{1}[loop3]{1} = sortRanges[loop3]{2};
        //     copy the grating order
        infoArray[1]{1}[loop3]{2} = sortRangeInfo[loop3]{1};
        //     copy the grating step
        infoArray[1]{1}[loop3]{3} = sortRangeInfo[loop3]{4};
        //     copy the number of grating step
        infoArray[1]{1}[loop3]{4} = confOBCP[loop3 + 1]{6};
        //     copy other data from obsTime
        infoArray[1]{1}[loop3]{5} = sumUpObsTime[loop3][0];
        infoArray[1]{1}[loop3]{6} = sumUpObsTime[loop3][1];
        infoArray[1]{1}[loop3]{7} = sumUpObsTime[loop3][2];
        infoArray[1]{1}[loop3]{8} = sumUpObsTime[loop3][3];
        infoArray[1]{1}[loop3]{9} = sumUpObsTime[loop3][4];
    }
    // Add more data from SlewCal to infoArray
    for(int loop4 = 0 .. nbKeyWAVE - 1) {
        //     for some reason it has to be "initialized"
        infoArray[0]{1}[loop4] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the wavelength
        infoArray[0]{1}[loop4]{0} = keyWAVE[loop4];
        //     copy other data from sumUpCalTime
        infoArray[0]{1}[loop4]{5} = sumUpCalTime[loop4][0];
        infoArray[0]{1}[loop4]{6} = sumUpCalTime[loop4][1];
        infoArray[0]{1}[loop4]{7} = sumUpCalTime[loop4][2];
        infoArray[0]{1}[loop4]{8} = sumUpCalTime[loop4][3];
        infoArray[0]{1}[loop4]{9} = sumUpCalTime[loop4][4];
    }
    // Further update of infoArray: add information from AOT_prologue    
    infoArray[0]{1}[nbKeyWAVE] = {0.0,0.0,0,0,0,0,0,0,0,0};
    // Copy OVR and TOT times
    infoArray[0]{1}[nbKeyWAVE]{9} = calTime[nbKeyWAVE][4];
    infoArray[0]{1}[nbKeyWAVE]{5} = calTime[nbKeyWAVE][4];
    // Copy the number of ranges observed and the number of key waves used
    infoArray[0]{0}{3} = nbKeyWAVE;
    infoArray[1]{0}{3} = nbRanges;
    // Copy the number of nod cycles and the number of raster points visited
    infoArray[1]{0}{4} = nbNods;
    infoArray[1]{0}{5} = m * n;
    // The duration of the OBS phase is given by timeObsEnd - timeSlewCal
    // Now get it from PntReq: timeObsPhase == tobs
    // int timeObsPhase = timeObsEnd - timeSlewCal - 1 - timeSetOBSID;
    if(verbose) {
        debug_print("CalSlew phase lasted [sec]: " + timeSlewCal);
        debug_print("The OBS phase lasted [sec]: " + tobs);
    }
    // Slew time during the OBS phase is then given by
    int timeSlewObs = tobs - nbOBS * timeOBS;
    if(verbose) {
        debug_print("Total slew during OBS [sec]: " + timeSlewObs);
    }
    // Populate the 3rd dimension of infoArray: global timing and AOT information
    // timeObsEnd is the total duration of the AOT
    infoArray[2] = {{"RangeSpec",0.0,timeObsEnd,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Case of SmallSrc with dithering
    if(source == "dithered") {
        infoArray[1]{0}{0} = "SmSrcDither";
    }
    // Use available entries to convey m,n, and nbNods
    infoArray[2]{0}{3} = m;
    infoArray[2]{0}{4} = n;
    // PointSources are also seen with composite_nodding
    if(pointMode == "fine_pointing" || pointMode == "composite_nodding") {
        infoArray[2]{0}{3} = 1;
        infoArray[2]{0}{4} = 1;
    }
    infoArray[2]{0}{5} = nbNods;
    // Case of raster/w OFF, repeated map
    if(source == "large" && mapOff) {
        infoArray[1]{0}{0} = "RasterOFF";
        infoArray[2]{0}{5} = nrepeat;
    }
    // Process the information contained in infoArray
    // NOTE: since implementing waveRef and fluxes, have to pass also 
    //       sortRanges and sortRangesExt data to ProcessInfoArray
    // aotID is no longer needed as only used for Range
    // but orderSel is needed by PacsSpecRMS
    // SPR-2927 Return bigTuple with information for plotting
    // Add nbOBS and nbOFF to ProcessInfoArray
    {{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[] bigTuple = PacsProcessInfoArrayRange(infoArray,sortRanges,confOBCP,orderSel,obsOverhead,nbOBS,nbOFF,verbose);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    //////// Silly code to convert bigTuple into smallTuple ////////////////////
    // bigTuple is too big for HSPOT. I have to remove the 1st double[] to
    // please HSPOT. Create smallTupleN
    {string,double[],double[],double[],string,double[],double[],double[],string,double[],double[],double[]}[] smallTuple = [{"1",[0.0],[0.0],[0.0],"2",[0.0],[0.0],[0.0],"3",[0.0],[0.0],[0.0]}];
    // Old returned tuples
    {int,int,{{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]},{string,double[],double[],double[],double[]}}[]} returnTuple = {fromPntReq[0],fromPntReq[1],bigTuple};
    // Copy returnTuple onto smallTuple
    nbRanges = length(bigTuple);
    // The accumulated SRC+REF time
    int accumSrceRef = 0;
    for(int loopR = 0 .. nbRanges - 1) {
        //  Use the nbRanges loop to add up SrceRef times (SRC + REF)
        accumSrceRef = accumSrceRef + infoArray[1]{1}[loopR]{6} + infoArray[1]{1}[loopR]{7};
        //  Define smallTuple
        smallTuple[loopR] = {"1",[0.0],[0.0],[0.0],"2",[0.0],[0.0],[0.0],"3",[0.0],[0.0],[0.0]};
        //   Extract vectors; retrun CONT noise in mJy
        //   First tuple is always the nominal range. Label it as RangeID + "Nominal"
        string id = sortRanges[loopR]{0} + "-nominal";
        smallTuple[loopR]{0} = id;
        double[] wave = returnTuple{2}[loopR]{0}{2};
        double[] cont = returnTuple{2}[loopR]{0}{3};
        double[] line = returnTuple{2}[loopR]{0}{4};
        int nbElem = length(wave);
        for(int loopT1 = 0 .. nbElem - 1) {
            smallTuple[loopR]{1}[loopT1] = wave[loopT1];
            smallTuple[loopR]{2}[loopT1] = 1000.0 * cont[loopT1];
            smallTuple[loopR]{3}[loopT1] = line[loopT1];
        }
        wave = returnTuple{2}[loopR]{1}{2};
        cont = returnTuple{2}[loopR]{1}{3};
        line = returnTuple{2}[loopR]{1}{4};
        nbElem = length(wave);
        //   If there is no "free" data
        id = "undefined";
        //   Else label second tuple as RangeID + "-free1"
        if(nbElem > 1) {
            id = sortRanges[loopR]{0} + "-free1";
        }
        smallTuple[loopR]{4} = id;
        for(int loopT2 = 0 .. nbElem - 1) {
            smallTuple[loopR]{5}[loopT2] = wave[loopT2];
            smallTuple[loopR]{6}[loopT2] = 1000.0 * cont[loopT2];
            smallTuple[loopR]{7}[loopT2] = line[loopT2];
        }
        wave = returnTuple{2}[loopR]{2}{2};
        cont = returnTuple{2}[loopR]{2}{3};
        line = returnTuple{2}[loopR]{2}{4};
        nbElem = length(wave);
        //   If existing, label third tuple as RangeID + "-free2"
        id = "undefined";
        if(nbElem > 1) {
            id = sortRanges[loopR]{0} + "-free2";
        }
        smallTuple[loopR]{8} = id;
        for(int loopT3 = 0 .. nbElem - 1) {
            smallTuple[loopR]{9}[loopT3] = wave[loopT3];
            smallTuple[loopR]{10}[loopT3] = 1000.0 * cont[loopT3];
            smallTuple[loopR]{11}[loopT3] = line[loopT3];
        }
        //  End loop on nbRanges
    }
    // Compute overheads as total "sky" time minus SRC+REF time
    int overPACSandSC = fromPntReq[0] - accumSrceRef;

    return {accumSrceRef,fromPntReq[1],overPACSandSC,smallTuple};
}

// Mission phase : PV Phase
//
// Purpose : PCD req.1.1.1bis for the PV Phase
//           Measure the responsivity with a 4x9 or 4x8 raster on a point source:
//           Chopped     : Noise measured after the 4x8 raster at the off chopper position
//                         during 4*measure_time. The chopped measurement requires 105 arcsec offset.
//           Non-chopped : Noise measured at last 4 pointings of the 4x9 raster of 13.5 arcsec offset.
//
// Author : Koryo Okumura
//
// Version : Wed Jul 29 12:16:22 EDT 2009
//
// CUS script : obs PacsCal_Phot_highGainBiasDDCS
//
// Argument :
//   string select = "ginit" in ["ginit","g2_0","g2_6","g3_0","binit","b2_0","b2_6","b3_0","final"]; // Select a configuration or initialize or finalize
//   int naifid = 2000001; // SSO tracking object number
//   double ra = 0.0; // RA
//   double dec = 0.0; // Dec
//   int measure_time = 120; // measure time in seconds
//   string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
//   string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
//   int nLoops1 = 30; // number of CSs cycles during slew
//   int nLoops5 = 30; // number of CSs cycles during final hold
//   int readouts_plateau = 64; // number of readouts per chopper plateau
//   string calGain = "HIGH" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//   bool chop = true; // Chopping within FOV during the raster
//   bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + PHOT_orbit_prologue is executed (then more than the minimum requirement below is fullfilled):
//     - Bolometers are biased
//     - Sequencer is activated
//
// Description : PacsCal script of Phot_highGainBiasDDCS
//   init + During the slew, CSs are measured through 2 filters
//        + Set a filter corresponding to the given seqNum
//        + Set the biases group by group
//   if no_chop
//        + Set the chopper on the optical center
//        + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group corresponding to the selected bias
//        + Do a 4x9 raster measurement
//   if chop
//        + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group corresponding to the selected bias
//        + Do a 4x8 raster with chopped measurement
//        + After the raster, noise measurement during 4xmeasure_time
//   then + After the raster, CSs and sky are measured through 2 filters
//   stop + The biases are set following a given bias table
//
// Dependencies : Commissioning and PV data at low gain of PCD req.1.1.1
// Comment : SCR PACS-1872
//
// Comments : generated by IA script : cus_PVph_highGainBias(0)
//
obs PacsCal_Phot_highGainBiasDDCS {
    string select = "ginit" in ["ginit","g2_0","g2_6","g3_0","binit","b2_0","b2_6","b3_0","final"]; // Select a configuration
    int naifid = 2000001; // SSO tracking object number
    double ra = 0.0; // RA
    double dec = 0.0; // Dec
    int measure_time = 120; // measure time in seconds per pointing
    string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
    string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 64; // number of readouts per chopper plateau
    string calGain = "HIGH" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    bool chop = true; // Chopping within FOV during the raster
    bool verbose = true;
}{
    bool execute = true;
    int nRdts = readouts_plateau - 1;
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = duration(PHOT_change_biases(endBiasTable,calMode,calGain));
    int timeBckBias = 0;
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,"DDCS","HIGH"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,calMode,"HIGH"));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,"DDCS",calGain));
    }
    int timeCal3CPR1 = duration(OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644));
    int tNewSetup = duration(Phot_highGainBiasDDCS(select,startBiasTable,endBiasTable));
    int tslewmin = 0;
    int tih = 0;
    int tfh = 0;
    // Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // yoffset [arcsec] (Positive offset to get an empty sky in the last 4 pointings)
    double yoffset = 13.5;
    // zoffset [arcsec] : Finally we do not risk to provoke the opposite correction
    double zoffset = 0.0;
    // Duration of "stable" pointing in seconds
    int tp = 0;
    //Issue PointReq
    int[] ts = [0];
    if(select == "ginit" || select == "binit" || select == "final") {
        // Several arguments needed for "basic_fine_pointing"
        // time to set OBSID and biases then PacsPhotSlewCal
        // Minimum slew time
        if(select == "final") {
            timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
        } else {
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,"DDCS","HIGH"));
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,"DDCS",calGain));
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"HIGH"));
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
            }
        }
        tslewmin = timeOBSID + timeChgBias + timeCal3CPR1 + tNewSetup;
        if(verbose) {
            debug_print("Tslewmin: " + tslewmin);
        }
        // Initial hold
        tih = 0;
        // Final hold
        tfh = timeEndID;
        // Duration of "stable" pointing in seconds
        tp = 1;
        //Issue PointReq
        ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    } else {
        // Several arguments needed for "basic_raster_pointing"
        // time to set OBSID and biases then PacsPhotSlewCal
        int timeCal3CPR5 = duration(OBCP_chopped_photometry(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,644));
        // Minimum slew time
        tslewmin = timeOBSID + timeChgBias + timeBckBias + tNewSetup + timeCal3CPR1;
        if(verbose) {
            debug_print("Tslewmin: " + tslewmin);
        }
        // Initial hold
        tih = 0;
        // Final hold
        tfh = timeChgBias + timeCal3CPR5 + timeEndID;
        // Fixed in the sky coordinates
        bool fixed = false;
        // Orientation angle (degrees)
        double patt = 0.0;
        // Number of pointings in a leg
        int m = 4;
        // Number of legs
        int n = 9;
        // Angular distance (arcsec) between 2 pointings
        double d1 = 26.0;
        // Angular distance (arcsec) between 2 legs
        double d2 = 26.5;
        // Duration of "stable" pointing in seconds
        if(chop) {
            int nLoops = measure_time * 40 / (2 * readouts_plateau);
            tp = duration(OBCP_chopped_photometry(0,0,nRdts,0,0,nLoops,1,-6578,7756,0,0,644));
            // 4x8 raster instead of 4x9
            n = 8;
            // Noise measurements after the raster
            tfh = tfh + 4 * measure_time + duration(TMMarker602()) + duration(TMMarker600());
            // Positive pointing offset for chopping to get negative chopper position offset
            yoffset = 105.0;
        } else {
            tp = measure_time;
        }
        // Go to OFF position every k pointings (not relevant with SSO tracking)
        int k = 0;
        // time in seconds on the OFF position (not relevant with SSO tracking)
        int top = 0;
        // OFF position RA coordinate (not relevant with SSO tracking)
        double raoff = 0.0;
        // OFF position Dec coordinate (not relevant with SSO tracking)
        double decoff = 0.0;
        //Issue PointReq
        ts = basic_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,k,top,raoff,decoff);
    }
}{
    int tNOW = time();
    int[] state = [0];
    if(select == "ginit" || select == "binit" || select == "final") {
        //  Start the sequence
        while(state[0] >= 0) {
            state = next_state();
            tNOW = time();
            if(state[0] == 1) {
                if(verbose) {
                    debug_print("SLEW starts at " + tNOW);
                }
                // Set OBSID
                WriteOBSID($OBSID);
                data_rate(120.0);
                // Set biases and start SPU
                if(select == "final") {
                    PHOT_change_biases(calBiasTable,calMode,calGain);
                } else {
                    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,"DDCS","HIGH");
                    }
                    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,"DDCS",calGain);
                    }
                    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,calMode,"HIGH");
                    }
                    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,calMode,calGain);
                    }
                }
                //************************************
                //  Call the Phot_highGainBiasDDCS
                //************************************
                Phot_highGainBiasDDCS(select,startBiasTable,endBiasTable);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                tNOW = time();
                if(verbose) {
                    debug_print("SLEW ends at   " + tNOW);
                }
            }
            if(state[0] == 2) {
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 3) {
                tNOW = time();
                if(verbose) {
                    debug_print("POINT starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("POINT ends at     " + tNOW);
                }
            }
            if(state[0] == 5) {
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD starts at   " + tNOW);
                }
                // Write EndID
                data_rate(0.0);
                WriteEndID();
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD ends at     " + tNOW);
                }
            }
        }
    } else {
        int finalChop = 0;
        //  Start the sequence
        while(state[0] >= 0) {
            state = next_state();
            tNOW = time();
            if(state[0] == 1) {
                if(verbose) {
                    debug_print("SLEW starts at " + tNOW);
                }
                // Set OBSID
                WriteOBSID($OBSID);
                data_rate(120.0);
                // Set biases and start SPU
                PHOT_change_biases(calBiasTable,calMode,calGain);
                //*******************************
                // Configure for the measurement
                //*******************************
                if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,"DDCS","HIGH");
                }
                if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,calMode,"HIGH");
                }
                if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,"DDCS",calGain);
                }
                //************************************
                //  Call the Phot_highGainBiasDDCS
                //************************************
                Phot_highGainBiasDDCS(select,startBiasTable,endBiasTable);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                tNOW = time();
                if(verbose) {
                    debug_print("SLEW ends at   " + tNOW);
                }
            }
            if(state[0] == 2) {
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 3) {
                tNOW = time();
                if(verbose) {
                    debug_print("POINT starts at   " + tNOW);
                }
                if(chop) {
                    //*********************************
                    // 2 positions chopping in the FOV
                    //*********************************
                    if(state[2] < m * n) {
                        finalChop = -6578;
                    } else {
                        finalChop = 7756;
                    }
                    OBCP_chopped_photometry(0,0,nRdts,0,0,nLoops,1,-6578,7756,0,0,finalChop);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("POINT ends at     " + tNOW);
                }
            }
            if(state[0] == 5) {
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD starts at   " + tNOW);
                }
                if(chop) {
                    TMMarker602();
                    delay(4 * measure_time);
                    TMMarker600();
                }
                // Set biases and start SPU
                PHOT_change_biases(calBiasTable,calMode,calGain);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                // Write EndID
                data_rate(0.0);
                WriteEndID();
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD ends at     " + tNOW);
                }
            }
        }
    }
}

// Missionphase  : PACS AVM ILT
//
// Purpose       : Reset detectors and HK after photometry,
//
// Author TCL    : T. Mueller
// Author CUS    : DAC 
//
// Arguments     : none
//                 
//
// Description   : This script will reset all parameters after
//                 photometry
//                              
// Comments      :  Has to be modified for CQM   
//
// Version       : 1.0 DAC 20-apr-2005
// History       : 1.0 DAC 20-apr-2005 Based on TM's 1.1 of 20-apr-2004 
//                 1.1 DAC 14-nov-2006 Cosmetical cleaning
procedure PHOT_dpu_dmc_reset {
}{
    // Invalidate science data photometry
    Pacs_DMC_INVAL_SCI_DATA_B();
    Pacs_DMC_INVAL_SCI_DATA_R();
    // Stop forwarding data to packet encoder
    int aux = 4;
    int check_sum = checksum("int",[aux]);
    {int}[] arg = Array2grp_1([aux]);
    Pacs_DMC_WRT_BOL_REC_OPT(arg,check_sum);
    aux = 4;
    check_sum = checksum("int",[aux]);
    arg = Array2grp_1([aux]);
    Pacs_DMC_WRT_B_DEC_REC_OPT(arg,check_sum);
    aux = 4;
    check_sum = checksum("int",[aux]);
    arg = Array2grp_1([aux]);
    Pacs_DMC_WRT_R_DEC_REC_OPT(arg,check_sum);
    Pacs_DPU_SET_HK_LIST("NO_PRIME","BOTH Array");
}

// CVS comments  : $Id: DMC_phot_2_3_chop.txt,v 1.5 2007/04/25 15:14:03 dcesarsk Exp $ 
// Missionphase  : 
//
// Purpose       : Two or three position chopping followed
//             by calibration readouts chopping between CS1 and CS2 
//             
//
// Author        : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : DMC_phot_2_3_chop.txt from AOT code
//
// Arguments     : 
//             nb_SRC_REF        Number of SRC->CHOPP1->SRC->CHOPP2 cycles
//             chop_pos_SRC      Position of chopper to see SRC
//             nb_rdouts_plateau Number of readouts per chopper plateau
//             chop_pos_REF1     Position of chopper for REF1
//             chop_pos_REF2     Position of chopper for REF2
//             nb_cycles_obs_cal Number of times (OBS = CAL)
//             nb_CS1_CS2        Number of CS1->CS2 cycles
//             chop_pos_CS1      Chopper position for CS1
//             chop_pos_CS2      Chopper position for CS2
//
// Description : Chopped observations of SRC in the manner:
//                     SRC->REF1->SRC->REF2 
//             followed by a calibration sequence using the internal 
//             blackbodies 
//                     CS1 -> CS2
//             User can specify the number of source observing cycles 
//            (nb_SRC_REF), the number of calibration cycles (nb_CS1_CS2) 
//             and how many times the whole sequence shall be repeated
//             (nb_cycles_obs_cal). 
//             The number of readouts per quiescent chopper position is 
//             the same (nb_rdouts_plateau) within each cycle  
//             
//
// Dependencies  : Stand alone DEC/MEC sequence  
//             
// Comments      : Follows line by line 4.1.1 in PACS-ME-LI-005
//
// Version       : 0.1 21-Jan-2004 Creation by DAC
// History       : 0.2 12-Oct-2004 Use only time related arguments
//             0.3 18-Oct-2004 Normalized variable names
//             0.4  9-Nov-2004 Return array containing 4 times.
//                             time[0] = total SRC time
//                             time[1] = total CAL time
//                             time[2] = total overhead time
//                             time[3] = total DMC time (by Version 0.1)
//             0.5 22-nov-2006 Removed debug_print
//             0.6 14-mar-2007 WAIT=1 for chopper are useful
//           :
int[] procedure DMC_phot_2_3_chop {
    int nb_SRC_REF = 1; // p01 Nb of cycles SRC->REF1->SRC->REF2
    int nb_rdouts_plateau = 16; // p03 Nb of readouts per chopper plateau
    int nb_cycles_obs_cal = 1; // p06 Nb of repetions of OBS-CAL cycle
    int nb_CS1_CS2 = 0; // p07 Nb of cycles CS1->CS2
}{
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Start tallying the duration (measured in number of readouts)
    int duration_rdouts = 0;
    // WAIT 1 ; have a defined start 
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; set Label to 0 
    // WAIT 1 ; have a defined start 
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // Outermost LOOP on nb_cycles_obs_cal
    for(int obs_cal_loop = 1 .. nb_cycles_obs_cal) {
        //  Inner LOOP on nb_SRC_REF 
        for(int obs_loop = 1 .. nb_SRC_REF) {
            // WAIT 1 ; sync. for chopper 
            duration_rdouts = duration_rdouts + 1;
            duree_SRC = duree_SRC + 1;
            // MOVE_CHOPPER_ABSOLUTE chop_pos_SRC; chopper to chop_pos_SRC 
            // LABEL 1 ; start quadruple 
            // WAIT nb_rdouts_plateau ; take nb_rdouts_plateau images 
            duration_rdouts = duration_rdouts + nb_rdouts_plateau;
            duree_SRC = duree_SRC + nb_rdouts_plateau;
            // WAIT 1 ; sync. for chopper 
            duration_rdouts = duration_rdouts + 1;
            duree_SRC = duree_SRC + 1;
            // MOVE_CHOPPER_ABSOLUTE chop_pos_REF1; chopper to chop_pos_REF1 
            // LABEL 3 ; next chopper position 
            // WAIT nb_rdouts_plateau ; take nb_rdouts_plateau images 
            duration_rdouts = duration_rdouts + nb_rdouts_plateau;
            duree_REF = duree_REF + nb_rdouts_plateau;
            // WAIT 1 ; sync. for chopper 
            duration_rdouts = duration_rdouts + 1;
            duree_SRC = duree_SRC + 1;
            // MOVE_CHOPPER_ABSOLUTE chop_pos_SRC; chopper to chop_pos_SRC 
            // LABEL 1 ; first chopper position 
            // WAIT nb_rdouts_plateau ; take nb_rdouts_plateau images 
            duration_rdouts = duration_rdouts + nb_rdouts_plateau;
            duree_SRC = duree_SRC + nb_rdouts_plateau;
            // WAIT 1 ; sync. for chopper 
            duration_rdouts = duration_rdouts + 1;
            duree_SRC = duree_SRC + 1;
            // MOVE_CHOPPER_ABSOLUTE chop_pos_REF2 ; move chopper to chop_pos_REF2 
            // LABEL 5 ; chopper position 3 
            // WAIT nb_rdouts_plateau ; take nb_rdouts_plateau images 
            duration_rdouts = duration_rdouts + nb_rdouts_plateau;
            duree_REF = duree_REF + nb_rdouts_plateau;
            // End inner loop on nb_SRC_REF
            // END_LOOP ; end loop measurement 
        }
        //  Inner LOOP on nb_CS1_CS2 
        for(int cal_loop = 1 .. nb_CS1_CS2) {
            // WAIT 1 ; sync. for chopper 
            duration_rdouts = duration_rdouts + 1;
            duree_CAL = duree_CAL + 1;
            // MOVE_CHOPPER_ABSOLUTE chop_pos_CS1 ; move chopper to CS1 
            // LABEL 65 ; chopper to CS1 
            // WAIT nb_rdouts_plateau ; take nb_rdouts_plateau images 
            duration_rdouts = duration_rdouts + nb_rdouts_plateau;
            duree_CAL = duree_CAL + nb_rdouts_plateau;
            // WAIT 1 ; sync. for chopper 
            duration_rdouts = duration_rdouts + 1;
            duree_CAL = duree_CAL + 1;
            // MOVE_CHOPPER_ABSOLUTE chop_pos_CS2 ; move chopper to CS2 
            // LABEL 129 ; chopper to CS2 
            // WAIT nb_rdouts_plateau ; take nb_rdouts_plateau images 
            duration_rdouts = duration_rdouts + nb_rdouts_plateau;
            duree_CAL = duree_CAL + nb_rdouts_plateau;
            // End inner loop on nb_CS1_CS2
            // END_LOOP ; end loop calibration
        }
        // End outermost loop on nb_cycles_obs_cal
        // END_LOOP ; end main loop
    }
    // WAIT 1 ; complete last plateau 
    duration_rdouts = duration_rdouts + 1;
    duree_OVR = duree_OVR + 1;
    // LABEL 0 ; no sequence anymore 
    // END_SEQUENCE
    // Define return array
    int[] time_array = [duration_rdouts,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    //    debug_print("DMC_phot_2_3_chop: " + time_array);
    // Return the array of times

    return time_array;
}

// Mission phase : Commissioning phase and later
//
// Purpose       : Read a BOLObias calibration table and command bias
//                 voltages for all the groups.
//                 VDL-BU for Group 3. Will also establish VDD_PROT_BLU
//                 and VDD_PROT_CL before setting bias voltages
//                 Then CKRLH and VDECX-L are set for the direct mode
//
// Author        : Koryo Okumura
// CUS script    : Koryo Okumura
//
// Arguments     : 
// string  biasTable    The bias table name
// string  gain         The gain "LOW" or "HIGH"
//
// Description   : Read a bias table in volts and set the direct mode
//                  
// Dependencies  : None
//
// Preconditions : Photometer is on and the sequencer is set
//
// Comments      :
//
// Version       : 0.1
// History       : 02-Jul-2008, KO: First version
//
procedure PHOT_set_bias_direct {
    string biasTable = "BOLObias_ILT_standard_low"; // Bias table [volts]
    string gain = "LOW"; // "LOW" or "HIGH"
}{
    //
    //***********************************************
    // Bias setting of the detectors
    //***********************************************
    //
    PHOT_set_bias_volt(biasTable,1);
    PHOT_set_bias_volt(biasTable,2);
    PHOT_set_bias_volt(biasTable,3);
    PHOT_set_bias_volt(biasTable,4);
    PHOT_set_bias_volt(biasTable,5);
    PHOT_set_bias_volt(biasTable,6);
    //
    //********************************************************
    // Sequence mode : blocking on VDEC_X for the direct mode
    //********************************************************
    //
    // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
    // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
    //
    //**********************************************************
    // Sequence mode : Sref_only (meaning set for the bolometer)
    //**********************************************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
    //# P 09 01 00 01
    int operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //**************************************
    // Start SPU in the appropriate setting
    //**************************************
    PHOT_spu_gain_setup(gain,0,0,3,3,true);
    delay(1);
    // to sync the bus
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Heat_SFT {
    /* No variables to call PacsEng_Spec_Heat_SFT                     */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Heat_SFT                   */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Heat_SFT()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Heat_SFT();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Filename	 : Pacs_Spec_Rsrf
// Purpose       :  Deep staring scan for RSRF verification 
//                  
//
// Input arguments  
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Uses OBCP28 for executing a deep scan
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                 
// Comments      : 
// Version	 : 1.0
// History	 : 1.0 30-oct-2008 BV Adopted from ILT PACS_Spec_Rsrf_OBS
//                      1.1 18-jul-2009 BV Corrected Ramp fitting instead of averages
// 
procedure Pacs_Spec_Rsrf {
    int chop_def = -21350; // chopper position during grating scan
    string filter = "POS A" in ["POS A","POS B"]; // Filter wheel position
    int grating_start = 32000; // grating start position for scan
    int grating_stepsize = 133; // grating step size
    int grating_numsteps = 7759; // number of grating steps
    int grating_numramps = 4; // number of ramps per grating position
    int readoutsperramp = 64; // number of readouts per ramp
    int capa_red = 12; // Red capacitor
    int capa_blu = 0; // Blue capacitor
    double bias_d_red = 0.07 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_red = 0.011 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.21 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_r_blu = 0.011 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
}{
    // OBCP parameters that are fixed
    int num_updown = 1;
    // number of grating updown scans
    int grat_def = 496000;
    // position of grating after the scan
    int chop_pos_CS1 = -21350;
    int chop_pos_CS2 = 21200;
    int detector = 1;
    // Synchronize on this detector 1:Blue 2:Red
    int nb_CS1_CS2 = 0;
    // number of cycles on calsources, 0=don't use them
    int nb_ramps_CS = 3;
    // number of ramps on CSs (not used)
    int grat_start_time = 15000;
    // time for grating to start [ms]
    int grat_def_time = 15000;
    // time for grating to go to default [ms]
    // CRE setup
    // cre_ctrl is a bit field:
    // 256=sync width=2, 128=T sensor on, 2=enable, 1=power on
    // Do not enable yet
    int cre_ctrl_red = 256 + 128 + 2 + 1;
    int cre_ctrl_blu = 256 + 128 + 2 + 1;
    int ramp_len_red = readoutsperramp;
    // Red ramp length
    int ramp_len_blu = readoutsperramp;
    // Blue ramps' length
    SPEC_CRE_No_Heater_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // Move the filter wheel to Position
    string filtername = "A";
    if(filter == "POS B") {
        filtername = "B";
    }
    SPEC_fltw_move(filter);
    // SPU setup
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int nb_samp_subramp_blu = 64;
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 64;
    // Nb of red samples per sub-ramp
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // scan
    OBCP_grat_scan_nochop(num_updown,grating_numsteps,grating_stepsize,-grating_stepsize,grating_numramps,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,nb_ramps_CS,grating_numsteps,chop_def,detector,grating_start,grat_start_time,comp_mode_blu,comp_mode_red,grat_def,grat_def_time,readoutsperramp);
    //
    // Reset spu
    SPEC_spu_reset();
}

// Missionphase  : 
//
// Purpose       : Move grating from gratNOW to gratNEW
//                 gratNOW is given only to estimate the needed time
//
// Author        : DAC
// CUS script    : Diego A. Cesarsky
// CVS file      : SPEC_grat_move.txt
//
// Arguments     : 
//Type   Name       DefVal     Description
//int    filter_id       1     Position of spectroscopic filter wheel  
//
// Description   :
// Dependencies  : 
//                 
// Comments      : This procedure sets necessary delay
//
// Version       : 0.1 
// History       : 0.1 14-feb-2007 DAC
//               :
procedure SPEC_grat_move {
    int gratNOW = 535000;
    int gratNEW = 596000;
    bool verbose = true;
}{
    // Time to move from NOW to NEW (SPEC_grat_time converts argument to abs)
    int neededTime = SPEC_grat_time(gratNOW - gratNEW);
    // Convert from msec to sec (at least 1 second wait!)
    neededTime = (neededTime + 999) / 1000;
    // Move now
    Pacs_DMC_MOVE_GRAT_ABS(gratNEW);
    if(verbose) {
        debug_print("MovGRAT: " + neededTime + " sec to move from/to " + gratNOW + "/" + gratNEW);
    }
    // set movement delay
    delay(neededTime);
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Script        : PACS_En_chopper_ast_OBS.cus
//
//
// Missionphase  : PACS IST Chopper Day
//
// Purpose       : Enable the chopper electronics
// Author CUS    : DAC/HD
//
// Input arguments
// Type  Name      Description
// Description   : Enable electronics, controller 
//
// Dependencies  : 
// Comments      : 
// Version       : 1.0 
// History       : 0.1 07-dec-2006 first creation
//               : 1.0 04-mar-2008  Converted into Eng OBS by VDP
//
//               : 0.2 05-jul-2007 IST Chopper Day
//               : 0.3 12-nov-2007 edited for SVT/PV conformance (MN)
obs PacsEng_En_chopper_ast {
    /* Needed variables to call PacsEng_En_chopper_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_En_chopper_ast                     */
}{
    string onoff = "ON";
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(EnDis_chopper(onoff)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            EnDis_chopper(onoff);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : FM IST
//
// Purpose	: Moves the grating back & forth throughout the RSRF, with long wait times, to study the transients
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: 
//
// Description	: 
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on
//	    The grating controller is SWON and ENABLED
//                       The FWSPEC is placed on position B
//
// Comments	: 
//
// Version	: 1.0
//               
// History	: 1.0 06-Apr-2007 PR Creation
//
procedure PACS_Spec_Time_Constant_IST {
    int idle_time = 240;
}{
    // Set OBSID
    WriteOBSID($OBSID);
    int gratposref = 150000;
    int gratposdef = 500000;
    int[] gratpos = [350000,550000,725000,925000];
    int npos = length(gratpos);
    int chop_BB1 = -21350;
    int chop_def = 0;
    //
    // Position FWSPEC on POS B
    //
    SPEC_fltw_move("POS B");
    //
    // Position Chopper on BB1
    //
    Pacs_DMC_MOVE_CHOP_ABS(chop_BB1);
    delay(1);
    //
    // Go
    //
    for(int n = 0 .. npos - 1) {
        Pacs_DMC_MOVE_GRAT_ABS_RAW(gratposref);
        delay(idle_time);
        Pacs_DMC_MOVE_GRAT_ABS_RAW(gratpos[n]);
        delay(idle_time);
    }
    Pacs_DMC_MOVE_GRAT_ABS_RAW(gratposref);
    delay(idle_time);
    Pacs_DMC_MOVE_CHOP_ABS(chop_def);
    Pacs_DMC_MOVE_GRAT_ABS_RAW(gratposdef);
    delay(10);
    // Reset OBSID
    WriteEndID();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
// 0.2 10-apr-2006 Update procedure name
obs PacsEng_SpectroscopytoNonPrime {
    /* No variables to call PacsEng_SpectroscopytoNonPrime                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POSB" */
    /* End of needed variables for PacsEng_SpectroscopytoNonPrime                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SpectroscopytoNonPrime()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SpectroscopytoNonPrime();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : PACS AVM ILT Orbit-Operations
//
// Purpose       : OBCP 10: Photometry Calibration I, calls DMC sequence 5
//
// OBCP author   : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky 
//
// Arguments: 
// Type  Name                  Description
// int   nb_main_loop          p01 number of times main loop is repeated
// int   chop_pos_CS1          p02 Chopper position on CS1
// int   nb_rdouts_plateau     p03 Number of readouts per chopper plateau
// int   nb_CS1_CS2_cycles     p04 Number of cycles alternating CS1-CS2
// int   chop_step_CS2_CS1     p05 Step size to go from CS2 to CS1
// int   chop_step_CS1_CS2     p06 Step size to go from CS1 to CS2
//
// Description   : This script mimics the OBCP_PHOT_CAL_I
//                 pseudo script, section 3.11.1 in PACS-ME-LI-005
//                 This CUS version computes the duration of the
//                 observation, as specified by the input parameters.
//                 It will also send the trigger TC to start the OBCP
//
// Dependencies  : DEC_phot_cal_I DECMEC sequence, 4.1.5
//                 WriteBBID to declare its BB identification 
// Comments      : 
//
// Version       : 0.1 17-Sep-2004 DAC
// History       : 0.2 29-Oct-2004 Editorial changes
//
int[] block OBCP_phot_cal_I PACS 10 {
    int nb_main_loop = 2; // p01 Number of times main loop is repeated
    int chop_pos_CS1 = -23680; // p02 Chopper position on CS1
    int nb_rdouts_plateau = 39; // p03 Nb rdouts per chopper plateau (4*n+1)
    int nb_CS1_CS2_cycles = 8; // p04 Number of cycles alternating CS1-CS2
    int chop_step_CS1_CS2 = 46270; // p05 Step to go from CS1 to CS2
    int chop_step_CS2_CS1 = -46020; // p06 Step to go from CS2 to CS1
    int comp_mode_blu = 0; // Compression mode BLUE channel
    int comp_mode_red = 0; // Compression mode RED channel
    int chop_def = 0; // Chopper default position
}{
    // Starting time
    int time_start = time();
    // Anounce start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Bolo sampling rate (needed to compute readout duration)
    double bol_freq = dlookup("PACSparams","bolo_sample","freq_time");
    string bol_unit = slookup("PACSparams","bolo_sample","unit");
    double bol_period = 1000.0 / bol_freq;
    debug_print("Bolo frequency: " + bol_freq + " " + bol_unit);
    debug_print("Bolo period: " + bol_period + "[msec]");
    // Obtain duration of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duration of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duration of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Accumulated duration of this script [msec]
    int duration_msec = 0;
    // OBCP pseudo-code starts here; accumulate duration as it goes)
    // OBCP_PHOT_CAL_I(seq,seq_time,P#1,&, P#6,comp_mode_blu,comp_mode_red,chop_def)
    // Begin 
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Call CUS version of DECMEC sequence to obtain duration
    // Returns array with [duration_rdouts,duree_SRC,duree_REF,duree_CAL,duree_OVR]
    int[] duree1 = DMC_phot_cal_I(nb_main_loop,nb_rdouts_plateau,nb_CS1_CS2_cycles);
    // Convert duration [readouts] into [msec]; add dmc_margin
    int seq_time = ifloor(double(duree1[0]) * bol_period) + dmc_margin;
    // Convert other times as well into msec
    duree_SRC = ifloor(double(duree1[1]) * bol_period);
    duree_REF = ifloor(double(duree1[2]) * bol_period);
    duree_CAL = ifloor(double(duree1[3]) * bol_period);
    duree_OVR = duree_OVR + ifloor(double(duree1[4]) * bol_period) + dmc_margin;
    // Tally into accumulated duration of OBCP   			 
    duration_msec = duration_msec + seq_time;
    // SYNCHRONIZE_ON_DETECTOR(4) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, comp_mode_blu, comp_mode_red, CHHKSUM) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_START_SEQUENCE 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(seq_time)
    // ; Check execution status of the sequence and in case of failure stop OBCP 
    // DMC_MOVE_CHOP_ABS(chop_def) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Issue TM(1,7) 
    // End
    // Duration: 7 x 200ms + seq_time + 0.5s
    // This procedure calls the sequence described in sec.4.1.5.
    //
    // Now trigger execution of OBCP
    // This OBCP is number 10, requires 11 parameters, call DEC seq #5
    // which lasts seq_time [msec]
    string obcp_ID = "PHOT_CALIB_I";
    int obcp_par_nber = 11;
    int seq_DMC = 5;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_main_loop},{4,chop_pos_CS1},{5,nb_rdouts_plateau},{6,nb_CS1_CS2_cycles},{7,chop_step_CS1_CS2},{8,chop_step_CS2_CS1},{9,comp_mode_blu},{10,comp_mode_red},{11,chop_def}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nber,grp);
    // Add the OBCP "jitter"
    duration_msec = duration_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Return total duration [sec] to calling program
    // Create return time array; convert into [sec]
    int[] time_array = [duration_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // Set delay()
    delay(time_array[0]);
    // Ending time
    int time_elapsed = time() - time_start;
    time_array[0] = time_elapsed;
    // Return

    return time_array;
}

// $Id: SPEC_spu_setup.txt,v 1.6 2007/08/09 15:40:11 dcesarsk Exp $
//
// Missionphase  : PACS ILT
//
// Purpose       : Condition SPU for SPECtroscopy observations
//                  
// TCL author    : Thomas Mueller
// TCL file      : tm_spec_spu_setup.tcl, version 1.3
//                    SetupSpectroscopyWEplusFPUsim.tcl v2.8
// CUS author    : Diego Cesarsky
// Script file   : SPEC_spu_setup.txt 
//
// Input arguments
// Type Name           Default   Description
// int  comp_mode_blu  16        Compression mode Default=16; double=17;
//                               lossless=20; transp=23; 4sec reset=24; 
//                               buffer_mode=25, noise=33
// int  comp_mode_red  16        As above for RED
// int  nb_samp_subramp_blu 64   Number of samples per sub-ramp 
//                               (>=4 and <= readouts per ramp)
// int  nb_samp_subramp_red 64   As above for RED
// int  spu_nraw_blu     3       Number of raw channels transmitted by SPU
// int  spu_nraw_red     3       As above for RED
// int  glitch_det       1       Glitch detection; 0=on; 1=off
// int  ramp_fit_alg     1       Ramp fit algorithm: 0=LstSq fit,1=mean value
// bool startSPU      true       Start SPU after setting values
//
// Description   : Sets values for compression mode,
//                 threshold values (glitch, chopper, grating), raw 
//                 channel transmission, sub-ramp and detector
//                 constants, load DPU time and restart SPU. Script
//                 sets its own delays [sec] and returns the total
//                 duration in milliseconds. This version addresses
//                 BLU and RED; could make a BLU only and RED only version
//                 The call sequence to this module is as follows:
//  PacsXXXXSpec->PacsSpecDefault->
//  PacsSpecSlewCal->SPEC_aot_prologue->SPEC_spu_setup 
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      : Based on V1.3 of TM's tm_spu_setup.tcl. Both
//                 SPUS and SPUL are initialized to same set of parameters
//
// Version         1.0
// History       : 0.1 13-Aug-2004 First creation
// 0.2  8-Oct-2004 Added separate variables for SPUL and
//                                 SPUS. Return duration.
//                                 Editorial changes (DAC)
// 0.3 12-Oct-2004 Reviewed after simplification of 
//                                 SPEC_spu_reset. Remove
//                                 redundant/useless TCs. Removed "delay"
//                                 statements
// 0.4 13-Oct-2004 Error in Pacs_SPUx_RAW_CHAN_TRAN_MODE:
//                                 second parameter should be spuX_nraw.
//                                 Added boolean START to be able to use
//                                 this procedure in SPEC_orbit_prologue
//                                 which DOES NOT start the SPU 
// 0.5 21-Oct-2004 Moved xx_RAW_CHAN_TRAN_MODE below 
//                                 WRT_DET_CST_SPEC to follow HF's setup script
// 0.6 18-Mar-2005 Redone to follow line by line TM's script,
//                                 Added several comments
// 0.7 10-Apr-2006 Parameter set has been changed for
//                 Pacs_SPUL_WRT_DET_CST_SPEC and      (RV)
//                 Pacs_SPUS_WRT_DET_CST_SPEC commands (comply w/SPU HLSW v12.1)
//                 "spu_par" has been changed, new parameters have been added:
//                  - "reor", Reordering algorithm
//                  - "llcs", Lossless compression algorith
//                  - "ords", Range for the PACS codec
//                 Changes based on SetupSpectroscopyWEplusFPUsim.tcl v2.8
// 0.8  3-jul-2006 Remove duration references
// 0.9  9-aug-2006 update of WRT_DET_CST_SPEC
// 0.91  29-aug-2006 TM: update of WRT_DET_CST_SPEC (SPU OBSW V12.8), new default values
// 0.92  06-dec-2006 TM: update of WRT_DET_CST_SPEC (SPU OBSW V12.8.1), new default values
// 1.0   28-mar-2007 DAC Update for SPU V13.x
// 1.1   24-mar-2009 DAC Update after SPU UM 13.95a
// 2.0   17-jun-2009 DAC Introduced reading of CONF_SPEC_param but for time 
//                       being I have no solution how to choose one row rather
//                       than other. Used row name will be hard coded here
//                       row = "Normal0" in CONF_SPEC_param
// 2.1   06-jul-2009 VD  de-hardcode comp_mode  
// 2.2   06-jul-2009 VD introduces SPU scenario                    
//             
procedure SPEC_spu_setupSPU {
    string scenario = "none";
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 16; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 16; // Nb of red samples per sub-ramp
    int nb_raw_spu_blu = 3; // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3; // Nb of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1; // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true; // Start SPU or not [true,false]
}{
    // Spectro "Ottensamer" block is now read off CONF_SPEC_param
    string calU = "CONF_SPEC_param";
    string rowName = "Normal0";
    if(scenario == "none") {
        string rowRED = "" + rowName + "RED";
        string rowBLU = "" + rowName + "BLU";
    } else {
        rowRED = "" + scenario + "RED";
        rowBLU = "" + scenario + "BLU";
    }
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    // Set the SPU compression modes
    // (TC arguments are defined as type {int}[], cf. definition of
    //  Pacs_DMC_WRT_SPU_TRAN_MODE; hence define comp_par accordingly)
    comp_mode_red = ilookup(calU,rowRED,"cmp_mde");
    comp_mode_blu = ilookup(calU,rowBLU,"cmp_mde");
    {int}[] comp_par = [{comp_mode_blu},{comp_mode_red}];
    // The "checksum" function needs an array as argument, hence use elements
    // of comp_par cast as an array:                      
    int[] aux = [comp_mode_blu,comp_mode_red];
    int check_sum = checksum("int",aux);
    // Issue the TC
    Pacs_DMC_WRT_SPU_TRAN_MODE(comp_par,check_sum);
    // Setting of start index of raw channels for SPUS and SPUL
    string spus_obs_mode = "SPEC";
    string spul_obs_mode = "SPEC";
    int spus_startraw = ilookup(calU,rowRED,"st_ind");
    int spul_startraw = ilookup(calU,rowBLU,"st_ind");
    Pacs_SPUS_RAW_CHAN_TRAN_MODE(spus_obs_mode,nb_raw_spu_blu,spus_startraw);
    Pacs_SPUL_RAW_CHAN_TRAN_MODE(spul_obs_mode,nb_raw_spu_red,spul_startraw);
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    int ppf = ilookup(calU,rowBLU,"ppf");
    // PPP: Pre-Processing Parameter
    int ppp = ilookup(calU,rowBLU,"ppp");
    // Threshold for glitch detection in spectroscopy
    int tfs = ilookup(calU,rowBLU,"tfs");
    // Threshold for chopper position deviation in spectroscopy
    int tcs = ilookup(calU,rowBLU,"tcs");
    // Threshold for grating deviation
    int tgd = ilookup(calU,rowBLU,"tgd");
    // Readouts per SubRamp readback
    int rsrr = nb_samp_subramp_blu;
    // Glitch detection for spectroscopy
    int gdfs = glitch_det;
    // Ramp fitting algorithm
    int rfal = ramp_fit_alg;
    // Sorting algorithm
    int soal = ilookup(calU,rowBLU,"soal");
    // lossless compression algorithm (0,1,2,3,4)
    int lcal = ilookup(calU,rowBLU,"lcal");
    // PACS Codec Order (3,4)
    int pcod = ilookup(calU,rowBLU,"pcod");
    // New 13.95a values are
    int rndb = ilookup(calU,rowBLU,"rndb");
    int rnds = ilookup(calU,rowBLU,"rnds");
    int fixrc = ilookup(calU,rowBLU,"fixrc");
    int dpre = ilookup(calU,rowBLU,"dpre");
    int dpost = ilookup(calU,rowBLU,"dpost");
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    {int}[] spu_par = Array2grp_1(aux);
    // and issue TC to "Short" SPU
    Pacs_SPUS_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    // Spectro "Ottensamer" block ("L" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    ppf = ilookup(calU,rowRED,"ppf");
    // PPP: Pre-Processing Parameter
    ppp = ilookup(calU,rowRED,"ppp");
    // Threshold for glitch detection in spectroscopy
    tfs = ilookup(calU,rowRED,"tfs");
    // Threshold for chopper position deviation in spectroscopy
    tcs = ilookup(calU,rowRED,"tcs");
    // Threshold for grating deviation
    tgd = ilookup(calU,rowRED,"tgd");
    // Readouts per SubRamp readback
    rsrr = nb_samp_subramp_red;
    // Glitch detection for spectroscopy
    gdfs = glitch_det;
    // Ramp fitting algorithm
    rfal = ramp_fit_alg;
    // Sorting algorithm
    soal = ilookup(calU,rowRED,"soal");
    // lossless compression algorithm (0,1,2,3,4)
    lcal = ilookup(calU,rowRED,"lcal");
    // PACS Codec Order (3,4)
    pcod = ilookup(calU,rowRED,"pcod");
    // New 13.95a values are
    rndb = ilookup(calU,rowRED,"rndb");
    rnds = ilookup(calU,rowRED,"rnds");
    fixrc = ilookup(calU,rowRED,"fixrc");
    dpre = ilookup(calU,rowRED,"dpre");
    dpost = ilookup(calU,rowRED,"dpost");
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    spu_par = Array2grp_1(aux);
    // and issue TC to "Long" SPU
    Pacs_SPUL_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    // Send time stamps
    // DMC_WRT_TIME: Write the time sent by the DPU into the DMC buffer
    // (No action on this one?)
    // DPU sends the time to DEC/MEC
    Pacs_DPU_SEND_TIME();
    // DMC_SET_TIME: Set the time previously written by the write time command
    Pacs_DMC_SET_TIME();
    // Start reduction/compression if commanded to do so
    if(startSPU) {
        Pacs_SPUS_START_REDUCT_COMPR();
        Pacs_SPUL_START_REDUCT_COMPR();
    }
    sync();
}

// $Id: PacsEng_Spec_dark_current_pv.txt,v 1.1 2008/11/12 11:40:20 vanessad Exp $
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose	:  Short performance test Dark Current
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do dark current measurements in buffer transmission mode on
//                     both CS positions.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and internal CSs switched off.
//                        CDMS has to be switched to burst mode. After the end of the
//                        test go back to nominal mode.
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 1.0
// 
// History 	: 1.0 04-04-07 HD. IST update.
// 		  2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//		  based on PacsEng_Spec_dark_current_imt502
//		  3.0 15-07-08 HD. Version now for PV.
//                4.0 13-11-08 HD. now including the busconfig(7) command
obs PacsEng_Spec_dark_current_pv {
    /* Needed variables to call PacsEng_Spec_dark_current_pv                        */
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    int gratPOS = 500000; // Grating Position
    /* End of needed variables for PacsEng_Spec_dark_current_imt502                     */
}{
    //
    busconfig (7);
    // BURST MODE :     4:PACS PRIME  -  7:BURST MODE  - 8:PARALLEL MODE
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_dark_current_pv(fltPOS,gratPOS)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(300.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_dark_current_pv(fltPOS,gratPOS);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Purpose	: SPU nominal data rate check (photometry)
//
// Author	: Roland Vavrek
// CUS script	: RV
// CVS file	: 
//
// Arguments	: No interactive parameters
//                         
//                 
//		   
// Description	: Photometry, staring 7 min on CS2/CS1 and chopper zero position in default/double compression SPU setup.
//  
//                  
// Dependencies :  - Chop_mov_abs
//                          - PHOT_spu_reset
//                          - PHOT_spu_setup
//
//
// Preconditions : - PACS is switched on
//                         - Setup photometry with nominal parameters 
//	      - Mechanics and CS controllers are SWON and ENABLED
//                         - CS2/CS1 temperature is raising but not yet stabilized
//
// Comments	: The default detector selection table is assumed to be used before executing this script.
//
// Version	: 2.0
//               
// History	: 2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
// 		  1.3 09-Apr-2007 Use PHOT_spu_reset and PHOT_spu_setup
//                1.2 05-Apr-2007 Chopper positions on CS1 and zero added, double compression mode 
//                                    added on CS2, unit time is reduced to 2 min. Constants updated for FM/ILT
//                1.1 27-Apr-2005 SPU reset attached to the end
//                1.0 21-Apr-2005 Creation by RV
//
procedure Pacs_Phot_spu_data_rate {
}{
    //
    // 1 - Mechanics parameters
    //
    // chopper in zero position
    int chop_def_zero = 664;
    // chopper on CS2
    int chop_CS2_pos = 21200;
    // chopper on CS1
    int chop_CS1_pos = -21350;
    // 
    // 2 - SPU parameters
    // 
    //  Compression blue: default=0, double=1, half=2, lossless=4, transp=7, buffer=9
    int comp_mode_blu = 0;
    //  Compression blue: default=0, double=1, half=2, lossless=4, transp=7, buffer=9
    int comp_mode_red = 0;
    // Number of raw channels transmitted in the blue SPU
    int nraw_blu = 3;
    // Number of raw channels transmitted in the red SPU
    int nraw_red = 3;
    // Start SPU or not [true,false]
    bool startSPU = true;
    // 
    // 3- Start test
    //
    //
    // 3.1 - Default compression, 3 raw channels
    //
    // 
    // 3.1.1 - Position chopper on CS2 position
    //
    Chop_mov_abs(chop_CS2_pos);
    // Switch off science data flow
    PHOT_spu_reset();
    // Default compression, 3 raw channels
    PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,startSPU);
    // 2 min staring measurement on CS2
    delay(120);
    // 
    // 3.1.2 - Move chopper to position 0
    //
    Chop_mov_abs(chop_def_zero);
    //  2 min staring measurement on chopper zero position
    delay(120);
    // 
    // 3.1.3 - Move chopper to CS1  
    //
    Chop_mov_abs(chop_CS1_pos);
    // 2 min staring measurement on chopper zero position
    delay(120);
    // Position chopper on zero position
    Chop_mov_abs(chop_def_zero);
    //
    // 3.2 - Double compression, 3 raw channels
    //
    // 
    // 3.2.1 - Position chopper on CS2 position
    //
    Chop_mov_abs(chop_CS2_pos);
    // Switch off science data flow
    PHOT_spu_reset();
    // Change compression mode
    comp_mode_blu = 1;
    comp_mode_red = 1;
    // Double compression, 3 raw channels
    PHOT_spu_setup(comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,startSPU);
    // 2 min staring measurement on CS2
    delay(120);
    //
    // 4 - End of measurement
    //
    // Switch off science data flow
    PHOT_spu_reset();
    // Position chopper on zero position
    Chop_mov_abs(chop_def_zero);
}

// Missionphase  : EQM IMT
//
// Purpose	: Perform one MOVE_GRATING_ABSOLUTE
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: target_pos : Grating target position
//
// Description	: executes Pacs_DMC_MOVE_GRAT_ABS_RAW
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on
//	    The grating controller is SWON, ENABLED and HOMED
//	    (e.g. SetupSpectroscopyEQMIMT takes care for it)
//
// Comments	: Since the amplitude of the movement cannot be computed, THIS BBlock/COMMAND DOES NOT INCLUDE ANY DELAY!!!
//
// Version	: 1.0
//               
// History	: 1.0 30-Mar-2004 Creation by PR
//
block SPEC_Gra_move_abs_raw PACS 103 {
    int target_pos = 500000; // Target position
}{
    // Register start of BB
    WriteBBID($BBID);
    Pacs_DMC_MOVE_GRAT_ABS_RAW(target_pos);
    // Mark End of Block
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Perform Spectroscopy Thermal behaviour test
//
// CUS author    : TM
// Script file   : SPEC_thermal_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform PACS spectroscopy thermal behaviour
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// 
// History       : 0.1 TM 17-nov-2006
// History       : 1.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_thermal {
    /* Needed variables to call PacsEng_Spec_thermal                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_thermal                     */
}{
    double temp_CS1 = 48.0;
    double temp_CS2 = 58.0;
    string fltPOS = "POS A";
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_thermal(fltPOS,temp_CS1,temp_CS2)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_thermal(fltPOS,temp_CS1,temp_CS2);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : Start Autonomy Function 17
//                 
//
// Author        : Helmut Feuchtgruber
//
// Arguments     : None
//
// Description   : Simply call Aut_17
//
// Dependencies  : Aut_17
//
// Comments      : 
//
// Version       : 1.0 26-Mar-2007 HF
// History       : 1.0 26-Mar-2007 initial Version 
//
procedure Aut_17 {
}{
    Pacs_DPU_SET_FUNCT("EVENT_BOL_V_PWR","ENABLE");
}

// Missionphase  : 
//
// Purpose       : Start Autonomy Function 14
//                 
//
// Author        : Helmut Feuchtgruber
//
// Arguments     : None
//
// Description   : Simply call Aut_14
//
// Dependencies  : Aut_14
//
// Comments      : 
//
// Version       : 1.0 26-Mar-2007 HF
// History       : 1.0 26-Mar-2007 initial Version 
//
procedure Aut_14 {
}{
    Pacs_DPU_SET_FUNCT("EVENT_BOL_T_FPU","ENABLE");
}

// $Id: PacsCal_WaveCalChop.txt,v 1.3 2008/04/21 09:48:07 vanessad Exp $
// Missionphase		: PACS PV Phase
//
// Purpose :		Wavelength calibration and instrumental profile
// 	      	      	 with Chop/Nod
// Author		 : HF
//
// Arguments:
//
// Prerequisite 	: PACS does not need to be on nor setup for spectroscopy
//
// Description		: Uses OBCP27 for executing a parameterized scan of any length,
// 			  stepsize etc. Represents a generic chopped grating scan
// Comments		:
//
// Version		: 1.4
// 
// History		: 0.1 Using example from PacsCal_WaveCalNoChop
// 			: 1.0 perform calibrations during slew and 
//    	  	       	   then a wavelength calibration on source
//			   usng NOD=1 and Choping
//		     1.1 17-12-2008 VD: SPR 5692 missing PacsSpecDefault call
//                       22-apr-2009   1.2 VD SPR 5447 
//	                 23-apr-2009	  1.3 VD SPR 6482
//                       23-jul-2009   1.4 BV SPR 1798 (default biases)
//                       14-sep-2009 1.5 VD PHS-1173
//                       
obs PacsCal_WaveCalNodRaster {
    /* Needed variables to call WaveCalChop */
    /* Spectro definitions */
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int grat_pos = 500000; // grating start position for scan
    int grat_time = 0; // time for grating to move to start position [msec]
    int grat_step_up = 200; // grating step size
    int nb_ramps_plateau = 1; // number of readouts per grating position
    int grat_step_dn = 200; // grating step size
    int nb_grat_steps = 50; // number of grating steps in one direction
    int order = 2; // end position for order selection: 1=Red, 2= or 3= Blue)                
    int nb_SRC_REF = 3; // number of ramps (cycles) per grating position
    int nb_CS1_CS2 = 0; // nb of cycles on internal CS
    int nb_rdouts_ramp = 64; // number of readouts per ramp
    int nb_up_down = 1; // number of grating updown scans
    /* Detector definitions */
    int nb_raw_red = 3; // number of red pixels
    int nb_raw_blu = 3; // number of blue pixels
    int capa_red = 12; // Red capacitor
    int capa_blu = 12; // Blue capacitor
    double bias_r_blu = 0.0101; // Bias "r" blue
    double bias_r_red = 0.0101; // Bias "r" red
    double bias_d_blu = 0.10001; // Bias "d" blue
    double bias_d_red = 0.04201; // Bias "d" red
    int comp_mode_blu = 16; // compression mode for blue detector
    int detector = 1; // 1=blue 2=red (sync on detector)
    int comp_mode_red = 16; // compression mode for red detector
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp
    /* Pointing parameters */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    double raoff = 0.0 in [0.0,360.0];
    double decoff = 0.0 in [-90.0,90.0];
    bool refSelected = false; // OFF position needed
    bool startAtB = false; // false=start nodding at A, true=start at B
    /* raster */
    int m = 2 in [2,100]; // Number of points in a raster line
    int n = 1 in [1,100]; // number of raster lines
    double d1 = 2.0 in [2.0,480.0]; // Raster point separation in a line [arcsec]
    double d2 = 2.0 in [2.0,480.0]; // Raster line separation [arcsec]
    bool fixed = false; // Raster in S/C (=false) or SKY coordinates (=true)
    int nnod = 1; // number of nods (AB or BA)
    double nodthrow = 30.0 in [2.0,960.0]; // chop/nod throw
    double patt = 0.0; // Raster pattern orientation
    double pattnod = 270.0; // Nodding orientation (defined along y-axis if fixed=false, else ccw to north)
    bool verbose = true;
}{
    // compiting time for slw / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Set OBSID
    int tobsid = duration(WriteOBSID($OBSID));
    // Verification for grating and chopper hard limits
    int[] gratpos = [0];
    Pacs_HardLimitsCheck(gratpos,nodthrow);
    // Calibration time during slew
    // SPEC parameters for BLU and RED               
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    string throwUsage = "small";
    string extraConf = "normal";
    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // frstLstGratPos is the last position for the grating after the Cals done
    // during Slew time... must be same as observations start position: grat_pos   
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    // "N/A" in string because of indexing 0,1,2,3
    string[] choix = ["N/A","order1","order2","order3","sed4"];
    string order_str = "order" + order;
    //    if(choix[order] != "order1") {
    //        double keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //    double keyWL = PacsSpecKeyWaves(order_str);
    double[] keyWAVE = [150.0];
    if(choix[order] == "order3" && fltPOS == "POS B") {
        error("Filter B and order 3 are not compatible");
    }
    if(choix[order] == "order1" && fltPOS == "POS A") {
        keyWAVE = [180.0];
    }
    if(choix[order] == "order1" && fltPOS == "POS B") {
        keyWAVE = [150.0];
    }
    if(choix[order] == "order2" && fltPOS == "POS B") {
        keyWAVE = [75.0];
    }
    if(choix[order] == "order3" && fltPOS == "POS A") {
        keyWAVE = [60.0];
    }
    // this is for extended Blue
    if(choix[order] == "order2" && fltPOS == "POS A") {
        keyWAVE = [60.0];
        choix[order] = "sed4";
    }
    // no need for SpecKeyWave!
    int tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]));
    //   } else {
    //       keyWAVE1 = dlookup("KEY_WAVES",order_str,"KeyWave1");
    //       double keyWAVE2 = dlookup("KEY_WAVES",order_str,"KeyWave2");
    //       keyWAVE = [keyWAVE1,keyWAVE2];
    //        tpacsSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]));
    //   }
    //Initial hold
    int tih = 0;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int grat_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int tepilog = duration(SPEC_aot_epilogue(grat_pos,grat_def,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(WaveCalChop(fltPOS,grat_pos,grat_time,grat_step_up,grat_step_dn,nb_grat_steps,nb_CS1_CS2,nb_rdouts_ramp,nb_ramps_plateau,nb_up_down,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_SRC_REF,nodthrow,detector));
    if(verbose) {
        debug_print("Duration of WaveCalChop" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    int k = 0;
    int tloadmin = 0;
    int nload = 0;
    int thold = 0;
    int nhold = 0;
    int top = 0;
    int nrepeat = 1;
    // minimum duration of the slew between repeats
    int trepeatmin = 0;
    //Issue PointReq
    int tslewmin = tobsid + tpacsSlewCal;
    if(verbose) {
        debug_print("Slewing time is:" + tslewmin + "sec");
    }
    int[] ts = nodding_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodthrow,nnod,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            int tNOW = time();
            // slew time calibration
            WriteOBSID($OBSID);
            if(verbose) {
                debug_print("Slewing starts at :" + tNOW + " sec");
            }
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            if(choix[order] == "order1") {
                PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]);
            } else {
                PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doPROLOG,keyWAVE,order,grat_pos,choix[order]);
            }
            tNOW = time();
            if(verbose) {
                debug_print("Slewing ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                WaveCalChop(fltPOS,grat_pos,grat_time,grat_step_up,grat_step_dn,nb_grat_steps,nb_CS1_CS2,nb_rdouts_ramp,nb_ramps_plateau,nb_up_down,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_SRC_REF,nodthrow,detector);
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 7) {
                    //       Call the WaveCal procedure
                    tNOW = time();
                    if(verbose) {
                        debug_print("Observation at NOD starts at :" + tNOW + " sec");
                    }
                    WaveCalChop(fltPOS,grat_pos,grat_time,grat_step_up,grat_step_dn,nb_grat_steps,nb_CS1_CS2,nb_rdouts_ramp,nb_ramps_plateau,nb_up_down,capa_red,capa_blu,bias_r_blu,bias_r_red,bias_d_blu,bias_d_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_SRC_REF,nodthrow,detector);
                    tNOW = time();
                    if(verbose) {
                        debug_print("Observation at NOD ends at :" + tNOW + " sec");
                    }
                } else {
                    if(state[0] == 5) {
                        tNOW = time();
                        if(verbose) {
                            debug_print("Final Hold starts at :" + tNOW + " sec");
                        }
                        SPEC_aot_epilogue(grat_pos,grat_def,verbose);
                        WriteEndID();
                        tNOW = time();
                        if(verbose) {
                            debug_print("Final Hold ends at :" + tNOW + " sec");
                        }
                    }
                }
            }
        }
    }
    // End of Observation
}

// version 1.0
// History 1.0 05-dec-2008 VD Change call of CONFGrat with ISTSafe
//
procedure PACS_Spec_Gra_PID_loop_Short_Less {
}{
    int[] kp = [1000,1250,1500,1750,2000];
    int[] ki = [10000,20000,30000,40000,50000];
    int[] kd = [5,8,11,15];
    int nsteps_kp = length(kp) - 1;
    int nsteps_ki = length(ki) - 1;
    int nsteps_kd = length(kd) - 1;
    string calUname = "CONFGrat";
    // GRATING CALIBRATION TABLE
    string calUrow = "ISTSafe";
    // INSTRUMENT VERSION
    //
    // ----------------------------
    // SWITCH ON GRATING CONTROLLER
    // ----------------------------
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    //
    int word0 = ilookup(calUname,calUrow,"Kp");
    int word1 = ilookup(calUname,calUrow,"Ki");
    int word2 = ilookup(calUname,calUrow,"Kd");
    int word3 = ilookup(calUname,calUrow,"Kf");
    int word4 = ilookup(calUname,calUrow,"Rate");
    int word5 = ilookup(calUname,calUrow,"AccLimit");
    int word6 = ilookup(calUname,calUrow,"OutputLimit");
    int word7 = ilookup(calUname,calUrow,"Scaling");
    int word8 = ilookup(calUname,calUrow,"ErrorLimit");
    {int}[] params = [];
    int[] aux = [];
    int chksum = 0;
    //
    for(int np = 0 .. nsteps_kp) {
        for(int ni = 0 .. nsteps_ki) {
            for(int nd = 0 .. nsteps_kd) {
                // DISABLE GRATING CONTROLLER
                Pacs_DMC_DISABLE_GRAT_CONT();
                delay(1);
                //
                word0 = kp[np];
                word1 = ki[ni];
                word2 = kd[nd];
                // Create the parameter list tuple
                params = [{word0},{word1},{word2},{word3},{word4},{word5},{word6},{word7},{word8}];
                // Create the array for the checksum function
                aux = [word0,word1,word2,word3,word4,word5,word6,word7,word8];
                chksum = checksum("int",aux);
                // Send the TC
                Pacs_DMC_WRT_GRAT_CONF_PAR(params,chksum);
                delay(1);
                // ENABLE GRATING CONTROLLER
                Pacs_DMC_ENABLE_GRAT_CONT();
                delay(3);
                for(int m = 0 .. 5) {
                    Pacs_DMC_MOVE_GRAT_REL_RAW(117);
                    delay(1);
                }
                for(int j = 0 .. 5) {
                    Pacs_DMC_MOVE_GRAT_REL_RAW(-117);
                    delay(1);
                }
                Pacs_DMC_MOVE_GRAT_REL_RAW(233010);
                delay(10);
                Pacs_DMC_MOVE_GRAT_REL_RAW(-233010);
                delay(10);
            }
        }
    }
    // DISABLE GRATING CONTROLLER
    Pacs_DMC_DISABLE_GRAT_CONT();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Fil_Diaghk_Setup {
    /* variables to call PacsEng_Spec_Fil_Diaghk_Setup                        */
    int diag_hk_period = 5; //1: sync w/ BLUE DET 2: sync with RED DET >4 period in ms 0: 1Khz (not to use w/ science
    /* End of needed variables for PacsEng_Spec_Fil_Diaghk_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Fil_Diaghk_Setup(diag_hk_period)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Fil_Diaghk_Setup(diag_hk_period);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Script file   :  PACS_Spec_Gra_IST_Full_Charac_OBS.cus 
//
// Purpose       :  Fully Characterize one set of PID parameters (Healthcheck & slewtime cal)
//
// Description  : 
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
//                 1.1  13-Nov-2007 BV Added MOIS comments
//	2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//	2.1 21-Nov-2008 Remove use of calUrowSECURE, useless right before going to SAFE MODE.
//
//
procedure Pacs_Spec_Gra_IST_Full_Charac {
    string calUrowSLOW = "PVSlow";
    string calUrowFAST = "PV";
}{
    mois_comment("Start of procedure: Full characterisation of the grating control loop parameter set");
    //
    mois_step("Configure Nominal SPEC_HK");
    debug_print("Configure Nominal SPEC_HK");
    PACS_Spec_HK_Setup();
    //
    // SETUP DIAGHK
    //
    int diag_hk_period = 5;
    // 5 msec diag hk period 
    debug_print("Configure Diag_HK");
    mois_step("Configure Diag_HK");
    PACS_Spec_Gra_Diaghk_SINCOS_Setup(diag_hk_period);
    //
    // PRE-CONFIGURE & HOME GRATING : SLOW RATE
    //
    mois_step("PRE-CONFIGURE & HOME GRATING : SLOW RATE");
    string calUname = "CONFGrat";
    // GRATING CALIBRATION TABLE
    //string calUrowSLOW = "ISTSlow";
    //string calUrowFAST = "IST";
    // string calUrowSECURE = "FMILTFast";
    // INSTRUMENT VERSION
    CONF_grating(calUname,calUrowSLOW);
    //
    // GRATING HEALTHCHECK
    //
    // HOMING_MODE : 0 for "POSITIVE" (homing at low grating positions), 1 for 'NEGATIVE"
    mois_step("Health check - homing positive");
    string homing_mode = "POSITIVE";
    PACS_Spec_Gra_Healthcheck_BB(homing_mode);
    mois_step("Health check - homing negative");
    homing_mode = "NEGATIVE";
    PACS_Spec_Gra_Healthcheck_BB(homing_mode);
    //
    // SET THE PID PARAMETERS SPECIFIC TO THIS TEST : FAST
    //
    mois_step("Configure grating controller: fast rate");
    int homing_mode_rate = 0;
    PACS_Spec_Gra_Set_Ctrl_Par(calUname,calUrowFAST,homing_mode_rate);
    //
    // MINI-SCANS OVER THE FULL RANGE
    //
    mois_step("mini-scans over the full range");
    int grat_start_pos = 80000;
    // grating starting position (~3 degrees from the hard stop)
    PACS_Spec_Gra_Tune_PID(grat_start_pos);
    //
    // FULL CHARACTERISATION WITH MOVEMENTS OF ALL AMPLITUDES
    //
    // (copy & paste of PACS_Spec_Gra_Slew_Time_Cal
    int gra_steps_per_block = 3;
    int time_on_pos = 2;
    double atomic_step_pos = 116.505;
    double atomic_step_neg = -116.505;
    double[] steps = [1.0,2.0,3.0,3.43,5.15,7.725,10.3,15.0,20.6,50.0,100.0,200.0,600.0];
    int n_steps = length(steps) - 1;
    int astep = 0;
    mois_step("full characterisation with movements of all amplitudes- block 1 - bottom upwards");
    // First block : from bottom, upwards 
    SPEC_Gra_move_abs_raw(66000);
    delay(25);
    for(int n1 = 0 .. n_steps) {
        // debug_print("n1 =" + n1 + " steps[n1] = " + steps[n1]);
        astep = iround(steps[n1] * atomic_step_pos);
        SPEC_Gra_move_rel_raw_loop(gra_steps_per_block,astep,time_on_pos);
    }
    mois_step("full characterisation with movements of all amplitudes- block 2 - center upwards");
    // Second block : from center, upwards 
    SPEC_Gra_move_abs_raw(500000);
    delay(25);
    for(int n2 = 0 .. n_steps) {
        astep = iround(steps[n2] * atomic_step_pos);
        SPEC_Gra_move_rel_raw_loop(gra_steps_per_block,astep,time_on_pos);
    }
    // Third block : from top, downwards 
    mois_step("full characterisation with movements of all amplitudes- block 3 - top downwards");
    SPEC_Gra_move_abs_raw(1030000);
    delay(25);
    for(int n3 = 0 .. n_steps) {
        astep = iround(steps[n3] * atomic_step_neg);
        SPEC_Gra_move_rel_raw_loop(gra_steps_per_block,astep,time_on_pos);
    }
    // Fourth block : from center, downwards 
    mois_step("full characterisation with movements of all amplitudes- block 4 - center downwards");
    SPEC_Gra_move_abs_raw(500000);
    delay(25);
    for(int n4 = 0 .. n_steps) {
        astep = iround(steps[n4] * atomic_step_neg);
        SPEC_Gra_move_rel_raw_loop(gra_steps_per_block,astep,time_on_pos);
    }
    // End : bring the grating back to central position
    mois_step("Bring the grating back to central position");
    SPEC_Gra_move_abs_raw(500000);
    delay(25);
    //
    // RESTORE ORIGINAL PID PARAMETERS
    //
    //mois_step("Restore origiinal PID parameters");
    //homing_mode_rate = 0;
    //PACS_Spec_Gra_Set_Ctrl_Par(calUname,calUrowSECURE,homing_mode_rate);
    //
    // RESET DIAGHK
    //
    mois_step("Reset diagnostic housekeeping");
    PACS_Diaghk_Reset();
    //
    mois_step("PACS to safe mode");
    debug_print("PACS to SAFE MODE");
    OBCP_SAFE();
    delay(10);
}

// Missionphase  : 
//
// Purpose       : Read a BOLObias calibration table and command bias
//                 voltages for the given group, viz.
//                 VDL-BU for Group 3. Will also establish VDD_PROT_BLU
//                 and VDD_PROT_CL before setting bias voltages
//
// Author        : Diego A. Cesarsky
// CUS script    : Diego A. Cesarsky
// CVS file      : PHOT_set_bias_volt.txt
//
// Arguments     : 
// string  calTableName    The Cal table name, f.i. BOLObias or BOLOsafe
// string  BiasGR          The group number, BiasGRn (n:1, 2, ..6)
//
// Description   : Read Bias U-CAL tables in volts.
//                 Since BIAS are to be set in a predetermined order, the
//                 array biasOrder lists the preconised ordering.
//                 Prior to commanding the voltage generators, two voltages
//                 have to be switched ON with the operand
// 
//                 0x0001 + 0x10000*BiasNum + 0x1000000*GroupNum
//
//                 and this for BiasNum 23, 22 and 21
//                  
// Dependencies  : 
//
// Preconditions :
//
// Comments      :
//
// Version       : 0.3
// History       : 0.1   07-aug-2006; 1st version DAC
//                 0.1.1 22-aug-2006, KO, waitFor set to 1s everywhere
//                 0.2 17-oct-2006 DAC Had forgotten GND-BU
//                 0.3 13-nov-2006 DAC&TM Wait 3 sec after GND-BU
//
procedure PHOT_set_bias_volt {
    string calTableName = "PHOT_bias_low_direct"; // The U-Cal table [volts]
    int groupNb = 1 in [1,6]; // Requested group
}{
    // Construct BiasGR entry
    string biasGR = "BiasGR" + groupNb;
    // Switch ON the requested group (bias numbers 22 and 21)
    int biasHexa = 0x1;
    int biasNb = 22;
    int operand = groupNb * 0x1000000 + biasNb * 0x10000 + biasHexa;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    int waitFor = 1;
    delay(waitFor);
    biasNb = 21;
    operand = groupNb * 0x1000000 + biasNb * 0x10000 + biasHexa;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    waitFor = 1;
    delay(waitFor);
    biasNb = 23;
    operand = groupNb * 0x1000000 + biasNb * 0x10000 + biasHexa;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    waitFor = 3;
    delay(waitFor);
    // Bias setting order
    string[] biasOrder = ["VDD-PROT-BU","VDD-PROT-CL","GND-BU","VGL-BU","VDL-BU","VSS-BU","VGG","VDD","VGL","VDL","VH-BLIND","VSS","VDECX-L","VDECX-H","CKRLL","CKRLH","VSMS-L","VSMS-H","VINJ","VH","VL","VRL","VCH"];
    // Introduce 1 sec delay after commanding each bias
    waitFor = 1;
    // Use lookup function; get BIAS voltage for given group and Bias number
    // For each BIAS defined in table and for demanded group
    for(int index = 3 .. 22) {
        biasNb = ilookup(calTableName,biasOrder[index],"Bias");
        double biasVolt = dlookup(calTableName,biasOrder[index],biasGR);
        //   Branch according to group number	
        if(groupNb == 1) {
            PHOT_bias_group_1(groupNb,biasNb,biasOrder[index],biasVolt);
        }
        if(groupNb == 2) {
            PHOT_bias_group_2(groupNb,biasNb,biasOrder[index],biasVolt);
        }
        if(groupNb == 3) {
            PHOT_bias_group_3(groupNb,biasNb,biasOrder[index],biasVolt);
        }
        if(groupNb == 4) {
            PHOT_bias_group_4(groupNb,biasNb,biasOrder[index],biasVolt);
        }
        if(groupNb == 5) {
            PHOT_bias_group_5(groupNb,biasNb,biasOrder[index],biasVolt);
        }
        if(groupNb == 6) {
            PHOT_bias_group_6(groupNb,biasNb,biasOrder[index],biasVolt);
        }
    }
    // to sync the bus
    sync();
}

// CVS comments  : $Id: PacsReadKeyWave.txt,v 1.2 2007/04/25 15:14:04 dcesarsk Exp $ 
// Missionphase  : Operations
//
// Purpose       : 
//
// CUS author    : 
// Script file   : PacsReadKeyWave.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-may-2005 DAC
double procedure PacsReadKeyWave {
    string order = "1"; //
    double waveUSER = 100.0; //
}{
    // Local variables
    double[] waves = [0.0];
    double differ = 1000.0;
    double closest = 0.0;
    // Open KEY_WAVES table and read number of columns for given order
    int nb_cols = ilookup("KEY_WAVES",order,"nWAVE");
    // Read each column (KeyWave1, KeyWave2, etc.)   
    for(int loop1 = 1 .. nb_cols) {
        string colNAME = "KeyWave" + loop1;
        waves[loop1 - 1] = dlookup("KEY_WAVES",order,colNAME);
        if(abs(waves[loop1 - 1] - waveUSER) <= differ) {
            closest = waves[loop1 - 1];
            differ = abs(closest - waveUSER);
        }
    }
    // debug_print ("Waves: " + waves + " closest " + closest);  

    return closest;
}

// $Id$
// Missionphase  : PACS PV Phase
// File          : PACS_Chopper_EnDis_PlateauTest_ast_OBS.cus
//
//
// Purpose       : Switch-on/switch-off and enanle/disable test of chopper
//
// Author        : MN/HD
// CUSification  : MN/HD
// Arguments     :
//
// Description   : This script allows to insert a chopper defelction and a
//                 duration in seconds during
//                 which the chopper is enabled. This is used to evaluate the
//                 stability of the chopper while selecting various chopper
//                 control parameters.
//
// Comments      :
//
// Version       : 4.0
// History       : 1.0 11-Apr-2007 initial version
//		 : 2.0 05-Jul-2007 IST Chopper Day
//		 : 3.0 12-Nov-2007 edited for SVT/PV conformance
//		 : 4.0 04-mar-2008 translated into PV phase script VDP
//
obs PacsEng_Chopper_EnDis_PlateauTest_ast {
    /* Needed variables to call PacsEng_Chopper_EnDis_PlateauTest_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Chopper_EnDis_PlateauTest_ast                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Chopper_EnDis_PlateauTest_NoConf_ast()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Chopper_EnDis_PlateauTest_NoConf_ast();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : FM ILT 
//
// Purpose       : Switch on/off the chopper electronics
//
// Author CUS    : MN 
//
// Author TCL    : N/A
//
// Original TCL  : N/A
//
// Input arguments
// Type    Name          DefVal   Description
// string  on_off        "ON"     ON: switch on chopper, OFF: switch off
//
// Description   : 
//
// Dependencies  : 
//                 
// Comments      : 
//
// Version       : 0.1 08-03-2007 First creation
//               :
//
procedure PACS_Chopper_SWON_SWOF_only {
    string on_off = "ON" in ["ON","OFF"];
}{
    if(on_off == "ON") {
        //      debug_print("Switching on chopper");
        Pacs_DMC_SWON_CHOP_CONT();
    }
    if(on_off == "OFF") {
        //      debug_print("Switching off chopper");
        Pacs_DMC_SWOF_CHOP_CONT();
    }
}

// Script file   : PACS_Spec_Gra_IST_PID_Loop_OBS.cus 
// Purpose       :  Run a loop of tens of different sets of PID parameters
//
// Description  : For each set, performs a dozen of small and two larger movements
//
// CUS author    : PR
//
// Preconditions : PACS in SAFE MODE
//
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
// 		   2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
procedure Pacs_Spec_Gra_IST_PID_Loop {
}{
    mois_comment("Start of procedure: Run a grid of daring PID parameters");
    // Register start of OBS
    //
    mois_step("Configure Nominal SPEC_HK");
    debug_print("Configure Nominal SPEC_HK");
    PACS_Spec_HK_Setup();
    //
    mois_step("Configure Diagnostic HK");
    debug_print("Configure DIAG_HK");
    int diag_hk_period = 5;
    PACS_Spec_Gra_Diaghk_Setup(diag_hk_period);
    //
    mois_step("Configure grating");
    debug_print("Configure Grating");
    string calUname = "CONFGrat";
    string calUrow = "IST";
    CONF_grating(calUname,calUrow);
    delay(10);
    //
    debug_print("PID LOOP : PIDs greater than in FMILT");
    mois_step("Loop over PID parameters; reconfigure and do diagnostic movements");
    PACS_Spec_Gra_PID_loop_Short();
    //
    mois_step("Reset DIAG_HK");
    debug_print("Reset DIAG_HK");
    PACS_Diaghk_Reset();
    //
    mois_step("PACS to SAFE mode");
    debug_print("PACS to SAFE MODE");
    OBCP_SAFE();
    delay(10);
}

// File          : CONF_chopper_ast.cus
// Missionphase  : PACS IST Chopper Day
//
// Purpose       : Configure the chopper servo loop 
//
// Author        : DAC/MN/HD
// CUSification  : DAC/MN/HD
// Arguments     : 
// string calUfile  CAL-U file
// string calUcol   Column identifier
//                 
//
// Description   : Read servo loop parameters off a CALU table; a set
//                 of parameters is arranged as a column; different
//                 columns list different sets. Must specify the CALU
//                 file name and the column identification string.
//                 Example: CONF_chopper ("CONFChopper","nom_sky")
//                              
// Comments      :      
//
// Version       : 0.6
// History       : 0.1  9-nov-2006 Initial version
//                 0.2 22-feb-2007 Adapted to revised CONFChopper table
//                                (PosLimit  <=> Scaling
//                 0.3  8-mar-2007 Added 2sec delay at end per HD's mail
//                 0.4  9-jun-2007 Changed entries for new DECMEC (MN)
//                 0.4  9-jun-2007 newly optimised parameters (MN)
//		   0.5  5-jul-2007 IST Chopper Day
//                 0.6 12-oct-2007 BV: added mois comment
procedure CONF_chopper_ast {
    string fileU = "CONFChopper_ast"; // CAL-U file
    string calUcol = "nom_ast"; // Column identifier
}{
    mois_comment("Start of procedure to write PACS chopper control parameters");
    mois_step("Write the control parameters to the DMC");
    // # DMC_WRT_CHOP_CONF_PAR (21 params). Use  values
    //   obtaied from CALU file
    int aKp = ilookup(fileU,"Kp",calUcol);
    int aKi = ilookup(fileU,"Ki",calUcol);
    int aKd = ilookup(fileU,"Kd",calUcol);
    int aKf = ilookup(fileU,"Kf",calUcol);
    int aRate = ilookup(fileU,"Rate",calUcol);
    int aAccumLimit = ilookup(fileU,"AccumLimit",calUcol);
    int aOutputLimit = ilookup(fileU,"OutputLimit",calUcol);
    int aPosLimit = ilookup(fileU,"PosLimit",calUcol);
    int aErrorLimit = ilookup(fileU,"ErrorLimit",calUcol);
    int aPosOffset = ilookup(fileU,"PosOffset",calUcol);
    int aKiCurr = ilookup(fileU,"KiCurr",calUcol);
    int aSelectFieldPlateLUT = ilookup(fileU,"SelectFieldPlateLUT",calUcol);
    int aSpare = ilookup(fileU,"Spare",calUcol);
    int aFilterN1 = ilookup(fileU,"FilterN1",calUcol);
    int aFilterN2 = ilookup(fileU,"FilterN2",calUcol);
    int aFilterN3 = ilookup(fileU,"FilterN3",calUcol);
    int aFilterD1 = ilookup(fileU,"FilterD1",calUcol);
    int aFilterD2 = ilookup(fileU,"FilterD2",calUcol);
    int aInductance = ilookup(fileU,"Inductance",calUcol);
    int aResistance = ilookup(fileU,"Resistance",calUcol);
    int aControlLoopGain = ilookup(fileU,"ControlLoopGain",calUcol);
    // Create tuple array and int array
    {int}[] list_tuple = [{aKp},{aKi},{aKd},{aKf},{aRate},{aAccumLimit},{aOutputLimit},{aPosLimit},{aErrorLimit},{aPosOffset},{aKiCurr},{aSelectFieldPlateLUT},{aSpare},{aFilterN1},{aFilterN2},{aFilterN3},{aFilterD1},{aFilterD2},{aInductance},{aResistance},{aControlLoopGain}];
    // Define as int [] to compute check sum
    int[] list_int = [aKp,aKi,aKd,aKf,aRate,aAccumLimit,aOutputLimit,aPosLimit,aErrorLimit,aPosOffset,aKiCurr,aSelectFieldPlateLUT,aSpare,aFilterN1,aFilterN2,aFilterN3,aFilterD1,aFilterD2,aInductance,aResistance,aControlLoopGain];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_CHOP_CONF_PAR(list_tuple,chksum);
    delay(2);
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       :  Open the Grating Launch Lock
//                  
//                 
//
// TCL author    : HF
// TCL file      : PACS_Open_Launch_Lock.tcl
// CUS author    : HF
// Script file   : LLock_Open.txt 
//
// Input arguments none
// type    name         description
//
// Return values none
// Type    Name      Default      Description
//
// Description   : Calls only OpenLLock
//	You can use the same parameters with both redundant and nominal electronics and command both motors separetely.
// 	Let's name "Motor N" the motor connected to nominal electronics and "Motor R" the motor connected to redundant electronics.
// 	Then the different parameters have the following effects :
//
// 	- When using nominal electronics :
// 	DMC_LOCK_GRAT + 0x12 = Lock Motor N + Motor R
// 	DMC_LOCK_GRAT + 0x2 = Lock Motor N
// 	DMC_LOCK_GRAT + 0x10 = Lock Motor R
// 	DMC_UNLOCK_GRAT + 0x28 = Unlock Motor N + Motor R
// 	DMC_UNLOCK_GRAT + 0x8 = Unlock Motor N
// 	DMC_UNLOCK_GRAT + 0x20 = Unlock Motor R
//
//	- When using redundant electronics :
// 	DMC_LOCK_GRAT + 0x12 = Lock Motor R + Motor N
// 	DMC_LOCK_GRAT + 0x2 = Lock Motor R
// 	DMC_LOCK_GRAT + 0x10 = Lock Motor N
// 	DMC_UNLOCK_GRAT + 0x28 = Unlock Motor R + Motor N
// 	DMC_UNLOCK_GRAT + 0x8 = Unlock Motor R
// 	DMC_UNLOCK_GRAT + 0x20 = Unlock Motor N
//
//                  
// Dependencies  : OpenLLock
//
// Preconditions : PACS must be switched-on and in the equivalent of the SAFE mode
// 
// Version	: 2.0
// History       : 1.0 24-Mar-2005  creation by HF
//                 1.1 12-Apr-2006 HF, include degraded modes operation
//		   2.0 04-Mar-2008 Translated into PV script VDP
//                 
obs PacsEng_LLock_Open {
    /* Needed variables to call PacsEng_LLock_Open                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_LLock_Open                     */
}{
    int unlock_mode = 40;
    // use motors: 8=motor 1, 32 =motor 2, 40 = both motors
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(OpenLLock(unlock_mode)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            OpenLLock(unlock_mode);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : EQM IMT 
//
// Purpose       :  SAFE mode OBCP
//                  
//                 
//
// TCL author    : HF
// TCL file      : 
// CUS author    : HF 
// Script file   : OBCP_SAFE.txt 
//
// Input arguments none
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Transit to SAFE mode
//                            
//                           
//                            
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                             
//                 
// Comments      : 
// 
// History       : 1.0 29-Mar-2005 creation by HF
//
int block OBCP_SAFE PACS 24 {
}{
    // Register start of BB
    WriteBBID($BBID);
    // Tally duration (NOTE: we use [msec] for the return value)
    int duration_msec = 0;
    Pacs_DPU_START_OBCP("GO_SAFE_MODE",0,[]);
    delay(10);
    duration_msec = duration_msec + 10000;
    // Mark End of Block
    WriteEndBB();
    // Return time

    return duration_msec;
}

// Missionphase  : 
//
// Purpose       : Prepare MEC for photometry, including filterwheel,
//                 chopper and calibration sources 
//                  
// TCL author    : TM
// TCL file      : tm_phot_mec_setup.tcl
// CUS author    : DAC
// Script file   : PHOT_dmc_setup.txt
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : This script will switch on and set all required
//                 parameters for the chopper, the photometry filter
//                 wheel and the calibration sources.
//                 This script should be executed just after the
//                 switch-on procedure and the bolometer setup
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version      0.8
// History      
// 0.1 12-apr-2005 DAC (based on TM's version 1.2)
// 0.2 13-apr-2005 DAC Redefined as procedure
// 0.3 20-apr-2005 DAC Use new CONF_cs
// 0.4 08-aug-2006 TM, integration of diagnostic HK for fw and chopper
// 0.5 10-nov-2006 DAC Use "current" chopper controller parameters          
// 0.6 13-nov-2006 DAC Use "Heidelberg 4deg" chopper controller parameters          
// 0.7 05-mar-2007 TM update for chopper and CSs
// 0.8 15-Jun-2007 PR modify PHOT_fltw_conf -> CONF_phot_fltw
//
int[] procedure PHOT_dmc_setup {
    string phot_fltw_id = "POS B" in ["POS A","POS B"]; // Photometer filter ID
    int chop_def_pos = 0; // Chopper default position
    double temp_CS1 = 48.0; //  Temperature for the PACS calibration source 1 
    double temp_CS2 = 58.0; //  Temperature for the PACS calibration source 2
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    //-------------------
    // FILTERWHEEL
    //-------------------
    //
    // Configure diagnostik HK for filterwheel
    // Read out every 5 ms
    // DMC_WRT_DIAG_HK_LIST
    // DMC_FW_PHOT_CTRL  211
    // DMC_FWGRAT_HALLA  256
    // DMC_FWGRAT_HALLB  257
    // DMC_FWPH_CUR_POS  260                    
    // DMC_FPU_T_SEN_ST  404
    // DMC_FW_PHOT_TEMP  406                    
    // DMC_FW_GR_VMOTA   556
    // DMC_FW_GR_IMOTA   560
    // DMC_FWPHOT_POS_A  563
    // DMC_FW_GR_VMOTB   564
    // DMC_FW_GR_IMOTB   567
    // DMC_FWPHOT_POS_B  569
    {int}[] parlist_fw = [{211},{256},{257},{260},{404},{406},{556},{560},{563},{564},{567},{569},{0xffff}];
    int[] aux_fw = [211,256,257,260,404,406,556,560,563,564,567,569,0xffff];
    int check_sum_fw = checksum("int",aux_fw);
    int diag_hk_length_fw = 13;
    int diag_hk_period_fw = 5;
    Pacs_DMC_WRT_DIAG_HK_LIST(diag_hk_length_fw,parlist_fw,check_sum_fw);
    Pacs_DMC_START_DIAG_HK(diag_hk_period_fw);
    //
    CONF_phot_fltw();
    //PHOT_fltw_conf();
    // PC129420 "DMC_SWON_FW_PHOTO" SWITCH ON POWER SUPPLY OF FILTER WHEEL PHOTO
    // PC136420 "DMC_MOVE_PHOT_FW_LOC" MOVE PHOTOMETER FILTER WHEEL TO LOCATION
    //         PP075420 "FW_ID"
    // PC109420 "DMC_SWOF_GRAT_CONT" SWITCH OFF GRATING CONTROLLER
    PHOT_fltw_move(phot_fltw_id);
    delay(1);
    //
    Pacs_DMC_STOP_DIAG_HK();
    delay(1);
    //
    //-------------------
    // CHOPPER
    //-------------------
    //
    // Configure diagnostik HK for chopper
    // Read out every 5 ms
    // DMC_CHOP_CTRL_ST  209
    // DMC_CHOP_CUR_POS  244
    // DMC_CHOP_SETPOIN  245
    // DMC_CHOP_TARGET   246
    // DMC_CHOP_PID_ERR  247
    // DMC_CHOP_PID_ACC  248
    // DMC_CHOP_MAX_DIT  249
    // DMC_CHOP_OUTPUT   258
    // DMC_CHOPPER_TEMP  407
    // DMC_CHOP_VA       557
    // DMC_CHOP_IA       561
    // DMC_CHOP_VB       565
    {int}[] parlist_cho = [{209},{244},{245},{246},{247},{248},{249},{258},{407},{557},{561},{565},{0xffff}];
    int[] aux_cho = [209,244,245,246,247,248,249,258,407,557,561,565,0xffff];
    int check_sum_cho = checksum("int",aux_cho);
    int diag_hk_length_cho = 13;
    int diag_hk_period_cho = 5;
    Pacs_DMC_WRT_DIAG_HK_LIST(diag_hk_length_cho,parlist_cho,check_sum_cho);
    Pacs_DMC_START_DIAG_HK(diag_hk_period_cho);
    //
    // DMC_WRT_CHOP_CONF_PAR (now modified for 20 parameters)
    CONF_chopper("CONFChopper","nom_sky");
    // PC119420 "DMC_SWON_CHOP_CONT" SWITCH ON CHOPPER CONTROLLER
    // PC121420 "DMC_ENABLE_CHOP_CONT" ENABLE CHOPPER CONTROLLER
    CHOP_on_off("ON");
    // PC123420 "DMC_MOVE_CHOP_ABS" MOVE CHOPPER TO AN ABSOLUTE POSITION
    //         PP079420 "SET_POINT"
    Pacs_DMC_MOVE_CHOP_ABS(chop_def_pos);
    delay(1);
    //
    Pacs_DMC_STOP_DIAG_HK();
    delay(1);
    //
    //-------------------------
    // PACS CALIBRATION SOURCES
    //-------------------------
    // DMC_WRT_CS1_CONF_PAR
    // DMC_WRT_CS2_CONF_PAR
    CONF_cs("Both");
    // PC138420 "DMC_SWON_BB_1_CONT" SWITCH ON BLACK BODY 1 CONTROLLER
    // PC206420 "DMC_ENABLE_BB_1_CONT" ENABLE BB1 CONTROLLER
    CS_on_off("CS1","ON");
    // PC140420 "DMC_SET_TEMP_BB_1" SET THE TEMPERATURE OF THE BLACK BODY 1
    //         PP079420 "SET_POINT"
    CS_temp("CS1",temp_CS1);
    // PC142420 "DMC_SWON_BB_2_CONT" SWITCH ON BLACK BODY 2 CONTROLLER
    // PC208420 "DMC_ENABLE_BB_2_CONT" ENABLE BB2 CONTROLLER
    CS_on_off("CS2","ON");
    // PC144420 "DMC_SET_TEMP_BB_2" SET THE TEMPERATURE OF THE BLACK BODY 2
    //         PP079420 "SET_POINT"
    CS_temp("CS2",temp_CS2);
    //-------------------------
    // End of Procedure
    //-------------------------
    // Return empty array for time being...
    // Time spent
    int duree_TCs = time() - time_start;
    duree_OVR = duree_TCs;
    duree_num = duree_OVR;
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// Filename	 : Pacs_Spec_chopped_SED
// Purpose       : Exercise chopped SED
//                  
//                 
//
// TCL author    : N/A
// TCL file      : tN/A
// CUS author    : TM
// Script file   : 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Exercise all available OBCPs for PHOT
//   
// Dependencies  : 
//
// Preconditions : SPEC_setup has been executed
//     
// Comments   : 
// 
// Version      2.1
// History      0.1 11-apr-2007 TM
// 		2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//              2.1 15-Apr-2008 VDP Adjusted blue heater current value
//                              from 1.5mA to 0.78mA  
//
procedure Pacs_Spec_chopped_SED {
}{
    // Register with environment
    // Start SPU
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    int nb_samp_subramp_blu = 32;
    int nb_samp_subramp_red = 32;
    int nb_raw_spu_blu = 0;
    int nb_raw_spu_red = 0;
    int glitch_det = 1;
    int ramp_fit_alg = 0;
    //
    // 32 readouts per ramp, 0,0 capacitor, (obsolete) 1.5mA blue heater current
    //                                      0.78 mA
    //
    SPEC_CRE_setup(32,32,0.069,0.01,0.198,0.01,0,0,0.78);
    //
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,true);
    //
    // Position the filter wheel at POS A
    //
    SPEC_fltw_move("POS A");
    //
    // Perform OBCP_grat_line_scan_chop_2 with default parameters  
    debug_print("Start OBCP_grat_line_scan_chop_2");
    OBCP_grat_line_scan_chop_2(1,430,1,648,2,-21350,0,0,0,2400,-2400,1,32000,20000,16,16,500000,0,10000,32);
    delay(2);
    //
    // Position the filter wheel at POS B
    //
    SPEC_fltw_move("POS B");
    //
    // Perform OBCP_grat_line_scan_chop_2 with default parameters
    debug_print("Start OBCP_grat_line_scan_chop_2");
    OBCP_grat_line_scan_chop_2(1,430,1,648,2,-21350,0,0,0,2400,-2400,1,32000,20000,16,16,500000,0,10000,32);
    delay(2);
    //
    SPEC_fltw_move("POS A");
    //
    // Stop SPU
    //
    PACS_spu_reset();
    // Leave environment
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose 
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//- Test of internal calibration recipes including different chopper
//  frequencies photometry including time constants for flux changes
//  (just between the 2 CSs)
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//                  
//                 
//
// TCL author    : TM
// TCL file      : TM
// CUS author    : TM
// Script file   : PHOT_cal_recipes_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version	 : 1.0
// History       : 0.1 27-apr-2005 DAC
//
//                 0.4 26-apr-2005 DAC Use PACS_spu_reset
//                 0.5  4-nov-2005 DAC Added 1 sec to the wait after DMC load (from 2 to 3 sec)
//                 0.6 11-apr-2007 update by TM (OBCPs, 40Hz, ....)
//		   1.0 25-mar-2008 VDP Translated from IST to PV phase syntax 
//
obs PacsEng_Phot_cal_recipes {
    /* Needed variables to call PacsEng_Phot_cal_recipes                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_cal_recipes                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Phot_cal_recipes()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Phot_cal_recipes();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : FM ILT
//
// Purpose	 : Move chopper in open-loop mode
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : This building block moves the chopper while in open-loop
//                 mode. The parameters are assumed in ROU representing
//                 current settings that are directly sent to the chopper. 
//                  
// Dependencies  :  
//
// Preconditions : PACS switched-on, chopper is switched on, enabled and in
//                 open-loop mode
//                 
// Comments	 : First try of a CUS BB
//
// Version	 : 1.0	
// 
// History 	 : 1.0 15-12-06 creation by MN
// Begin Mode description
block PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB PACS 432 {
    int chop_pos = 0;
}{
    // Get BBID from environment
    int myBBID = $BBID;
    // Send BBID to DMC
    WriteBBID(myBBID);
    // Moving chopper
    debug_print("Commanding chopper to " + chop_pos);
    Pacs_DMC_MOVE_CHOP_ABS(chop_pos);
    // Mark End of Block
    WriteEndBB();
}

/////////////////////////////////////////////////////////////////////////////
/// $Id$
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsCal_PacsLineSpec
//
// CUS author    : DAC
//
// Input arguments: see after module identification
//
// Return values
// {int,int,int} {totalDuration,slewDuration,obsOverPACSandSC}
//
// Comments      :
//
// History: 
// 22-may-2008 0.1  DAC PV version based on PacsLineSpecObs
//                  - reads PV version of EstimatorOBCP35
//                  - removed most of AOT features
//                  - only one line per AOT 
//                  - either raster or scan w/off mode
//                  - chopper throw is user defined
// 22-apr-2009 1.0 VD: SPR 5447: added KeyWave CalSlew  
// 23-apr-2009 1.1 VD SPR 6482
//
{int,int,int} obs PacsCal_PacsLineSpec {
    /* "lines" is defined as an array; its elements (and hence its dimension)    */
    /*  are provided by HSPOT in the AOT version. Here they are filled in-situ   */
    /* {id,redshifted wavelength,repeat factor,line flux,continuum flux,      */
    /*  line width,line flux unit,line width unit}                            */
    {string,double,int,double,double,double,string,string}[] lines = [];
    /*------------- following only to use CUS interface -------------------------*/
    string[] lineId = ["My lines"];
    double[] lWave = [82.0]; // line wavelength  in [55.0,210.0]
    int[] repeatLine = [1]; // repeat line in [0,10]
    double[] lineFlux = [111.0]; // Line Flux in [0.0,10000.0]
    double[] lcontFlux = [111.11]; // Continuum flux  in [0.0,10000.0]
    double[] lineWidth = [30.0];
    string[] fluxUnit = ["Jy/m2"];
    string[] widthUnit = ["kms"];
    /*------------- above only to use CUS interface -------------------------*/
    int userNODcycles = 1 in [1,100];
    string orderSel = "order2" in ["order2","order3"];
    /* Here we may chop and/or nod, raster or scan mode (no staring mode!!) */
    bool chopper = true; // Chopping does not apply to scan mode
    bool nodding = true; // Nodding  does not apply to scan mode
    string pmode = "raster" in ["raster","scan"];
    /* Raster parameters */
    int m = 3 in [2,32];
    int n = 3 in [1,32];
    double pointStep = 20.0 in [2.0,480.0];
    double lineStep = 20.0 in [2.0,480.0];
    /* Scan parameters */
    double mapScanSpeed = 10.0; // Scan rate
    double mapScanLegLength = 30.0 in [1.0,1200.0]; //Scan leg [arcmin]
    int mapScanNumLegs = 2 in [1,1500]; //Number of scan legs
    string mapScanAngleRef = "inst" in ["sky","inst","i+c","s+c"];
    double mapScanConstrFrom = 0.0 in [0.0,360.0];
    double mapScanConstrTo = 0.0 in [0.0,360.0];
    double mapScanAngle = 0.0 in [0.0,360.0];
    double mapScanCrossScan = 2.0 in [2.0,480.0]; // Scan separation [arcsec]
    bool faintLines = true;
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    string throw = "large" in ["large","medium","small"];
    double chopthrow = 60.0; // Chopper throw [arcsec]
    string source = "point" in ["point","dithered","large"];
    double mapRasterAngle = 0.0 in [0.0,360.0];
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    bool refSelected = false;
    double raoff = 0.0 in [0.0,360.0];
    double decoff = 0.0 in [-90.0,90.0];
    int naifid = 0; // RA,DEC or SSO
    string redshiftType = "redshift" in ["redshift","optical"];
    double redshiftValue = 0.0;
    int obsOverhead = 180; // Slew overhead
    bool verbose = true; // debugging verbose
}{
    //*--------- following only when using CUS interface -------------------*/
    int linesIdLength = length(lineId);
    int linesLength = length(lines);
    if(linesLength == 0) {
        for(int lLoop00 = 0 .. linesIdLength - 1) {
            lines[lLoop00] = {lineId[lLoop00],lWave[lLoop00],repeatLine[lLoop00],lineFlux[lLoop00],lcontFlux[lLoop00],lineWidth[lLoop00],fluxUnit[lLoop00],widthUnit[lLoop00]};
        }
    }
    //*--------- above only when using CUS interface -------------------*/
    // Start of "Pointing" section
    // New variable to start at nodded position
    bool startAtOFF = false;
    // extraConf: whatever affects PACS default configuration 
    // Currently: the option faintLines calls for an extraConf
    string extraConf = "normal";
    // For bright lines
    if(!faintLines) {
        extraConf = "bright";
    }
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // Need switching boolean
    bool chopNod = true;
    bool switching = !chopNod;
    // Decode more HSPOT information
    int nbLines = length(lines);
    int nbLines1 = nbLines - 1;
    // Cannot call with empty "lines"
    if(nbLines == 0) {
        error("STOP!! There are no spectral lines defined!");
    }
    // Nodding/chopping are not allowed in scan pmode
    if(pmode == "scan") {
        nodding = false;
    }
    if(pmode == "scan") {
        chopper = false;
    }
    // Establish now the applicable Pointing Mode (use same pointCase convention
    // used in PacsPhoto)
    // Pointing mode is undefined. If it remains undefined at the end of
    // the next tests, then there is a problem with the source definition
    int pointCase = 0;
    // Based on the definitions of PacsPhoto, and since there is no staring case,
    // pointCase is of the form 31 (raster no nod), 32 (raster w/nod) or 33 (scan
    // mode)
    if(pmode == "raster" && !nodding) {
        pointCase = 31;
        string pointMode = "raster_pointing";
        string userMode = "Raster, no chopper,  no nodding";
        if(chopper) {
            userMode = "Raster, chopper,  no nodding";
        }
    }
    if(pmode == "raster" && nodding) {
        pointCase = 32;
        pointMode = "nodding_raster_pointing";
        userMode = "Raster, no chopper,  nodding";
        if(chopper) {
            userMode = "Raster, chopper, nodding";
        }
    }
    if(pmode == "scan") {
        pointCase = 33;
        pointMode = "line_scan_pointing";
        userMode = "Scan, no chopper, no nodding";
    }
    // Establish pointing offsets (index into PACSyzoffsets CAL file)
    string yzoffsetROW = "S" + pointCase;
    // For symmetrical chopping, virtual apertures are dependent on the chopper
    // throw. The chopperthrow will be used to compute yzoffsets
    yzoffsetROW = yzoffsetROW;
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("     PointCase ID: " + pointCase);
        debug_print("     PointMode   : " + pointMode);
        debug_print("     CALU entry  : " + yzoffsetROW);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Define array of wavelengths (will be needed by the SORT procedure)
    double[] lineWave = [55.0];
    // Populate the array of wavelengths (inherited from AOT where several lines
    // are allowed)
    lineWave[0] = lines[0]{1};
    // For each line obtain the grating order and the grating position 
    int[] orders = [0];
    double[] grat_pos = [0.0];
    // Fill the tuple waveTuple {waveLen,order,gratPos,nbStep,gratStep}
    {double,int,int,int,int}[] waveTuple = [{0.0,0,0,0,0}];
    waveTuple[0] = SPEC_get_grat_info(lineWave[0],"HI",switching,extraConf,orderSel,verbose);
    // Create vector of intermediate results
    orders[0] = waveTuple[0]{1};
    grat_pos[0] = double(waveTuple[0]{2});
    // Determine the filter needed with given lines
    // No filter needed, i.e. ORDER=1
    int filter = 1;
    // Determine filter based on HSPOT input
    if(orderSel == "order2") {
        filter = 2;
    }
    if(orderSel == "order3") {
        filter = 3;
    }
    if(verbose) {
        debug_print("ORDER array: " + orders);
    }
    // Filter below will be set by SPEC_aot_prologue via SlewCal
    if(verbose) {
        debug_print("MAIN:The full OBS will be performed with filter " + filter);
    }
    // The tuple arrays confOBCP, confSPECred, and confSPECblu play a major
    // role. They contain the parameters related to commanding different PACS
    // subsystems. They are susceptible of changing with the observing conditions.
    // Hence, they have to be watched for changes since these imply sending one or
    // more TCs (usually invoking a building block)
    // Define confOBCP array
    // confOBCP{0 -> 19} contains:
    // nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
    // nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
    // grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
    // chop_pos_SRC     chop_pos_REF1    chop_pos_REF2    chop_pos_CS1
    // chop_pos_CS2     chop_def         detector         order
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confSPECblu and confSPECred
    // confSPEC contains:
    //   capa,       nb_rdouts_ramp, nb_rdouts_subramp, comp_mode,
    //   glitch_det, ramp_fit_alg,   nb_raw,            bias_r,    bias_d
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // Estimator module returns {confSPECblu,confSPECred,confOBCP}
    // Reunite all three tuples into paramsSPECdef
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    // AOT code uses "throwUsage" as a description of allowed chopper throws
    // Here the throw is user defined. Use "large" to please the script and
    // compute the ENG throw below.
    paramsSPECdef = PacsSpecDefaults("large",extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // Convert chopperthrow into into ENG values
    string convU = "SPEC_CHOP_sky";
    confOBCP[0]{12} = PacsReadChopSky(convU,-chopthrow / 2.0);
    confOBCP[0]{13} = PacsReadChopSky(convU,chopthrow / 2.0);
    confOBCP[0]{14} = confOBCP[0]{13};
    // Here comes the module(s) to estimate OBS times as a function of the
    // input given by the HSPOT user.
    // Define tuple to contain the "variable" parameters
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPEC = clone(paramsSPECdef);
    // Need more info... create paramsSPECext (zut alors!)
    // paramsSPECext (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,nb_up_dn,timeOBS,aux2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for each wavelength. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("MAIN.confOBCP[0]: " + confOBCP[0]);
    }
    int nbNods = 0;
    // Accumulator total OBS time
    int totalOBS = 0;
    // For each demanded wavelength compute minimum duration (only one wave
    // in PV version)
    // Always use OBCP35
    // Here we perform nodding/chopping
    // SCR-2942: consider case of faintLines = false
    string forDEBUG = "chop/nod";
    paramsSPECext = PacsLineSpecEstimatorOBCP35(lines[0],waveTuple[0],paramsSPEC,nodding,faintLines,verbose);
    // Copy estimates to respective tuples
    confSPECblu[1] = paramsSPECext{0};
    confSPECred[1] = paramsSPECext{1};
    confOBCP[1] = paramsSPECext{2};
    // Accumulate total OBS time
    totalOBS = totalOBS + paramsSPECext{3}{2};
    if(verbose) {
        debug_print("MAIN.Wavelength: " + lines[0]{1});
        debug_print("MAIN.confOBCP[" + 1 + "]: " + confOBCP[1]);
        debug_print("MAIN.confSPEC[" + 1 + "]: " + confSPECblu[1]);
        debug_print("MAIN.Minimum required time: " + totalOBS + " [sec]");
    }
    if(nodding) {
        // Here we perform nodding/chopping
        nbNods = userNODcycles;
        if(verbose) {
            debug_print("MAIN.The PointReq will contain " + nbNods + " nod cycles");
        }
    } else {
        // Here we perform freq switch
        nbNods = 0;
    }
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Minimum required OBStime: " + totalOBS + " [sec]</p>";
    lineCnt = lineCnt + 1;
    int nodTotal = nbNods * totalOBS;
    if(nodding) {
        msgLine[lineCnt] = "<p>With the specified NOD count, " + nbNods + ", the total OBS time amounts to " + nodTotal + "[sec]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Since no NOD was specified the total OBS time is equal" + " to the minimum required time. The time can be changed" + " by changing the line(s) repeat factor</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("Accumulated SRC+REF time estimation",lineCnt,msgLine);
    // Messages on general Detector/SPU parameters
    lineCnt = 0;
    msgLine[lineCnt] = "<p>Red channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECred[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    int subRamps = confSPECred[0]{1} / confSPECred[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECred[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECred[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Blue channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECblu[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    subRamps = confSPECblu[0]{1} / confSPECblu[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECblu[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECblu[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Selected PACS setup parameters",lineCnt,msgLine);
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source
    // First operation is to set the OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // Will call PacsSpecSlewCal to perform AOT prologue and CAL during
    // slew to source. Establish an array of key wavelengths, one per order,
    // commensurate with user given wavelengths
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    double keyWL = PacsSpecKeyWaves(orderSel,lWave);
    double[] keyWAVE = [keyWL];
    // double[] keyWAVE = PacsLineSpecKeyWaves(waveTuple);
    //    int nbKeyWAVE = length(keyWAVE); == 1 
    int nbKeyWAVE = 1;
    // With current versions of CommandOBCP37 and CommandOBCP32, the grating is
    // supposed to be left by SlewCal at the position needed for the 1st line
    // The OBCPs will leave the grating at that same position
    int frstLstGratPos = confOBCP[1]{8};
    if(verbose) {
        debug_print("MAIN:waveTuple: " + waveTuple);
        debug_print("MAIN:keyWAVES " + keyWAVE);
        debug_print("MAIN:SlewCal should leave grating at: " + frstLstGratPos);
    }
    // IMPORTANT NOTE
    //---------------
    // Logic to stop the "non-prime" channel. This is the channel not used by 
    // the KeyWave
    // In principle neither channel shall be stopped
    bool stopSPUS = false;
    bool stopSPUL = false;
    // Channel selection
    if(keyWAVE[0] > 100.0) {
        stopSPUS = true;
    }
    if(keyWAVE[0] < 100.0) {
        stopSPUL = true;
    }
    // To stop unused channel we need
    int timeToStop = duration(SPEC_spu_channel_stop(stopSPUS,stopSPUL,verbose));
    // Time needed to perform these activities during slew (includes AOT
    // prologue)
    bool doAOTprologue = true;
    int timeSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel));
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during slew: " + timeSlewCal);
    }
    // CAL for HOLD 
    doAOTprologue = false;
    int timeHoldCal = duration(PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,0,frstLstGratPos,orderSel));
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during HOLD: " + timeHoldCal);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsSpecCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsSpecCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // IMPORTANT NOTE: the duration could be different for the first cycle through 
    // all wavelengths than for the following ones owing to differing initial state.
    // However, all steps have been taken so that PACS starts the actual observation
    // in the same state as it would be left at the end of any wavelength cycle
    // Duration of any nod leg or staring observation
    // Different OBCP for wavelength switch
    if(!switching) {
        // Here we perform nodding/chopping
        int timeOBS = duration(PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,verbose));
        if(verbose) {
            debug_print("Duration OBCP35: " + timeOBS + " [sec] per pointing;  nbNods: " + nbNods);
        }
    } else {
        // Here we perform freq switch
        timeOBS = duration(PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,verbose));
        if(verbose) {
            debug_print("Duration OBCP32: " + timeOBS + " [sec] per pointing");
        }
    }
    // Get duration of module to close AOT operations
    // This includes parking the grating
    // Park position
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // The grating was left by OBCPs at frstLstGratPos
    int timeEpilogue = duration(SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose));
    // WriteEndID will be the last TC; get its duration
    int timeEndID = duration(WriteEndID());
    // Summary of relevant data collected so far
    // timeSlewCal: duration of the leading CAL, including AOT_prologue
    // timeOBS    : duration of a single pointed OBS
    // nb_nods    : number of nods for staring mode or per raster position
    // chopNod : invoke nodding or not (nb_nods = 0 is equivalent to no nod)
    // m, n       : raster nb_points/line, nbLines per RREQ
    // pointStep,lineStep: more raster parameters
    // ra,dec: more pointing parameters
    //
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Ready to issue a FinePointing mode with/without nodding or
    // a RasterReq with/without nodding. Either one will use time during
    // slew to perform SlewCal.
    //
    // The chopper step has been read already (PacsSpecDefaults). However,
    // there are no provisions to carry that information here. Easiest is to
    // read again the relevant CAL-U table. Read chopper position SRC and
    // REF1 [arcsec]
    double chopAngleSrc = dlookup("SPEC_CHOP_params",throw,"SRC");
    double chopAngleRef = dlookup("SPEC_CHOP_params",throw,"REF1");
    // The total nodThrow = chopperTotalThrow
    double nodThrow = abs(chopAngleSrc - chopAngleRef);
    if(verbose) {
        debug_print("PacsSpecDef: CHOP/NOD params SRC/REF/NOD: " + chopAngleSrc + "/" + chopAngleRef + "/" + nodThrow);
    }
    // Issue pointing request (when possible use JBr's variable names for clarity)
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    // Virtual aperture
    string ib = "P02_0";
    // Get x, y offsets and skewCorrec from the offset CALU file
    // Here since the chopper throw is user defined, compute yhe yoffset
    ///    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    ///    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    ///    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    double yoffset = chopthrow / 2.0;
    double zoffset = 0.0;
    double skewCorrec = 0.0;
    if(verbose) {
        debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("#### skewCorrec : " + skewCorrec);
    }
    int tslewmin = timeSetOBSID + timeSlewCal + timeToStop;
    int tinithold = 0;
    int tfinalhold = timeEndID + timeEpilogue;
    int tp = timeOBS;
    double patt = 0.0;
    double pattnod = 270.0 + skewCorrec;
    int k = 0;
    // DAC Test ONLY
    int thold = timeHoldCal;
    int nhold = 0;
    int nload = 0;
    int tloadslewmin = 0;
    bool fixed = true;
    // FinePointingMode with setup time
    if(pointCase == 11) {
        //     FinePointingMode without nodding     
        int[] fromPntReq = basic_fine_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,yoffset,zoffset,tp);
    }
    if(pointCase == 12) {
        //     FinePointingMode without nodding, section 3.4     
        ib = "P02_0";
        //     Nodding is specified wrt spacecraft
        fixed = false;
        //     Nodding is along y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        fromPntReq = nodding_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nbNods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
    }
    if(pointCase == 21 || pointCase == 31) {
        //     RasterMode repeated_raster_with_hold_and_OFF, section 3.5
        ib = "P02_0";
        //     Raster in instrument coordinates
        fixed = false;
        double d1 = pointStep;
        double d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        k = 0;
        int top = 0;
        int nrepeat = 1;
        // If Small source: no Off position
        if(!switching && pointCase == 21) {
            raoff = 0.0;
            decoff = 0.0;
        }
        //     If switching for "large" source perform OFF observation
        if(switching || pointCase == 31) {
            //        Repeat raster according to userNODcycles
            nrepeat = userNODcycles;
            k = n * m;
            top = tp;
        }
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        //     SPR-3237 (map orientation parameter) applies only to raster
        if(pointCase == 31) {
            fixed = true;
            patt = mapRasterAngle;
        }
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
    }
    if(pointCase == 22 || pointCase == 32) {
        //     Raster mode w/nodding, section 3.6
        ib = "P02_0";
        //     Raster in instrument coordinates
        fixed = false;
        //     Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        //     Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        k = 0;
        nrepeat = 1;
        //     New arguments for pointing request; will be dealt with next iteration
        top = 0;
        raoff = 0.0;
        decoff = 0.0;
        trepeatmin = 0;
        tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nbNods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
    }
    if(pointCase == 33) {
        ib = "P01_0";
        //   Use instrument coordinates unless HSPOT says otherwise
        fixed = false;
        ///     if (useINST == false) {fixed = true;}
        patt = mapScanAngle;
        n = mapScanNumLegs;
        d1 = 60.0 * mapScanLegLength;
        d2 = mapScanCrossScan;
        thold = timeSlewCal;
        nhold = 0;
        nrepeat = 1;
        fromPntReq = line_scan_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,n,d1,d2,mapScanSpeed,thold,nhold,nrepeat);
    }
    // Parameters returned by PointReq
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Issue PointRequest now");
        debug_print("Return from PointReq: " + fromPntReq);
    }
    //Info from API (nomenclature from Jon Br)
    tobs = fromPntReq[0];
    tslew = fromPntReq[1];
    ///////////////////////// end of "timing" section //////////////////////////
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + userMode);
        int tNOW = time();
        debug_print("=====Issued PointReq Time_now: " + tNOW);
    }
    // Issue TCs
    int[] stateVar = [0];
    int nbOBS = 0;
    int nbOFF = 0;
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            // Write OBSID (logical part of SlewCal)
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            int[][] calTime = PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel);
            //          Stop unused SPU
            SPEC_spu_channel_stop(stopSPUS,stopSPUL,verbose);
            // Define accumulated Cal time
            int[][] sumUpCalTime = calTime;
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW ends at: " + tNOW);
                debug_print("    SumUpCalTime: " + sumUpCalTime);
            }
        } else {
            if(stateVar[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== POINT starts at: " + tNOW);
                }
                //       Regular OBCP or frequency switched OBCP?
                if(!switching) {
                    int[][] obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                } else {
                    obsTime = PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                }
                nbOBS = nbOBS + 1;
                // Logic to sum up obsTime
                if(nbOBS == 1) {
                    int[][] sumUpObsTime = obsTime;
                }
                if(nbOBS > 1) {
                    sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("    SumUpObsTime: " + sumUpObsTime);
                    debug_print("=== POINT ends at: " + tNOW);
                }
            } else {
                if(stateVar[0] == 4) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF starts at: " + tNOW);
                    }
                    //       Regular OBCP or frequency switched OBCP?
                    if(!switching) {
                        ///            obsTime =  
                        PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                    } else {
                        ///            obsTime =  
                        PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                    }
                    nbOFF = nbOFF + 1;
                    //       Logic to sum up obsTime
                    ///         if (nbOFF == 1) {sumUpObsTime = obsTime;}
                    ///         if (nbOFF > 1)  {sumUpObsTime = SumFunction(obsTime,sumUpObsTime);}
                    if(verbose) {
                        tNOW = time();
                        ///          debug_print("    SumUpObsTime: " + sumUpObsTime);
                        debug_print("=== OFF ends at: " + tNOW);
                    }
                } else {
                    if(stateVar[0] == 7) {
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== NOD starts at: " + tNOW);
                        }
                        obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                        nbOBS = nbOBS + 1;
                        // Logic to sum up obsTime
                        if(nbOBS == 1) {
                            sumUpObsTime = obsTime;
                        }
                        if(nbOBS > 1) {
                            sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                        }
                        if(verbose) {
                            tNOW = time();
                            debug_print("    SumUpObsTime: " + sumUpObsTime);
                            debug_print("=== NOD ends at: " + tNOW);
                        }
                    } else {
                        if(stateVar[0] == 8) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== LINE starts at: " + tNOW);
                            }
                            obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                            nbOBS = nbOBS + 1;
                            // Logic to sum up obsTime
                            if(nbOBS == 1) {
                                sumUpObsTime = obsTime;
                            }
                            if(nbOBS > 1) {
                                sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                            }
                            if(verbose) {
                                tNOW = time();
                                debug_print("    SumUpObsTime: " + sumUpObsTime);
                                debug_print("=== LINE ends at: " + tNOW);
                            }
                        } else {
                            if(stateVar[0] == 6) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== HOLD starts at: " + tNOW);
                                }
                                calTime = PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel);
                                sumUpCalTime = SumFunction(calTime,sumUpCalTime);
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("    SumUpCalTime: " + sumUpCalTime);
                                    debug_print("=== HOLD ends at: " + tNOW);
                                }
                            } else {
                                if(stateVar[0] == 5) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== FinalHOLD  starts at: " + tNOW);
                                    }
                                    SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose);
                                    WriteEndID();
                                    tNOW = time();
                                    if(verbose) {
                                        debug_print("=== FinalHOLD  ends at: " + tNOW);
                                    }
                                } else {
                                    if(stateVar[0] == -1) {
                                        if(verbose) {
                                            tNOW = time();
                                            debug_print("=== AOT  ends at: " + tNOW);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    if(verbose) {
        debug_print("OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("Ending with NbOFF: " + nbOFF);
    }
    // The original concept of returning durations did not take into 
    // account the bandwidth of the TC bus (2 TCs/sec). The "real" 
    // duration is given by the result from the "duration()" function. Hence
    // the true total duration of the SlewCal phase is given by
    ///   calTime[0] = timeSlewCal;
    // as a result, the overheads are now
    ///   calTime[4] = calTime[0]-(calTime[1]+calTime[2]+calTime[3]); 
    if(verbose) {
        debug_print("Slew & HOLD Cal return: " + sumUpCalTime);
    }
    // The same holds true for the OBCP35 phase. However, I cannot make the
    // break-down by wavelength (the OBCP35 duration is given for ALL lines).
    // We may add up the SRC, CAL, and OVR components of OBCP35 duration. For
    // this we need a tuple so we can add the wavelength and other relevant
    // information to the (per wave) duration arrays.
    //
    //  infoArray[] contains a "fixed" global information part
    //  infoArray[0]: {Slew,   intTime,TotDur,nbRanges,nnods,m*n}
    //  infoArray[1]: {Point,  intTime,TotDur,nbRanges,nnods,m*n}
    //  infoArray[2]: {AOTinfo,intTime,TotDur,nbRanges,nnods,m*n}
    //
    // and a per wavelength array:
    //    [waveSTART,waveEND,order,gratStep,nbGratStep,TOT,SRC,REF,CAL,OVR]
    // TotDur as given by duration(); TOT,SRC,REF,CAL,OVR are also in [sec]
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    // Fill 1st dimension of infoArray with data from SlewCal
    // Instead of using timeSlewCal, use tslew time returned by PointReq
    // infoArray[0] = {{"SlewCal",0.0,timeSlewCal,0,0,0},[{0.,0.,0,0,0,0,0,0,0,0}]};
    infoArray[0] = {{"SlewCal",0.0,tslew,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Compute integration time per chopper plateau
    // intTime = nbRamps/plateau x nbRdouts/ramp x sampleInterval 
    // Sampling frequency
    double specSample = dlookup("PACSparams","spec_sample","freq_time");
    // Number of readouts per ramp
    int nbRdoutRamp = confSPECblu[1]{1};
    // NOTE: WAIT=1 are now counted as useful ramps; hence
    int wait1 = 1;
    // but there is no wait in FreqSwitch
    // Count the WAIT=1 for grating as a useful SRC
    if(switching) {
        wait1 = 1;
    }
    int nbRampPlateau = confOBCP[1]{4} + wait1;
    // 
    double intTime = double(nbRampPlateau * nbRdoutRamp) / specSample;
    if(verbose) {
        debug_print("MAIN:AOT          : " + userMode);
        debug_print("MAIN:Rdouts/ramp  : " + nbRdoutRamp);
        debug_print("MAIN:Ramps/plateau: " + nbRampPlateau);
        debug_print("MAIN:IntTime      : " + intTime);
    }
    // Replace timeOBS (per raster and per nod) with tobs from PntReq (matching
    // change in PacsProcessInfoArray)   
    // infoArray[1] = {{userMode,intTime,timeOBS,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    infoArray[1] = {{userMode,intTime,tobs,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    for(int loop3 = 0 .. nbLines1) {
        //     for some reason it has to be "initialized"
        infoArray[1]{1}[loop3] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the START wavelength (for LINE START = END = line wave)
        infoArray[1]{1}[loop3]{0} = lines[loop3]{1};
        //     copy the END   wavelength (for LINE START = END = line wave)
        infoArray[1]{1}[loop3]{1} = lines[loop3]{1};
        //     copy the grating order
        infoArray[1]{1}[loop3]{2} = waveTuple[loop3]{1};
        //     copy the grating step
        infoArray[1]{1}[loop3]{3} = waveTuple[loop3]{4};
        infoArray[1]{1}[loop3]{3} = (confOBCP[loop3 + 1]{2} - confOBCP[loop3 + 1]{1}) / 2;
        //     copy the number of grating steps
        infoArray[1]{1}[loop3]{4} = confOBCP[loop3 + 1]{6};
        //     copy other data from sumUpObsTime
        infoArray[1]{1}[loop3]{5} = sumUpObsTime[loop3][0];
        infoArray[1]{1}[loop3]{6} = sumUpObsTime[loop3][1];
        infoArray[1]{1}[loop3]{7} = sumUpObsTime[loop3][2];
        infoArray[1]{1}[loop3]{8} = sumUpObsTime[loop3][3];
        infoArray[1]{1}[loop3]{9} = sumUpObsTime[loop3][4];
    }
    // Also data from SlewCal to infoArray
    for(int loop4 = 0 .. nbKeyWAVE - 1) {
        //     for some reason it has to be "initialized"
        infoArray[0]{1}[loop4] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the wavelength
        infoArray[0]{1}[loop4]{0} = keyWAVE[loop4];
        //     copy other data from sumUpCalTimeTime
        infoArray[0]{1}[loop4]{5} = sumUpCalTime[loop4][0];
        infoArray[0]{1}[loop4]{6} = sumUpCalTime[loop4][1];
        infoArray[0]{1}[loop4]{7} = sumUpCalTime[loop4][2];
        infoArray[0]{1}[loop4]{8} = sumUpCalTime[loop4][3];
        infoArray[0]{1}[loop4]{9} = sumUpCalTime[loop4][4];
    }
    // Further update of infoArray: add information from AOT_prologue    
    infoArray[0]{1}[nbKeyWAVE] = {0.0,0.0,0,0,0,0,0,0,0,0};
    //   Copy OVR and TOT times
    infoArray[0]{1}[nbKeyWAVE]{9} = calTime[nbKeyWAVE][4];
    infoArray[0]{1}[nbKeyWAVE]{5} = calTime[nbKeyWAVE][4];
    //   Copy the number of lines observed and the number of key waves used
    infoArray[0]{0}{3} = nbKeyWAVE;
    infoArray[1]{0}{3} = nbLines;
    //   Copy the number of nod cycles and the number of raster points visited
    infoArray[1]{0}{4} = nbNods;
    infoArray[1]{0}{5} = m * n;
    // The duration of the OBS phase is given by timeObsEnd - timeSlewCal
    // Now get it from PntReq: timeObsPhase == tobs
    // int timeObsPhase = timeObsEnd - timeSlewCal;
    // Slew time during the OBS phase is then given by
    int timeSlewObs = tobs - nbOBS * timeOBS;
    if(verbose) {
        debug_print("CalSlew phase lasted [sec]: " + timeSlewCal);
        debug_print("The OBS phase lasted [sec]: " + tobs);
        debug_print("Total slew during OBS [sec]: " + timeSlewObs);
    }
    // Fill 3rd dimension of infoArray with global timing and AOT information
    // timeObsEnd is the total duration of the AOT
    // Pass details of AOT
    // We use OBCP35: OBCP_grat_scan_chop3 (unless FreqSwitch)
    string aotName = "GratScanChop3";
    // Special "sky time"  for FreqSwitch and SmallSourceDither
    if(switching) {
        aotName = "FreqSwitch";
    }
    if(source == "dithered") {
        infoArray[1]{0}{0} = "SmSrcDither";
    }
    infoArray[2] = {{aotName,0.0,timeObsEnd,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Use available entries to convey m,n, and nbNods
    infoArray[2]{0}{3} = m;
    infoArray[2]{0}{4} = n;
    // PointSources are also seen with composite_nodding
    if(pointMode == "fine_pointing" || pointMode == "composite_nodding") {
        infoArray[2]{0}{3} = 1;
        infoArray[2]{0}{4} = 1;
    }
    infoArray[2]{0}{5} = nbNods;
    // If switching 
    if(switching && source == "Large") {
        infoArray[1]{0}{0} = "RasterOFF";
    } else {
        if(switching && source == "Point") {
            infoArray[1]{0}{0} = "Pointed";
        }
        infoArray[2]{0}{5} = userNODcycles;
    }
    // Process the information contained in infoArray (pass also lines)
    PacsProcessInfoArrayLine(infoArray,lines,confOBCP,obsOverhead,nbOBS,nbOFF,verbose);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    // Compute the total time SRC + REF
    int accumSrceRef = 0;
    for(int loopL = 0 .. nbLines - 1) {
        //   Add up Srce and Ref times (SRC + REF)
        accumSrceRef = accumSrceRef + infoArray[1]{1}[loopL]{6} + infoArray[1]{1}[loopL]{7};
    }
    // Compute overheads as total "sky" time minus SRC+REF time
    int overPACSandSC = fromPntReq[0] - accumSrceRef;
    // Return demanded tuples

    return {accumSrceRef,fromPntReq[1],overPACSandSC};
}

// CVS comments  : $Id: SPEC_BAND_read.txt,v 1.3 2007/05/07 13:48:17 dcesarsk Exp $ 
// Purpose       : Return the BAND limits (from SPEC_BAND) for a given order
// CUS author    : DAC
// Script file   : SPEC_BAND_read.txt 
//
// Input arguments
// type    name         description
// int     order        Grating order
//
// Return values
// Type          Description
// double []     LO and HI wavelengths
//
// Description   : Access the table SPEC_BAND_params. Read and return the
//                 band limits for a given order
//
// Dependencies  :
//
// Preconditions :
//                 
// Comments      : 
// type string
// 
// History       : 0.1 23-may-2008 DAC Based on SPEC_BAND_read
//                                 - Reads SPEC_BAND_params_PV
double[] procedure SPEC_BAND_read_PV {
    string order = "1"; // Give order
}{
    // Open and read SPEC_BAND_params table. Table indexed by ORDER
    // read BLU and RED edges of the SPEC bands
    double blu = dlookup("SPEC_BAND_params_PV",order,"BLU");
    double red = dlookup("SPEC_BAND_params_PV",order,"RED");

    return [blu,red];
}

// Script        : PACS_Chopper_uk_move_3000_NoConf_ast.cus
// Missionphase  : SVT / Flight
//
// Purpose	: Move chopper to absolute position  
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-3000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched on and Chopper switched on.
//                 
// Comments	: This script is based on PACS_Chopper_uk_move_3000_ast_OBS,
//                     but without configuration and with mois comments
//
// Version	: 1.0	
// 
// History 	: 1.0 17-10-2007 BV First version
//		  
procedure PACS_Chopper_uk_move_3000_NoConf_ast {
}{
    mois_comment("Perform rectangular chopping with step 3000");
    //
    int chop_pos = 3000;
    // chopper position
    int cycle = 10;
    // give cycle #
    int plateau_time = 2;
    // select plateau time in sec
    // Start Diag. HK
    mois_step("Start Diagnostic housekeeping");
    SPEC_Chopper_dhk_5hk_1khz_bb();
    mois_step("Enable chopper controller");
    // Enable Chopper Controller 
    EnDis_chopper("ON");
    delay(5);
    mois_step("Perform rectangular chopping");
    // move chopper to zero
    PACS_Chopper_mov_abs_fm_bb(0);
    delay(1);
    // do observations
    int i = 1;
    while(i <= cycle) {
        PACS_Chopper_mov_abs_fm_bb(chop_pos);
        delay(plateau_time);
        PACS_Chopper_mov_abs_fm_bb(-chop_pos);
        delay(plateau_time);
        i = i + 1;
    }
    // move chopper to zero
    PACS_Chopper_mov_abs_fm_bb(0);
    delay(1);
    mois_step("Disable chopper");
    // Disable Chopper Controller 
    EnDis_chopper("OFF");
    delay(5);
    mois_step("Disable diagnostic housekeeping");
    // Stop diagnostic housekeeping
    PACS_stop_dhk_fm_bb();
}

// Missionphase  : FM
//
// Purpose	:  Setup diagnostic housekeeping for the FM 
//                 detector test PTD 0.7.6 in spectroscopy.
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: Set up  housekeeping parameter for diagnostic housekeeping 
//	  of the detector.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy.
//                 
// Comments	: 
//
// Version	: 3.0	
// 
// History 	: 1.0 27-07-06 creation by HD. script test.
//                2.0 27-07-06 HD. script works.
//		  3.0 20-06-07 HD. Prepare Test for FM-ILT3.
block SPEC_chop_det_dhk_fmilt076spec_V2_bb PACS 386 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //----------------------------------------------------- 
    // Setup and start diagnostic HK for PTD 0.7.6 V2
    //----------------------------------------------------- 
    int diag_hk_length = 5;
    {int}[] parlist = [{209},{244},{245},{258},{0xffff}];
    int[] aux = [209,244,245,258,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(diag_hk_length,parlist,check_sum);
    int diag_hk_period = 0;
    // Synchronize diagnostic HK on blue spectrometer readouts
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark End of Block
    WriteEndBB();
}

// CVS comments  : $Id: PacsRangeMessage.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $ 
// Script file   : PacsRangeMessage.txt 
//
// Purpose       : 'HTMLize' some information passed in tinyTuple
//
// CUS author    : DAC
//
// Input arguments
// 
// tuple sortRangesEXT HSPOT input added later
// {string,double[],double[],double[],double[]} tinyTuple
//
// Description   : Print the information in tinyTuple in HTML format
// Dependencies  : 
//
// Comments      : NOTE!! Here we start UnorderedList <ul>; it has to </ul> in 
//                        the next module writing to HTML
// 
// History       : 0.1 19-apr-2007 DAC
// 0.2  7-may-2007 Added missing "worst" line information
{int,string[]} procedure PacsRangeMessage {
    {string,double[],double[],double[],double[]} tinyTuple = {"",[0.0],[0.0],[0.0],[0.0]};
}{
    int lineCnt = 0;
    string[] msgLine = [""];
    double[] noiseWave = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0];
    //      CONTinuum
    noiseWave[0] = tinyTuple{1}[0];
    noiseWave[1] = tinyTuple{1}[1];
    noiseWave[2] = tinyTuple{1}[2];
    noiseWave[3] = tinyTuple{1}[3];
    //      LINE
    noiseWave[4] = tinyTuple{1}[4];
    noiseWave[5] = tinyTuple{1}[5];
    noiseWave[6] = tinyTuple{1}[6];
    noiseWave[7] = tinyTuple{1}[7];
    //      CONT and LINE for refWave     
    noiseWave[8] = tinyTuple{1}[8];
    noiseWave[9] = tinyTuple{1}[9];
    noiseWave[10] = tinyTuple{1}[10];
    //      Start HTML list
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    double waveRef = noiseWave[8];
    msgLine[lineCnt] = "<li><B>Reference wavelength: " + dformat(waveRef,1) + " [&micro;m]</B></li>";
    lineCnt = lineCnt + 1;
    int noiseMjy = ifloor(1000.0 * noiseWave[9]);
    msgLine[lineCnt] = "<li>   Continuum RMS (reference wavelength): " + noiseMjy + " [mJy]</li>";
    lineCnt = lineCnt + 1;
    double lineNoise = noiseWave[10] * 1.0E18;
    msgLine[lineCnt] = "<li>   Line RMS (reference wavelength): " + dformat(lineNoise,2) + "E-18 [W/m2]</li>";
    lineCnt = lineCnt + 1;
    noiseMjy = ifloor(1000.0 * noiseWave[1]);
    msgLine[lineCnt] = "<li>   Best continuum RMS occurs at " + dformat(noiseWave[0],2) + " [&micro;m]: " + noiseMjy + " [mJy]</li>";
    lineCnt = lineCnt + 1;
    lineNoise = noiseWave[5] * 1.0E18;
    msgLine[lineCnt] = "<li>   Best line RMS occurs at " + dformat(noiseWave[4],2) + " [&micro;m]: " + dformat(lineNoise,2) + "E-18 [W/m2]</li>";
    lineCnt = lineCnt + 1;
    noiseMjy = ifloor(1000.0 * noiseWave[3]);
    msgLine[lineCnt] = "<li>   Worst continuum RMS occurs at " + dformat(noiseWave[2],2) + " [&micro;m]: " + noiseMjy + " [mJy]</li>";
    lineCnt = lineCnt + 1;
    lineNoise = noiseWave[7] * 1.0E18;
    msgLine[lineCnt] = "<li>   Worst line RMS occurs at " + dformat(noiseWave[6],2) + " [&micro;m]: " + dformat(lineNoise,2) + "E-18 [w/m2]</li>";
    lineCnt = lineCnt + 1;
    // Return count and messages
    ///   lineCnt = lineCnt - 1;

    return {lineCnt,msgLine};
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Diaghk_Reset {
    /* No variables to call PacsEng_Diaghk_Reset                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Diaghk_Reset                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Diaghk_Reset()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Diaghk_Reset();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 16-oct-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_CRE_01pF0bias_Setup_Warm {
    /* No variables to call PacsEng_Spec_CRE_01pF0bias_Setup_Warm                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_CRE_01pF0bias_Setup_Warm                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_CRE_01pF0bias_Setup_Warm()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_CRE_01pF0bias_Setup_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
// Purpose       : Stop SPECtroscopy observations at end of AOT and stop of OBCP 
//                  
// TCL author    : 
// TCL file      : 
// CUS author    : Diego Cesarsky
// Script file   : SPEC_aot_epilogue_stopOPCP.txt 
//
// Input arguments
// Type Name           Default   Description
//
// Description   : Not much for now (just STOP SPU)
//                 Move grating from wwwhere OBCPs left it to the park
//                 position
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      : Based on V1.3 of TM's tm_spu_setup.tcl. Both
//                 SPUS and SPUL are initialized to same set of parameters
//
// Version       : 1,0
// History       : 0.1 13-apr-2006 First creation
//                 0.2 15-feb-2007 Leave grating at park position
//		   1.0 23-sep-2008 SCR 4431 data_rate
procedure SPEC_aot_epilogue_stopOBCP {
    int gratFrom = 500000; // Where OBCPs have left the grating
    int gratTo = 535000; // Grating park position
    bool verbose = false;
}{
    // Stop the running OBCP
    Pacs_DPU_STOP_OBCP("GRAT_SCAN_CHOP2");
    // Abort the running DMC sequence
    Pacs_DMC_ABORT_SEQUENCE();
    // Park the grating
    SPEC_grat_move(gratFrom,gratTo,verbose);
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    data_rate(0.0);
    // Sync the bus (function duration will get the "true" duration)
    sync();
    // end of procedure
}

// Missionphase  : EQM IMT
//
// Purpose	: Switch on/off and enable/disable a controller for a PACS
//                internal Calibration Source
//
// Author	: DAC
// CUS script	: DAC
// CVS file	: CS_on_off.txt
//
// Arguments	:
// type  name               Description
// string   cal_source      Either CS1 or CS2
// string   on_off          Either ON or OFF  
//
// Description	: Switch on/off and enable/disable controller for selected
//                PACS internal CS (calibration source)
//                  
// Dependencies : 
//
// Preconditions : Configuration parameters have been uploaded for CS1 and CS2
//                 
// Comments	: Several ways exist to fill in the preconditions, 
//                e.g. CONF_csx, or SetupSpectroscopyEQMIMT.
//
// Version	: 1.0
//               
// History	: 1.0 12-Apr-2005 Creation by DAC
//
procedure CS_on_off {
    string cal_source = "CS1" in ["CS1","CS2"];
    string on_off = "ON" in ["ON","OFF"];
}{
    // Start with internal source CS1
    if(cal_source == "CS1") {
        if(on_off == "ON") {
            Pacs_DMC_SWON_BB_1_CONT();
            Pacs_DMC_ENABLE_BB_1_CONT();
        }
        if(on_off == "OFF") {
            Pacs_DMC_DISABLE_BB_1_CONT();
            Pacs_DMC_SWOF_BB_1_CONT();
        }
    }
    // Continue with CS2
    if(cal_source == "CS2") {
        if(on_off == "ON") {
            Pacs_DMC_SWON_BB_2_CONT();
            Pacs_DMC_ENABLE_BB_2_CONT();
        }
        if(on_off == "OFF") {
            Pacs_DMC_DISABLE_BB_2_CONT();
            Pacs_DMC_SWOF_BB_2_CONT();
        }
    }
    // end of procedure
}

// $Id
// Missionphase		: PACS PV Phase
//
// Purpose :		Wavelength calibration during PacsSlew
// Author		 : VDP
//
// Arguments		:
//
// Prerequisite 	: PACS does not need to be on nor setup for spectroscopy
//
// Description		: Uses OBCP13 and performs AOT prologue and epilogue
// 
// Comments		:
//
// Dependencies		: CONF_SPEC_params : The detector biases are read from column "Normal0"
//
// Version		: 1.1
// 
// History		: 0.1 Using example from PacsCal_WaveCalChop
// 			: 1.0 perform calibrations during slew and 
//    	  	       	   then a wavelength calibration on source
//			   usng NOD=1 and Choping
//			  1.1 13-Nov-2008 Added data_rate() commands
// 			  1.2 07-May-2009 PR Upgrade ramp_fit_alg (match FS database) & nb_raw as parameters
//			                      Add parameter no_gratmove
//
obs PacsCal_PacsSpecSlewCal_Flex {
    /* Needed variables to call PacsSpecSlewCal */
    /* FW, WAVELENGTH & OBCP parameters */
    double[] waves = [60.0]; // Wavelengths
    int order = 2;
    string fltPOS = "POS A" in ["POS A","POS B"]; //Filter wheel position 0="POS A", 1="POS B"
    int nb_up_dn = 1; // nb_up_down  	OBCP 13 DMCSeq. P#1
    int nb_grat_steps = 16; // nb_grating_steps  	OBCP 13 DMCSeq. P#3
    int nb_cycles_grat = 2; // nb_chop_cycles_per_gratpos  	OBCP 13 DMCSeq. P#5
    int nb_ramps_grat_pos = 1; // nb_clean_ramps_per_gratpos  	OBCP 13 DMCSeq. P#7
    bool no_gratmove = false; // false: gratstep read from CALU. True: gratstep forced to 0
    /* CRE & SPU PARAMETERS */
    int capa_blu = 12;
    int capa_red = 12;
    int nb_rdouts_ramp_blu = 64;
    int nb_rdouts_ramp_red = 64;
    int nb_rdouts_subramp_blu = 16;
    int nb_rdouts_subramp_red = 16;
    int ramp_fit_alg_blu = 1;
    int ramp_fit_alg_red = 1;
    int nb_raw_blu = 3;
    int nb_raw_red = 3;
    int comp_mode_blu = 16;
    int comp_mode_red = 16;
    /* POINTING PARAMETERS */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    bool verbose = true;
}{
    // FIXED CRE & SPU Parameters
    int glitch_det_blu = 1;
    int glitch_det_red = 1;
    int bias_d_blu_mV = ilookup("CONF_SPEC_params","bias_d_blu","Normal0");
    int bias_d_red_mV = ilookup("CONF_SPEC_params","bias_d_red","Normal0");
    int bias_r_blu_mV = ilookup("CONF_SPEC_params","bias_r_blu","Normal0");
    int bias_r_red_mV = ilookup("CONF_SPEC_params","bias_r_red","Normal0");
    // FIXED OBCP Parameters
    // OBCP 13 DMCSeq. P#2
    int grat_step_coarse = 0;
    // OBCP 13 DMCSeq. P#4
    string order_str = "" + order;
    int grat_step_up_fine = ilookup("SPEC_BAND_params",order_str,"HI");
    if(no_gratmove) {
        grat_step_up_fine = 0;
    }
    // OBCP 13 DMCSeq. P#6
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","SPEC","pos_CS1");
    // OBCP 13 DMCSeq. P#8
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    // OBCP 13 DMCSeq. P#9 : this parameter is set in PacsSpecSlewCal_Flex
    // int grat_step_dn_fine = -grat_step_up_fine;
    // Synchronize on this detector 1:Blue 2:Red
    int detector = 1;
    // Chopped default position
    int chop_def = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    int grat_pos = grat_park;
    // PacsSpecSlewCal_Flex parks the grating already
    //
    // compiting time for slw / calibration during slew time and others
    //Execute the pointing request
    bool execute = true;
    // Verification for grating and chopper hard limits
    //double chopthrow = 30.0;
    //int[] gratpos = [0];
    //Pacs_HardLimitsCheck(gratpos,chopthrow);
    // Calibration time during slew
    // SPEC parameters for BLU and RED    
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{capa_blu,nb_rdouts_ramp_blu,nb_rdouts_subramp_blu,comp_mode_blu,glitch_det_blu,ramp_fit_alg_blu,nb_raw_blu,bias_r_blu_mV,bias_d_blu_mV}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{capa_red,nb_rdouts_ramp_red,nb_rdouts_subramp_red,comp_mode_red,glitch_det_red,ramp_fit_alg_red,nb_raw_red,bias_r_red_mV,bias_d_red_mV}];
    // OBCP parameters none is given since PacsSpecSlewCal takes them from OBCPparam                
    {int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,detector,chop_def}];
    // Perform/don't AOT prologue                    
    bool doPROLOG = true;
    //
    //
    //Initial hold
    int tih = duration(WriteOBSID($OBSID));
    int tslewmin = 0;
    //Final hold
    int tendobsid = duration(WriteEndID());
    int tepilog = duration(SPEC_aot_epilogue(grat_pos,grat_park,verbose));
    int tfh = tendobsid + tepilog;
    //Duration of stable pointing
    int tp = duration(PacsSpecSlewCal_Flex(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,waves,fltPOS,order));
    if(verbose) {
        debug_print("Duration of PacsSpecSlewCal_Flex" + tp + "sec");
    }
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    debug_print("ts: " + ts);
    //
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            int tNOW = time();
            // 
            WriteOBSID($OBSID);
            data_rate(120.0);
            if(verbose) {
                debug_print("WriteOBSID at :" + tNOW + " sec");
            }
            tNOW = time();
            if(verbose) {
                debug_print("WriteOBSID ends at " + tNOW + " sec");
            }
        } else {
            if(state[0] == 3) {
                //       Call the WaveCal procedure
                tNOW = time();
                if(verbose) {
                    debug_print("Observation on SRC starts at :" + tNOW + " sec");
                }
                tNOW = time();
                PacsSpecSlewCal_Flex(verbose,confSPECblu,confSPECred,confOBCP,doPROLOG,waves,fltPOS,order);
                if(verbose) {
                    debug_print("Observation on SRC ends at :" + tNOW + " sec");
                }
            } else {
                if(state[0] == 5) {
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold starts at :" + tNOW + " sec");
                    }
                    SPEC_aot_epilogue(grat_pos,grat_park,verbose);
                    data_rate(0.0);
                    WriteEndID();
                    tNOW = time();
                    if(verbose) {
                        debug_print("Final Hold ends at :" + tNOW + " sec");
                    }
                }
            }
        }
    }
    // End of Observation
}

//
// Author	: DAC
// CUS script	: DAC
// CVS file	: 
//
// Arguments	:
// type     name         Description
// string   cal_source   Internal CAL source CS1 or CS2
// double   resist_temp  Desired resistance [ohm]
//
// Description	: Set the temperature of a PACS internal Calibration source  
//                  
// Dependencies : 
//
// Preconditions : Configuration parameters have been uploaded  and the 
//                 controller has been SWON & enabled
//                 
// Comments	: 
//
// Version	: 1.0
//               
// History	: 1.0 13-Apr-2005 Creation by DAC
//
procedure CS_temp {
    string cal_source = "CS1" in ["CS1","CS2"]; // Chosen calibration source
    double resist_temp = 80.0; // The desired resistance of CS2, in Ohms
}{
    // Start with CS1
    if(cal_source == "CS1") {
        Pacs_DMC_SET_TEMP_BB_1(resist_temp);
    }
    // Continue with CS2
    if(cal_source == "CS2") {
        Pacs_DMC_SET_TEMP_BB_2(resist_temp);
    }
}

/////////////////////////////////////////////////////////////////////////////
// $Id
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsLineSpec_unChop AOT
//
// CUS author    : DAC
//
// Input arguments: see after module identification
//
// Return values
// {int,int,int} {totalDuration,slewDuration,obsOverPACSandSC}
//
// Comments      : shouod be used only for unChopped or what ever the
// 		 possibilities are vast
//
// History: 1.0 cloned from PacsCal_PacsLineSpec_PV
//          2.0 27-oct-2009 VD PHS-1227 remove implmentation of doSlewScience (keep logic .. hardcode == false
//          3.0 27-oct-2009 VD PHS-1226 enables both SPU channels. Disable PHS-1118
// 
{int,int,int} obs PacsCal_PacsLineSpec_unChop {
    /* "lines" is defined as an array; its elements (and hence its dimension) */
    /*  are provided by HSPOT */
    /* {id,redshifted wavelength,repeat factor,line flux,continuum flux,      */
    /*  line width,line flux unit,line width unit}                            */
    {string,double,int,double,double,double,string,string}[] lines = []; //Filled by HSPOT
    /*------------- following only to use CUS interface -------------------------*/
    string[] lineId = ["My lines"];
    double[] lWave = [82.0]; // line wavelength  in [55.0,210.0]
    int[] repeatLine = [1]; // repeat line in [0,10]
    double[] lineFlux = [111.0]; // Line Flux in [0.0,10000.0]
    double[] lcontFlux = [111.11]; // Continuum flux  in [0.0,10000.0]
    double[] lineWidth = [30.0];
    string[] fluxUnit = ["Jy/m2"];
    string[] widthUnit = ["kms"];
    /*------------- above only to use CUS interface -------------------------*/
    string choppedOBCPxx = "OBCP35" in ["OBCP27","OBCP35"];
    int userNODcycles = 1 in [1,100];
    string orderSel = "order2" in ["order2","order3"];
    bool overrideOBCPparams = false;
    /*     bool useScanParam = false; // Overwrite cal-u values for the scan parameters */
    int nb_SRC_OFF = 1; // scan parameter: (SRC_OFF)chop cycles per grating position
    int nb_ramps_plateau = 2; // scan parameter: ramps per chopper plateau 
    int nb_up_down = 1; // scan parameters: nb_up_down cycle
    /* bool useGratParams */
    bool overrideGratparams = false;
    int grat_step_size = 1200; // scan OBCP parameter: grating step size (to center the line, use negative step size)
    int nb_grat_steps = 148; // scan OBCP parameter: nb of grating steps
    /*    bool useCalblockParam = false; // overwrite cal-u values for the calibration block parameters */
    bool overrideCalBlockOBCP35params = false;
    int cb_nb_up_down = 1; // Cal Block: up_down cycle   
    int cb_nb_ramps_plateau = 2; // Cal Block : number of ramps per chopper plateau
    int cb_nb_CS1_CS2 = 1; // Cal Block: (CS1_CS2) chop cycles per grating position
    /* bool override grating params for calblock */
    bool overrideGratSPEC_BAND_paramsCalBlock = false;
    int cb_nb_grat_step = 16; // cal block : number of grating steps around key wavelength
    int cb_grat_step_size = 168; // cal block : grating step size
    /* bool override SPU in CalBlock */
    bool overrideDefaultsCONF_SPEC_param_SPU = false;
    int nbRdoutRamp_red = 64; // cal block: red readouts per ramp
    int nbRdoutRamp_blu = 64; // cal block: blue readouts per ramp   
    int rdouts_subramp_blu = 16; // detector setting: blue number of readouts per subramp 
    int rdouts_subramp_red = 16; // detector setting: red number of readouts per subramp
    int compression_mode_red = 16; // compression mode in red channel
    int compression_mode_blu = 16; // compression mode is blue channel
    int glitch_det_red = 1; // glitch detection algor. for red channel
    int glitch_det_blu = 1; // glitch detection algo. for the blue channel
    int nb_raw_red = 3; // nb of raw pixels used in red channel
    int nb_raw_blu = 3; // nb of raw pixlels used in blue channel
    string reduction_mode = "ramp average" in ["ramp average","ramp fitting"]; // detector setting: spu reduction mode
    /*    bool useBiasParam = false; // Overwrite the detectors BIAS values */
    bool overrideDefaultsCONF_SPEC_param_CRE = false;
    int capaBlue = 0; // detector setting: capacitance blue  in [0,8,4,12]
    int capaRed = 0; // detector setting: capacitance red  in [0,8,4,12]
    double bias_d_blu = 0.2101 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_d_red = 0.0701 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_blu = 0.0101; // Bias "r" blue
    double bias_r_red = 0.0101; // Bias "b" red
    /* override ALL SPU CRE params */
    bool overrideAll_SPU_CRE_params = false; // do you want allow overriding ALL SPU CRE parameters?
    string scenario = "none"; // scenario name: usage in CONF_SPEC_param rows: scenario_Normal0RED/BLU
    /*    bool useWaveSwitchParam = false; // overwrite cal-u values for wavelength switching */
    bool overrideOBCP32param = false;
    int switch_nb_ramps = 1; // P6 wave switching: number of ramps per grating position
    int switch_nb_up_dn = 1; // P1 wave switching: number of up_dn cycles
    int switch_nbABBA = 3; // P4 wave switching: number of ABBA cyles
    int switch_ditherCount = 11; // P2  wave switching: number of grating dither steps
    int switch_dither_step_size = 300; // P3 wave switching: dithering step size
    int switch_param7 = 700; // P#7
    /*     bool chopNod = true;  PHS-1119*/
    bool chopper = true;
    bool nodding = true;
    double nodOFF = 10.0 in [0.033,120.0]; // Nod Offsets for Pointed unChopped (arcmin)
    bool faintLines = true;
    int nload = 0; // cal block : repeat calibration block every n nod / raster slews   
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    string throw = "large" in ["large","medium","small"];
    string source = "point" in ["point","dithered","large","large_b"];
    double mapRasterAngle = 0.0 in [0.0,360.0];
    int m = 3 in [2,32];
    int n = 3 in [1,32];
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    bool refSelected = false;
    double raoff = 0.0 in [0.0,360.0];
    double decoff = 0.0 in [-90.0,90.0];
    int naifid = 0; // RA,DEC or SSO
    double pointStep = 20.0 in [2.0,480.0];
    double lineStep = 20.0 in [2.0,480.0];
    int knod = 1; // knod in [1,m*n] 
    int obsOverhead = 180; // Slew overhead
    bool startAtOFF = false;
    bool verbose = true;
}{
    //*--------- following only when using CUS interface -------------------*/
    int linesIdLength = length(lineId);
    int linesLength = length(lines);
    if(linesLength == 0) {
        for(int lLoop00 = 0 .. linesIdLength - 1) {
            lines[lLoop00] = {lineId[lLoop00],lWave[lLoop00],repeatLine[lLoop00],lineFlux[lLoop00],lcontFlux[lLoop00],lineWidth[lLoop00],fluxUnit[lLoop00],widthUnit[lLoop00]};
        }
    }
    //*--------- above only when using CUS interface -------------------*/
    // starting catching conflicts
    if(overrideDefaultsCONF_SPEC_param_SPU && overrideAll_SPU_CRE_params) {
        error("Attention conflicting overriding parameters, Defaults wil override the scenario's setup, choose either: ALL or Defaults");
    }
    if(overrideDefaultsCONF_SPEC_param_CRE && overrideAll_SPU_CRE_params) {
        error("Attention conflicting overriding parameters, Defaults will override the scenario's setup, choose either: ALL or Defaults");
    }
    // PHS-1227 (dis-able PHS-200)
    bool doSlewScience = false;
    // switch on SPU during slew prior to CAL block?
    // PHS-1226
    bool stopUnUsedChannelSPU = false;
    // stop the unused SPU chanel?
    //*-----------------------------------------------------------------*/
    // Start of "Pointing" section
    // 
    // extraConf: whatever affects PACS default configuration 
    // Currently: the option faintLines calls for an extraConf
    string extraConf = "normal";
    // Need switching boolean
    bool chopNod = true;
    if(chopper && nodding) {
        chopNod = true;
    } else {
        if(!chopper && !nodding) {
            chopNod = false;
        }
    }
    bool switching = !chopNod;
    bool stare = false;
    if(!chopper && nodding) {
        switching = false;
        chopNod = false;
        stare = true;
    }
    // For bright lines
    if(!faintLines && chopNod) {
        extraConf = "bright";
    } else {
        extraConf = "normal";
    }
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // PHS-1119 starring observation enabled
    //    if(switching && source != "large") {
    //        if(switching && source != "large_b") {
    //            error("Frequency Switch only in mode raster (large source) with OFF");
    //        }
    //    }
    // Decode more HSPOT information
    int nbLines = length(lines);
    int nbLines1 = nbLines - 1;
    // Cannot call with empty "lines"
    if(nbLines == 0) {
        error("STOP!! There are no spectral lines defined!");
    }
    // No more than 10 lines or repetitions
    int nbLinesRep = 0;
    for(int loop00 = 0 .. nbLines - 1) {
        //  Default repetion factor is 1
        int repFactor = lines[loop00]{2};
        if(repFactor == 0) {
            repFactor = 1;
        }
        nbLinesRep = nbLinesRep + repFactor;
    }
    if(verbose) {
        debug_print("Total lines/repeat: " + nbLinesRep);
    }
    if(nbLinesRep > 10) {
        error("STOP!! The number of lines/repetitions exceeds 10");
    }
    // Establish now the applicable Pointing Mode (use same pointCase convention
    // used in PacsPhoto)
    // Pointing mode is undefined. If it remains undefined at the end of
    // the next tests, then there is a problem with the source definition
    int pointCase = 0;
    // FinePointingMode with setup time
    // POINT source, with and without chopNod
    if(source == "point") {
        //    For completiness define a 1x1 raster
        m = 1;
        n = 1;
        if(chopper && !nodding) {
            error("Invalid observation mode");
        }
        //    without nodding
        if(!chopNod) {
            if(switching) {
                string pointMode = "fine_pointing";
                //            string userMode = "Point source (no nodding)";
                //            if(switching) {
                string userMode = "Point source (frequency switch, no nodding)";
                //            }
                pointCase = 11;
                string yzoffsetROW = "S" + pointCase;
            } else {
                if(stare) {
                    //    with nodding      
                    //	      switching = true;
                    pointMode = "composite_nodding";
                    userMode = "Point source (unchopped nodding with off (on nod B)";
                    pointCase = 12;
                    yzoffsetROW = "S" + pointCase;
                }
            }
        } else {
            //    with nodding      
            pointMode = "composite_nodding";
            userMode = "Point source (nodding)";
            pointCase = 12;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // DITHERED source
    // For source "dithered" use predetermined raster parameters
    if(source == "dithered") {
        m = ilookup("SMALL_SRC_params","SPEC","mRast");
        n = ilookup("SMALL_SRC_params","SPEC","nRast");
        pointStep = dlookup("SMALL_SRC_params","SPEC","pointStep");
        lineStep = dlookup("SMALL_SRC_params","SPEC","lineStep");
        if(chopper && !nodding) {
            error("Invalid observation mode");
        }
        //    Raster mode without noding
        if(!chopNod) {
            if(switching) {
                pointMode = "repeated_raster_with_hold";
                userMode = "Small source (frequency switch, no nodding)";
                pointCase = 21;
                yzoffsetROW = "S" + pointCase;
            } else {
                if(stare) {
                    //		switching = true;
                    pointMode = "nodding_in_raster";
                    userMode = "Small source (unchopped nodding with off)";
                    pointCase = 22;
                    yzoffsetROW = "S" + pointCase;
                }
            }
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Small source (nodding)";
            pointCase = 22;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For source "large" user given raster parameters
    if(source == "large") {
        //    Raster mode without noding
        if(chopper && !nodding) {
            error("Invalid observing mode");
        }
        if(!chopNod) {
            if(switching) {
                //	 switching = true;
                pointMode = "repeated_raster_with_hold";
                userMode = "Large source (Wavelngth switching no nodding)";
                pointCase = 31;
                yzoffsetROW = "S" + pointCase;
            } else {
                if(stare) {
                    //	    no switching but use OBCP32;
                    pointMode = "nodding_in_raster";
                    userMode = "Large source (unchopped nodding)";
                    pointCase = 32;
                    yzoffsetROW = "S" + pointCase;
                }
            }
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Large source (nodding)";
            pointCase = 32;
            yzoffsetROW = "S" + pointCase;
        }
    }
    if(source == "large_b") {
        if(chopper && !nodding) {
            error("Invalid observing mode");
        }
        //    Raster mode without noding
        if(!chopNod) {
            if(switching) {
                pointMode = "raster_pointing";
                userMode = "Large source (freq/switch raster w/OFF, no nodding)";
                pointCase = 31;
                yzoffsetROW = "S" + pointCase;
            } else {
                if(stare) {
                    //      with nodding
                    //	    switching = true;
                    pointMode = "nodding_of_raster";
                    userMode = "Large source (unchopped nodding)";
                    pointCase = 32;
                    yzoffsetROW = "S" + pointCase;
                }
            }
        } else {
            if(chopNod) {
                pointMode = "nodding_of_raster";
                userMode = "Large source (nodding)";
                pointCase = 32;
                yzoffsetROW = "S" + pointCase;
            }
        }
    }
    // For symmetrical chopping, virtual apertures are dependent on the chopper
    // throw. Add this information to the CALU key entry
    yzoffsetROW = throw + "" + yzoffsetROW;
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("     PointCase ID: " + pointCase);
        debug_print("     PointMode   : " + pointMode);
        debug_print("     CALU entry  : " + yzoffsetROW);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        for(int iii = 0 .. nbLines1) {
            debug_print("MAIN:Id, Wave, repeat, Lflux, Cflux, etc. " + lines[iii]);
        }
    }
    // Define array of wavelengths (will be needed by the SORT procedure)
    double[] lineWave = [55.0];
    // Populate the array of wavelengths
    for(int loop0 = 0 .. nbLines1) {
        lineWave[loop0] = lines[loop0]{1};
    }
    // For each line obtain the grating order and the grating position 
    int[] orders = [0];
    double[] grat_pos = [0.0];
    // Fill the tuple waveTuple {waveLen,order,gratPos,nbStep,gratStep}
    {double,int,int,int,int}[] waveTuple = [{0.0,0,0,0,0}];
    bool useOBCP32 = false;
    if(stare || switching) {
        useOBCP32 = true;
        if(verbose) {
            debug_print("using OBCP32 for staring");
        }
    }
    for(int loop1 = 0 .. nbLines1) {
        waveTuple[loop1] = SPEC_get_grat_info(lineWave[loop1],"HI",useOBCP32,extraConf,orderSel,verbose);
        //      Create vector of intermediate results
        orders[loop1] = waveTuple[loop1]{1};
        grat_pos[loop1] = double(waveTuple[loop1]{2});
    }
    // To reject forbidden order combination, count how many orders
    int nORDER1 = 0;
    int nORDER2 = 0;
    int nORDER3 = 0;
    for(int loop2 = 0 .. nbLines1) {
        if(orders[loop2] == 1) {
            nORDER1 = nORDER1 + 1;
        }
        if(orders[loop2] == 2) {
            nORDER2 = nORDER2 + 1;
        }
        if(orders[loop2] == 3) {
            nORDER3 = nORDER3 + 1;
        }
    }
    // Reject mixed orders
    if(nORDER2 != 0 && nORDER3 != 0) {
        //    Report band limits
        double[] band2 = SPEC_BAND_read("L2");
        double[] band3 = SPEC_BAND_read("L3");
        error("Combination of 2nd (" + band2[0] + "-" + band2[1] + " mic) and 3rd (" + band3[0] + "-" + band3[1] + " mic) grating orders is not allowed");
    }
    // Reject lines not belonging to authorized order
    if(nORDER2 != 0 && orderSel == "order3") {
        error("You have chosen " + orderSel + " but have specified one/several order2 lines");
    }
    if(nORDER3 != 0 && orderSel == "order2") {
        error("You have chosen " + orderSel + " but have specified one/several order3 lines");
    }
    // Determine the filter needed with given lines
    // No filter needed, i.e. ORDER=1
    int filter = 1;
    // Determine filter based on HSPOT input
    if(orderSel == "order2") {
        filter = 2;
    }
    if(orderSel == "order3") {
        filter = 3;
    }
    if(verbose) {
        debug_print("ORDER array: " + orders);
    }
    // Filter below will be set by SPEC_aot_prologue via SlewCal
    if(verbose) {
        debug_print("MAIN:The full OBS will be performed with filter " + filter);
    }
    // Sort grat_pos from smallest to largest
    int[] sortIndex = SortProc(verbose,grat_pos);
    // Sort by wavelengths (from blue to red)
    // int sortIndex = SortProc(verbose,lineWave);
    // Recast "lines" and waveTuple according to the ordered grating positions
    {string,double,int,double,double,double,string,string}[] sortLines = [{"empty",0.0,0,0.0,0.0,0.0,"bla","bla"}];
    {double,int,int,int,int}[] sortWaveTuple = [{0.0,0,0,0,0}];
    for(int reSORT = 0 .. nbLines1) {
        //      Reversed sort
        // No reverse SORT (start observations with filter A)
        //        int revSORT         = nbLines1 - reSORT;
        int revSORT = reSORT;
        int sortedIndex = sortIndex[revSORT];
        sortLines[reSORT] = lines[sortedIndex];
        sortWaveTuple[reSORT] = waveTuple[sortedIndex];
        if(verbose) {
            debug_print("Sorted Line: " + sortLines[reSORT]);
        }
    }
    // The tuple arrays confOBCP, confSPECred, and confSPECblu play a major
    // role. They contain the parameters related to commanding different PACS
    // subsystems. They are susceptible of changing with the observing conditions.
    // Hence, they have to be watched for changes since these imply sending one or
    // more TCs (usually invoking a building block)
    // Define confOBCP array
    // confOBCP{0 -> 19} contains:
    // nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
    // nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
    // grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
    // chop_pos_SRC     chop_pos_REF1    chop_pos_REF2    chop_pos_CS1
    // chop_pos_CS2     chop_def         detector         order
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // a very long confSPEC/red/blu/SPU tuple ... 
    // Define confSPECblu and confSPECred
    // confSPEC contians:
    //   capa,       nb_rdouts_ramp, nb_rdouts_subramp, comp_mode,
    //   glitch_det, ramp_fit_alg,   nb_raw,            bias_r,    bias_d
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // Estimator module returns {confSPECblu,confSPECred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    // Obtain default values
    string throwUsage = throw;
    // Frequency switch parameters are as for offraster in PacsRange
    // REF1 is not set to be equal to REF2 (relevant OBCP 32)
    if(switching || stare && source == "large") {
        throwUsage = "offraster";
    }
    if(verbose) {
        debug_print("PacsLine:Use throw: " + throwUsage);
    }
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    double[] refWL = [sortLines[0]{1}];
    double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    double[] keyWAVE = [keyWL];
    // gniark complicated --- do I update PacsSpecdefaults .. I don't want a LONG tuple ... just a scenario
    //  !!! detecor too
    // IMPORTANT NOTE
    //---------------
    // Logic to stop the "non-prime" channel. This is the channel not used by 
    // the KeyWave, making also sure that detector sync follows
    // 
    // PHS-1226
    // 
    //    bool stopSPUS = false;
    //    bool stopSPUL = false;
    // Channel selection
    //    if(keyWAVE[0] > 100.0) {
    //        stopSPUS = true;
    //        int detector = 2;
    //    }
    //    if(keyWAVE[0] < 100.0) {
    //        stopSPUL = true;
    //        detector = 1;
    //    }
    if(overrideAll_SPU_CRE_params) {
        //        paramsSPECdef = PacsSpecDefaultsSPU(throwUsage,extraConf,detector,stopUnUsedChannelSPU,scenario,verbose);
        paramsSPECdef = PacsSpecDefaultsSPU(throwUsage,extraConf,scenario,verbose);
    } else {
        //    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,detector,verbose);
        paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    }
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    //    confOBCP[0]{18} = detector;
    // Here comes the module(s) to estimate OBS times as a function of the
    // input given by the HSPOT user.
    //Define tuple to contain the "variable" parameters
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPEC = clone(paramsSPECdef);
    // paramsSPECext (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,nb_up_dn,aux1,aux2}
    // More info: {nb_nods,nb_up_dn,timeOBS,aux2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for each wavelength. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("MAIN.confOBCP[0]: " + confOBCP[0]);
    }
    int nbNods = 0;
    // Accumulator total OBS time
    int totalOBS = 0;
    // For each demanded wavelength compute minimum duration
    for(int waveLOOP = 1 .. nbLines) {
        int waveLOOP1 = waveLOOP - 1;
        //    Different OBCPs if frequency switch or not
        if(chopNod) {
            // Here we perform nodding/chopping
            // SCR-2942: consider case of faintLines = false
            string forDEBUG = "chop/nod";
            if(choppedOBCPxx == "OBCP35") {
                // implement OBCP35 for test indem OBCP27 carefull OBCPconf parameters order
                paramsSPECext = PacsLineSpecEstimatorOBCP35(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,chopNod,faintLines,verbose);
            } else {
                if(choppedOBCPxx == "OBCP27") {
                    paramsSPECext = PacsLineSpecEstimatorOBCP27(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,chopNod,faintLines,verbose);
                }
            }
            //      Copy estimates to respective tuples
            confSPECblu[waveLOOP] = paramsSPECext{0};
            confSPECred[waveLOOP] = paramsSPECext{1};
            confOBCP[waveLOOP] = paramsSPECext{2};
            //            confOBCP[waveLOOP]{18} = detector;
            if(overrideOBCPparams) {
                confOBCP[waveLOOP]{0} = nb_up_down;
                confOBCP[waveLOOP]{3} = nb_SRC_OFF;
                confOBCP[waveLOOP]{4} = nb_ramps_plateau;
            }
            if(overrideGratparams) {
                confOBCP[waveLOOP]{1} = grat_step_size;
                confOBCP[waveLOOP]{2} = -grat_step_size;
                confOBCP[waveLOOP]{6} = nb_grat_steps;
                confOBCP[waveLOOP]{7} = nb_grat_steps;
            }
        } else {
            if(switching) {
                // Here we perform frequency switching
                forDEBUG = "freq/switch";
                paramsSPECext = PacsLineSpecEstimatorOBCP32(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,verbose);
            } else {
                // Here we perform frequency switching
                forDEBUG = "unChopped Obs.";
                debug_print("UNCHOPPED");
                paramsSPECext = PacsLineSpecEstimatorOBCP32_unChop(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,verbose);
            }
        }
        //      Copy estimates to respective tuples
        confSPECblu[waveLOOP] = paramsSPECext{0};
        confSPECred[waveLOOP] = paramsSPECext{1};
        confOBCP[waveLOOP] = paramsSPECext{2};
        //       confOBCP[waveLOOP]{18} = detector;
        if(overrideOBCP32param) {
            confOBCP[waveLOOP]{1} = switch_param7;
            confOBCP[waveLOOP]{2} = switch_nbABBA;
            confOBCP[waveLOOP]{4} = switch_nb_ramps;
            confOBCP[waveLOOP]{0} = userNODcycles * switch_nb_up_dn;
            confOBCP[waveLOOP]{6} = switch_ditherCount;
            confOBCP[waveLOOP]{7} = switch_ditherCount;
            confOBCP[waveLOOP]{9} = switch_dither_step_size;
        }
    }
    if(overrideCalBlockOBCP35params) {
        confOBCP[0]{0} = cb_nb_up_down;
        confOBCP[0]{5} = cb_nb_CS1_CS2;
        confOBCP[0]{4} = cb_nb_ramps_plateau;
    }
    if(overrideGratSPEC_BAND_paramsCalBlock) {
        confOBCP[0]{6} = cb_nb_grat_step;
        confOBCP[0]{7} = cb_nb_grat_step;
        confOBCP[0]{1} = -cb_grat_step_size;
        confOBCP[0]{2} = cb_grat_step_size;
    }
    // Warning complicated !!!!	   
    if(overrideDefaultsCONF_SPEC_param_SPU) {
        // here comes the SPU and CRE setup: calibration block
        confSPECblu[0]{1} = nbRdoutRamp_blu;
        confSPECred[0]{1} = nbRdoutRamp_red;
        confSPECred[0]{2} = rdouts_subramp_blu;
        confSPECblu[0]{2} = rdouts_subramp_red;
        confSPECred[0]{3} = compression_mode_red;
        confSPECblu[0]{3} = compression_mode_blu;
        confSPECred[0]{4} = glitch_det_red;
        confSPECblu[0]{4} = glitch_det_blu;
        confSPECred[0]{6} = nb_raw_red;
        confSPECblu[0]{6} = nb_raw_blu;
        //       if(nbRdoutRamp_blu >= nbRdoutRamp_red) {
        //           detector = 1;
        //           confOBCP[0]{18} = detector;
        //       }
        //       if(nbRdoutRamp_blu < nbRdoutRamp_red) {
        //           detector = 2;
        //           confOBCP[0]{18} = detector;
        //       }
        // the same for SCI OBCPs
        confSPECblu[waveLOOP]{1} = nbRdoutRamp_blu;
        confSPECred[waveLOOP]{1} = nbRdoutRamp_red;
        confSPECred[waveLOOP]{2} = rdouts_subramp_blu;
        confSPECblu[waveLOOP]{2} = rdouts_subramp_red;
        confSPECred[waveLOOP]{3} = compression_mode_red;
        confSPECblu[waveLOOP]{3} = compression_mode_blu;
        confSPECred[waveLOOP]{4} = glitch_det_red;
        confSPECblu[waveLOOP]{4} = glitch_det_blu;
        confSPECred[waveLOOP]{6} = nb_raw_red;
        confSPECblu[waveLOOP]{6} = nb_raw_blu;
        //       if(nbRdoutRamp_blu >= nbRdoutRamp_red) {
        //           detector = 1;
        //           confOBCP[waveLOOP]{18} = detector;
        //       }
        //       if(nbRdoutRamp_blu < nbRdoutRamp_red) {
        //           detector = 2;
        //           confOBCP[waveLOOP]{18} = detector;
        //       }
    }
    if(overrideDefaultsCONF_SPEC_param_CRE) {
        // 
        confSPECred[0]{0} = capaRed;
        confSPECblu[0]{0} = capaBlue;
        confSPECred[0]{7} = iround(1000.0 * bias_r_red);
        confSPECblu[0]{7} = iround(1000.0 * bias_r_blu);
        confSPECred[0]{8} = iround(1000.0 * bias_d_red);
        confSPECblu[0]{8} = iround(1000.0 * bias_d_blu);
        if(reduction_mode == "ramp average") {
            confSPECblu[0]{5} = 1;
            confSPECred[0]{5} = 1;
        } else {
            if(reduction_mode == "ramp fitting") {
                confSPECred[0]{5} = 0;
                confSPECblu[0]{5} = 0;
            }
        }
        confSPECred[waveLOOP]{0} = capaRed;
        confSPECblu[waveLOOP]{0} = capaBlue;
        confSPECred[waveLOOP]{7} = iround(1000.0 * bias_r_red);
        confSPECblu[waveLOOP]{7} = iround(1000.0 * bias_r_blu);
        confSPECred[waveLOOP]{8} = iround(1000.0 * bias_d_red);
        confSPECblu[waveLOOP]{8} = iround(1000.0 * bias_d_blu);
        if(reduction_mode == "ramp average") {
            confSPECblu[waveLOOP]{5} = 1;
            confSPECred[waveLOOP]{5} = 1;
        } else {
            if(reduction_mode == "ramp fitting") {
                confSPECred[waveLOOP]{5} = 0;
                confSPECblu[waveLOOP]{5} = 0;
            }
        }
        //      Accumulate total OBS time
        totalOBS = totalOBS + paramsSPECext{3}{2};
        if(verbose) {
            debug_print("MAIN.confOBCP[0]: " + confOBCP[0]);
            debug_print("MAIN.Obs mode    : " + forDEBUG);
            debug_print("MAIN.Wavelength  : " + sortLines[0]{1});
            debug_print("MAIN.confOBCP[" + waveLOOP + "]: " + confOBCP[waveLOOP]);
            debug_print("MAIN.confSPEC[" + waveLOOP + "]: " + confSPECblu[waveLOOP]);
            debug_print("MAIN.confSPEC[" + waveLOOP + "]: " + confSPECred[waveLOOP]);
        }
    }
    if(verbose) {
        debug_print("MAIN.Minimum required time: " + totalOBS + " [sec]");
    }
    if(chopNod || stare) {
        // Here we perform nodding/chopping
        nbNods = userNODcycles;
        if(verbose) {
            debug_print("MAIN.The PointReq will contain " + nbNods + " nod cycles");
        }
    } else {
        if(switching) {
            // Here we perform freq switch
            nbNods = 0;
        }
    }
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Minimum required OBStime: " + totalOBS + " [sec]</p>";
    lineCnt = lineCnt + 1;
    int nodTotal = nbNods * totalOBS;
    if(chopNod) {
        msgLine[lineCnt] = "<p>With the specified NOD count, " + nbNods + ", the total OBS time amounts to " + nodTotal + "[sec]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Since no NOD was specified the total OBS time is equal" + " to the minimum required time. The time can be changed" + " by changing the line(s) repeat factor</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("Accumulated SRC+REF time estimation",lineCnt,msgLine);
    // Messages on general Detector/SPU parameters
    lineCnt = 0;
    msgLine[lineCnt] = "<p>Red channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECred[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    int subRamps = confSPECred[0]{1} / confSPECred[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECred[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECred[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Blue channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECblu[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    subRamps = confSPECblu[0]{1} / confSPECblu[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECblu[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECblu[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Selected PACS setup parameters",lineCnt,msgLine);
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source
    // First operation is to set the OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // Will call PacsSpecSlewCal to perform AOT prologue and CAL during
    // slew to source. Establish an array of key wavelengths, one per order,
    // commensurate with user given wavelengths
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    //    int order4key = sortWaveTuple[0]{1};
    //    double[] refWL = [sortLines[0]{1}];
    //    string keyOrder = "order" + order4key;
    //    double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    //    double[] keyWAVE = [keyWL];
    // double[] keyWAVE = PacsLineSpecKeyWaves(sortWaveTuple);
    //    int nbKeyWAVE = length(keyWAVE); == 1 
    int nbKeyWAVE = 1;
    // With current versions of CommandOBCP27 and CommandOBCP32, the grating is
    // supposed to be left by SlewCal at the position needed for the 1st line
    // The OBCPs will leave the grating at that same position
    int frstLstGratPos = confOBCP[1]{8};
    if(verbose) {
        debug_print("MAIN:SortWaveTuple: " + sortWaveTuple);
        debug_print("MAIN:keyWAVES " + keyWAVE);
        debug_print("MAIN:SlewCal should leave grating at: " + frstLstGratPos);
    }
    // To stop unused channel we need
    // PHS-1226
    //    int timeToStop = duration(SPEC_spu_channel_stop(stopSPUS,stopSPUL,verbose));
    // Time needed to perform these activities during slew (includes AOT
    // prologue) ...
    bool doAOTprologue = true;
    if(overrideAll_SPU_CRE_params) {
        int timeSlewCal = duration(PacsSpecSlewCalSPU(verbose,scenario,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel));
    } else {
        timeSlewCal = duration(PacsSpecSlewCal_override(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalBlockOBCP35params));
    }
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during slew: " + timeSlewCal);
    }
    // CAL for HOLD 
    doAOTprologue = false;
    if(overrideAll_SPU_CRE_params) {
        int timeHoldCal = duration(PacsSpecSlewCalSPU(false,scenario,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,0,frstLstGratPos,orderSel));
    } else {
        timeHoldCal = duration(PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,0,frstLstGratPos,orderSel,overrideCalBlockOBCP35params));
    }
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during HOLD: " + timeHoldCal);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsSpecCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsSpecCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // IMPORTANT NOTE: the duration could be different for the first cycle through 
    // all wavelengths than for the following ones owing to differing initial state.
    // However, all steps have been taken so that PACS starts the actual observation
    // in the same state as it would be left at the end of any wavelength cycle
    // Duration of any nod leg or staring observation
    // Different OBCP for wavelength switch
    if(chopNod) {
        // Here we perform nodding/chopping
        if(choppedOBCPxx == "OBCP35") {
            int timeOBS = duration(PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,verbose));
            if(verbose) {
                debug_print("Duration OBCP35: " + timeOBS + " [sec] per pointing;  nbNods: " + nbNods);
            }
        }
        if(choppedOBCPxx == "OBCP27") {
            timeOBS = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
            if(verbose) {
                debug_print("Duration OBCP27: " + timeOBS + " [sec] per pointing;  nbNods: " + nbNods);
            }
        }
    } else {
        if(switching) {
            // Here we perform freq switch or unChopped Obs.
            timeOBS = duration(PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,verbose));
            if(verbose) {
                debug_print("Duration OBCP32: " + timeOBS + " [sec] per pointing");
            }
        } else {
            // here we perform unchopped nodding/rasters etc...
            timeOBS = duration(PacsSpecCommandOBCP32_unChop(confSPECblu,confSPECred,confOBCP,verbose));
            if(verbose) {
                debug_print("Duration OBCP32 unchopped: " + timeOBS + " [sec] per pointing;  nbNods: " + nbNods);
            }
        }
    }
    // Get duration of module to close AOT operations
    // This includes parking the grating
    // Park position
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // The grating was left by OBCPs at frstLstGratPos
    int timeEpilogue = duration(SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose));
    // WriteEndID will be the last TC; get its duration
    int timeEndID = duration(WriteEndID());
    // Summary of relevant data collected so far
    // timeSlewCal: duration of the leading CAL, including AOT_prologue
    // timeOBS    : duration of a single pointed OBS
    // nb_nods    : number of nods for staring mode or per raster position
    // chopNod : invoke nodding or not (nb_nods = 0 is equivalent to no nod)
    // m, n       : raster nb_points/line, nbLines per RREQ
    // pointStep,lineStep: more raster parameters
    // ra,dec: more pointing parameters
    //
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Ready to issue a FinePointing mode with/without nodding or
    // a RasterReq with/without nodding. Either one will use time during
    // slew to perform SlewCal.
    //
    // The chopper step has been read already (PacsSpecDefaults). However,
    // there are no provisions to carry that information here. Easiest is to
    // read again the relevant CAL-U table. Read chopper position SRC and
    // REF1 [arcsec]
    double chopAngleSrc = dlookup("SPEC_CHOP_params",throw,"SRC");
    double chopAngleRef = dlookup("SPEC_CHOP_params",throw,"REF1");
    // The total nodThrow = chopperTotalThrow
    double nodThrow = abs(chopAngleSrc - chopAngleRef);
    if(verbose) {
        debug_print("PacsSpecDef: CHOP/NOD params SRC/REF/NOD: " + chopAngleSrc + "/" + chopAngleRef + "/" + nodThrow);
    }
    // Issue pointing request (when possible use JBr's variable names for clarity)
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    // Virtual aperture
    string ib = "P02_0";
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("#### skewCorrec : " + skewCorrec);
    }
    if(stopUnUsedChannelSPU) {
        int tslewmin = timeSetOBSID + timeSlewCal;
    } else {
        tslewmin = timeSetOBSID + timeSlewCal;
    }
    int tinithold = 0;
    int tfinalhold = timeEndID + timeEpilogue;
    int tp = timeOBS;
    double patt = 0.0;
    double pattnod = 270.0 + skewCorrec;
    int k = 0;
    int thold = 0;
    int nhold = 0;
    nload = 0;
    int tloadslewmin = 0;
    bool fixed = true;
    // FinePointingMode with setup time
    if(pointCase == 11) {
        //     FinePointingMode without nodding     
        int[] fromPntReq = basic_fine_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,yoffset,zoffset,tp);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        int tend = fromPntReq[2];
    }
    if(pointCase == 12) {
        //     FinePointingMode with nodding, section 3.4     
        ib = "P02_0";
        //     Nodding is specified wrt spacecraft
        fixed = false;
        //     Nodding is along y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        if(stare) {
            nodThrow = nodOFF * 60.0;
        }
        fromPntReq = nodding_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nbNods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tnod = fromPntReq[2];
        tss = fromPntReq[3];
        tload = fromPntReq[4];
        tend = fromPntReq[5];
    }
    if(pointCase == 21 || pointCase == 31) {
        //     RasterMode repeated_raster_with_hold_and_OFF, section 3.5
        ib = "P02_0";
        //     Raster in instrument coordinates
        fixed = false;
        double d1 = pointStep;
        double d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        k = 0;
        int top = 0;
        if(!switching && pointCase == 21) {
            raoff = 0.0;
            decoff = 0.0;
        }
        int nrepeat = 1;
        //     If switching for "large" source perform OFF observation
        if(switching || pointCase == 31) {
            //        Repeat raster according to userNODcycles
            nrepeat = userNODcycles;
            k = n * m;
            top = tp;
        }
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        //     SPR-3237 (map orientation parameter) applies only to raster
        if(pointCase == 31) {
            fixed = true;
            patt = mapRasterAngle;
        }
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
        // XY-stage variables
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        tsop = fromPntReq[5];
        trep = fromPntReq[4];
        tend = fromPntReq[6];
    }
    if(pointCase == 22 || pointCase == 32 && source != "large_b") {
        //     Raster mode w/nodding, section 3.6
        ib = "P02_0";
        //     Raster in instrument coordinates
        fixed = false;
        //     Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        //     Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        //     New arguments for pointing request; will be dealt with next iteration
        if(!stare) {
            k = 0;
            nrepeat = 1;
            top = 0;
            raoff = 0.0;
            decoff = 0.0;
        } else {
            top = tp;
            k = m * n;
            nrepeat = 1;
        }
        trepeatmin = 0;
        tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nbNods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
        tend = fromPntReq[9];
    }
    if(pointCase == 32 && source == "large_b") {
        //    Nodding of Raster, section 3.6
        ib = "P02_0";
        //   Raster in instrument coordinates
        fixed = false;
        //   Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        //   Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        //        k = m * n;
        int ncycles = userNODcycles;
        nrepeat = 1;
        tloadmin = 0;
        fromPntReq = nodding_of_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,pattnod,nodThrow,ncycles,knod,nrepeat,tloadmin,nload);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        tnod = fromPntReq[4];
        tload = fromPntReq[5];
        trep = fromPntReq[6];
        tend = fromPntReq[7];
    }
    // Parameters returned by PointReq
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Issue PointRequest now");
        debug_print("Return from PointReq: " + fromPntReq);
    }
    //Info from API (nomenclature from Jon Br)
    tobs = fromPntReq[0];
    tslew = fromPntReq[1];
    ///////////////////////// end of "timing" section //////////////////////////
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
        int tNOW = time();
        debug_print("=====Issued PointReq Time_now: " + tNOW);
    }
    // Issue TCs
    int[] stateVar = [0];
    int nbOBS = 0;
    int nbOFF = 0;
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            //       Write OBSID (logical part of SlewCal)
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            if(!doSlewScience) {
                tNOW = time();
                if(verbose) {
                    debug_print(" AOT science Data OFF: " + tNOW);
                }
                if(tslew > tslewmin) {
                    delay(tslew - tslewmin);
                }
                // Now, execute the standard calibration block pushed to the end of the slew
                tNOW = time();
                if(verbose) {
                    debug_print("SLEW_CAL starts at   " + tNOW);
                }
                if(overrideAll_SPU_CRE_params) {
                    int[][] calTime = PacsSpecSlewCalSPU(false,scenario,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel);
                } else {
                    calTime = PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalBlockOBCP35params);
                }
                //          Stop unused SPU
                // PHS-1226
                //                if(stopUnUsedChannelSPU) {
                //                    SPEC_spu_channel_stop(stopSPUS,stopSPUL,verbose);
                //                }
            }
            if(doSlewScience) {
                tNOW = time();
                if(verbose) {
                    debug_print("Aot Science Data ON: " + tNOW);
                }
                int[] aotTime = Pacs_SPEC_aot_prologue(false,confSPECblu,confSPECred,confOBCP,filter);
                if(tslew > tslewmin) {
                    delay(tslew - tslewmin);
                }
                // Now, execute the standard calibration block pushed to the end of the slew
                tNOW = time();
                if(verbose) {
                    debug_print("SLEW_CAL starts at   " + tNOW);
                }
                if(overrideAll_SPU_CRE_params) {
                    calTime = PacsSpecSlewCalSPU(false,scenario,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel);
                } else {
                    calTime = PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalBlockOBCP35params);
                }
                //          Stop unused SPU
                //               if(stopUnUsedChannelSPU) {
                //                   SPEC_spu_channel_stop(stopSPUS,stopSPUL,verbose);
                //               }
            }
            //       Define accumulated Cal time
            int[][] sumUpCalTime = calTime;
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW ends at: " + tNOW);
                debug_print("    SumUpCalTime: " + sumUpCalTime);
            }
        } else {
            if(stateVar[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== POINT starts at: " + tNOW);
                }
                //       Regular OBCP or frequency switched OBCP?
                if(chopNod) {
                    if(choppedOBCPxx == "OBCP35") {
                        int[][] obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                    }
                    if(choppedOBCPxx == "OBCP27") {
                        obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                    }
                } else {
                    if(switching) {
                        obsTime = PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                    }
                    if(stare) {
                        obsTime = PacsSpecCommandOBCP32_unChop(confSPECblu,confSPECred,confOBCP,false);
                    }
                }
                nbOBS = nbOBS + 1;
                //       Logic to sum up obsTime
                if(nbOBS == 1) {
                    int[][] sumUpObsTime = obsTime;
                }
                if(nbOBS > 1) {
                    sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("    SumUpObsTime: " + sumUpObsTime);
                    debug_print("=== POINT ends at: " + tNOW);
                }
            } else {
                if(stateVar[0] == 4) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF starts at: " + tNOW);
                    }
                    //       Regular OBCP or frequency switched OBCP?
                    if(chopNod) {
                        if(choppedOBCPxx == "OBCP35") {
                            PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                        }
                        if(choppedOBCPxx == "OBCP27") {
                            ///            obsTime =  
                            PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                        }
                    } else {
                        if(switching) {
                            obsTime = PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                        }
                        if(stare) {
                            obsTime = PacsSpecCommandOBCP32_unChop(confSPECblu,confSPECred,confOBCP,false);
                        }
                    }
                    nbOFF = nbOFF + 1;
                    //       Logic to sum up obsTime
                    ///         if (nbOFF == 1) {sumUpObsTime = obsTime;}
                    ///         if (nbOFF > 1)  {sumUpObsTime = SumFunction(obsTime,sumUpObsTime);}
                    if(verbose) {
                        tNOW = time();
                        ///          debug_print("    SumUpObsTime: " + sumUpObsTime);
                        debug_print("=== OFF ends at: " + tNOW);
                    }
                } else {
                    if(stateVar[0] == 7) {
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== NOD starts at: " + tNOW);
                        }
                        if(chopNod) {
                            if(choppedOBCPxx == "OBCP35") {
                                obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                            }
                            if(choppedOBCPxx == "OBCP27") {
                                obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                            }
                        } else {
                            if(stare) {
                                obsTime = PacsSpecCommandOBCP32_unChop(confSPECblu,confSPECred,confOBCP,false);
                            }
                        }
                        nbOBS = nbOBS + 1;
                        //       Logic to sum up obsTime
                        if(nbOBS == 1) {
                            sumUpObsTime = obsTime;
                        }
                        if(nbOBS > 1) {
                            sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                        }
                        if(verbose) {
                            tNOW = time();
                            debug_print("    SumUpObsTime: " + sumUpObsTime);
                            debug_print("=== NOD ends at: " + tNOW);
                        }
                    } else {
                        if(stateVar[0] == 6) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== HOLD starts at: " + tNOW);
                            }
                            if(overrideAll_SPU_CRE_params) {
                                calTime = PacsSpecSlewCalSPU(false,scenario,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel);
                            } else {
                                calTime = PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalBlockOBCP35params);
                            }
                            sumUpCalTime = SumFunction(calTime,sumUpCalTime);
                            if(verbose) {
                                tNOW = time();
                                debug_print("    SumUpCalTime: " + sumUpCalTime);
                                debug_print("=== HOLD ends at: " + tNOW);
                            }
                        } else {
                            if(stateVar[0] == 5) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== FinalHOLD  starts at: " + tNOW);
                                }
                                SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose);
                                WriteEndID();
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== FinalHOLD  ends at: " + tNOW);
                                }
                            } else {
                                if(stateVar[0] == -1) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== AOT  ends at: " + tNOW);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    if(verbose) {
        debug_print("OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("Ending with NbOFF: " + nbOFF);
    }
    if(!stare) {
        // The original concept of returning durations did not take into 
        // account the bandwidth of the TC bus (2 TCs/sec). The "real" 
        // duration is given by the result from the "duration()" function. Hence
        // the true total duration of the SlewCal phase is given by
        ///   calTime[0] = timeSlewCal;
        // as a result, the overheads are now
        ///   calTime[4] = calTime[0]-(calTime[1]+calTime[2]+calTime[3]); 
        if(verbose) {
            debug_print("Slew & HOLD Cal return: " + sumUpCalTime);
        }
        // The same holds true for the OBCP27 phase. However, I cannot make the
        // break-down by wavelength (the OBCP27 duration is given for ALL lines).
        // We may add up the SRC, CAL, and OVR components of OBCP27 duration. For
        // this we need a tuple so we can add the wavelength and other relevant
        // information to the (per wave) duration arrays.
        //
        //  infoArray[] contains a "fixed" global information part
        //  infoArray[0]: {Slew,   intTime,TotDur,nbRanges,nnods,m*n}
        //  infoArray[1]: {Point,  intTime,TotDur,nbRanges,nnods,m*n}
        //  infoArray[2]: {AOTinfo,intTime,TotDur,nbRanges,nnods,m*n}
        //
        // and a per wavelength array:
        //    [waveSTART,waveEND,order,gratStep,nbGratStep,TOT,SRC,REF,CAL,OVR]
        // TotDur as given by duration(); TOT,SRC,REF,CAL,OVR are also in [sec]
        {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
        // Fill 1st dimension of infoArray with data from SlewCal
        // Instead of using timeSlewCal, use tslew time returned by PointReq
        // infoArray[0] = {{"SlewCal",0.0,timeSlewCal,0,0,0},[{0.,0.,0,0,0,0,0,0,0,0}]};
        infoArray[0] = {{"SlewCal",0.0,tslew,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
        // Compute integration time per chopper plateau
        // intTime = nbRamps/plateau x nbRdouts/ramp x sampleInterval 
        // Sampling frequency
        double specSample = dlookup("PACSparams","spec_sample","freq_time");
        // Number of readouts per ramp
        int nbRdoutRamp = confSPECblu[1]{1};
        // NOTE: WAIT=1 are now counted as useful ramps; hence
        int wait1 = 1;
        // but there is no wait in FreqSwitch
        // Count the WAIT=1 for grating as a useful SRC
        if(switching) {
            wait1 = 1;
        }
        int nbRampPlateau = confOBCP[1]{4} + wait1;
        // 
        double intTime = double(nbRampPlateau * nbRdoutRamp) / specSample;
        if(verbose) {
            debug_print("MAIN:AOT          : " + userMode);
            debug_print("MAIN:Rdouts/ramp  : " + nbRdoutRamp);
            debug_print("MAIN:Ramps/plateau: " + nbRampPlateau);
            debug_print("MAIN:IntTime      : " + intTime);
        }
        // Replace timeOBS (per raster and per nod) with tobs from PntReq (matching
        // change in PacsProcessInfoArray)   
        // infoArray[1] = {{userMode,intTime,timeOBS,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
        infoArray[1] = {{userMode,intTime,tobs,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
        for(int loop3 = 0 .. nbLines1) {
            //     for some reason it has to be "initialized"
            infoArray[1]{1}[loop3] = {0.0,0.0,0,0,0,0,0,0,0,0};
            //     copy the START wavelength (for LINE START = END = line wave)
            infoArray[1]{1}[loop3]{0} = sortLines[loop3]{1};
            //     copy the END   wavelength (for LINE START = END = line wave)
            infoArray[1]{1}[loop3]{1} = sortLines[loop3]{1};
            //     copy the grating order
            infoArray[1]{1}[loop3]{2} = sortWaveTuple[loop3]{1};
            //     copy the grating step
            infoArray[1]{1}[loop3]{3} = sortWaveTuple[loop3]{4};
            //        infoArray[1]{1}[loop3]{3} = (confOBCP[loop3 + 1]{2} - confOBCP[loop3 + 1]{1}) / 2;
            //     copy the number of grating steps
            infoArray[1]{1}[loop3]{4} = confOBCP[loop3 + 1]{6};
            debug_print("infoArray[1]{1}[]{4} = " + infoArray[1]{1}[loop3]{4});
            //     copy other data from sumUpObsTime
            infoArray[1]{1}[loop3]{5} = sumUpObsTime[loop3][0];
            infoArray[1]{1}[loop3]{6} = sumUpObsTime[loop3][1];
            infoArray[1]{1}[loop3]{7} = sumUpObsTime[loop3][2];
            infoArray[1]{1}[loop3]{8} = sumUpObsTime[loop3][3];
            infoArray[1]{1}[loop3]{9} = sumUpObsTime[loop3][4];
        }
        // Also data from SlewCal to infoArray
        for(int loop4 = 0 .. nbKeyWAVE - 1) {
            //     for some reason it has to be "initialized"
            infoArray[0]{1}[loop4] = {0.0,0.0,0,0,0,0,0,0,0,0};
            //     copy the wavelength
            infoArray[0]{1}[loop4]{0} = keyWAVE[loop4];
            //     copy other data from sumUpCalTimeTime
            infoArray[0]{1}[loop4]{5} = sumUpCalTime[loop4][0];
            infoArray[0]{1}[loop4]{6} = sumUpCalTime[loop4][1];
            infoArray[0]{1}[loop4]{7} = sumUpCalTime[loop4][2];
            infoArray[0]{1}[loop4]{8} = sumUpCalTime[loop4][3];
            infoArray[0]{1}[loop4]{9} = sumUpCalTime[loop4][4];
        }
        // Further update of infoArray: add information from AOT_prologue    
        infoArray[0]{1}[nbKeyWAVE] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //   Copy OVR and TOT times
        infoArray[0]{1}[nbKeyWAVE]{9} = calTime[nbKeyWAVE][4];
        infoArray[0]{1}[nbKeyWAVE]{5} = calTime[nbKeyWAVE][4];
        //   Copy the number of lines observed and the number of key waves used
        infoArray[0]{0}{3} = nbKeyWAVE;
        infoArray[1]{0}{3} = nbLines;
        //   Copy the number of nod cycles and the number of raster points visited
        infoArray[1]{0}{4} = nbNods;
        infoArray[1]{0}{5} = m * n;
        // The duration of the OBS phase is given by timeObsEnd - timeSlewCal
        // Now get it from PntReq: timeObsPhase == tobs
        // int timeObsPhase = timeObsEnd - timeSlewCal;
        // Slew time during the OBS phase is then given by
        int timeSlewObs = tobs - nbOBS * timeOBS;
        if(verbose) {
            debug_print("CalSlew phase lasted [sec]: " + timeSlewCal);
            debug_print("The OBS phase lasted [sec]: " + tobs);
            debug_print("Total slew during OBS [sec]: " + timeSlewObs);
        }
        // Fill 3rd dimension of infoArray with global timing and AOT information
        // timeObsEnd is the total duration of the AOT
        // Pass details of AOT
        // change of OBCP
        // We use OBCP27: OBCP_grat_scan_chop2 or grat_line_scan_chop_3 (unless FreqSwitch)
        if(choppedOBCPxx == "OBCP35" && !stare) {
            string aotName = "GratLineScanChop3";
        }
        if(choppedOBCPxx == "OBCP27" && !stare) {
            aotName = "GratScanChop2";
        }
        // Special "sky time"  for FreqSwitch and SmallSourceDither
        if(switching) {
            aotName = "FreqSwitch";
        }
        if(stare) {
            aotName = "Staring";
        }
        if(source == "dithered") {
            infoArray[1]{0}{0} = "SmSrcDither";
        }
        infoArray[2] = {{aotName,0.0,timeObsEnd,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
        // Use available entries to convey m,n, and nbNods
        infoArray[2]{0}{3} = m;
        infoArray[2]{0}{4} = n;
        // PointSources are also seen with composite_nodding
        if(pointMode == "fine_pointing" || pointMode == "composite_nodding") {
            infoArray[2]{0}{3} = 1;
            infoArray[2]{0}{4} = 1;
        }
        infoArray[2]{0}{5} = nbNods;
        // If switching 
        if(switching && source == "Large") {
            infoArray[1]{0}{0} = "RasterOFF";
        } else {
            if(switching && source == "Point") {
                infoArray[1]{0}{0} = "Pointed";
            }
            infoArray[2]{0}{5} = userNODcycles;
        }
        // Process the information contained in infoArray (pass also sortLines)
        PacsProcessInfoArrayLine(infoArray,sortLines,confOBCP,obsOverhead,nbOBS,nbOFF,verbose);
        // Close messages for HTML format
        message("</html>");
        message("</body>");
        // Compute the total time SRC + REF
        int accumSrceRef = 0;
        for(int loopL = 0 .. nbLines - 1) {
            //   Add up Srce and Ref times (SRC + REF)
            accumSrceRef = accumSrceRef + infoArray[1]{1}[loopL]{6} + infoArray[1]{1}[loopL]{7};
        }
        // Compute overheads as total "sky" time minus SRC+REF time
        int overPACSandSC = fromPntReq[0] - accumSrceRef;
        // Return demanded tuples
    } else {
        overPACSandSC = 0;
        accumSrceRef = 0;
    }

    return {accumSrceRef,fromPntReq[1],overPACSandSC};
}

// Missionphase  : 
//
// Purpose       : Generic PACS spectroscopy AOT setup                 
//
// Author        : Diego A. Cesarsky, HF
// CUS script    : Diego A. Cesarsky
// CVS file      : SPEC_aot_prologue.txt
//
// Arguments     :
// type    Name         DefVal   Description 
// int     ramp_len_red    64    Red ramps' length
// int     ramp_len_blu    64    Blue ramps' length
// double  bias_d_red     0.042  BIAS_D for red spectro  (0-1V)
// double  bias_r_red     0.011  BIAS_R for red spectro  (0-1V)
// double  bias_d_blu     0.100   BIAS_D for blue spectro (0-1V)
// double  bias_r_blu     0.011  BIAS_R for blue spectro (0-1V)
// int     capa_red         8    Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
// int     capa_blu         8    Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
// int     comp_mode_blu   16    Compression mode blue channel
// int     comp_mode_red   16    Compression mode red channel
// int     nb_samp_subramp_blu 64   Number of blue samples per sub-ramp
// int     nb_samp_subramp_red 64   Number of red samples per sub-ramp
// int     nb_raw_spu_blu  1     Number of raw channels transmitted by SPUS
// int     nb_raw_spu_red  1     Number of raw channels transmitted by SPUL
// int     glitch_det      1     Glitch detection; 0=on; 1=off
// int     ramp_fit_alg    1     Ramp fit algorithm [0=LstSq;1=mean value]
// int     filter          0     Desired FLTW position (0: ignore FLTW)
//                 
//
// Description   : Calls successively:                
//                - SPEC_cre_setup: generic setup of detectors for AOT
//                - SPEC_spu_setup: generic AOT setup of SPU  
//                - SPEC_fltw_move: Move FWSPEC to default position
//                - SPEC_MOV_CHOP_and_GRAT: Move chopper and grating to 
//                  default position
//
// Dependencies  : SPEC_fltw_move 
//                 SPEC_cre_setup
//                 SPEC_spu_setup
//                 SPEC_MOV_CHOP_and_GRAT
//
// Preconditions : 
//                 
// Comments      : This BB belongs to the 100 series (spectro)       
//
// Version       : 0.1  7-Oct-2004 Creation by DAC
// History       : 0.2 12-Oct-2004 Revised after revision of the used
//                 1.0  7-jun-2005 Adapted for SPEC_MEC_defalut table giving
//                                 filter position as {int}
//                 1.1 29-aug-2005 Added "whoCalledMe" to SpecSlewCal
//                 1.2  1-sep-2005 Added verbose
// procedures
//                 0.3 18-Oct-2004 Was SPEC_prologue; normalized variable names
//                 0.4 22-Oct-2004 Use new SPEC_cre_setup; cre_ctrl default
// is for capa_xx = 0, heater no longer handled by SPEC_cre_setup
// 1.0 22-Apr-2005 HF introduce mechanisms to default and 
//                 removed duplicate stop SPUs
// 1.1 10-May-2005 DAC Renamed HF's tables without ".txt"
//                 Removed spurious "delay()" at end of block (each called 
//                 module sets it own delay)
// 1.2 12-apr-2006 No longer moves FLTW
// 1.3  1-jun-2006 Reinstated FLTW using passed value (null means ignore
//                 FLTW logic)
// 1.4  6-dec-2006 Adapted for SPEC_fltw_move from ILT
// 2.0	23-sep-2008 SCR 4431 Data rate
// 3.0  06-jul-2009 VD introduces scenario for PV 
// 3.1  23-jul-2009 BV SPR 1798 corrected biases
//
int[] block SPEC_aot_prologueSPU PACS 1110 {
    string scenario = "none";
    int ramp_len_red = 64; // Red ramps' length
    int ramp_len_blu = 64; // Blue ramps' length
    double bias_d_red = 0.042 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_red = 0.011 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.1 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_r_blu = 0.011 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    int capa_red = 0; // Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
    int capa_blu = 0; // Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 64; // Number of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Number of red samples per sub-ramp
    int nb_raw_spu_blu = 1; // Number of raw channels transmitted by SPUS
    int nb_raw_spu_red = 1; // Number of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1; // Ramp fit algorithm [0:LstSq;1:MeanVal]
    int filter = 0; // Desired FLTW position (0: ignore filter)
    bool verbose = true;
}{
    // Register start of BB
    WriteBBID($BBID);
    // Define the elements of time_array
    int duree_sec = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    data_rate(120.0);
    // Accumulated duree [milliseconds]
    int duree_msec = 0;
    // Perform SPEC_cre_setup.
    // NOTE: capa_xxx is added to cre_ctrl_xx within SPEC_cre_setup
    int cre_ctrl_red = 386;
    int cre_ctrl_blu = 386;
    int duree2 = SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    duree_msec = duree_msec + duree2;
    if(verbose) {
        debug_print("duree of SPEC_cre_setup: " + duree2);
    }
    // Perform SPEC_spu_setup, starting SPU
    bool startSPU = true;
    int duree3 = 0;
    if(scenario == "none") {
        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    } else {
        SPEC_spu_setupSPU(scenario,comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    }
    duree_msec = duree_msec + duree3;
    // Position filter wheel at desired position
    // Look up table order <=> telecommand ENG parameter
    string[] fltPOS = ["N/A","NoFilter","POS B","POS A"];
    // Command only for filter 2 or 3
    if(filter == 2 || filter == 3) {
        string fw_posENG = fltPOS[filter];
        int duree4 = SPEC_fltw_move(fw_posENG);
        //    WARNING! SPEC_fltw_move returns its duration in [sec]   
        duree_msec = duree_msec + 1000 * duree4;
        if(verbose) {
            debug_print("SPEC_aot_prologue turns FLTW to " + fw_posENG);
        }
    }
    // Position chopper and grating at their default positions
    int chop_pos = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    int grat_pos = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    if(verbose) {
        debug_print("Moving CHOP and GRAT to positions: " + chop_pos + ", " + grat_pos);
    }
    int[] duree5 = SPEC_MOV_CHOP_and_GRAT(chop_pos,grat_pos);
    duree_msec = duree_msec + duree5[0];
    // Total time is now computed including TC rate
    duree_sec = time() - time_start;
    // All the time spent here is OVR
    duree_OVR = duree_sec;
    // Define time_array 
    int[] time_array = [duree_sec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // Report duration
    if(verbose) {
        debug_print("+++++ SPEC_aot_prologue: " + time_array);
    }
    // Return the array of times
    //Reset Block ID
    WriteEndBB();
    //Return time_array

    return time_array;
}

// File          : PACS_Spec_Curing.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Flasher curing : short flashes with dead times -> Temp & signal evolutions
//		   Third part of the Flashers Performance check (curing schemes)
//
// Author        : P. Royer
//
// Arguments     : flasher current for the curing
//                       number & duration of flashes
//                       idle time between the flashes
//
// Prerequisite  : spectrometer detectors & chopper configured
//
// Description   :  SPU Setup
//                       position chopper on BB2 (reasonnable signal when trying to estimate quality of curing), grating supposed at default position, FW position not critical
//	    Flexible scheme for flasher curing : short flashes with dead times
// 	    chopper to default position
//                       SPU reset
//
// Dependencies : SPEC_spu_setup
//                        SPEC_spu_reset
//                        PACS_Spec_Flash_SWON
//	     PACS_Spec_Flash_Setup
//	     PACS_Spec_Flash_SWOF
//
// Comments      : 
//
// Version       : 1.1
// History       : 1.0 / 12-Mar-2008 initial version by PR
//                    1.1 /  01-Jul-2008 introduced CRE Setup & corresponding CALU, "final_delay" & grat_pos
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.1
// @purpose Flasher curing : short flashes with dead times -> Temp & signal evolutions
// @comment - 
//
procedure PACS_Spec_Curing {
    int blue_flasher_current = 819 in [0,820]; //4mA. [0,4095] = [0,20 mA]
    int red_flasher_current = 819 in [0,820]; //4mA. [0,4095] = [0,20 mA]
    int nflash = 3; // Number of flashes
    int flash_time = 20; // Duration of each flash
    int idle_time = 30; // Idle time between the flashes
    int final_delay = 1; // Idle time at the end of the test (flasher cooldown, detector stabilisation),
}{
    //
    // Internal parameters
    // -------------------
    int chop_pos_BB2 = ilookup("CHOPPERCSparams","SPEC","pos_CS2");
    //int chop_pos_BB2 = 21200;
    //
    // SPU RESET
    //
    PACS_Spec_SPU_Reset();
    delay(1);
    //
    // Setup CREs    -->    Largest Capacitance (No command to the heaters)
    //
    string calUname = "CONFCRECuring";
    // Calibration Table
    string calUrow = "PV";
    // Row in table = Instrument Configuration
    double bias_d_blue = dlookup(calUname,calUrow,"bias_d_blue");
    double bias_d_red = dlookup(calUname,calUrow,"bias_d_red");
    double bias_res_blue = dlookup(calUname,calUrow,"bias_res_blue");
    double bias_res_red = dlookup(calUname,calUrow,"bias_res_red");
    int ramp_blue = ilookup(calUname,calUrow,"ramp_blue");
    int ramp_red = ilookup(calUname,calUrow,"ramp_red");
    int capacity_blue = ilookup(calUname,calUrow,"capacity_blue");
    int capacity_red = ilookup(calUname,calUrow,"capacity_red");
    // CURING PARAMETER
    int curing_mode = 0;
    //
    SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red);
    //
    // SPU SETUP (default = slope fitting)
    //
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int nb_samp_subramp_blu = ilookup(calUname,calUrow,"ramp_blue");
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = ilookup(calUname,calUrow,"ramp_red");
    // Nb of red samples per sub-ramp
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //
    // SEND CHOPPER TO BB2
    PACS_Chop_Move_Abs(chop_pos_BB2);
    delay(1);
    //
    // Start Flashers DiagHK
    //
    // 1: synch w/ BLUE DET  2: synch w/ RED DET  >4: period in ms   0: 1KHz (not to use w/ science)
    int diag_hk_period = 100;
    PACS_Spec_FlashHeat_Diaghk_Setup(diag_hk_period);
    delay(10);
    //
    // SWON FLASHERS
    //
    PACS_Spec_Flash_SWON();
    delay(10);
    //
    // Loop on low power regimes
    // -------------------------
    for(int loopin = 1 .. nflash) {
        PACS_Spec_SPU_Reset();
        delay(1);
        curing_mode = 1;
        SPEC_CRE_Curing_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red,curing_mode);
        delay(1);
        PACS_Spec_Flash_Setup(blue_flasher_current,red_flasher_current);
        delay(flash_time);
        PACS_Spec_Flash_Setup(0,0);
        curing_mode = 0;
        SPEC_CRE_Curing_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red,curing_mode);
        SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
        delay(idle_time);
    }
    //
    // SWOF FLASHERS
    //
    PACS_Spec_Flash_SWOF();
    delay(10);
    // 
    // Detector stabilisation / cooldown / recovery
    // --------------------------------------------
    delay(final_delay);
    //
    // SEND CHOPPER TO DEFAULT
    PACS_Chop_Move_Abs(0);
    delay(1);
    //
    // RESET DIAGHK
    //
    PACS_Diaghk_Reset();
    //
    // RESET SPU
    //
    PACS_Spec_SPU_Reset();
    delay(1);
    //
    // SYNC
    //= = =
    sync();
}

// File          : SPEC_Chopper_fmilt076spec_detsel_llc_ast_V1_OBS.cus
//
// Purpose	:  Chopper synchronous operation with detectors in spec
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do OBCP13 with different RIs
//                  
// Dependencies : DXS7602.
//
// Preconditions   : PACS switched-on and setup spectroscopy.
//                 
// Comments	: 
//
// Version	: 6.0	
// 
// History 	: 0.1 26-07-06 creation by HD. script test.
//                0.2 27-07-06 HD. with all three RIs.
//                0.3 27-07-06 HD. script works
//		  0.4 16-08-06 HD. Included setup and reset of burst
//				   mode.
//		  1.0 24-08-06 HD. DXS&LLC, wo BM.
//		  2.0 24-08-06 HD. script works
//                3.0 06-12-06 HD. Renamed file and mode to xxxx_OBS, sets DetSel table
//				 and resets to default at end of procedure..
//		  4.0 20-06-07 HD. Prepare Test for FM-ILT3.
//		  5.0 05-07-07 HD. IST Chopper Day
//		  6.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//		  7.0 10-feb-2009 HD. Update according to SPR1323.
procedure Pacs_Spec_Chopper_fmilt076spec_detsel_llc_ast_V2 {
}{
    // Setup the diagnostic HK for chopper
    SPEC_chop_det_dhk_fmilt076spec_V2_bb();
    // Assume SPU is stopped, load needed
    PACS_Det_Sel("PACSDetSel_7602");
    // Set Loss-less compression mode for all the observations
    // SPU setup   
    int comp_mode_blu = 20;
    int comp_mode_red = 20;
    int nb_samp_subramp_blu = 16;
    int nb_samp_subramp_red = 16;
    int nb_raw_spu_blu = 3;
    int nb_raw_spu_red = 3;
    int glitch_det = 1;
    int ramp_fit_alg = 1;
    bool startSPU = true;
    // CRE setup
    int ramp_len_red = 16;
    int ramp_len_blu = 16;
    double bias_d_red = 0.069;
    double bias_r_red = 0.01;
    double bias_d_blu = 0.198;
    double bias_r_blu = 0.01;
    int capa_red = 0;
    int capa_blu = 0;
    // RI=1/64
    SPEC_CRE_No_Heater_setup(4,4,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Setup OBCP13
    int nb_up_dn = 50;
    // Nb of up down up... cycles (P#1)
    int grat_step_coarse = 0;
    // Grating coarse movement (P#2)
    int nb_grat_steps = 1;
    // Seq P#3  Nb of grating  steps
    int grat_step_up_fine = 0;
    // Grating fine movement (P#4)
    int nb_cycles_grat = 1;
    // Seq P#5  Nb cycles/grating position
    int chop_pos_CS1 = -21350;
    // Chopper position for CS1 (P#6)
    int nb_ramps_grat_pos = 8;
    // Seq P#7  Nb of ramps per grating position    
    int chop_pos_CS2 = 21200;
    // Chopper position for CS2 (P#8)
    int grat_step_dn_fine = 0;
    // Grating fine movement (P#9)
    int detector = 1;
    // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 496000;
    // Starting grating position
    int grat_time = 40000;
    // Time for grating to move to start position
    //int comp_mode_blu = 25; // "Blue" compression
    //int comp_mode_red = 25; // "Red" compression
    int grat_def = 496000;
    // Grating default position
    int chop_def = 0;
    // Chopped default position
    int grat_def_time = 20000;
    // Grating time to move to grat_def [msec]
    int nb_rdouts_ramp = 4;
    // Number of readouts per ramp
    // execute OBCP13
    OBCP_chop_grat_scan_cal(nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,grat_step_dn_fine,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,4);
    SPEC_spu_reset();
    // RI=1/32
    SPEC_CRE_No_Heater_setup(8,8,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Setup OBCP13
    nb_up_dn = 50;
    // Nb of up down up... cycles (P#1)
    grat_step_coarse = 0;
    // Grating coarse movement (P#2)
    nb_grat_steps = 1;
    // Seq P#3  Nb of grating  steps
    grat_step_up_fine = 0;
    // Grating fine movement (P#4)
    nb_cycles_grat = 1;
    // Seq P#5  Nb cycles/grating position
    chop_pos_CS1 = -21350;
    // Chopper position for CS1 (P#6)
    nb_ramps_grat_pos = 8;
    // Seq P#7  Nb of ramps per grating position    
    chop_pos_CS2 = 21200;
    // Chopper position for CS2 (P#8)
    grat_step_dn_fine = 0;
    // Grating fine movement (P#9)
    detector = 1;
    // Synchronize on this detector 1:Blue 2:Red
    grat_pos = 496000;
    // Starting grating position
    grat_time = 40000;
    // Time for grating to move to start position
    //int comp_mode_blu = 25; // "Blue" compression
    //int comp_mode_red = 25; // "Red" compression
    grat_def = 496000;
    // Grating default position
    chop_def = 0;
    // Chopped default position
    grat_def_time = 20000;
    // Grating time to move to grat_def [msec]
    nb_rdouts_ramp = 8;
    // Number of readouts per ramp
    // execute OBCP13
    OBCP_chop_grat_scan_cal(nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,grat_step_dn_fine,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,8);
    SPEC_spu_reset();
    // RI=1/4
    SPEC_CRE_No_Heater_setup(64,64,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Setup OBCP13
    nb_up_dn = 50;
    // Nb of up down up... cycles (P#1)
    grat_step_coarse = 0;
    // Grating coarse movement (P#2)
    nb_grat_steps = 1;
    // Seq P#3  Nb of grating  steps
    grat_step_up_fine = 0;
    // Grating fine movement (P#4)
    nb_cycles_grat = 1;
    // Seq P#5  Nb cycles/grating position
    chop_pos_CS1 = -21350;
    // Chopper position for CS1 (P#6)
    nb_ramps_grat_pos = 8;
    // Seq P#7  Nb of ramps per grating position    
    chop_pos_CS2 = 21200;
    // Chopper position for CS2 (P#8)
    grat_step_dn_fine = 0;
    // Grating fine movement (P#9)
    detector = 1;
    // Synchronize on this detector 1:Blue 2:Red
    grat_pos = 496000;
    // Starting grating position
    grat_time = 40000;
    // Time for grating to move to start position
    //int comp_mode_blu = 25; // "Blue" compression
    //int comp_mode_red = 25; // "Red" compression
    grat_def = 496000;
    // Grating default position
    chop_def = 0;
    // Chopped default position
    grat_def_time = 20000;
    // Grating time to move to grat_def [msec]
    nb_rdouts_ramp = 64;
    // Number of readouts per ramp
    // execute OBCP13
    OBCP_chop_grat_scan_cal(nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,grat_step_dn_fine,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,64);
    SPEC_spu_reset();
    // Set instrument in default mode
    // CRE setup
    ramp_len_red = 16;
    ramp_len_blu = 16;
    bias_d_red = 0.069;
    bias_r_red = 0.01;
    bias_d_blu = 0.198;
    bias_r_blu = 0.01;
    capa_red = 0;
    capa_blu = 0;
    SPEC_CRE_No_Heater_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // SPU default mode
    comp_mode_blu = 16;
    comp_mode_red = 16;
    nb_samp_subramp_blu = 16;
    nb_samp_subramp_red = 16;
    nb_raw_spu_blu = 3;
    nb_raw_spu_red = 3;
    glitch_det = 1;
    ramp_fit_alg = 1;
    startSPU = false;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //SPU is stopped, load default DetSel Table
    PACS_Det_Sel("PACSDetSel_10000");
    // Move chopper to position 0
    PACS_Chopper_mov_abs_fm_bb(0);
    // Move grating to desired position for this test
    SPEC_Gra_move_abs_raw(496000);
    // Wait 40s for grating to move to its default position
    delay(40);
    // Stop diagnostic housekeeping
    PACS_stop_dhk_bb();
}

// File          : SPEC_Chopper_fmilt076spec_detsel_llc_ast_V1_OBS.cus
//
// Purpose	:  Chopper synchronous operation with detectors in spec
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do OBCP13 with different RIs
//                  
// Dependencies : DXS7602.
//
// Preconditions   : PACS switched-on and setup spectroscopy.
//                 
// Comments	: 
//
// Version	: 6.0	
// 
// History 	: 0.1 26-07-06 creation by HD. script test.
//                0.2 27-07-06 HD. with all three RIs.
//                0.3 27-07-06 HD. script works
//		  0.4 16-08-06 HD. Included setup and reset of burst
//				   mode.
//		  1.0 24-08-06 HD. DXS&LLC, wo BM.
//		  2.0 24-08-06 HD. script works
//                3.0 06-12-06 HD. Renamed file and mode to xxxx_OBS, sets DetSel table
//				 and resets to default at end of procedure..
//		  4.0 20-06-07 HD. Prepare Test for FM-ILT3.
//		  5.0 05-07-07 HD. IST Chopper Day
//		  6.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//		  7.0 10-feb-2009 HD. Update according to SPR1323.
procedure Pacs_Spec_Chopper_fmilt076spec_detsel_llc_ast_V1 {
}{
    // Setup the diagnostic HK for chopper
    SPEC_chop_det_dhk_fmilt076spec_V1_bb();
    // Assume SPU is stopped, load needed
    PACS_Det_Sel("PACSDetSel_7602");
    // Set Loss-less compression mode for all the observations
    // SPU setup   
    int comp_mode_blu = 20;
    int comp_mode_red = 20;
    int nb_samp_subramp_blu = 16;
    int nb_samp_subramp_red = 16;
    int nb_raw_spu_blu = 3;
    int nb_raw_spu_red = 3;
    int glitch_det = 1;
    int ramp_fit_alg = 1;
    bool startSPU = true;
    // CRE setup
    int ramp_len_red = 16;
    int ramp_len_blu = 16;
    double bias_d_red = 0.069;
    double bias_r_red = 0.01;
    double bias_d_blu = 0.198;
    double bias_r_blu = 0.01;
    int capa_red = 0;
    int capa_blu = 0;
    // RI=1/64
    SPEC_CRE_No_Heater_setup(4,4,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Setup OBCP13
    int nb_up_dn = 50;
    // Nb of up down up... cycles (P#1)
    int grat_step_coarse = 0;
    // Grating coarse movement (P#2)
    int nb_grat_steps = 1;
    // Seq P#3  Nb of grating  steps
    int grat_step_up_fine = 0;
    // Grating fine movement (P#4)
    int nb_cycles_grat = 1;
    // Seq P#5  Nb cycles/grating position
    int chop_pos_CS1 = -21350;
    // Chopper position for CS1 (P#6)
    int nb_ramps_grat_pos = 8;
    // Seq P#7  Nb of ramps per grating position    
    int chop_pos_CS2 = 21200;
    // Chopper position for CS2 (P#8)
    int grat_step_dn_fine = 0;
    // Grating fine movement (P#9)
    int detector = 1;
    // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 496000;
    // Starting grating position
    int grat_time = 40000;
    // Time for grating to move to start position
    //int comp_mode_blu = 25; // "Blue" compression
    //int comp_mode_red = 25; // "Red" compression
    int grat_def = 496000;
    // Grating default position
    int chop_def = 0;
    // Chopped default position
    int grat_def_time = 20000;
    // Grating time to move to grat_def [msec]
    int nb_rdouts_ramp = 4;
    // Number of readouts per ramp
    // execute OBCP13
    OBCP_chop_grat_scan_cal(nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,grat_step_dn_fine,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,4);
    SPEC_spu_reset();
    // RI=1/32
    SPEC_CRE_No_Heater_setup(8,8,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Setup OBCP13
    nb_up_dn = 50;
    // Nb of up down up... cycles (P#1)
    grat_step_coarse = 0;
    // Grating coarse movement (P#2)
    nb_grat_steps = 1;
    // Seq P#3  Nb of grating  steps
    grat_step_up_fine = 0;
    // Grating fine movement (P#4)
    nb_cycles_grat = 1;
    // Seq P#5  Nb cycles/grating position
    chop_pos_CS1 = -21350;
    // Chopper position for CS1 (P#6)
    nb_ramps_grat_pos = 8;
    // Seq P#7  Nb of ramps per grating position    
    chop_pos_CS2 = 21200;
    // Chopper position for CS2 (P#8)
    grat_step_dn_fine = 0;
    // Grating fine movement (P#9)
    detector = 1;
    // Synchronize on this detector 1:Blue 2:Red
    grat_pos = 496000;
    // Starting grating position
    grat_time = 40000;
    // Time for grating to move to start position
    //int comp_mode_blu = 25; // "Blue" compression
    //int comp_mode_red = 25; // "Red" compression
    grat_def = 496000;
    // Grating default position
    chop_def = 0;
    // Chopped default position
    grat_def_time = 20000;
    // Grating time to move to grat_def [msec]
    nb_rdouts_ramp = 8;
    // Number of readouts per ramp
    // execute OBCP13
    OBCP_chop_grat_scan_cal(nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,grat_step_dn_fine,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,8);
    SPEC_spu_reset();
    // RI=1/4
    SPEC_CRE_No_Heater_setup(64,64,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    // Setup OBCP13
    nb_up_dn = 50;
    // Nb of up down up... cycles (P#1)
    grat_step_coarse = 0;
    // Grating coarse movement (P#2)
    nb_grat_steps = 1;
    // Seq P#3  Nb of grating  steps
    grat_step_up_fine = 0;
    // Grating fine movement (P#4)
    nb_cycles_grat = 1;
    // Seq P#5  Nb cycles/grating position
    chop_pos_CS1 = -21350;
    // Chopper position for CS1 (P#6)
    nb_ramps_grat_pos = 8;
    // Seq P#7  Nb of ramps per grating position    
    chop_pos_CS2 = 21200;
    // Chopper position for CS2 (P#8)
    grat_step_dn_fine = 0;
    // Grating fine movement (P#9)
    detector = 1;
    // Synchronize on this detector 1:Blue 2:Red
    grat_pos = 496000;
    // Starting grating position
    grat_time = 40000;
    // Time for grating to move to start position
    //int comp_mode_blu = 25; // "Blue" compression
    //int comp_mode_red = 25; // "Red" compression
    grat_def = 496000;
    // Grating default position
    chop_def = 0;
    // Chopped default position
    grat_def_time = 20000;
    // Grating time to move to grat_def [msec]
    nb_rdouts_ramp = 64;
    // Number of readouts per ramp
    // execute OBCP13
    OBCP_chop_grat_scan_cal(nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,grat_step_dn_fine,detector,grat_pos,grat_time,comp_mode_blu,comp_mode_red,grat_def,chop_def,grat_def_time,64);
    SPEC_spu_reset();
    // Set instrument in default mode
    // CRE setup
    ramp_len_red = 16;
    ramp_len_blu = 16;
    bias_d_red = 0.069;
    bias_r_red = 0.01;
    bias_d_blu = 0.198;
    bias_r_blu = 0.01;
    capa_red = 0;
    capa_blu = 0;
    SPEC_CRE_No_Heater_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // SPU default mode
    comp_mode_blu = 16;
    comp_mode_red = 16;
    nb_samp_subramp_blu = 16;
    nb_samp_subramp_red = 16;
    nb_raw_spu_blu = 3;
    nb_raw_spu_red = 3;
    glitch_det = 1;
    ramp_fit_alg = 1;
    startSPU = false;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    //SPU is stopped, load default DetSel Table
    PACS_Det_Sel("PACSDetSel_10000");
    // Move chopper to position 0
    PACS_Chopper_mov_abs_fm_bb(0);
    // Move grating to desired position for this test
    SPEC_Gra_move_abs_raw(496000);
    // Wait 40s for grating to move to its default position
    delay(40);
    // Stop diagnostic housekeeping
    PACS_stop_dhk_bb();
}

// $Id$
// Missionphase  : PACS PV Phase
// File          : WriteENDID_ast_OBS.cus//
//
// Purpose       : Configure the chopper servo loop
//
// Author        : MN
// CUSification  : MN
// Arguments     :
//
// Description   : Write END ID to system
//
// Comments      :
//
// Version       : 2.0
// History       : 1.0  12-nov-2007 initial version
// History       : 2.0  04-mar-2008  Converted into PV script by VDP
//
// 
obs PacsEng_WriteENDID_ast {
    /* Needed variables to call PacsEng_WriteENDID_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_WriteENDID_ast                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(WriteEndID()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
// Purpose       : Stop SPECtroscopy observations at end of AOT
//                  
// TCL author    : 
// TCL file      : 
// CUS author    : Diego Cesarsky
// Script file   : SPEC_aot_epilogue.txt 
//
// Input arguments
// Type Name           Default   Description
//
// Description   : Not much for now (just STOP SPU)
//                 Move grating from wwwhere OBCPs left it to the park
//                 position
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      : Based on V1.3 of TM's tm_spu_setup.tcl. Both
//                 SPUS and SPUL are initialized to same set of parameters
//
// Version       : 0.2
// History       : 0.1 13-apr-2006 First creation
//                 0.2 15-feb-2007 Leave grating at park position
procedure SPEC_aot_epilogue_DataRates {
    int gratFrom = 500000; // Where OBCPs have left the grating
    int gratTo = 535000; // Grating park position
    bool verbose = false;
}{
    // Park the grating
    SPEC_grat_move(gratFrom,gratTo,verbose);
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    // Sync the bus (function duration will get the "true" duration)
    data_rate(0.0);
    sync();
    // end of procedure
}

// File          : PACS_Spec_CRE_01pF0bias_Setup_Warm.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Configure CRE bias, reset interval and capacitor for 
//                 testing at room temperature
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
// Comments      : Intermediate version
//
// 
// Version       : 1.0
// History       : 1.0 / 16-Nov-2004 Initial version
//                 1.1    7-mar-2006 SPEC_HEAT_1_C renamed
// 1.2  6-apr-2006 DMC v6.0.1
// 1.3 16-oct-2006 As PACS_Spec_CRE_Setup_Warm but with 0.1pF and 0 v bias
//                 
procedure PACS_Spec_CRE_01pF0bias_Setup_Warm {
}{
    //                  
    // red_reset integer 64 Enter red reset interval
    // blue_reset integer 64 Enter blue reset interval
    // red_bias_d integer 287 Enter BIAS_D for red spectrometer (1V=4095)
    // red_bias_r integer 0 Enter BIAS_R for red spectrometer (1V=4095)
    // blue_bias_d integer 860 Enter BIAS_D for blue spectrometer (1V=4095)
    // blue_bias_r integer 0 Enter BIAS_R for blue spectrometer (1V=4095)
    // red_capacitor integer 8 Enter Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
    // blue_capacitor integer 8 Enter Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
    // heater_blue_1c integer 4095 Enter blue HEATER_1C value (0=0mA, 4095=0.2mA)
    // heater_blue_2c integer 0 Enter blue HEATER_2C value (0=0mA, 4095=0.2mA)
    int red_reset = 64;
    int blue_reset = 64;
    int red_bias_d = 0;
    int red_bias_r = 0;
    int blue_bias_d = 0;
    int blue_bias_r = 0;
    int red_capacitor = 0;
    int blue_capacitor = 0;
    int heater_blue_1c = 0;
    int heater_blue_2c = 0;
    // PC174420 "DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    //         Fixed GroupSize: 1, repetition: 8
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // cre_ctrl: 256=sync width=2, 128=T sensor on, 2=select, 1=power on
    int blue_cre_ctrl = blue_capacitor + 256 + 128 + 2 + 1;
    int[] list_int = [32,blue_reset,blue_cre_ctrl,blue_bias_r,blue_bias_d,0];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,blue_reset,blue_cre_ctrl,blue_bias_r,blue_bias_d,0,chksum);
    delay(1);
    // PC173420 "DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    //         Fixed GroupSize: 1, repetition: 8
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // cre_ctrl: 256=sync width=2, 128=T sensor on, 2=select, 1=power on
    // set red_cre_ctrl [expr $red_capacitor+256+128+2+1]
    // set spec_par_r [list {PP095420 32} \
    //         [list PP096420 $red_reset] \
    //         [list PP097420 $red_cre_ctrl] \
    //         [list PP098420 $red_bias_r] \
    //         [list PP099420 $red_bias_d] {PP100420 0}]
    // set chksum [getChkSum -d -32 $spec_par_r]
    // putlog "ChkSum for spec_par_r: $spec_par_r"
    int red_cre_ctrl = red_capacitor + 256 + 128 + 2 + 1;
    list_int = [32,red_reset,red_cre_ctrl,red_bias_r,red_bias_d,0];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,red_reset,red_cre_ctrl,red_bias_r,red_bias_d,0,chksum);
    delay(1);
    // PC094420 "DMC_SET_PAR_BOTH_SPEC" SEND COMPLETE PARAMETERS TABLE TO BOTH DECS
    // tcsend PC094420 
    // waittime 0.5
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    delay(1);
    // PC094420 "DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    //tcsend PC086420 
    //waittime 0.5
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // PC094420 "DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    //tcsend PC093420 
    //waittime 0.5
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    //  DMC_SET_B_SPE_HEAT_1C(0)
    // eval tcsend PC087420 [list [list PP073420 $heater_blue_1c]]
    // waittime 0.5
    Pacs_DMC_SET_B_SPEC_HEAT_C_RAW(heater_blue_1c);
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

// Missionphase  : FM ILT
//
// Purpose	 : Switch to chopper open-loop mode
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : This building block toggles between settings enabling
//                 and disabling the open-loop mode of chopper movements.
//                 Receiving signals:
//                   ON: switch on open-loop mode
//                   OFF: switch off open-loop mode
//                  
// Dependencies  :  
//
// Preconditions : PACS switched-on, chopper is switched on and disabled
//                 
// Comments	 : First try of a CUS BB
//
// Version	 : 1.0	
// 
// History 	 : 1.0 15-12-06 creation by MN
//                 1.1 14-feb-2008 DAC Added WriteEndBB
// Begin Mode description
block PACS_SPEC_Chopper_SetOpenLoop_BB PACS 431 {
    string onoff = "OFF" in ["ON","OFF"];
}{
    // Get BBID from environment and send to DMC
    WriteBBID($BBID);
    // IF-statement for switching on
    if(onoff == "ON") {
        Pacs_DMC_SET_CHOP_COIL_DRIVE(0x128);
    }
    // IF-statement for switching off
    if(onoff == "OFF") {
        Pacs_DMC_SET_CHOP_COIL_DRIVE(0x28);
    }
    // End of BB
    WriteEndBB();
}

// Missionphase  : 
//
// Purpose       : Prepare MEC for spectrometer, including filterwheel,
//                 chopper, grating and calibration sources 
//                  
// Script file   : SPEC_dmc_setup.cus
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : This script will switch on and set all required
//                 parameters for 
//                 - chopper
//                 - spectrometry filter wheel
//                 - grating,  and
//                 - calibration sources.
//                 This script should be executed just after the
//                 switch-on procedure and the bolometer setup
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version      1.0
// History      
// 0.1 16-nov-2006 DAC Based on spec_dmc_setup
// 0.5 02-mar-2007 TM update for FM
// 0.6 02-mar-2007 BV update chopper configuration to CSLopt3-600
// 0.7 30-mar-2007 TM filter wheel configuration moved to the end
// 0.8 30-mar-2007 TM update chopper configuration to "nom_sky"
// 1.0 05-dec-2008 VD chnge call for CONFGrat with ISTSafe
//
procedure SPEC_dmc_setup {
    string spec_fltw_id = "POS A" in ["POS A","POS B"]; // Photometer filter ID
    int chop_def_pos = 0; // Chopper default position
    double temp_CS1 = 48.0; //  Temperature 55K for the PACS calibration source 1 
    double temp_CS2 = 58.0; //  Temperature 60K for the PACS calibration source 2
}{
    //-------------------
    // CHOPPER
    // Configure diagnostics HK for chopper
    // Read out every 5 ms
    int diag_hk_period_cho = 5;
    // DMC_CHOP_CTRL_ST  209
    // DMC_CHOP_CUR_POS  244
    // DMC_CHOP_SETPOIN  245
    // DMC_CHOP_TARGET   246
    // DMC_CHOP_PID_ERR  247
    // DMC_CHOP_PID_ACC  248
    // DMC_CHOP_MAX_DIT  249
    // DMC_CHOP_OUTPUT   258
    // DMC_CHOPPER_TEMP  407
    // DMC_CHOP_VA       557
    // DMC_CHOP_IA       561
    // DMC_CHOP_VB       565
    {int}[] parlist_cho = [{209},{244},{245},{246},{247},{248},{249},{258},{407},{557},{561},{565},{0xffff}];
    int[] aux_cho = [209,244,245,246,247,248,249,258,407,557,561,565,0xffff];
    int check_sum_cho = checksum("int",aux_cho);
    int diag_hk_length_cho = 13;
    Pacs_DMC_WRT_DIAG_HK_LIST(diag_hk_length_cho,parlist_cho,check_sum_cho);
    Pacs_DMC_START_DIAG_HK(diag_hk_period_cho);
    // DMC_WRT_CHOP_CONF_PAR (now modified for 20 parameters)
    CONF_chopper("CONFChopper","nom_sky");
    CHOP_on_off("ON");
    Pacs_DMC_MOVE_CHOP_ABS(chop_def_pos);
    delay(1);
    //
    Pacs_DMC_STOP_DIAG_HK();
    //-------------------------
    // PACS CALIBRATION SOURCES
    CONF_cs("Both");
    CS_on_off("CS1","ON");
    CS_temp("CS1",temp_CS1);
    CS_on_off("CS2","ON");
    CS_temp("CS2",temp_CS2);
    // Grating
    // NOTE: The grating default position is set in CONF_grating
    int diag_hk_period_grat = 1;
    // Max number of requested diag HK parameters = 16
    // (including the last one, which is always forced to the same value)
    //
    //     DMC_GR_IND_SINE        539
    //     DMC_GR_IND_COS         540
    //     DMC_FWGRAT_HALLA       256
    //     DMC_FWGRAT_HALLB       257
    //     DMC_FW_GR_VMOTA        556
    //     DMC_FW_GR_VMOTB        564
    //     DMC_FW_GR_IMOTA        560
    //     DMC_FW_GR_IMOTB        567
    //     DMC_GRAT_CTRL_ST       208
    //     DMC_GRAT_CUR_POS       250
    //     DMC_GRAT_SETPOIN       251
    //     DMC_GRAT_TARGET        252
    //     DMC_GRAT_PID_ERR       253
    //     DMC_GRAT_OUTPUT        452
    //     DMC_GRAT_IND_READ      512
    {int}[] list_tuple = [{539},{540},{256},{257},{556},{564},{560},{567},{208},{250},{251},{252},{253},{452},{512},{0xffff}];
    int[] list_int = [539,540,256,257,556,564,560,567,208,250,251,252,253,452,512,0xffff];
    int chksum = checksum("int",list_int);
    int nbParams = length(list_int);
    Pacs_DMC_WRT_DIAG_HK_LIST(nbParams,list_tuple,chksum);
    delay(1);
    Pacs_DMC_START_DIAG_HK(diag_hk_period_grat);
    CONF_grating("CONFGrat","ISTSafe");
    // Stop HK
    Pacs_DMC_STOP_DIAG_HK();
    //-------------------
    // FILTERWHEEL
    // Configure diagnostics HK for filterwheel
    // Read out every 5 ms
    int diag_hk_period_fw = 5;
    // DMC_WRT_DIAG_HK_LIST
    // DMC_FW_SPEC_CTRL  210
    // DMC_FWGRAT_HALLA  256
    // DMC_FWGRAT_HALLB  257
    // DMC_FWSP_CUR_POS  255                    
    // DMC_FPU_T_SEN_ST  404
    // DMC_FW_SPEC_TEMP  405                    
    // DMC_FW_GR_VMOTA   556
    // DMC_FW_GR_IMOTA   560
    // DMC_FWSPEC_POS_A  555
    // DMC_FW_GR_VMOTB   564
    // DMC_FW_GR_IMOTB   567
    // DMC_FWSPEC_POS_B  559
    {int}[] parlist_fw = [{210},{256},{257},{255},{404},{405},{556},{560},{555},{564},{567},{559},{0xffff}];
    int[] aux_fw = [210,256,257,255,404,405,556,560,555,564,567,559,0xffff];
    int check_sum_fw = checksum("int",aux_fw);
    int diag_hk_length_fw = 13;
    Pacs_DMC_WRT_DIAG_HK_LIST(diag_hk_length_fw,parlist_fw,check_sum_fw);
    Pacs_DMC_START_DIAG_HK(diag_hk_period_fw);
    // CONFigure controller
    CONF_spec_fltw();
    // and move
    SPEC_fltw_move(spec_fltw_id);
    // Move to demanded position
    Pacs_DMC_STOP_DIAG_HK();
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Home Grat
//
// CUS author    : Pierre Royer
//
// Version       : 2.0
//
// History       : 1.0 29-Jul-2007
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_Gra_IST_Home {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Home                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_Home                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_IST_Home()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_IST_Home();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       : Perform Setup Spectroscopy
//
// CUS author    : TM
// Script file   : SPEC_setup_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform PACS setup for spectroscopy
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// 
// History       : 0.1 TM 10-nov-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//                 0.2 17-nov-2005 blue_heater_curr as input argument
//                 0.3 18-dec-2006 Temporary change for blue<>red
//                 0.4 19-feb-2007 Back to nominal blue<>red
//                 0.5 03-Mar-07 Changed defaults for CSs to 48/58 Ohms
//                 0.6 21-Jun-07 adapted heater current
//		   1.0 04-mar-2008 translated into PV script
//
obs PacsEng_Spec_setup {
    /* Needed variables to call PacsEng_Spec_setup                        */
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double temp_CS1 = 48.0;
    double temp_CS2 = 58.0;
    double blu_heater_curr = 0.78; // Heater current [mA]
    /* End of needed variables for PacsEng_Spec_setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_setup(fltPOS,temp_CS1,temp_CS2,blu_heater_curr)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_setup(fltPOS,temp_CS1,temp_CS2,blu_heater_curr);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Spec_Gra_DEG_MODE_Diaghk_Setup.cus
// Missionphase  : FM ILT
//
// Purpose       : Switch on diagnostic hk relevant to grating in DEG MODE
//
// Author        : P. Royer
//
// Arguments     :
//
// Description   : Grating diagnostic housekeeping ON (DEG MODE)
//               :
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 07-Jul-2006 creation
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose Switch on diagnostic housekeeping relevant to grating
// @comment - 
// ------------------------------
block PACS_Spec_Gra_DEG_MODE_Diaghk_Setup PACS 172 {
    int diag_hk_period = 5; // 5 msec diag hk period 
}{
    // Register start of BB
    WriteBBID($BBID);
    // DMC_WRT_DIAG_HK_LIST
    // DMC_DATA_LENGTH            PP065420 contains the number of desired HK parameters
    // DMC_4_BYTES_WORDS_DATA     PP067420 contains the desired HK parameters' IDs
    // DMC_CHECKSUM               PP066420
    //
    // Max number of requested diag HK parameters = 16
    // (including the last one, which is always forced to the same value)
    //
    //     DMC_GR_IND_SINE        539
    //     DMC_GR_IND_COS         540
    //     DMC_FWGRAT_HALLA       256
    //     DMC_FWGRAT_HALLB       257
    //     DMC_FW_GR_VMOTA        556
    //     DMC_FW_GR_VMOTB        564
    //     DMC_FW_GR_IMOTA        560
    //     DMC_FW_GR_IMOTB        567
    //     DMC_GRAT_CTRL_ST       208
    //     DMC_GRAT_CUR_POS       250
    //     DMC_GRAT_SETPOIN       251
    //     DMC_GRAT_TARGET        252
    //     DMC_GRAT_PID_ERR       253
    //     DMC_GRAT_OUTPUT        452
    //     DMC_GRAT_DEG_POS       515
    {int}[] list_tuple = [{539},{540},{256},{257},{556},{564},{560},{567},{208},{250},{251},{252},{253},{452},{515},{0xffff}];
    int[] list_int = [539,540,256,257,556,564,560,567,208,250,251,252,253,452,515,0xffff];
    int chksum = checksum("int",list_int);
    int nbParams = length(list_int);
    Pacs_DMC_WRT_DIAG_HK_LIST(nbParams,list_tuple,chksum);
    delay(1);
    // DMC_START_DIAG_HK
    // DIAG_HK_PERIOD             PP076420
    // tcsend PC146420 [list PP076420 $diag_hk_period]
    // waittime $command_time
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    // End of procedure
    //------------------
    // Mark End of Block
    WriteEndBB();
}

// Missionphase  : FMIST
//
// Purpose       : Disable Grat
//
// Author        : PR
// Arguments     : 
//
// Version       : 1.0 
// History       : 1.0 29-Jul-2007 PR
//
procedure PACS_Spec_Gra_IST_Disable {
}{
    Pacs_DMC_DISABLE_GRAT_CONT();
    delay(1);
}

// Missionphase  :  FM-ILT
//
// Purpose       : Perform Thermal behaviour photometry test
//                 Check before executing:
//                 o  TEMP_EV still below 0.3 K?
//                    (cooler recycling has to be finished)
//                 o  detector groups off
//                 o  CSs have to off and cold
//                 o  chopper and filter wheel controller off
//                 o  Check that the temperature sensors are on
//
//                 Duration: 53 min
//
// CUS author    : TM
// Script file   : PHOT_thermal_OBS.cus
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 0.8 
// History       : 0.1 creation by XXX
//                 0.2. DAC&PR Added PHOT_change_data_mode 
//                 0.3 09-nov-2006 TM: updated for FM-ILT
//                 0.4 10-nov-2006 TM: new bias table, low gain
//                 0.5 10-nov-2006 DAC New CONF_xxx scripts    
//                 0.6 14-nov-2006 TM: update of the bias setting
//                 0.7 05-mar-2007 TM: diagHk for OBCP, new CONF_chopper
//                 0.8 07-apr-2007 TM: new CONF_chopper
//                 0.9 15-jun-2007 TM: new configuration of fltw: PHOT_fltw_conf -> CONF_phot_fltw
//
procedure PHOT_thermal {
}{
    // initial wait
    delay(60);
    // preparation for PHOT
    PHOT_dpu_dmc_setup("BOTH Array",4);
    delay(60);
    //   switch on bolometer groups and autonomy function
    PHOT_switchon_groups();
    delay(300);
    //   set safe polarisations
    PHOT_set_bias_volt("BOLObias_preILT_standard_low",1);
    PHOT_set_bias_volt("BOLObias_preILT_standard_low",2);
    PHOT_set_bias_volt("BOLObias_preILT_standard_low",3);
    PHOT_set_bias_volt("BOLObias_preILT_standard_low",4);
    PHOT_set_bias_volt("BOLObias_preILT_standard_low",5);
    PHOT_set_bias_volt("BOLObias_preILT_standard_low",6);
    delay(300);
    // sequencer configuration
    PHOT_seq_setup();
    delay(300);
    // change data mode to Bolo & HK
    PHOT_change_data_mode("Bolo_HK");
    delay(60);
    // change sequence mode to Sb-Sref
    PHOT_change_seq_mode("Sb_Sref");
    delay(60);
    // Set gain LOW
    PHOT_set_gain("LOW");
    delay(60);
    //   configure diagHK and start
    //  configure diag HK for filterwheel, grating, chopper
    int diag_hk_period = 5;
    //     DMC_CHOP_CUR_POS       244
    //     DMC_CHOP_SETPOINT      245
    //     DMC_CHOP_TARGET        246
    //     DMC_FWGRAT_HALL_A      256
    //     DMC_FWGRAT_HALL_B      257
    //     DMC_CHOP_OUTPUT        258
    //     DMC_FWPH_CUR_POS       260
    //     DMC_CHOP_IA            561
    //     DMC_FW_FWPHOT_POS_A    563
    //     DMC_FW_FWPHOT_POS_B    569
    {int}[] list_tuple = [{244},{245},{246},{256},{257},{258},{260},{561},{563},{569},{0xffff}];
    int[] list_int = [244,245,246,256,257,258,260,561,563,569,0xffff];
    int chksum = checksum("int",list_int);
    int nbParams = length(list_int);
    Pacs_DMC_WRT_DIAG_HK_LIST(nbParams,list_tuple,chksum);
    delay(1);
    // DMC_START_DIAG_HK
    // DIAG_HK_PERIOD             PP076420
    // tcsend PC146420 [list PP076420 $diag_hk_period]
    // waittime $command_time
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    delay(1);
    //   configure and switch on chopper
    CONF_chopper("CONFChopper","nom_sky");
    CHOP_on_off("ON");
    delay(60);
    // Perform OBCP_chopped_photometry  for 3 min (high frequency, large amplitude)
    OBCP_chopped_photometry(1,-12000,3,12000,12000,450,0,-5000,+5000,0,0,0);
    delay(60);
    //  configure filter wheel
    CONF_phot_fltw();
    //PHOT_fltw_conf();
    delay(60);
    //  move 6 times to both positions
    for(int imove = 1 .. 6) {
        PHOT_fltw_move("POS A");
        PHOT_fltw_move("POS B");
    }
    delay(60);
    // stop diag HK again
    Pacs_DMC_STOP_DIAG_HK();
    //   configuration of calibration sources and switch on
    CONF_cs("Both");
    CS_on_off("CS1","ON");
    CS_on_off("CS2","ON");
    delay(60);
    //  CS1 to 48.0 (55K) and CS2 to 58.0 (60K)
    CS_temp("CS1",48.0);
    CS_temp("CS2",58.0);
    delay(2700);
    //   Switch off the CSs
    CS_on_off("CS1","OFF");
    CS_on_off("CS2","OFF");
    delay(300);
    //   Switch off chopper and grating controller
    CHOP_on_off("OFF");
    delay(120);
    //
    // Reset the biases, disable the AF and switch off the groups
    PHOT_switchoff_groups();
    delay(300);
    //  
    PHOT_dpu_dmc_reset();
    delay(60);
    // SAFE mode
    OBCP_SAFE();
    //End of procedure
}

// File          : PACS_Chopper_EnDis_Test_NoConf_ast1.cus
// Missionphase  : SVT / flight 
//
// Purpose       : Switch-on/switch-off and enanle/disable test of chopper
//
// Author        : MN/HD
// CUSification  : MN/HD
// Arguments     :
//
// Description   : Flight procedure to verify the stability of the chopper.
//                      Produces diagnostic housekeeping data, enables the
//                      chopper for 1 second, and disables again.
//
// Comments      : Copied from PACS_Chopper_EnDis_Test_ast1_OBS
//                         without the configuration and with MOIS comments
//
// Version       : 1.0
// History       : 1.0 17-Oct-2007 BV initial version
//		  
//
procedure PACS_Chopper_EnDis_Test_NoConf_ast1 {
}{
    mois_comment("Start of procedure: verify the stability of the PACS chopper during 1 sec");
    //  Time 1 sec
    int n = 1;
    mois_step("Enable diagnostic housekeeping");
    // Set diagnostic HK (1 kHz, 4 parameters)
    PACS_Chopper_EnDis_Test_dhk("ON");
    delay(10);
    //
    mois_step("Switch on and enable chopper for 1 second");
    // Switch on and enable chopper for n seconds, while n is given by the user
    PACS_Chopper_SWON_SWOF_only("ON");
    delay(10);
    EnDis_chopper("ON");
    delay(n);
    EnDis_chopper("OFF");
    delay(10);
    PACS_Chopper_SWON_SWOF_only("OFF");
    delay(10);
    mois_step("Stop diagnostic housekeeping");
    // Stop diagnostic HK
    PACS_Chopper_EnDis_Test_dhk("OFF");
}

// Missionphase  : FMIST
//
// Purpose       : Move Grat Abs
//
// Author        : PR
// Arguments     : 
//
// Version       : 1.0 
// History       : 1.0 29-Jul-2007 PR
//
procedure PACS_Spec_Gra_IST_Move_Abs {
}{
    // NEW TARGET POSITION
    int gratNEW = 500000;
    int delayTime = 10;
    // Move
    Pacs_DMC_MOVE_GRAT_ABS_RAW(gratNEW);
    delay(delayTime);
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Missionphase  : PACS FMILT
//
// Purpose       : Configure the spec filter wheel Redundant Cold
//
// Author        : PR
//
// Arguments     : 
//
// Description   : 
//                 
// Comments      :      
//
// History       : 1.0  04-Jul-2007 Initial version
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//
obs PacsEng_CONF_spec_fltw_R {
    /* No variables to call PacsEng_CONF_spec_fltw_R                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POSB" */
    /* End of needed variables for PacsEng_CONF_spec_fltw_R                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_spec_fltw_R()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_spec_fltw_R();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : FMILT 
//
// Purpose       : Enable/disable the chopper electronics
// Author CUS    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
//
// Input arguments
// Type  Name      Description
// string onoff    ON: Enable chopper, OFF: Disable
// Description   : Enable/disable electronics, controller 
//
// Dependencies  : 
// Comments      : 
// Version       : 0.1 10-nov-2006 First creation
// History       : 
//               :
procedure EnDis_chopper {
    string onoff = "ON" in ["ON","OFF"];
}{
    if(onoff == "ON") {
        //Pacs_DMC_SWON_CHOP_CONT();
        Pacs_DMC_ENABLE_CHOP_CONT();
        //      debug_print("Chopper was enabled");
    }
    // Disable
    if(onoff == "OFF") {
        Pacs_DMC_DISABLE_CHOP_CONT();
        //Pacs_DMC_SWOF_CHOP_CONT();
        //      debug_print("Chopper was disabled");
    }
}

// Missionphase  :
//
// Purpose       : Read detector selection data from a CAL-U file and send
//                 the required TCs to load the chosen Selection Table
//
// Author        : Diego A. Cesarsky
// CUS script    : Diego A. Cesarsky
// CUS file      : PACS_Det_Sel.txt
//
// Arguments     :
// string  calTableName    The DetSel cal table name
//
// Description   : Read a PACS DetSel table and uplink the relevant information.
//                 CAL tables are named PACSDetSel_nnn, where nnn is the
//                 selection table identification. The table is setup as 14
//                 rows of 24 columns each. Each ROW contains information for
//                 a DXSn telecommand; there are Short and Long SPU rows (SPUS and SPUL)
//                 as well. CUS access a Table by ROW name and, within a
//                 ROW by COLumn name. Hence it is important that the table
//                 conforms to the naming convention used here. Consecutive
//                 ROWs are named:
//                 BoloBlu1S (for Bolometer Blue, 1st quadrant, Short SPU)
//                 BoloBlu1L
//                 BoloBlu2S
//                 BoloBlu2L
//                 ---------
//                 BoloBlu4L
//                 BoloRed1S
//                 BoloRed1L
//                 SpecBlu1S
//                 SpecBlu1L
//                 SpecRed1S
//                 SpecRed1L
//                 Columns are named from COL0 (the one containing the ROW
//                 name) to COL24
//
// Dependencies  :
//
// Preconditions :
//
// Comments      :
//
// Version       : 0.2
// History       : 0.1 21-Jan-2004 Creation by DAC
//                 0.2 14-nov-2006 Removed duration logic
//               :
procedure PACS_Det_Sel {
    string calUTable = "PACSDetSel_100"; // U-CAL table name (PACSDet_Sel_nnn)
}{
    // Useful variables 
    // Array of ROW names 
    string[] rowName = ["BoloBlu1S","BoloBlu1L","BoloBlu2S","BoloBlu2L","BoloBlu3S","BoloBlu3L","BoloBlu4S","BoloBlu4L","BoloRed1S","BoloRed1L","SpecBlu1S","SpecBlu1L","SpecRed1S","SpecRed1L"];
    // COLumn names
    string col = "COL1";
    // Contents of each ROW will be copied to int array detSel; create it:
    int[] detSel = [0];
    // Parameters for actual TCs are to be cast as {int} [] arrays.
    {int}[] params = [{0}];
    // DetSel will be indexed by
    int index = 0;
    // Auxiliary integer
    int aux = 0;
    // Checksum
    int check_sum = 0;
    // Use lookup function to read all 24 COLs from each of the 14 ROWs in 
    // calUTable
    // Read each one of the 14 ROWs
    for(int row = 0 .. 13) {
        //   Build ROW name
        string rowRead = rowName[row];
        //   Now read each of the 24 COLs from the current ROW
        for(int column = 1 .. 24) {
            col = "COL" + column;
            aux = ilookup(calUTable,rowRead,col);
            //       Fill array detSel
            detSel[column - 1] = aux;
            //       Also fill TC param array
            params[column - 1] = {aux};
            //    end COL 1-24 loop
        }
        debug_print("Read ROW " + rowRead + "; ID: " + detSel[1]);
        //   Compute the check sum
        check_sum = checksum("int",detSel);
        // Send the TC. This part of the script is not nice: get the proper
        // Pacs telecommand according to ROW)
        if(rowRead == "BoloBlu1S") {
            Pacs_SPUS_WRT_DXS1(params,check_sum);
        }
        if(rowRead == "BoloBlu1L") {
            Pacs_SPUL_WRT_DXS1(params,check_sum);
        }
        if(rowRead == "BoloBlu2S") {
            Pacs_SPUS_WRT_DXS2(params,check_sum);
        }
        if(rowRead == "BoloBlu2L") {
            Pacs_SPUL_WRT_DXS2(params,check_sum);
        }
        if(rowRead == "BoloBlu3S") {
            Pacs_SPUS_WRT_DXS3(params,check_sum);
        }
        if(rowRead == "BoloBlu3L") {
            Pacs_SPUL_WRT_DXS3(params,check_sum);
        }
        if(rowRead == "BoloBlu4S") {
            Pacs_SPUS_WRT_DXS4(params,check_sum);
        }
        if(rowRead == "BoloBlu4L") {
            Pacs_SPUL_WRT_DXS4(params,check_sum);
        }
        if(rowRead == "BoloRed1S") {
            Pacs_SPUS_WRT_DXS5(params,check_sum);
        }
        if(rowRead == "BoloRed1L") {
            Pacs_SPUL_WRT_DXS5(params,check_sum);
        }
        if(rowRead == "SpecBlu1S") {
            Pacs_SPUS_WRT_DXS6(params,check_sum);
        }
        if(rowRead == "SpecBlu1L") {
            Pacs_SPUL_WRT_DXS6(params,check_sum);
        }
        if(rowRead == "SpecRed1S") {
            Pacs_SPUS_WRT_DXS7(params,check_sum);
        }
        if(rowRead == "SpecRed1L") {
            Pacs_SPUL_WRT_DXS7(params,check_sum);
        }
    }
}

// $Id: 
// Purpose        : Obs to run the OBCP 32 updates
//                 
//
// CUS author     : VD + HF
//
// Input arguments: see after module identification
//
// Return values: none
// N/A
//
// Comments      : only run it once
//
// History: 1.0 created
//
//
obs PacsEng_PacsDPUOBCP32Update {
    /* no need for inputs this Eng will only be done once!! */
}{
    int t_DPU_update = duration(PacsDPUOBCP32Update());
    // Add needed time to set/unset OBSID
    int tset = duration(WriteOBSID($OBSID));
    int tunset = duration(WriteEndID());
    int tp = t_DPU_update;
    // Issue PointReq
    int[] ts = no_pointing(true,tset,tunset,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            WriteOBSID($OBSID);
        }
        if(state[0] == 3) {
            PacsDPUOBCP32Update();
        }
        if(state[0] == 5) {
            WriteEndID();
        }
    }
}

// CVS comments  : $Id: OBCP_chopped_photometry_dither.txt,v 1.4 2007/08/22 10:18:28 dcesarsk Exp $ 
// Missionphase  : PACS AVM ILT Orbit-Operations
//
// Purpose       : OnBoardControlProcedure to perform
//                 chopped photometry
//
// OBCP author   : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : OBCP_chopped_photometry_dither.txt  
//
// Arguments: 
// Type  Name                 Description
// int   nb_SRC_REF           p01 Number of observations in OBS loop
// int   chop_pos_SRC         p02 Chopper position for SRC
// int   nb_rdouts_plateau    p03 Number of readouts per chopper position 
// int   chop_pos_REF1        p04 Chopper position for BKG1
// int   chop_pos_REF2        p05 Chopper position for BKG2 (may be equal to BKG1) 
// int   nb_cycles_obs_cal    p06 Number of obs/cal cycles
// int   nb_CS1_CS2           p07 Number of observations in CAL loop
// int   chop_pos_CS1         p08 Chopper position for CS1
// int   chop_pos_CS2         p09 Ditto for CS2 
// int   comp_mode_blu        Compression mode BLUE
// int   comp_mode_red        Ditto RED 
// int   chop_def             Chopper default position
// int   max_dither           Maximum dither amplitude
//
// Description   : This script mimics the OBCP_CHOPPED_PHOTOMETRY
//                 pseudo script, section 3.1.2 in PACS-ME-LI-005
//                 This CUS version computes the duration of the
//                 observation, as specified by the input parameters.
//                 It will also send the trigger TC to start the OBCP
//
// Dependencies  : DMC_phot_2_3_chop_dither
//                 WriteBBID   
// Comments      : Based on OBCP_chopped_photometry
//
// Version       : 0.1  2-Nov-2005 Creation by DAC
// History       : 0.2 21-aug-2007 SRC-3507 Indicate end of BB
//
int[] block OBCP_chopped_photometry_dither PACS 5 {
    int nb_SRC_REF = 1; // p01 Number of observations in OBS loop
    int chop_pos_SRC = 0; // p02 Chopper position for SRCE
    int nb_rdouts_plateau = 8; // p03 Number of readouts per chopper position 
    int chop_pos_REF1 = -2000; // p04 Chopper position for BKG1
    int chop_pos_REF2 = 2000; // p05 Chopper position for BB2
    int nb_cycles_obs_cal = 1; // p06 Number of obs/cal cycles
    int nb_CS1_CS2 = 0; // p07 Number of observations in CAL loop
    int chop_pos_CS1 = -22680; // p08 Chopper position for CS1
    int chop_pos_CS2 = 22680; // p09 Chopper position for CS2
    int comp_mode_blu = 0; // Compression mode BLUE channel
    int comp_mode_red = 0; // Compression mode RED channel
    int chop_def = 0; // Chopper default position
    int max_dither = 5; // Maximum dither amplitude
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain system parameter from PACSparams
    // BOL readout frequency [Hz] and readout period [msec]
    double bol_freq = dlookup("PACSparams","bolo_sample","freq_time");
    //  string bol_unit = slookup("PACSparams","bolo_sample","unit");
    double bol_period = 1000.0 / bol_freq;
    //  debug_print("Bolo sample: " + bol_freq + " " + bol_unit);
    //  debug_print("Bolo period: " + bol_period + "[msec]");
    // Obtain duration of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duration of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duration of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duration_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duration_msec [msec] as it goes)
    // Begin 
    // DEC_WRITE_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    // Here and elsewhere it is assumed that OBCP "internal" TCs take t_cmd
    // [msec] to be executed
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // SET_TIME 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DEC_WRITE_MAX_DITHER(max_dither)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DEC_WRITE_SEQ_BUF(ID, LENGTH, DATA, CHECKSUM)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Invoke CUS version of DECMEC sequence above (DMC_PHOT_2_3_CHOP)
    // (only to compute duration!! Hence use only duration related parameters
    // in the call).
    // NOTE: use DMC_phot_2_3_chop since its duration is identical to the
    //       dither version (except for internal CHOP_DITHER)
    // The DMC is number seq_DMC=2 and lasts seq_time [msec]
    // Duration "duree1" is an array with five elements
    int[] duree1 = DMC_phot_2_3_chop(nb_SRC_REF,nb_rdouts_plateau,nb_cycles_obs_cal,nb_CS1_CS2);
    // Convert duration [readouts] into [msec]; add dmc_margin
    int seq_time = ifloor(double(duree1[0]) * bol_period) + dmc_margin;
    // Convert other times as well into msec
    duree_SRC = ifloor(double(duree1[1]) * bol_period);
    duree_REF = ifloor(double(duree1[2]) * bol_period);
    duree_CAL = ifloor(double(duree1[3]) * bol_period);
    duree_OVR = duree_OVR + ifloor(double(duree1[4]) * bol_period) + dmc_margin;
    // Tally into accumulated duration of OBCP   			 
    duration_msec = duration_msec + seq_time;
    // SYNCHRONIZE_ON_DETECTOR(3) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DEC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par, CHHKSUM) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // START_SEQUENCE duration_msec(seq_time)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(seq_time)
    // Check execution status of the sequence and in case of failure stop OBCP
    // and issue TM(1,8) + event 
    // MOVE_CHOP_ABSOLUTE(chop_def) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Issue TM(1,7) 
    // Now trigger execution of OBCP
    // This OBCP is number 5, requires 15 parameters and lasts seq_time [msec]
    string obcp_ID = "CHOP_PHOT_DITHER";
    int obcp_par_nber = 15;
    int seq_DMC = 2;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_SRC_REF},{4,chop_pos_SRC},{5,nb_rdouts_plateau},{6,chop_pos_REF1},{7,chop_pos_REF2},{8,nb_cycles_obs_cal},{9,nb_CS1_CS2},{10,chop_pos_CS1},{11,chop_pos_CS2},{12,comp_mode_blu},{13,comp_mode_red},{14,chop_def},{15,max_dither}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nber,grp);
    // Add the "communication jitter"
    duration_msec = duration_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Return total duration [sec] to calling program
    // Create return time array; convert into [sec]
    int[] time_array = [duration_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // Set delay()
    delay(time_array[0]);
    // Mark end of BB
    WriteEndBB();
    // Ending time
    //  int time_elapsed = time() - time_start;
    //  time_array[0] = time_elapsed;
    // Return

    return time_array;
}

command PacsCcuMonitorPeriodDefault HFKACQP1 {
} {
    bus_schedule(SC, 6);
}

// Script file   : Pacs_EDAC_to_DMC_HK
// Missionphase  : RP
//
// Purpose       : The purpose of the observation is to transfer the 
//                 addresses of the last 10 occurences of EDAC single failures
//                 into the DMC configurable housekeeping.
//
// CUS author    : VD & HF
//
//
// Description   : The script extracts the addresses of the last 10 EDAC 
//                 failures to the DMC HK
//                 The Ninc allows to shift down the addresses location
//                  
// Dependencies  : 
//
// Preconditions :
//     
// Comments      : 
// 
// History       : 0.1 09-Nov-2010 created (used extract from SPEC_dpu_dmc_setup)  
//               : 0.2 10-Nov-2010 added PACS-3137 and memory address to be mapped
// 
block Pacs_EDAC_to_DMC_HK PACS 1111 {
    int addMem = 0x0; // memory address in HEX
    int incN = 0;
}{
    Pacs_DMC_SET_BBID($BBID);
    // Custom Hk Configuration Table : This buffer contains configuration data
    // allowing us to increase the number of available HK measure without 
    // recompiling the application. The table is composed of 10 entries each of 
    // them being 5 words long :
    //1. the address of the memory area to monitor
    int[] f1 = [0x0];
    //2. the size (in words) of the memory area to monitor
    int f2 = 0x1;
    //3. the size (in bytes) of the memory area to monitor
    int f3 = 0x4;
    //4. a pointer to a function performing the monitoring (if you want to use this
    //   field, it is highly probable that you need to patch your code anyway to 
    //   upload the new monitoring function).
    int f4 = 0x0;
    //5. the validity at startup (0 = invalid, 1 = valid)
    int f5 = 0x1;
    for(int loopN = 0 .. 9) {
        f1[loopN] = addMem + (incN + loopN);
    }
    // All the fields are initialized to zero at startup. (for advanced users only)
    {int}[] params = [{f1[0]},{f2},{f3},{f4},{f5},{f1[1]},{f2},{f3},{f4},{f5},{f1[2]},{f2},{f3},{f4},{f5},{f1[3]},{f2},{f3},{f4},{f5},{f1[4]},{f2},{f3},{f4},{f5},{f1[5]},{f2},{f3},{f4},{f5},{f1[6]},{f2},{f3},{f4},{f5},{f1[7]},{f2},{f3},{f4},{f5},{f1[8]},{f2},{f3},{f4},{f5},{f1[9]},{f2},{f3},{f4},{f5}];
    int[] forsum = [f1[0],f2,f3,f4,f5,f1[1],f2,f3,f4,f5,f1[2],f2,f3,f4,f5,f1[3],f2,f3,f4,f5,f1[4],f2,f3,f4,f5,f1[5],f2,f3,f4,f5,f1[6],f2,f3,f4,f5,f1[7],f2,f3,f4,f5,f1[8],f2,f3,f4,f5,f1[9],f2,f3,f4,f5];
    int check_sum = checksum("int",forsum);
    int wrdLen = 50;
    Pacs_DMC_WRT_DIAGHK_CONF_TAB(wrdLen,params,check_sum);
    delay(2);
    // bus sync
    Pacs_DMC_SET_BBID(0x40000000);
    sync();
}

// CVS comments  : $Id: PacsSpecSlewCal.txt,v 1.5 2008/05/28 09:27:05 vanessad Exp $ 
// Purpose       : Invoke a PACS calibration OBCP during slew to source;
//                 leave PACS ready to start observations once in source
//
// CUS author    : DAC
// Script file   : PacsSpecSlewCal.txt 
//
// Input arguments
// Type                     Name          Description
// bool                     verbose       Debug_print or not 
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECblu   BLUE SPU parameters
// {int,int,int,int,
//  int,int,int,int,int} [] confSPECred   RED  SPU parameters
// {int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int,
//  int,int,int,int,int}[]  confOBCP      OBCP parameters
//  bool                    doPROLOG      Perform/don't AOT prologue
//  double []               keyWAVE       One or several key wavelengths
//  int                     filter        Where to move FltW (as order)
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per key line
//
// Description   : Perform AOT prologue and then OBCP #13.
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// History       : 0.1 DAC 10-may-2006 New version losely based on old 
//                     PacsSpecSlewCal. Implies recasting OBCP13params as 
//                     other OBCP CAL-U files
// 0.2 30-may-2006 Adapted to SPEC_get_grat_info modified for freq switch
// 0.3  1-jun-2006 ORDER 2 and 3 are nolonger simultaneously allowed
//                 Use grating strategy as in OBCP22 and 27: grating remains
//                 where DMC left it (grat_def_time = 0)
// 1.0 15-feb-2007 SlewCal is supposed to leave the grating ready to start
//                 observing the 1st "science" line
//     16-feb-2007 Error in call to OBCP: grating should remain at 
//                 new_grat_def_pos (was grat_park) 
// 1.1 14-mar-2007 Add extraConf in call to SPEC_get_grat_info  
// 1.2  8-may-2007 Add orderSel needd by SPEC_get_grat_info
// 1.3 10-oct-2007 SCR3632. SPEC_get_grat_info is called with KHI
// 1.4 16-Jul-2008 Add dubugging prints (confSPEC)
//
int[][] procedure PacsSpecSlewCal_DataRates {
    /* verbose debug print                          */
    bool verbose = false;
    /* SPEC parameters for BLU and RED              */
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,64,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,64,0,0,0,0,0,0,0}];
    /* OBCP parameters                               */
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    /* Perform/don't AOT prologue                    */
    bool doPROLOG = true;
    /* One or several key wavelengths                */
    double[] keyWAVE = [62.5];
    /* Where to leave FltW (as order)                */
    int filter = 2;
    /* Where to leave grating at end of CAL          */
    int frstLstGratPos = 535000;
    /* User defined grating order                    */
    string orderSel = "order2";
}{
    // Array to collect OBCP times per line
    // NOTE: time variables in units of either number of ramps (SPEC) or
    // number of readouts (BOLO) or plain seconds. The calling program 
    // must convert, if applicable, this information into actual duration 
    // in true time units [seconds].
    // SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky), CAL source, 
    // and overheads (wait for something). Total duration is given by duree_num. 
    // If no error, this duration must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    int[][] dureeCalKey = [[0,0,0,0,0]];
    // Long sequence to "unpack" default values from tuples
    int capa_blu = confSPECblu[0]{0};
    int nb_rdouts_ramp_blu = confSPECblu[0]{1};
    int nb_rdouts_subramp_blu = confSPECblu[0]{2};
    int comp_mode_blu = confSPECblu[0]{3};
    int glitch_det_blu = confSPECblu[0]{4};
    int ramp_fit_alg_blu = confSPECblu[0]{5};
    int nb_raw_blu = confSPECblu[0]{6};
    int bias_r_blu_mV = confSPECblu[0]{7};
    int bias_d_blu_mV = confSPECblu[0]{8};
    int capa_red = confSPECred[0]{0};
    int nb_rdouts_ramp_red = confSPECred[0]{1};
    int nb_rdouts_subramp_red = confSPECred[0]{2};
    int comp_mode_red = confSPECred[0]{3};
    int glitch_det_red = confSPECred[0]{4};
    int ramp_fit_alg_red = confSPECred[0]{5};
    int nb_raw_red = confSPECred[0]{6};
    int bias_r_red_mV = confSPECred[0]{7};
    int bias_d_red_mV = confSPECred[0]{8};
    int nb_up_down = confOBCP[0]{0};
    int grat_step_up = confOBCP[0]{1};
    int grat_step_dn = confOBCP[0]{2};
    int nb_SRC_OFF = confOBCP[0]{3};
    int nb_ramps_plateau = confOBCP[0]{4};
    int nb_CS1_CS2 = confOBCP[0]{5};
    int nb_grat_step_up = confOBCP[0]{6};
    int nb_grat_step_dn = confOBCP[0]{7};
    //  int grat_start_pos        = confOBCP[0]{ 8};
    //  int grat_start_time       = confOBCP[0]{ 9};
    //  int grat_def_pos          = confOBCP[0]{10};
    //  int grat_def_time         = confOBCP[0]{11};
    int chop_pos_SRC = confOBCP[0]{12};
    int chop_pos_REF1 = confOBCP[0]{13};
    int chop_pos_REF2 = confOBCP[0]{14};
    int chop_pos_CS1 = confOBCP[0]{15};
    int chop_pos_CS2 = confOBCP[0]{16};
    int chop_def = confOBCP[0]{17};
    int detector = confOBCP[0]{18};
    int filterPOS = confOBCP[0]{19};
    // Bias voltages (needed by SPEC_aot_prologue) are commanded in (double) volts
    double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
    double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
    double bias_r_red = double(bias_r_red_mV) / 1000.0;
    double bias_d_red = double(bias_d_red_mV) / 1000.0;
    if(verbose) {
        debug_print("confSPEC: capa_blu" + capa_blu);
        debug_print("confSPEC: nb_rdouts_ramp_blu" + nb_rdouts_ramp_blu);
        debug_print("confSPEC: nb_rdouts_subramp_blu" + nb_rdouts_subramp_blu);
        debug_print("confSPEC: comp_mode_blu" + comp_mode_blu);
        debug_print("confSPEC: glitch_det_blu" + glitch_det_blu);
        debug_print("confSPEC: ramp_fit_alg_blu" + ramp_fit_alg_blu);
        debug_print("confSPEC: nb_raw_blu" + nb_raw_blu);
        debug_print("confSPEC: bias_r_blu_mV" + bias_r_blu_mV);
        debug_print("confSPEC: bias_d_blu_mV" + bias_d_blu_mV);
    }
    // Issue SPEC_aot_prologue if demanded
    if(doPROLOG) {
        totalDUREE = SPEC_aot_prologue_DataRates(nb_rdouts_ramp_red,nb_rdouts_ramp_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,comp_mode_blu,comp_mode_red,nb_rdouts_subramp_blu,nb_rdouts_subramp_red,nb_raw_blu,nb_raw_red,glitch_det_red,ramp_fit_alg_red,filter,verbose);
    }
    // NOTE: Grating starts at grat_start_pos determined by SPEC_get_grat. At end of
    // SlewCal grating should park. Park position is generally grat_def_pos:
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // AOT_prologue is supposed to have left grating at park position
    int grat_def_pos = grat_park;
    // NOTE for version 1.0 and later. Upon execution of SpecSlew, grating is
    //      indeed where SPEC_orbit_prologue left it (the default park position);
    //      this fact remains unchanged. What is new is that SpecSlew will leave
    //      the grating not at the default park position but already at the
    //      position needed by the 1st line that will be observed. There are two
    //      advantages:
    //      1- the new logic in the OBCP incurs in less grating movements when
    //         the OBCP is repeated within a NOD or the next raster point, and
    //      2- the detector will see the illumination corresponding to the line
    //         wavelength before the actual observation starts.
    // Observe now each key wavelength
    int nbKEY = length(keyWAVE);
    {double,int,int,int,int}[] gratTuple = [{0.0,0,0,0,0}];
    for(int loopKEY = 0 .. nbKEY - 1) {
        //     We may perform the loop starting with high ORDER
        int keyWaveLoop1 = nbKEY - 1 - loopKEY;
        // or not....
        keyWaveLoop1 = loopKEY;
        //       
        //     Get grating start position (CAL is performeed with HI resolution)
        //     (frequency switch boolean is set to false)
        bool switching = false;
        string extraConf = "normal";
        //      Seek K rows in CAL-U, i.e. key wavelength parameters	
        gratTuple[keyWaveLoop1] = SPEC_get_grat_info(keyWAVE[keyWaveLoop1],"KHI",switching,extraConf,orderSel,verbose);
        //      Issue now OBCP#13 for each of the given key wavelengths
        int order = gratTuple[keyWaveLoop1]{1};
        int grat_start_pos = gratTuple[keyWaveLoop1]{2};
        int nb_grat_steps = gratTuple[keyWaveLoop1]{3};
        int grat_step_up_fine = gratTuple[keyWaveLoop1]{4};
        int grat_step_dn_fine = -grat_step_up_fine;
        //      Table OBCP13params is indexed by order
        string key = "" + order;
        string calU = "OBCP13params";
        int nb_up_dn = ilookup(calU,key,"nb_up_down");
        int nb_cycles_grat = ilookup(calU,key,"nb_CS1_CS2");
        int nb_ramps_grat_pos = ilookup(calU,key,"nb_ramps_plateau");
        int grat_step_coarse = 0;
        //      Lookup chopper CS1 and CS2 positions
        calU = "CHOPPERCSparams";
        chop_pos_CS1 = ilookup(calU,"SPEC","pos_CS1");
        chop_pos_CS2 = ilookup(calU,"SPEC","pos_CS2");
        int nb_rdouts_ramp = nb_rdouts_ramp_red;
        //     Grating logic (OBCP is up/down ==> grating ends where it started)
        //     Leave the grating where it is, i.e. end-of-DMC value
        int new_grat_def_pos = grat_start_pos;
        //     But the last line should leave grating at frstLstGratPos
        if(keyWaveLoop1 == nbKEY - 1) {
            new_grat_def_pos = frstLstGratPos;
        }
        //     Number of steps to start position for current line
        int steps_start = grat_def_pos - grat_start_pos;
        int grat_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("OBCPcal:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_time);
        }
        //
        int steps_end = grat_start_pos - new_grat_def_pos;
        int grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("OBCPcal:GratEnd from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
        }
        int[] dureeOBCP = OBCP_chop_grat_scan_cal(nb_up_dn,grat_step_coarse,nb_grat_steps,grat_step_up_fine,nb_cycles_grat,chop_pos_CS1,nb_ramps_grat_pos,chop_pos_CS2,grat_step_dn_fine,detector,grat_start_pos,grat_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp);
        if(verbose) {
            debug_print("SlewCal performed KeyWave: " + keyWAVE[keyWaveLoop1] + " [mic] requires " + dureeOBCP[0] + " [sec]");
        }
        //     Update dureeCalKey
        dureeCalKey[keyWaveLoop1] = [0,0,0,0,0];
        for(int loop1 = 0 .. 4) {
            dureeCalKey[keyWaveLoop1][loop1] = dureeOBCP[loop1];
        }
        //     Prepare the grating to be ready for the next wavelength
        grat_def_pos = new_grat_def_pos;
    }
    // Add after the KeyWaves in dureeCalKey the duration from AOT_prologue
    dureeCalKey[nbKEY] = [0,0,0,0,0];
    dureeCalKey[nbKEY][4] = totalDUREE[4];
    if(verbose) {
        debug_print("End SlewCal with dureeCalKey: " + dureeCalKey);
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return dureeCalKey;
}

// File          : PACS_Chopper_EnDis_Test_NoConf_ast300.cus
// Missionphase  : SVT / flight 
//
// Purpose       : Switch-on/switch-off and enanle/disable test of chopper
//
// Author        : MN/HD
// CUSification  : MN/HD
// Arguments     :
//
// Description   : Flight procedure to verify the stability of the chopper.
//                      Produces diagnostic housekeeping data, enables the
//                      chopper for 300 seconds, and disables again.
//
// Comments      : Copied from PACS_Chopper_EnDis_Test_ast300_OBS
//                         without the configuration and with MOIS comments
//
// Version       : 1.0
// History       : 1.0 17-Oct-2007 BV initial version
//		  
//
procedure PACS_Chopper_EnDis_Test_NoConf_ast300 {
}{
    mois_comment("Start of procedure: verify the stability of the PACS chopper during 300 sec");
    //  Time 1 sec
    int n = 300;
    mois_step("Enable diagnostic housekeeping");
    // Set diagnostic HK (1 kHz, 4 parameters)
    PACS_Chopper_EnDis_Test_dhk("ON");
    delay(10);
    //
    mois_step("Switch on and enable chopper for 300 seconds");
    // Switch on and enable chopper for n seconds, while n is given by the user
    PACS_Chopper_SWON_SWOF_only("ON");
    delay(10);
    EnDis_chopper("ON");
    delay(n);
    EnDis_chopper("OFF");
    delay(10);
    PACS_Chopper_SWON_SWOF_only("OFF");
    delay(10);
    mois_step("Stop diagnostic housekeeping");
    // Stop diagnostic HK
    PACS_Chopper_EnDis_Test_dhk("OFF");
}

// Missionphase  : PACS AVM ILT Orbit-Operations
//
// Purpose       : OnBoardControlProcedure to perform
//                 chopped spectroscopic scans (OBCP #8)
//
// Author        : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : OBCP_spec_2_3_chop.txt
//
// Arguments needed to call OBCP
// Type  Name              Deault   Description
// int   nb_up_down         1       Number of sequences: up down up  P#1
// int   nb_grat_steps     16       Number of grating steps          P#2
// int   nb_SRC_OFF         2       Nb cycles grating position       P#3
// int   chop_pos_REF1   1000       Chopper position 1               P#4
// int   nb_ramps_plateau   3       Nb of ramps per chopper plateau  P#5
// int   chop_pos_REF2  -3000       Chopper position 2               P#6
// int   chop_pos_REF3   5000       Chopper position 3               P#7
// int   nb_CS1_CS2         1       Nbr cycles on CS                 P#8
// int   chop_pos_CS1  -25000       Chopper position on CS1          P#9
// int   chop_pos_CS2   25000       Chopper position on CS2          P#10
// int   grat_step_up     133       Grating step                     P#11
// int   grat_step_dn    -133       Grating step                     P#12
// int   detector           1       Synchronize on this detector 1:Blue 2:Red
// int   grat_pos      461000       Starting grating position
// int   grat_time      40000       Time for grating to move to start position
// int   comp_mode_blu    16        "Blue" compression
// int   comp_mode_red    16        "Red" compression 
// int   grat_def     500000        Grating default position
// int   chop_def          0        Chopper default position
// int   grat_def_time 20000        Grating time to move to grat_def [msec]
// int   nb_rdouts_ramp   64        Number of readouts per ramp
//
// Description   : This script mimics the OBCP_GRATING_LINE_SCAN_CHOPPED
//                 pseudo script, section 3.9.1 in PACS-ME-LI-005
//                 This CUS version computes the duree of the
//                 observation, as specified by the input parameters.
//                 It will also send the trigger TC to start the OBCP
//
// Dependencies  : Calls "two_three_position_chopped_spectroscopy" DEC
//                 MEC sequence 4.2.1, DMC_spec_2_3_chop.txt
// Comments      : 
//
// Version       : 0.1 17-Aug-2004 Creation by DAC
// History       : 
// 0.2 16-Sep-2004 OBCP and corresponding DMC files renamed
//                                 Block renamed as well
// 0.3 18-Oct-2004 Normalized variable names 
// 0.4 22-Oct-2004 Added "communication jitter" after test on PACS QM
// 0.5 12-Nov-2004 Added time_array elements; return duree times in [sec]
// 1.0 24-Mar-2005 HF modified debug_print statement
// 1.1 11-Apr-2005 DAC Corrected returned time array
// 1.2 22-apr-2005 DAC Changed default values to match TM's
//                     Added t_cmd for forgotten DMC command
// 1.3 25-apr-2005 DAC Added grat_step_dn to match OBCP description
//                             
//
int[] block OBCP_spec_2_3_chop PACS 8 {
    int nb_up_down = 1; // Number of sequences: up down up  P#1
    int nb_grat_steps = 16; // Number of grating steps          P#2
    int nb_SRC_OFF = 2; // Nb cycles grating position       P#3
    int chop_pos_REF1 = 1000; // Chopper position 1              P#4
    int nb_ramps_plateau = 3; // Nb of ramps per chopper plateau P#5
    int chop_pos_REF2 = -3000; // Chopper position 2              P#6
    int chop_pos_REF3 = 5000; // Chopper position 3              P#7
    int nb_CS1_CS2 = 1; // Nbr cycles on CS                P#8
    int chop_pos_CS1 = -25000; // Chopper position on CS1       P#9
    int chop_pos_CS2 = 25000; // Chopper position on CS2        P#10
    int grat_step_up = 133; // Grating step                   P#11
    int grat_step_dn = -133; // Grating step                   P#12
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 461000; // Starting grating position
    int grat_time = 40000; // Time for grating to move to start position
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopped default position
    int grat_def_time = 20000; // Grating time to move to grat_def [msec]
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Register with environment
    WriteBBID($BBID);
    // Variables for time_array
    int duree_ramps = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    //    debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    //    debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // duree of this OBCP (computed and returned in [msec])
    int duree_msec = 0;
    // OBCP pseudo code 
    // OBCP_GRAT_LINE_SCAN_CHOP(seq, seq_time, P#1,&,P#12,  
    //                          detector, grat_pos, grat_time,
    //                          comp_mode_blu, comp_mode_red, 
    //                          grat_def, chop_def, grat_def_time) 
    // Begin 
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_pos) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // (all parameters filled by DPU based on seq parameter) 
    // DMC_SYNCHRONIZE_ON_DET(detector) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, comp_mode_blu, comp_mode_red, CHHKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT (grat_time) 
    duree_msec = duree_msec + t_cmd + grat_time;
    duree_OVR = duree_OVR + t_cmd + grat_time;
    // DMC_START_SEQUENCE
    // Call DEC/MEC sequence just to know the execution time
    int[] duree1 = DMC_spec_2_3_chop(nb_up_down,nb_grat_steps,nb_SRC_OFF,nb_ramps_plateau,nb_CS1_CS2);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    // WAIT (seq_time) 
    duree_msec = duree_msec + t_cmd;
    duree_msec = duree_msec + seq_time;
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT (grat_def_time) 
    duree_msec = duree_msec + t_cmd + grat_def_time;
    duree_OVR = duree_OVR + t_cmd + grat_def_time;
    // Issue TM(1,7) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Now trigger execution of OBCP
    // This OBCP is number, requires 22 parameters and calls DEC/MEC #8
    string obcp_ID = "GRAT_LINE_CHOP";
    int obcp_par_nb = 22;
    int seq_DMC = 8;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_grat_steps},{5,nb_SRC_OFF},{6,chop_pos_REF1},{7,nb_ramps_plateau},{8,chop_pos_REF2},{9,chop_pos_REF3},{10,nb_CS1_CS2},{11,chop_pos_CS1},{12,chop_pos_CS2},{13,grat_step_up},{14,grat_step_dn},{15,detector},{16,grat_pos},{17,grat_time},{18,comp_mode_blu},{19,comp_mode_red},{20,grat_def},{21,chop_def},{22,grat_def_time}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    //    debug_print("OBCP_spec_2_3_chop [sec]: " + time_array);
    delay(time_array[0]);
    // Return the array of times

    return time_array;
}

// Missionphase  : 
//
// Purpose       : Loading the sequencer to build up the signal (OBMO)
//                 for normal DDCS mode                  
//                 
//
// TCL author    : TM
// TCL file      : tm_phot_sequencer_setup.tcl
// CUS author    : DAC
// Script file   : PHOT_seq_setup.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description  : This script will set the sequencer, which is building
//                up the final signal and it sets the data mode
//                to "Bolo & HK".
//                This script should be executed just after the
//                switch-on procedure, the BOLC initialisation
//                and the bias SETTING (polarizer)
//                The purpose of this scenario is to configure the BOLC 
//                sequencer.
//                The sequencer will provide clock signals for detector
//                readout and for BOLC analog synchronous operation 
//                (switching between S and Sref, triggering A to D conversion)
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 0.2 
// History       : 0.1 13-apr-2005 DAC. Based on TM's V1.0 from 20-apr-2004
//               : 0.2 13-apr-2006 TM, updated for new sequencer, cleaning
//                                 of commands in the end (2_Load_of_new_sequencer.txt)
int[] procedure PHOT_seq_setup {
}{
    // Define variables to communicate various durations to HSPOT.
    // NOTE: all time variables in units of number of ramps (SPEC) or
    //       number of readouts (BOLO). The calling program must convert this
    //       count into actual duration in true time units [seconds].
    //       SRC, REF, CAL, OVR stand for time spent on SRC, REF (on sky),
    //       CAL source, and overheads (wait for something). Total
    //       duration is given by duree_num. If no error, this duration
    //       must be equal to the sum of all others
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    //--------------------------------------
    //  BOLC sequencer initialisation (OBMO)
    //--------------------------------------
    //   
    // PC103420 "DMC_SEND_COMMAND_BOLC" SEND COMMAND TO BOL CONTROLLER
    //         PP071420 "BOLOMETER_COMMAND"
    //
    // Sequence of command to load the BOLC programmable sequencer:
    // The timing is defined according to timing diagram given by P.Agnese
    //    Set_clock_mux stop
    //    P 09 00 00 00
    Pacs_BOLC_SET_CLOCK_MUX("STOP");
    // Set seq param table 0 time 0 clk 20
    // P 0C 00 0014
    Pacs_BOLC_FINE_TIME_SETTING(0x14);
    // Set seq param table 1 time 35 clk 52
    // P 0C 01 11B4
    Pacs_BOLC_FINE_TIME_SETTING(0x111b4);
    // Set seq param table 2 time 144 clk 116
    // P 0C 02 4874
    Pacs_BOLC_FINE_TIME_SETTING(0x24874);
    // Set seq param table 3 time 153 clk 100
    // P 0C 03 4CE4
    Pacs_BOLC_FINE_TIME_SETTING(0x34ce4);
    // Set seq param table 4 time 159 clk 108
    // P 0C 04 4FEC
    Pacs_BOLC_FINE_TIME_SETTING(0x44fec);
    // Set seq param table 5 time 280 clk 44
    // P 0C 05 8C2C
    Pacs_BOLC_FINE_TIME_SETTING(0x58c2c);
    // Set seq param table 6 time 290 clk 36
    // P 0C 06 9124
    Pacs_BOLC_FINE_TIME_SETTING(0x69124);
    // Set seq param table 7 time 294 clk 52
    // P 0C 07 9334
    Pacs_BOLC_FINE_TIME_SETTING(0x79334);
    // Set seq param table 8 time 314 clk 20
    // P 0C 08 9B14
    Pacs_BOLC_FINE_TIME_SETTING(0x89b14);
    // Set seq param table 9 time 322 clk 0
    // P 0C 09 A100
    Pacs_BOLC_FINE_TIME_SETTING(0x9a100);
    // Set clock mux sequencer
    // P 09 00 00 01
    Pacs_BOLC_SET_CLOCK_MUX("Sequencer");
    //-----------------
    // End of Procedure
    //-----------------
    // Time spent
    int duree_TCs = time() - time_start;
    duree_OVR = duree_TCs;
    duree_num = duree_OVR;
    // Return the array of times
    int[] time_array = [duree_num,duree_SRC,duree_REF,duree_CAL,duree_OVR];

    return time_array;
}

// File          : PACS_Spec_CRE_Setup_Cold.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Configure CRE bias, reset interval and capacitor for 
//                 testing at room temperature
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
// Comments      : Intermediate version
//
// 
// Version       : 1.5
// History       : 1.0 / 16-Nov-2004 Initial version
//                    1.1    7-mar-2006 SPEC_HEAT_1_C renamed
//                    1.2 10-apr-2006 Modified heater setting for FM 
//                    1.3 06-nov-2006 HF - Changed bias_r to 82
//                    1.4 13-nov-2005 Changed bias_r to 12
//                    1.5 8-Apr-2008 HF changed to in-flight default biases
procedure PACS_Spec_CRE_Setup_Cold {
}{
    int red_reset = 64;
    int blue_reset = 64;
    int red_bias_d = 123;
    int red_bias_r = 12;
    int blue_bias_d = 328;
    int blue_bias_r = 12;
    int red_capacitor = 0;
    int blue_capacitor = 0;
    int heater_blue = 0;
    // PC174420 "DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    //         Fixed GroupSize: 1, repetition: 8
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // cre_ctrl: 256=sync width=2, 128=T sensor on, 2=select, 1=power on
    int blue_cre_ctrl = blue_capacitor + 256 + 128 + 2 + 1;
    int[] list_int = [32,blue_reset,blue_cre_ctrl,blue_bias_r,blue_bias_d,0];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,blue_reset,blue_cre_ctrl,blue_bias_r,blue_bias_d,0,chksum);
    delay(1);
    // PC173420 "DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    //         Fixed GroupSize: 1, repetition: 8
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // cre_ctrl: 256=sync width=2, 128=T sensor on, 2=select, 1=power on
    // set red_cre_ctrl [expr $red_capacitor+256+128+2+1]
    // set spec_par_r [list {PP095420 32} \
    //         [list PP096420 $red_reset] \
    //         [list PP097420 $red_cre_ctrl] \
    //         [list PP098420 $red_bias_r] \
    //         [list PP099420 $red_bias_d] {PP100420 0}]
    // set chksum [getChkSum -d -32 $spec_par_r]
    // putlog "ChkSum for spec_par_r: $spec_par_r"
    int red_cre_ctrl = red_capacitor + 256 + 128 + 2 + 1;
    list_int = [32,red_reset,red_cre_ctrl,red_bias_r,red_bias_d,0];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,red_reset,red_cre_ctrl,red_bias_r,red_bias_d,0,chksum);
    delay(1);
    // PC094420 "DMC_SET_PAR_BOTH_SPEC" SEND COMPLETE PARAMETERS TABLE TO BOTH DECS
    // tcsend PC094420 
    // waittime 0.5
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    delay(1);
    // PC094420 "DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    //tcsend PC086420 
    //waittime 0.5
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // PC094420 "DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    //tcsend PC093420 
    //waittime 0.5
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    //  DMC_SET_B_SPE_HEAT_1C(0)
    // eval tcsend PC087420 [list [list PP073420 $heater_blue]]
    // waittime 0.5
    Pacs_DMC_SET_B_SPEC_HEAT_C_RAW(heater_blue);
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

// Missionphase  : 
//
// Purpose       : Generic PACS spectroscopy AOT setup                 
//
// Author        : Diego A. Cesarsky, HF
// CUS script    : Diego A. Cesarsky
// CVS file      : SPEC_aot_prologue.txt
//
// Arguments     :
// type    Name         DefVal   Description 
// int     ramp_len_red    64    Red ramps' length
// int     ramp_len_blu    64    Blue ramps' length
// double  bias_d_red     0.07   BIAS_D for red spectro  (0-1V)
// double  bias_r_red     0.011  BIAS_R for red spectro  (0-1V)
// double  bias_d_blu     0.21   BIAS_D for blue spectro (0-1V)
// double  bias_r_blu     0.011  BIAS_R for blue spectro (0-1V)
// int     capa_red         8    Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
// int     capa_blu         8    Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
// int     comp_mode_blu   16    Compression mode blue channel
// int     comp_mode_red   16    Compression mode red channel
// int     nb_samp_subramp_blu 64   Number of blue samples per sub-ramp
// int     nb_samp_subramp_red 64   Number of red samples per sub-ramp
// int     nb_raw_spu_blu  1     Number of raw channels transmitted by SPUS
// int     nb_raw_spu_red  1     Number of raw channels transmitted by SPUL
// int     glitch_det      1     Glitch detection; 0=on; 1=off
// int     ramp_fit_alg    1     Ramp fit algorithm [0=LstSq;1=mean value]
// int     filter          0     Desired FLTW position (0: ignore FLTW)
//                 
//
// Description   : Calls successively:                
//                - SPEC_cre_setup: generic setup of detectors for AOT
//                - SPEC_spu_setup: generic AOT setup of SPU  
//                - SPEC_fltw_move: Move FWSPEC to default position
//                - SPEC_MOV_CHOP_and_GRAT: Move chopper and grating to 
//                  default position
//
// Dependencies  : SPEC_fltw_move 
//                 SPEC_cre_setup
//                 SPEC_spu_setup
//                 SPEC_MOV_CHOP_and_GRAT
//
// Preconditions : 
//                 
// Comments      : This BB belongs to the 100 series (spectro)       
//
// Version       : 0.1  7-Oct-2004 Creation by DAC
// History       : 0.2 12-Oct-2004 Revised after revision of the used
//                 1.0  7-jun-2005 Adapted for SPEC_MEC_defalut table giving
//                                 filter position as {int}
//                 1.1 29-aug-2005 Added "whoCalledMe" to SpecSlewCal
//                 1.2  1-sep-2005 Added verbose
// procedures
//                 0.3 18-Oct-2004 Was SPEC_prologue; normalized variable names
//                 0.4 22-Oct-2004 Use new SPEC_cre_setup; cre_ctrl default
// is for capa_xx = 0, heater no longer handled by SPEC_cre_setup
// 1.0 22-Apr-2005 HF introduce mechanisms to default and 
//                 removed duplicate stop SPUs
// 1.1 10-May-2005 DAC Renamed HF's tables without ".txt"
//                 Removed spurious "delay()" at end of block (each called 
//                 module sets it own delay)
// 1.2 12-apr-2006 No longer moves FLTW
// 1.3  1-jun-2006 Reinstated FLTW using passed value (null means ignore
//                 FLTW logic)
// 1.4  6-dec-2006 Adapted for SPEC_fltw_move from ILT
// 2.0	23-sep-2008 SCR 4431 Data rate
// 2.1  23-07-2009 BV SPR 1798 corrected biases
//
int[] block SPEC_aot_prologue PACS 111 {
    int ramp_len_red = 64; // Red ramps' length
    int ramp_len_blu = 64; // Blue ramps' length
    double bias_d_red = 0.042 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_red = 0.011 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.1 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_r_blu = 0.011 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    int capa_red = 0; // Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
    int capa_blu = 0; // Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 64; // Number of blue samples per sub-ramp
    int nb_samp_subramp_red = 64; // Number of red samples per sub-ramp
    int nb_raw_spu_blu = 1; // Number of raw channels transmitted by SPUS
    int nb_raw_spu_red = 1; // Number of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1; // Ramp fit algorithm [0:LstSq;1:MeanVal]
    int filter = 0; // Desired FLTW position (0: ignore filter)
    bool verbose = true;
}{
    // Register start of BB
    WriteBBID($BBID);
    // Define the elements of time_array
    int duree_sec = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    data_rate(120.0);
    // Accumulated duree [milliseconds]
    int duree_msec = 0;
    // Perform SPEC_cre_setup.
    // NOTE: capa_xxx is added to cre_ctrl_xx within SPEC_cre_setup
    int cre_ctrl_red = 386;
    int cre_ctrl_blu = 386;
    int duree2 = SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    duree_msec = duree_msec + duree2;
    if(verbose) {
        debug_print("duree of SPEC_cre_setup: " + duree2);
    }
    // Perform SPEC_spu_setup, starting SPU
    bool startSPU = true;
    int duree3 = 0;
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    duree_msec = duree_msec + duree3;
    // Position filter wheel at desired position
    // Look up table order <=> telecommand ENG parameter
    string[] fltPOS = ["N/A","NoFilter","POS B","POS A"];
    // Command only for filter 2 or 3
    if(filter == 2 || filter == 3) {
        string fw_posENG = fltPOS[filter];
        int duree4 = SPEC_fltw_move(fw_posENG);
        //    WARNING! SPEC_fltw_move returns its duration in [sec]   
        duree_msec = duree_msec + 1000 * duree4;
        if(verbose) {
            debug_print("SPEC_aot_prologue turns FLTW to " + fw_posENG);
        }
    }
    // Position chopper and grating at their default positions
    int chop_pos = ilookup("SPEC_MEC_Defaults","Spectroscopy","chopper");
    int grat_pos = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    if(verbose) {
        debug_print("Moving CHOP and GRAT to positions: " + chop_pos + ", " + grat_pos);
    }
    int[] duree5 = SPEC_MOV_CHOP_and_GRAT(chop_pos,grat_pos);
    duree_msec = duree_msec + duree5[0];
    // Total time is now computed including TC rate
    duree_sec = time() - time_start;
    // All the time spent here is OVR
    duree_OVR = duree_sec;
    // Define time_array 
    int[] time_array = [duree_sec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // Report duration
    if(verbose) {
        debug_print("+++++ SPEC_aot_prologue: " + time_array);
    }
    // Return the array of times
    //Reset Block ID
    WriteEndBB();
    //Return time_array

    return time_array;
}

// Mission phase : ILT at Garching
//
// Purpose : PCD req.1.1.11
//           Low frequency noise measurement for EMT
//
// Author : Koryo Okumura
//
// CUS script : procedure Phot_lowFreq_DDCS_EMT
//
// Argument :
//   measureTime : response measure time in seconds [3600s = 1hour]
//   biasFile    : Bias table file containing the initial values ["BOLObias_ILT_standard_high"]
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + SPU is ON in a normal downlink
//
// Description :
//   Low frequency measurement on one of the CSs
//
// Dependencies : None
//
// Comments : 
//
// Version : Fri Mar 30 2007
//              10-apr-2007, OGSE BB1 at 20K
//
procedure Phot_lowFreq_DDCS_IST {
    string cs_num = "cs1" in ["cs1","cs2"]; // CS1 or CS2
    int measureTime = 3600; // response measure time in seconds
    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
}{
    //
    int[] cs_pos = [-23382,22347];
    int i_cs = 0;
    if(cs_num == "cs2") {
        i_cs = 1;
    }
    //
    //***********************************************
    //***********************************************
    //
    //	Bias setting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(biasFile,1);
    PHOT_set_bias_volt(biasFile,2);
    PHOT_set_bias_volt(biasFile,3);
    PHOT_set_bias_volt(biasFile,4);
    PHOT_set_bias_volt(biasFile,5);
    PHOT_set_bias_volt(biasFile,6);
    //
    //**************************
    // Sequence mode : Sref_only
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sb-Sref (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sb-Sref");
    //# P 09 01 00 00
    int operand = 0x9010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    //
    //***************
    // Set gain high
    //***************
    Pacs_BOLC_SET_GAIN("HIGH");
    //
    //*******************************
    // Select Filter A (110 microns)
    //*******************************
    PHOT_fltw_move("POS A");
    //
    //********************
    // Let all stabilized
    //********************
    delay(300);
    //
    //************************************
    // Response measurement during 300 (s)
    //************************************
    TMMarker602();
    OBCP_chopped_photometry(0,0,39,0,0,150,1,cs_pos[0],cs_pos[1],0,0,0);
    TMMarker600();
    //
    //**********************************************
    // Set the PACS chopper at the central position
    //**********************************************
    Pacs_DMC_MOVE_CHOP_ABS(cs_pos[i_cs]);
    //
    //********************
    // Let all stabilized
    //********************
    delay(300);
    //
    //*****************************************
    // Noise measurement during measureTime (s)
    //*****************************************
    TMMarker601();
    delay(measureTime);
    TMMarker600();
    //
    //********************
    // Let all stabilized
    //********************
    delay(300);
    //
    //************************************
    // Response measurement during 300 (s)
    //************************************
    TMMarker602();
    OBCP_chopped_photometry(0,0,39,0,0,150,1,cs_pos[0],cs_pos[1],0,0,0);
    TMMarker600();
    //
    // Stop SPU
    PHOT_spu_reset();
    sync();
}

// Mission phase : Commissioning Phase
//
// Purpose : PCD req.1.1.9 Measure time constants after cosmic ray impact
//
// Author : Koryo Okumura
//
// Version : June 08 2009
//
// CUS script : mode PacsEng_Phot_glitch
//
// Argument :
//   string biasTable = "BOLObias_standard_high"; // Bias table
//   string gain = "HIGH" in ["LOW","HIGH"]; // gain used during the measurements
//   int measureTime = 1200; // Measurement duration in seconds
//   string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
//   string calGain = "NO_CHANGE" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//
// Check before executing :
//   + Bolometer is already normally operating
//
// Description : OBS script to execute Phot_glitch
//
// Dependencies : None
//
// Comments : None
// Update :
//   2009-06-08 : Modified from PacsCal_Phot_glitch
//
obs PacsEng_Phot_glitch {
    string biasTable = "BOLObias_standard_high"; // Bias table
    string gain = "HIGH" in ["LOW","HIGH"]; // gain used during the measurements
    int measureTime = 1400; // Measurement duration in seconds
    string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
    string calGain = "NO_CHANGE" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    int nLoops2 = 30; // number of CSs cycles during initial hold
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 16; // number of readouts per plateau
    bool verbose = true;
}{
    // Bus configuration for the Burst mode (7)
    busconfig (7);
    // Several arguments needed for "basic_fine_pointing"
    int nRdts = readouts_plateau - 1;
    //Execute the pointing request
    bool execute = true;
    // time to set OBSID and biases then PacsPhotSlewCal
    //int timeOBSID = imax(1, duration(WriteOBSID($OBSID))+ duration(data_rate(300.0)));
    //int timeEndID = imax(1, duration(data_rate(0.0))+ duration(WriteEndID()));
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = 0;
    int timeCal3CPR2 = duration(Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    int timeCal3CPR5 = duration(Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"HIGH",3,3,false));
    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT","LOW"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT",calGain));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"LOW"));
    }
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
    }
    //Initial hold
    int tih = timeOBSID + timeChgBias + timeCal3CPR2;
    //Final hold
    int tfh = timeChgBias + timeCal3CPR5 + timeEndID;
    //Duration of "stable" pointing
    int tp = duration(Phot_glitch(biasTable,gain,measureTime));
    //Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    //  Start the sequence
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        int tNOW = time();
        if(state[0] == 2) {
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD starts at   " + tNOW);
            }
            // Set OBSID
            WriteOBSID($OBSID);
            data_rate(300.0);
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops2,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            tNOW = time();
            if(verbose) {
                debug_print("INITIAL_HOLD ends at     " + tNOW);
            }
        }
        if(state[0] == 3) {
            tNOW = time();
            if(verbose) {
                debug_print("POINT starts at   " + tNOW);
            }
            //********************************
            //  Call the Phot_glitch
            //********************************
            Phot_glitch(biasTable,gain,measureTime);
            tNOW = time();
            if(verbose) {
                debug_print("POINT ends at     " + tNOW);
            }
        }
        if(state[0] == 5) {
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD starts at   " + tNOW);
            }
            // Set biases and start SPU
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT","LOW");
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,"DIRECT",calGain);
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,"LOW");
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                PHOT_change_biases(calBiasTable,calMode,calGain);
            }
            //***************************************************
            // 3 chopper positions measurement through 2 filters
            //***************************************************
            Pacs_OBCP_chopped_photometry2(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,664,"blue70um",false,"LOW",3,3,false);
            // Write EndID
            data_rate(0.0);
            WriteEndID();
            tNOW = time();
            if(verbose) {
                debug_print("FINAL_HOLD ends at     " + tNOW);
            }
        }
    }
}

// VS comments  : $Id: PacsSpecAuxRMS.txt,v 1.9 2007/10/25 12:15:42 dcesarsk Exp $ 
// Purpose       : To compute RMS vs. WaveLength; to establish min,max RMS
//                 and their associated wavelength. arrayID 
//
// CUS author    : 
// Script file   : PacsSpecAuxRMS.txt 
//
// Input arguments
// type    name         description
// string  aotID        RANGE or LINE AOT
// string  arrayID      ID for current array
// double  wave         Array of wavelengths
// double  waveRef      Wave reference
// double  intTime      Integration time
// bool    verbose      Verbose or not
//
// Return values
// Type          Description
// tuple {{double[]},{double[],double[],double[]}}
// Description   : 
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 0.1
// History       : 0.1  12-mar-2007 DAC
//                 0.2  13-mar-2007 Added "string" to return tuple
//                 0.3  16-apr-2007 Use arrayID to choose the relevant
//                                  sensitivity table. Added logic to
//                                  choose one of the four SPECcontline
//                                  files
//                 1.0  23-oct-2007 Added input variable to identify
//                                  FreqSwitch
//                 1.1  24-oct-2007 Accept nbOBS and nbOFF (not used
//                                  yet)
//                 2.0 01-dec-2009 VD SCR PHS-1272 
//                 3.0 20-jan-2010 VD PHS-1302
//                 4.0 26-jan-2010 VD PHS-1302 !! sedb2a .. waveRef <102.0!
//                                                order 3 too! etc
//                 5.0 03-may-2010 VD PHS-1393 order23
//                 6.0 05-may-2010 VD PHS-1385 ripples etc..
//
{string,double[],double[],double[],double[]} procedure PacsSpecAuxRMS_4unchop {
    /* RANGE or LINE AOT                                                    */
    string aotID = "RANGE";
    /* ID for this RMS computation                                          */
    string arrayID = "undefined";
    /* define A / B filter */
    string orderSel = "undefined";
    /* Array of wavelengths                                                 */
    double[] wave = [0.0];
    /* Wave reference                                                       */
    double waveRef = 100.0;
    /* Integration time                                                     */
    double intTime = 10.0;
    /* Type of observation                                                  */
    string obsType = "whatever";
    /* nbOBS and nbOFF                                                       */
    int nbOBS = 1;
    int nbOFF = 0;
    int gratScanObsTime = 1;
    /* Verbose or not                                                        */
    bool verbose = false;
}{
    // Number of wavelengths in array
    int nbWaves = length(wave);
    if(verbose) {
        debug_print("AuxRMS:Size wave table: " + nbWaves);
    }
    // Create arrays for rmsNoiseCONT and rmsNoiseLINE
    double[] rmsNoiseC = [0.0];
    double[] rmsNoiseL = [0.0];
    // Integration time related variables
    // intTime is SRC/REF for chopping !!Each one, not the sum!!
    // For FreqSwitch, intTime is the total time LINE+REF  (assume we switch by a 
    // few pixels)
    // In either case, the "line" is the result of a subtraction (either SRC-REF 
    // or SRC - shiftedSRC). When both "SRC" and "REF" have the same rms, the RMS
    // increase introduced by the subtraction operation is sqrt(2). 
    // In raster/OFF, each raster point has a noise ONrms. However, the OFF position
    // is performed nbOFF times; its rms is OFFrms = ONrms/sqrt(nbOFF). The rms
    // of the difference is then sqrt(1 + 1/nbOFF) larger. Ignore for raster
    // for time being
    double difRMSfactor = sqrt(2.0);
    // The new frequency switch scheme uses 2 OFF positions to be subtracted
    // from the SRC - shiftedSRC array. This introduces an extra sqrt(1+1/2)
    // difRMSfactor = sqrt(2.0)*sqrt(1.5) = sqrt(3.0)
    if(obsType == "FreqSwitch" || obsType == "GratScanNoChop") {
        difRMSfactor = sqrt(3.0);
    }
    // Scaling factor for tabulated rms (good for 1 sec time)
    debug_print("AuxRMS: intTime " + dformat(intTime,2));
    double scale = difRMSfactor / sqrt(intTime);
    if(verbose) {
        debug_print("AuxRMS: intTime " + dformat(intTime,2));
        debug_print("AuxRMS: difRMSfactor  " + dformat(difRMSfactor,2));
        debug_print("AuxRMS: scaleRMS" + dformat(scale,3));
        debug_print("AuxRMS: waveRef: " + waveRef);
    }
    // Establish which sensitivity table shall be used
    // PHS-198 in parts: waveRef MUST be entered in order 1 parallel bands
    string sensTable = "TBD";
    string sensTablePar = "TBD";
    //    if(arrayID == "order1" || waveRef >= 103.1) {
    if(arrayID == "order1") {
        if(waveRef >= 102.0) {
            sensTable = "SPECContLine1";
            sensTablePar = "SPECContLine1";
            debug_print("here is all in Red");
        } else {
            if(waveRef <= 73.0) {
                if(orderSel == "order2") {
                    sensTable = "SPECContLine1";
                    sensTablePar = "SPECContLine2";
                    debug_print("here is given in red but ref in 2B");
                }
                if(orderSel == "order3") {
                    sensTable = "SPECContLine1";
                    sensTablePar = "SPECContLine23";
                    debug_print("here is given in red but ref in 2A");
                }
            } else {
                if(waveRef > 73.0 && waveRef <= 105.0) {
                    sensTable = "SPECContLine1";
                    sensTablePar = "SPECContLine3";
                    debug_print("here is given in red but ref in 3A");
                }
            }
        }
    }
    if(arrayID == "order2" && waveRef < 102.0) {
        sensTable = "SPECContLine2";
        sensTablePar = "SPECContLine2";
    } else {
        if(arrayID == "order2" && waveRef >= 102.0) {
            sensTable = "SPECContLine2";
            sensTablePar = "SPECContLine1";
        }
    }
    if(arrayID == "order3" && waveRef < 102.0) {
        sensTable = "SPECContLine3";
        sensTablePar = "SPECContLine3";
    } else {
        if(arrayID == "order3" && waveRef >= 102.0) {
            sensTable = "SPECContLine3";
            sensTablePar = "SPECContLine1";
        }
    }
    if(arrayID == "order23" && waveRef < 102.0) {
        sensTable = "SPECContLine23";
        sensTablePar = "SPECContLine23";
    } else {
        if(arrayID == "order23" && waveRef >= 102.0) {
            sensTable = "SPECContLine23";
            sensTablePar = "SPECContLine1";
        }
    }
    if(verbose) {
        debug_print("AuxRMS in Nom band will use table " + sensTable);
        debug_print("AuxRMS in Par band will use table " + sensTablePar);
    }
    if(sensTable == "TBD") {
        error("Internal error: did not find proper sensitivity table");
    }
    // Get rms/sec from SPECcontline, a value per wavelength
    // Create CONT and LINE noise arrays; wave array already exists
    ///   if (verbose) {debug_print("AuxRMS:Wave Interpol From/To]: " 
    ///                          + wave[0] + "/" + wave[nbWaves-1]);}
    for(int loop0 = 0 .. nbWaves - 1) {
        //     Current wavelength
        double waveNow = wave[loop0];
        //     Get CONT and LINE rms values
        //     Use scale factor to convert into observed noise     
        rmsNoiseC[loop0] = scale * interpolate(sensTable,"contRMS",waveNow);
        rmsNoiseL[loop0] = scale * interpolate(sensTable,"lineRMS",waveNow);
    }
    // Find min and max of rmsNoiseC
    int[] minmax = PacsArrayMinMax(rmsNoiseC,verbose);
    double noiseCmin = rmsNoiseC[minmax[0]];
    double waveCmin = wave[minmax[0]];
    double noiseCmax = rmsNoiseC[minmax[1]];
    double waveCmax = wave[minmax[1]];
    // Find min and max of rmsNoiseL
    minmax = PacsArrayMinMax(rmsNoiseL,verbose);
    double noiseLmin = rmsNoiseL[minmax[0]];
    double waveLmin = wave[minmax[0]];
    double noiseLmax = rmsNoiseL[minmax[1]];
    double waveLmax = wave[minmax[1]];
    //  Deal with reference wavelength
    if(verbose) {
        debug_print("AuxRMS:Interpolate w/lambda " + waveRef);
    }
    double noiseRefCont = scale * interpolate(sensTablePar,"contRMS",waveRef);
    double noiseRefLine = scale * interpolate(sensTablePar,"lineRMS",waveRef);
    // Compute the RMS fluctuations at special wavelengths
    // Continuum
    double noiseCref = noiseRefCont;
    // Line
    double noiseLref = noiseRefLine;
    if(obsType == "GratScanNoChop") {
        noiseCmin = sqrt(double(gratScanObsTime)) * noiseCmin / sqrt(intTime);
        noiseCmax = sqrt(double(gratScanObsTime)) * noiseCmax / sqrt(intTime);
        noiseCref = sqrt(double(gratScanObsTime)) * noiseCref / sqrt(intTime);
        noiseLmin = sqrt(double(gratScanObsTime)) * noiseLmin / sqrt(intTime);
        noiseLmax = sqrt(double(gratScanObsTime)) * noiseLmax / sqrt(intTime);
        noiseLref = sqrt(double(gratScanObsTime)) * noiseLref / sqrt(intTime);
    }
    if(verbose) {
        debug_print("AuxRMS:nbOBS/nbOFF: " + nbOBS + "/" + nbOFF);
        //      debug_print("AuxRMS:rmsCONT min/max: " + noiseCmin + "/" + noiseCmax);
        debug_print("AuxRMS:RMScont min/waveMin: " + noiseCmin + " [Jy] at " + waveCmin);
        debug_print("AuxRMS:RMScont max/waveMax: " + noiseCmax + " [Jy] at " + waveCmax);
        debug_print("AuxRMS:RMScont ref/waveRef: " + noiseCref + " [Jy] at " + waveRef);
        //      debug_print("AuxRMS:rmsLINE min/max: " + noiseLmin + "/" + noiseLmax);
        debug_print("AuxRMS:RMSline min/waveMin: " + noiseLmin + " [Jy] at " + waveLmin);
        debug_print("AuxRMS:RMSline max/waveMax: " + noiseLmax + " [Jy] at " + waveLmax);
        debug_print("AuxRMS:RMSline ref/waveRef: " + noiseLref + " [Jy] at " + waveRef);
    }
    // Copy results to noiseWave and return
    double[] noiseWave = [0.0];
    //   CONTinuum
    noiseWave[0] = waveCmin;
    noiseWave[1] = noiseCmin;
    noiseWave[2] = waveCmax;
    noiseWave[3] = noiseCmax;
    //   LINE
    noiseWave[4] = waveLmin;
    noiseWave[5] = noiseLmin;
    noiseWave[6] = waveLmax;
    noiseWave[7] = noiseLmax;
    //   CONT and LINE for refWave     
    noiseWave[8] = waveRef;
    noiseWave[9] = noiseCref;
    noiseWave[10] = noiseLref;
    if(verbose) {
        debug_print("AuxRMS:arrayID: " + arrayID);
    }

    return {arrayID,noiseWave,wave,rmsNoiseC,rmsNoiseL};
}

// Missionphase  : 
//
// Purpose       : Enable/disable the chopper electronics
//
// Author CUS    : Diego A. Cesarsky (diego.cesarsky@mpe.mpg.de)
//
// Author TCL    : N/A
//
// Original TCL  : N/A
//
// Input arguments
// Type    Name          DefVal   Description
// string  on_off        "ON"     ON: Enable chopper, OFF: Disable
//
// Description   : 
//
// Dependencies  : 
//                 
// Comments      : 
//
// Version       : 0.3
// History       : 0.1 23-Aug-2004 First creation
//                 0.2 13-apr-2005 DAC Renamed and modified
//                                 Enable_disable_chopper procedure
//                 0.3  8-mar-2007 Added 10sec delay between SWON and ENABLE
//                                 (HD's e-mail)
//               :
//
procedure CHOP_on_off {
    string on_off = "ON" in ["ON","OFF"]; //Enable/Disable chopper
}{
    if(on_off == "ON") {
        Pacs_DMC_SWON_CHOP_CONT();
        delay(10);
        Pacs_DMC_ENABLE_CHOP_CONT();
    }
    // Disable
    if(on_off == "OFF") {
        Pacs_DMC_DISABLE_CHOP_CONT();
        Pacs_DMC_SWOF_CHOP_CONT();
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_Sequencer_Setup {
    /* No variables to call PacsEng_Phot_Sequencer_Setup                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_Sequencer_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_Sequencer_Setup()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_Sequencer_Setup();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Phot_SFT_Cooler.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Performing a cooler short functional test in the cold
//
// Author        : T. Mueller
// CUSification  : DAC
// Arguments     : none
//
// Description   : Between 2 and 4 Kelvin all thermal switches are open.
//                 Setting of SP_heater_current to 2 mA: "TEMP_SP" increases
//                 and perhaps a very little change on "TEMP_EV".
//                 Setting of HSE_heater current to 0.5 mA: "TEMP_EV_SWITCH"
//                 will increase.
//                 Setting HSP_heater current to 0.5 mA: "TEMP_SP_SWITCH"
//                 will increase.
//                 Resetting of all currents to 0mA: temperatures will decrease.
//
// Comments      :  Based on Email by Eric Doumayrou, 18/Nov/2004
//
// Version       : 1.0
// History       : 1.0 / 18-Nov-2004 initial version by TM
//                 1.1    7-mar-2006 SEND_COMMAND_TO_BOLC renamed
//                 1.2 10-apr-2006 Review for FM
//                 1.3 22-jun-2007 TM: AF21 disabled before running this script and
//                                                  enable after (+ switches for AF18)
//
procedure PACS_Phot_SFT_Cooler {
}{
    //-------------------------------
    // disable AF 21 (to check if the absolute value of the HSP current is below 2*10^(-5)A)
    //-------------------------------
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_SP1","DISABLE");
    // enable AF 18 (to check if the current of the sorption pump heater is below 30mA)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_SP2","ENABLE");
    //-------------------------------
    // Set HK list to PHOT
    //-------------------------------
    // DPU_SET_HK_LIST (PHOT HK_PACKT_ID=2;
    //           SPU_ARRAY: 1 for both channels, 2 for blue chan, 3: for red chan)
    // PC003380 "DPU_SET_HK_LIST" SET THE PREDIFINED LIST OF HK VALUES
    //                            FOR THE HK PACKET
    //         PP005380 "HK_PACKT_ID"
    //         PP025380 "SPU_ARRAY"
    // tcsend PC003380 {PP005380 2} {PP025380 1}
    // waittime 0.5
    Pacs_DPU_SET_HK_LIST("PHOT","BOTH Array");
    //----------------------------------------------------------------
    // Short function test of cooler between 2 and 4 K environment
    //----------------------------------------------------------------
    // Set SP heater current to  to 0.002 amperes (2mA)
    // P 07 01 00AE
    // tcsend PC103420 {PP071420 0x070100AE LO}; waittime 0.5
    // waittime 120.0
    int operand = 0x70100ae;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(120);
    // Set HSE heater current to  to 0.0005 amperes (0.5mA)
    // P 07 03 04FB
    // tcsend PC103420 {PP071420 0x070304FB LO}; waittime 0.5
    // waittime 120.0
    operand = 0x70304fb;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(120);
    // Set HSP heater current to  to 0.0005 amperes (0.5mA)
    // P 07 02 04FB
    // tcsend PC103420 {PP071420 0x070204FB LO}; waittime 0.5
    // waittime 120.0
    operand = 0x70204fb;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(120);
    //----------
    // Resetting
    //----------
    // Set SP heater current to  to 0mA
    // P 07 01 0000
    // tcsend PC103420 {PP071420 0x07010000 LO}; waittime 0.5
    // waittime 0.5
    operand = 0x7010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set HSE heater current to  to 0mA
    // P 07 03 0000
    // tcsend PC103420 {PP071420 0x07030000 LO}; waittime 0.5
    // waittime 0.5
    operand = 0x7030000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set HSP heater current to  to 0mA
    // P 07 02 0000
    // tcsend PC103420 {PP071420 0x07020000 LO}; waittime 0.5
    // waittime 0.5
    operand = 0x7020000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //--------------------
    // disable AF 18 (to check if the current of the sorption pump heater is below 30mA)
    //--------------------
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_SP2","DISABLE");
    // enable AF 21 (to check if the absolute value of the HSP current is below 2*10^(-5)A)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_SP1","ENABLE");
    //-----------------------
    // end of procedure
    //-----------------------
    sync();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_Fil_Diaghk_Setup {
    /* No variables to call PacsEng_Phot_Fil_Diaghk_Setup                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_Fil_Diaghk_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_Fil_Diaghk_Setup()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_Fil_Diaghk_Setup();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id:
// Missionphase  : Operations
//
// Purpose       : Estimate several PACS parameters for each spectral
//                 range specified by the HSPOT user
//
// CUS author    : DAC
// Script file   : PacsRangeSpecEstimatorOBCP35.txt
//
// Input arguments
// type           name       Description
//
// Return values
// Type    Description
// tuple  {confSPECblu,confSPECred,confOBCP,{extension}}
//
// Description   : 
//
// Dependencies  : 
//
// Preconditions :
//
// Comments      : 
// 
// History       : 0.1 21-jun-2005 DAC Based on PacsLineSpecEstimator
// 		 : 1,0 VD OBCP35
//
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsRangeSpecEstimatorOBCP35 {
    /* rangeSPOT from HSPOT (but already sorted                            */
    {string,double,double,int,double,double,double,string,string,double} rangeSPOT = {"",0.0,0.0,0,0.0,0.0,0.0,"","",0.0};
    /* rangeInfo tuple derived from HSPOT                                  */
    {string,int,int,int,int,double,double} rangeInfo = {"NONE",0,0,0,0,0.0,0.0};
    /* union of SPECconf and OBCPconf                                      */
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    /* nodding yes/no needed to double/not OBCP duration                  */
    bool noddingSel = false;
    /* good old verbose                                                   */
    bool verbose = true; // Print bla-bla
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    // Gather information pertaining to the current range
    int order = rangeInfo{1};
    int grat_start_pos = rangeInfo{2};
    int grat_stop_pos = rangeInfo{3};
    int grat_step_up = rangeInfo{4};
    // Use different CAL files if RANGE or SED
    bool sedOBS = false;
    if(rangeInfo{0} == "SED") {
        sedOBS = true;
    }
    // Compute number of steps to go from grat_start_pos to grat_stop_pos stepping
    // by "grat_step_up" steps
    double aux_step = double(grat_stop_pos - grat_start_pos) / double(grat_step_up);
    int nb_grat_step_up = iround(abs(aux_step));
    // step_size may be negative...
    if(grat_stop_pos < grat_start_pos) {
        grat_step_up = -grat_step_up;
    }
    if(verbose) {
        debug_print("OBCP35: order/startGRAT/stopGRAT/stepGRAT/nbSTEP " + order + "/" + grat_start_pos + "/" + grat_stop_pos + "/" + grat_step_up + "/" + nb_grat_step_up);
    }
    // SCR-3663 Do not allow less than 16 steps
    if(nb_grat_step_up < 16) {
        error("Input range results in only " + nb_grat_step_up + " grating steps; minimum number of steps is 16. Increase range");
    }
    // Update corresponding elements of confOBCP
    int nb_grat_step_dn = nb_grat_step_up;
    int grat_step_dn = -grat_step_up;
    // Get "duration related" parameters from OBCP35params U-CAL table
    string calNAME = "OBCP35params";
    // The acces key is the grating order (times 10 for SED mode!)
    if(verbose) {
        debug_print("order: " + order);
    }
    string key = "" + order;
    // SED rows are (completely arbitrarily!) called 20 and 30   
    if(sedOBS) {
        key = "" + 10 * order;
    }
    // There is a row per order; it lists main OBCP parameters
    //     int nb_up_down       = ilookup(calNAME,key,"nb_up_down");
    //   User desired repeat factor for current line replaces nb_up_down
    int nb_up_down = rangeSPOT{3};
    //   Don't allow null number of repetitions
    if(nb_up_down == 0) {
        nb_up_down = 1;
    }
    int nb_SRC_OFF = ilookup(calNAME,key,"nb_SRC_OFF");
    int nb_ramps_plateau = ilookup(calNAME,key,"nb_ramps_plateau");
    int nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    //   Need nb_rdouts (different according to faintLines)
    int nb_rdouts = confSPECblu{1};
    // Estimate the OBS time for this rangeInfo
    int[] dureeOBCP35 = PacsDureeOBCP35(nb_up_down,nb_grat_step_up,nb_ramps_plateau,nb_CS1_CS2,nb_SRC_OFF,nb_rdouts);
    if(verbose) {
        debug_print("++Duration DMC: " + dureeOBCP35);
    }
    // Return SRC+REF (used to be total duration)
    int quantumOBStime = dureeOBCP35[1] + dureeOBCP35[2];
    // Get the "quantum" OBS time for the current order. OBCP duration doubles if 
    // nodding is allowed
    int nodFactor = 1;
    int nb_nods = 1;
    if(noddingSel) {
        nodFactor = 2;
    } else {
        nb_nods = 0;
    }
    quantumOBStime = nodFactor * quantumOBStime;
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    if(noddingSel) {
        msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + rangeSPOT{1} + "/" + rangeSPOT{2} + " [&micro;m] range repeated " + nb_up_down + " time(s)</p>";
    } else {
        msgLine[lineCnt] = "<p>Estimated SRC+CalSrce time: " + quantumOBStime + " [sec] for " + rangeSPOT{1} + "-" + rangeSPOT{2} + " [&micro;m] range repeated " + nb_up_down + " time(s)</p>";
    }
    if(verbose) {
        debug_print("OBCP35: SRC+REF minimum " + quantumOBStime + " [sec] for " + rangeSPOT{1} + " - " + rangeSPOT{2} + " [&micro;m] range with " + nb_up_down + " repetition(s)");
    }
    lineCnt = lineCnt + 1;
    // Alessandra SRC-3513 would come here. Compute velocity range with respect 
    // to WaveRef line (last entry in rangeSPOT)
    // Light speed km/sec
    double clight = 300000.0;
    // Just in case WaveRef is null
    if(abs(rangeSPOT{9}) > 1.0E-4) {
        //    Velocity at each end-of-range
        double vblu = clight * (rangeSPOT{1} - rangeSPOT{9}) / rangeSPOT{9};
        double vred = clight * (rangeSPOT{2} - rangeSPOT{9}) / rangeSPOT{9};
        if(verbose) {
            debug_print("OBCP35: RANGE VELOCITY: " + dformat(vblu,1) + "/" + dformat(vred,1));
        }
        msgLine[lineCnt] = "<p>Velocity range from WaveRef = " + dformat(rangeSPOT{9},2) + " [&micro;m]; blue/red: " + dformat(vblu,1) + "/" + dformat(vred,1) + " km/sec</p>";
        lineCnt = lineCnt + 1;
    }
    // Some more Pointing parameters (auxN just in case I need more...)
    int aux2 = 0;
    int aux3 = 0;
    // Pack information into proper tuples
    confOBCP{0} = nb_up_down;
    confOBCP{1} = grat_step_up;
    confOBCP{2} = grat_step_dn;
    confOBCP{3} = nb_SRC_OFF;
    confOBCP{4} = nb_ramps_plateau;
    confOBCP{5} = nb_CS1_CS2;
    confOBCP{6} = nb_grat_step_up;
    confOBCP{7} = nb_grat_step_dn;
    confOBCP{8} = grat_start_pos;
    //    confOBCP { 9}  =   grat_start_time  ;
    //    confOBCP {10}  =   grat_def_pos     ;
    //    confOBCP {11}  =   grat_def_time    ;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    //   confSPECred{ 0} =  capa_red;
    //   confSPECred{ 1} =  nb_rdouts;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    int comp_mode_red = 16;
    confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    //   confSPECblu{ 0} =  capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    int comp_mode_blu = 16;
    confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    string msgLabel = "Observing time for " + rangeSPOT{0};
    PacsMessageCenter(msgLabel,lineCnt,msgLine);
    // Debug info
    if(verbose) {
        debug_print("RangeEstimatorOBCP35 duration: " + quantumOBStime);
    }

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,nb_up_down,quantumOBStime,aux3}};
}

// File          : PACS_Spec_Heat_FFT.cus
//
// Purpose       : Heaters Functional Test
//
// Author        : P. Royer
//
// Arguments     :
//
// Description   : Sends 2 current to both heaters 
//
//
// Prerequisite : 
//	  The correct HK & Diaghk lists are already set & acquired
//
// Comments      : 
//                 
//
// Version       : 2.0
// History       : 1.0 05-Apr-2007 initial version by PR
// 		 : 2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose Heaters Functional Test
// @comment - 
//
procedure Pacs_Spec_Heat_FFT {
}{
    //
    // SWON the heaters
    PACS_Spec_Heat_SWON();
    //
    // 2.0mA  -> 2.5 mA  ->  0.0 mA
    //
    PACS_Spec_Heat_Setup(410,410);
    delay(540);
    PACS_Spec_Heat_Setup(512,512);
    delay(540);
    PACS_Spec_Heat_Setup(0,0);
    delay(30);
    //
    // SWOF the heaters
    PACS_Spec_Heat_SWOF();
    //
}

// $Id$
// Missionphase  : PACS PV Phase
//
// File          : PACS_Chopper_EnDis_Test_ast1_OBS.cus
//
//
// Missionphase  : PACS IST Chopper Day
//
// Purpose       : Switch-on/switch-off and enanle/disable test of chopper
//
// Author        : MN/HD
// CUSification  : MN/HD
// Arguments     :
//
// Description   : This script allows to insert a duration in seconds during
//                 which the chopper is switched-on and enabled. This is used
//                 to evaluate the
//                 stability of the chopper while selecting various chopper
//                 control parameters.
//
// Comments      :
//
// Version       : 4.0
// History       : 1.0 20-Mar-2007 initial version
//		   2.0 05-Jul-2007 IST Chopper Day
//		   3.0 12-Nov-2007 edited for SVT/PV conformance
//		   4.0 04-mar-2008 translated into PV phase script VDP
//
obs PacsEng_Chopper_EnDis_Test_ast1 {
    /* Needed variables to call PacsEng_Chopper_EnDis_Test_ast1                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Chopper_EnDis_Test_ast1                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Chopper_EnDis_Test_NoConf_ast1()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Chopper_EnDis_Test_NoConf_ast1();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : 
//                  
//                 
//
// OBCP author   : HF
// TCL file      : N/A
// CUS author    : DAC
// Script file   : OBCP_27_grat_line_scan_chopped_2.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Belongs to Section 3.8: Grating Spectral Line Scan 
//                 of PACS-ME-LI-005
//                 Consists mainly of a sequence with repetitive up- and
//                 down-scans with the grating around a given center position,
//                 while the chopper is operating as well on either two- or
//                 three-positions. This is OBCP 3.8.2, calling DMC sequence
//                 12 (in 4.2.2)
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 19-apr-2005 DAC
//                 0.2 22-apr-2005 Rearranged arguments P#1 P#2 etc.
//                 0.3 25-apr-2005 DAC Use same defaults as TM's scripts
//                 0.4 27-apr-2005 DAC MIB name is GRAT_SCAN_CHOP2 (not _2)
//                 0.5 20-sep-2005 Wrong sign for grat_step_dn
//                 0.6 26-mar-2008 modify BB ID because of duplicate with OBCP_grat_scan_chop_2.txt
//
int[] block OBCP_grat_line_scan_chop_2 PACS 21 {
    int nb_up_down = 1; // Nb of "up-down" sequences (P#1); 
    int nb_grat_steps = 20; // Nb of grating steps (P#2)
    int nb_cycles_grat_pos = 2; // Nb of cycles per grating position (P#3); 
    int chop_pos_REF1 = 1000; // Chopper position 1 (P#4) 
    int nb_ramps_plateau = 3; // Nb of readouts per chopper position (P#5); 
    int chop_pos_REF2 = 3000; // Chopper position 2 (P#6)
    int nb_CS1_CS2 = 1; // Nb of cycles on the internal CSs (P#7); 
    int chop_pos_CS1 = -25000; // Chopper position on CS1 (P#8)
    int chop_pos_CS2 = 25000; // Chopper position on CS2 (P#9)
    int grat_step_up = 1600; // Grating step up (P#10) 
    int grat_step_dn = -1600; // Grating step down (P#11) 
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 445000; // Starting grating position
    int grat_time = 40000; // Grating time to move to start [msec]
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopper default position
    int grat_def_time = 20000; // Time to come back to default position
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duree_msec [msec] as it goes)
    // Begin 
    // OBCP_GRATING_LINE_SCAN_CHOPPED_2(seq, seq_time,
    //   P#1,&,P#11, detector, grat_def, grat_time,
    //   cmp_par_blue, cmp_par_red, grat_def, chop_def, grat_time)
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) ; (all parameters filled 
    // by DPU based on seq parameter) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_time) 
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    // DMC_START_SEQUENCE
    //////////////////////////////////////////////////////////////////////////
    // Call DC/MEC code to estimate its duration
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    int[] duree1 = DMC_12_grat_line_scan(nb_up_down,nb_grat_steps,nb_ramps_plateau,nb_CS1_CS2,nb_cycles_grat_pos);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    debug_print("Execution time [msec] from DMC: " + seq_time);
    // duree_msec(seq_time) 
    duree_msec = duree_msec + t_cmd + seq_time;
    // WAIT(seq_time) ; Check execution status of the sequence and in case of 
    // failure stop OBCP and issue TM(1,8)+event 
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_def_time) 
    duree_msec = duree_msec + grat_def_time;
    duree_OVR = duree_OVR + grat_def_time;
    // Issue TM(1,7)
    // End 
    // Now trigger execution of OBCP
    // This OBCP is number 27, requires 21 parameters and calls DEC/MEC #12
    string obcp_ID = "GRAT_SCAN_CHOP2";
    int obcp_par_nb = 21;
    int seq_DMC = 12;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_grat_steps},{5,nb_cycles_grat_pos},{6,chop_pos_REF1},{7,nb_ramps_plateau},{8,chop_pos_REF2},{9,nb_CS1_CS2},{10,chop_pos_CS1},{11,chop_pos_CS2},{12,grat_step_up},{13,grat_step_dn},{14,detector},{15,grat_pos},{16,grat_time},{17,comp_mode_blu},{18,comp_mode_red},{19,grat_def},{20,chop_def},{21,grat_def_time}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    debug_print(obcp_ID + ": " + time_array);
    delay(time_array[0]);
    // Return the array of times

    return time_array;
}

// Missionphase  : 
//
// Purpose       : 
//                  
//                 
//
// OBCP author   : HF
// TCL file      : N/A
// CUS author    : VD (based on DAC)
// Script file   : OBCP_grat_line_scan_chopped_3.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Belongs to Section 3.7: Grating Spectral Line Scan 
//                 of PACS-ME-LI-005
//                 Consists mainly of a sequence with repetitive up- and
//                 down-scans with the grating around a given center position,
//                 while the chopper is operating on ABBA pattern: section
//		   3.7.6 (ABBA chopping OBCP 35, DMC 19)
//
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 VD (based on DAC)
//                    0.2 TM modified for compliance with DPU OBSW code
//                 1.0 18-jun-2009 DAC Added logic to perform the CAL
//                                 using the science loop, i.e. the ABBA
//                                 We recognize that a CAL is intended when
//                                 nb_CS1_CS2 is different from zero.
//		   2.0 23-jun-2009 VD .. back to JUST science
// NOTE: The same change is performed in DMC_19 to obtain the right CAL
//       times
//
int[] block OBCP_grat_line_scan_chop_3 PACS 35 {
    int nb_up_down = 1; // Nb of "up-down" sequences (P#1); 
    int nb_grat_steps = 16; // Nb of grating steps (P#2)
    int grat_step_up = 168; // Grating step up (P#3) 
    int nb_ABBA_sci = 2; // Nb of on-sky cycles per grating position (P#4); 
    int chop_REF1 = -1000; // Chopper position 1 SRC (P#5) 
    int nb_ramps_plateau = 3; // Nb of readouts per chopper position (P#6); 
    int chop_REF2 = 2000; // Chopper position 2 REF (P#7)
    int nb_CS1_CS2 = 0; // Nb of cycles on the internal CSs (P#8); 
    int chop_CS1 = -21350; // Chopper position on CS1 (P#9)
    int chop_CS2 = 21200; // Chopper position on CS2 (P#10)
    int grat_step_dn = -168; // Grating step down (P#11) 
    int detector = 1; // Synchronize on this detector 1:Blue 2:Red
    int grat_pos = 445000; // Starting grating position
    int grat_time = 40000; // Grating time to move to start [msec]
    int comp_mode_blu = 16; // "Blue" compression
    int comp_mode_red = 16; // "Red" compression 
    int grat_def = 500000; // Grating default position
    int chop_def = 0; // Chopper default position
    int grat_def_time = 20000; // Time to come back to default position
    int nb_rdouts_ramp = 64; // Number of readouts per ramp
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_rdouts = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain some parameters from table PACSparams
    // Spectro sampling rate (needed to compute ramp duree)
    double spec_sample = dlookup("PACSparams","spec_sample","freq_time");
    string spec_unit = slookup("PACSparams","spec_sample","unit");
    double ramp_time = 1000.0 * double(nb_rdouts_ramp) / spec_sample;
    //    debug_print("Spectro_sample: " + spec_sample + " " + spec_unit);
    //    debug_print("Ramp duree: " + ramp_time + "[msec]");
    // Obtain duree of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duree of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duree of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duree_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duree_msec [msec] as it goes)
    // Begin 
    // OBCP_GRATING_LINE_SCAN_CHOPPED_3(seq, seq_time,
    //   P#1,&,P#11, detector, grat_def, grat_time,
    //   cmp_par_blue, cmp_par_red, grat_def, chop_def, grat_time)
    // DMC_WRT_TIME (DPU_TIME in standard 48 bit format according to PS-ICD) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SET_TIME 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(P#5)
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SEQ_BUFFER(ID, LENGTH, DATA, CHECKSUM) ; (all parameters filled 
    // by DPU based on seq parameter) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_SYNCHRONIZE_ON_DET(detector) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_WRT_SPU_TRAN_MODE(ID, 2, cmp_par_blue, cmp_par_red, CHHKSUM) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_time) 
    duree_msec = duree_msec + grat_time;
    duree_OVR = duree_OVR + grat_time;
    // DMC_START_SEQUENCE
    //////////////////////////////////////////////////////////////////////////
    // Call DC/MEC code to estimate its duration
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    int[] duree1 = DMC_19_grat_line_scan(nb_up_down,nb_grat_steps,nb_ramps_plateau,nb_CS1_CS2,nb_ABBA_sci);
    // Convert array "duree1" into [msec]
    int seq_time = iround(double(duree1[0]) * ramp_time) + dmc_margin;
    duree_SRC = iround(double(duree1[1]) * ramp_time);
    duree_REF = iround(double(duree1[2]) * ramp_time);
    duree_CAL = iround(double(duree1[3]) * ramp_time);
    duree_OVR = duree_OVR + iround(double(duree1[4]) * ramp_time) + dmc_margin;
    //    debug_print("Execution time [msec] from DMC: " + seq_time);
    // duree_msec(seq_time) 
    duree_msec = duree_msec + t_cmd + seq_time;
    // WAIT(seq_time) ; Check execution status of the sequence and in case of 
    // failure stop OBCP and issue TM(1,8)+event 
    // DMC_MOVE_GRAT_ABS(grat_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DMC_MOVE_CHOP_ABS(chop_def) 
    duree_msec = duree_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(grat_def_time) 
    duree_msec = duree_msec + grat_def_time;
    duree_OVR = duree_OVR + grat_def_time;
    // Issue TM(1,7)
    // End 
    // Now trigger execution of OBCP
    // This OBCP is number 35, requires 21 parameters and calls DEC/MEC #19
    //string obcp_ID = "GRAT_SCAN_CHOP3";
    int obcp_ID = 35;
    int obcp_par_nb = 21;
    int seq_DMC = 19;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_up_down},{4,nb_grat_steps},{5,grat_step_up},{6,nb_ABBA_sci},{7,chop_REF1},{8,nb_ramps_plateau},{9,chop_REF2},{10,nb_CS1_CS2},{11,chop_CS1},{12,chop_CS2},{13,grat_step_dn},{14,detector},{15,grat_pos},{16,grat_time},{17,comp_mode_blu},{18,comp_mode_red},{19,grat_def},{20,chop_def},{21,grat_def_time}];
    //    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nb,grp);
    Pacs_DPU_START_OBCP_RAW(obcp_ID,obcp_par_nb,grp);
    // Add the "communication jitter"
    duree_msec = duree_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Define time_array (return to caller)
    int[] time_array = [duree_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    // and convert from [msec] to [sec]
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    //    debug_print(obcp_ID + ": " + time_array);
    delay(time_array[0]);
    // Return the array of times

    return time_array;
}

// Missionphase  : FM
//
// Purpose	:  Chopper Scan in one waz
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: This script has the purpose to be used for  a chopper scan both in photometric
//                and spectrometric mode. The parameters needed are start position,
//	          step length, number of steps and observing time on each position. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on
//                 
// Comments	: This script is based on the commanding during CQM ILT.
//
// Version	: 3.0	
// 
// History 	: 1.0 21-07-06 creation by HD. Based on EQM IMT script "Chop_scan"
//		  3.0 26-07-06 HD. script works.
//
block PACS_Chopper_one_way_scan_fm_bb PACS 356 {
    int chop_start_pos = 0; // chopper start position
    int chop_step_length = 100; // chopper step length
    int chop_step_number = 10; // chopper step number
    int chop_obs_time = 5; // observing time on chopper position in seconds     
}{
    // Register start of BB
    WriteBBID($BBID);
    //-------------------
    // Scan 
    //-------------------
    // Begin with the Scan from chop_start_pos and do chop_step_number times the step of length
    // chop_step_length and observe obs_time seconds on each position
    Pacs_DMC_MOVE_CHOP_ABS(chop_start_pos);
    delay(chop_obs_time);
    // counter n
    int n = 1;
    while(n <= chop_step_number) {
        Pacs_DMC_MOVE_CHOP_REL(chop_step_length);
        delay(chop_obs_time);
        n = n + 1;
    }
    // Mark End of Block
    WriteEndBB();
}

/////////////////////////////////////////////////////////////////////////////
/// $Id
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsLineSpec AOT
//
// CUS author    : DAC
//
// Input arguments: see after module identification
//
// Return values
// {int,int,int} {totalDuration,slewDuration,obsOverPACSandSC}
//
// Comments      : If this file is called PacsLineSpecObs.def, it is the 
//                 CUSGUI version. To use with HSPOT:
//                 - copy and rename PacsLineSpec.def
//                 - rename obs module to PacsLineSpec
//                 - remove extra code for CUSGUI
//                 - do not forget to set verbose = false !!
//
// History: 
// 25-apr-2007 14.0 For earlier history see v1.37 in CVS
//                  Removed history up to today
// 22-may-2007 14.1 SPR-3199 Return only SRC+REF time
// 29-may-2007 14.2 SPR-3237 Use map orientation parameter
// 11-jun-2007 14.3 Count WAIT=1 for grating in OBCP22 as SRC/REF
// 20-sep-2007 14.4 SCR-3552. Correct pattnod with skewCorrec in PACSyzoffsets
// 15-oct-2007 15.0 SCR-3691
//                  Add state=4 (OFF) in the StateMachine logic. Ready to
//                  implement raster with OFF for pointing 21 & 31
// 22-oct-2007 15.1 FreqSwitch only allowed with source="large"
//                  Introduce RAoff DECoff as in PacsRange
// 23-oct-2007 15.2 UserNodCycles is now a rasterRepeat factor for
//                  FreqSwitch (it was a cycle repeater)
// 16-dec-2007 15.3 SPR-3830 (RAoff,DECoff out of boundaries)
// 14-jan-2008 16.0 Use standard names for RA,DEC
// 13-may-2008 17.0 SCR-3699 Implemented raoff and decoff refSelected 
// 13-oct-2008 18.0 implemented Default Line values for HSC deliveries
// 	       	    Default Buggy: need to only take default values if
//		    length(lines) == 0
// 22-apr-2009 19.0 VD SPR5447: added KeyWL as fnct of order+filter comb.
// 23-apr-2009 20.0 VD SPR 6482
//  4-jun-2009 20.1 DAC Use new OBCP32 for FreqSwitch and OBCP35 for CalSlew
// 16-jun-2009 21.0 DAC Use OBCP35 for science as well (already in CalSlew)
// 10-jul-2009 22.0 VD adds detector sync in PacsSpecDefaults 
// 03-sep-2009 23.0 VD PHS-200 (doSlewScience for turning on science dataflow at slew time) 
// 14-sep-2009 24.0 VD PHS-1174 use grat_keyWave 
// 15-oct-2009 25.0 VD PHS-1220 SPEC_NOD_params: decouple ND from chop throw
// 16-oct-2009 VD PHS-1221: enable BOTH channels
// 27-oct-2009 VD PHS-1227 dis-able doSlewScience (hardcode == false)
// 26-nov-2009 VD PHS-1266 Wavelength switching and Raster map angle
// 11-dec-2009 VD PHS-193 capacitance switching as function of Line and cont. flux densities
// 15-jan.2010 VD PHS-193 added user's message relative to capa switch
// 08-feb-2010 VD PHS-1308 WS needs to include the nbNod
// 20-apr-2010 VD PHS-1385 unchopped line scan: OBCP28 in use
// 28-apr-2010 VD PHS-1385 oops Line repeat 1 minimum
// 05-may-2010 VD PHS-1385 cont'd RMS for un-chopped via freqSwitch
// 07-may-2010 VD PHS-1385 and PHS-1393 compatibiliy
// 10-may-2010 VD removed.. changed back to SPEC_get_grat_info_unchop
// 10-may-2010 VD PHS.. Hspot 5.0 as PacsLineSpec
// 13-may-2010 VD PHS-1416, PHS-1417
// 20-may-2010 VD PHS-1429
// 26-may-2010 VD PHS-1444 chopNod / gratScan for SPEC_get_grat_info_unchop
// 09-jun-2010 VD PHS-1451 CUS fix instead of Hspot fix. Hspot uses (mistakingly)
//                         mapGratScanOffRepeat instaed of gratScanOffRepeat
// 16-jun-2010 VD PHS-1467 constrain pattnod to [0,360] and gratScan NODs in sky coordinates
// 16-jun-2010 VD PHS-1466 sensitivy in un-chopped mode: must be also scaled for the nb of cycles
//
{int,int,int} obs PacsLineSpec {
    /* "lines" is defined as an array; its elements (and hence its dimension) */
    /*  are provided by HSPOT */
    /* {id,redshifted wavelength,repeat factor,line flux,continuum flux,      */
    /*  line width,line flux unit,line width unit}                            */
    {string,double,int,double,double,double,string,string}[] lines = []; //Filled by HSPOT
    /*------------- following only to use CUS interface -------------------------*/
    string[] lineId = ["My lines"];
    double[] lWave = [82.0]; // line wavelength  in [55.0,210.0]
    int[] repeatLine = [1]; // repeat line in [0,10]
    double[] lineFlux = [1000.0]; // Line Flux in [0.0,10000.0]
    double[] lcontFlux = [200.0]; // Continuum flux  in [0.0,10000.0]
    double[] lineWidth = [30.0];
    string[] fluxUnit = ["Jy/m2"];
    string[] widthUnit = ["kms"];
    /*------------- above only to use CUS interface -------------------------*/
    int userNODcycles = 1 in [1,100];
    string orderSel = "order2" in ["order2","order3"];
    bool chopNod = true;
    /* new Hspot parameters PHS 1385 +PHS-1451 */
    bool gratScan = false;
    int mapGratScanOffRep = 2; // repeat OFF in Raster if != m*n (== 2 off) 
    /* end */
    bool faintLines = true;
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    string throw = "large" in ["large","medium","small"];
    string source = "point" in ["point","dithered","large"];
    double mapRasterAngle = 0.0 in [0.0,360.0];
    bool mapRasterAngleRefFrame = true;
    int m = 3 in [2,32];
    int n = 3 in [1,32];
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    bool refSelected = false;
    double raoff = 0.0 in [0.0,360.0];
    double decoff = 0.0 in [-90.0,90.0];
    int naifid = 0; // RA,DEC or SSO
    double pointStep = 20.0 in [2.0,480.0];
    double lineStep = 20.0 in [2.0,480.0];
    string redshiftType = "redshift" in ["redshift","optical"];
    double redshiftValue = 0.0;
    int obsOverhead = 180; // Slew overhead
    bool verbose = false;
}{
    //*--------- following only when using CUS interface -------------------*/
    int linesIdLength = length(lineId);
    int linesLength = length(lines);
    if(linesLength == 0) {
        for(int lLoop00 = 0 .. linesIdLength - 1) {
            lines[lLoop00] = {lineId[lLoop00],lWave[lLoop00],repeatLine[lLoop00],lineFlux[lLoop00],lcontFlux[lLoop00],lineWidth[lLoop00],fluxUnit[lLoop00],widthUnit[lLoop00]};
        }
    }
    //PHS-1385 making sure that chopNod and gratScan are NOT true toghether
    if(chopNod && gratScan) {
        error("This observing mode is NOT allowed");
    }
    if(!chopNod && !gratScan) {
        error("This observing mode is NOT allowed");
    }
    //*--------- above only when using CUS interface -------------------*/
    // PHS-1451 aliasing
    int gratScanOffRep = mapGratScanOffRep;
    // Start of "Pointing" section
    // 
    // New variable to start at nodded position
    bool startAtOFF = false;
    // extraConf: whatever affects PACS default configuration 
    // Currently: the option faintLines calls for an extraConf
    string extraConf = "normal";
    // For bright lines
    if(!faintLines && chopNod) {
        extraConf = "bright";
    } else {
        extraConf = "normal";
    }
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // Need switching boolean
    if(!gratScan && !chopNod) {
        bool switching = true;
        string obsmode = "switching";
    } else {
        if(gratScan) {
            switching = false;
            obsmode = "gratScan";
        }
        if(chopNod) {
            switching = false;
            obsmode = "chopNod";
        }
    }
    // Switching only allowed with source "large"
    if(switching && source != "large") {
        error("Frequency Switch only in mode raster (large source) with OFF");
    }
    // Decode more HSPOT information
    int nbLines = length(lines);
    int nbLines1 = nbLines - 1;
    // Cannot call with empty "lines"
    if(nbLines == 0) {
        error("STOP!! There are no spectral lines defined!");
    }
    // No more than 10 lines or repetitions
    int nbLinesRep = 0;
    for(int loop00 = 0 .. nbLines - 1) {
        //  Default repetion factor is 1
        int repFactor = lines[loop00]{2};
        if(repFactor == 0) {
            repFactor = 1;
        }
        nbLinesRep = nbLinesRep + repFactor;
    }
    if(verbose) {
        debug_print("Total lines/repeat: " + nbLinesRep);
    }
    if(nbLinesRep > 10) {
        error("STOP!! The number of lines/repetitions exceeds 10");
    }
    // Establish now the applicable Pointing Mode (use same pointCase convention
    // used in PacsPhoto)
    // Pointing mode is undefined. If it remains undefined at the end of
    // the next tests, then there is a problem with the source definition
    int pointCase = 0;
    // FinePointingMode with setup time
    // POINT source, with and without chopNod
    if(source == "point") {
        //    For completiness define a 1x1 raster
        m = 1;
        n = 1;
        //    without nodding
        if(!chopNod) {
            string pointMode = "fine_pointing";
            string userMode = "Point source (no nodding)";
            if(switching) {
                userMode = "Point source (frequency switch, no nodding)";
                pointCase = 11;
            } else {
                // PHS-1385
                if(gratScan) {
                    userMode = "Point source un-chopped mode with nodding)";
                    pointCase = 12;
                }
            }
        } else {
            //    with nodding      
            pointMode = "composite_nodding";
            userMode = "Point source (nodding)";
            pointCase = 12;
        }
        string yzoffsetROW = "S" + pointCase;
    }
    // DITHERED source
    // For source "dithered" use predetermined raster parameters
    if(source == "dithered") {
        m = ilookup("SMALL_SRC_params","SPEC","mRast");
        n = ilookup("SMALL_SRC_params","SPEC","nRast");
        pointStep = dlookup("SMALL_SRC_params","SPEC","pointStep");
        lineStep = dlookup("SMALL_SRC_params","SPEC","lineStep");
        //    Raster mode without noding
        if(!chopNod) {
            pointMode = "repeated_raster_with_hold";
            userMode = "Small source (no nodding)";
            pointCase = 21;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Small source (nodding)";
            pointCase = 22;
        }
        yzoffsetROW = "S" + pointCase;
    }
    // For source "large" user given raster parameters
    if(source == "large") {
        //    Raster mode without noding
        if(!chopNod) {
            // valid for both WS and un-chopped
            pointMode = "repeated_raster_with_off";
            userMode = "Large source (no nodding)";
            pointCase = 31;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Large source (nodding)";
            pointCase = 32;
        }
        yzoffsetROW = "S" + pointCase;
    }
    // For symmetrical chopping, virtual apertures are dependent on the chopper
    // throw. Add this information to the CALU key entry
    yzoffsetROW = throw + "" + yzoffsetROW;
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("     PointCase ID: " + pointCase);
        debug_print("     PointMode   : " + pointMode);
        debug_print("     CALU entry  : " + yzoffsetROW);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        for(int iii = 0 .. nbLines1) {
            debug_print("MAIN:Id, Wave, repeat, Lflux, Cflux, etc. " + lines[iii]);
        }
    }
    // Define array of wavelengths (will be needed by the SORT procedure)
    double[] lineWave = [55.0];
    // Populate the array of wavelengths
    for(int loop0 = 0 .. nbLines1) {
        lineWave[loop0] = lines[loop0]{1};
    }
    // For each line obtain the grating order and the grating position 
    int[] orders = [0];
    double[] grat_pos = [0.0];
    // Fill the tuple waveTuple {waveLen,order,gratPos,nbStep,gratStep}
    {double,int,int,int,int}[] waveTuple = [{0.0,0,0,0,0}];
    for(int loop1 = 0 .. nbLines1) {
        waveTuple[loop1] = SPEC_get_grat_info_unchop(lineWave[loop1],"HI",obsmode,extraConf,orderSel,verbose);
        // 
        //      Create vector of intermediate results
        orders[loop1] = waveTuple[loop1]{1};
        grat_pos[loop1] = double(waveTuple[loop1]{2});
    }
    // To reject forbidden order combination, count how many orders
    int nORDER1 = 0;
    int nORDER2 = 0;
    int nORDER3 = 0;
    for(int loop2 = 0 .. nbLines1) {
        if(orders[loop2] == 1) {
            nORDER1 = nORDER1 + 1;
        }
        if(orders[loop2] == 2) {
            nORDER2 = nORDER2 + 1;
        }
        if(orders[loop2] == 3) {
            nORDER3 = nORDER3 + 1;
        }
    }
    // Reject mixed orders
    if(nORDER2 != 0 && nORDER3 != 0) {
        //    Report band limits
        double[] band2 = SPEC_BAND_read("L2");
        double[] band3 = SPEC_BAND_read("L3");
        error("Combination of 2nd (" + band2[0] + "-" + band2[1] + " mic) and 3rd (" + band3[0] + "-" + band3[1] + " mic) grating orders is not allowed");
    }
    // Reject lines not belonging to authorized order
    if(nORDER2 != 0 && orderSel == "order3") {
        error("You have chosen " + orderSel + " but have specified one/several order2 lines");
    }
    if(nORDER3 != 0 && orderSel == "order2") {
        error("You have chosen " + orderSel + " but have specified one/several order3 lines");
    }
    // Determine the filter needed with given lines
    // No filter needed, i.e. ORDER=1
    int filter = 1;
    // Determine filter based on HSPOT input
    if(orderSel == "order2") {
        filter = 2;
    }
    if(orderSel == "order3") {
        filter = 3;
    }
    if(verbose) {
        debug_print("ORDER array: " + orders);
    }
    // Filter below will be set by SPEC_aot_prologue via SlewCal
    if(verbose) {
        debug_print("MAIN:The full OBS will be performed with filter " + filter);
    }
    // Sort grat_pos from smallest to largest
    int[] sortIndex = SortProc(verbose,grat_pos);
    // Sort by wavelengths (from blue to red)
    // int sortIndex = SortProc(verbose,lineWave);
    // Recast "lines" and waveTuple according to the ordered grating positions
    {string,double,int,double,double,double,string,string}[] sortLines = [{"empty",0.0,0,0.0,0.0,0.0,"bla","bla"}];
    {double,int,int,int,int}[] sortWaveTuple = [{0.0,0,0,0,0}];
    for(int reSORT = 0 .. nbLines1) {
        //      Reversed sort
        // No reverse SORT (start observations with filter A)
        //        int revSORT         = nbLines1 - reSORT;
        int revSORT = reSORT;
        int sortedIndex = sortIndex[revSORT];
        sortLines[reSORT] = lines[sortedIndex];
        sortWaveTuple[reSORT] = waveTuple[sortedIndex];
        if(verbose) {
            debug_print("Sorted Line: " + sortLines[reSORT]);
        }
    }
    // The tuple arrays confOBCP, confSPECred, and confSPECblu play a major
    // role. They contain the parameters related to commanding different PACS
    // subsystems. They are susceptible of changing with the observing conditions.
    // Hence, they have to be watched for changes since these imply sending one or
    // more TCs (usually invoking a building block)
    // Define confOBCP array
    // confOBCP{0 -> 19} contains:
    // nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
    // nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
    // grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
    // chop_pos_SRC     chop_pos_REF1    chop_pos_REF2    chop_pos_CS1
    // chop_pos_CS2     chop_def         detector         order
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP_off = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP_simul = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confSPECblu and confSPECred
    // confSPEC contians:
    //   capa,       nb_rdouts_ramp, nb_rdouts_subramp, comp_mode,
    //   glitch_det, ramp_fit_alg,   nb_raw,            bias_r,    bias_d
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // Estimator module returns {confSPECblu,confSPECred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    // Obtain default values
    string throwUsage = throw;
    // Frequency switch parameters are as for offraster in PacsRange
    // (this will set REF1=REF2=CS1 but this is irrelevant for OBCP32)
    if(switching) {
        throwUsage = "offraster";
    }
    if(verbose) {
        debug_print("PacsLine:Use throw: " + throwUsage);
    }
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    double[] refWL = [sortLines[0]{1}];
    // actually rcover grat_keyWave instead
    {double,int} keys = PacsSpecKeyWaves_grat(orderSel,refWL);
    //    double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    double keyWL = keys{0};
    int grat_keyWL = keys{1};
    // PHS-1174 keyWave => grat_keyWave keyWave should be kept for info AND detector sync : user's friendly
    // 
    double[] keyWAVE = [keyWL];
    int[] grat_keyWAVE = [grat_keyWL];
    //    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,detector,verbose);
    //    cannot implement in PacsSpecDefaults because for the moment too many definitions depend on it
    //    so I implemented a very dirty trick BEURK!
    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // PHS-193
    //   debug_print("nbLines: " +nbLines);
    {int,double,double,double,double,string,double,string}[] forCapaSwitch = [{0,0.0,0.0,0.0,0.0,"",0.0,""}];
    for(int loopXY = 0 .. nbLines - 1) {
        forCapaSwitch[loopXY] = {confSPECblu[0]{0},lines[loopXY]{1},lines[loopXY]{3},lines[loopXY]{4},lines[loopXY]{5},lines[loopXY]{7},keyWAVE[0],orderSel};
        //      debug_print("forCapaSwitch: " +forCapaSwitch[loopXY]);
    }
    {bool,int} switchCapa = PacsSpecSwitchCapa(forCapaSwitch);
    if(switchCapa{0}) {
        debug_print("switchCapa{1}:" + switchCapa{1});
        message("<h1> Attention!! </h1>");
        message("<p>The Capacitance has changed from the default value 0 to the higher value " + switchCapa{1} + " due to high flux density in one or several requested lines </p>");
        message("<p>This will cause a loss of sensitivity in the faintest lines. Please refer to the User's manual, and/or to the PacsLineSpec Release notes for more informations </p>");
        confSPECblu[0]{0} = switchCapa{1};
        confSPECred[0]{0} = switchCapa{1};
    }
    // END of change capa code!
    // Here comes the module(s) to estimate OBS times as a function of the
    // input given by the HSPOT user.
    //Define tuple to contain the "variable" parameters
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPEC = clone(paramsSPECdef);
    // paramsSPECext (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,nb_up_dn,timeOBS,aux2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext_off = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext_simul = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for each wavelength. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("MAIN.confOBCP[0]: " + confOBCP[0]);
    }
    int nbNods = 0;
    // Accumulator total OBS time
    int totalOBS = 0;
    // For each demanded wavelength compute minimum duration
    for(int waveLOOP = 1 .. nbLines) {
        int waveLOOP1 = waveLOOP - 1;
        //    Different OBCPs if frequency switch or not
        if(chopNod) {
            // Here we perform nodding/chopping
            // SCR-2942: consider case of faintLines = false
            string forDEBUG = "chop/nod";
            paramsSPECext = PacsLineSpecEstimatorOBCP35(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,chopNod,faintLines,verbose);
            //      Copy estimates to respective tuples
            confSPECblu[waveLOOP] = paramsSPECext{0};
            confSPECred[waveLOOP] = paramsSPECext{1};
            confOBCP[waveLOOP] = paramsSPECext{2};
            //            confOBCP[waveLOOP]{18} = detector;
        } else {
            if(switching) {
                // Here we perform frequency switching
                forDEBUG = "freq/switch";
                // SPR-2926: Use userNODcycles as overall multiplier for repeatLine
                // No longer true with raster+OFF; repeat raster instead
                paramsSPECext = PacsLineSpecEstimatorOBCP32(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,verbose);
                //      Copy estimates to respective tuples
                confSPECblu[waveLOOP] = paramsSPECext{0};
                confSPECred[waveLOOP] = paramsSPECext{1};
                confOBCP[waveLOOP] = paramsSPECext{2};
                //            confOBCP[waveLOOP]{18} = detector;
            } else {
                if(gratScan) {
                    forDEBUG = "un-chopped";
                    bool gratScanOff = false;
                    paramsSPECext = PacsLineSpecEstimatorOBCP28(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,gratScan,faintLines,gratScanOff,verbose);
                    gratScanOff = true;
                    paramsSPECext_off = PacsLineSpecEstimatorOBCP28(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,gratScan,faintLines,gratScanOff,verbose);
                    //      Copy estimates to respective tuples
                    confSPECblu[waveLOOP] = paramsSPECext{0};
                    confSPECred[waveLOOP] = paramsSPECext{1};
                    confOBCP[waveLOOP] = paramsSPECext{2};
                    confOBCP_off[waveLOOP] = paramsSPECext_off{2};
                    paramsSPECext_simul = PacsLineSpecEstimatorOBCP32_simul(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,true,false);
                    confOBCP_simul[waveLOOP] = paramsSPECext_simul{2};
                }
            }
        }
        //      Accumulate total OBS time
        totalOBS = totalOBS + paramsSPECext{3}{2};
        if(verbose) {
            debug_print("MAIN.Obs mode    : " + forDEBUG);
            debug_print("MAIN.Wavelength  : " + sortLines[waveLOOP1]{1});
            debug_print("MAIN.confOBCP[" + waveLOOP + "]: " + confOBCP[waveLOOP]);
            debug_print("MAIN.confSPEC[" + waveLOOP + "]: " + confSPECblu[waveLOOP]);
        }
    }
    if(verbose) {
        debug_print("MAIN.Minimum required time: " + totalOBS + " [sec]");
    }
    if(chopNod) {
        // Here we perform nodding/chopping
        nbNods = userNODcycles;
        if(verbose) {
            debug_print("MAIN.The PointReq will contain " + nbNods + " nod cycles");
        }
    } else {
        // Here we perform freq switch
        nbNods = userNODcycles;
        if(verbose) {
            debug_print("MAIN.The PointReq will contain " + nbNods + " pattern repetitions");
        }
    }
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Minimum required OBStime: " + totalOBS + " [sec]</p>";
    lineCnt = lineCnt + 1;
    int nodTotal = nbNods * totalOBS;
    if(chopNod) {
        msgLine[lineCnt] = "<p>With the specified NOD count, " + nbNods + ", the total OBS time amounts to " + nodTotal + "[sec]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Since no NOD was specified the total OBS time is equal" + " to the minimum required time. The time can be changed" + " by changing the line(s) repeat factor</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("Accumulated SRC+REF time estimation",lineCnt,msgLine);
    // Messages on general Detector/SPU parameters
    lineCnt = 0;
    msgLine[lineCnt] = "<p>Red channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECred[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    int subRamps = confSPECred[0]{1} / confSPECred[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECred[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECred[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Blue channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECblu[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    subRamps = confSPECblu[0]{1} / confSPECblu[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECblu[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECblu[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Selected PACS setup parameters",lineCnt,msgLine);
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source
    // First operation is to set the OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // Will call PacsSpecSlewCal to perform AOT prologue and CAL during
    // slew to source. Establish an array of key wavelengths, one per order,
    // commensurate with user given wavelengths
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    //     double[] refWL = [sortLines[0]{1}];
    //    double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    //    double[] keyWAVE = [keyWL];
    // double[] keyWAVE = PacsLineSpecKeyWaves(sortWaveTuple);
    //    int nbKeyWAVE = length(keyWAVE); == 1 
    int nbKeyWAVE = 1;
    // With current versions of CommandOBCP35 and CommandOBCP32, the grating is
    // supposed to be left by SlewCal at the position needed for the 1st line
    // The OBCPs will leave the grating at that same position
    int frstLstGratPos = confOBCP[1]{8};
    if(verbose) {
        debug_print("MAIN:SortWaveTuple: " + sortWaveTuple);
        debug_print("MAIN:keyWAVES " + keyWAVE);
        debug_print("MAIN:SlewCal should leave grating at: " + frstLstGratPos);
    }
    // Time needed to perform these activities during slew (includes AOT
    // prologue)
    bool doAOTprologue = true;
    // PHS-1174 grat_keyWave should be passed on!
    int timeSlewCal = duration(PacsSpecSlewCal_grat(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,grat_keyWAVE,keyWAVE,filter,frstLstGratPos,orderSel));
    //    int timeSlewCal = duration(PacsSpecSlewCal(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel));
    // To stop unused channel we need
    // PHS-1221 re-enable both Channels
    // 
    //    int timeToStop = duration(SPEC_spu_channel_stop(stopSPUS,stopSPUL,verbose));
    // This time gets added to the CAL time
    //    timeSlewCal = timeSlewCal + timeToStop;
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during slew: " + timeSlewCal);
    }
    // CAL for HOLD 
    doAOTprologue = false;
    // same as from Slew ... grat_keyWave
    int timeHoldCal = duration(PacsSpecSlewCal_grat(false,confSPECblu,confSPECred,confOBCP,doAOTprologue,grat_keyWAVE,keyWAVE,0,frstLstGratPos,orderSel));
    //    int timeHoldCal = duration(PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,0,frstLstGratPos,orderSel));   
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during HOLD: " + timeHoldCal);
    }
    // compute aot_prologue for turning on the science data (SCR 7005)
    //    int timeDoSlewScience = duration(Pacs_SPEC_aot_prologue(false,confSPECblu,confSPECred,confOBCP,filter));
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsSpecCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsSpecCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // IMPORTANT NOTE: the duration could be different for the first cycle through 
    // all wavelengths than for the following ones owing to differing initial state.
    // However, all steps have been taken so that PACS starts the actual observation
    // in the same state as it would be left at the end of any wavelength cycle
    // Duration of any nod leg or staring observation
    // Different OBCP for wavelength switch
    // 
    // PHS-1385 need change the logic
    int timeOFF = 0;
    if(chopNod) {
        // Here we perform nodding/chopping
        int timeOBS = duration(PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,verbose));
        if(verbose) {
            debug_print("Duration OBCP35: " + timeOBS + " [sec] per pointing;  nbNods: " + nbNods);
        }
    } else {
        if(switching) {
            // Here we perform freq switch
            timeOBS = duration(PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,verbose));
            if(verbose) {
                debug_print("Duration OBCP32: " + timeOBS + " [sec] per pointing");
            }
        } else {
            if(gratScan) {
                // Here we perform un-chopped
                timeOBS = duration(PacsSpecCommandOBCP28(confSPECblu,confSPECred,confOBCP,verbose));
                timeOFF = duration(PacsSpecCommandOBCP28(confSPECblu,confSPECred,confOBCP_off,verbose));
                int timeSIMUL = duration(PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP_simul,false));
                if(verbose) {
                    debug_print("Duration OBCP28: " + timeOBS + " [sec] per pointing");
                    debug_print("Duration OBCP28 on OFF: " + timeOFF + " [sec] per pointing");
                }
            }
        }
    }
    // Get duration of module to close AOT operations
    // This includes parking the grating
    // Park position
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // The grating was left by OBCPs at frstLstGratPos
    int timeEpilogue = duration(SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose));
    // WriteEndID will be the last TC; get its duration
    int timeEndID = duration(WriteEndID());
    // Summary of relevant data collected so far
    // timeSlewCal: duration of the leading CAL, including AOT_prologue
    // timeOBS    : duration of a single pointed OBS
    // nb_nods    : number of nods for staring mode or per raster position
    // chopNod : invoke nodding or not (nb_nods = 0 is equivalent to no nod)
    // m, n       : raster nb_points/line, nbLines per RREQ
    // pointStep,lineStep: more raster parameters
    // ra,dec: more pointing parameters
    //
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Ready to issue a FinePointing mode with/without nodding or
    // a RasterReq with/without nodding. Either one will use time during
    // slew to perform SlewCal.
    //--->> this is not valid: decoupling the NOD throw from Chopper throw
    //
    // The chopper step has been read already (PacsSpecDefaults). However,
    // there are no provisions to carry that information here. Easiest is to
    // read again the relevant CAL-U table. Read chopper position SRC and
    // REF1 [arcsec]
    //
    // PHS-1220
    double chopAngleSrc = dlookup("SPEC_CHOP_params",throw,"SRC");
    double chopAngleRef = dlookup("SPEC_CHOP_params",throw,"REF1");
    double nodAngleSrc = dlookup("SPEC_NOD_params",throw,"SRC");
    double nodAngleRef = dlookup("SPEC_NOD_params",throw,"REF1");
    // The total nodThrow = chopperTotalThrow
    double nodThrow = abs(nodAngleSrc - nodAngleRef);
    if(verbose) {
        debug_print("PacsSpecDef: CHOP/NOD params SRC/REF/NOD: " + chopAngleSrc + "/" + chopAngleRef + "/" + nodThrow);
    }
    // Issue pointing request (when possible use JBr's variable names for clarity)
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    // Virtual aperture
    string ib = "P02_0";
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    int tslewmin = timeSetOBSID + timeSlewCal;
    int tinithold = 0;
    int tfinalhold = timeEndID + timeEpilogue;
    int tp = timeOBS;
    int top = 0;
    double patt = 0.0;
    double pattnod = 270.0 + skewCorrec;
    int k = 0;
    // DAC Test ONLY
    int thold = timeHoldCal;
    int nhold = 0;
    int nload = 0;
    int tloadslewmin = 0;
    bool fixed = true;
    // FinePointingMode with setup time
    if(pointCase == 11) {
        //     FinePointingMode without nodding
        if(verbose) {
            debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
            debug_print("#### skewCorrec : " + skewCorrec);
        }
        int[] fromPntReq = basic_fine_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,yoffset,zoffset,tp);
    }
    if(pointCase == 12) {
        //     FinePointingMode without nodding, section 3.4     
        ib = "P02_0";
        //     Nodding is specified wrt spacecraft
        fixed = false;
        if(chopNod) {
            pattnod = 270.0 + skewCorrec;
            top = timeOBS;
        }
        if(gratScan) {
            // The NOD A MUST be on target
            zoffset = 0.0;
            yoffset = 0.0;
            // PHS-1467 MOD is sky coordinates
            fixed = true;
            //PHS-1385 from raoff and decoff I need to get pattnod and nod throw
            {double,double} nodOffparams = NodOffFunction(ra,dec,raoff,decoff);
            double skewAngle = nodOffparams{0};
            nodThrow = nodOffparams{1};
            if(verbose) {
                debug_print("pattnod: " + skewAngle);
                debug_print("nodThrow: " + nodThrow);
            }
            if(abs(nodThrow) < 2.0) {
                message("The Given NOD offset is too small for the requested pointing mode, it will be set by defaut to +2 arcsec. Please change if necessary.");
                nodThrow = 2.0;
            }
            pattnod = skewAngle;
            top = timeOFF;
        }
        if(verbose) {
            debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
            debug_print("#### skewCorrec : " + skewCorrec);
        }
        // PHS-1385 need to recompute nodThrow and pattnod ??? can't that be given by Hspot
        fromPntReq = nodding_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nbNods,nodThrow,tp,top,tloadslewmin,nload,thold,nhold,startAtOFF);
    }
    if(pointCase == 21 || pointCase == 31) {
        //     RasterMode repeated_raster_with_hold_and_OFF, section 3.5
        ib = "P02_0";
        //     Raster in instrument coordinates
        fixed = false;
        double d1 = pointStep;
        double d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        k = 0;
        top = 0;
        if(!switching && pointCase == 21) {
            raoff = 0.0;
            decoff = 0.0;
        }
        int nrepeat = 1;
        //     If switching for "large" source perform OFF observation
        if(switching || pointCase == 31) {
            //        Repeat raster according to userNODcycles
            nrepeat = userNODcycles;
            k = n * m;
            if(!gratScan) {
                top = tp;
            } else {
                top = timeOFF;
            }
        }
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        //     SPR-3237 (map orientation parameter) applies only to raster
        // PHS-1266 map orientation modification
        if(pointCase == 31) {
            if(mapRasterAngleRefFrame) {
                fixed = true;
                patt = mapRasterAngle;
            } else {
                fixed = false;
                patt = 0.0;
            }
        }
        if(gratScan && gratScanOffRep < 1) {
            message("The map should contain at least 2 OFF: one at the beginning and one at the end");
            message("The number of OFF source observations will be set to 2");
            k = n * m;
        }
        if(gratScan && gratScanOffRep >= 1) {
            if(gratScanOffRep > n * m) {
                error("The map should contain at least 2 OFF: one at the beginning and one at the end");
            }
            k = gratScanOffRep;
            top = timeOFF;
        }
        if(verbose) {
            debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
            debug_print("#### skewCorrec : " + skewCorrec);
        }
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
    }
    if(pointCase == 22 || pointCase == 32) {
        //     Raster mode w/nodding, section 3.6
        ib = "P02_0";
        //     Raster in instrument coordinates
        fixed = false;
        //     Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        //     Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        k = 0;
        nrepeat = 1;
        //     New arguments for pointing request; will be dealt with next iteration
        top = 0;
        raoff = 0.0;
        decoff = 0.0;
        trepeatmin = 0;
        tloadmin = 0;
        nload = 0;
        if(verbose) {
            debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
            debug_print("#### skewCorrec : " + skewCorrec);
        }
        fromPntReq = nodding_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nbNods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
    }
    // Parameters returned by PointReq
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Issue PointRequest now");
        debug_print("Return from PointReq: " + fromPntReq);
    }
    //Info from API (nomenclature from Jon Br)
    tobs = fromPntReq[0];
    tslew = fromPntReq[1];
    ///////////////////////// end of "timing" section //////////////////////////
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
        int tNOW = time();
        debug_print("=====Issued PointReq Time_now: " + tNOW);
    }
    // Issue TCs
    int[] stateVar = [0];
    int nbOBS = 0;
    int nbOFF = 0;
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            //       Write OBSID (logical part of SlewCal)
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            tNOW = time();
            if(verbose) {
                debug_print(" AOT science Data OFF: " + tNOW);
            }
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            int[][] calTime = PacsSpecSlewCal_grat(false,confSPECblu,confSPECred,confOBCP,true,grat_keyWAVE,keyWAVE,filter,frstLstGratPos,orderSel);
            //       Define accumulated Cal time
            int[][] sumUpCalTime = calTime;
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW ends at: " + tNOW);
                debug_print("    SumUpCalTime: " + sumUpCalTime);
            }
        } else {
            if(stateVar[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== POINT starts at: " + tNOW);
                }
                //       Regular OBCP or frequency switched OBCP?
                if(chopNod) {
                    int[][] obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                } else {
                    if(switching) {
                        obsTime = PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                    } else {
                        if(gratScan) {
                            obsTime = PacsSpecCommandOBCP28(confSPECblu,confSPECred,confOBCP,false);
                        }
                    }
                }
                nbOBS = nbOBS + 1;
                //       Logic to sum up obsTime
                if(nbOBS == 1) {
                    int[][] sumUpObsTime = obsTime;
                }
                if(nbOBS > 1) {
                    sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("    SumUpObsTime: " + sumUpObsTime);
                    debug_print("=== POINT ends at: " + tNOW);
                }
            } else {
                if(stateVar[0] == 4) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF starts at: " + tNOW);
                    }
                    //       Regular OBCP or frequency switched OBCP?
                    if(chopNod) {
                        //            obsTime =  
                        int[][] offTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                    } else {
                        ///            obsTime =
                        if(switching) {
                            offTime = PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                        } else {
                            if(gratScan) {
                                offTime = PacsSpecCommandOBCP28(confSPECblu,confSPECred,confOBCP_off,false);
                            }
                        }
                    }
                    nbOFF = nbOFF + 1;
                    if(nbOFF == 1) {
                        int[][] sumUpOffTime = offTime;
                    }
                    if(nbOFF > 1) {
                        sumUpOffTime = SumFunction(offTime,sumUpOffTime);
                    }
                    //       Logic to sum up offTime
                    ///         if (nbOFF == 1) {sumUpObsTime = obsTime;}
                    ///         if (nbOFF > 1)  {sumUpObsTime = SumFunction(obsTime,sumUpObsTime);}
                    if(verbose) {
                        tNOW = time();
                        ///          debug_print("    SumUpObsTime: " + sumUpObsTime);
                        debug_print("    SumUpOffTime: " + sumUpOffTime);
                        debug_print("=== OFF ends at: " + tNOW);
                    }
                } else {
                    if(stateVar[0] == 7) {
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== NOD starts at: " + tNOW);
                        }
                        if(chopNod) {
                            obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                            nbOBS = nbOBS + 1;
                            //       Logic to sum up obsTime
                            if(nbOBS == 1) {
                                sumUpObsTime = obsTime;
                            }
                            if(nbOBS > 1) {
                                sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                            }
                            if(verbose) {
                                tNOW = time();
                                debug_print("    SumUpObsTime: " + sumUpObsTime);
                                debug_print("=== NOD ends at: " + tNOW);
                            }
                        }
                        if(gratScan) {
                            offTime = PacsSpecCommandOBCP28(confSPECblu,confSPECred,confOBCP_off,false);
                            nbOFF = nbOFF + 1;
                            if(nbOFF == 1) {
                                sumUpOffTime = offTime;
                            }
                            if(nbOFF > 1) {
                                sumUpOffTime = SumFunction(offTime,sumUpOffTime);
                            }
                            if(verbose) {
                                tNOW = time();
                                ///          debug_print("    SumUpObsTime: " + sumUpObsTime);
                                debug_print("    SumUpOffTime: " + sumUpOffTime);
                                debug_print("=== NOD OFF ends at: " + tNOW);
                            }
                        }
                    } else {
                        if(stateVar[0] == 6) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== HOLD starts at: " + tNOW);
                            }
                            //                            calTime = PacsSpecSlewCal(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel);			   
                            calTime = PacsSpecSlewCal_grat(false,confSPECblu,confSPECred,confOBCP,false,grat_keyWAVE,keyWAVE,filter,frstLstGratPos,orderSel);
                            sumUpCalTime = SumFunction(calTime,sumUpCalTime);
                            if(verbose) {
                                tNOW = time();
                                debug_print("    SumUpCalTime: " + sumUpCalTime);
                                debug_print("=== HOLD ends at: " + tNOW);
                            }
                        } else {
                            if(stateVar[0] == 5) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== FinalHOLD  starts at: " + tNOW);
                                }
                                SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose);
                                WriteEndID();
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== FinalHOLD  ends at: " + tNOW);
                                }
                            } else {
                                if(stateVar[0] == -1) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== AOT  ends at: " + tNOW);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    if(verbose) {
        debug_print("OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("Ending with NbOFF: " + nbOFF);
    }
    // The original concept of returning durations did not take into 
    // account the bandwidth of the TC bus (2 TCs/sec). The "real" 
    // duration is given by the result from the "duration()" function. Hence
    // the true total duration of the SlewCal phase is given by
    ///   calTime[0] = timeSlewCal;
    // as a result, the overheads are now
    ///   calTime[4] = calTime[0]-(calTime[1]+calTime[2]+calTime[3]); 
    if(verbose) {
        debug_print("Slew & HOLD Cal return: " + sumUpCalTime);
    }
    // The same holds true for the OBCP35 phase. However, I cannot make the
    // break-down by wavelength (the OBCP35 duration is given for ALL lines).
    // We may add up the SRC, CAL, and OVR components of OBCP35 duration. For
    // this we need a tuple so we can add the wavelength and other relevant
    // information to the (per wave) duration arrays.
    //
    //  infoArray[] contains a "fixed" global information part
    //  infoArray[0]: {Slew,   intTime,TotDur,nbRanges,nnods,m*n}
    //  infoArray[1]: {Point,  intTime,TotDur,nbRanges,nnods,m*n}
    //  infoArray[2]: {AOTinfo,intTime,TotDur,nbRanges,nnods,m*n}
    //
    // and a per wavelength array:
    //    [waveSTART,waveEND,order,gratStep,nbGratStep,TOT,SRC,REF,CAL,OVR]
    // TotDur as given by duration(); TOT,SRC,REF,CAL,OVR are also in [sec]
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    // Fill 1st dimension of infoArray with data from SlewCal
    // Instead of using timeSlewCal, use tslew time returned by PointReq
    infoArray[0] = {{"SlewCal",0.0,tslew,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    int[] gratScanObsTime = [0];
    // Compute integration time per chopper plateau
    // intTime = nbRamps/plateau x nbRdouts/ramp x sampleInterval 
    // Sampling frequency
    double specSample = dlookup("PACSparams","spec_sample","freq_time");
    // Number of readouts per ramp
    int nbRdoutRamp = confSPECblu[1]{1};
    // NOTE: WAIT=1 are now counted as useful ramps; hence
    int wait1 = 1;
    // but there is no wait in FreqSwitch
    if(switching || gratScan) {
        wait1 = 0;
    }
    int nbRampPlateau = confOBCP[1]{4} + wait1;
    if(gratScan) {
        nbRampPlateau = confOBCP_simul[1]{4} + wait1;
    }
    double intTime = double(nbRampPlateau * nbRdoutRamp) / specSample;
    if(verbose) {
        debug_print("MAIN:AOT          : " + userMode);
        debug_print("MAIN:Rdouts/ramp  : " + nbRdoutRamp);
        debug_print("MAIN:Ramps/plateau: " + nbRampPlateau);
        debug_print("MAIN:IntTime      : " + intTime);
    }
    // Replace timeOBS (per raster and per nod) with tobs from PntReq (matching
    // change in PacsProcessInfoArray)   
    infoArray[1] = {{userMode,intTime,tobs,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    for(int loop3 = 0 .. nbLines1) {
        //     for some reason it has to be "initialized"
        infoArray[1]{1}[loop3] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the START wavelength (for LINE START = END = line wave)
        infoArray[1]{1}[loop3]{0} = sortLines[loop3]{1};
        //     copy the END   wavelength (for LINE START = END = line wave)
        infoArray[1]{1}[loop3]{1} = sortLines[loop3]{1};
        //     copy the grating order
        infoArray[1]{1}[loop3]{2} = sortWaveTuple[loop3]{1};
        //     copy the grating step
        infoArray[1]{1}[loop3]{3} = sortWaveTuple[loop3]{4};
        if(gratScan) {
            infoArray[1]{1}[loop3]{3} = (confOBCP_simul[loop3 + 1]{2} - confOBCP_simul[loop3 + 1]{1}) / 2;
        } else {
            infoArray[1]{1}[loop3]{3} = (confOBCP[loop3 + 1]{2} - confOBCP[loop3 + 1]{1}) / 2;
        }
        //     copy the number of grating steps
        if(gratScan) {
            infoArray[1]{1}[loop3]{4} = confOBCP_simul[loop3 + 1]{6};
        } else {
            infoArray[1]{1}[loop3]{4} = confOBCP[loop3 + 1]{6};
        }
        //     copy other data from sumUpObsTime
        infoArray[1]{1}[loop3]{5} = sumUpObsTime[loop3][0];
        infoArray[1]{1}[loop3]{6} = sumUpObsTime[loop3][1];
        infoArray[1]{1}[loop3]{7} = sumUpObsTime[loop3][2];
        infoArray[1]{1}[loop3]{8} = sumUpObsTime[loop3][3];
        infoArray[1]{1}[loop3]{9} = sumUpObsTime[loop3][4];
        //PHS-1466 sensitivity in un-chopped line depends also on the nb of cycle
        gratScanObsTime[loop3] = sumUpObsTime[loop3][1];
    }
    // Also data from SlewCal to infoArray
    for(int loop4 = 0 .. nbKeyWAVE - 1) {
        //     for some reason it has to be "initialized"
        infoArray[0]{1}[loop4] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the wavelength
        infoArray[0]{1}[loop4]{0} = keyWAVE[loop4];
        //     copy other data from sumUpCalTimeTime
        infoArray[0]{1}[loop4]{5} = sumUpCalTime[loop4][0];
        infoArray[0]{1}[loop4]{6} = sumUpCalTime[loop4][1];
        infoArray[0]{1}[loop4]{7} = sumUpCalTime[loop4][2];
        infoArray[0]{1}[loop4]{8} = sumUpCalTime[loop4][3];
        infoArray[0]{1}[loop4]{9} = sumUpCalTime[loop4][4];
    }
    // Further update of infoArray: add information from AOT_prologue    
    infoArray[0]{1}[nbKeyWAVE] = {0.0,0.0,0,0,0,0,0,0,0,0};
    //   Copy OVR and TOT times
    infoArray[0]{1}[nbKeyWAVE]{9} = calTime[nbKeyWAVE][4];
    infoArray[0]{1}[nbKeyWAVE]{5} = calTime[nbKeyWAVE][4];
    //   Copy the number of lines observed and the number of key waves used
    infoArray[0]{0}{3} = nbKeyWAVE;
    infoArray[1]{0}{3} = nbLines;
    //   Copy the number of nod cycles and the number of raster points visited
    infoArray[1]{0}{4} = nbNods;
    infoArray[1]{0}{5} = m * n;
    // The duration of the OBS phase is given by timeObsEnd - timeSlewCal
    // Now get it from PntReq: timeObsPhase == tobs
    // int timeObsPhase = timeObsEnd - timeSlewCal;
    // Slew time during the OBS phase is then given by
    // don't forget OFF slews
    int timeSlewObs = tobs - (nbOBS * timeOBS + nbOFF * timeOFF);
    if(verbose) {
        debug_print("CalSlew phase lasted [sec]: " + timeSlewCal);
        debug_print("The OBS (inc OFF) phase lasted [sec]: " + tobs);
        debug_print("Total slew during OBS (inc OFF) [sec]: " + timeSlewObs);
    }
    // Fill 3rd dimension of infoArray with global timing and AOT information
    // timeObsEnd is the total duration of the AOT
    // Pass details of AOT
    // We use OBCP35: OBCP_grat_scan_chop3 (unless FreqSwitch)
    string aotName = "GratScanChop3";
    // Special "sky time"  for FreqSwitch and SmallSourceDither
    if(switching) {
        aotName = "FreqSwitch";
    }
    if(gratScan) {
        aotName = "GratScanNoChop";
    }
    if(source == "dithered") {
        infoArray[1]{0}{0} = "SmSrcDither";
    }
    infoArray[2] = {{aotName,0.0,timeObsEnd,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Use available entries to convey m,n, and nbNods
    infoArray[2]{0}{3} = m;
    infoArray[2]{0}{4} = n;
    // PointSources are also seen with composite_nodding
    if(pointMode == "fine_pointing" || pointMode == "composite_nodding") {
        infoArray[2]{0}{3} = 1;
        infoArray[2]{0}{4} = 1;
    }
    infoArray[2]{0}{5} = nbNods;
    // PHS-1385 If switching && gratScan so ...  
    if(!chopNod && source == "Large") {
        infoArray[1]{0}{0} = "RasterOFF";
    } else {
        if(!chopNod && source == "Point") {
            infoArray[1]{0}{0} = "Pointed";
        }
        infoArray[2]{0}{5} = userNODcycles;
    }
    // Process the information contained in infoArray (pass also sortLines)
    if(gratScan) {
        PacsProcessInfoArrayLine_tmp(infoArray,sortLines,confOBCP_simul,obsOverhead,nbOBS,nbOFF,gratScanObsTime,verbose);
    } else {
        PacsProcessInfoArrayLine_tmp(infoArray,sortLines,confOBCP,obsOverhead,nbOBS,nbOFF,gratScanObsTime,verbose);
    }
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    // Compute the total time SRC + REF
    int accumSrceRef = 0;
    for(int loopL = 0 .. nbLines - 1) {
        //   Add up Srce and Ref times (SRC + REF)
        accumSrceRef = accumSrceRef + infoArray[1]{1}[loopL]{6} + infoArray[1]{1}[loopL]{7};
    }
    // Compute overheads as total "sky" time minus SRC+REF time
    int overPACSandSC = fromPntReq[0] - accumSrceRef;
    // Return demanded tuples

    return {accumSrceRef,fromPntReq[1],overPACSandSC};
}

// CVS comments  : $Id: PHOT_aot_prologue.txt,v 1.8 2008/05/06 13:34:53 vanessa Exp $ 
// Purpose       : SetUp of BOLO preceding AOT (but after orbit_prologue)
//
// CUS author    : DAC
// Script file   : PHOT_aot_prologue.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type          Description
//
// Description   : Conditions and starts SPU
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 18-jan-2006 DAC
//                 0.2 21-aug-2007 SRC-3507 Indicate end of BB
//                 1.0 10-oct-2007 Added input variables after SCR-3628
//		   2.0 06-may-2008 Added Gain setup: LOW/HIGH gain obs.
//		   2.1 23-spe-2008 SCR 4431 data_rate		   
int[] block PHOT_aot_prologue PACS 211 {
    string set_gain = "LOW";
    int comp_mode_blu = 0;
    int comp_mode_red = 0;
    int nraw_blu = 3;
    int nraw_red = 3;
    bool verbose = true;
}{
    int timeStart = time();
    // Register start of BB
    WriteBBID($BBID);
    // Define the elements of time_array
    int duree_sec = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Setup SPU
    bool startSPU = true;
    PHOT_spu_gain_setup(set_gain,comp_mode_blu,comp_mode_red,nraw_blu,nraw_red,startSPU);
    data_rate(120.0);
    // Mark end of BB
    WriteEndBB();
    // Synch bus
    sync();
    // Accumulated duree [milliseconds]
    int duree_msec = 0;
    duree_sec = time() - timeStart;
    // Do nothing for time being
    if(verbose) {
        debug_print("PHOT_aot_prologue: " + duree_sec + " [sec]");
    }

    return [duree_sec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Purpose       : Flashers Short Functional Test
//
// Author        : P. Royer
//
// Arguments     :
//
// Description   : Sends current to both flashers for short times, the goal is only to see some reaction in the HK
//
//
// Prerequisite : The flashers are SWITCHED ON ALREADY
//	  	  The correct HK & Diaghk lists are already set & acquired
//
// Comments      : 
//                 
//
// Version       : 1.0
// History       : 1.0 / 08-Jun-2006 initial version by PR
// 		 : 1.2 13-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Flash_SFT {
    /* No need for variables to call PacsEng_Spec_Flash_SFT                        */
    /*  string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Flash_SFT                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Flash_SFT()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Flash_SFT();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id: PacsEng_Phot_spu_reset.txt,v 1.5 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : TM
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version       : 1.0
// 
// History       : 0.1 22-mar-2006
//                 0.2 09-oct-2006, TM
//		   1.0 04-mar-2008 translated into PV script
//
obs PacsEng_Phot_spu_reset_l {
    /* Needed variables to call PacsEng_Phot_spu_reset_l                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_spu_reset_l                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PHOT_spu_reset()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_spu_reset();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : Start Autonomy Function 14
//                 
//
// Author        : Helmut Feuchtgruber
//
// Arguments     : None
//
// Description   : Use service 14 and a memory load to disable all HK packets
//
// Dependencies  : none
//
// Comments      : 
//
// Version       : 1.0 27-Mar-2007 HF
// History       : 1.0 27-Mar-2007 initial Version 
//
procedure Disable_HK {
}{
    // DPU_DISABLE_PACKT_TRAN
    {int,int,int}[] grp1 = [{3,25,1},{3,25,2},{3,25,3},{3,25,4}];
    Pacs_DPU_DISABLE_PACKT_TRAN(4,grp1);
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
//
// Purpose	 : SFT in Open Loop Mode (cold conditions)
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : SFT cold for FM1 chopper in open-loop mode. All 3 coils are
//                 operative. The chopper is commanded between -20 mA and +20mA
//                 in steps of 4 mA.
//                 The first part consists of chopper deflections equivalent to
//                 commanded chopper coil currents between 0 and +/-20 mA,
//                 alternating between positive and negative values. Absolute
//                 position commanding is used.
//                 The second part consists of a ramp of chopper deflections
//                 between -20 and +20 mA, commanded in relative steps of 4 mA.
//                 Finally, the chopper returns to its zero position.
//                  
// Dependencies  : 
//
// Preconditions : PACS switched-on, chopper is switched off and disabled
//                 Diagnostic HK not running
//                 
// Comments	 : Adapted from PACS_SPEC_Chopper_OpenLoop_MoveAbs_OBS.cus
//
// Version	 : 2.0
// 
// History 	 : 1.0 09-03-07 creation by MN
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
//                 2.0 12-03-07 creation by MN
// Begin Mode description
obs PacsEng_Chopper_SFT_Cold_OpenLoop {
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Chopper_SFT_Cold_OpenLoop()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Chopper_SFT_Cold_OpenLoop();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS file      : SPEC_CRE_setup.cus
// IMPORTANT NOTE: functionally similar to SPEC_cre_setup; see history
//                 to see new features
// Missionphase  : FM ILT
//
// Purpose       : Set CRE bias, ramps' length and capacitor values;
//                 Switch on blue heater
//                  
// Author        : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
//
// Arguments     : 
// Type     Name          DefVal   Description
// int      ramp_len_red     64    Red ramps' length
// int      ramp_len_blu     64    Blue ramps' lengthl
// double   bias_d_red        0    BIAS_D for red spectrometer (1V=4095)
// double   bias_r_red        0    BIAS_R for red spectrometer (1V=4095)
// double   bias_d_blu        0    BIAS_D for blue spectrometer (1V=4095)
// double   bias_r_blu        0    BIAS_R for blue spectrometer (1V=4095)
// int      capa_red          0    Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
// int      capa_blu          0    Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
// double blue_heat_current   1.5  Heater current [mA]
//
//
// CRE setup according to the DEC/MEC User's Manual
//
// 1. DMC_SWON_B_DEC to switch on the DEC 
// 2. Wait 5 seconds to get the 1355 connection between DEC and CPU board 
// 3. Send the complete set of default parameters. 
//    First send a DMC_WRT_B_SPEC_PAR command with these values 
//    (in hex: 20-8-18C-0-0-EA60-0-0).    
// 3a. Then, send a DMC_SET_PAR_B_SPEC to really send the parameters to the DEC. 
// 4. DMC_SWON_B_SPEC to switch on the detector array 
// 5. Wait 15 seconds to let the switch on procedure run and all voltages 
//    become stables 
// 6. Then, to activate the CREs (signal SELECT on the CREs), send the first 
//    3 parameters, i.e. DMC_WRT_B_SPEC_PAR command with these 
//    values (length: 3, values in hex : 20- 8-18E). 
// 6a. Then, send a DMC_SET_PAR_B_SPEC to really send the parameters to the DEC. 
//    Note: with this command, we set bit1 to 1 (activate CRE). Bit0 
//    has been set to 1 by the DMC_SWON_B_SPEC command but, 
//    bit0 is not commandable through the DMC_WRT_B_SPEC_PAR. 
//    The only way to switch on/off the detector array is to use the 
//    trigger commands. 
// 7. Then, you should set the bias voltages by writing the first 4 or 5 
//    parameters of the block. Make sure to copy the latest values you use 
//    for the first 3 parameters.
//
// Description   : Sets CRE parameters (see list of arguments).
//                 User specifies cre_ctrl_xx as:
//                 cre_ctrl: 256 to set "sync width=2"
//                           128 to set "T sensor on" 
//                             2 to set "select"
//                             1 power on (not relevant here)
//                 Script adds capa_xx to cre_ctrl_xx
//                     xx_cre_ctrl = capa_xx + cre_ctrl_xx
//                 xx_cre_ctrl gets written to the CRE register
//                 Switch on blue detector heater
//                 Must be called on a stopped SPU. This procedure will
//                 neither stop nor start SPU (call SPEC_spu_reset and 
//                 SPEC_spu_setup respectively for that)
//
//                  
// Dependencies  : 
//                 
// Comments      : Based on V1.3 of FGB's fgb_spec_cre_setup.tcl. Major
//                 change is getting ENG values for the bias voltages
//
// Version       : 0.1  7-Oct-2004 Creation by DAC
// History       : 0.2 12-Oct-2004 Removed "delay" statements
//                 0.3 18-Oct-2004 Normalized variable names
//                 0.4 21-Oct-2004 Added cre_ctrl_xx and heater_on
//                                 arguments to allow calling by
//                                 SPEC_orbit_prologue. 
//                                 Removed heater commands
//                 0.5 27-Oct-2004 Put bck delay statement 
//                 1.0 10-Apr-2006 HF, modified for FM
//                 1.1 16-nov-2006 Reviewed for use in OpDataBase
//                                 - removed "duree" computations
//                                 - moved "fix" arguments to body
//                                 - added heater, write receiver, and synch
//                                   commands
//                 1.2 BV 27-07-2009 SPR 1798 corrected biases
//
procedure SPEC_CRE_setup {
    int ramp_len_red = 64; // Red  ramp length
    int ramp_len_blu = 64; // Blue ramp length
    double bias_d_red = 0.042 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_red = 0.01 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.1 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_r_blu = 0.01 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    int capa_red = 0; // Capacitor red  (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_blu = 0; // Capacitor blue (0=100fF,4=400fF,8=0.2pf,12=1pF)
    double blue_heat_current = 0.78 in [0.0,10.01]; // Current [mAmp]
}{
    // Red  CRE register (capa_red=0)
    int cre_ctrl_red = 386;
    // Blue CRE register (capa_blu=0)
    int cre_ctrl_blu = 386;
    // Blue CRE register (capa_blu=0)
    // Write the blue spectrometer parameters
    int blu_cre_ctrl = capa_blu + cre_ctrl_blu;
    // Bias values have been given in ENG units. Have to convert to RAW in
    // order to compute check-sums
    int i_blu_bias_r = convert_to_raw("pacs_DMC_BIAS_R",bias_r_blu);
    int i_blu_bias_d = convert_to_raw("pacs_DMC_BIAS_D",bias_d_blu);
    int clks_rdout = 32;
    int simul_reg = 60000;
    int[] aux = [clks_rdout,ramp_len_blu,blu_cre_ctrl,i_blu_bias_r,i_blu_bias_d,simul_reg];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_B_SPEC_PAR(clks_rdout,ramp_len_blu,blu_cre_ctrl,bias_r_blu,bias_d_blu,simul_reg,check_sum);
    // Same for RED parameters
    int red_cre_ctrl = capa_red + cre_ctrl_red;
    int i_bias_r_red = convert_to_raw("pacs_DMC_BIAS_R",bias_r_red);
    int i_bias_d_red = convert_to_raw("pacs_DMC_BIAS_D",bias_d_red);
    aux = [clks_rdout,ramp_len_red,red_cre_ctrl,i_bias_r_red,i_bias_d_red,simul_reg];
    check_sum = checksum("int",aux);
    Pacs_DMC_WRT_R_SPEC_PAR(clks_rdout,ramp_len_red,red_cre_ctrl,bias_r_red,bias_d_red,simul_reg,check_sum);
    // Send complete parameters table to both DECS
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    // Switchon and set blue detector heater
    Pacs_DMC_SWON_BD_HEATER();
    delay(1);
    Pacs_DMC_SET_B_SPEC_HEAT_C(blue_heat_current);
    // DMC_SYNCHRONIZE_ON_DET(1)
    Pacs_DMC_SYNCHRONIZE_ON_DET(1);
    delay(1);
    // DMC_WRT_B_DEC_REC_OPT" WRITE THE BLUE DEC RECEIVER OPTIONS
    {int}[] argTuple = [{0}];
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,0x84c0);
    delay(1);
    // DMC_WRT_R_DEC_REC_OPT" WRITE THE RED DEC RECEIVER OPTIONS
    argTuple = [{0}];
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,0x84c0);
    delay(1);
    // DMC_VAL_SCI_DATA_BOTH" VALIDATE SCIENCE DATA FROM BOTH CHANNELS
    Pacs_DMC_VAL_SCI_DATA_BOTH();
    delay(1);
}

// $Id: PacsEng_Spec_GeGa_BufferTransmission_Loop.txt,v 1.4 2008/11/12 11:40:20 vanessad Exp $
// Missionphase  : PACS Commissiong Phase
//
//
//
//
// Purpose      : Ge:Ga detector Loop
//
// Author       : Helmut Dannerbauer
// CUS script   : HD
// CVS file     :
//
// Arguments    : bias, integration time, capacity, measurement time, resistor bias
//
//
// Description  : Loop over bias, integration time and capacity.
//
// Dependencies :  - Pacs_Spec_GeGa_Loop_Comm 
//		   - WriteOBSID
//		   - WriteEndID
//
//
// Preconditions : - PACS is switched on
//                 - Setup spectroscopy
//		   - Mechanics and CS controllers are SWON and ENABLED
//
// Comments     : 
//
// Version      : 1.0
//
// History      : 1.0 20090608 PR
//
//
obs PacsEng_Spec_BufferTransmission_Loop {
    /* Needed variables to call PacsEng_Spec_GeGa_Loop_Comm                        */
    int repeat_global = 2; // Global repetition factor (main loop)
    int repeat_intern = 1; // Repetition factor inside the bias loop (ramplen+capa loops)
    double[] bias_blue = [0.06,0.08,0.1,0.12]; //bias blue
    double[] bias_red = [0.03,0.04,0.05,0.06]; //bias red red
    int[] ramp_len_blue = [32,64]; //ramp length blue (set integration time)
    int[] ramp_len_red = [32,64]; //ramp length red (set integration time)
    int[] capa_blue = [8,12]; //capacity blue
    int[] capa_red = [8,12]; //capacity red
    int meas_time = 360; //observing time in seconds per setting
    double bias_res_blue = 0.01; //resistor bias blue
    double bias_res_red = 0.01; //resistor bias red
    int chop_pos = 0; //chopper position
    int grat_pos = 737500; // grating position
    string filter_pos = "POS B" in ["POS A","POS B"]; // FW position
    /* End of needed variables for PacsEng_Spec_GeGa_Loop_Comm  */
}{
    //
    busconfig (7);
    // BURST MODE :     4:PACS PRIME  -  7:BURST MODE  - 8:PARALLEL MODE
    //
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_BufferTransmission_Loop(repeat_global,repeat_intern,bias_blue,bias_red,ramp_len_blue,ramp_len_red,capa_blue,capa_red,meas_time,bias_res_blue,bias_res_red,chop_pos,grat_pos,filter_pos)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic.
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_BufferTransmission_Loop(repeat_global,repeat_intern,bias_blue,bias_red,ramp_len_blue,ramp_len_red,capa_blue,capa_red,meas_time,bias_res_blue,bias_res_red,chop_pos,grat_pos,filter_pos);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: OBCP_chopped_photometry.txt,v 1.6 2007/08/22 10:18:28 dcesarsk Exp $ 
// Missionphase  : PACS AVM ILT Orbit-Operations
//
// Purpose       : OnBoardControlProcedure to perform
//                 chopped photometry
//                 Chopped observations of SRC in the manner:
//                     SRC->REF1->SRC->REF2
//                 followed by a calibration sequence using the internal
//                 blackbodies
//                     CS1 -> CS2
//                 User can specify the number of source observing cycles
//                (nb_SRC_REF), the number of calibration cycles (nb_CS1_CS2)
//                 and how many times the whole sequence shall be repeated
//                (nb_cycles_obs_cal).
//                 The number of readouts per quiescent chopper position is
//                 the same (nb_rdouts_plateau) within each cycle
//
// OBCP author   : Helmut Feuchtgruber
// CUS script    : Diego A. Cesarsky
// CVS file      : OBCP_chopped_photometry.txt from AOT code  
//
// Arguments: 
// Type  Name                 Description
// int   nb_SRC_REF           p01 Number of observations in OBS loop
// int   chop_pos_SRC         p02 Chopper position for SRC
// int   nb_rdouts_plateau    p03 Number of readouts per chopper position 
// int   chop_pos_REF1        p04 Chopper position for BKG1
// int   chop_pos_REF2        p05 Chopper position for BKG2 (may be equal to BKG1) 
// int   nb_cycles_obs_cal    p06 Number of obs/cal cycles
// int   nb_CS1_CS2           p07 Number of observations in CAL loop
// int   chop_pos_CS1         p08 Chopper position for CS1
// int   chop_pos_CS2         p09 Ditto for CS2 
// int   comp_mode_blu         Compression mode BLUE
// int   comp_mode_red         Ditto RED 
// int   chop_def              Chopper default position 
//
//
// Description   : This script mimics the OBCP_CHOPPED_PHOTOMETRY
//                 pseudo script, section 3.1.1 in PACS-ME-LI-005
//                 This CUS version computes the duration of the
//                 observation, as specified by the input parameters.
//                 It will also send the trigger TC to start the OBCP
//
// Dependencies  : DMC_phot_2_3_chop
//                 WriteBBID   
// Comments      : 
//
// Version       : 1.2 21-Jan-2004 Creation by DAC
// History       : 0.2 23-Jan-2004 Set value for seq_time, removed seq
//                                 and seq_time as arguments  
//               : 0.3 08-Aug-2004 Changed variable name as "duration" 
//                                 is now a reserved name
//               : 0.4  08-Aug-2004 Rename to block OBCP_etc PACS 4
//                 0.5  20-Aug-2004 Use redefined DMC script
//                 0.6  25-Aug-2004 The BBID is generated and TCed here
//                 0.7  17-Sep-2004 Use renamed DEC_phot_2_3_chop
//                 0.8  27-Sep-2004 Use "double" for BOL frequency and associated data
//                 0.9   7-Oct-2004 Use renamed WriteBBID
//                 0.91 18-Oct 2004 Normalized variable names
//                 0.92  9-Nov-2004 DMC now returns [] of times
//                                  [duration_rdouts,
//                                   duree_SRC,
//                                   duree_REF,
//                                   duree_CAL,
//                                   duree_OVR]
//                                   (expressed in nb_of_readouts)
//                 0.93 10-Dec-2004 True duration must include the fact that
//                                  TCs are sent 2 per second, i.e. each TC
//                                  takes 1/2 second. Use "time" function to
//                                  get actual duration.
//                                  obcp_ID is now a string
//                 1.0  30-Nov-2005 Use computed duration; remove debug_print
//                 1.1  21-aug-2007 SRC-3507 Indicate end of BB
//                 1.2  18-feb-2008 DAC Added sync at end
//                 1.3 09-sep-2009 VD SPR PACS-2039 add 5sec delay for Bolometer stabilisation
//                 1.4 15-sep-2009 VD: SPR PACS-2039. delay removed from OBCP (too many dependences)
//
int[] block OBCP_chopped_photometry PACS 4 {
    int nb_SRC_REF = 1; // p01 Number of observations in OBS loop
    int chop_pos_SRC = 0; // p02 Chopper position for SRCE
    int nb_rdouts_plateau = 8; // p03 Number of readouts per chopper position 
    int chop_pos_REF1 = -2000; // p04 Chopper position for BKG1
    int chop_pos_REF2 = 2000; // p05 Chopper position for BB2
    int nb_cycles_obs_cal = 1; // p06 Number of obs/cal cycles
    int nb_CS1_CS2 = 0; // p07 Number of observations in CAL loop
    int chop_pos_CS1 = -22680; // p08 Chopper position for CS1
    int chop_pos_CS2 = 22680; // p09 Chopper position for CS2
    int comp_mode_blu = 0; // Compression mode BLUE channel
    int comp_mode_red = 0; // Compression mode RED channel
    int chop_def = 0; // Chopper default position
}{
    // Starting time
    int time_start = time();
    // Register start of BB
    WriteBBID($BBID);
    // Variables that may be used to define various times
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    // Obtain system parameter from PACSparams
    // BOL readout frequency [Hz] and readout period [msec]
    double bol_freq = dlookup("PACSparams","bolo_sample","freq_time");
    //  string bol_unit = slookup("PACSparams","bolo_sample","unit");
    double bol_period = 1000.0 / bol_freq;
    //  debug_print("Bolo sample: " + bol_freq + " " + bol_unit);
    //  debug_print("Bolo period: " + bol_period + "[msec]");
    // Obtain duration of an "internal" command [msec]
    int t_cmd = iceil(dlookup("PACSparams","int_cmd","freq_time"));
    // Obtain duration of DEC/MEC "communication jitter" [msec]
    int dmc_margin = iceil(dlookup("PACSparams","dmc_margin","freq_time"));
    // Obtain duration of OBCP "communication jitter" [msec]
    int obcp_margin = iceil(dlookup("PACSparams","obcp_margin","freq_time"));
    // Start tallying the duration of this script [msec]
    int duration_msec = 0;
    // OBCP Pseudo Code starts here (accumulate duration_msec [msec] as it goes)
    // Begin 
    // DEC_WRITE_TIME (DPU_TIME in standard 48 bit format according to PS-ICD)
    // Here and elsewhere it is assumed that OBCP "internal" TCs take t_cmd
    // [msec] to be executed
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // SET_TIME 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DEC_WRITE_SEQ_BUF(ID, LENGTH, DATA, CHECKSUM)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Invoke CUS version of DECMEC sequence above (DMC_PHOT_2_3_CHOP)
    // (only to compute duration!! Hence use only duration related parameters
    // in the call)
    // The DMC is number seq_DMC=1 and lasts seq_time [msec]
    // Duration "duree1" is an array with five elements
    int[] duree1 = DMC_phot_2_3_chop(nb_SRC_REF,nb_rdouts_plateau,nb_cycles_obs_cal,nb_CS1_CS2);
    // Convert duration [readouts] into [msec]; add dmc_margin
    int seq_time = ifloor(double(duree1[0]) * bol_period) + dmc_margin;
    // Convert other times as well into msec
    duree_SRC = ifloor(double(duree1[1]) * bol_period);
    duree_REF = ifloor(double(duree1[2]) * bol_period);
    duree_CAL = ifloor(double(duree1[3]) * bol_period);
    duree_OVR = duree_OVR + ifloor(double(duree1[4]) * bol_period) + dmc_margin;
    // Tally into accumulated duration of OBCP   			 
    duration_msec = duration_msec + seq_time;
    // SYNCHRONIZE_ON_DETECTOR(3) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // DEC_WRITE_TRM_CMP(ID, 1, cmp_par, CHHKSUM) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // START_SEQUENCE duration_msec(seq_time)
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // WAIT(seq_time)
    // Check execution status of the sequence and in case of failure stop OBCP
    // and issue TM(1,8) + event 
    // MOVE_CHOPPER_ABSOLUTE(chop_def) 
    duration_msec = duration_msec + t_cmd;
    duree_OVR = duree_OVR + t_cmd;
    // Issue TM(1,7) 
    // Now trigger execution of OBCP
    // This OBCP is number 4, requires 14 parameters and lasts seq_time [msec]
    string obcp_ID = "CHOPPED_PHOT";
    int obcp_par_nber = 14;
    int seq_DMC = 1;
    {int,int}[] grp = [{1,seq_DMC},{2,seq_time},{3,nb_SRC_REF},{4,chop_pos_SRC},{5,nb_rdouts_plateau},{6,chop_pos_REF1},{7,chop_pos_REF2},{8,nb_cycles_obs_cal},{9,nb_CS1_CS2},{10,chop_pos_CS1},{11,chop_pos_CS2},{12,comp_mode_blu},{13,comp_mode_red},{14,chop_def}];
    Pacs_DPU_START_OBCP(obcp_ID,obcp_par_nber,grp);
    // Add the "communication jitter"
    duration_msec = duration_msec + obcp_margin;
    duree_OVR = duree_OVR + obcp_margin;
    // Return total duration [sec] to calling program
    // Create return time array; convert into [sec]
    int[] time_array = [duration_msec,duree_SRC,duree_REF,duree_CAL,duree_OVR];
    for(int aux = 0 .. 4) {
        time_array[aux] = Msec2sec(time_array[aux]);
    }
    // Set delay()
    // removed: add delay 5sec for Bolo stabilisation: SPR PACS-2039
    delay(time_array[0]);
    // Mark end of BB
    WriteEndBB();
    // Sync the bus
    sync();
    // Return OBCP time estimates

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Heaters Functional Test
//
// Author        : P. Royer
//
// Arguments     :
//
// Description   : Sends 2 current to both heaters 
//
//
// Prerequisite : 
//	  The correct HK & Diaghk lists are already set & acquired
//
// Comments      : 
//                 
//
// Version       : 2.0
// History       : 1.0 05-Apr-2007 initial version by PR
// 		   2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.0
// @purpose Heaters Functional Test
// @comment - 
//
obs PacsEng_Spec_Heat_FFT {
    /* Needed variables to call PacsEng_Spec_Heat_FFT                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Heat_FFT                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Heat_FFT()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Heat_FFT();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id: PacsEng_Spec_CRE_setup.txt,v 1.6 2008/05/28 09:27:05 vanessad Exp $
// Missionphase  : PACS PV Phase
//
// CVS file      : SPEC_CRE_setup_OBS.cus//
//
// Missionphase  : 
//
// Purpose       : TOPE schedule SPEC_cre_setup
//                  
// Author        : DAC
//
// Arguments     : 
// Type     Name          DefVal   Description
// int      ramp_len_red     64    Red ramps' length
// int      ramp_len_blu     64    Blue ramps' lengthl
// double   bias_d_red    0.070    BIAS_D for red spectrometer (1V=4095)
// double   bias_r_red    0.010    BIAS_R for red spectrometer (1V=4095)
// double   bias_d_blu    0.210    BIAS_D for blue spectrometer (1V=4095)
// double   bias_r_blu    0.010    BIAS_R for blue spectrometer (1V=4095)
// int      capa_red         12    Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
// int      capa_blu         12    Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
//
// Version       : 1.1
// History       : 0.1 17-nov-2006 DAC
//                 0.2 18-dec-2006 Exchange red/blue detectors
//                 0.3 19-feb-2007 Exchange red/blue detectors back to nominal
//		   1.0 04-mar-2008 translated into PV script VDP
//                 1.1 15-Apr-2008 modified blue_heat_current from 1,5 
//                                 to 0.78 mAmp (HF)
//
obs PacsEng_Spec_CRE_setup_u {
    /* Needed variables to call PacsEng_Spec_CRE_setup_u                        */
    int ramp_len_red = 64; // Red  ramp length
    int ramp_len_blu = 64; // Blue ramp length
    double bias_d_red = 0.0701 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    /*  double bias_d_red = 0.21 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)*/
    double bias_r_red = 0.0101 in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_d_blu = 0.2101 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    /*  double bias_d_blu = 0.07 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)*/
    double bias_r_blu = 0.0101 in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    int capa_red = 12; // Capacitor red  (0=100fF,4=400fF,8=0.2pf,12=1pF)
    int capa_blu = 12; // Capacitor blue (0=100fF,4=400fF,8=0.2pf,12=1pF)
    double blue_heat_current = 0.78 in [0.0,10.01]; // Current [mAmp]
    /*  double blue_heat_current = 0.0 in [0.0,10.01]; // Current [mAmp] */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_CRE_setup_u                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_CRE_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,blue_heat_current)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_CRE_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu,blue_heat_current);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// VS comments  : $Id: PacsSpecAuxRMS.txt,v 1.9 2007/10/25 12:15:42 dcesarsk Exp $ 
// Purpose       : To compute RMS vs. WaveLength; to establish min,max RMS
//                 and their associated wavelength. arrayID 
//
// CUS author    : 
// Script file   : PacsSpecAuxRMS.txt 
//
// Input arguments
// type    name         description
// string  aotID        RANGE or LINE AOT
// string  arrayID      ID for current array
// double  wave         Array of wavelengths
// double  waveRef      Wave reference
// double  intTime      Integration time
// bool    verbose      Verbose or not
//
// Return values
// Type          Description
// tuple {{double[]},{double[],double[],double[]}}
// Description   : 
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 0.1
// History       : 0.1  12-mar-2007 DAC
//                 0.2  13-mar-2007 Added "string" to return tuple
//                 0.3  16-apr-2007 Use arrayID to choose the relevant
//                                  sensitivity table. Added logic to
//                                  choose one of the four SPECcontline
//                                  files
//                 1.0  23-oct-2007 Added input variable to identify
//                                  FreqSwitch
//                 1.1  24-oct-2007 Accept nbOBS and nbOFF (not used
//                                  yet)
//                 2.0 01-dec-2009 VD SCR PHS-1272 
//                 3.0 20-jan-2010 VD PHS-1302
//                 4.0 26-jan-2010 VD PHS-1302 !! sedb2a .. waveRef <102.0!
//                                                order 3 too! etc
//                 5.0 03-may-2010 VD PHS-1393 order23
//                 6.0 05-may-2010 VD PHS-1385 ripples etc..
//                 7.0 07-may-2010 VD .. adapt to range?
//                 8.0 11-jun-2010 VD PHS-1463
//                 9.0 18-jun-2010 VD PHS-1472 
//
{string,double[],double[],double[],double[]} procedure PacsSpecAuxRMS_tmp {
    /* RANGE or LINE AOT                                                    */
    string aotID = "RANGE";
    /* ID for this RMS computation                                          */
    string arrayID = "undefined";
    /* define A / B filter */
    string orderSel = "undefined";
    /* Array of wavelengths                                                 */
    double[] wave = [0.0];
    /* Wave reference                                                       */
    double waveRef = 100.0;
    /* Integration time                                                     */
    double intTime = 10.0;
    /* Type of observation                                                  */
    string obsType = "whatever";
    /* nbOBS and nbOFF                                                       */
    int nbOBS = 1;
    int nbOFF = 0;
    int gratScanObsTime = 1;
    /* Verbose or not                                                        */
    bool verbose = false;
}{
    // Number of wavelengths in array
    int nbWaves = length(wave);
    if(verbose) {
        debug_print("AuxRMS:Size wave table: " + nbWaves);
    }
    // Create arrays for rmsNoiseCONT and rmsNoiseLINE
    double[] rmsNoiseC = [0.0];
    double[] rmsNoiseL = [0.0];
    // Integration time related variables
    // intTime is SRC/REF for chopping !!Each one, not the sum!!
    // For FreqSwitch, intTime is the total time LINE+REF  (assume we switch by a 
    // few pixels)
    // In either case, the "line" is the result of a subtraction (either SRC-REF 
    // or SRC - shiftedSRC). When both "SRC" and "REF" have the same rms, the RMS
    // increase introduced by the subtraction operation is sqrt(2). 
    // In raster/OFF, each raster point has a noise ONrms. However, the OFF position
    // is performed nbOFF times; its rms is OFFrms = ONrms/sqrt(nbOFF). The rms
    // of the difference is then sqrt(1 + 1/nbOFF) larger. Ignore for raster
    // for time being
    double difRMSfactor = sqrt(2.0);
    // The new frequency switch scheme uses 2 OFF positions to be subtracted
    // from the SRC - shiftedSRC array. This introduces an extra sqrt(1+1/2)
    // difRMSfactor = sqrt(2.0)*sqrt(1.5) = sqrt(3.0)
    if(obsType == "FreqSwitch" || obsType == "GratScanNoChop") {
        if(aotID != "RANGE") {
            difRMSfactor = sqrt(3.0);
        }
    }
    // Scaling factor for tabulated rms (good for 1 sec time)
    double scale = difRMSfactor / sqrt(intTime);
    if(verbose) {
        debug_print("AuxRMS: intTime " + dformat(intTime,2));
        debug_print("AuxRMS: difRMSfactor  " + dformat(difRMSfactor,2));
        debug_print("AuxRMS: scaleRMS" + dformat(scale,3));
        debug_print("AuxRMS: waveRef: " + waveRef);
    }
    // Establish which sensitivity table shall be used
    // PHS-198 in parts: waveRef MUST be entered in order 1 parallel bands
    string sensTable = "TBD";
    string sensTablePar = "TBD";
    //    if(arrayID == "order1" || waveRef >= 103.1) {
    if(arrayID == "order1") {
        if(waveRef >= 102.0) {
            sensTable = "SPECContLine1";
            sensTablePar = "SPECContLine1";
            if(verbose) {
                debug_print("here is all in Red");
            }
        } else {
            if(waveRef <= 73.0) {
                if(orderSel == "order2") {
                    sensTable = "SPECContLine1";
                    sensTablePar = "SPECContLine2";
                    if(verbose) {
                        debug_print("here is given in red but ref in 2A");
                    }
                }
                if(orderSel == "order3") {
                    sensTable = "SPECContLine1";
                    sensTablePar = "SPECContLine3";
                    if(verbose) {
                        debug_print("here is given in red but ref in 3A");
                    }
                }
                if(orderSel == "order23") {
                    sensTable = "SPECContLine1";
                    sensTablePar = "SPECContLine23";
                    if(verbose) {
                        debug_print("here is given in red but ref in 2A");
                    }
                }
            } else {
                if(waveRef > 73.0 && waveRef <= 105.0) {
                    sensTable = "SPECContLine1";
                    sensTablePar = "SPECContLine2";
                    if(verbose) {
                        debug_print("here is given in red but ref in 2B");
                    }
                }
            }
        }
    }
    if(arrayID == "order2" && waveRef < 102.0) {
        sensTable = "SPECContLine2";
        sensTablePar = "SPECContLine2";
    } else {
        if(arrayID == "order2" && waveRef >= 102.0) {
            sensTable = "SPECContLine2";
            sensTablePar = "SPECContLine1";
        }
    }
    if(arrayID == "order3" && waveRef < 102.0) {
        sensTable = "SPECContLine3";
        sensTablePar = "SPECContLine3";
    } else {
        if(arrayID == "order3" && waveRef >= 102.0) {
            sensTable = "SPECContLine3";
            sensTablePar = "SPECContLine1";
        }
    }
    if(arrayID == "order23" && waveRef < 102.0) {
        sensTable = "SPECContLine23";
        sensTablePar = "SPECContLine23";
    } else {
        if(arrayID == "order23" && waveRef >= 102.0) {
            sensTable = "SPECContLine23";
            sensTablePar = "SPECContLine1";
        }
    }
    if(verbose) {
        debug_print("AuxRMS in Nom band will use table " + sensTable);
        debug_print("AuxRMS in Par band will use table " + sensTablePar);
    }
    if(sensTable == "TBD") {
        error("Internal error: did not find proper sensitivity table");
    }
    // Get rms/sec from SPECcontline, a value per wavelength
    // Create CONT and LINE noise arrays; wave array already exists
    ///   if (verbose) {debug_print("AuxRMS:Wave Interpol From/To]: " 
    ///                          + wave[0] + "/" + wave[nbWaves-1]);}
    for(int loop0 = 0 .. nbWaves - 1) {
        //     Current wavelength
        double waveNow = wave[loop0];
        //     Get CONT and LINE rms values
        //     Use scale factor to convert into observed noise     
        rmsNoiseC[loop0] = scale * interpolate(sensTable,"contRMS",waveNow);
        rmsNoiseL[loop0] = scale * interpolate(sensTable,"lineRMS",waveNow);
    }
    // Find min and max of rmsNoiseC
    int[] minmax = PacsArrayMinMax(rmsNoiseC,verbose);
    double noiseCmin = rmsNoiseC[minmax[0]];
    double waveCmin = wave[minmax[0]];
    double noiseCmax = rmsNoiseC[minmax[1]];
    double waveCmax = wave[minmax[1]];
    // Find min and max of rmsNoiseL
    minmax = PacsArrayMinMax(rmsNoiseL,verbose);
    double noiseLmin = rmsNoiseL[minmax[0]];
    double waveLmin = wave[minmax[0]];
    double noiseLmax = rmsNoiseL[minmax[1]];
    double waveLmax = wave[minmax[1]];
    //  Deal with reference wavelength
    if(verbose) {
        debug_print("AuxRMS:Interpolate w/lambda " + waveRef);
    }
    double noiseRefCont = scale * interpolate(sensTablePar,"contRMS",waveRef);
    double noiseRefLine = scale * interpolate(sensTablePar,"lineRMS",waveRef);
    // Compute the RMS fluctuations at special wavelengths
    // Continuum
    double noiseCref = noiseRefCont;
    // Line
    double noiseLref = noiseRefLine;
    // PHS-1472 on time scaling
    if(obsType == "GratScanNoChop" && aotID != "RANGE") {
        noiseCmin = noiseCmin * sqrt(intTime) / sqrt(double(gratScanObsTime));
        noiseCmax = noiseCmax * sqrt(intTime) / sqrt(double(gratScanObsTime));
        noiseCref = noiseCref * sqrt(intTime) / sqrt(double(gratScanObsTime));
        noiseLmin = noiseLmin * sqrt(intTime) / sqrt(double(gratScanObsTime));
        noiseLmax = noiseLmax * sqrt(intTime) / sqrt(double(gratScanObsTime));
        noiseLref = noiseLref * sqrt(intTime) / sqrt(double(gratScanObsTime));
        if(verbose) {
            debug_print("intTime / graScanObsTime: " + intTime + " / " + gratScanObsTime);
        }
    }
    if(verbose) {
        debug_print("AuxRMS:nbOBS/nbOFF: " + nbOBS + "/" + nbOFF);
        //      debug_print("AuxRMS:rmsCONT min/max: " + noiseCmin + "/" + noiseCmax);
        debug_print("AuxRMS:RMScont min/waveMin: " + noiseCmin + " [Jy] at " + waveCmin);
        debug_print("AuxRMS:RMScont max/waveMax: " + noiseCmax + " [Jy] at " + waveCmax);
        debug_print("AuxRMS:RMScont ref/waveRef: " + noiseCref + " [Jy] at " + waveRef);
        //      debug_print("AuxRMS:rmsLINE min/max: " + noiseLmin + "/" + noiseLmax);
        debug_print("AuxRMS:RMSline min/waveMin: " + noiseLmin + " [Jy] at " + waveLmin);
        debug_print("AuxRMS:RMSline max/waveMax: " + noiseLmax + " [Jy] at " + waveLmax);
        debug_print("AuxRMS:RMSline ref/waveRef: " + noiseLref + " [Jy] at " + waveRef);
    }
    // Copy results to noiseWave and return
    double[] noiseWave = [0.0];
    //   CONTinuum
    noiseWave[0] = waveCmin;
    noiseWave[1] = noiseCmin;
    noiseWave[2] = waveCmax;
    noiseWave[3] = noiseCmax;
    //   LINE
    noiseWave[4] = waveLmin;
    noiseWave[5] = noiseLmin;
    noiseWave[6] = waveLmax;
    noiseWave[7] = noiseLmax;
    //   CONT and LINE for refWave     
    noiseWave[8] = waveRef;
    noiseWave[9] = noiseCref;
    noiseWave[10] = noiseLref;
    if(verbose) {
        debug_print("AuxRMS:arrayID: " + arrayID);
    }

    return {arrayID,noiseWave,wave,rmsNoiseC,rmsNoiseL};
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose 
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//   - 2-3 position chopping AOT with/without calibration block  ~0.50h
//    (1 filter may be sufficient)
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//                 
//
// TCL author    : N/A
// TCL file      : tN/A
// CUS author    : TM
// Script file   : PHOT_chopped_photometry_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version	 : 1.0 
// History       : 0.1 20-apr-2005 DAC
//
//                 0.2 25-apr-2005 DAC Filter back to POS A
//                 0.3 25-apr-2005 DAC Start/stop SPU
//                 0.4 26-apr-2005 DAC Use PACS_spu_reset
//		   1.0 25-mar-2008 VDP translated from IST to PV phase syntax
//
obs PacsEng_Phot_chopped_photometry {
    /* Needed variables to call PacsEng_Phot_chopped_photometry                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_chopped_photometry                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Phot_chopped_photometry()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Phot_chopped_photometry();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : CONF_grating_DEGMODE.cus
// Missionphase  : PACS FM ILT
//
// Purpose       : Prepare grating mechanism for operations in DEGRADED MODE
//
// Author        : P. Royer
//
// Arguments     :  
//
// Description   : This script will switch on and set all required parameters 
//                 for the grating to be used in OPEN LOOP / DEGRADED MODE
//                              
// Comments      : 
//
// Version       : 1.0
// History       : 1.0 / 05-Jul-2006 created from the nominal mode script
//		   1.1 / 03-Nov-2006 removed movement to 'center' 
//			             (position 8192 !=center)
//
procedure CONF_grating_DEGMODE {
}{
    // Use HF's approach, where everything is hardcoded
    // Default parameters :
    //		Rate = 32 (grating speed ~ 1 deg / sec)
    //		Maximum Output Current = 8192 (138.75 mA)
    //
    {int}[] parlist = [{32},{8192}];
    int[] aux = [32,8192];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_GRAT_DEGMOD_PAR(parlist,check_sum);
    delay(1);
    //
    // SWITCH ON GRATING CONTROLLER
    //
    Pacs_DMC_SWON_GRAT_CONT();
    delay(1);
    //
    // ENTER DEGRADED MODE
    //
    Pacs_DMC_ENTER_GRAT_CONT_DEG(0);
    delay(1);
    //-------------------------
    // End of Procedure
    //-------------------------
}

//$Id$
//
// Purpose       : Perform Check for saturation according to TM's input:
//- Bolometers: Check for saturation for low-high gain settings at
//              PACS calibration sources and background level for
//              both filters
// -----> Assume PHOT_setup_OBS has been run before.
//        (check list should be correct...)
//  Check before executing:
//      o  is the gain still "high"?
//      o  is the filter position still at "1"?
//      o  is the sequence mode "Sbolo-Sref"?
//      o  is the data mode "Bolo & HK"?
//      o  are the photometry science packets still generated?
//
//  Description:
//      o  move the chopper to various positions, with 2 sec per plateau:
//         CUS script Chop_scan_both_ways <-25000,5000,10,2> --> 48 sec
//      o  switch to gain "low"               (PACS_Phot_Gain_low.tcl)
//      o  repeat chopper sequence
//         CUS script Chop_scan_both_ways <-25000,5000,10,2> --> 48 sec
//      o  switch filter to position "0"      (tm_phot_fil_switch.tcl)
//      o  repeat chopper sequence
//         CUS script Chop_scan_both_ways <-25000,5000,10,2> --> 48 sec
//      o  switch to gain "high"              (PACS_Phot_Gain_high.tcl)
//      o  repeat chopper sequence
//         CUS script Chop_scan_both_ways <-25000,5000,10,2> --> 48 sec
//      o  switch filter back to position "1" (tm_phot_fil_switch.tcl)
//      o  repeat chopper sequence
//         CUS script Chop_scan_both_ways <-25000,5000,10,2> --> 48 sec
//  Scripts:
//      o  PACS_Phot_Gain_low.tcl
//      o  PACS_Phot_Gain_high.tcl
//      o  tm_phot_fil_switch.tcl
//      o  CUS script "Chop_scan_both_ways"
//      
//  Expected Results:
//      o  check signal patterns in QLA
//      o  in case of saturation: note the gain-filter-chopper
//         combinations and avoid these settings later on
//
// CUS author    : DAC
// Script file   : PHOT_saturation_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version	 : 1.0
// History       : 0.1 22-apr-2005 DAC
//                 0.2 25-apr-2005 DAC
//                 0.3 26-apr-2005 DAC Start/stop SPU
//                 0.4 20-oct-2005 DAC Added SPEC_Chop_move_abs_raw
//                 0.5 10-apr-2007 TM updated
//		   1.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//
procedure Pacs_Phot_saturation {
}{
    //
    // preparation of the bolometers and start of SPU (included in "PhotSetDirectMode")
    //
    PHOT_set_gain("LOW");
    PhotSetDirectMode();
    //
    PHOT_fltw_move("POS B");
    //
    //     o  move the chopper to various positions, with 2 sec per plateau:
    //   
    int nb_up_down = 1;
    // P#1  number of up-down seqs.
    int nb_rdouts = 80;
    // P#2  number of readouts on step
    int nb_steps_up = 20;
    // P#3  number of steps up
    int nb_steps_dn = 20;
    // P#4  number of steps down
    int step_up = 2300;
    // P#5  relative move up
    int step_dn = -2300;
    // P#6  relative move down
    int detector = 4;
    // Detector to SYNCH on
    int comp_mode_blu = 0;
    // "Blue" compression
    int comp_mode_red = 0;
    // "Red" compression
    int chop_start = -23000;
    // Chopper start position
    int chop_def = 0;
    // Chopper default position
    debug_print("Start OBCP_chop_scan_phot");
    OBCP_chop_scan_phot(nb_up_down,nb_rdouts,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,comp_mode_blu,comp_mode_red,chop_start,chop_def);
    delay(2);
    //
    PHOT_fltw_move("POS A");
    //
    //      o  repeat chopper sequence
    //
    debug_print("Start OBCP_chop_scan_phot");
    OBCP_chop_scan_phot(nb_up_down,nb_rdouts,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,comp_mode_blu,comp_mode_red,chop_start,chop_def);
    delay(2);
    //
    //
    PHOT_fltw_move("POS B");
    //
    //      o  repeat chopper sequence
    //
    debug_print("Start OBCP_chop_scan_phot");
    OBCP_chop_scan_phot(nb_up_down,nb_rdouts,nb_steps_up,nb_steps_dn,step_up,step_dn,detector,comp_mode_blu,comp_mode_red,chop_start,chop_def);
    delay(2);
    //
    // Stop SPU
    //
    PACS_spu_reset();
    // Sync to return real execution time (maybe fractional)
    sync();
}

// File          : PACS_GeGa_SFT_Init_Cold.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Cold SFT of Ge:Ga detector chain 
//
// Author        : H. Feuchtgruber
//
// Arguments     : none
//                 
//
// Description   : This script will switch on and set all required parameters
//                 for a test of the Ge:Ga detector chain at cold conditions
//                 
//                              
// Comments      :      
//
// Version       : 1.0
// History       : 1.0 / 16-Nov-2004 initial version
// 1.1  7-mar-2006 TeleCommand Pacs_DMC_SET_B_SPEC_HEAT_1_C renamed
//                 TeleCommand Pacs_DMC_SET_B_SPEC_HEAT_2_C renamed
// 1.2 24-mar-2006 Large overhaul based on 
//                 SetupSpectroscopyWEplusFPUsim.tcl script
// 1.3 30-oct-2005 Delay after detector setup 5->8 sec
// 1.4 24-nov-2006 modified bias according to LB input
//                 
procedure PACS_GeGa_SFT_Init_Cold {
}{
    debug_print("Start PACS_GeGa_SFT_Init_Cold");
    //DPU_SET_HK_LIST (SPEC for both channels)
    Pacs_DPU_SET_HK_LIST("SPEC","BOTH Array");
    delay(1);
    // DMC_WRT_BOL_REC_OPT(ID,LENGTH,4,CHKSUM)
    int[] argum = [4];
    {int}[] argTuple = [{4}];
    int chksum = checksum("int",argum);
    Pacs_DMC_WRT_BOL_REC_OPT(argTuple,chksum);
    delay(1);
    // DMC_WRT_B_DEC_REC_OPT(ID,LENGTH,4,CHKSUM)
    argum = [4];
    argTuple = [{4}];
    chksum = checksum("int",argum);
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,chksum);
    delay(1);
    // DMC_WRT_R_DEC_OPT(ID,LENGTH,4,CHKSUM)
    argum = [4];
    argTuple = [{4}];
    chksum = checksum("int",argum);
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,chksum);
    delay(1);
    // DMC_WRT_TIMING_FPGA_PAR(ID,LENGTH,16384,40,2,32,0,P//9,CHKSUM)
    {int}[] list_tuple = [{0x0},{0x0},{0x0},{26},{0x95217cb},{0xb}];
    int[] list_int = [0x0,0x0,0x0,26,0x95217cb,0xb];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_TIMING_FPGA_PAR(list_tuple,chksum);
    delay(1);
    // DMC_SET_TIMING_FPGA_PAR
    Pacs_DMC_SET_TIMING_FPGA_PAR();
    message("Default spectroscopy timing parameters set!");
    //  ======== Initial detector setup ====================
    // DMC_SWON_B_DEC SWITCH ON THE BLUE DEC POWER
    Pacs_DMC_SWON_B_DEC();
    delay(8);
    // DMC_SWON_R_DEC" SWITCH ON RED DEC POWER
    Pacs_DMC_SWON_R_DEC();
    delay(8);
    // Wait after DEC switch-on
    delay(5);
    debug_print("DECs are on !");
    // Now define the startup Ge:Ga detector setup
    int read_per_ramp_b = 8;
    int cre_ctrl_b = 396;
    int bias_r_b = 0;
    int bias_d_b = 0;
    int read_per_ramp_r = 8;
    int cre_ctrl_r = 396;
    int bias_r_r = 0;
    int bias_d_r = 0;
    // DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000,chksum);
    delay(1);
    // DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000,chksum);
    delay(1);
    // DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    // DMC_SWON_B_SPEC" SWITCH ON BLUE SPECTROMETER ARRAY POWER
    Pacs_DMC_SWON_B_SPEC();
    delay(1);
    // PC091420 "DMC_SWON_R_SPEC" SWITCH ON RED SPECTROMETER ARRAY POWER
    Pacs_DMC_SWON_R_SPEC();
    delay(1);
    debug_print("SPECs are on !");
    // Wait for CRE HW sequence to finish
    delay(15);
    // now select the CREs
    cre_ctrl_b = 398;
    cre_ctrl_r = 398;
    // DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000,chksum);
    delay(1);
    // DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000,chksum);
    delay(1);
    // DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    // Now define the actual Ge:Ga detector setup
    read_per_ramp_b = 64;
    cre_ctrl_b = 398;
    bias_r_b = 41;
    bias_d_b = 4;
    read_per_ramp_r = 64;
    cre_ctrl_r = 398;
    bias_r_r = 41;
    bias_d_r = 4;
    double heater_blue = 0.0;
    // DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,read_per_ramp_b,cre_ctrl_b,bias_r_b,bias_d_b,60000,chksum);
    delay(1);
    // DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    list_int = [32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000];
    chksum = checksum("int",list_int);
    // Use the RAW version of the TC not to bother with ENG conversions
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,read_per_ramp_r,cre_ctrl_r,bias_r_r,bias_d_r,60000,chksum);
    delay(1);
    // DMC-SET-PARAM-BOTH-SPEC SET TIMING PARAMTERS FOR BOTH SPEC ARRAYs
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    delay(1);
    // DMC_SWON_BD_HEATER
    Pacs_DMC_SWON_BD_HEATER();
    delay(1);
    // DMC_SET_B_SPEC_HEAT_C
    Pacs_DMC_SET_B_SPEC_HEAT_C(heater_blue);
    delay(1);
    debug_print("Detectors are up and running at default settings!");
    // DMC_SYNCHRONIZE_ON_DET(1)
    Pacs_DMC_SYNCHRONIZE_ON_DET(1);
    delay(1);
    // DMC_WRT_B_DEC_REC_OPT" WRITE THE BLUE DEC RECEIVER OPTIONS
    argTuple = [{0}];
    Pacs_DMC_WRT_B_DEC_REC_OPT(argTuple,0x84c0);
    delay(1);
    // DMC_WRT_R_DEC_REC_OPT" WRITE THE RED DEC RECEIVER OPTIONS
    argTuple = [{0}];
    Pacs_DMC_WRT_R_DEC_REC_OPT(argTuple,0x84c0);
    delay(1);
    // DMC_VAL_SCI_DATA_BOTH" VALIDATE SCIENCE DATA FROM BOTH CHANNELS
    Pacs_DMC_VAL_SCI_DATA_BOTH();
    delay(1);
    // # ==== End of detector setup ==============
}

// Missionphase  : EQM IMT
//
// Purpose	: Move chopper to absolute position
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  is called.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and chopper enabled.
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 1.0	
// 
// History 	: 1.0 13-04-05 creation by HD
//                //1.1 19-sep-2006 DAC Add duration !=0
//		  2.0 07-02-2008 VDP added WriteEndBB for PV phase
//
block Chop_mov_abs PACS 321 {
    int chop_abs_pos = 0; // chopper absolute position
}{
    // Register start of BB
    WriteBBID($BBID);
    ////    delay(1);
    Pacs_DMC_MOVE_CHOP_ABS(chop_abs_pos);
    // Reset Block ID
    WriteEndBB();
}

// Missionphase  : FM
//
// Purpose	: Stop diagnostic housekeeping
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for stopping the diagnostic housekeeping
//		  is called.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, and diagnostic housekeeping is started.
//	      
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 1.0	
// 
// History 	: 1.0 21-07-06 creation by HD
//		  
block PACS_stop_dhk_bb PACS 354 {
}{
    // Register start of BB
    WriteBBID($BBID);
    // Stop diagnostic HK
    Pacs_DMC_STOP_DIAG_HK();
    // Mark End of Block
    WriteEndBB();
}

// File          : PACS_Spec_Curing_OBS.cus
//
// Purpose       : Flasher curing : short flashes with dead times -> Temp & signal evolutions
//		   Third part of the Flashers Performance check (curing schemes)
//
// Author        : P. Royer
//
// Arguments     : 
//
// Prerequisite  : Flashers on
//
// Description   : Check scheme of flasher curing : short flashes with dead times
//               :
// Comments      : 
//                 
//
// Version       : 2.1
// History       : 1.0 / 09-Jun-2006 initial version by PR
//                 1.1 / 06-Apr-2007 Updated chop_pos_BB -> FMILT BB2
//		   2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//                    2.1 /  01-Jul-2008 introduced CRE Setup & corresponding CALU
//
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.1
// @purpose Flasher curing : short flashes with dead times -> Temp & signal evolutions
// @comment - 
//
procedure Pacs_Spec_Curing {
    int blue_flasher_current = 205; //1mA
    int red_flasher_current = 205; //1mA
    int nflash = 3;
    int flash_time = 20;
    int idle_time = 30;
}{
    //
    // Internal parameters
    // -------------------
    int chop_pos_BB2 = 21200;
    //
    // Setup CREs    -->    Largest Capacitance
    //
    string calUname = "CONFCRECuring";
    // Calibration Table
    string calUrow = "PV";
    // Row in table = Instrument Configuration
    double bias_d_blue = dlookup(calUname,calUrow,"bias_d_blue");
    double bias_d_red = dlookup(calUname,calUrow,"bias_d_red");
    double bias_res_blue = dlookup(calUname,calUrow,"bias_res_blue");
    double bias_res_red = dlookup(calUname,calUrow,"bias_res_red");
    int ramp_blue = ilookup(calUname,calUrow,"ramp_blue");
    int ramp_red = ilookup(calUname,calUrow,"ramp_red");
    int capacity_blue = ilookup(calUname,calUrow,"capacity_blue");
    int capacity_red = ilookup(calUname,calUrow,"capacity_red");
    //
    SPEC_CRE_No_Heater_setup(ramp_red,ramp_blue,bias_d_red,bias_res_red,bias_d_blue,bias_res_blue,capacity_blue,capacity_red);
    //
    // SPU SETUP
    //
    int comp_mode_blu = 16;
    // Compression mode blue channel
    int comp_mode_red = 16;
    // Compression mode red channel
    int nb_samp_subramp_blu = 16;
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 16;
    // Nb of red samples per sub-ramp
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    delay(5);
    //
    // SEND CHOPPER TO BB2
    PACS_Chop_Move_Abs(chop_pos_BB2);
    delay(1);
    //
    // SWON FLASHERS
    //
    PACS_Spec_Flash_SWON();
    delay(10);
    //
    // Loop on low power regimes
    // -------------------------
    for(int loopin = 1 .. nflash) {
        PACS_Spec_Flash_Setup(blue_flasher_current,red_flasher_current);
        delay(flash_time);
        PACS_Spec_Flash_Setup(0,0);
        delay(idle_time);
    }
    //
    // SWOF FLASHERS
    //
    PACS_Spec_Flash_SWOF();
    delay(10);
    // 
    // Detector stabilisation / cooldown / recovery
    // --------------------------------------------
    delay(1200);
    //
    // SEND CHOPPER TO DEFAULT
    PACS_Chop_Move_Abs(0);
    delay(1);
    //
    //
    // SPU RESET
    //
    PACS_Spec_SPU_Reset();
    delay(1);
    //
}

// $Id:$
// Purpose        : Set the temperatures of CS1 and CS2
//
// CUS author     : K. Okumura
//
// Input arguments:
//   temp_CS1 : Temperature of CS1
//   temp_CS2 : Temperature of CS1
//   tStabili : Stanilisation time after the temperatures are set
//
// Return values
// N/A
//
// Comments      :
//
// History: 
// 0.1  18-jul-2008  First version
//
obs PacsEng_setCSsTemp {
    double set_CS1 = 48.0; // CS1 setting (ohms)
    double set_CS2 = 58.0; // CS2 setting (ohms)
    int tStabili = 2100; // CSs stabilisation time in seconds
}{
    bool execute = true;
    // Initial hold
    int tih = imax(1,duration(WriteOBSID($OBSID)));
    // Final hold
    int tfh = imax(1,duration(WriteEndID())) + tStabili;
    // Duration of "stable" pointing
    int tp = duration(CS_temp("CS1",set_CS1));
    tp = tp + duration(CS_temp("CS2",set_CS2));
    tp = imax(1,tp);
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            // Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            // Call the PHOT setup script
            CS_temp("CS1",set_CS1);
            CS_temp("CS2",set_CS2);
        }
        if(state[0] == 5) {
            // Wait for CS to stabilize
            delay(tStabili);
            // Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// Script        : PACS_Chopper_uk_move_21000_NoConf_ast.cus
// Missionphase  : SVT / Flight
//
// Purpose	: Move chopper to absolute position  
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for move chopper to absolute position
//	  	  is called. Go to chopper position +-21000 with plateau time 
//	          of 2 sec and chop cycles of 10. 
//                  
// Dependencies : 
//
// Preconditions   : PACS switched on and Chopper switched on.
//                 
// Comments	: This script is based on PACS_Chopper_uk_move_21000_ast_OBS,
//                     but without configuration and with mois comments
//
// Version	: 1.0	
// 
// History 	: 1.0 17-10-2007 BV First version
//		  
procedure PACS_Chopper_uk_move_21000_NoConf_ast {
}{
    mois_comment("Perform rectangular chopping with step 21000");
    //
    int chop_pos = 21000;
    // chopper position
    int cycle = 10;
    // give cycle #
    int plateau_time = 2;
    // select plateau time in sec
    // Start Diag. HK
    mois_step("Start Diagnostic housekeeping");
    SPEC_Chopper_dhk_5hk_1khz_bb();
    mois_step("Enable chopper controller");
    // Enable Chopper Controller 
    EnDis_chopper("ON");
    delay(5);
    mois_step("Perform rectangular chopping");
    // move chopper to zero
    PACS_Chopper_mov_abs_fm_bb(0);
    delay(1);
    // do observations
    int i = 1;
    while(i <= cycle) {
        PACS_Chopper_mov_abs_fm_bb(chop_pos);
        delay(plateau_time);
        PACS_Chopper_mov_abs_fm_bb(-chop_pos);
        delay(plateau_time);
        i = i + 1;
    }
    // move chopper to zero
    PACS_Chopper_mov_abs_fm_bb(0);
    delay(1);
    mois_step("Disable chopper");
    // Disable Chopper Controller 
    EnDis_chopper("OFF");
    delay(5);
    mois_step("Disable diagnostic housekeeping");
    // Stop diagnostic housekeeping
    PACS_stop_dhk_fm_bb();
}

// Purpose       : Set PACS in burst mode
// Author        : T.Mueller, H. Feuchtgruber
// CUSification  : DAC
// Version       : 1.0
// History       : 1.0 / 16-Nov-2004 initial version
//                 
procedure PACS_Burstmode_Setup {
}{
    // PC009380 "DPU_SET_BUS_LIST" SWITCH THE DPU FROM NOMINAL TO BURST MODE
    //                             AND VICEVERSA
    //                             PP006380 "ENABLE_DISABLE"
    // tcsend PC009380 {PP006380 1}
    // Switch CDMU to Burst profile
    Pacs_DPU_SET_BUS_LIST("ENABLE");
    delay(1);
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : Pierre Royer
//
// Description   : Set/resets OBSID, calls associated procedure
//                      The procedure
//		DISABLES THE GRATING CONTROLLER
//                                         WRITES THE GRATING CONTROLLER PARAMETERS
//                                         ENABLES THE GRATING CONTROLLER
//
// Dependencies  : see associated procedure
//
// Preconditions : GRATING CONTROLLER SWON
//
// Comments      :
//
// Version       : 2.0
// 
// History       : 1.0 29-Jul-2007 Creation
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_Gra_IST_Set_Ctrl_Par {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Set_Ctrl_Par                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_Set_Ctrl_Par                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_IST_Set_Ctrl_Par()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_IST_Set_Ctrl_Par();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
// Purpose       : Stop SPECtroscopy observations at end of AOT
//                  
// TCL author    : 
// TCL file      : 
// CUS author    : Diego Cesarsky
// Script file   : SPEC_aot_epilogue.txt 
//
// Input arguments
// Type Name           Default   Description
//
// Description   : Not much for now (just STOP SPU)
//                 Move grating from wwwhere OBCPs left it to the park
//                 position
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      : Based on V1.3 of TM's tm_spu_setup.tcl. Both
//                 SPUS and SPUL are initialized to same set of parameters
//
// Version       : 1,0
// History       : 0.1 13-apr-2006 First creation
//                 0.2 15-feb-2007 Leave grating at park position
//		   1.0 23-sep-2008 SCR 4431 data_rate
procedure SPEC_aot_epilogue {
    int gratFrom = 500000; // Where OBCPs have left the grating
    int gratTo = 535000; // Grating park position
    bool verbose = false;
}{
    // Park the grating
    SPEC_grat_move(gratFrom,gratTo,verbose);
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    data_rate(0.0);
    // Sync the bus (function duration will get the "true" duration)
    sync();
    // end of procedure
}

// $Id$
// Missionphase  : PACS PV Phase
//
// Purpose       : Flashers Short Functional Test
//
// Author        : P. Royer
//
// Arguments     :
//
// Description   : Sends current to both flashers for short times, the goal is only to see some reaction in the HK
//
//
// Prerequisite : The flashers are SWITCHED ON ALREADY
//	  	  The correct HK & Diaghk lists are already set & acquired
//
// Comments      : 
//                 
//
// Version       : 1.0
// 		 : 1.2 13-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Spec_Flash_SFT_Warm {
    /* No need for variables to call PacsEng_Spec_Flash_SFT_Warm           */
    /*  string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Flash_SFT_Warm                   */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Flash_SFT_Warm()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Flash_SFT_Warm();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsLineSpecEstimatorOBCP27.txt,v 1.16 2007/04/25 15:14:04 dcesarsk Exp $ 
// Script file   : PacsLineSpecEstimatorOBCP27_PV.txt 
// Purpose       : Estimate several PACS parameters for each spectral
//                 line specified by the HSPOT user
//
// CUS author    : DAC
//
// Input arguments
// type           name          Description
// tuple          lines         spectral line info from HSPOT
// tuple          waveTuple     grating info associated to "lines"
// tuple          paramsSPECdef confSPECblu & confSPECred & confOBCP
// bool           noddingSel    nodding demanded?
//
// Return values
// Type             Description
// tuple            Derived values for paramsSPECdef
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 22-may-2008 DAC Based on PacsLineSpecEstimatorOBCP27
//                                     - reads OBCP27params_PV
//                                     - ignores userREPfactor (read CAL file)
// 0.2 15-jul-2008 DAC No longer ignore repFACTOR
//
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsLineSpecEstimatorOBCP27_PV {
    {string,double,int,double,double,double,string,string} lines = {"NONE",60.2,0,0.0,0.0,0.0,"bla","bla"}; // linesTuple HSPOT
    {double,int,int,int,int} waveTuple = {0.0,0,0,0,0}; // waveTuple          
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; // Default values
    bool noddingSel = false; // Nodding requested?
    bool faintLines = true; // Fast OBCP if false 
    bool verbose = false; // print debug information
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    //////////////// Logic to obtain desired OBS time ///////////////////////////
    //
    // ORDER of the current line
    int order = waveTuple{1};
    double waveLEN = waveTuple{0};
    // User desired repetition factor for current line
    int userREPfactor = lines{2};
    // Get the "quantum" OBS time for the current order. U-CAL time doubles if 
    // nodding is allowed
    int nodFactor = 1;
    if(noddingSel) {
        nodFactor = 2;
        int nb_nods = 1;
    } else {
        nb_nods = 0;
    }
    // Grating info pertaining to the current wavelength is in waveTuple
    int nb_grat_step_up = waveTuple{3};
    int nb_grat_step_dn = waveTuple{3};
    int grat_step_up = waveTuple{4};
    int grat_step_dn = -grat_step_up;
    int grat_start_pos = waveTuple{2};
    // Get "duration related" parameters from OBCP27params U-CAL table
    string calNAME = "OBCP27params_PV";
    // The acces key is the grating order
    string key = "" + order;
    // There is a row per order; it lists main OBCP parameters
    //    int nb_up_down = ilookup(calNAME,key,"nb_up_down");
    int nb_up_down = userREPfactor;
    int nb_SRC_OFF = ilookup(calNAME,key,"nb_SRC_OFF");
    int nb_ramps_plateau = ilookup(calNAME,key,"nb_ramps_plateau");
    int nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    // Estimate the OBS time for this rangeInfo; estimation is for ONE nod only.
    int nb_rdouts_ramp = confSPECred{1};
    int[] dureeOBCP27 = PacsDureeOBCP27(nb_up_down,nb_grat_step_up,nb_ramps_plateau,nb_CS1_CS2,nb_SRC_OFF,nb_rdouts_ramp);
    // Use SRC/REF time alone (used to be total duration)
    int quantumOBStime = nodFactor * (dureeOBCP27[1] + dureeOBCP27[2]);
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + waveLEN + " [&micro;m] with line repeated " + userREPfactor + " time(s)</p>";
    lineCnt = lineCnt + 1;
    // This is complete fantasy; just to check the code
    //============== React on LINE/CONT fluxes ========================
    // Line and continuum flux from HSPOT
    double lineFLUX = lines{3};
    double contFLUX = lines{4};
    // Low flux use large integrating capacitor
    int capa_red = 0;
    int capa_blu = 0;
    ///   if (lineFLUX <= 400.0) 
    ///     {
    ///      capa_red = 4;
    ///      capa_blu = 8;
    ///     }
    ///   if (lineFLUX <= 100.0) 
    ///     {
    ///      capa_red = 12;
    ///      capa_blu = 4;
    ///      }
    // Pack information into proper tuples
    confOBCP{0} = nb_up_down;
    confOBCP{1} = grat_step_up;
    confOBCP{2} = grat_step_dn;
    confOBCP{3} = nb_SRC_OFF;
    confOBCP{4} = nb_ramps_plateau;
    confOBCP{5} = nb_CS1_CS2;
    confOBCP{6} = nb_grat_step_up;
    confOBCP{7} = nb_grat_step_dn;
    confOBCP{8} = grat_start_pos;
    //    confOBCP { 9}  =   grat_start_time  ;
    //    confOBCP {10}  =   grat_def_pos     ;
    //    confOBCP {11}  =   grat_def_time    ;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    confSPECred{0} = capa_red;
    //   confSPECred{ 1} =  nb_rdouts_ramp_red;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    int comp_mode_red = 16;
    confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    confSPECblu{0} = capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts_ramp_blu;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    int comp_mode_blu = 16;
    confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    string msgLabel = "Observing time for " + lines{0};
    PacsMessageCenter(msgLabel,lineCnt,msgLine);
    // Debug info
    if(verbose) {
        debug_print("LineEstimatorOBCP27 duration: " + quantumOBStime);
    }
    int aux3 = 0;

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,nb_up_down,quantumOBStime,aux3}};
}

// $Id:$
//
// Missionphase  : FM CoP, PV, routine
//
// Purpose       : Leave PACS in switched off mode
//
// Author        : Diego A. Cesarsky
//
// Arguments     : None
//
// Description   : Calls OBCP_safe_2
//
// Dependencies  : OBCP_SAFE_2
//
// Comments      : Use new "no_pointing" request
//
// Version       : 0.1
// History       : 0.1 14-feb-2008 Based on AOT's PacsEng_orbit_epilogue
//                 1.0 : KO, TM : 10-jun-2009 Made from PacsEng_orbit_epilogue
//                 1.1 : KO, 03-aug-2009 OBCP_SAFE changed to OBCP_SAFE_2 in tp (SCR: PHS-1167)
//
obs PacsEng_orbit_epilogue_CSon {
}{
    bool execute = true;
    int tih = 0;
    int tfh = 0;
    int tp = duration(OBCP_SAFE_2());
    // Add needed time to set/unset OBSID
    int tset = duration(WriteOBSID($OBSID));
    int tunset = duration(WriteEndID());
    tp = tp + tset + tunset;
    // Issue PointReq
    int[] ts = no_pointing(execute,0,0,tp);
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 3) {
            //     Obtain and set OBSID
            WriteOBSID($OBSID);
            data_rate(120.0);
            //     Call OBCP_SAFE_2
            OBCP_SAFE_2();
            //     Reset OBSID and BBID
            data_rate(0.0);
            WriteEndID();
        }
    }
}

// File          : PACS_Phot_Fil_nturns.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Position sequence test of photometer filterwheel  
//
// Author        : BV, modifications by TM
// CUSification  : DAC 
// Arguments     :
//
// Description   : Moves the Photometer filter wheel <num_turns> times
//                 to position 2 and back to position 1 using absolute position
//                 commands. 
//
// Comments      : Prerequisite : spec_mec_setup has been executed 
//
// Version       : 1.6
// History       : 1.0 / 25-Nov-2003 initial version by BV 
//                 1.1 / 05-Jan-2004 Changed step strategy 
//                 1.2 / 13-Jan-2004 Taken out relative commands
//                 1.3 / 31-May-2004 Positions cfr DMC UM 2.8
//                 1.4 / 07-Jul-2004 changed for phot filter wheel
//                 1.5 / 11-Aug-2004 addition of time_on_fw_pos
//                 1.6 / 17-Nov-2004 modified for "non-interactive" EQM test
procedure PACS_Phot_Fil_nturns {
    int num_turns = 3; // Number of full turns
    int backward_toA = 0; // direction of FW rotation towards POS A : 0 forward; 1 backward
    int backward_toB = 0; // direction of FW rotation towards POS B : 0 forward; 1 backward
}{
    // fw_start integer          1 Enter initial filter wheel position (0=A; 1=B)
    // time_on_fw_pos integer   20 Enter time spent on each FW stop position (sec)
    int fw_start = 1;
    int time_on_fw_pos = 20;
    string[] fltPOS = ["POS A","POS B"];
    // Default time for one 'standard' command execution (sec)
    // set command_time 0.5
    // Minimum time between two filter wheel movements (sec)
    int slew_time = 15;
    backward_toA = 2 * backward_toA;
    backward_toB = 2 * backward_toB;
    int[] backward = [backward_toA,backward_toB];
    int movepar = 0;
    // SWON FW CONTROLLER
    Pacs_DMC_SWON_FW_PHOTO();
    delay(1);
    // Go to start position
    Pacs_DMC_MOVE_PHOT_FW_LOC_RAW(fw_start);
    delay(slew_time);
    // Move num_turns to position 0 and back to position 1 using absolute 
    // location commands
    for(int loop0 = 1 .. num_turns) {
        int i = (fw_start + 1) % 2;
        movepar = i + backward[i];
        Pacs_DMC_MOVE_PHOT_FW_LOC_RAW(movepar);
        delay(slew_time);
        delay(time_on_fw_pos);
        i = (fw_start + 2) % 2;
        movepar = i + backward[i];
        Pacs_DMC_MOVE_PHOT_FW_LOC_RAW(movepar);
        delay(slew_time);
        delay(time_on_fw_pos);
    }
    //------------------
    // End of procedure
    //------------------
}

// Missionphase  : EQM IMT
//
// Purpose       : Open Launch Lock
//                  
// Author        : Helmut Feuchtgruber
// CUS script    : HF
// CVS file      : OpenLLock.txt
//
// Arguments     : none 
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions : PACS is on or in the equivalent of SAFE mode
//                 
// Comments      : At the end PACS will still be in SPEC HK mode
//
// Version       : 1.0 24-Mar-2004 Creation by HF
//               
// History       : 1.1 29-Mar-2005 DAC. Corrected "BOTH Array" in DPU_SET_HK_LIST
//                    1.2 11-Apr-2006 HF, adapted unlock parameter to DMC SUM V4.0
//                    1.3 12-Apr-2006 HF, adapted unlock to degraded modes
//               :
int procedure OpenLLock {
    int unlock_mode = 40; // use motors: 8=motor 1, 32 =motor 2, 40 = both motors
}{
    // Tally total duration [milliseconds]
    int duration_msec = 0;
    // Set HK list
    Pacs_DPU_SET_HK_LIST("SPEC","BOTH Array");
    // Switch on grating controller
    Pacs_DMC_SWON_GRAT_CONT();
    // Unlock the grating launch lock, with parameter 0x28
    Pacs_DMC_UNLOCK_GRAT(unlock_mode);
    delay(10);
    duration_msec = duration_msec + 10000;
    // Switch off grating controller
    Pacs_DMC_SWOF_GRAT_CONT();
    delay(4);
    // go back to non prime HK list
    Pacs_DPU_SET_HK_LIST("NO_PRIME","BOTH Array");

    return duration_msec;
}

//
// $Id$
// Missionphase  : PACS FM IST SOVT2 & PV Phase
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : PR
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : PACS Spectrometer FoV Scan on the cryo cover
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version	: 1.0
// History       : 1.0  22-Oct-2008  PR
//
obs PacsCal_Spec_Dark_SOVT2 {
    /* Needed variables to call PacsCal_Spec_FoV_Scan                        */
    int obs_time = 540; // Observing time per CS/FW/Grating setting
    int chop_time = 180; // Chopper plateau [sec] during CS temp rise time (0 = no chopping)
    /* POINTING PARAMETERS */
    int naifid = 0; // 0 = Non Solar System source, >0 if fast tracking is required (Solar System sources) 
    double yoffset = 0.0; // yoffset [arcsec]
    double zoffset = 0.0; // xoffset [arcsec]
    double ra = 0.0; // RA
    double dec = 0.0; // DEC
    /* End of needed variables for PacsEng_Spec_FoV_Scan                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    int tslewmin = 0;
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Dark_SOVT2(obs_time,chop_time)));
    if(tp < 10) {
        error("The dwell time cannot be smaller than 10 sec, adjust parameters");
    }
    //
    //Use SPECTRO virtual aperture
    string ib = "P02_0";
    //Issue PointReq
    int[] ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    debug_print("ts: " + ts);
    //
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Dark_SOVT2(obs_time,chop_time);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

//$Id$
// Purpose	:  Short performance test of Chopper in IMT
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: We do rectangular chopping for four frequencies with OBCP27 and its
//                corresponding DMC-sequence 12.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on and setup spectroscopy
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 2.0	
// 
// History 	: 1.0 04-04-07 HD. IST tuned.
// 		: 2.0 25-mar-2008 VDP Adjusted to match PV phase syntax
//                      2.1 08-Apr-08 HF adapted biases to in-flight defaults
procedure Pacs_Spec_Chopper_imt504 {
}{
    // Start chopper diagnostic housekeeping
    SPEC_Chopper_dhk_imt_bb();
    // Move chopper to default position
    PACS_Chopper_mov_abs_fm_bb(0);
    // Setup CRE and set to rpr32
    int ramp_len_red = 32;
    int ramp_len_blu = 32;
    double bias_d_red = 0.03;
    double bias_r_red = 0.01;
    double bias_d_blu = 0.08;
    double bias_r_blu = 0.01;
    int capa_red = 0;
    int capa_blu = 0;
    SPEC_CRE_No_Heater_setup(ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    // setup the parameters for rectangular chopping with OBCP27
    int nb_up_down_27 = 1;
    int nb_grat_steps_27 = 1;
    int nb_cycles_grat_def_27 = 10;
    int chop_pos_REF1_27 = -12386;
    int nb_ramps_plateau_27 = 4;
    int chop_pos_REF2_27 = 12047;
    int nb_CS1_CS2_27 = 10;
    int chop_pos_CS1_27 = -21350;
    int chop_pos_CS2_27 = 21200;
    int grat_step_up_27 = 0;
    int grat_step_dn_27 = 0;
    int detector_27 = 1;
    int grat_pos_27 = 496000;
    int grat_time_27 = 40000;
    int comp_mode_blu_27 = 16;
    int comp_mode_red_27 = 16;
    int grat_def_27 = 496000;
    int chop_def_27 = 0;
    int grat_def_time_27 = 40000;
    int nb_rdouts_ramp_27 = 32;
    // Execute OBCP27 with rpr 32 and 3 ramps per chopper:1 Hz
    SPEC_CRE_No_Heater_setup(32,32,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    OBCP_grat_line_scan_chop_2(nb_up_down_27,nb_grat_steps_27,nb_cycles_grat_def_27,chop_pos_REF1_27,3,chop_pos_REF2_27,nb_CS1_CS2_27,chop_pos_CS1_27,chop_pos_CS2_27,grat_step_up_27,grat_step_dn_27,detector_27,grat_pos_27,grat_time_27,comp_mode_blu_27,comp_mode_red_27,grat_def_27,chop_def_27,grat_def_time_27,32);
    // Execute OBCP27 with rpr 32 and 1 ramps per chopper:2 Hz
    OBCP_grat_line_scan_chop_2(nb_up_down_27,nb_grat_steps_27,nb_cycles_grat_def_27,chop_pos_REF1_27,1,chop_pos_REF2_27,nb_CS1_CS2_27,chop_pos_CS1_27,chop_pos_CS2_27,grat_step_up_27,grat_step_dn_27,detector_27,grat_pos_27,grat_time_27,comp_mode_blu_27,comp_mode_red_27,grat_def_27,chop_def_27,grat_def_time_27,32);
    // Execute OBCP27 with rpr 16 and 1 ramps per chopper:4 Hz 
    SPEC_CRE_No_Heater_setup(16,16,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    OBCP_grat_line_scan_chop_2(nb_up_down_27,nb_grat_steps_27,nb_cycles_grat_def_27,chop_pos_REF1_27,1,chop_pos_REF2_27,nb_CS1_CS2_27,chop_pos_CS1_27,chop_pos_CS2_27,grat_step_up_27,grat_step_dn_27,detector_27,grat_pos_27,grat_time_27,comp_mode_blu_27,comp_mode_red_27,grat_def_27,chop_def_27,grat_def_time_27,16);
    // Move chopper to default position
    PACS_Chopper_mov_abs_fm_bb(0);
    // CRE setup to default values
    SPEC_CRE_No_Heater_setup(64,64,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,12,12);
    // Stop diagnostic housekeeping
    PACS_stop_dhk_fm_bb();
}

// File          : PACS_Phot_Warm_Startinputsignal.txt
// Missionphase  : PACS FM Test
//
// Purpose       : BOLC starting the input signal (based on PhFPU UM
//                 and email by KO 20060808)
//
// Author        : T. Mueller
// CUSification  : DAC, TM, KO
// Arguments     : none
//
//
// Description   : 
// 
// Comments      :  Coded based on PhFPU UM and Email from KO, August 8, 2006
//
// Version       : 2.1
// History       : 1.0 / 02-Jul-2004 initial version by TM
//                 1.1    7-mar-2006 SEND_COMMAND_TO_BOLC renamed
//                 1.2   13-apr-2006 TM: modifications: now 3 loops over
//                       all groups, followed by 3 loops over each group
//                       individually; test duration: 
//                 1.3   10-Aug-2006 TM: update for FM, including
//                       a group-by-group element, duration 309 sec
//                 1.4   10-Aug-2006 TM: sequencer taken out again
//                         (to be configured with PACS_Phot_Warm_Loadseq_OBS)
//                 1.5   01-Sep-2006 TM: update after BOLC-acceptance
//                       test at MPE, bugs with "delay(5)" removed
//                 1.6   09-Oct-2006 OK: TMMarkers and an extra delay(30) added
//                 1.7   17-Oct-2006 TM: delays are enlarged
//                 1.8   17-oct-2006 TM: 12 sec delay after seq mode change
//                 1.9   26-oct-2006 TM: setting of Bolo&HK data mode has been
//                                              moved to the sequencer configuration
//                 2.0   08-Nov-2006 TM: SPU stop/start introduced, changed wait times
//                 2.1   13-Nov-2006 TM: wait time of 3 sec after GND-BU
//
procedure PACS_Phot_Warm_Startinputsignal {
}{
    // ---------------------------------------------
    // PhFPU UM, draft 5:
    // Functional tests at 300K
    // ---------------------------------------------
    // ---------------------------------------------
    // Set data mode Bolo & HK
    //# P 09 02 00 01
    int operand = 0x9020001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Reset bias all groups
    //# P 00 00 00 00
    operand = 0x0;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Validate TM recording
    //# S 09
    delay(20);
    // Set all groups bol bias 22 (VDD-PROT-BU) ON (1)
    //# P 00 16 0001
    operand = 0x160001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 21 (VDD-PROT-CL) ON (1)
    //# P 00 15 0001
    operand = 0x150001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 23 (GND-BU) ON (1)
    //# P 00 17 0001
    operand = 0x170001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(3);
    // Set all groups bol bias 05 (VCH) to 0.00000000 Volt (0)
    //# P 00 05 0000
    operand = 0x50000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 19 (VGL-BU) to 3.00000000 Volt (2455)
    //# P 00 13 0997
    operand = 0x130997;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 18 (VDL-BU) to 4.20000000 Volt (3436)
    //# P 00 12 0D6C
    operand = 0x120d6c;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 17 (VSS-BU) to 1.00000000 Volt (819)
    //# P 00 11 0333
    operand = 0x110333;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // BU level test starts here
    // ---------------------------------------------
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    TMMarker601();
    // ---------------------------------------------
    // Set seq mode Sref only
    // ---------------------------------------------
    //# P 09 01 00 01
    operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // ---------------------------------------------
    // Set all groups bol bias 15 (VGG) to 0.00000000 Volt (1)
    //# P 00 0F 0001
    operand = 0xf0001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set gain low
    //# P 08 00 00 01
    operand = 0x8000001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 20 (VH_BLIND) to 1.20000000 Volt (982)
    //# P 00 14 03D6
    operand = 0x1403d6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 16 (VDD) to 1.20000000 Volt (981)
    //# P 00 10 03D5
    operand = 0x1003d5;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // output should be around 30000 ADU
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 16 (VDD) to 1.22000000 Volt (998)
    //# P 00 10 03E6
    operand = 0x1003e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 16 (VDD) to 1.24000000 Volt (1014)
    //# P 00 10 03F6
    operand = 0x1003f6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 16 (VDD) to 1.26000000 Volt (1030)
    //# P 00 10 0406
    operand = 0x100406;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 20 (VH_BLIND) to 1.22000000 Volt (998)
    //# P 00 14 03E6
    operand = 0x1403e6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 20 (VH_BLIND) to 1.24000000 Volt (1014)
    //# P 00 14 03F6
    operand = 0x1403f6;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 20 (VH_BLIND) to 1.26000000 Volt (1031)
    //# P 00 14 0407
    operand = 0x140407;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // ---------------------------------------------
    // BU level test is now complete
    // ---------------------------------------------
    // Block the CL MOS to make it work with the BU in "PEL commute" mode
    // ---------------------------------------------
    // Set all groups bol bias 15 (VGG) to 1.90000000 Volt (1556)
    //# P 00 0F 0614
    operand = 0xf0614;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 16 (VDD) to 2.60000000 Volt (2126)
    //# P 00 10 084E
    operand = 0x10084e;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 08 (VGL) to 3.00000000 Volt (3448)
    //# P 00 08 0D78
    operand = 0x80d78;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 06 (VDL) to 3.00000000 Volt (3447)
    //# P 00 06 0D77
    operand = 0x60d77;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 07 (VSS) to 0.70000000 Volt (804)
    //# P 00 07 0324
    operand = 0x70324;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // VRL test starts here
    TMMarker601();
    // ---------------------------------------------
    // Set all groups bol bias 11 (VDECX-H) to 0.00000000 Volt (0)
    //# P 00 0B 0000
    operand = 0xb0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 12 (VDECX-L) to 0.00000000 Volt (0)
    //# P 00 0C 0000
    operand = 0xc0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 09 (CKRLH) to 1.50000000 Volt (1724)
    //# P 00 09 06BC
    operand = 0x906bc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 10 (CKRLL) to 1.50000000 Volt (1724)
    //# P 00 0A 06BC
    operand = 0xa06bc;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 14 (VSMS-L) to 3.00000000 Volt (3447)
    //# P 00 0E 0D77
    operand = 0xe0d77;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 13 (VSMS-H) to 0.00000000 Volt (0)
    //# P 00 0D 0000
    operand = 0xd0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 15 (VGG) to 1.80000000 Volt (1474)
    //# P 00 0F 05C2
    operand = 0xf05c2;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // CL current (I_VSS_BU) should be between 0.5 microA et 2 microA
    TMMarker601();
    // ---------------------------------------------
    // Set all groups bol bias 20 (VH_BLIND) to 1.80000000 Volt (1473)
    //# P 00 14 05C1
    operand = 0x1405c1;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 00 03 0159
    operand = 0x30159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 03 (VRL) to 0.40000000 Volt (459)
    //# P 00 03 01CB
    operand = 0x301cb;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 03 (VRL) to 0.50000000 Volt (574)
    //# P 00 03 023E
    operand = 0x3023e;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 03 (VRL) to 0.40000000 Volt (459)
    //# P 00 03 01CB
    operand = 0x301cb;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 00 03 0159
    operand = 0x30159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // ---------------------------------------------
    // VRL test for all groups is complete
    // ---------------------------------------------
    // 
    // ---------------------------------------------
    // VRL test group by group
    // ---------------------------------------------
    // group 1
    TMMarker602();
    // ---------------------------------------------
    // Set group 1 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 01 03 0159
    operand = 0x1030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 1 bol bias 03 (VRL) to 0.50000000 Volt (574)
    //# P 01 03 023E
    operand = 0x103023e;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 1 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 01 03 0159
    operand = 0x1030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // group 2
    TMMarker602();
    // ---------------------------------------------
    // Set group 2 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 02 03 0159
    operand = 0x2030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 2 bol bias 03 (VRL) to 0.50000000 Volt (574)
    //# P 02 03 023E
    operand = 0x203023e;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 2 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 02 03 0159
    operand = 0x2030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // group 3
    TMMarker602();
    // ---------------------------------------------
    // Set group 3 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 03 03 0159
    operand = 0x3030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 3 bol bias 03 (VRL) to 0.50000000 Volt (574)
    //# P 03 03 023E
    operand = 0x303023e;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 3 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 03 03 0159
    operand = 0x3030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // group 4
    TMMarker602();
    // ---------------------------------------------
    // Set group 4 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 04 03 0159
    operand = 0x4030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 4 bol bias 03 (VRL) to 0.50000000 Volt (574)
    //# P 04 03 023E
    operand = 0x403023e;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 4 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 04 03 0159
    operand = 0x4030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // group 5
    TMMarker602();
    // ---------------------------------------------
    // Set group 5 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 05 03 0159
    operand = 0x5030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 5 bol bias 03 (VRL) to 0.50000000 Volt (574)
    //# P 05 03 023E
    operand = 0x503023e;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 5 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 05 03 0159
    operand = 0x5030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // group 6
    TMMarker602();
    // ---------------------------------------------
    // Set group 6 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 06 03 0159
    operand = 0x6030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 6 bol bias 03 (VRL) to 0.50000000 Volt (574)
    //# P 06 03 023E
    operand = 0x603023e;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // Set group 6 bol bias 03 (VRL) to 0.30000000 Volt (345)
    //# P 06 03 0159
    operand = 0x6030159;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(10);
    // ---------------------------------------------
    // VRL test group by group is complete
    TMMarker600();
    // ---------------------------------------------
    // ---------------------------------------------
    //
    // Set all groups bol bias 09 (CKRLH) to 0.00000000 Volt (0)
    //# P 00 09 0000
    operand = 0x90000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 10 (CKRLL) to 0.00000000 Volt (0)
    //# P 00 0A 0000
    operand = 0xa0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 11 (VDECX-H) to 2.00000000 Volt (2298)
    //# P 00 0B 08FA
    operand = 0xb08fa;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 12 (VDECX-L) to 2.00000000 Volt (2298)
    //# P 00 0C 08FA
    operand = 0xc08fa;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 04 (VINJ) to 3.00000000 Volt (3447)
    //# P 00 04 0D77
    operand = 0x40d77;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 20 (VH_BLIND) to 1.15000000 Volt (941)
    //# P 00 14 03AD
    operand = 0x1403ad;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set gain high
    //# P 08 00 00 00
    operand = 0x8000000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    TMMarker601();
    // Set all groups bol bias 01 (VH) to 0.10000000 Volt (115)
    //# P 00 01 0073
    operand = 0x10073;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 02 (VL) to -0.10000000 Volt (277)
    //# P 00 02 0115
    operand = 0x20115;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 01 (VH) to 0.00000000 Volt (0)
    //# P 00 01 0000
    operand = 0x10000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //# S 01 001388
    // Set all groups bol bias 02 (VL) to 0.00000000 Volt (0)
    //# P 00 02 0000
    operand = 0x20000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Wait 10000 ms
    delay(10);
    //---------------------------------
    // Extra wait 30000 ms for a noise check
    TMMarker603();
    delay(30);
    TMMarker601();
    //---------------------------------
    //# S 01 001388
    // Set all groups bol bias 12 (VDECX-L) to 0.00000000 Volt (0)
    //# P 00 0C 0000
    operand = 0xc0000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Set all groups bol bias 09 (CKRLH) to 2.00000000 Volt (2298)
    //# P 00 09 08FA
    operand = 0x908fa;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    //---------------------------------
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    //---------------------------------
    // Set seq mode Sb only
    //# P 09 01 00 02
    operand = 0x9010002;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    //---------------------------------
    // Wait 30000 ms
    delay(30);
    //# S 01 001388
    //---------------------------------
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    //---------------------------------
    // Set seq mode Sref only
    //# P 09 01 00 01
    operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // ---------------------------------------------
    // Wait 30000 ms
    delay(30);
    //# S 01 001388
    //---------------------------------
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    //---------------------------------
    // Set seq mode Sb-Sref
    //# P 09 01 00 00
    operand = 0x9010000;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // ---------------------------------------------
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // ---------------------------------------------
    // Wait 30000 ms
    delay(30);
    //# S 01 001388
    // Stop telemetry recording TM
    //# S 08
    // ---------------------------------------------
    //-----------------
    // End of Procedure
    //-----------------
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose : Reduced NEP measurements for the new sequencer test
//           Search for the optimum bias with 11 values
//           using the high gain
//
// Author : Koryo Okumura
//
//
// Argument :
//    int response_measure_time = 60; // response measure time in seconds
//    int noise_measure_time = 120; // noise measure time in seconds
//    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Instrument is in safe mode
//
// Description : OBS script of PHOT_redArray_direct_IST
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_oldSeq_IST(1)
//
// Version 	: 1.0
// History	: 0.1 Fri Oct 05 12:17:10 CEST 2007
// 		: 1.0 translated into PV script VDP
//
obs PacsEng_Phot_redArray_direct_IST {
    /* Needed variables to call PacsEng_Phot_redArray_direct_IST                        */
    int response_measure_time = 60; // response measure time in seconds
    int noise_measure_time = 120; // noise measure time in seconds
    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_redArray_direct_IST                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PHOT_redArray_direct_IST(response_measure_time,noise_measure_time,biasFile)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_redArray_direct_IST(response_measure_time,noise_measure_time,biasFile);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       : Perform Setup Spectroscopy
//
// CUS author    : PR
// Script file   : SPEC_setup_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform PACS setup for spectroscopy
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// Version       : 1.0
// 
// History       : 1.0 16-Jun-2009 PR
//
obs PacsEng_Spec_setup_Flex {
    /* Needed variables to call PacsEng_Spec_setup_Flex                        */
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double temp_CS1 = 48.0;
    double temp_CS2 = 58.0;
    double blu_heater_curr = 0.78; // Heater current [mA]
    int gratpos = 737500; // Starting Grating Position
    string fwpos = "POS B" in ["POS A","POS B"]; // Predefined positions [POS A, POS B]
    int choppos = 21200; // Chopper position : CS1 -21350, CS2 21200
    double bias_d_red = 0.035; // BIAS_D for red spectro  (0-1V)
    double bias_d_blu = 0.08; // BIAS_D for blue spectro (0-1V)
    int capa_red = 4; // Capacitor red  (0=0.1pF,4=0.4pF,8=0.2pf,12=1pF)
    int capa_blu = 0; // Capacitor blue (0=0.1pF,4=0.4pF,8=0.2pf,12=1pF)
    /* End of needed variables for PacsEng_Spec_setup_Flex                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(SPEC_setup_Flex(fltPOS,temp_CS1,temp_CS2,blu_heater_curr,gratpos,fwpos,choppos,bias_d_red,bias_d_blu,capa_red,capa_blu)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            SPEC_setup_Flex(fltPOS,temp_CS1,temp_CS2,blu_heater_curr,gratpos,fwpos,choppos,bias_d_red,bias_d_blu,capa_red,capa_blu);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : Perform Setup Photometry according to TM's input:
//                 Scripts:
//      a) tm_phot_dpu_dmc_setup.tcl  <phot_hk 1, syn_source 4>
//      b) tm_phot_mec_setup.tcl      <phot_filter_wheel_id 1,
//                                     chop_def_pos 0, temp_bb1 800000
//                                     temp_bb2 920000 >
//      c) tm_phot_sequencer_setup.tcl
//      d) tm_phot_polar_bestM7_setup.tcl
//         (Setting of optimal polarisations in the cold 0.3K)
//      e) tm_phot_change_datamode.tcl  <"Bolo & HK">
//      f) tm_phot_change_seq_mode.tcl  <"Sbolo-Sref">
//      g) PACS_Phot_Gain_high.tcl
//         (gain setting  <"high">)
//      h) tm_phot_spu_setup.tcl   <comp_mode_blue 0, comp_mode_red 0
//                                  spus_nraw 3, spul_nraw 3>
//
//
// CUS author    : DAC
// Script file   : PHOT_setup.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : SCR PACS-1866
// 
// Version       : 3.0
// History:
// 0.1 DAC 22-apr-2005
// 0.2 DAC 25-apr-2005 New default: Do not start SPU
// 1.0 TM  12-apr-2006, update for FM with new settings
// 1.1 TM  08-aug-2006, new procedure to read bias tables in [V]
// 1.2 TM  10-oct-2006, autonomy function added
// 2.0 DAC 17-oct-2006 Use BIAS tables in volts, eliminate useless
//                     timing calculation, call with BIAS table name and
//                     initial filter position, initial CS temperatures
// 2.1 TM 08-Nov-2006 add the switch on of the groups
// 2.2 TM 08-Nov-2006 autonomy function 17 added
// 2.3 TM 08-Nov-2006 autonomy functions modified again (moved to PHOT_switchon_groups)
// 2.4 TM 10-Nov-2006 default bias table changed, low gain
// 2.5 13-nov-2006 Use RAW bias tables
// 2.6 15-nov-2006 Using volts again
// 2.7  8-dec-2006 Add temperature autonomy function
// 2.8  5-mar-2007 update for chopper, CSs
// 2.9  4-apr-2007 TM: number of raw channels set to zero
// 3.0  9-apr-2007 TM & KO: update of AFs
// 3.1  9-apr-2007 TM & KO: AF 15 taken out again
// 3.2 21-aug-2007 SRC-3507 Indicate end of BB
//                 Sync bus at end of script
// 3.3 06-oct-2008 TM & VDP: PHOT_change_seq_mode set to Sref_only 
// 3.4 12-nov-2008 KO: gotoDirect option added
// 1.0 22-jul-2009 KO: Copied from PHOT_setup and Group6 stays off
//                     (for red detector tests in PV)
//
int[] block PHOT_setup12346 PACS 210 {
    string calUfile = "BOLObias_preILT_standard_low"; //BIAS table name
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double set_CS1 = 48.0; // CS1 settings (ohms)
    double set_CS2 = 58.0; // CS2 settings (ohms)
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
}{
    // Register BBID with environment
    WriteBBID($BBID);
    // Define variables to communicate various durations to HSPOT.
    int time_start = time();
    PHOT_dpu_dmc_setup("BOTH Array",4);
    // Place filter wheel
    PHOT_dmc_setup(fltPOS,0,set_CS1,set_CS2);
    // switch on groups and enable AF 17
    PHOT_switchon_12346();
    // Set polarisations
    PHOT_set_bias_volt(calUfile,1);
    PHOT_set_bias_volt(calUfile,2);
    PHOT_set_bias_volt(calUfile,3);
    PHOT_set_bias_volt(calUfile,4);
    //PHOT_set_bias_volt(calUfile,5);
    PHOT_set_bias_volt(calUfile,6);
    // Set sequencer
    PHOT_seq_setup();
    // Set data mode
    PHOT_change_data_mode("Bolo_HK");
    //  PHOT_change_seq_mode("Sb_Sref"); New setup post-SOVT1
    // Now we set the direct mode post-SOVT1
    int operand = 0;
    if(gotoDirect) {
        //*********************************************************
        // Sequence mode : blocking on VDEC_X for the direct mode
        //*********************************************************
        //
        // Set groups 1234 bol bias 09 (CKRLH) to 0.0 volt (0)
        //Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
        Pacs_BOLC_SET_CKRLH_G1_RAW(0);
        Pacs_BOLC_SET_CKRLH_G2_RAW(0);
        Pacs_BOLC_SET_CKRLH_G3_RAW(0);
        Pacs_BOLC_SET_CKRLH_G4_RAW(0);
        Pacs_BOLC_SET_CKRLH_G6_RAW(0);
        // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
        //Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
        Pacs_BOLC_SET_VDECX_L_G1(2.0);
        Pacs_BOLC_SET_VDECX_L_G2(2.0);
        Pacs_BOLC_SET_VDECX_L_G3(2.0);
        Pacs_BOLC_SET_VDECX_L_G4(2.0);
        Pacs_BOLC_SET_VDECX_L_G6(2.0);
        // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
        //# P 09 01 00 01
        operand = 0x9010001;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
    } else {
        // Set seq mode Sb_Sref (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sb_Sref");
        //# P 09 01 00 00
        operand = 0x9010000;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
    }
    // Set gain LOW
    PHOT_set_gain("LOW");
    // Set SPU but do not start it yet
    PHOT_spu_setup(0,0,0,0,false);
    // Time spent
    int duree_TCs = time() - time_start;
    int duree_num = duree_TCs;
    // Return the array of times
    int[] time_array = [duree_num,0,0,0,0];
    //
    // enable AF 12 (to check for the protection biases)
    //Pacs_DPU_SET_FUNCT("EVENT_BOL_BIAS","ENABLE");
    // enable AF 14 to check for TEMP_EV < 0.3 K
    Pacs_DPU_SET_FUNCT("EVENT_BOL_T_FPU","ENABLE");
    // enable AF 15 (to check for the VSS currents of groups and BUs)
    // Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","ENABLE");
    // Mark end of BB
    WriteEndBB();
    // Sync bus
    sync();

    return time_array;
}

// Missionphase  : 
//
// Purpose       : Perform Setup Photometry according to TM's input:
//                 Scripts:
//      a) tm_phot_dpu_dmc_setup.tcl  <phot_hk 1, syn_source 4>
//      b) tm_phot_mec_setup.tcl      <phot_filter_wheel_id 1,
//                                     chop_def_pos 0, temp_bb1 800000
//                                     temp_bb2 920000 >
//      c) tm_phot_sequencer_setup.tcl
//      d) tm_phot_polar_bestM7_setup.tcl
//         (Setting of optimal polarisations in the cold 0.3K)
//      e) tm_phot_change_datamode.tcl  <"Bolo & HK">
//      f) tm_phot_change_seq_mode.tcl  <"Sbolo-Sref">
//      g) PACS_Phot_Gain_high.tcl
//         (gain setting  <"high">)
//      h) tm_phot_spu_setup.tcl   <comp_mode_blue 0, comp_mode_red 0
//                                  spus_nraw 3, spul_nraw 3>
//
//
// CUS author    : DAC
// Script file   : PHOT_setup.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : SCR PACS-1866
// 
// Version       : 3.0
// History:
// 0.1 DAC 22-apr-2005
// 0.2 DAC 25-apr-2005 New default: Do not start SPU
// 1.0 TM  12-apr-2006, update for FM with new settings
// 1.1 TM  08-aug-2006, new procedure to read bias tables in [V]
// 1.2 TM  10-oct-2006, autonomy function added
// 2.0 DAC 17-oct-2006 Use BIAS tables in volts, eliminate useless
//                     timing calculation, call with BIAS table name and
//                     initial filter position, initial CS temperatures
// 2.1 TM 08-Nov-2006 add the switch on of the groups
// 2.2 TM 08-Nov-2006 autonomy function 17 added
// 2.3 TM 08-Nov-2006 autonomy functions modified again (moved to PHOT_switchon_groups)
// 2.4 TM 10-Nov-2006 default bias table changed, low gain
// 2.5 13-nov-2006 Use RAW bias tables
// 2.6 15-nov-2006 Using volts again
// 2.7  8-dec-2006 Add temperature autonomy function
// 2.8  5-mar-2007 update for chopper, CSs
// 2.9  4-apr-2007 TM: number of raw channels set to zero
// 3.0  9-apr-2007 TM & KO: update of AFs
// 3.1  9-apr-2007 TM & KO: AF 15 taken out again
// 3.2 21-aug-2007 SRC-3507 Indicate end of BB
//                 Sync bus at end of script
// 3.3 06-oct-2008 TM & VDP: PHOT_change_seq_mode set to Sref_only 
// 3.4 12-nov-2008 KO: gotoDirect option added
// 1.0 22-jul-2009 KO: Copied from PHOT_setup and Group6 stays off
//                     (for red detector tests in PV)
//
int[] block PHOT_setup12345 PACS 202 {
    string calUfile = "BOLObias_preILT_standard_low"; //BIAS table name
    string fltPOS = "POS A" in ["POS A","POS B"]; // Filter wheel position
    double set_CS1 = 48.0; // CS1 settings (ohms)
    double set_CS2 = 58.0; // CS2 settings (ohms)
    bool gotoDirect = true in [true,false]; // DDCS setting to Direct setting
}{
    // Register BBID with environment
    WriteBBID($BBID);
    // Define variables to communicate various durations to HSPOT.
    int time_start = time();
    PHOT_dpu_dmc_setup("BOTH Array",4);
    // Place filter wheel
    PHOT_dmc_setup(fltPOS,0,set_CS1,set_CS2);
    // switch on groups and enable AF 17
    PHOT_switchon_12345();
    // Set polarisations
    PHOT_set_bias_volt(calUfile,1);
    PHOT_set_bias_volt(calUfile,2);
    PHOT_set_bias_volt(calUfile,3);
    PHOT_set_bias_volt(calUfile,4);
    PHOT_set_bias_volt(calUfile,5);
    //PHOT_set_bias_volt(calUfile,6);
    // Set sequencer
    PHOT_seq_setup();
    // Set data mode
    PHOT_change_data_mode("Bolo_HK");
    //  PHOT_change_seq_mode("Sb_Sref"); New setup post-SOVT1
    // Now we set the direct mode post-SOVT1
    int operand = 0;
    if(gotoDirect) {
        //*********************************************************
        // Sequence mode : blocking on VDEC_X for the direct mode
        //*********************************************************
        //
        // Set groups 1234 bol bias 09 (CKRLH) to 0.0 volt (0)
        //Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
        Pacs_BOLC_SET_CKRLH_G1_RAW(0);
        Pacs_BOLC_SET_CKRLH_G2_RAW(0);
        Pacs_BOLC_SET_CKRLH_G3_RAW(0);
        Pacs_BOLC_SET_CKRLH_G4_RAW(0);
        Pacs_BOLC_SET_CKRLH_G5_RAW(0);
        // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
        //Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
        Pacs_BOLC_SET_VDECX_L_G1(2.0);
        Pacs_BOLC_SET_VDECX_L_G2(2.0);
        Pacs_BOLC_SET_VDECX_L_G3(2.0);
        Pacs_BOLC_SET_VDECX_L_G4(2.0);
        Pacs_BOLC_SET_VDECX_L_G5(2.0);
        // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
        //# P 09 01 00 01
        operand = 0x9010001;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
    } else {
        // Set seq mode Sb_Sref (hexadecimal value to avoid the commanding confusion)
        //Pacs_BOLC_SET_SEQ_MODE("Sb_Sref");
        //# P 09 01 00 00
        operand = 0x9010000;
        Pacs_DMC_SEND_COMMAND_BOLC(operand);
        delay(1);
    }
    // Set gain LOW
    PHOT_set_gain("LOW");
    // Set SPU but do not start it yet
    PHOT_spu_setup(0,0,0,0,false);
    // Time spent
    int duree_TCs = time() - time_start;
    int duree_num = duree_TCs;
    // Return the array of times
    int[] time_array = [duree_num,0,0,0,0];
    //
    // enable AF 12 (to check for the protection biases)
    //Pacs_DPU_SET_FUNCT("EVENT_BOL_BIAS","ENABLE");
    // enable AF 14 to check for TEMP_EV < 0.3 K
    Pacs_DPU_SET_FUNCT("EVENT_BOL_T_FPU","ENABLE");
    // enable AF 15 (to check for the VSS currents of groups and BUs)
    // Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","ENABLE");
    // Mark end of BB
    WriteEndBB();
    // Sync bus
    sync();

    return time_array;
}

// $Id: PacsCal_Phot_PSF_FieldDistort.txt,v 1.2 2008/11/12 11:40:20 vanessad Exp $
// Missionphase  : PACS PV Phase
//
// Purpose       : Template for a PHOT AOT with chopped nodding in raster
//                 OBCP used: OBCP_chopped_photometry (OBCP#3)
//                 Calls nodding_raster_pointing (3.6 in Point document)
// Author        : DAC
//
// Arguments     : See input list below
//
// Prerequisite  : PACS is PHOT ready (PHOT_orbit_prologue), SPU is stopped 
//                 and ready to be (re)configured.
//
// Description   : Uses OBCP3
// Comments      :
//
// Version       : 0.1
// History       : 0.1 18-feb-2008 DAC
//                 0.2 19-feb-2008 - Use PacsPhotSlewCal
//                                 - Read more input parameters
//		   1.0 21-oct-2008 - VDP - PSF for DL
//		       		   modify pointingRequests:
//                 		   Flexible = raster_nodding pointing
//				   tripleChop = nodding only
//		   1.1 22-oct-2008 included scanmap @fixed chopped position
//		   1.2 03-nov-2008 added staring raster
//		   1.3 23-apr-2009 VD SPR 6482
//		   2.0 30-jul-2009 VD SCR PACS-1292 PHS-1130
//		   2.1 06-aug-2009 VD : error delayed timing in POINT
//		       		      state/NOD state. 
//		   2.2 10-aug-2009 VD PACS-1882
//
obs PacsCal_Phot_PSF_FieldDistort {
    /* Needed variables to call PHOT_NodRaster                               */
    string fltPOS = "POS A" in ["POS A","POS B"]; // Fltw position 
    string psfMeth = "flexible" in ["flexible","tripleChop","fieldDist_scan","fieldDist_rast"]; // Field distortion measure method
    /*    string filter = "blue1" in ["blue1","blue2"]; */
    string gain = "LOW" in ["LOW","HIGH"]; // BOLC gain
    int nrepeat = 1;
    /*                                 */
    /* OBCP related parameters         */
    /*                                 */
    /* PHOT compression modes          */
    /* 0x00 BOL0: Default              */
    /* 0x01 BOL1: Double Compression   */
    /* 0x02 BOL2: Half Compression     */
    /* 0x04 BOL4: Lossless Compression */
    /* 0x07 BOL7: Transparent          */
    /* 0x09 BOL9: Buffer Transmission  */
    int comp_mode_blu = 0x0; // blue Compression mode
    int comp_mode_red = 0x0; // red Compression mode
    int nraw_blu = 3; // Number of blue raw pixels
    int nraw_red = 3; // Number of red raw pixels
    int nb_SRC_REF = 2; // Nb of SRC-REF1-SRC-REF2 cycles
    int nb_rd_plateau = 31; // Nb rdouts/plateau (4*nn - 1)
    int nb_cycles_obs_cal = 1; // Outermost CS-SRC DMC loop
    int nb_CS1_CS2 = 0; // Loop on CSs
    /* Pointing parameters             */
    /* The ofssets are passed directly to the PointReq. Unless changed the */
    /* telecope boresight will fall in between SRC and REF                 */
    double ra = 0.0; // RA (returned by xHPOT pop-up window)
    double dec = 0.0; // DEC (ditto)
    double yoffset = 0.0; // yoffset [arcsec] used as is in PntReq 
    double zoffset = 0.0; // zoffset [arcsec] used as is in PntReq
    int naifid = 0; // (Source type: > 0 for Solar System source (N/A for tripleChop method) 
    /* Raster parameters               */
    int m = 2 in [2,100]; // Number of raster points (flexible)      
    int n = 1 in [1,100]; // Number of raster lines (flexible)
    double d1 = 2.0 in [2.0,480.0]; // Raster point step [arcsec] (flexible)       
    double d2 = 2.0 in [2.0,480.0]; // Raster line separation [arcsec] (flexible)
    bool fixed = false; // Raster in S/C (false) or SKY coordinates 
    double nodthrow = 30.0 in [2.0,960.0]; // Nod throw [arcsec]  
    double chopthrow = 30.0; // Chop throw [arcsec]
    int chop_pos = 664; // chopper fixed position (ONLY fieldDist_xxx method)
    /* scan line */
    string mapScanSpeed = "high" in ["high","medium","low"]; // Scan rate
    double mapScanLegLength = 30.0 in [1.0,1200.0]; //Scan leg [arcmin]
    int mapScanNumLegs = 2 in [1,1500]; //Number of scan legs
    string mapScanAngleRef = "inst" in ["sky","inst","i+c","s+c"];
    double mapScanConstrFrom = 0.0 in [0.0,360.0];
    double mapScanConstrTo = 0.0 in [0.0,360.0];
    double mapScanAngle = 0.0 in [0.0,360.0];
    double mapScanCrossScan = 2.0 in [2.0,480.0]; // Scan separation [arcsec]
    bool mapScanHomCoverage = true;
    bool mapScanSquare = false;
    /* or staring raster */
    double dwellTime = 10.0; // dwell time for staring raster (sec)
    /* end */
    double patt = 0.0; // Raster pattern orientation
    double pattnod = 270.0; // Nodding orientation (def: along y-axis)
    int nnod = 1; // Number of Aa aA ... nods
    bool startAtB = false; // enabled: start at off-nod B position
    /* NOTE: raster size shall not be larger than 14880x14880 arcsec */
    /* Overall "verbosity"             */
    bool verbose = true;
}{
    string filter = "blue1";
    if(fltPOS == "POS B") {
        filter = "blue2";
    }
    int mapRasterNumCycles = nrepeat;
    // Useful variables
    // Bolo size: Short Size, i.e. 32 pixels and Long Size [arcsec]
    double boloSSize = 1.75 * 60.0;
    double boloLSize = 3.5 * 60.0;
    double boloArea = boloSSize * boloLSize;
    // Compute duration of tasks to be performed during slew to source
    // Set OBSID
    int timeOBSID = duration(WriteOBSID($OBSID));
    int tWriteEnd = duration(PacsBbWriteEndBB());
    int tWrite = duration(PacsBbWriteIdBB());
    // Condition BOLC to gain setting. This may change the data rate but SPU
    // is still stopped and a proper comp_mode may be defined
    // Can I set the gain directly (Thomas says "yes")
    // setting gain defaults
    if(gain == "LOW") {
        int int_gain = 1;
    } else {
        if(gain == "HIGH") {
            int_gain = 0;
        }
    }
    //    int timeGAIN = duration(PHOT_set_gain(gain));
    // Use PacsPhotSlewCal from AOT code. Define three input tuples
    // SPU-like parameters
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,comp_mode_blu,0,nraw_blu,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,comp_mode_red,0,nraw_red,0,0,0,0,0}];
    // OBCP-like values (none is used since SlewCal takes them from OBCP$params)
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // including a new section for Low Gain implementation SCR4196
    bool isBrightPacs = false;
    string srcID = "pointSRC";
    // Obtain default values for "Prime" mode
    paramsPHOT = PacsPhotDefaults(srcID,"Prime",isBrightPacs,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    confPHOTblu[0]{0} = int_gain;
    confPHOTblu[0]{3} = comp_mode_blu;
    confPHOTblu[0]{6} = nraw_blu;
    confPHOTred[0] = paramsPHOT{1};
    confPHOTred[0]{0} = int_gain;
    confPHOTred[0]{3} = comp_mode_red;
    confPHOTred[0]{6} = nraw_red;
    confOBCP[0] = paramsPHOT{2};
    // Perform the calibration block now
    bool doProlog = true;
    int timeCAL = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,filter));
    //
    // Before dealing with the OBCP, obtain the chopper position for CS1 & CS2
    // (likely not to be used here, but just for completeness)
    int chop_pos_CS1 = ilookup("CHOPPERCSparams","PHOT","pos_CS1");
    int chop_pos_CS2 = ilookup("CHOPPERCSparams","PHOT","pos_CS2");
    if(psfMeth == "flexible") {
        // The chopper moves from -chopthrow/2 to +chopthrow/2 [arcsec]
        double auxSRC = -chopthrow / 2.0;
        double auxREF = +chopthrow / 2.0;
        int chop_pos_SRC = PacsReadChopSky("PHOT_CHOP_sky",auxSRC);
        int chop_pos_REF = PacsReadChopSky("PHOT_CHOP_sky",auxREF);
    } else {
        if(psfMeth == "tripleChop") {
            auxSRC = 0.0;
            double auxREF1 = -chopthrow / 2.0;
            double auxREF2 = +chopthrow / 2.0;
            chop_pos_SRC = PacsReadChopSky("PHOT_CHOP_sky",auxSRC);
            int chop_pos_REF1 = PacsReadChopSky("PHOT_CHOP_sky",auxREF1);
            int chop_pos_REF2 = PacsReadChopSky("PHOT_CHOP_sky",auxREF2);
        }
    }
    // Report settings if verbose
    if(verbose) {
        if(psfMeth == "flexible") {
            debug_print("+++CHOPPER, SRC: " + auxSRC + " [arcsec] -> " + chop_pos_SRC + " [ENG]");
            debug_print("+++CHOPPER, REF: " + auxREF + " [arcsec] -> " + chop_pos_REF + " [ENG]");
        } else {
            if(psfMeth == "tripleChop") {
                debug_print("+++CHOPPER, SRC: " + auxSRC + " [arcsec] -> " + chop_pos_SRC + " [ENG]");
                debug_print("+++CHOPPER, REF1: " + auxREF1 + " [arcsec] -> " + chop_pos_REF1 + " [ENG]");
                debug_print("+++CHOPPER, REF2: " + auxREF2 + " [arcsec] -> " + chop_pos_REF2 + " [ENG]");
            }
        }
    }
    // Default position for chopper
    if(psfMeth == "fieldDist_scan" || psfMeth == "fieldDist_rast") {
        int chop_def = chop_pos;
        int tChop_set = imax(1,duration(PHOT_dmc_setup(fltPOS,chop_def,48.0,58.0)));
    } else {
        chop_def = ilookup("SPEC_MEC_Defaults","Photometry","chopper");
        tChop_set = 0;
    }
    int tp = 0;
    if(psfMeth == "tripleChop") {
        // Duration of OBCP to be performed ON and NOD
        tp = duration(OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def));
    } else {
        if(psfMeth == "flexible") {
            tp = duration(OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def));
        }
    }
    if(psfMeth == "fieldDist_scan") {
        //    Estimate how long OBCP7 has to run to cover a scan leg
        //    Scan speed (CAL-U FILE in new version??). Default is "low": 10 arcsec/sec
        double rate = 10.0;
        if(mapScanSpeed == "medium") {
            rate = 20.0;
        }
        if(mapScanSpeed == "high") {
            rate = 60.0;
        }
        double timeLEG = mapScanLegLength * 60.0 / rate;
        tp = iceil(timeLEG);
    } else {
        if(psfMeth == "fieldDist_rast") {
            timeLEG = dwellTime;
            tp = iceil(timeLEG);
        }
    }
    // tp cannot be shorted than 10 sec
    if(tp < 10) {
        error("The OBCP cannot be shorter than 10 sec; adjust your dwellTime parameter");
    }
    int timeEpilogue = duration(WriteEndID());
    //
    // Several arguments needed for "nodding_raster_pointing"
    //
    //Execute the pointing request
    bool execute = true;
    //Minimum slew time
    //    int tslewmin = timeOBSID + timeGAIN + timeCAL + tChop_set;
    if(psfMeth == "fieldDist_scan" || psfMeth == "fieldDist_rast") {
        int tslewmin = timeOBSID + timeCAL + tChop_set;
    } else {
        tslewmin = timeOBSID + timeCAL;
    }
    if(verbose) {
        debug_print("+++SlewMinTime is " + tslewmin + " [sec]");
    }
    // Pointing requests
    //Initial hold
    int tih = 0;
    //Final hold
    int tfh = timeEpilogue;
    //Use PHOT virtual aperture
    string ib = "P01_0";
    //Issue PointReq
    // Still undefined pointing variables
    // Number of points/scan lines before going to OFF
    int k = 0;
    // Number of nods/raster/scan before performing a hold
    int nhold = 0;
    // Duration of a hold operation
    int thold = 0;
    // Time spent at OFF
    int top = 0;
    // Coordinates of OFF position
    double raoff = 0.0;
    double decoff = 0.0;
    // Repetitions of pattern
    // The minimum duration of return slew between repetitions
    int trepeatmin = 0;
    // Minimum duration of a "load" operation
    int tloadmin = 0;
    // Number of slews before starting a "load" slew
    int nload = 0;
    // Issue de PointReq  
    int tpa = tp;
    int tpb = tp;
    debug_print("tp = tpa = tpb: " + tp);
    if(psfMeth == "tripleChop") {
        int[] ts = nodding_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nnod,nodthrow,tpa,tpb,tloadmin,nload,thold,nhold,startAtB);
        debug_print("truple zut");
    }
    if(psfMeth == "flexible") {
        ts = nodding_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodthrow,nnod,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
        debug_print("ZUT!!");
    }
    if(psfMeth == "fieldDist_scan") {
        //   line_scan_pointing. Keep (most of) JBr's variable names
        //        tslewmin = timeOBSID + timeCAL + timeGAIN + tChop_set;
        tslewmin = timeOBSID + timeCAL + tChop_set;
        // Scan speed (CAL-U FILE in new version??). Default is "low": 10 arcsec/sec
        rate = 10.0;
        if(mapScanSpeed == "medium") {
            rate = 20.0;
        }
        if(mapScanSpeed == "high") {
            rate = 60.0;
        }
        //  Case of homogeneous coverage
        double pi = 3.1415926535;
        //  degrees to radians    
        double dtor = 0.0;
        double rtod = 0.0;
        double halfDiag = 0.0;
        double halfDiagAngle = 0.0;
        dtor = 2.0 * pi / 360.0;
        rtod = 1.0 / dtor;
        halfDiag = sqrt(boloSSize * boloSSize + boloLSize * boloLSize) / 2.0;
        halfDiagAngle = atan(boloSSize / boloLSize) * rtod;
        // Add further constraint from RV (SPR-2889)
        // Add SPR-2699 further logic: mapScanAngleRef overrides ScanHom and ScanSquare
        if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
            mapScanHomCoverage = false;
            mapScanSquare = false;
        }
        //  Could simplify logic after SPR-2699 (mapScanHomCoverage cannot be true
        //  unless inst or i+c have been specified)
        if(mapScanHomCoverage == true && (mapScanAngleRef == "inst" || mapScanAngleRef == "i+c")) {
            mapScanCrossScan = halfDiag * (abs(sin(dtor * (mapScanAngle + 90.0 - halfDiagAngle))) + abs(cos(dtor * (90.0 - halfDiagAngle - mapScanAngle + 90.0))));
            if(verbose) {
                debug_print("New mapScancCross: " + mapScanCrossScan);
            }
        }
        // Case of square map request
        if(mapScanSquare == true && mapScanHomCoverage == true) {
            mapScanNumLegs = iceil(60.0 * (mapScanLegLength / mapScanCrossScan));
            if(verbose) {
                debug_print("New mapScanNumLegs: " + mapScanNumLegs);
            }
        }
        ib = "P01_0";
        tih = 0;
        tfh = timeEpilogue;
        patt = mapScanAngle;
        n = mapScanNumLegs;
        d1 = 60.0 * mapScanLegLength;
        d2 = mapScanCrossScan;
        thold = timeCAL;
        if(verbose) {
            debug_print("Map reference: " + mapScanAngleRef + "=" + fixed);
        }
        ts = line_scan_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,n,d1,d2,rate,thold,nhold,nrepeat);
        //Info from API (nomenclature from Jon Br)
        int tobs = ts[0];
        int tslew = ts[1];
        int tacc = ts[2];
        int tdec = ts[3];
        int tl = ts[4];
        int tll = ts[5];
        int trep = ts[6];
        if(verbose) {
            debug_print("##### line_scan_with_hold");
        }
        if(verbose) {
            debug_print("##### rate: " + rate + " arcsec/sec");
        }
        //   Here we record how long it takes to scan a line [sec]
        int scanTime = tl;
        //   Gather the overheads
        int scanOVER = tacc + tdec;
    }
    if(psfMeth == "fieldDist_rast") {
        //        tslewmin = timeOBSID + timeCAL + timeGAIN + tChop_set;
        tslewmin = timeOBSID + timeCAL + tChop_set;
        ib = "P01_0";
        tih = 0;
        tfh = timeEpilogue;
        //thold = timeCAL;
        ts = basic_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,k,top,raoff,decoff);
    }
}{
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 1) {
            int tNOW = time();
            if(verbose) {
                debug_print("SLEW starts at " + tNOW);
            }
            //      Set OBSID, move filter, set gain, perform prologue
            WriteOBSID($OBSID);
            data_rate(120.0);
            //            PHOT_set_gain(gain);
            // ON TARGET SLEW
            if(ts[1] > tslewmin) {
                delay(ts[1] - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,filter);
            if(psfMeth == "fieldDist_scan" || psfMeth == "fieldDist_rast") {
                PHOT_dmc_setup(fltPOS,chop_def,48.0,58.0);
                debug_print("we are setting the chopper at:" + chop_pos);
            }
            tNOW = time();
            if(verbose) {
                debug_print("SLEW ends at   " + tNOW);
            }
        } else {
            if(state[0] == 3) {
                tNOW = time();
                if(verbose) {
                    debug_print("POINT starts at   " + tNOW);
                }
                //      Call the OBCP with the known parameters
                if(psfMeth == "flexible") {
                    OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
                }
                if(psfMeth == "tripleChop") {
                    OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
                }
                if(psfMeth == "fieldDist_rast") {
                    PacsBbWriteIdBB();
                    int tDelay = tp - tWriteEnd;
                    delay(tDelay);
                    PacsBbWriteEndBB();
                }
                tNOW = time();
                if(verbose) {
                    debug_print("POINT ends at     " + tNOW);
                }
            } else {
                if(state[0] == 5) {
                    tNOW = time();
                    if(verbose) {
                        debug_print("FINAL_HOLD starts at   " + tNOW);
                    }
                    //      Write EndID
                    data_rate(0.0);
                    WriteEndID();
                    tNOW = time();
                    if(verbose) {
                        debug_print("FINAL_HOLD ends at     " + tNOW);
                    }
                } else {
                    if(state[0] == 7) {
                        tNOW = time();
                        if(verbose) {
                            debug_print("NOD   starts at   " + tNOW);
                        }
                        //      Call the OBCP with the same parameters as for POINT
                        if(psfMeth == "flexible") {
                            OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF,chop_pos_REF,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
                        }
                        if(psfMeth == "tripleChop") {
                            OBCP_chopped_photometry(nb_SRC_REF,chop_pos_SRC,nb_rd_plateau,chop_pos_REF1,chop_pos_REF2,nb_cycles_obs_cal,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,comp_mode_blu,comp_mode_red,chop_def);
                        }
                        tNOW = time();
                        if(verbose) {
                            debug_print("NOD   ends at     " + tNOW);
                        }
                    } else {
                        if(state[0] == 8) {
                            tNOW = time();
                            if(verbose) {
                                debug_print("Scan   starts at   " + tNOW);
                            }
                            PacsBbWriteIdBB();
                            tDelay = ts[4] - tWriteEnd;
                            delay(tDelay);
                            PacsBbWriteEndBB();
                            tNOW = time();
                            if(verbose) {
                                debug_print("Scan   ends at     " + tNOW);
                            }
                        }
                    }
                }
            }
        }
    }
}

// Missionphase  : FM
//
// Purpose	:  Setup diagnostic housekeeping for the FM 
//                 chopper tests.
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: Set up 12 housekeeping parameter for diagnostic housekeeping 
//	  of the chopper during the chopper full functional test.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, setup spectroscopy and SPEC_Chop_fft_eqmimt_obs
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 3.0	
// 
// History 	: 1.0 21-07-06 creation by HD. Based on EQM IMT scripts.
//	  2.0 24-07-06 HD. test this script.
//        3.0 24-07-06 HD. script works.	  
block PHOT_Chopper_dhk_imt_bb PACS 478 {
}{
    // Register start of BB
    WriteBBID($BBID);
    //-------------------------------------------- 
    // Setup and start diagnostic HK for Chopper
    //-------------------------------------------- 
    int chop_diag_hk_length = 13;
    {int}[] parlist = [{209},{244},{245},{246},{247},{248},{249},{258},{407},{557},{561},{565},{0xffff}];
    int[] aux = [209,244,245,246,247,248,249,258,407,557,561,565,0xffff];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_DIAG_HK_LIST(chop_diag_hk_length,parlist,check_sum);
    int diag_hk_period = 4;
    // Synchronize diagnostic HK on blue spectrometer readouts
    Pacs_DMC_START_DIAG_HK(diag_hk_period);
    // Mark End of Block
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS PV Phase
// File          : CONF_chopper_ast_OBS.cus
//
// Version       : 0.1
//
// Missionphase  : PACS IST Chopper Day
//
// Purpose       : Configure the chopper servo loop 
//
// Author        : DAC/MN/HD
// CUSification  : DAC/MN/HD
// Arguments     : 
// string calUfile  CAL-U file
// string calUcol   Column identifier
//                 
//
// Description   : Read servo loop parameters off a CALU table; a set
//                 of parameters is arranged as a column; different
//                 columns list different sets. Must specify the CALU
//                 file name and the column identification string.
//                 Example: CONF_chopper ("CONFChopper","nom_sky")
//                              
// Comments      :      
//
// Version       : 0.4 
// History       : 0.1  7-dec-2006 Initial version
// 		 : 0.2  11-jun-2007 version for new elliptical filter (MN)
//		 : 0.3  05-jul-2007 IST Chopper Day	
//		 : 0.4  12-nov-2007 edited for SVT/PV conformance
//		 : 0.5  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_CONF_chopper_ast {
    /* Needed variables to call PacsEng_CONF_chopper_ast                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_CONF_chopper_ast                     */
}{
    // string calUfile  CAL-U file
    // string calUcol   Column identifier
    //                 file name and the column identification string.
    string fileU = "CONFChopper_ast";
    string calUcol = "nom_ast";
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(CONF_chopper_ast(fileU,calUcol)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            CONF_chopper_ast(fileU,calUcol);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// File          : PACS_Spec_CRE_1pF0bias_Setup_Warm.cus
// Missionphase  : PACS EQM Test
//
// Purpose       : Configure CRE bias, reset interval and capacitor for 
//                 testing at room temperature
//
// Author        : H. Feuchtgruber
// CUSification  : DAC
// Comments      : Intermediate version
//
// 
// Version       : 1.0
// History       : 1.0 / 16-Nov-2004 Initial version
//                 1.1    7-mar-2006 SPEC_HEAT_1_C renamed
// 1.2  6-apr-2006 DMC v6.0.1
// 1.3 16-oct-2006 As PACS_Spec_CRE_Setup_Warm but with 0.1pF and 0 v bias
//                 
procedure PACS_Spec_CRE_1pF0bias_Setup_Warm {
}{
    //                  
    // red_reset integer 64 Enter red reset interval
    // blue_reset integer 64 Enter blue reset interval
    // red_bias_d integer 287 Enter BIAS_D for red spectrometer (1V=4095)
    // red_bias_r integer 0 Enter BIAS_R for red spectrometer (1V=4095)
    // blue_bias_d integer 860 Enter BIAS_D for blue spectrometer (1V=4095)
    // blue_bias_r integer 0 Enter BIAS_R for blue spectrometer (1V=4095)
    // red_capacitor integer 8 Enter Capacitor red (0=100f,4=300f,8=1pf,12=3pF)
    // blue_capacitor integer 8 Enter Capacitor blue (0=100f,4=300f,8=1pf,12=3pF)
    // heater_blue_1c integer 4095 Enter blue HEATER_1C value (0=0mA, 4095=0.2mA)
    // heater_blue_2c integer 0 Enter blue HEATER_2C value (0=0mA, 4095=0.2mA)
    int red_reset = 64;
    int blue_reset = 64;
    int red_bias_d = 0;
    int red_bias_r = 0;
    int blue_bias_d = 0;
    int blue_bias_r = 0;
    int red_capacitor = 12;
    int blue_capacitor = 12;
    int heater_blue_1c = 0;
    int heater_blue_2c = 0;
    // PC174420 "DMC_WRT_B_SPEC_PAR" WRITE THE BLUE SPECTROMETER PARAMETERS
    //         Fixed GroupSize: 1, repetition: 8
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // cre_ctrl: 256=sync width=2, 128=T sensor on, 2=select, 1=power on
    int blue_cre_ctrl = blue_capacitor + 256 + 128 + 2 + 1;
    int[] list_int = [32,blue_reset,blue_cre_ctrl,blue_bias_r,blue_bias_d,0];
    int chksum = checksum("int",list_int);
    Pacs_DMC_WRT_B_SPEC_PAR_RAW(32,blue_reset,blue_cre_ctrl,blue_bias_r,blue_bias_d,0,chksum);
    delay(1);
    // PC173420 "DMC_WRT_R_SPEC_PAR" WRITE THE RED SPECTROMETER PARAMETERS
    //         Fixed GroupSize: 1, repetition: 8
    //         PP067420 "DMC_4_BYTES_WORDS_DATA"
    //         PP066420 "DMC_CHECKSUM"
    // cre_ctrl: 256=sync width=2, 128=T sensor on, 2=select, 1=power on
    // set red_cre_ctrl [expr $red_capacitor+256+128+2+1]
    // set spec_par_r [list {PP095420 32} \
    //         [list PP096420 $red_reset] \
    //         [list PP097420 $red_cre_ctrl] \
    //         [list PP098420 $red_bias_r] \
    //         [list PP099420 $red_bias_d] {PP100420 0}]
    // set chksum [getChkSum -d -32 $spec_par_r]
    // putlog "ChkSum for spec_par_r: $spec_par_r"
    int red_cre_ctrl = red_capacitor + 256 + 128 + 2 + 1;
    list_int = [32,red_reset,red_cre_ctrl,red_bias_r,red_bias_d,0];
    chksum = checksum("int",list_int);
    Pacs_DMC_WRT_R_SPEC_PAR_RAW(32,red_reset,red_cre_ctrl,red_bias_r,red_bias_d,0,chksum);
    delay(1);
    // PC094420 "DMC_SET_PAR_BOTH_SPEC" SEND COMPLETE PARAMETERS TABLE TO BOTH DECS
    // tcsend PC094420 
    // waittime 0.5
    Pacs_DMC_SET_PAR_BOTH_SPEC();
    delay(1);
    // PC094420 "DMC_SET_PAR_B_SPEC" SEND COMPLETE PARAMETERS TABLE TO Blue DEC
    //tcsend PC086420 
    //waittime 0.5
    Pacs_DMC_SET_PAR_B_SPEC();
    delay(1);
    // PC094420 "DMC_SET_PAR_R_SPEC" SEND COMPLETE PARAMETERS TABLE TO Red DEC
    //tcsend PC093420 
    //waittime 0.5
    Pacs_DMC_SET_PAR_R_SPEC();
    delay(1);
    //  DMC_SET_B_SPE_HEAT_1C(0)
    // eval tcsend PC087420 [list [list PP073420 $heater_blue_1c]]
    // waittime 0.5
    Pacs_DMC_SET_B_SPEC_HEAT_C_RAW(heater_blue_1c);
    delay(1);
    //-----------------
    // End of Procedure
    //-----------------
}

// Missionphase  : FM ILT
//
// Purpose	 : SFT in Open Loop Mode (cold conditions)
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : SFT cold for FM1 chopper in open-loop mode. All 3 coils are
//                 operative. The chopper is commanded between -20 mA and +20mA
//                 in steps of 4 mA.
//                 The first part consists of chopper deflections equivalent to
//                 commanded chopper coil currents between 0 and +/-20 mA,
//                 alternating between positive and negative values. Absolute
//                 position commanding is used.
//                 The second part consists of a ramp of chopper deflections
//                 between -20 and +20 mA, commanded in relative steps of 4 mA.
//                 Finally, the chopper returns to its zero position.
//                  
// Dependencies  : 
//
// Preconditions : PACS switched-on, chopper is switched off and disabled
//                 Diagnostic HK not running
//                 
// Comments	 : Adapted from PACS_SPEC_Chopper_OpenLoop_MoveAbs_OBS.cus
//
// Version	 : 1.0
// 
// History 	 : 1.0 12-10-2007 - BV: extracted procedure from observation by MN and added mois comments
//                 
procedure PACS_Chopper_SFT_Cold_OpenLoop {
}{
    mois_comment("Start of procedure - PACS short functional test chopper - cold conditions, open loop");
    mois_step("Start diagnostic HK");
    // Start diagnostic HK
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_dHK_BB("ON");
    delay(5);
    mois_step("Set default spectroscopy timing parameters");
    // Set default spectroscopy timing parameters
    SPEC_Chopper_SynchBlue();
    mois_step("Set Chopper Controller Parameters: CONFChopper -> SFTcold");
    // Set Chopper Controller Parameters: CONFChopper -> SFTcold
    CONF_chopper("CONFChopper","SFTcold");
    delay(2);
    mois_step("Switch on chopper");
    // Switch on chopper
    PACS_Chopper_SWON_SWOF_only("ON");
    delay(10);
    mois_step("Set open-loop mode and enable chopper");
    // Set open-loop mode and enable chopper
    PACS_SPEC_Chopper_SetOpenLoop_BB("ON");
    delay(1);
    EnDis_chopper("ON");
    delay(10);
    // Translate mA into ROU
    // The conversion factor is in fact 130, but we use 133 in order to be able
    // to compare the measurement with previous ones, where the same value was
    // assumed.
    // chopper maximal deflection in mA
    double chop_max_ma = 20.0;
    // chopper movement step size in mA
    double chop_step_ma = 4.0;
    // chopper timescale in seconds allowing for initial
    // oscillation damping in open-loop mode
    int chop_damptime = 15;
    double chop_max_rou = chop_max_ma * 32767.0 / 133.0;
    double chop_step_rou = chop_step_ma * 32767.0 / 133.0;
    int ichop_max_rou = iround(chop_max_rou);
    int ichop_step_rou = iround(chop_step_rou);
    // Create table of chopper positions for absolute movement
    // Starting position (integer)
    int ichop_pos = 0;
    // Array of chopper positions sequence 1
    int[] chop_steps = [];
    // Running variable
    int i = 0;
    chop_steps[i] = ichop_pos;
    i = i + 1;
    ichop_pos = ichop_pos + ichop_step_rou;
    while(ichop_pos <= ichop_max_rou) {
        chop_steps[i] = ichop_pos;
        i = i + 1;
        chop_steps[i] = -ichop_pos;
        i = i + 1;
        ichop_pos = ichop_pos + ichop_step_rou;
    }
    int len = length(chop_steps);
    //Length of array
    mois_step("First sequence: alternating chopper movement");
    // First sequence: alternating chopper movement
    for(int s1 = 0 .. len - 1) {
        PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(chop_steps[s1]);
        delay(chop_damptime);
    }
    // End of first sequence
    // Move chopper to zero position
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(0);
    delay(chop_damptime);
    mois_step("Second sequence: alternating chopper movement, repeated once -> k loop");
    // Second sequence: alternating chopper movement, repeated once -> k loop
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(-5 * ichop_step_rou);
    delay(chop_damptime);
    for(int s2 = 1 .. 10) {
        PACS_SPEC_Chopper_OpenLoop_MoveRel_BB(ichop_step_rou);
        delay(chop_damptime);
    }
    // End of second sequence
    // Move chopper to zero position
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_BB(0);
    delay(chop_damptime);
    mois_step("Disable chopper and switch off open-loop mode");
    // Disable chopper and switch off open-loop mode
    EnDis_chopper("OFF");
    PACS_SPEC_Chopper_SetOpenLoop_BB("OFF");
    delay(10);
    // Switch off chopper 
    PACS_Chopper_SWON_SWOF_only("OFF");
    delay(5);
    mois_step("Set Chopper Controller Parameters: CONFChopper -> nom_sky");
    // Set Chopper Controller Parameters: CONFChopper -> nom_sky
    CONF_chopper("CONFChopper","nom_sky");
    delay(2);
    mois_step("Stop diagnostic HK");
    // Stop diagnostic HK
    PACS_SPEC_Chopper_OpenLoop_MoveAbs_dHK_BB("OFF");
}

// CVS file      : CONF_spec_fltw_R_Warm.txt
// Missionphase  : FMILT_3 & Later
//
// Purpose       : CONFigure the spectro filter wheel for Redundant Warm
//                  
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 0.1 
// History       : 1.0 4-Jul-2007 PR creation
//               :
procedure CONF_spec_fltw_R_Warm {
}{
    string calUname = "CONFFWSPEC";
    // FWSPEC CALIBRATION TABLE
    string calUrow = "FMILT_WR";
    // INSTRUMENT VERSION
    int rate = ilookup(calUname,calUrow,"Rate");
    int current = ilookup(calUname,calUrow,"Drive_current");
    int threshold_A = ilookup(calUname,calUrow,"Threshold_A");
    int threshold_B = ilookup(calUname,calUrow,"Threshold_B");
    int status_A = ilookup(calUname,calUrow,"Status_A");
    int status_B = ilookup(calUname,calUrow,"Status_B");
    {int}[] parlist = [{rate},{current},{threshold_A},{threshold_B},{status_A},{status_B}];
    int[] aux = [rate,current,threshold_A,threshold_B,status_A,status_B];
    int check_sum = checksum("int",aux);
    Pacs_DMC_WRT_FWSPEC_CONF_PAR(parlist,check_sum);
}

// Mission phase : ILT at Garching
//
// Purpose :
//   Reduced NEP measurements for the new sequencer test
//
// Author : Koryo Okumura
//
// CUS script : procedure PHOT_redArray_alternatePolarisation_direct_IST
//
// Argument :
//    int response_measure_time = 60; // response measure time in seconds
//    int noise_measure_time = 120; // noise measure time in seconds
//    int lowFreq_noise_time = 1800; // long noise measure time in seconds
//    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//
// Description :
//   + First, all 24 biases are set group by group
//   + Loop over 11 sets of 4 baisc biases (VH, VL, VRL, VH-BLIND) are set group by group
//   + Set PACS chopper on CS1 to measure the noise
//   + Loop over 11 sets of 4 baisc biases (VH, VL, VRL, VH-BLIND) are set group by group
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_newSeq_IST(1)
//
// Version : Thu Oct 04 20:34:35 CEST 2007
//
procedure PHOT_redArray_alternatePolarisation_direct_IST {
    int response_measure_time = 60; // response measure time in seconds
    int noise_measure_time = 120; // noise measure time in seconds
    int lowFreq_noise_time = 1800; // long noise measure time in seconds
    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
}{
    int operand = 0;
    int posCS1 = -21500;
    int posCS2 = 21500;
    //*********************************
    // Apply the new sequencer setting
    //*********************************
    //
    PACS_Phot_Sequencer_SetupNew();
    //
    //*******************************
    // Select Filter A (110 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //***********************************************
    //***********************************************
    //
    //	Bias setting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(biasFile,1);
    PHOT_set_bias_volt(biasFile,2);
    PHOT_set_bias_volt(biasFile,3);
    PHOT_set_bias_volt(biasFile,4);
    PHOT_set_bias_volt(biasFile,5);
    PHOT_set_bias_volt(biasFile,6);
    //
    //********************************************************
    // Sequence mode : blocking on VDEC_X for the direct mode
    //********************************************************
    //
    // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
    // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
    //
    //**************************
    // Sequence mode : Sref_only
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
    //# P 09 01 00 01
    operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // Set gain high
    Pacs_BOLC_SET_GAIN("HIGH");
    //
    //**********************************************
    // Set the PACS chopper at the central position
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(0);
    //
    //**********************************************************************
    //                       Response Measurement
    // Expected fluxes : 1.7 and 2.0pW on the blue
    //               and 5.3 and 6.2pW on the red
    //**********************************************************************
    //
    TMMarker600();
    //***********************************************************
    // Bias 1 (Vh-Vl)blue = 1.0 Volts, (Vh-Vl)red = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G1(0.99);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.2875928897414196 Volts
    Pacs_BOLC_SET_VRL_G1(0.2875928897414196);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.78435816010763 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.78435816010763);
    // Set group 2 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G2(0.99);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.2976890643549285 Volts
    Pacs_BOLC_SET_VRL_G2(0.2976890643549285);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.7946385038224304 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.7946385038224304);
    // Set group 3 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G3(0.99);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.2921869021406959 Volts
    Pacs_BOLC_SET_VRL_G3(0.2921869021406959);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.8111181679623898 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.8111181679623898);
    // Set group 4 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G4(0.99);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.2833032550752384 Volts
    Pacs_BOLC_SET_VRL_G4(0.2833032550752384);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.8038951101792082 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.8038951101792082);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3346340277410602 Volts
    Pacs_BOLC_SET_VRL_G5(0.3346340277410602);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8466792279676985 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8466792279676985);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.32636237036822335 Volts
    Pacs_BOLC_SET_VRL_G6(0.32636237036822335);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8367532617835844 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8367532617835844);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)blue = 1.2 Volts, (Vh-Vl)red = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G1(1.19);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.3577080013822565 Volts
    Pacs_BOLC_SET_VRL_G1(0.3577080013822565);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9420622421434064 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9420622421434064);
    // Set group 2 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G2(1.19);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.36696811904468774 Volts
    Pacs_BOLC_SET_VRL_G2(0.36696811904468774);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9515329512935697 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9515329512935697);
    // Set group 3 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G3(1.19);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.3640303856110917 Volts
    Pacs_BOLC_SET_VRL_G3(0.3640303856110917);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9482056457093682 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9482056457093682);
    // Set group 4 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G4(1.19);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3523579205628669 Volts
    Pacs_BOLC_SET_VRL_G4(0.3523579205628669);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9603646239045185 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9603646239045185);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4064368830411808 Volts
    Pacs_BOLC_SET_VRL_G5(0.4064368830411808);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8950576820742784 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8950576820742784);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.39643145192214363 Volts
    Pacs_BOLC_SET_VRL_G6(0.39643145192214363);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8837201139355604 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8837201139355604);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)blue = 1.4 Volts, (Vh-Vl)red = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.3525857926230986 Volts
    Pacs_BOLC_SET_VH_G1(1.3525857926230986);
    // Set group 1 bol bias 02 (VL) to -0.047414207376901184 Volts
    Pacs_BOLC_SET_VL_G1(-0.047414207376901184);
    // Set group 1 bol bias 03 (VRL) to 0.3926244201072773 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926244201072773);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.976547929868054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.976547929868054);
    // Set group 2 bol bias 01 (VH) to 1.3374255283716547 Volts
    Pacs_BOLC_SET_VH_G2(1.3374255283716547);
    // Set group 2 bol bias 02 (VL) to -0.06257447162834509 Volts
    Pacs_BOLC_SET_VL_G2(-0.06257447162834509);
    // Set group 2 bol bias 03 (VRL) to 0.38802799053825054 Volts
    Pacs_BOLC_SET_VRL_G2(0.38802799053825054);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9723540060682856 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9723540060682856);
    // Set group 3 bol bias 01 (VH) to 1.341267296137658 Volts
    Pacs_BOLC_SET_VH_G3(1.341267296137658);
    // Set group 3 bol bias 02 (VL) to -0.058732703862341994 Volts
    Pacs_BOLC_SET_VL_G3(-0.058732703862341994);
    // Set group 3 bol bias 03 (VRL) to 0.38970189090896923 Volts
    Pacs_BOLC_SET_VRL_G3(0.38970189090896923);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9735810667835696 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9735810667835696);
    // Set group 4 bol bias 01 (VH) to 1.352746675150765 Volts
    Pacs_BOLC_SET_VH_G4(1.352746675150765);
    // Set group 4 bol bias 02 (VL) to -0.04725332484923491 Volts
    Pacs_BOLC_SET_VL_G4(-0.04725332484923491);
    // Set group 4 bol bias 03 (VRL) to 0.3856108728986011 Volts
    Pacs_BOLC_SET_VRL_G4(0.3856108728986011);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9932003720526934 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9932003720526934);
    // Set group 5 bol bias 01 (VH) to 1.320583197395035 Volts
    Pacs_BOLC_SET_VH_G5(1.320583197395035);
    // Set group 5 bol bias 02 (VL) to -0.07941680260496485 Volts
    Pacs_BOLC_SET_VL_G5(-0.07941680260496485);
    // Set group 5 bol bias 03 (VRL) to 0.4116095244710064 Volts
    Pacs_BOLC_SET_VRL_G5(0.4116095244710064);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055742088043621 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055742088043621);
    // Set group 6 bol bias 01 (VH) to 1.3562697990163495 Volts
    Pacs_BOLC_SET_VH_G6(1.3562697990163495);
    // Set group 6 bol bias 02 (VL) to -0.04373020098365052 Volts
    Pacs_BOLC_SET_VL_G6(-0.04373020098365052);
    // Set group 6 bol bias 03 (VRL) to 0.43594530124025854 Volts
    Pacs_BOLC_SET_VRL_G6(0.43594530124025854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.011921670046162 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.011921670046162);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)blue = 1.6 Volts, (Vh-Vl)red = 1.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4783736198117614 Volts
    Pacs_BOLC_SET_VH_G1(1.4783736198117614);
    // Set group 1 bol bias 02 (VL) to -0.12162638018823857 Volts
    Pacs_BOLC_SET_VL_G1(-0.12162638018823857);
    // Set group 1 bol bias 03 (VRL) to 0.392515090355521 Volts
    Pacs_BOLC_SET_VRL_G1(0.392515090355521);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9764399412468519 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9764399412468519);
    // Set group 2 bol bias 01 (VH) to 1.4615686869832905 Volts
    Pacs_BOLC_SET_VH_G2(1.4615686869832905);
    // Set group 2 bol bias 02 (VL) to -0.13843131301670974 Volts
    Pacs_BOLC_SET_VL_G2(-0.13843131301670974);
    // Set group 2 bol bias 03 (VRL) to 0.3878839845398352 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878839845398352);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9722117106846373 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9722117106846373);
    // Set group 3 bol bias 01 (VH) to 1.4655563032867613 Volts
    Pacs_BOLC_SET_VH_G3(1.4655563032867613);
    // Set group 3 bol bias 02 (VL) to -0.13444369671323875 Volts
    Pacs_BOLC_SET_VL_G3(-0.13444369671323875);
    // Set group 3 bol bias 03 (VRL) to 0.38996914633068824 Volts
    Pacs_BOLC_SET_VRL_G3(0.38996914633068824);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9738455591218464 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9738455591218464);
    // Set group 4 bol bias 01 (VH) to 1.4803815567917744 Volts
    Pacs_BOLC_SET_VH_G4(1.4803815567917744);
    // Set group 4 bol bias 02 (VL) to -0.11961844320822568 Volts
    Pacs_BOLC_SET_VL_G4(-0.11961844320822568);
    // Set group 4 bol bias 03 (VRL) to 0.3860593630979322 Volts
    Pacs_BOLC_SET_VRL_G4(0.3860593630979322);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9936441996882226 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9936441996882226);
    // Set group 5 bol bias 01 (VH) to 1.3828510880972673 Volts
    Pacs_BOLC_SET_VH_G5(1.3828510880972673);
    // Set group 5 bol bias 02 (VL) to -0.11714891190273273 Volts
    Pacs_BOLC_SET_VL_G5(-0.11714891190273273);
    // Set group 5 bol bias 03 (VRL) to 0.4109562973201683 Volts
    Pacs_BOLC_SET_VRL_G5(0.4109562973201683);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055094312734005 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055094312734005);
    // Set group 6 bol bias 01 (VH) to 1.4187389541758537 Volts
    Pacs_BOLC_SET_VH_G6(1.4187389541758537);
    // Set group 6 bol bias 02 (VL) to -0.08126104582414631 Volts
    Pacs_BOLC_SET_VL_G6(-0.08126104582414631);
    // Set group 6 bol bias 03 (VRL) to 0.4349651037009118 Volts
    Pacs_BOLC_SET_VRL_G6(0.4349651037009118);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0109400872654906 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0109400872654906);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)blue = 1.7 Volts, (Vh-Vl)red = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.542293926761549 Volts
    Pacs_BOLC_SET_VH_G1(1.542293926761549);
    // Set group 1 bol bias 02 (VL) to -0.15770607323845098 Volts
    Pacs_BOLC_SET_VL_G1(-0.15770607323845098);
    // Set group 1 bol bias 03 (VRL) to 0.3926294451860477 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926294451860477);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9765528932845227 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9765528932845227);
    // Set group 2 bol bias 01 (VH) to 1.5247596019367946 Volts
    Pacs_BOLC_SET_VH_G2(1.5247596019367946);
    // Set group 2 bol bias 02 (VL) to -0.17524039806320546 Volts
    Pacs_BOLC_SET_VL_G2(-0.17524039806320546);
    // Set group 2 bol bias 03 (VRL) to 0.3878550325870832 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878550325870832);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9721831025166574 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9721831025166574);
    // Set group 3 bol bias 01 (VH) to 1.5286400044176514 Volts
    Pacs_BOLC_SET_VH_G3(1.5286400044176514);
    // Set group 3 bol bias 02 (VL) to -0.1713599955823485 Volts
    Pacs_BOLC_SET_VL_G3(-0.1713599955823485);
    // Set group 3 bol bias 03 (VRL) to 0.3901485670988867 Volts
    Pacs_BOLC_SET_VRL_G3(0.3901485670988867);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9740231261405279 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9740231261405279);
    // Set group 4 bol bias 01 (VH) to 1.5451742923820575 Volts
    Pacs_BOLC_SET_VH_G4(1.5451742923820575);
    // Set group 4 bol bias 02 (VL) to -0.15482570761794245 Volts
    Pacs_BOLC_SET_VL_G4(-0.15482570761794245);
    // Set group 4 bol bias 03 (VRL) to 0.3871858356177216 Volts
    Pacs_BOLC_SET_VRL_G4(0.3871858356177216);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9947589297629622 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9947589297629622);
    // Set group 5 bol bias 01 (VH) to 1.4463934011524333 Volts
    Pacs_BOLC_SET_VH_G5(1.4463934011524333);
    // Set group 5 bol bias 02 (VL) to -0.15360659884756683 Volts
    Pacs_BOLC_SET_VL_G5(-0.15360659884756683);
    // Set group 5 bol bias 03 (VRL) to 0.4101701125060366 Volts
    Pacs_BOLC_SET_VRL_G5(0.4101701125060366);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.054314719447538 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.054314719447538);
    // Set group 6 bol bias 01 (VH) to 1.4826068632993925 Volts
    Pacs_BOLC_SET_VH_G6(1.4826068632993925);
    // Set group 6 bol bias 02 (VL) to -0.11739313670060761 Volts
    Pacs_BOLC_SET_VL_G6(-0.11739313670060761);
    // Set group 6 bol bias 03 (VRL) to 0.4338779750444286 Volts
    Pacs_BOLC_SET_VRL_G6(0.4338779750444286);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.009851264439135 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.009851264439135);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)blue = 1.8 Volts, (Vh-Vl)red = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.60690529764583 Volts
    Pacs_BOLC_SET_VH_G1(1.60690529764583);
    // Set group 1 bol bias 02 (VL) to -0.19309470235416992 Volts
    Pacs_BOLC_SET_VL_G1(-0.19309470235416992);
    // Set group 1 bol bias 03 (VRL) to 0.39257168553053945 Volts
    Pacs_BOLC_SET_VRL_G1(0.39257168553053945);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9987180645064364 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9987180645064364);
    // Set group 2 bol bias 01 (VH) to 1.5888225493633414 Volts
    Pacs_BOLC_SET_VH_G2(1.5888225493633414);
    // Set group 2 bol bias 02 (VL) to -0.2111774506366586 Volts
    Pacs_BOLC_SET_VL_G2(-0.2111774506366586);
    // Set group 2 bol bias 03 (VRL) to 0.387719891228717 Volts
    Pacs_BOLC_SET_VRL_G2(0.387719891228717);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9720495652990864 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9720495652990864);
    // Set group 3 bol bias 01 (VH) to 1.5926816774791708 Volts
    Pacs_BOLC_SET_VH_G3(1.5926816774791708);
    // Set group 3 bol bias 02 (VL) to -0.20731832252082927 Volts
    Pacs_BOLC_SET_VL_G3(-0.20731832252082927);
    // Set group 3 bol bias 03 (VRL) to 0.39036266684895493 Volts
    Pacs_BOLC_SET_VRL_G3(0.39036266684895493);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.974235015140725 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.974235015140725);
    // Set group 4 bol bias 01 (VH) to 1.6103713769916332 Volts
    Pacs_BOLC_SET_VH_G4(1.6103713769916332);
    // Set group 4 bol bias 02 (VL) to -0.1896286230083667 Volts
    Pacs_BOLC_SET_VL_G4(-0.1896286230083667);
    // Set group 4 bol bias 03 (VRL) to 0.38763171869999546 Volts
    Pacs_BOLC_SET_VRL_G4(0.38763171869999546);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9952001524800798 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9952001524800798);
    // Set group 5 bol bias 01 (VH) to 1.575230733402161 Volts
    Pacs_BOLC_SET_VH_G5(1.575230733402161);
    // Set group 5 bol bias 02 (VL) to -0.22476926659783908 Volts
    Pacs_BOLC_SET_VL_G5(-0.22476926659783908);
    // Set group 5 bol bias 03 (VRL) to 0.40838061675412257 Volts
    Pacs_BOLC_SET_VRL_G5(0.40838061675412257);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.052540349440553 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.052540349440553);
    // Set group 6 bol bias 01 (VH) to 1.6128643450774607 Volts
    Pacs_BOLC_SET_VH_G6(1.6128643450774607);
    // Set group 6 bol bias 02 (VL) to -0.1871356549225394 Volts
    Pacs_BOLC_SET_VL_G6(-0.1871356549225394);
    // Set group 6 bol bias 03 (VRL) to 0.4319097861053989 Volts
    Pacs_BOLC_SET_VRL_G6(0.4319097861053989);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.007881605555887 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.007881605555887);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)blue = 2.0 Volts, (Vh-Vl)red = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.739376176417995 Volts
    Pacs_BOLC_SET_VH_G1(1.739376176417995);
    // Set group 1 bol bias 02 (VL) to -0.2606238235820051 Volts
    Pacs_BOLC_SET_VL_G1(-0.2606238235820051);
    // Set group 1 bol bias 03 (VRL) to 0.3921536831520859 Volts
    Pacs_BOLC_SET_VRL_G1(0.3921536831520859);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9760829613086472 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9760829613086472);
    // Set group 2 bol bias 01 (VH) to 1.719809813472755 Volts
    Pacs_BOLC_SET_VH_G2(1.719809813472755);
    // Set group 2 bol bias 02 (VL) to -0.28019018652724503 Volts
    Pacs_BOLC_SET_VL_G2(-0.28019018652724503);
    // Set group 2 bol bias 03 (VRL) to 0.38744168454874117 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744168454874117);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9717746579976725 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9717746579976725);
    // Set group 3 bol bias 01 (VH) to 1.7343527587435847 Volts
    Pacs_BOLC_SET_VH_G3(1.7343527587435847);
    // Set group 3 bol bias 02 (VL) to -0.2656472412564153 Volts
    Pacs_BOLC_SET_VL_G3(-0.2656472412564153);
    // Set group 3 bol bias 03 (VRL) to 0.4017790445564455 Volts
    Pacs_BOLC_SET_VRL_G3(0.4017790445564455);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9855314406558735 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9855314406558735);
    // Set group 4 bol bias 01 (VH) to 1.7440573141484068 Volts
    Pacs_BOLC_SET_VH_G4(1.7440573141484068);
    // Set group 4 bol bias 02 (VL) to -0.2559426858515932 Volts
    Pacs_BOLC_SET_VL_G4(-0.2559426858515932);
    // Set group 4 bol bias 03 (VRL) to 0.38894738596666634 Volts
    Pacs_BOLC_SET_VRL_G4(0.38894738596666634);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.996502027278406 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.996502027278406);
    // Set group 5 bol bias 01 (VH) to 1.6403549621270441 Volts
    Pacs_BOLC_SET_VH_G5(1.6403549621270441);
    // Set group 5 bol bias 02 (VL) to -0.25964503787295584 Volts
    Pacs_BOLC_SET_VL_G5(-0.25964503787295584);
    // Set group 5 bol bias 03 (VRL) to 0.4071234038646236 Volts
    Pacs_BOLC_SET_VRL_G5(0.4071234038646236);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051293864758269 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051293864758269);
    // Set group 6 bol bias 01 (VH) to 1.6787311020540112 Volts
    Pacs_BOLC_SET_VH_G6(1.6787311020540112);
    // Set group 6 bol bias 02 (VL) to -0.22126889794598872 Volts
    Pacs_BOLC_SET_VL_G6(-0.22126889794598872);
    // Set group 6 bol bias 03 (VRL) to 0.4305158637367362 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305158637367362);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0064867220677454 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0064867220677454);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)blue = 2.3 Volts, (Vh-Vl)red = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.9636608873020274 Volts
    Pacs_BOLC_SET_VH_G1(1.9636608873020274);
    // Set group 1 bol bias 02 (VL) to -0.3363391126979725 Volts
    Pacs_BOLC_SET_VL_G1(-0.3363391126979725);
    // Set group 1 bol bias 03 (VRL) to 0.40278769107629514 Volts
    Pacs_BOLC_SET_VRL_G1(0.40278769107629514);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9865763456310306 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9865763456310306);
    // Set group 2 bol bias 01 (VH) to 1.927696912686972 Volts
    Pacs_BOLC_SET_VH_G2(1.927696912686972);
    // Set group 2 bol bias 02 (VL) to -0.37230308731302775 Volts
    Pacs_BOLC_SET_VL_G2(-0.37230308731302775);
    // Set group 2 bol bias 03 (VRL) to 0.3858403551587576 Volts
    Pacs_BOLC_SET_VRL_G2(0.3858403551587576);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9924144642105024 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9924144642105024);
    // Set group 3 bol bias 01 (VH) to 1.9431226670014545 Volts
    Pacs_BOLC_SET_VH_G3(1.9431226670014545);
    // Set group 3 bol bias 02 (VL) to -0.35687733299854535 Volts
    Pacs_BOLC_SET_VL_G3(-0.35687733299854535);
    // Set group 3 bol bias 03 (VRL) to 0.4024839037666154 Volts
    Pacs_BOLC_SET_VRL_G3(0.4024839037666154);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9862268670149914 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9862268670149914);
    // Set group 4 bol bias 01 (VH) to 1.9579270398291708 Volts
    Pacs_BOLC_SET_VH_G4(1.9579270398291708);
    // Set group 4 bol bias 02 (VL) to -0.3420729601708289 Volts
    Pacs_BOLC_SET_VL_G4(-0.3420729601708289);
    // Set group 4 bol bias 03 (VRL) to 0.3906771012878555 Volts
    Pacs_BOLC_SET_VRL_G4(0.3906771012878555);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.99821351608857 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.99821351608857);
    // Set group 5 bol bias 01 (VH) to 1.7079035410760286 Volts
    Pacs_BOLC_SET_VH_G5(1.7079035410760286);
    // Set group 5 bol bias 02 (VL) to -0.29209645892397146 Volts
    Pacs_BOLC_SET_VL_G5(-0.29209645892397146);
    // Set group 5 bol bias 03 (VRL) to 0.405804322083024 Volts
    Pacs_BOLC_SET_VRL_G5(0.405804322083024);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0499861292550787 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0499861292550787);
    // Set group 6 bol bias 01 (VH) to 1.7476622867412348 Volts
    Pacs_BOLC_SET_VH_G6(1.7476622867412348);
    // Set group 6 bol bias 02 (VL) to -0.2523377132587652 Volts
    Pacs_BOLC_SET_VL_G6(-0.2523377132587652);
    // Set group 6 bol bias 03 (VRL) to 0.429562228366719 Volts
    Pacs_BOLC_SET_VRL_G6(0.429562228366719);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.005532468489443 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.005532468489443);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)blue = 2.6 Volts, (Vh-Vl)red = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2151628880310112 Volts
    Pacs_BOLC_SET_VH_G1(2.2151628880310112);
    // Set group 1 bol bias 02 (VL) to -0.3848371119689889 Volts
    Pacs_BOLC_SET_VL_G1(-0.3848371119689889);
    // Set group 1 bol bias 03 (VRL) to 0.41342338183313837 Volts
    Pacs_BOLC_SET_VRL_G1(0.41342338183313837);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0193446104924915 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0193446104924915);
    // Set group 2 bol bias 01 (VH) to 2.1588489399994213 Volts
    Pacs_BOLC_SET_VH_G2(2.1588489399994213);
    // Set group 2 bol bias 02 (VL) to -0.4411510600005787 Volts
    Pacs_BOLC_SET_VL_G2(-0.4411510600005787);
    // Set group 2 bol bias 03 (VRL) to 0.3838811209851186 Volts
    Pacs_BOLC_SET_VRL_G2(0.3838811209851186);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9682559687629309 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9682559687629309);
    // Set group 3 bol bias 01 (VH) to 2.1867239063317037 Volts
    Pacs_BOLC_SET_VH_G3(2.1867239063317037);
    // Set group 3 bol bias 02 (VL) to -0.4132760936682966 Volts
    Pacs_BOLC_SET_VL_G3(-0.4132760936682966);
    // Set group 3 bol bias 03 (VRL) to 0.4136603871411812 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136603871411812);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9973179392427267 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9973179392427267);
    // Set group 4 bol bias 01 (VH) to 2.20827452044462 Volts
    Pacs_BOLC_SET_VH_G4(2.20827452044462);
    // Set group 4 bol bias 02 (VL) to -0.39172547955538 Volts
    Pacs_BOLC_SET_VL_G4(-0.39172547955538);
    // Set group 4 bol bias 03 (VRL) to 0.4039414339062088 Volts
    Pacs_BOLC_SET_VRL_G4(0.4039414339062088);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.011301244644244 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.011301244644244);
    // Set group 5 bol bias 01 (VH) to 1.7875017871866707 Volts
    Pacs_BOLC_SET_VH_G5(1.7875017871866707);
    // Set group 5 bol bias 02 (VL) to -0.31249821281332946 Volts
    Pacs_BOLC_SET_VL_G5(-0.31249821281332946);
    // Set group 5 bol bias 03 (VRL) to 0.41576367399178094 Volts
    Pacs_BOLC_SET_VRL_G5(0.41576367399178094);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.037668873916454 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.037668873916454);
    // Set group 6 bol bias 01 (VH) to 1.8172008318899895 Volts
    Pacs_BOLC_SET_VH_G6(1.8172008318899895);
    // Set group 6 bol bias 02 (VL) to -0.2827991681100106 Volts
    Pacs_BOLC_SET_VL_G6(-0.2827991681100106);
    // Set group 6 bol bias 03 (VRL) to 0.42845474144203777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42845474144203777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.004424303719793 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.004424303719793);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)blue = 2.9 Volts, (Vh-Vl)red = 2.3 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.517666343337925 Volts
    Pacs_BOLC_SET_VH_G1(2.517666343337925);
    // Set group 1 bol bias 02 (VL) to -0.382333656662075 Volts
    Pacs_BOLC_SET_VL_G1(-0.382333656662075);
    // Set group 1 bol bias 03 (VRL) to 0.4351367995957048 Volts
    Pacs_BOLC_SET_VRL_G1(0.4351367995957048);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9965703186107444 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9965703186107444);
    // Set group 2 bol bias 01 (VH) to 2.4353683146246183 Volts
    Pacs_BOLC_SET_VH_G2(2.4353683146246183);
    // Set group 2 bol bias 02 (VL) to -0.4646316853753816 Volts
    Pacs_BOLC_SET_VL_G2(-0.4646316853753816);
    // Set group 2 bol bias 03 (VRL) to 0.39230855172448975 Volts
    Pacs_BOLC_SET_VRL_G2(0.39230855172448975);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9765832317921543 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9765832317921543);
    // Set group 3 bol bias 01 (VH) to 2.4565430314555052 Volts
    Pacs_BOLC_SET_VH_G3(2.4565430314555052);
    // Set group 3 bol bias 02 (VL) to -0.4434569685444947 Volts
    Pacs_BOLC_SET_VL_G3(-0.4434569685444947);
    // Set group 3 bol bias 03 (VRL) to 0.4116559215687209 Volts
    Pacs_BOLC_SET_VRL_G3(0.4116559215687209);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175436768747823 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175436768747823);
    // Set group 4 bol bias 01 (VH) to 2.4726040303622487 Volts
    Pacs_BOLC_SET_VH_G4(2.4726040303622487);
    // Set group 4 bol bias 02 (VL) to -0.4273959696377513 Volts
    Pacs_BOLC_SET_VL_G4(-0.4273959696377513);
    // Set group 4 bol bias 03 (VRL) to 0.3940712295914811 Volts
    Pacs_BOLC_SET_VRL_G4(0.3940712295914811);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.023793793137234 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.023793793137234);
    // Set group 5 bol bias 01 (VH) to 1.9226793871045598 Volts
    Pacs_BOLC_SET_VH_G5(1.9226793871045598);
    // Set group 5 bol bias 02 (VL) to -0.37732061289544 Volts
    Pacs_BOLC_SET_VL_G5(-0.37732061289544);
    // Set group 5 bol bias 03 (VRL) to 0.40093587460771146 Volts
    Pacs_BOLC_SET_VRL_G5(0.40093587460771146);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.022938134951507 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.022938134951507);
    // Set group 6 bol bias 01 (VH) to 1.9672658597937258 Volts
    Pacs_BOLC_SET_VH_G6(1.9672658597937258);
    // Set group 6 bol bias 02 (VL) to -0.332734140206274 Volts
    Pacs_BOLC_SET_VL_G6(-0.332734140206274);
    // Set group 6 bol bias 03 (VRL) to 0.4263945599495246 Volts
    Pacs_BOLC_SET_VRL_G6(0.4263945599495246);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.002362975913312 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.002362975913312);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)blue = 3.2 Volts, (Vh-Vl)red = 2.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.847199981495237 Volts
    Pacs_BOLC_SET_VH_G1(2.847199981495237);
    // Set group 1 bol bias 02 (VL) to -0.3528000185047631 Volts
    Pacs_BOLC_SET_VL_G1(-0.3528000185047631);
    // Set group 1 bol bias 03 (VRL) to 0.4347941377293029 Volts
    Pacs_BOLC_SET_VRL_G1(0.4347941377293029);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.018449774761696 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.018449774761696);
    // Set group 2 bol bias 01 (VH) to 2.7602559944480873 Volts
    Pacs_BOLC_SET_VH_G2(2.7602559944480873);
    // Set group 2 bol bias 02 (VL) to -0.43974400555191273 Volts
    Pacs_BOLC_SET_VL_G2(-0.43974400555191273);
    // Set group 2 bol bias 03 (VRL) to 0.4036708891743245 Volts
    Pacs_BOLC_SET_VRL_G2(0.4036708891743245);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.0099936291338243 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.0099936291338243);
    // Set group 3 bol bias 01 (VH) to 2.805732095961401 Volts
    Pacs_BOLC_SET_VH_G3(2.805732095961401);
    // Set group 3 bol bias 02 (VL) to -0.3942679040385992 Volts
    Pacs_BOLC_SET_VL_G3(-0.3942679040385992);
    // Set group 3 bol bias 03 (VRL) to 0.4339248022480186 Volts
    Pacs_BOLC_SET_VRL_G3(0.4339248022480186);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175166229478236 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175166229478236);
    // Set group 4 bol bias 01 (VH) to 2.8132260321912117 Volts
    Pacs_BOLC_SET_VH_G4(2.8132260321912117);
    // Set group 4 bol bias 02 (VL) to -0.3867739678087883 Volts
    Pacs_BOLC_SET_VL_G4(-0.3867739678087883);
    // Set group 4 bol bias 03 (VRL) to 0.4141623922109569 Volts
    Pacs_BOLC_SET_VRL_G4(0.4141623922109569);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.0213933637092976 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.0213933637092976);
    // Set group 5 bol bias 01 (VH) to 2.1145200531318697 Volts
    Pacs_BOLC_SET_VH_G5(2.1145200531318697);
    // Set group 5 bol bias 02 (VL) to -0.38547994686813014 Volts
    Pacs_BOLC_SET_VL_G5(-0.38547994686813014);
    // Set group 5 bol bias 03 (VRL) to 0.4292977832137159 Volts
    Pacs_BOLC_SET_VRL_G5(0.4292977832137159);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.006817368773259 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.006817368773259);
    // Set group 6 bol bias 01 (VH) to 2.1293608950052523 Volts
    Pacs_BOLC_SET_VH_G6(2.1293608950052523);
    // Set group 6 bol bias 02 (VL) to -0.3706391049947475 Volts
    Pacs_BOLC_SET_VL_G6(-0.3706391049947475);
    // Set group 6 bol bias 03 (VRL) to 0.4231555942593115 Volts
    Pacs_BOLC_SET_VRL_G6(0.4231555942593115);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9769002872568586 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9769002872568586);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //
    //
    //************************************************************************
    //                           Noise Measurement
    // Expected fluxes : 1.7pW on the blue and 5.3pW on the red detector
    //************************************************************************
    //
    //*****************************
    // Set the PACS chopper on CS1
    //*****************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(posCS1);
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)blue = 1.0 Volts, (Vh-Vl)red = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G1(0.99);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.2875928897414196 Volts
    Pacs_BOLC_SET_VRL_G1(0.2875928897414196);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.78435816010763 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.78435816010763);
    // Set group 2 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G2(0.99);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.2976890643549285 Volts
    Pacs_BOLC_SET_VRL_G2(0.2976890643549285);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.7946385038224304 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.7946385038224304);
    // Set group 3 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G3(0.99);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.2921869021406959 Volts
    Pacs_BOLC_SET_VRL_G3(0.2921869021406959);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.8111181679623898 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.8111181679623898);
    // Set group 4 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G4(0.99);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.2833032550752384 Volts
    Pacs_BOLC_SET_VRL_G4(0.2833032550752384);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.8038951101792082 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.8038951101792082);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3346340277410602 Volts
    Pacs_BOLC_SET_VRL_G5(0.3346340277410602);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8466792279676985 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8466792279676985);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.32636237036822335 Volts
    Pacs_BOLC_SET_VRL_G6(0.32636237036822335);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8367532617835844 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8367532617835844);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)blue = 1.2 Volts, (Vh-Vl)red = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G1(1.19);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.3577080013822565 Volts
    Pacs_BOLC_SET_VRL_G1(0.3577080013822565);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9420622421434064 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9420622421434064);
    // Set group 2 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G2(1.19);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.36696811904468774 Volts
    Pacs_BOLC_SET_VRL_G2(0.36696811904468774);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9515329512935697 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9515329512935697);
    // Set group 3 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G3(1.19);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.3640303856110917 Volts
    Pacs_BOLC_SET_VRL_G3(0.3640303856110917);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9482056457093682 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9482056457093682);
    // Set group 4 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G4(1.19);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3523579205628669 Volts
    Pacs_BOLC_SET_VRL_G4(0.3523579205628669);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9603646239045185 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9603646239045185);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4064368830411808 Volts
    Pacs_BOLC_SET_VRL_G5(0.4064368830411808);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8950576820742784 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8950576820742784);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.39643145192214363 Volts
    Pacs_BOLC_SET_VRL_G6(0.39643145192214363);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8837201139355604 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8837201139355604);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)blue = 1.4 Volts, (Vh-Vl)red = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.3525857926230986 Volts
    Pacs_BOLC_SET_VH_G1(1.3525857926230986);
    // Set group 1 bol bias 02 (VL) to -0.047414207376901184 Volts
    Pacs_BOLC_SET_VL_G1(-0.047414207376901184);
    // Set group 1 bol bias 03 (VRL) to 0.3926244201072773 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926244201072773);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.976547929868054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.976547929868054);
    // Set group 2 bol bias 01 (VH) to 1.3374255283716547 Volts
    Pacs_BOLC_SET_VH_G2(1.3374255283716547);
    // Set group 2 bol bias 02 (VL) to -0.06257447162834509 Volts
    Pacs_BOLC_SET_VL_G2(-0.06257447162834509);
    // Set group 2 bol bias 03 (VRL) to 0.38802799053825054 Volts
    Pacs_BOLC_SET_VRL_G2(0.38802799053825054);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9723540060682856 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9723540060682856);
    // Set group 3 bol bias 01 (VH) to 1.341267296137658 Volts
    Pacs_BOLC_SET_VH_G3(1.341267296137658);
    // Set group 3 bol bias 02 (VL) to -0.058732703862341994 Volts
    Pacs_BOLC_SET_VL_G3(-0.058732703862341994);
    // Set group 3 bol bias 03 (VRL) to 0.38970189090896923 Volts
    Pacs_BOLC_SET_VRL_G3(0.38970189090896923);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9735810667835696 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9735810667835696);
    // Set group 4 bol bias 01 (VH) to 1.352746675150765 Volts
    Pacs_BOLC_SET_VH_G4(1.352746675150765);
    // Set group 4 bol bias 02 (VL) to -0.04725332484923491 Volts
    Pacs_BOLC_SET_VL_G4(-0.04725332484923491);
    // Set group 4 bol bias 03 (VRL) to 0.3856108728986011 Volts
    Pacs_BOLC_SET_VRL_G4(0.3856108728986011);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9932003720526934 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9932003720526934);
    // Set group 5 bol bias 01 (VH) to 1.320583197395035 Volts
    Pacs_BOLC_SET_VH_G5(1.320583197395035);
    // Set group 5 bol bias 02 (VL) to -0.07941680260496485 Volts
    Pacs_BOLC_SET_VL_G5(-0.07941680260496485);
    // Set group 5 bol bias 03 (VRL) to 0.4116095244710064 Volts
    Pacs_BOLC_SET_VRL_G5(0.4116095244710064);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055742088043621 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055742088043621);
    // Set group 6 bol bias 01 (VH) to 1.3562697990163495 Volts
    Pacs_BOLC_SET_VH_G6(1.3562697990163495);
    // Set group 6 bol bias 02 (VL) to -0.04373020098365052 Volts
    Pacs_BOLC_SET_VL_G6(-0.04373020098365052);
    // Set group 6 bol bias 03 (VRL) to 0.43594530124025854 Volts
    Pacs_BOLC_SET_VRL_G6(0.43594530124025854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.011921670046162 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.011921670046162);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)blue = 1.6 Volts, (Vh-Vl)red = 1.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4783736198117614 Volts
    Pacs_BOLC_SET_VH_G1(1.4783736198117614);
    // Set group 1 bol bias 02 (VL) to -0.12162638018823857 Volts
    Pacs_BOLC_SET_VL_G1(-0.12162638018823857);
    // Set group 1 bol bias 03 (VRL) to 0.392515090355521 Volts
    Pacs_BOLC_SET_VRL_G1(0.392515090355521);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9764399412468519 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9764399412468519);
    // Set group 2 bol bias 01 (VH) to 1.4615686869832905 Volts
    Pacs_BOLC_SET_VH_G2(1.4615686869832905);
    // Set group 2 bol bias 02 (VL) to -0.13843131301670974 Volts
    Pacs_BOLC_SET_VL_G2(-0.13843131301670974);
    // Set group 2 bol bias 03 (VRL) to 0.3878839845398352 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878839845398352);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9722117106846373 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9722117106846373);
    // Set group 3 bol bias 01 (VH) to 1.4655563032867613 Volts
    Pacs_BOLC_SET_VH_G3(1.4655563032867613);
    // Set group 3 bol bias 02 (VL) to -0.13444369671323875 Volts
    Pacs_BOLC_SET_VL_G3(-0.13444369671323875);
    // Set group 3 bol bias 03 (VRL) to 0.38996914633068824 Volts
    Pacs_BOLC_SET_VRL_G3(0.38996914633068824);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9738455591218464 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9738455591218464);
    // Set group 4 bol bias 01 (VH) to 1.4803815567917744 Volts
    Pacs_BOLC_SET_VH_G4(1.4803815567917744);
    // Set group 4 bol bias 02 (VL) to -0.11961844320822568 Volts
    Pacs_BOLC_SET_VL_G4(-0.11961844320822568);
    // Set group 4 bol bias 03 (VRL) to 0.3860593630979322 Volts
    Pacs_BOLC_SET_VRL_G4(0.3860593630979322);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9936441996882226 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9936441996882226);
    // Set group 5 bol bias 01 (VH) to 1.3828510880972673 Volts
    Pacs_BOLC_SET_VH_G5(1.3828510880972673);
    // Set group 5 bol bias 02 (VL) to -0.11714891190273273 Volts
    Pacs_BOLC_SET_VL_G5(-0.11714891190273273);
    // Set group 5 bol bias 03 (VRL) to 0.4109562973201683 Volts
    Pacs_BOLC_SET_VRL_G5(0.4109562973201683);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055094312734005 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055094312734005);
    // Set group 6 bol bias 01 (VH) to 1.4187389541758537 Volts
    Pacs_BOLC_SET_VH_G6(1.4187389541758537);
    // Set group 6 bol bias 02 (VL) to -0.08126104582414631 Volts
    Pacs_BOLC_SET_VL_G6(-0.08126104582414631);
    // Set group 6 bol bias 03 (VRL) to 0.4349651037009118 Volts
    Pacs_BOLC_SET_VRL_G6(0.4349651037009118);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0109400872654906 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0109400872654906);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)blue = 1.7 Volts, (Vh-Vl)red = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.542293926761549 Volts
    Pacs_BOLC_SET_VH_G1(1.542293926761549);
    // Set group 1 bol bias 02 (VL) to -0.15770607323845098 Volts
    Pacs_BOLC_SET_VL_G1(-0.15770607323845098);
    // Set group 1 bol bias 03 (VRL) to 0.3926294451860477 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926294451860477);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9765528932845227 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9765528932845227);
    // Set group 2 bol bias 01 (VH) to 1.5247596019367946 Volts
    Pacs_BOLC_SET_VH_G2(1.5247596019367946);
    // Set group 2 bol bias 02 (VL) to -0.17524039806320546 Volts
    Pacs_BOLC_SET_VL_G2(-0.17524039806320546);
    // Set group 2 bol bias 03 (VRL) to 0.3878550325870832 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878550325870832);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9721831025166574 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9721831025166574);
    // Set group 3 bol bias 01 (VH) to 1.5286400044176514 Volts
    Pacs_BOLC_SET_VH_G3(1.5286400044176514);
    // Set group 3 bol bias 02 (VL) to -0.1713599955823485 Volts
    Pacs_BOLC_SET_VL_G3(-0.1713599955823485);
    // Set group 3 bol bias 03 (VRL) to 0.3901485670988867 Volts
    Pacs_BOLC_SET_VRL_G3(0.3901485670988867);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9740231261405279 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9740231261405279);
    // Set group 4 bol bias 01 (VH) to 1.5451742923820575 Volts
    Pacs_BOLC_SET_VH_G4(1.5451742923820575);
    // Set group 4 bol bias 02 (VL) to -0.15482570761794245 Volts
    Pacs_BOLC_SET_VL_G4(-0.15482570761794245);
    // Set group 4 bol bias 03 (VRL) to 0.3871858356177216 Volts
    Pacs_BOLC_SET_VRL_G4(0.3871858356177216);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9947589297629622 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9947589297629622);
    // Set group 5 bol bias 01 (VH) to 1.4463934011524333 Volts
    Pacs_BOLC_SET_VH_G5(1.4463934011524333);
    // Set group 5 bol bias 02 (VL) to -0.15360659884756683 Volts
    Pacs_BOLC_SET_VL_G5(-0.15360659884756683);
    // Set group 5 bol bias 03 (VRL) to 0.4101701125060366 Volts
    Pacs_BOLC_SET_VRL_G5(0.4101701125060366);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.054314719447538 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.054314719447538);
    // Set group 6 bol bias 01 (VH) to 1.4826068632993925 Volts
    Pacs_BOLC_SET_VH_G6(1.4826068632993925);
    // Set group 6 bol bias 02 (VL) to -0.11739313670060761 Volts
    Pacs_BOLC_SET_VL_G6(-0.11739313670060761);
    // Set group 6 bol bias 03 (VRL) to 0.4338779750444286 Volts
    Pacs_BOLC_SET_VRL_G6(0.4338779750444286);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.009851264439135 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.009851264439135);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)blue = 1.8 Volts, (Vh-Vl)red = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.60690529764583 Volts
    Pacs_BOLC_SET_VH_G1(1.60690529764583);
    // Set group 1 bol bias 02 (VL) to -0.19309470235416992 Volts
    Pacs_BOLC_SET_VL_G1(-0.19309470235416992);
    // Set group 1 bol bias 03 (VRL) to 0.39257168553053945 Volts
    Pacs_BOLC_SET_VRL_G1(0.39257168553053945);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9987180645064364 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9987180645064364);
    // Set group 2 bol bias 01 (VH) to 1.5888225493633414 Volts
    Pacs_BOLC_SET_VH_G2(1.5888225493633414);
    // Set group 2 bol bias 02 (VL) to -0.2111774506366586 Volts
    Pacs_BOLC_SET_VL_G2(-0.2111774506366586);
    // Set group 2 bol bias 03 (VRL) to 0.387719891228717 Volts
    Pacs_BOLC_SET_VRL_G2(0.387719891228717);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9720495652990864 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9720495652990864);
    // Set group 3 bol bias 01 (VH) to 1.5926816774791708 Volts
    Pacs_BOLC_SET_VH_G3(1.5926816774791708);
    // Set group 3 bol bias 02 (VL) to -0.20731832252082927 Volts
    Pacs_BOLC_SET_VL_G3(-0.20731832252082927);
    // Set group 3 bol bias 03 (VRL) to 0.39036266684895493 Volts
    Pacs_BOLC_SET_VRL_G3(0.39036266684895493);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.974235015140725 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.974235015140725);
    // Set group 4 bol bias 01 (VH) to 1.6103713769916332 Volts
    Pacs_BOLC_SET_VH_G4(1.6103713769916332);
    // Set group 4 bol bias 02 (VL) to -0.1896286230083667 Volts
    Pacs_BOLC_SET_VL_G4(-0.1896286230083667);
    // Set group 4 bol bias 03 (VRL) to 0.38763171869999546 Volts
    Pacs_BOLC_SET_VRL_G4(0.38763171869999546);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9952001524800798 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9952001524800798);
    // Set group 5 bol bias 01 (VH) to 1.575230733402161 Volts
    Pacs_BOLC_SET_VH_G5(1.575230733402161);
    // Set group 5 bol bias 02 (VL) to -0.22476926659783908 Volts
    Pacs_BOLC_SET_VL_G5(-0.22476926659783908);
    // Set group 5 bol bias 03 (VRL) to 0.40838061675412257 Volts
    Pacs_BOLC_SET_VRL_G5(0.40838061675412257);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.052540349440553 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.052540349440553);
    // Set group 6 bol bias 01 (VH) to 1.6128643450774607 Volts
    Pacs_BOLC_SET_VH_G6(1.6128643450774607);
    // Set group 6 bol bias 02 (VL) to -0.1871356549225394 Volts
    Pacs_BOLC_SET_VL_G6(-0.1871356549225394);
    // Set group 6 bol bias 03 (VRL) to 0.4319097861053989 Volts
    Pacs_BOLC_SET_VRL_G6(0.4319097861053989);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.007881605555887 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.007881605555887);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)blue = 2.0 Volts, (Vh-Vl)red = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.739376176417995 Volts
    Pacs_BOLC_SET_VH_G1(1.739376176417995);
    // Set group 1 bol bias 02 (VL) to -0.2606238235820051 Volts
    Pacs_BOLC_SET_VL_G1(-0.2606238235820051);
    // Set group 1 bol bias 03 (VRL) to 0.3921536831520859 Volts
    Pacs_BOLC_SET_VRL_G1(0.3921536831520859);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9760829613086472 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9760829613086472);
    // Set group 2 bol bias 01 (VH) to 1.719809813472755 Volts
    Pacs_BOLC_SET_VH_G2(1.719809813472755);
    // Set group 2 bol bias 02 (VL) to -0.28019018652724503 Volts
    Pacs_BOLC_SET_VL_G2(-0.28019018652724503);
    // Set group 2 bol bias 03 (VRL) to 0.38744168454874117 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744168454874117);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9717746579976725 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9717746579976725);
    // Set group 3 bol bias 01 (VH) to 1.7343527587435847 Volts
    Pacs_BOLC_SET_VH_G3(1.7343527587435847);
    // Set group 3 bol bias 02 (VL) to -0.2656472412564153 Volts
    Pacs_BOLC_SET_VL_G3(-0.2656472412564153);
    // Set group 3 bol bias 03 (VRL) to 0.4017790445564455 Volts
    Pacs_BOLC_SET_VRL_G3(0.4017790445564455);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9855314406558735 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9855314406558735);
    // Set group 4 bol bias 01 (VH) to 1.7440573141484068 Volts
    Pacs_BOLC_SET_VH_G4(1.7440573141484068);
    // Set group 4 bol bias 02 (VL) to -0.2559426858515932 Volts
    Pacs_BOLC_SET_VL_G4(-0.2559426858515932);
    // Set group 4 bol bias 03 (VRL) to 0.38894738596666634 Volts
    Pacs_BOLC_SET_VRL_G4(0.38894738596666634);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.996502027278406 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.996502027278406);
    // Set group 5 bol bias 01 (VH) to 1.6403549621270441 Volts
    Pacs_BOLC_SET_VH_G5(1.6403549621270441);
    // Set group 5 bol bias 02 (VL) to -0.25964503787295584 Volts
    Pacs_BOLC_SET_VL_G5(-0.25964503787295584);
    // Set group 5 bol bias 03 (VRL) to 0.4071234038646236 Volts
    Pacs_BOLC_SET_VRL_G5(0.4071234038646236);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051293864758269 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051293864758269);
    // Set group 6 bol bias 01 (VH) to 1.6787311020540112 Volts
    Pacs_BOLC_SET_VH_G6(1.6787311020540112);
    // Set group 6 bol bias 02 (VL) to -0.22126889794598872 Volts
    Pacs_BOLC_SET_VL_G6(-0.22126889794598872);
    // Set group 6 bol bias 03 (VRL) to 0.4305158637367362 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305158637367362);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0064867220677454 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0064867220677454);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)blue = 2.3 Volts, (Vh-Vl)red = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.9636608873020274 Volts
    Pacs_BOLC_SET_VH_G1(1.9636608873020274);
    // Set group 1 bol bias 02 (VL) to -0.3363391126979725 Volts
    Pacs_BOLC_SET_VL_G1(-0.3363391126979725);
    // Set group 1 bol bias 03 (VRL) to 0.40278769107629514 Volts
    Pacs_BOLC_SET_VRL_G1(0.40278769107629514);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9865763456310306 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9865763456310306);
    // Set group 2 bol bias 01 (VH) to 1.927696912686972 Volts
    Pacs_BOLC_SET_VH_G2(1.927696912686972);
    // Set group 2 bol bias 02 (VL) to -0.37230308731302775 Volts
    Pacs_BOLC_SET_VL_G2(-0.37230308731302775);
    // Set group 2 bol bias 03 (VRL) to 0.3858403551587576 Volts
    Pacs_BOLC_SET_VRL_G2(0.3858403551587576);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9924144642105024 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9924144642105024);
    // Set group 3 bol bias 01 (VH) to 1.9431226670014545 Volts
    Pacs_BOLC_SET_VH_G3(1.9431226670014545);
    // Set group 3 bol bias 02 (VL) to -0.35687733299854535 Volts
    Pacs_BOLC_SET_VL_G3(-0.35687733299854535);
    // Set group 3 bol bias 03 (VRL) to 0.4024839037666154 Volts
    Pacs_BOLC_SET_VRL_G3(0.4024839037666154);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9862268670149914 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9862268670149914);
    // Set group 4 bol bias 01 (VH) to 1.9579270398291708 Volts
    Pacs_BOLC_SET_VH_G4(1.9579270398291708);
    // Set group 4 bol bias 02 (VL) to -0.3420729601708289 Volts
    Pacs_BOLC_SET_VL_G4(-0.3420729601708289);
    // Set group 4 bol bias 03 (VRL) to 0.3906771012878555 Volts
    Pacs_BOLC_SET_VRL_G4(0.3906771012878555);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.99821351608857 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.99821351608857);
    // Set group 5 bol bias 01 (VH) to 1.7079035410760286 Volts
    Pacs_BOLC_SET_VH_G5(1.7079035410760286);
    // Set group 5 bol bias 02 (VL) to -0.29209645892397146 Volts
    Pacs_BOLC_SET_VL_G5(-0.29209645892397146);
    // Set group 5 bol bias 03 (VRL) to 0.405804322083024 Volts
    Pacs_BOLC_SET_VRL_G5(0.405804322083024);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0499861292550787 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0499861292550787);
    // Set group 6 bol bias 01 (VH) to 1.7476622867412348 Volts
    Pacs_BOLC_SET_VH_G6(1.7476622867412348);
    // Set group 6 bol bias 02 (VL) to -0.2523377132587652 Volts
    Pacs_BOLC_SET_VL_G6(-0.2523377132587652);
    // Set group 6 bol bias 03 (VRL) to 0.429562228366719 Volts
    Pacs_BOLC_SET_VRL_G6(0.429562228366719);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.005532468489443 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.005532468489443);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)blue = 2.6 Volts, (Vh-Vl)red = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2151628880310112 Volts
    Pacs_BOLC_SET_VH_G1(2.2151628880310112);
    // Set group 1 bol bias 02 (VL) to -0.3848371119689889 Volts
    Pacs_BOLC_SET_VL_G1(-0.3848371119689889);
    // Set group 1 bol bias 03 (VRL) to 0.41342338183313837 Volts
    Pacs_BOLC_SET_VRL_G1(0.41342338183313837);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0193446104924915 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0193446104924915);
    // Set group 2 bol bias 01 (VH) to 2.1588489399994213 Volts
    Pacs_BOLC_SET_VH_G2(2.1588489399994213);
    // Set group 2 bol bias 02 (VL) to -0.4411510600005787 Volts
    Pacs_BOLC_SET_VL_G2(-0.4411510600005787);
    // Set group 2 bol bias 03 (VRL) to 0.3838811209851186 Volts
    Pacs_BOLC_SET_VRL_G2(0.3838811209851186);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9682559687629309 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9682559687629309);
    // Set group 3 bol bias 01 (VH) to 2.1867239063317037 Volts
    Pacs_BOLC_SET_VH_G3(2.1867239063317037);
    // Set group 3 bol bias 02 (VL) to -0.4132760936682966 Volts
    Pacs_BOLC_SET_VL_G3(-0.4132760936682966);
    // Set group 3 bol bias 03 (VRL) to 0.4136603871411812 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136603871411812);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9973179392427267 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9973179392427267);
    // Set group 4 bol bias 01 (VH) to 2.20827452044462 Volts
    Pacs_BOLC_SET_VH_G4(2.20827452044462);
    // Set group 4 bol bias 02 (VL) to -0.39172547955538 Volts
    Pacs_BOLC_SET_VL_G4(-0.39172547955538);
    // Set group 4 bol bias 03 (VRL) to 0.4039414339062088 Volts
    Pacs_BOLC_SET_VRL_G4(0.4039414339062088);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.011301244644244 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.011301244644244);
    // Set group 5 bol bias 01 (VH) to 1.7875017871866707 Volts
    Pacs_BOLC_SET_VH_G5(1.7875017871866707);
    // Set group 5 bol bias 02 (VL) to -0.31249821281332946 Volts
    Pacs_BOLC_SET_VL_G5(-0.31249821281332946);
    // Set group 5 bol bias 03 (VRL) to 0.41576367399178094 Volts
    Pacs_BOLC_SET_VRL_G5(0.41576367399178094);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.037668873916454 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.037668873916454);
    // Set group 6 bol bias 01 (VH) to 1.8172008318899895 Volts
    Pacs_BOLC_SET_VH_G6(1.8172008318899895);
    // Set group 6 bol bias 02 (VL) to -0.2827991681100106 Volts
    Pacs_BOLC_SET_VL_G6(-0.2827991681100106);
    // Set group 6 bol bias 03 (VRL) to 0.42845474144203777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42845474144203777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.004424303719793 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.004424303719793);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)blue = 2.9 Volts, (Vh-Vl)red = 2.3 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.517666343337925 Volts
    Pacs_BOLC_SET_VH_G1(2.517666343337925);
    // Set group 1 bol bias 02 (VL) to -0.382333656662075 Volts
    Pacs_BOLC_SET_VL_G1(-0.382333656662075);
    // Set group 1 bol bias 03 (VRL) to 0.4351367995957048 Volts
    Pacs_BOLC_SET_VRL_G1(0.4351367995957048);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9965703186107444 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9965703186107444);
    // Set group 2 bol bias 01 (VH) to 2.4353683146246183 Volts
    Pacs_BOLC_SET_VH_G2(2.4353683146246183);
    // Set group 2 bol bias 02 (VL) to -0.4646316853753816 Volts
    Pacs_BOLC_SET_VL_G2(-0.4646316853753816);
    // Set group 2 bol bias 03 (VRL) to 0.39230855172448975 Volts
    Pacs_BOLC_SET_VRL_G2(0.39230855172448975);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9765832317921543 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9765832317921543);
    // Set group 3 bol bias 01 (VH) to 2.4565430314555052 Volts
    Pacs_BOLC_SET_VH_G3(2.4565430314555052);
    // Set group 3 bol bias 02 (VL) to -0.4434569685444947 Volts
    Pacs_BOLC_SET_VL_G3(-0.4434569685444947);
    // Set group 3 bol bias 03 (VRL) to 0.4116559215687209 Volts
    Pacs_BOLC_SET_VRL_G3(0.4116559215687209);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175436768747823 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175436768747823);
    // Set group 4 bol bias 01 (VH) to 2.4726040303622487 Volts
    Pacs_BOLC_SET_VH_G4(2.4726040303622487);
    // Set group 4 bol bias 02 (VL) to -0.4273959696377513 Volts
    Pacs_BOLC_SET_VL_G4(-0.4273959696377513);
    // Set group 4 bol bias 03 (VRL) to 0.3940712295914811 Volts
    Pacs_BOLC_SET_VRL_G4(0.3940712295914811);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.023793793137234 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.023793793137234);
    // Set group 5 bol bias 01 (VH) to 1.9226793871045598 Volts
    Pacs_BOLC_SET_VH_G5(1.9226793871045598);
    // Set group 5 bol bias 02 (VL) to -0.37732061289544 Volts
    Pacs_BOLC_SET_VL_G5(-0.37732061289544);
    // Set group 5 bol bias 03 (VRL) to 0.40093587460771146 Volts
    Pacs_BOLC_SET_VRL_G5(0.40093587460771146);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.022938134951507 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.022938134951507);
    // Set group 6 bol bias 01 (VH) to 1.9672658597937258 Volts
    Pacs_BOLC_SET_VH_G6(1.9672658597937258);
    // Set group 6 bol bias 02 (VL) to -0.332734140206274 Volts
    Pacs_BOLC_SET_VL_G6(-0.332734140206274);
    // Set group 6 bol bias 03 (VRL) to 0.4263945599495246 Volts
    Pacs_BOLC_SET_VRL_G6(0.4263945599495246);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.002362975913312 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.002362975913312);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)blue = 3.2 Volts, (Vh-Vl)red = 2.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.847199981495237 Volts
    Pacs_BOLC_SET_VH_G1(2.847199981495237);
    // Set group 1 bol bias 02 (VL) to -0.3528000185047631 Volts
    Pacs_BOLC_SET_VL_G1(-0.3528000185047631);
    // Set group 1 bol bias 03 (VRL) to 0.4347941377293029 Volts
    Pacs_BOLC_SET_VRL_G1(0.4347941377293029);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.018449774761696 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.018449774761696);
    // Set group 2 bol bias 01 (VH) to 2.7602559944480873 Volts
    Pacs_BOLC_SET_VH_G2(2.7602559944480873);
    // Set group 2 bol bias 02 (VL) to -0.43974400555191273 Volts
    Pacs_BOLC_SET_VL_G2(-0.43974400555191273);
    // Set group 2 bol bias 03 (VRL) to 0.4036708891743245 Volts
    Pacs_BOLC_SET_VRL_G2(0.4036708891743245);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.0099936291338243 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.0099936291338243);
    // Set group 3 bol bias 01 (VH) to 2.805732095961401 Volts
    Pacs_BOLC_SET_VH_G3(2.805732095961401);
    // Set group 3 bol bias 02 (VL) to -0.3942679040385992 Volts
    Pacs_BOLC_SET_VL_G3(-0.3942679040385992);
    // Set group 3 bol bias 03 (VRL) to 0.4339248022480186 Volts
    Pacs_BOLC_SET_VRL_G3(0.4339248022480186);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175166229478236 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175166229478236);
    // Set group 4 bol bias 01 (VH) to 2.8132260321912117 Volts
    Pacs_BOLC_SET_VH_G4(2.8132260321912117);
    // Set group 4 bol bias 02 (VL) to -0.3867739678087883 Volts
    Pacs_BOLC_SET_VL_G4(-0.3867739678087883);
    // Set group 4 bol bias 03 (VRL) to 0.4141623922109569 Volts
    Pacs_BOLC_SET_VRL_G4(0.4141623922109569);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.0213933637092976 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.0213933637092976);
    // Set group 5 bol bias 01 (VH) to 2.1145200531318697 Volts
    Pacs_BOLC_SET_VH_G5(2.1145200531318697);
    // Set group 5 bol bias 02 (VL) to -0.38547994686813014 Volts
    Pacs_BOLC_SET_VL_G5(-0.38547994686813014);
    // Set group 5 bol bias 03 (VRL) to 0.4292977832137159 Volts
    Pacs_BOLC_SET_VRL_G5(0.4292977832137159);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.006817368773259 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.006817368773259);
    // Set group 6 bol bias 01 (VH) to 2.1293608950052523 Volts
    Pacs_BOLC_SET_VH_G6(2.1293608950052523);
    // Set group 6 bol bias 02 (VL) to -0.3706391049947475 Volts
    Pacs_BOLC_SET_VL_G6(-0.3706391049947475);
    // Set group 6 bol bias 03 (VRL) to 0.4231555942593115 Volts
    Pacs_BOLC_SET_VRL_G6(0.4231555942593115);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9769002872568586 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9769002872568586);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //
    //
    //************************************************************************
    //                   Longer Noise Measurement
    // Expected fluxes : 1.7pW on the blue and 5.3pW on the red detector
    //************************************************************************
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)blue = 1.8 Volts, (Vh-Vl)red = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.60690529764583 Volts
    Pacs_BOLC_SET_VH_G1(1.60690529764583);
    // Set group 1 bol bias 02 (VL) to -0.19309470235416992 Volts
    Pacs_BOLC_SET_VL_G1(-0.19309470235416992);
    // Set group 1 bol bias 03 (VRL) to 0.39257168553053945 Volts
    Pacs_BOLC_SET_VRL_G1(0.39257168553053945);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9987180645064364 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9987180645064364);
    // Set group 2 bol bias 01 (VH) to 1.5888225493633414 Volts
    Pacs_BOLC_SET_VH_G2(1.5888225493633414);
    // Set group 2 bol bias 02 (VL) to -0.2111774506366586 Volts
    Pacs_BOLC_SET_VL_G2(-0.2111774506366586);
    // Set group 2 bol bias 03 (VRL) to 0.387719891228717 Volts
    Pacs_BOLC_SET_VRL_G2(0.387719891228717);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9720495652990864 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9720495652990864);
    // Set group 3 bol bias 01 (VH) to 1.5926816774791708 Volts
    Pacs_BOLC_SET_VH_G3(1.5926816774791708);
    // Set group 3 bol bias 02 (VL) to -0.20731832252082927 Volts
    Pacs_BOLC_SET_VL_G3(-0.20731832252082927);
    // Set group 3 bol bias 03 (VRL) to 0.39036266684895493 Volts
    Pacs_BOLC_SET_VRL_G3(0.39036266684895493);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.974235015140725 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.974235015140725);
    // Set group 4 bol bias 01 (VH) to 1.6103713769916332 Volts
    Pacs_BOLC_SET_VH_G4(1.6103713769916332);
    // Set group 4 bol bias 02 (VL) to -0.1896286230083667 Volts
    Pacs_BOLC_SET_VL_G4(-0.1896286230083667);
    // Set group 4 bol bias 03 (VRL) to 0.38763171869999546 Volts
    Pacs_BOLC_SET_VRL_G4(0.38763171869999546);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9952001524800798 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9952001524800798);
    // Set group 5 bol bias 01 (VH) to 1.320583197395035 Volts
    Pacs_BOLC_SET_VH_G5(1.320583197395035);
    // Set group 5 bol bias 02 (VL) to -0.07941680260496485 Volts
    Pacs_BOLC_SET_VL_G5(-0.07941680260496485);
    // Set group 5 bol bias 03 (VRL) to 0.4116095244710064 Volts
    Pacs_BOLC_SET_VRL_G5(0.4116095244710064);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055742088043621 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055742088043621);
    // Set group 6 bol bias 01 (VH) to 1.3562697990163495 Volts
    Pacs_BOLC_SET_VH_G6(1.3562697990163495);
    // Set group 6 bol bias 02 (VL) to -0.04373020098365052 Volts
    Pacs_BOLC_SET_VL_G6(-0.04373020098365052);
    // Set group 6 bol bias 03 (VRL) to 0.43594530124025854 Volts
    Pacs_BOLC_SET_VRL_G6(0.43594530124025854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.011921670046162 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.011921670046162);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for lowFreq_noise_time seconds
    TMMarker603();
    delay(lowFreq_noise_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)blue = 2.6 Volts, (Vh-Vl)red = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2151628880310112 Volts
    Pacs_BOLC_SET_VH_G1(2.2151628880310112);
    // Set group 1 bol bias 02 (VL) to -0.3848371119689889 Volts
    Pacs_BOLC_SET_VL_G1(-0.3848371119689889);
    // Set group 1 bol bias 03 (VRL) to 0.41342338183313837 Volts
    Pacs_BOLC_SET_VRL_G1(0.41342338183313837);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0193446104924915 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0193446104924915);
    // Set group 2 bol bias 01 (VH) to 2.1588489399994213 Volts
    Pacs_BOLC_SET_VH_G2(2.1588489399994213);
    // Set group 2 bol bias 02 (VL) to -0.4411510600005787 Volts
    Pacs_BOLC_SET_VL_G2(-0.4411510600005787);
    // Set group 2 bol bias 03 (VRL) to 0.3838811209851186 Volts
    Pacs_BOLC_SET_VRL_G2(0.3838811209851186);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9682559687629309 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9682559687629309);
    // Set group 3 bol bias 01 (VH) to 2.1867239063317037 Volts
    Pacs_BOLC_SET_VH_G3(2.1867239063317037);
    // Set group 3 bol bias 02 (VL) to -0.4132760936682966 Volts
    Pacs_BOLC_SET_VL_G3(-0.4132760936682966);
    // Set group 3 bol bias 03 (VRL) to 0.4136603871411812 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136603871411812);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9973179392427267 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9973179392427267);
    // Set group 4 bol bias 01 (VH) to 2.20827452044462 Volts
    Pacs_BOLC_SET_VH_G4(2.20827452044462);
    // Set group 4 bol bias 02 (VL) to -0.39172547955538 Volts
    Pacs_BOLC_SET_VL_G4(-0.39172547955538);
    // Set group 4 bol bias 03 (VRL) to 0.4039414339062088 Volts
    Pacs_BOLC_SET_VRL_G4(0.4039414339062088);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.011301244644244 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.011301244644244);
    // Set group 5 bol bias 01 (VH) to 1.7079035410760286 Volts
    Pacs_BOLC_SET_VH_G5(1.7079035410760286);
    // Set group 5 bol bias 02 (VL) to -0.29209645892397146 Volts
    Pacs_BOLC_SET_VL_G5(-0.29209645892397146);
    // Set group 5 bol bias 03 (VRL) to 0.405804322083024 Volts
    Pacs_BOLC_SET_VRL_G5(0.405804322083024);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0499861292550787 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0499861292550787);
    // Set group 6 bol bias 01 (VH) to 1.7476622867412348 Volts
    Pacs_BOLC_SET_VH_G6(1.7476622867412348);
    // Set group 6 bol bias 02 (VL) to -0.2523377132587652 Volts
    Pacs_BOLC_SET_VL_G6(-0.2523377132587652);
    // Set group 6 bol bias 03 (VRL) to 0.429562228366719 Volts
    Pacs_BOLC_SET_VRL_G6(0.429562228366719);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.005532468489443 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.005532468489443);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for lowFreq_noise_time seconds
    TMMarker603();
    delay(lowFreq_noise_time);
    TMMarker600();
    //
    //*********************************
    // Apply the old sequencer setting
    //*********************************
    //
    PACS_Phot_Sequencer_Setup();
    //
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose 
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//- Test of internal calibration recipes including different chopper
//  frequencies photometry including time constants for flux changes
//  (just between the 2 CSs)
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//                  
//                 
//
// TCL author    : TM
// TCL file      : TM
// CUS author    : TM
// Script file   : PHOT_timeconst_fluxchange_OBS.txt 
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name      Default      Description
//                  
// Dependencies  : 
//
// Preconditions : BOLO_recycle and PHOT_setup have been executed
//                 
// Comments      : 
// 
// Version	 : 1.0
// History       : 0.1 27-apr-2005 DAC
//                 0.4 26-apr-2005 DAC Use PACS_spu_reset
//                 0.5  4-nov-2005 DAC Added 1 sec to the wait after DMC load (from 2 to 3 sec)
//                 0.6 11-apr-2007 update by TM (OBCPs, 40Hz, ....)
//		   1.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
obs PacsEng_Phot_timeconst_fluxchange {
    /* Needed variables to call PacsEng_Phot_timeconst_fluxchange                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_timeconst_fluxchange                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Phot_timeconst_fluxchange()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Phot_timeconst_fluxchange();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose       : Move Grat Abs
//
// CUS author    : Pierre Royer
//
//
// Version       : 2.0
// History       : 1.0 29-Jul-2007
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
//
obs PacsEng_Spec_Gra_IST_Enable {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Enable                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_Enable                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Spec_Gra_IST_Enable()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Spec_Gra_IST_Enable();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : 
//
// Purpose       : Move the PHOT filter wheel to one of the two defined
//                 positions
//                  
// TCL script    : N/A
// CUS script    : Diego A. Cesarsky
//
// CVS file      : Pacs_PHOT_fltw_move.txt 
//
// Arguments     : 
// Type    Name      DefVal  Description
// string  flt_id    POS A   One of two preset positions [POS A, POS B]
//
// Description   : Switch ON filter controller, move wheel, switch OFF
//                  
// Dependencies  : Low level PACS TCs
//
// Preconditions : Servo loop already configured
//                 
// Comments      : useless comment by Bart
//                        Quite useless indeed!
//
// Version       : 0.1 13-Aug-2004 Creation by DAC
// History       : 0.1 Cloned from PHOT_fltw_move
// 
// 
int block Pacs_PHOT_fltw_move PACS 216 {
    string filter_id = "POS A" in ["POS A","POS B"];
}{
    // Register start of BB
    WriteBBID($BBID);
    // Get the duration of the move
    int move_time = iceil(dlookup("PACSparams","fltw_time","freq_time"));
    // Same in [sec]
    int move_time_sec = Msec2sec(move_time);
    //  debug_print("PHOT fltw moves to " + filter_id + 
    //              "; " + move_time_sec + " [sec]");
    // Set the filter wheel: switch on the filter/grating controller
    Pacs_DMC_SWON_FW_PHOTO();
    // Move filter to desired position 
    Pacs_DMC_MOVE_PHOT_FW_LOC(filter_id);
    // Wait move_time_sec sec for wheel to end its movement
    delay(move_time_sec);
    // Switch off the controller
    Pacs_DMC_SWOF_GRAT_CONT();
    // Return duration
    //Reset Block ID
    WriteEndBB();

    return move_time_sec;
}

/////////////////////////////////////////////////////////////////////////////
// $Id
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsLineSpec_PV AOT
//
// CUS author    : DAC
//
// Input arguments: see after module identification
//
// Return values
// {int,int,int} {totalDuration,slewDuration,obsOverPACSandSC}
//
// Comments      : If this file is called PacsLineSpecObs.def, it is the 
//                 CUSGUI version. To use with HSPOT:
//                 - copy and rename PacsLineSpec.def
//                 - rename obs module to PacsLineSpec
//                 - remove extra code for CUSGUI
//                 - do not forget to set verbose = false !!
//
// History: 
// 25-apr-2007 14.0 For earlier history see v1.37 in CVS
//                  Removed history up to today
// 22-may-2007 14.1 SPR-3199 Return only SRC+REF time
// 29-may-2007 14.2 SPR-3237 Use map orientation parameter
// 11-jun-2007 14.3 Count WAIT=1 for grating in OBCP22 as SRC/REF
// 20-sep-2007 14.4 SCR-3552. Correct pattnod with skewCorrec in PACSyzoffsets
// 15-oct-2007 15.0 SCR-3691
//                  Add state=4 (OFF) in the StateMachine logic. Ready to
//                  implement raster with OFF for pointing 21 & 31
// 22-oct-2007 15.1 FreqSwitch only allowed with source="large"
//                  Introduce RAoff DECoff as in PacsRange
// 23-oct-2007 15.2 UserNodCycles is now a rasterRepeat factor for
//                  FreqSwitch (it was a cycle repeater)
// 16-dec-2007 15.3 SPR-3830 (RAoff,DECoff out of boundaries)
// 14-jan-2008 16.0 Use standard names for RA,DEC
// 13-may-2008 17.0 SCR-3699 Implemented raoff and decoff refSelected 
// 17-nov-2008 18.0 SCR 5473 Removed redshift parameters: taken into account by HSpot
// 	       	    add nb_grat_steps
//		    modify grat_step into grat_step_size for clarity
// 18-nov-2008 19.0 SCR 5473 "switch_dither_step_size" added (RV)
// 17-feb-2009 20.0 VD SPR6074 added Bias_r/d set-up
// 19-feb-2009 21.0 VD: implemetation of the new ABBA grating scan OBCP32 implementation
// 	       	    REF1 NOT REF2 OBCP32_PV
// 	       	    
// 	       	    
// 11-mar-20098 22.0 VD implementation of ABBA CHOPPER pattern OBCP35
// 12-mar-2009	23.0 VD implement ABBA chop in Calibration
// 18-mar-2009 23.0 BV correct XY nodding dwell time (off raster time)
// 24-mar-2009 24.0 VD re-implement "std AOT ABBA for wavelength switching
// 25-mar-2009 25.9 VD bugg and UseCal bla in th right OBCP tuple position(WAVELOOP==0)
// 26-mar-2009 26.0 VD From debugged XY stage version
// 22-apr-2009 27.0 VD: SPR 5447 added selection KeyWave as fnct of filter+order
// 23-apr-2009 28.0 VD SPR 6482
// 02-jul-2009 29.0 VD modified HSpot interface for User's friendly
// 	       	       parameters override
// 03-aug-2009 29.0 VD SPR: PHS-1133, logic interferences between nb_SRC_OFF and nb_CS1_CS2
//                     Change on some Hspot names?
// 07-sep-2009 31.0 VD PHS-1149
// 20-oct-2009 32.0 VD PHS-1225 & PHS-1221
//                     Problematics
// 27-oct-2009 33.0 VD PHS-1226 enable BOTH SPU channels. disable PHS-1118
// 06-nov-2009 34.0 VD PHS-1243 ... override grat_start_pos
// 09-nov-2009 35.0 VD PHS-1246 add mapRasterAngle  to patt angle
// 12-nov-2009 36.0 VD CCB 12-11-2009: comment out PHS-1243
// xx-nov-2009 37.0 VD PHS-193
// 24-nov-2009 38.0 VD PHS-1243 de-comment PHS-1243 for testing and consolidation
// 24-nov-2009 39.0 VD PHS-1264 change bands
// 24-nov-2009 40.0 VD PHS-193 & BV comments (THX)
// 14-jan-2010 41.0 VD latest from PHS-193
// 
{int,int,int} obs PacsCal_PacsLineSpec_PV {
    /* "lines" is defined as an array; its elements (and hence its dimension) */
    /*  are provided by HSPOT */
    /* {id,redshifted wavelength,repeat factor,line flux,continuum flux,      */
    /*  line width,line flux unit,line width unit}                            */
    {string,double,int,double,double,double,string,string}[] lines = []; //Filled by HSPOT
    /*------------- following only to use CUS interface -------------------------*/
    string[] lineId = ["My lines"];
    double[] lWave = [82.0]; // line wavelength  in [55.0,210.0]
    int[] repeatLine = [1]; // repeat line in [0,10]
    double[] lineFlux = [111.0]; // Line Flux in [0.0,10000.0]
    double[] lcontFlux = [111.11]; // Continuum flux  in [0.0,10000.0]
    double[] lineWidth = [30.0];
    string[] fluxUnit = ["Jy/m2"];
    string[] widthUnit = ["kms"];
    /*------------- above only to use CUS interface -------------------------*/
    string choppedOBCPxx = "OBCP35" in ["OBCP27","OBCP35"];
    int userNODcycles = 1 in [1,100];
    string orderSel = "order2" in ["order2","order3"];
    bool overrideOBCPparams = false;
    /*     bool useScanParam = false; // Overwrite cal-u values for the scan parameters */
    int nb_SRC_OFF = 1; // scan parameter: (SRC_OFF)chop cycles per grating position
    int nb_ramps_plateau = 2; // scan parameter: ramps per chopper plateau 
    int nb_up_down = 1; // scan parameters: nb_up_down cycle
    /* bool useGratParams */
    bool overrideGratparams = false;
    int grat_step_size = 1200; // scan OBCP parameter: grating step size (to center the line, use negative step size)
    int nb_grat_steps = 148; // scan OBCP parameter: nb of grating steps
    /*    bool useCalblockParam = false; // overwrite cal-u values for the calibration block parameters */
    bool overrideCalBlockOBCP35params = false;
    int cb_nb_up_down = 1; // Cal Block: up_down cycle   
    int cb_nb_ramps_plateau = 2; // Cal Block : number of ramps per chopper plateau
    int cb_nb_CS1_CS2 = 1; // Cal Block: (CS1_CS2) chop cycles per grating position
    /* bool override grating params for calblock */
    bool overrideGratSPEC_BAND_paramsCalBlock = false;
    int cb_nb_grat_step = 16; // cal block : number of grating steps around key wavelength
    int cb_grat_step_size = 168; // cal block : grating step size (to center the line, use negative step size)
    /* bool override SPU in CalBlock */
    bool overrideDefaultsCONF_SPEC_param_SPU = false;
    int nbRdoutRamp_red = 64; // cal block: red readouts per ramp
    int nbRdoutRamp_blu = 64; // cal block: blue readouts per ramp   
    int rdouts_subramp_blu = 16; // detector setting: blue number of readouts per subramp 
    int rdouts_subramp_red = 16; // detector setting: red number of readouts per subramp
    int compression_mode_red = 16; // compression mode in red channel
    int compression_mode_blu = 16; // compression mode is blue channel
    int glitch_det_red = 1; // glitch detection algor. for red channel
    int glitch_det_blu = 1; // glitch detection algo. for the blue channel
    int nb_raw_red = 3; // nb of raw pixels used in red channel
    int nb_raw_blu = 3; // nb of raw pixlels used in blue channel
    string reduction_mode = "ramp average" in ["ramp average","ramp fitting"]; // detector setting: spu reduction mode
    /*    bool useBiasParam = false; // Overwrite the detectors BIAS values */
    bool overrideDefaultsCONF_SPEC_param_CRE = false;
    int capaBlue = 0; // detector setting: capacitance blue  in [0,8,4,12]
    int capaRed = 0; // detector setting: capacitance red  in [0,8,4,12]
    double bias_d_blu = 0.2101 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    double bias_d_red = 0.0701 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_r_blu = 0.0101; // Bias "r" blue
    double bias_r_red = 0.0101; // Bias "b" red
    /* override ALL SPU CRE params */
    bool overrideAll_SPU_CRE_params = false; // do you want allow overriding ALL SPU CRE parameters?
    string scenario = "none"; // scenario name: usage in CONF_SPEC_param rows: scenario_Normal0RED/BLU
    /*    bool useWaveSwitchParam = false; // overwrite cal-u values for wavelength switching */
    bool overrideOBCP32param = false;
    int switch_nb_ramps = 1; // P6 wave switching: number of ramps per grating position
    int switch_nb_up_dn = 1; // P1 wave switching: number of up_dn cycles
    int switch_nbABBA = 3; // P4 wave switching: number of ABBA cyles
    int switch_ditherCount = 11; // P2  wave switching: number of grating dither steps
    int switch_dither_step_size = 300; // P3 wave switching: dithering step size
    int switch_param7 = 700; // P#7
    bool chopNod = true;
    bool faintLines = true;
    int nload = 0; // cal block : repeat calibration block every n nod / raster slews   
    double chopAvoidFrom = 0.0 in [0.0,360.0];
    double chopAvoidTo = 0.0 in [0.0,360.0];
    string throw = "large" in ["large","medium","small"];
    string source = "point" in ["point","dithered","large","large_b"];
    double mapRasterAngle = 0.0 in [0.0,360.0];
    int m = 3 in [2,32];
    int n = 3 in [1,32];
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    bool refSelected = false;
    double raoff = 0.0 in [0.0,360.0];
    double decoff = 0.0 in [-90.0,90.0];
    int naifid = 0; // RA,DEC or SSO
    double pointStep = 20.0 in [2.0,480.0];
    double lineStep = 20.0 in [2.0,480.0];
    int knod = 1; // knod in [1,m*n] 
    int obsOverhead = 180; // Slew overhead
    bool startAtOFF = false;
    bool verbose = true;
}{
    //*--------- following only when using CUS interface -------------------*/
    int linesIdLength = length(lineId);
    int linesLength = length(lines);
    if(linesLength == 0) {
        for(int lLoop00 = 0 .. linesIdLength - 1) {
            lines[lLoop00] = {lineId[lLoop00],lWave[lLoop00],repeatLine[lLoop00],lineFlux[lLoop00],lcontFlux[lLoop00],lineWidth[lLoop00],fluxUnit[lLoop00],widthUnit[lLoop00]};
        }
    }
    //*--------- above only when using CUS interface -------------------*/
    // starting catching conflicts
    if(overrideDefaultsCONF_SPEC_param_SPU && overrideAll_SPU_CRE_params) {
        error("Attention conflicting overriding parameters, Defaults wil override the scenario's setup, choose either: ALL or Defaults");
    }
    if(overrideDefaultsCONF_SPEC_param_CRE && overrideAll_SPU_CRE_params) {
        error("Attention conflicting overriding parameters, Defaults will override the scenario's setup, choose either: ALL or Defaults");
    }
    //PHS-1226
    bool stopUnUsedChannelSPU = false;
    // stop the unused SPU chanel?   
    //*-----------------------------------------------------------------*/
    // Start of "Pointing" section
    // 
    // extraConf: whatever affects PACS default configuration 
    // Currently: the option faintLines calls for an extraConf
    string extraConf = "normal";
    // For bright lines
    if(!faintLines && chopNod) {
        extraConf = "bright";
    } else {
        extraConf = "normal";
    }
    int nbLines = length(lines);
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // Need switching boolean
    bool switching = !chopNod;
    // Switching only allowed with source "large"
    if(switching && source != "large") {
        if(switching && source != "large_b") {
            error("Frequency Switch only in mode raster (large source) with OFF");
        }
    }
    // Decode more HSPOT information
    //    int nbLines = length(lines);
    int nbLines1 = nbLines - 1;
    // Cannot call with empty "lines"
    if(nbLines == 0) {
        error("STOP!! There are no spectral lines defined!");
    }
    // No more than 10 lines or repetitions
    int nbLinesRep = 0;
    for(int loop00 = 0 .. nbLines - 1) {
        //  Default repetion factor is 1
        int repFactor = lines[loop00]{2};
        if(repFactor == 0) {
            repFactor = 1;
        }
        nbLinesRep = nbLinesRep + repFactor;
    }
    if(verbose) {
        debug_print("Total lines/repeat: " + nbLinesRep);
    }
    if(nbLinesRep > 10) {
        error("STOP!! The number of lines/repetitions exceeds 10");
    }
    // Establish now the applicable Pointing Mode (use same pointCase convention
    // used in PacsPhoto)
    // Pointing mode is undefined. If it remains undefined at the end of
    // the next tests, then there is a problem with the source definition
    int pointCase = 0;
    // FinePointingMode with setup time
    // POINT source, with and without chopNod
    if(source == "point") {
        //    For completiness define a 1x1 raster
        m = 1;
        n = 1;
        //    without nodding
        if(!chopNod) {
            string pointMode = "fine_pointing";
            string userMode = "Point source (no nodding)";
            if(switching) {
                userMode = "Point source (frequency switch, no nodding)";
            }
            pointCase = 11;
            string yzoffsetROW = "S" + pointCase;
        } else {
            //    with nodding      
            pointMode = "composite_nodding";
            userMode = "Point source (nodding)";
            pointCase = 12;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // DITHERED source
    // For source "dithered" use predetermined raster parameters
    if(source == "dithered") {
        m = ilookup("SMALL_SRC_params","SPEC","mRast");
        n = ilookup("SMALL_SRC_params","SPEC","nRast");
        pointStep = dlookup("SMALL_SRC_params","SPEC","pointStep");
        lineStep = dlookup("SMALL_SRC_params","SPEC","lineStep");
        //    Raster mode without noding
        if(!chopNod) {
            pointMode = "repeated_raster_with_hold";
            userMode = "Small source (no nodding)";
            pointCase = 21;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Small source (nodding)";
            pointCase = 22;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For source "large" user given raster parameters
    if(source == "large") {
        //    Raster mode without noding
        if(!chopNod) {
            pointMode = "repeated_raster_with_hold";
            userMode = "Large source (no nodding)";
            pointCase = 31;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_in_raster";
            userMode = "Large source (nodding)";
            pointCase = 32;
            yzoffsetROW = "S" + pointCase;
        }
    }
    if(source == "large_b") {
        //    Raster mode without noding
        if(!chopNod) {
            pointMode = "raster_pointing";
            userMode = "Large source (raster w/OFF, no nodding)";
            pointCase = 31;
            yzoffsetROW = "S" + pointCase;
        } else {
            //      with nodding
            pointMode = "nodding_of_raster";
            userMode = "Large source (nodding)";
            pointCase = 32;
            yzoffsetROW = "S" + pointCase;
        }
    }
    // For symmetrical chopping, virtual apertures are dependent on the chopper
    // throw. Add this information to the CALU key entry
    yzoffsetROW = throw + "" + yzoffsetROW;
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("     PointCase ID: " + pointCase);
        debug_print("     PointMode   : " + pointMode);
        debug_print("     CALU entry  : " + yzoffsetROW);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        for(int iii = 0 .. nbLines1) {
            debug_print("MAIN:Id, Wave, repeat, Lflux, Cflux, etc. " + lines[iii]);
        }
    }
    // Define array of wavelengths (will be needed by the SORT procedure)
    double[] lineWave = [55.0];
    // Populate the array of wavelengths
    for(int loop0 = 0 .. nbLines1) {
        lineWave[loop0] = lines[loop0]{1};
    }
    // For each line obtain the grating order and the grating position 
    int[] orders = [0];
    // !!this is starting gart pos for OBCP27/35 so it includes the ( + nbStep*stepSize/2.0 increment) because we start by
    // scanning DOWNward ... // line_pos for OBCP32
    double[] grat_pos = [0.0];
    // Fill the tuple waveTuple {waveLen,order,gratPos,nbStep,gratStep}
    {double,int,int,int,int}[] waveTuple = [{0.0,0,0,0,0}];
    for(int loop1 = 0 .. nbLines1) {
        waveTuple[loop1] = SPEC_get_grat_info(lineWave[loop1],"HI",switching,extraConf,orderSel,verbose);
        //      Create vector of intermediate results
        //  !!! stepSize has changed SIGN!
        // 
        orders[loop1] = waveTuple[loop1]{1};
        grat_pos[loop1] = double(waveTuple[loop1]{2});
    }
    // To reject forbidden order combination, count how many orders
    int nORDER1 = 0;
    int nORDER2 = 0;
    int nORDER3 = 0;
    for(int loop2 = 0 .. nbLines1) {
        if(orders[loop2] == 1) {
            nORDER1 = nORDER1 + 1;
        }
        if(orders[loop2] == 2) {
            nORDER2 = nORDER2 + 1;
        }
        if(orders[loop2] == 3) {
            nORDER3 = nORDER3 + 1;
        }
    }
    // Reject mixed orders
    if(nORDER2 != 0 && nORDER3 != 0) {
        //    Report band limits
        double[] band2 = SPEC_BAND_read("L2");
        double[] band3 = SPEC_BAND_read("L3");
        error("Combination of 2nd (" + band2[0] + "-" + band2[1] + " mic) and 3rd (" + band3[0] + "-" + band3[1] + " mic) grating orders is not allowed");
    }
    // Reject lines not belonging to authorized order
    if(nORDER2 != 0 && orderSel == "order3") {
        error("You have chosen " + orderSel + " but have specified one/several order2 lines");
    }
    if(nORDER3 != 0 && orderSel == "order2") {
        error("You have chosen " + orderSel + " but have specified one/several order3 lines");
    }
    // Determine the filter needed with given lines
    // No filter needed, i.e. ORDER=1
    int filter = 1;
    // Determine filter based on HSPOT input
    if(orderSel == "order2") {
        filter = 2;
    }
    if(orderSel == "order3") {
        filter = 3;
    }
    if(verbose) {
        debug_print("ORDER array: " + orders);
    }
    // Filter below will be set by SPEC_aot_prologue via SlewCal
    if(verbose) {
        debug_print("MAIN:The full OBS will be performed with filter " + filter);
    }
    // Sort grat_pos from smallest to largest
    int[] sortIndex = SortProc(verbose,grat_pos);
    // Sort by wavelengths (from blue to red)
    // int sortIndex = SortProc(verbose,lineWave);
    // Recast "lines" and waveTuple according to the ordered grating positions
    {string,double,int,double,double,double,string,string}[] sortLines = [{"empty",0.0,0,0.0,0.0,0.0,"bla","bla"}];
    {double,int,int,int,int}[] sortWaveTuple = [{0.0,0,0,0,0}];
    for(int reSORT = 0 .. nbLines1) {
        //      Reversed sort
        // No reverse SORT (start observations with filter A)
        //        int revSORT         = nbLines1 - reSORT;
        int revSORT = reSORT;
        int sortedIndex = sortIndex[revSORT];
        sortLines[reSORT] = lines[sortedIndex];
        sortWaveTuple[reSORT] = waveTuple[sortedIndex];
        if(verbose) {
            debug_print("Sorted Line: " + sortLines[reSORT]);
        }
    }
    // The tuple arrays confOBCP, confSPECred, and confSPECblu play a major
    // role. They contain the parameters related to commanding different PACS
    // subsystems. They are susceptible of changing with the observing conditions.
    // Hence, they have to be watched for changes since these imply sending one or
    // more TCs (usually invoking a building block)
    // Define confOBCP array
    // confOBCP{0 -> 19} contains:
    // nb_up_down       grat_step_up     grat_step_dn     nb_SRC_OFF     
    // nb_ramps_plateau nb_CS1_CS2       nb_grat_step_up  nb_grat_step_dn
    // grat_start_pos   grat_start_time  grat_def_pos     grat_def_time 
    // chop_pos_SRC     chop_pos_REF1    chop_pos_REF2    chop_pos_CS1
    // chop_pos_CS2     chop_def         detector         order
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // a very long confSPEC/red/blu/SPU tuple ... 
    // Define confSPECblu and confSPECred
    // confSPEC contians:
    //   capa,       nb_rdouts_ramp, nb_rdouts_subramp, comp_mode,
    //   glitch_det, ramp_fit_alg,   nb_raw,            bias_r,    bias_d
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    // Estimator module returns {confSPECblu,confSPECred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {clone(confSPECblu[0]),clone(confSPECred[0]),clone(confOBCP[0])};
    // Obtain default values
    string throwUsage = throw;
    // Frequency switch parameters are as for offraster in PacsRange
    // REF1 is not set to be equal to REF2 (relevant OBCP 32)
    if(switching) {
        throwUsage = "offraster";
    }
    if(verbose) {
        debug_print("PacsLine:Use throw: " + throwUsage);
    }
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    double[] refWL = [sortLines[0]{1}];
    double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    double[] keyWAVE = [keyWL];
    // gniark complicated --- do I update PacsSpecdefaults .. I don't want a LONG tuple ... just a scenario
    //  !!! detecor too
    // IMPORTANT NOTE
    //---------------
    // Logic to stop the "non-prime" channel. This is the channel not used by 
    // the KeyWave, making also sure that detector sync follows
    // 
    // re-enable both channels PHS-1221
    // 
    // bool stopSPUS = false;
    // bool stopSPUL = false;
    // Channel selection
    if(keyWAVE[0] > 100.0) {
        //        stopSPUS = true;
        int detector = 2;
    }
    if(keyWAVE[0] < 100.0) {
        //        stopSPUL = true;
        detector = 1;
    }
    if(overrideAll_SPU_CRE_params) {
        //        paramsSPECdef = PacsSpecDefaultsSPU(throwUsage,extraConf,detector,stopUnUsedChannelSPU,scenario,verbose);
        //        PHS-1226
        paramsSPECdef = PacsSpecDefaultsSPU(throwUsage,extraConf,scenario,verbose);
    } else {
        //    paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,detector,verbose);
        paramsSPECdef = PacsSpecDefaults(throwUsage,extraConf,verbose);
    }
    confSPECblu[0] = paramsSPECdef{0};
    confSPECred[0] = paramsSPECdef{1};
    confOBCP[0] = paramsSPECdef{2};
    // PHS-193.... add extra proc for ChangeCapa as function of input signal Line+Cont+telBckgd wrt to saturation limits
    // for the moment keep at obs level ... may move to PacsSpecDefaults or PacsSpecSlewCal???
    // simple logic based on KEY wave to select table ... otherwise:
    // based on wave and orderSel ( wave >< 103.1) can come later then 2 maxV and maxSignal and capa based on maxSignalB and maxSignalR
    // 
    // 
    // 
    // 
    {int,double,double,double,double,string,double,string}[] forCapaSwitch = [{0,0.0,0.0,0.0,0.0,"",0.0,""}];
    for(int loopXY = 0 .. nbLines - 1) {
        forCapaSwitch[loopXY] = {confSPECblu[0]{0},lines[loopXY]{1},lines[loopXY]{3},lines[loopXY]{4},lines[loopXY]{5},lines[loopXY]{7},keyWAVE[0],orderSel};
        //      debug_print("forCapaSwitch: " +forCapaSwitch[loopXY]);
    }
    {bool,int} switchCapa = PacsSpecSwitchCapa(forCapaSwitch);
    if(switchCapa{0}) {
        debug_print("switchCapa{1}:" + switchCapa{1});
        message("<h1> Attention!! </h1>");
        message("<p>The Capacitance has changed due to high flux density (line and/or continuum) </p>");
        message("<p> <please contact Helpdesk </p>");
        confSPECblu[0]{0} = switchCapa{1};
        confSPECred[0]{0} = switchCapa{1};
    }
    // END of change capa code!
    // 
    //    confOBCP[0]{18} = detector;
    // Here comes the module(s) to estimate OBS times as a function of the
    // input given by the HSPOT user.
    //Define tuple to contain the "variable" parameters
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPEC = clone(paramsSPECdef);
    // paramsSPECext (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,nb_up_dn,aux1,aux2}
    // More info: {nb_nods,nb_up_dn,timeOBS,aux2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsSPECext = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for each wavelength. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("MAIN.confOBCP[0]: " + confOBCP[0]);
    }
    int nbNods = 0;
    // Accumulator total OBS time
    int totalOBS = 0;
    int[] gratStartPos = [0];
    int[] opti_gratPos = [0];
    // For each demanded wavelength compute minimum duration
    for(int waveLOOP = 1 .. nbLines) {
        int waveLOOP1 = waveLOOP - 1;
        //    Different OBCPs if frequency switch or not
        if(chopNod) {
            // Here we perform nodding/chopping
            // SCR-2942: consider case of faintLines = false
            string forDEBUG = "chop/nod";
            if(choppedOBCPxx == "OBCP35") {
                // implement OBCP35 for test indem OBCP27 carefull OBCPconf parameters order
                paramsSPECext = PacsLineSpecEstimatorOBCP35(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,chopNod,faintLines,verbose);
            } else {
                if(choppedOBCPxx == "OBCP27") {
                    paramsSPECext = PacsLineSpecEstimatorOBCP27(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,chopNod,faintLines,verbose);
                }
            }
            //      Copy estimates to respective tuples
            confSPECblu[waveLOOP] = paramsSPECext{0};
            confSPECred[waveLOOP] = paramsSPECext{1};
            confOBCP[waveLOOP] = paramsSPECext{2};
            //          confOBCP[waveLOOP]{18} = detector;
            if(overrideOBCPparams) {
                confOBCP[waveLOOP]{0} = nb_up_down;
                confOBCP[waveLOOP]{3} = nb_SRC_OFF;
                confOBCP[waveLOOP]{4} = nb_ramps_plateau;
            }
            if(overrideGratparams) {
                confOBCP[waveLOOP]{1} = grat_step_size;
                confOBCP[waveLOOP]{2} = -grat_step_size;
                confOBCP[waveLOOP]{6} = nb_grat_steps;
                confOBCP[waveLOOP]{7} = nb_grat_steps;
                // CCB 12-11-2009 pending
                // compute gratStartPos
                // recover optimum grat pos
                // !!! stepSize deom SPEC_get_grat_info is NEG!
                opti_gratPos[waveLOOP1] = waveTuple[waveLOOP1]{2} + iround(double(waveTuple[waveLOOP1]{4}) * double(waveTuple[waveLOOP1]{3}) / 2.0);
                if(verbose) {
                    debug_print("back to gratPos/old_step/old_size: " + opti_gratPos + "//" + waveTuple[waveLOOP1]{3} + "//" + waveTuple[waveLOOP1]{4});
                }
                //                // make sure we follow the right logic
                if(nb_grat_steps < 0) {
                    gratStartPos[waveLOOP1] = opti_gratPos[waveLOOP1] - iround(double(grat_step_size) * double(nb_grat_steps) / 2.0);
                    confOBCP[waveLOOP]{1} = grat_step_size;
                    confOBCP[waveLOOP]{2} = -grat_step_size;
                    confOBCP[waveLOOP]{6} = nb_grat_steps;
                    confOBCP[waveLOOP]{7} = nb_grat_steps;
                    if(verbose) {
                        debug_print("gratStartPos: " + gratStartPos + "... we start going UP and then Down");
                    }
                } else {
                    gratStartPos[waveLOOP1] = opti_gratPos[waveLOOP1] + iround(double(grat_step_size) * double(nb_grat_steps) / 2.0);
                    confOBCP[waveLOOP]{1} = -grat_step_size;
                    confOBCP[waveLOOP]{2} = grat_step_size;
                    confOBCP[waveLOOP]{6} = nb_grat_steps;
                    confOBCP[waveLOOP]{7} = nb_grat_steps;
                    if(verbose) {
                        debug_print("gratStartPos: " + gratStartPos + " .... we start Down and then Up");
                    }
                }
                confOBCP[waveLOOP]{8} = gratStartPos[waveLOOP1];
            }
        } else {
            // Here we perform frequency switching
            forDEBUG = "freq/switch";
            // SPR-2926: Use userNODcycles as overall multiplier for repeatLine
            // No longer true with raster+OFF; repeat raster instead
            paramsSPECext = PacsLineSpecEstimatorOBCP32(sortLines[waveLOOP1],sortWaveTuple[waveLOOP1],paramsSPEC,verbose);
            //      Copy estimates to respective tuples
            confSPECblu[waveLOOP] = paramsSPECext{0};
            confSPECred[waveLOOP] = paramsSPECext{1};
            confOBCP[waveLOOP] = paramsSPECext{2};
            //        confOBCP[waveLOOP]{18} = detector;
            if(overrideOBCP32param) {
                confOBCP[waveLOOP]{1} = switch_param7;
                confOBCP[waveLOOP]{2} = switch_nbABBA;
                confOBCP[waveLOOP]{4} = switch_nb_ramps;
                confOBCP[waveLOOP]{0} = userNODcycles * switch_nb_up_dn;
                confOBCP[waveLOOP]{6} = switch_ditherCount;
                confOBCP[waveLOOP]{7} = switch_ditherCount;
                confOBCP[waveLOOP]{9} = switch_dither_step_size;
            }
        }
        if(overrideCalBlockOBCP35params) {
            confOBCP[0]{0} = cb_nb_up_down;
            confOBCP[0]{5} = cb_nb_CS1_CS2;
            confOBCP[0]{4} = cb_nb_ramps_plateau;
        }
        if(overrideGratSPEC_BAND_paramsCalBlock) {
            confOBCP[0]{6} = cb_nb_grat_step;
            confOBCP[0]{7} = cb_nb_grat_step;
            confOBCP[0]{1} = -cb_grat_step_size;
            confOBCP[0]{2} = cb_grat_step_size;
        }
        // Warning complicated !!!!	   
        if(overrideDefaultsCONF_SPEC_param_SPU) {
            // here comes the SPU and CRE setup: calibration block
            confSPECblu[0]{1} = nbRdoutRamp_blu;
            confSPECred[0]{1} = nbRdoutRamp_red;
            confSPECred[0]{2} = rdouts_subramp_blu;
            confSPECblu[0]{2} = rdouts_subramp_red;
            confSPECred[0]{3} = compression_mode_red;
            confSPECblu[0]{3} = compression_mode_blu;
            confSPECred[0]{4} = glitch_det_red;
            confSPECblu[0]{4} = glitch_det_blu;
            confSPECred[0]{6} = nb_raw_red;
            confSPECblu[0]{6} = nb_raw_blu;
            if(nbRdoutRamp_blu >= nbRdoutRamp_red) {
                detector = 1;
                //              confOBCP[0]{18} = detector;
            }
            if(nbRdoutRamp_blu < nbRdoutRamp_red) {
                detector = 2;
                //               confOBCP[0]{18} = detector;
            }
            // the same for SCI OBCPs
            confSPECblu[waveLOOP]{1} = nbRdoutRamp_blu;
            confSPECred[waveLOOP]{1} = nbRdoutRamp_red;
            confSPECred[waveLOOP]{2} = rdouts_subramp_blu;
            confSPECblu[waveLOOP]{2} = rdouts_subramp_red;
            confSPECred[waveLOOP]{3} = compression_mode_red;
            confSPECblu[waveLOOP]{3} = compression_mode_blu;
            confSPECred[waveLOOP]{4} = glitch_det_red;
            confSPECblu[waveLOOP]{4} = glitch_det_blu;
            confSPECred[waveLOOP]{6} = nb_raw_red;
            confSPECblu[waveLOOP]{6} = nb_raw_blu;
            if(nbRdoutRamp_blu >= nbRdoutRamp_red) {
                detector = 1;
                //              confOBCP[waveLOOP]{18} = detector;
            }
            if(nbRdoutRamp_blu < nbRdoutRamp_red) {
                detector = 2;
                //               confOBCP[waveLOOP]{18} = detector;
            }
        }
        //        if(change_capa) {
        //            confSPECred[0]{0} = capaRed;
        //            confSPECblu[0]{0} = capaBlue;
        //            confSPECred[waveLOOP]{0} = capaRed;
        //            confSPECblu[waveLOOP]{0} = capaBlue;
        //        }
        if(overrideDefaultsCONF_SPEC_param_CRE) {
            // 
            confSPECred[0]{0} = capaRed;
            confSPECblu[0]{0} = capaBlue;
            confSPECred[0]{7} = iround(1000.0 * bias_r_red);
            confSPECblu[0]{7} = iround(1000.0 * bias_r_blu);
            confSPECred[0]{8} = iround(1000.0 * bias_d_red);
            confSPECblu[0]{8} = iround(1000.0 * bias_d_blu);
            if(reduction_mode == "ramp average") {
                confSPECblu[0]{5} = 1;
                confSPECred[0]{5} = 1;
            } else {
                if(reduction_mode == "ramp fitting") {
                    confSPECred[0]{5} = 0;
                    confSPECblu[0]{5} = 0;
                }
            }
            confSPECred[waveLOOP]{0} = capaRed;
            confSPECblu[waveLOOP]{0} = capaBlue;
            confSPECred[waveLOOP]{7} = iround(1000.0 * bias_r_red);
            confSPECblu[waveLOOP]{7} = iround(1000.0 * bias_r_blu);
            confSPECred[waveLOOP]{8} = iround(1000.0 * bias_d_red);
            confSPECblu[waveLOOP]{8} = iround(1000.0 * bias_d_blu);
            if(reduction_mode == "ramp average") {
                confSPECblu[waveLOOP]{5} = 1;
                confSPECred[waveLOOP]{5} = 1;
            } else {
                if(reduction_mode == "ramp fitting") {
                    confSPECred[waveLOOP]{5} = 0;
                    confSPECblu[waveLOOP]{5} = 0;
                }
            }
        }
        //      Accumulate total OBS time
        totalOBS = totalOBS + paramsSPECext{3}{2};
        if(verbose) {
            debug_print("MAIN.confOBCP[0]: " + confOBCP[0]);
            debug_print("MAIN.Obs mode    : " + forDEBUG);
            debug_print("MAIN.Wavelength  : " + sortLines[0]{1});
            debug_print("MAIN.confOBCP[" + waveLOOP + "]: " + confOBCP[waveLOOP]);
            debug_print("MAIN.confSPEC[" + waveLOOP + "]: " + confSPECblu[waveLOOP]);
            debug_print("MAIN.confSPEC[" + waveLOOP + "]: " + confSPECred[waveLOOP]);
        }
    }
    if(verbose) {
        debug_print("MAIN.Minimum required time: " + totalOBS + " [sec]");
    }
    if(chopNod) {
        // Here we perform nodding/chopping
        nbNods = userNODcycles;
        if(verbose) {
            debug_print("MAIN.The PointReq will contain " + nbNods + " nod cycles");
        }
    } else {
        // Here we perform freq switch
        nbNods = 0;
    }
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "<p>Minimum required OBStime: " + totalOBS + " [sec]</p>";
    lineCnt = lineCnt + 1;
    int nodTotal = nbNods * totalOBS;
    if(chopNod) {
        msgLine[lineCnt] = "<p>With the specified NOD count, " + nbNods + ", the total OBS time amounts to " + nodTotal + "[sec]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Since no NOD was specified the total OBS time is equal" + " to the minimum required time. The time can be changed" + " by changing the line(s) repeat factor</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("Accumulated SRC+REF time estimation",lineCnt,msgLine);
    // Messages on general Detector/SPU parameters
    lineCnt = 0;
    msgLine[lineCnt] = "<p>Red channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECred[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    int subRamps = confSPECred[0]{1} / confSPECred[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECred[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECred[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Blue channel</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Number of readouts per ramp: " + confSPECblu[0]{1} + "</li>";
    lineCnt = lineCnt + 1;
    subRamps = confSPECblu[0]{1} / confSPECblu[0]{2};
    msgLine[lineCnt] = "<li>Number of subramps/ramp: " + subRamps + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Fitting algorithm: " + confSPECblu[0]{5} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Integration capacitor: " + confSPECblu[0]{0} + "</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "</ul>";
    lineCnt = lineCnt + 1;
    PacsMessageCenter("Selected PACS setup parameters",lineCnt,msgLine);
    //////////////////////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source
    // First operation is to set the OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // Will call PacsSpecSlewCal to perform AOT prologue and CAL during
    // slew to source. Establish an array of key wavelengths, one per order,
    // commensurate with user given wavelengths
    // MODIF: this leads to redundancy when Lines are selected both in
    // the norder+1st order: hence 1KWL per Filter: i.e. in practice 1
    // per "blue order
    //    int order4key = sortWaveTuple[0]{1};
    //    double[] refWL = [sortLines[0]{1}];
    //    string keyOrder = "order" + order4key;
    //    double keyWL = PacsSpecKeyWaves(orderSel,refWL);
    //    double[] keyWAVE = [keyWL];
    // double[] keyWAVE = PacsLineSpecKeyWaves(sortWaveTuple);
    //    int nbKeyWAVE = length(keyWAVE); == 1 
    int nbKeyWAVE = 1;
    // With current versions of CommandOBCP27 and CommandOBCP32, the grating is
    // supposed to be left by SlewCal at the position needed for the 1st line
    // The OBCPs will leave the grating at that same position
    int frstLstGratPos = confOBCP[1]{8};
    if(verbose) {
        debug_print("MAIN:SortWaveTuple: " + sortWaveTuple);
        debug_print("MAIN:keyWAVES " + keyWAVE);
        debug_print("MAIN:SlewCal should leave grating at: " + frstLstGratPos);
    }
    // To stop unused channel we need
    //    int timeToStop = duration(SPEC_spu_channel_stop(stopSPUS,stopSPUL,verbose));
    // Time needed to perform these activities during slew (includes AOT
    // prologue) ...
    bool doAOTprologue = true;
    if(overrideAll_SPU_CRE_params) {
        int timeSlewCal = duration(PacsSpecSlewCalSPU(verbose,scenario,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel));
    } else {
        timeSlewCal = duration(PacsSpecSlewCal_override(verbose,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalBlockOBCP35params));
    }
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during slew: " + timeSlewCal);
    }
    // CAL for HOLD 
    doAOTprologue = false;
    if(overrideAll_SPU_CRE_params) {
        int timeHoldCal = duration(PacsSpecSlewCalSPU(false,scenario,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,0,frstLstGratPos,orderSel));
    } else {
        timeHoldCal = duration(PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,doAOTprologue,keyWAVE,0,frstLstGratPos,orderSel,overrideCalBlockOBCP35params));
    }
    if(verbose) {
        debug_print("&&&&&&&&&&&&&&& CAL time during HOLD: " + timeHoldCal);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsSpecCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsSpecCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // IMPORTANT NOTE: the duration could be different for the first cycle through 
    // all wavelengths than for the following ones owing to differing initial state.
    // However, all steps have been taken so that PACS starts the actual observation
    // in the same state as it would be left at the end of any wavelength cycle
    // Duration of any nod leg or staring observation
    // Different OBCP for wavelength switch
    if(!switching) {
        // Here we perform nodding/chopping
        if(choppedOBCPxx == "OBCP35") {
            int timeOBS = duration(PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,verbose));
            if(verbose) {
                debug_print("Duration OBCP35: " + timeOBS + " [sec] per pointing;  nbNods: " + nbNods);
            }
        }
        if(choppedOBCPxx == "OBCP27") {
            timeOBS = duration(PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,verbose));
            if(verbose) {
                debug_print("Duration OBCP27: " + timeOBS + " [sec] per pointing;  nbNods: " + nbNods);
            }
        }
    } else {
        // Here we perform freq switch
        timeOBS = duration(PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,verbose));
        if(verbose) {
            debug_print("Duration OBCP32: " + timeOBS + " [sec] per pointing");
        }
    }
    // Get duration of module to close AOT operations
    // This includes parking the grating
    // Park position
    int grat_park = ilookup("SPEC_MEC_Defaults","Spectroscopy","grating");
    // The grating was left by OBCPs at frstLstGratPos
    int timeEpilogue = duration(SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose));
    // WriteEndID will be the last TC; get its duration
    int timeEndID = duration(WriteEndID());
    // Summary of relevant data collected so far
    // timeSlewCal: duration of the leading CAL, including AOT_prologue
    // timeOBS    : duration of a single pointed OBS
    // nb_nods    : number of nods for staring mode or per raster position
    // chopNod : invoke nodding or not (nb_nods = 0 is equivalent to no nod)
    // m, n       : raster nb_points/line, nbLines per RREQ
    // pointStep,lineStep: more raster parameters
    // ra,dec: more pointing parameters
    //
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Ready to issue a FinePointing mode with/without nodding or
    // a RasterReq with/without nodding. Either one will use time during
    // slew to perform SlewCal.
    //
    // The chopper step has been read already (PacsSpecDefaults). However,
    // there are no provisions to carry that information here. Easiest is to
    // read again the relevant CAL-U table. Read chopper position SRC and
    // REF1 [arcsec]
    // 
    // PHS-1225 decouple nod from chop throw
    // 
    double chopAngleSrc = dlookup("SPEC_CHOP_params",throw,"SRC");
    double chopAngleRef = dlookup("SPEC_CHOP_params",throw,"REF1");
    double nodAngleSrc = dlookup("SPEC_NOD_params",throw,"SRC");
    double nodAngleRef = dlookup("SPEC_NOD_params",throw,"REF1");
    // The total nodThrow = chopperTotalThrow
    double nodThrow = abs(nodAngleSrc - nodAngleRef);
    if(verbose) {
        debug_print("PacsSpecDef: CHOP/NOD params SRC/REF/NOD: " + chopAngleSrc + "/" + chopAngleRef + "/" + nodThrow);
    }
    // Issue pointing request (when possible use JBr's variable names for clarity)
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    // Virtual aperture
    string ib = "P02_0";
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("#### Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("#### skewCorrec : " + skewCorrec);
    }
    if(stopUnUsedChannelSPU) {
        int tslewmin = timeSetOBSID + timeSlewCal;
    } else {
        tslewmin = timeSetOBSID + timeSlewCal;
    }
    int tinithold = 0;
    int tfinalhold = timeEndID + timeEpilogue;
    int tp = timeOBS;
    double patt = 0.0;
    double pattnod = 270.0 + skewCorrec;
    int k = 0;
    int thold = 0;
    int nhold = 0;
    nload = 0;
    int tloadslewmin = 0;
    bool fixed = true;
    // FinePointingMode with setup time
    if(pointCase == 11) {
        //     FinePointingMode without nodding     
        int[] fromPntReq = basic_fine_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,yoffset,zoffset,tp);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        int tend = fromPntReq[2];
    }
    if(pointCase == 12) {
        //     FinePointingMode without nodding, section 3.4     
        ib = "P02_0";
        //     Nodding is specified wrt spacecraft
        fixed = false;
        //     Nodding is along y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        fromPntReq = nodding_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nbNods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tnod = fromPntReq[2];
        tss = fromPntReq[3];
        tload = fromPntReq[4];
        tend = fromPntReq[5];
    }
    if(pointCase == 21 || pointCase == 31) {
        //     RasterMode repeated_raster_with_hold_and_OFF, section 3.5
        ib = "P02_0";
        //     Raster in instrument coordinates
        fixed = false;
        double d1 = pointStep;
        double d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        patt = 0.0;
        k = 0;
        int top = 0;
        if(!switching && pointCase == 21) {
            raoff = 0.0;
            decoff = 0.0;
        }
        int nrepeat = 1;
        //     If switching for "large" source perform OFF observation
        if(switching || pointCase == 31) {
            //        Repeat raster according to userNODcycles
            nrepeat = userNODcycles;
            k = n * m;
            top = tp;
        }
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        //     SPR-3237 (map orientation parameter) applies only to raster
        if(pointCase == 31) {
            fixed = true;
            patt = mapRasterAngle;
        }
        fromPntReq = raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
        // XY-stage variables
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        tsop = fromPntReq[5];
        trep = fromPntReq[4];
        tend = fromPntReq[6];
    }
    if(pointCase == 22 || pointCase == 32 && source != "large_b") {
        //     Raster mode w/nodding, section 3.6
        ib = "P02_0";
        //     Raster in instrument coordinates
        fixed = false;
        //     Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //     Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        // PHS-1246 allows  mapRasterAngle: patt is counter-clockwise with respect to z-axis: only add mapRasterAngle
        // and forget about + 90.0, to avoid confusion on already defined AORs
        patt = mapRasterAngle;
        //     Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        k = 0;
        nrepeat = 1;
        //     New arguments for pointing request; will be dealt with next iteration
        top = 0;
        raoff = 0.0;
        decoff = 0.0;
        trepeatmin = 0;
        tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nbNods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
        tend = fromPntReq[9];
    }
    if(pointCase == 32 && source == "large_b") {
        //    Nodding of Raster, section 3.6
        ib = "P02_0";
        //   Raster in instrument coordinates
        fixed = false;
        //   Convert pixel into arcsec NOTE: ALREADY in [arcsec]
        d1 = pointStep;
        d2 = lineStep;
        //   Some variables already defined above (may need different values!)
        tinithold = 0;
        tfinalhold = timeEndID + timeEpilogue;
        // PHS-1246
        patt = mapRasterAngle;
        //   Nod parallel to y axis, opposite chopper
        pattnod = 270.0 + skewCorrec;
        //        k = m * n;
        int ncycles = userNODcycles;
        nrepeat = 1;
        tloadmin = 0;
        fromPntReq = nodding_of_raster_pointing(true,tslewmin,tinithold,tfinalhold,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,pattnod,nodThrow,ncycles,knod,nrepeat,tloadmin,nload);
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
        tend = fromPntReq[9];
    }
    // Parameters returned by PointReq
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Issue PointRequest now");
        debug_print("Return from PointReq: " + fromPntReq);
    }
    //Info from API (nomenclature from Jon Br)
    tobs = fromPntReq[0];
    tslew = fromPntReq[1];
    ///////////////////////// end of "timing" section //////////////////////////
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
        int tNOW = time();
        debug_print("=====Issued PointReq Time_now: " + tNOW);
    }
    // Issue TCs
    int[] stateVar = [0];
    int nbOBS = 0;
    int nbOFF = 0;
    while(stateVar[0] >= 0) {
        stateVar = next_state();
        if(stateVar[0] == 1) {
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW starts at: " + tNOW);
            }
            //       Write OBSID (logical part of SlewCal)
            WriteOBSID($OBSID);
            // ON TARGET SLEW
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            if(overrideAll_SPU_CRE_params) {
                int[][] calTime = PacsSpecSlewCalSPU(false,scenario,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel);
            } else {
                calTime = PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,true,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalBlockOBCP35params);
            }
            //          Stop unused SPU
            //            if(stopUnUsedChannelSPU) {
            //                SPEC_spu_channel_stop(stopSPUS,stopSPUL,verbose);
            //            }
            //       Define accumulated Cal time
            int[][] sumUpCalTime = calTime;
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW ends at: " + tNOW);
                debug_print("    SumUpCalTime: " + sumUpCalTime);
            }
        } else {
            if(stateVar[0] == 3) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== POINT starts at: " + tNOW);
                }
                //       Regular OBCP or frequency switched OBCP?
                if(!switching) {
                    if(choppedOBCPxx == "OBCP35") {
                        int[][] obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                    }
                    if(choppedOBCPxx == "OBCP27") {
                        obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                    }
                } else {
                    obsTime = PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                }
                nbOBS = nbOBS + 1;
                //       Logic to sum up obsTime
                if(nbOBS == 1) {
                    int[][] sumUpObsTime = obsTime;
                }
                if(nbOBS > 1) {
                    sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("    SumUpObsTime: " + sumUpObsTime);
                    debug_print("=== POINT ends at: " + tNOW);
                }
            } else {
                if(stateVar[0] == 4) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== OFF starts at: " + tNOW);
                    }
                    //       Regular OBCP or frequency switched OBCP?
                    if(!switching) {
                        if(choppedOBCPxx == "OBCP35") {
                            PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                        }
                        if(choppedOBCPxx == "OBCP27") {
                            ///            obsTime =  
                            PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                        }
                    } else {
                        ///            obsTime =  
                        PacsSpecCommandOBCP32(confSPECblu,confSPECred,confOBCP,false);
                    }
                    nbOFF = nbOFF + 1;
                    //       Logic to sum up obsTime
                    ///         if (nbOFF == 1) {sumUpObsTime = obsTime;}
                    ///         if (nbOFF > 1)  {sumUpObsTime = SumFunction(obsTime,sumUpObsTime);}
                    if(verbose) {
                        tNOW = time();
                        ///          debug_print("    SumUpObsTime: " + sumUpObsTime);
                        debug_print("=== OFF ends at: " + tNOW);
                    }
                } else {
                    if(stateVar[0] == 7) {
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== NOD starts at: " + tNOW);
                        }
                        if(choppedOBCPxx == "OBCP35") {
                            obsTime = PacsSpecCommandOBCP35(confSPECblu,confSPECred,confOBCP,false);
                        }
                        if(choppedOBCPxx == "OBCP27") {
                            obsTime = PacsSpecCommandOBCP27(confSPECblu,confSPECred,confOBCP,false);
                        }
                        nbOBS = nbOBS + 1;
                        //       Logic to sum up obsTime
                        if(nbOBS == 1) {
                            sumUpObsTime = obsTime;
                        }
                        if(nbOBS > 1) {
                            sumUpObsTime = SumFunction(obsTime,sumUpObsTime);
                        }
                        if(verbose) {
                            tNOW = time();
                            debug_print("    SumUpObsTime: " + sumUpObsTime);
                            debug_print("=== NOD ends at: " + tNOW);
                        }
                    } else {
                        if(stateVar[0] == 6) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== HOLD starts at: " + tNOW);
                            }
                            if(overrideAll_SPU_CRE_params) {
                                calTime = PacsSpecSlewCalSPU(false,scenario,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel);
                            } else {
                                calTime = PacsSpecSlewCal_override(false,confSPECblu,confSPECred,confOBCP,false,keyWAVE,filter,frstLstGratPos,orderSel,overrideCalBlockOBCP35params);
                            }
                            sumUpCalTime = SumFunction(calTime,sumUpCalTime);
                            if(verbose) {
                                tNOW = time();
                                debug_print("    SumUpCalTime: " + sumUpCalTime);
                                debug_print("=== HOLD ends at: " + tNOW);
                            }
                        } else {
                            if(stateVar[0] == 5) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== FinalHOLD  starts at: " + tNOW);
                                }
                                SPEC_aot_epilogue(frstLstGratPos,grat_park,verbose);
                                WriteEndID();
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== FinalHOLD  ends at: " + tNOW);
                                }
                            } else {
                                if(stateVar[0] == -1) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== AOT  ends at: " + tNOW);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    if(verbose) {
        debug_print("OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("Ending with NbOFF: " + nbOFF);
    }
    // The original concept of returning durations did not take into 
    // account the bandwidth of the TC bus (2 TCs/sec). The "real" 
    // duration is given by the result from the "duration()" function. Hence
    // the true total duration of the SlewCal phase is given by
    ///   calTime[0] = timeSlewCal;
    // as a result, the overheads are now
    ///   calTime[4] = calTime[0]-(calTime[1]+calTime[2]+calTime[3]); 
    if(verbose) {
        debug_print("Slew & HOLD Cal return: " + sumUpCalTime);
    }
    // The same holds true for the OBCP35 phase. However, I cannot make the
    // break-down by wavelength (the OBCP35 duration is given for ALL lines).
    // We may add up the SRC, CAL, and OVR components of OBCP35 duration. For
    // this we need a tuple so we can add the wavelength and other relevant
    // information to the (per wave) duration arrays.
    //
    //  infoArray[] contains a "fixed" global information part
    //  infoArray[0]: {Slew,   intTime,TotDur,nbRanges,nnods,m*n}
    //  infoArray[1]: {Point,  intTime,TotDur,nbRanges,nnods,m*n}
    //  infoArray[2]: {AOTinfo,intTime,TotDur,nbRanges,nnods,m*n}
    //
    // and a per wavelength array:
    //    [waveSTART,waveEND,order,gratStep,nbGratStep,TOT,SRC,REF,CAL,OVR]
    // TotDur as given by duration(); TOT,SRC,REF,CAL,OVR are also in [sec]
    {{string,double,int,int,int,int},{double,double,int,int,int,int,int,int,int,int}[]}[] infoArray = [{{"",0.0,0,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]}];
    // Fill 1st dimension of infoArray with data from SlewCal
    // Instead of using timeSlewCal, use tslew time returned by PointReq
    // infoArray[0] = {{"SlewCal",0.0,timeSlewCal,0,0,0},[{0.,0.,0,0,0,0,0,0,0,0}]};
    infoArray[0] = {{"SlewCal",0.0,tslew,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Compute integration time per chopper plateau
    // intTime = nbRamps/plateau x nbRdouts/ramp x sampleInterval 
    // Sampling frequency
    double specSample = dlookup("PACSparams","spec_sample","freq_time");
    // Number of readouts per ramp
    int nbRdoutRamp = confSPECblu[1]{1};
    // NOTE: WAIT=1 are now counted as useful ramps; hence
    int wait1 = 1;
    // but there is no wait in FreqSwitch
    // Count the WAIT=1 for grating as a useful SRC
    if(switching) {
        wait1 = 1;
    }
    int nbRampPlateau = confOBCP[1]{4} + wait1;
    // 
    double intTime = double(nbRampPlateau * nbRdoutRamp) / specSample;
    if(verbose) {
        debug_print("MAIN:AOT          : " + userMode);
        debug_print("MAIN:Rdouts/ramp  : " + nbRdoutRamp);
        debug_print("MAIN:Ramps/plateau: " + nbRampPlateau);
        debug_print("MAIN:IntTime      : " + intTime);
    }
    // Replace timeOBS (per raster and per nod) with tobs from PntReq (matching
    // change in PacsProcessInfoArray)   
    // infoArray[1] = {{userMode,intTime,timeOBS,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    infoArray[1] = {{userMode,intTime,tobs,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    for(int loop3 = 0 .. nbLines1) {
        //     for some reason it has to be "initialized"
        infoArray[1]{1}[loop3] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the START wavelength (for LINE START = END = line wave)
        infoArray[1]{1}[loop3]{0} = sortLines[loop3]{1};
        //     copy the END   wavelength (for LINE START = END = line wave)
        infoArray[1]{1}[loop3]{1} = sortLines[loop3]{1};
        //     copy the grating order
        infoArray[1]{1}[loop3]{2} = sortWaveTuple[loop3]{1};
        //     copy the grating step
        infoArray[1]{1}[loop3]{3} = sortWaveTuple[loop3]{4};
        infoArray[1]{1}[loop3]{3} = (confOBCP[loop3 + 1]{2} - confOBCP[loop3 + 1]{1}) / 2;
        //     copy the number of grating steps
        infoArray[1]{1}[loop3]{4} = confOBCP[loop3 + 1]{6};
        //     copy other data from sumUpObsTime
        infoArray[1]{1}[loop3]{5} = sumUpObsTime[loop3][0];
        infoArray[1]{1}[loop3]{6} = sumUpObsTime[loop3][1];
        infoArray[1]{1}[loop3]{7} = sumUpObsTime[loop3][2];
        infoArray[1]{1}[loop3]{8} = sumUpObsTime[loop3][3];
        infoArray[1]{1}[loop3]{9} = sumUpObsTime[loop3][4];
    }
    // Also data from SlewCal to infoArray
    for(int loop4 = 0 .. nbKeyWAVE - 1) {
        //     for some reason it has to be "initialized"
        infoArray[0]{1}[loop4] = {0.0,0.0,0,0,0,0,0,0,0,0};
        //     copy the wavelength
        infoArray[0]{1}[loop4]{0} = keyWAVE[loop4];
        //     copy other data from sumUpCalTimeTime
        infoArray[0]{1}[loop4]{5} = sumUpCalTime[loop4][0];
        infoArray[0]{1}[loop4]{6} = sumUpCalTime[loop4][1];
        infoArray[0]{1}[loop4]{7} = sumUpCalTime[loop4][2];
        infoArray[0]{1}[loop4]{8} = sumUpCalTime[loop4][3];
        infoArray[0]{1}[loop4]{9} = sumUpCalTime[loop4][4];
    }
    // Further update of infoArray: add information from AOT_prologue    
    infoArray[0]{1}[nbKeyWAVE] = {0.0,0.0,0,0,0,0,0,0,0,0};
    //   Copy OVR and TOT times
    infoArray[0]{1}[nbKeyWAVE]{9} = calTime[nbKeyWAVE][4];
    infoArray[0]{1}[nbKeyWAVE]{5} = calTime[nbKeyWAVE][4];
    //   Copy the number of lines observed and the number of key waves used
    infoArray[0]{0}{3} = nbKeyWAVE;
    infoArray[1]{0}{3} = nbLines;
    //   Copy the number of nod cycles and the number of raster points visited
    infoArray[1]{0}{4} = nbNods;
    infoArray[1]{0}{5} = m * n;
    // The duration of the OBS phase is given by timeObsEnd - timeSlewCal
    // Now get it from PntReq: timeObsPhase == tobs
    // int timeObsPhase = timeObsEnd - timeSlewCal;
    // Slew time during the OBS phase is then given by
    int timeSlewObs = tobs - nbOBS * timeOBS;
    if(verbose) {
        debug_print("CalSlew phase lasted [sec]: " + timeSlewCal);
        debug_print("The OBS phase lasted [sec]: " + tobs);
        debug_print("Total slew during OBS [sec]: " + timeSlewObs);
    }
    // Fill 3rd dimension of infoArray with global timing and AOT information
    // timeObsEnd is the total duration of the AOT
    // Pass details of AOT
    // change of OBCP
    // We use OBCP27: OBCP_grat_scan_chop2 or grat_line_scan_chop_3 (unless FreqSwitch)
    if(choppedOBCPxx == "OBCP35") {
        string aotName = "GratLineScanChop3";
    }
    if(choppedOBCPxx == "OBCP27") {
        aotName = "GratScanChop2";
    }
    // Special "sky time"  for FreqSwitch and SmallSourceDither
    if(switching) {
        aotName = "FreqSwitch";
    }
    if(source == "dithered") {
        infoArray[1]{0}{0} = "SmSrcDither";
    }
    infoArray[2] = {{aotName,0.0,timeObsEnd,0,0,0},[{0.0,0.0,0,0,0,0,0,0,0,0}]};
    // Use available entries to convey m,n, and nbNods
    infoArray[2]{0}{3} = m;
    infoArray[2]{0}{4} = n;
    // PointSources are also seen with composite_nodding
    if(pointMode == "fine_pointing" || pointMode == "composite_nodding") {
        infoArray[2]{0}{3} = 1;
        infoArray[2]{0}{4} = 1;
    }
    infoArray[2]{0}{5} = nbNods;
    // If switching 
    if(switching && source == "Large") {
        infoArray[1]{0}{0} = "RasterOFF";
    } else {
        if(switching && source == "Point") {
            infoArray[1]{0}{0} = "Pointed";
        }
        infoArray[2]{0}{5} = userNODcycles;
    }
    // Process the information contained in infoArray (pass also sortLines)
    PacsProcessInfoArrayLine(infoArray,sortLines,confOBCP,obsOverhead,nbOBS,nbOFF,verbose);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    // Compute the total time SRC + REF
    int accumSrceRef = 0;
    for(int loopL = 0 .. nbLines - 1) {
        //   Add up Srce and Ref times (SRC + REF)
        accumSrceRef = accumSrceRef + infoArray[1]{1}[loopL]{6} + infoArray[1]{1}[loopL]{7};
    }
    // Compute overheads as total "sky" time minus SRC+REF time
    int overPACSandSC = fromPntReq[0] - accumSrceRef;
    // Return demanded tuples

    return {accumSrceRef,fromPntReq[1],overPACSandSC};
}

// Missionphase  : FM
//
// Purpose	: Stop diagnostic housekeeping
//                  
// Author	: Helmut Dannerbauer
// CUS author 	: HD
//
// Description	: The instrumental command for stopping the diagnostic housekeeping
//	  is called.
//                  
// Dependencies : 
//
// Preconditions   : PACS switched-on, and diagnostic housekeeping is started.
//	      
//                 
// Comments	: This script is based on the commanding during the CQM ILT.
//
// Version	: 3.1
// 
// History 	: 1.0 21-07-06 creation by HD
//	  2.0 24-07-06 HD. test this script.
//        3.0 24-07-06 HD. script works.	  
//        3.1 21-jan-2008 DAC Added WriteEndBB
block PACS_stop_dhk_fm_bb PACS 357 {
}{
    // Register start of BB
    WriteBBID($BBID);
    // Stop diagnostic HK
    Pacs_DMC_STOP_DIAG_HK();
    // End of BB
    WriteEndBB();
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : TM
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Switch on groups
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 08-nov-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_Switchon {
    /* No variables to call PacsEng_Phot_Switchon                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_Switchon                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_Switchon()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_Switchon();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : FM ILT
//
// Purpose	 : Switch on/off diagnostic HK
//                  
// Author	 : Markus Nielbock
// CUS author 	 : MN
//
// Description	 : This building block switches on/off diagnaostic HK.
//                 Receiving signals:
//                   ON: switch on diagnostic HK
//                   OFF: switch off diagnostic HK
//                  
// Dependencies  :  
//
// Preconditions : PACS switched-on, chopper is switched on
//                 
// Comments	 :
//
// Version	 : 1.2
// 
// History 	 : 1.0 15-12-06 creation by MN
//         	 : 1.1 03-01-07 modified HK list (MN)
//         	 : 1.2 08-03-07 modified HK list (MN)
// Begin Mode description
block PACS_SPEC_Chopper_OpenLoop_MoveAbs_dHK_BB PACS 430 {
    string onoff = "OFF" in ["ON","OFF"];
}{
    // For housekeeping using the chopper in open-loop mode, we need the
    // following parameters:
    // 242      DMC_IRS_CNT
    // 244	DMC_CHOP_CUR_POS
    // 245	DMC_CHOP_SETPOIN
    // 258	DMC_CHOP_OUTPUT
    // 561	DMC_CHOP_IA
    // Get BBID from environment
    int myBBID = $BBID;
    // Send BBID to DMC
    WriteBBID(myBBID);
    // IF-statement for switching on
    if(onoff == "ON") {
        // Readout period set to 1kHz
        int diag_hk_period = 0;
        // Create list of HK parameters
        {int}[] parlist = [{242},{244},{245},{258},{561},{0xffff}];
        int hk_len = length(parlist);
        // Calculate check sum
        int[] aux = [242,244,245,258,561,0xffff];
        int check_sum = checksum("int",aux);
        // Write HK parameters and start HK
        debug_print("Starting chopper diagnostics with " + hk_len + " parameters:");
        Pacs_DMC_WRT_DIAG_HK_LIST(hk_len,parlist,check_sum);
        Pacs_DMC_START_DIAG_HK(diag_hk_period);
    }
    // End IF
    // IF-statement for switching off
    if(onoff == "OFF") {
        debug_print("Stopping diagnostic HK");
        Pacs_DMC_STOP_DIAG_HK();
    }
    // End IF
    // Mark End of Block
    WriteEndBB();
}

// CVS comments  : $Id
// Purpose       : Issue PACS commands at each raster position in order to
//                 observe all the HSPOT defined spectral lines
//
// CUS author    : DAC
// Script file   : PacsSpecCommand.txt 
//
// Input arguments
// Type                                                 Description
// {int,int,int,int,int,int,int,int,int}[] confSPECblu  BLUE SPU parameters
// {int,int,int,int,int,int,int,int,int}[] confSPECred  RED  SPU parameters
// {int,int,int,int,int,int,int,int,int,int,int,
//  int,int,int,int,int,int,int,int,int}[] confOBCP     OBCP parameters
// bool verbose                                         Print debug information
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per spectral line
//
// Description   : Loops over all wavelengths at current raster point. If raster
// identifier "rast_pnt" is a negative number, it means that we are in the
// "nodding" phase of "rast_pnt". Chopper pattern ABBA
// IMPORTANT NOTE: the duration for the first raster position
//                 may be different than the following raster points, due to the
//                 fact that we start at the default configuration whereas for
//                 any subsequent raster point, we start from where we ended at
//                 raster_point-1.
// NOTE: starting with version 3.0, grating is left at start position used by
//       first line in OBCP. This minimizes grating movements within a raster
//       or when nodding
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
//
// Version       : 3.0
// History       : 
// 0.1 DAC  6-May-2005
// 1.0 11-mar-2009 VD OBCP35
// 1.1 23-mar-2009 remove PacsSpecConfSet ... not allowed
// 2.x 24-feb-2010 VD PHS-1285 for Ranges .. could be actually for SED?
//                    add bool dither (if(sed) dither = false)
// 2.2 14-Apr-2010 VD PHS-1383 ...
// 2.3 22-Nov-2010 VD PHS-3169 Wrong timing ofr grating moves in Range scan dithered (not SED)
//
int[][] procedure PacsSpecCommandOBCP35_dither {
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}]; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}]; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]; // OBCP parameters
    bool dither = false;
    bool verbose = true; // Print debug information
}{
    // Create array of durations; one duration per line
    int[][] time_array = [[0,0,0,0,0]];
    // Start grating position should be the 1st line to observe
    // later it will be commanded elsewhere
    int grat_def_pos = confOBCP[1]{8};
    // How many lines are we supposed to observe?
    int nbLines = length(confOBCP) - 1;
    // ========================= LOOP on lines ===============================
    for(int loop2 = 1 .. nbLines) {
        int[] quantum_time_array = [0,0,0,0,0];
        int[] dither_time_array = [0,0,0,0,0];
        //   Long sequence to "unpack" contents of tuples
        int capa_blu = confSPECblu[loop2]{0};
        int nb_rdouts_ramp_blu = confSPECblu[loop2]{1};
        int nb_rdouts_subramp_blu = confSPECblu[loop2]{2};
        int comp_mode_blu = confSPECblu[loop2]{3};
        int glitch_det_blu = confSPECblu[loop2]{4};
        int ramp_fit_alg_blu = confSPECblu[loop2]{5};
        int nb_raw_blu = confSPECblu[loop2]{6};
        int bias_r_blu_mV = confSPECblu[loop2]{7};
        int bias_d_blu_mV = confSPECblu[loop2]{8};
        int capa_red = confSPECred[loop2]{0};
        int nb_rdouts_ramp_red = confSPECred[loop2]{1};
        int nb_rdouts_subramp_red = confSPECred[loop2]{2};
        int comp_mode_red = confSPECred[loop2]{3};
        int glitch_det_red = confSPECred[loop2]{4};
        int ramp_fit_alg_red = confSPECred[loop2]{5};
        int nb_raw_red = confSPECred[loop2]{6};
        int bias_r_red_mV = confSPECred[loop2]{7};
        int bias_d_red_mV = confSPECred[loop2]{8};
        // ahhh that is the one to save .. then set to 1 then recover
        // PHS-1285
        int nb_up_down = confOBCP[loop2]{0};
        int grat_step_up = confOBCP[loop2]{1};
        // PHS-1285
        // also t be used for the dither
        int grat_step_dn = confOBCP[loop2]{2};
        int nb_SRC_OFF = confOBCP[loop2]{3};
        int nb_ramps_plateau = confOBCP[loop2]{4};
        int nb_CS1_CS2 = confOBCP[loop2]{5};
        // PHS-1285
        // this one does NOT change
        int nb_grat_step_up = confOBCP[loop2]{6};
        int nb_grat_step_dn = confOBCP[loop2]{7};
        // PHS-1285
        // this one will be dithered
        int grat_start_pos = confOBCP[loop2]{8};
        //   int grat_start_time       = confOBCP[loop2]{ 9};
        //   int grat_def_pos          = confOBCP[loop2]{10};
        //   int grat_def_time         = confOBCP[loop2]{11};
        int chop_pos_SRC = confOBCP[loop2]{12};
        int chop_pos_REF1 = confOBCP[loop2]{13};
        int chop_pos_REF2 = confOBCP[loop2]{14};
        int chop_pos_CS1 = confOBCP[loop2]{15};
        int chop_pos_CS2 = confOBCP[loop2]{16};
        int chop_def = confOBCP[loop2]{17};
        int detector = confOBCP[loop2]{18};
        int filterPOS = confOBCP[loop2]{19};
        //   Bias voltages (needed by SPEC_aot_prologue) are commanded in 
        //  (double) volts
        double bias_r_blu = double(bias_r_blu_mV) / 1000.0;
        double bias_d_blu = double(bias_d_blu_mV) / 1000.0;
        double bias_r_red = double(bias_r_red_mV) / 1000.0;
        double bias_d_red = double(bias_d_red_mV) / 1000.0;
        //   Call OBCP once per spectral line (local loop) 
        //   (this module is invoked once per per raster position)
        //   Grating movement facts and strategy:
        //   0-  OBCP starts with grating already at grat_start_pos (done by SlewCal) 
        //   1-  OBCP moves grating from grat_start_pos to grat_start_pos 
        //   1a- above operation takes grat_start_time = 0 seconds
        //   2-  perform all the CHOPPER, CAL, loops
        //   2a- above operation takes whatever time
        //   3-  at end, OBCP moves grating to grat_start_pos for 1st line
        //   3a- above operation takes grat_def_time
        //
        //   This is up-down scan. Hence grating ends at position grat_start_pos
        //   If we set grat_def_pos position to grat_start_pos  for the next line, 
        //   we reduce grat_start_time to 0 [sec] for all lines but the first.
        //   At end of line "n", place grating at the position expected by line 
        //   "n+1" for all lines but last. For last observed wavelength use 
        //   grat_def_pos to ensure that next cycle will start exactly as this one,
        //   i.e. with grating parked at grat_def_pos
        //   Leave the grating where it is, i.e. end-of-DMC position
        // 
        // PHS-1285: carefull this also NEEDS to be saved and dithered...
        // 
        int new_grat_def_pos = confOBCP[loop2]{8};
        //   The last observed line should leave the grating ready to start
        //   all over again
        //
        //PHS-1285 here we start looping on the dither
        //
        double ext_grat_blu_pos = double(new_grat_def_pos);
        if(loop2 == nbLines) {
            new_grat_def_pos = confOBCP[1]{8};
        }
        int save_nb_up_down = nb_up_down;
        if(dither) {
            if(save_nb_up_down > 1) {
                for(int loopDith = 0 .. save_nb_up_down - 1) {
                    int nbDith = loopDith + 1;
                    //  debug_print("loopDith: " + nbDith + "/" + save_nb_up_down);
                    // the funtion??
                    double grat_dither = double(loopDith) * (double(grat_step_up) / double(save_nb_up_down));
                    double ext_grat_bluEdge_shift = ext_grat_blu_pos - grat_dither;
                    grat_start_pos = iround(ext_grat_bluEdge_shift);
                    //                    grat_def_pos = grat_start_pos;
                    new_grat_def_pos = grat_start_pos;
                    nb_up_down = 1;
                    //   Starting times, viz. grat_time.
                    //   NOTE: grat_start_pos is in OBCP tuple {8}
                    int steps_start = grat_def_pos - grat_start_pos;
                    int grat_start_time = SPEC_grat_time(steps_start);
                    if(verbose) {
                        debug_print("OBCP35:Observing line/of:" + loop2 + "/" + nbLines);
                        debug_print("OBCP35:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_start_time);
                    }
                    //   Ending times, viz. grat_def_time
                    //   NOTE: DMC of OBCP35 leaves grating at start position
                    int steps_end = grat_start_pos - new_grat_def_pos;
                    int grat_def_time = SPEC_grat_time(steps_end);
                    if(verbose) {
                        debug_print("OBCP35:GratEnd   from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
                    }
                    //   Call OBCP35 with derived parameters 
                    // PHS-1285 
                    // this is in a loop for nb_up_down to become the dither
                    quantum_time_array = OBCP_grat_line_scan_chop_3(nb_up_down,nb_grat_step_up,grat_step_up,nb_SRC_OFF,chop_pos_SRC,nb_ramps_plateau,chop_pos_REF1,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_dn,detector,grat_start_pos,grat_start_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
                    for(int array = 0 .. 4) {
                        dither_time_array[array] = quantum_time_array[array] + dither_time_array[array];
                    }
                    //   Prepare the grating to be ready for the next wavelength
                    grat_def_pos = new_grat_def_pos;
                }
                time_array[loop2 - 1] = dither_time_array;
            } else {
                nb_up_down = save_nb_up_down;
                steps_start = grat_def_pos - grat_start_pos;
                grat_start_time = SPEC_grat_time(steps_start);
                if(verbose) {
                    debug_print("OBCP35:Observing line/of:" + loop2 + "/" + nbLines);
                    debug_print("OBCP35:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_start_time);
                }
                //   Ending times, viz. grat_def_time
                //   NOTE: DMC of OBCP35 leaves grating at start position
                steps_end = grat_start_pos - new_grat_def_pos;
                grat_def_time = SPEC_grat_time(steps_end);
                if(verbose) {
                    debug_print("OBCP35:GratEnd   from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
                }
                //   Call OBCP35 with derived parameters 
                // PHS-1285 
                // this is in a loop for nb_up_down to become the dither
                time_array[loop2 - 1] = OBCP_grat_line_scan_chop_3(nb_up_down,nb_grat_step_up,grat_step_up,nb_SRC_OFF,chop_pos_SRC,nb_ramps_plateau,chop_pos_REF1,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_dn,detector,grat_start_pos,grat_start_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
                //   Prepare the grating to be ready for the next wavelength
                // 
                grat_def_pos = new_grat_def_pos;
            }
        } else {
            nb_up_down = save_nb_up_down;
            //   Starting times, viz. grat_time.
            //   NOTE: grat_start_pos is in OBCP tuple {8}
            steps_start = grat_def_pos - grat_start_pos;
            grat_start_time = SPEC_grat_time(steps_start);
            if(verbose) {
                debug_print("OBCP35:Observing line/of:" + loop2 + "/" + nbLines);
                debug_print("OBCP35:GratStart from/to: " + grat_def_pos + "/" + grat_start_pos + "; time: " + grat_start_time);
            }
            //   Ending times, viz. grat_def_time
            //   NOTE: DMC of OBCP35 leaves grating at start position
            steps_end = grat_start_pos - new_grat_def_pos;
            grat_def_time = SPEC_grat_time(steps_end);
            if(verbose) {
                debug_print("OBCP35:GratEnd   from/to: " + grat_start_pos + "/" + new_grat_def_pos + "; time: " + grat_def_time);
            }
            //   Call OBCP35 with derived parameters 
            // PHS-1285 
            // this is in a loop for nb_up_down to become the dither
            time_array[loop2 - 1] = OBCP_grat_line_scan_chop_3(nb_up_down,nb_grat_step_up,grat_step_up,nb_SRC_OFF,chop_pos_SRC,nb_ramps_plateau,chop_pos_REF1,nb_CS1_CS2,chop_pos_CS1,chop_pos_CS2,grat_step_dn,detector,grat_start_pos,grat_start_time,comp_mode_blu,comp_mode_red,new_grat_def_pos,chop_def,grat_def_time,nb_rdouts_ramp_red);
            //   Prepare the grating to be ready for the next wavelength
            // 
            grat_def_pos = new_grat_def_pos;
            // End of nbLines loop
        }
    }
    // time_array is indexed [wavelength][durations]     
    if(verbose) {
        debug_print("CmdOBCP35 returns " + time_array);
    }
    //SPR1707 Add sync()
    sync();

    return time_array;
}

//
// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// Version	: 2.0
// History       : 0.1 22-mar-2006
// History       : 2.0 04-mar-2008  Converted into PV script by VDP
//
obs PacsEng_Phot_Fil_nturns {
    /* Needed variables to call PacsEng_Phot_Fil_nturns                        */
    int num_turns = 3; // Number of full turns
    int backward_toA = 0; // direction of FW rotation towards POS A : 0 forward; 1 backward
    int backward_toB = 0; // direction of FW rotation towards POS B : 0 forward; 1 backward
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_Fil_nturns                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_Fil_nturns(num_turns,backward_toA,backward_toB)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_Fil_nturns(num_turns,backward_toA,backward_toB);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

/////////////////////////////////////////////////////////////////////////////
/// $Id$ 
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsPhoto AOT
// CUS author    : DAC
// Script file   : PacsCal_PacsPhotoDAC.txt
// Return values
// Description   : 
// This AOT has to cater to three different source morphologies:
// "point", "small", and "large". Each mode requires its own pointing modes.
// Available pointing modes (reference is to JBr's document):
// NOTE: All modes include operations during SLEW and operations at end of OBS.
// NOTE: Updated based on e-mail from MS dated 3-Dec-2005 (denoted UPDATE)
// NOTE: Updated after Saclay meeting
// ==== "point"
// no nodding                         2.1  fine_pointing
// nodding (includes "hold" periods)  3.4  nodding_pointing
// UPDATE: Nodding is always needed ==> eliminate fine_pointing
//
// ==== "small"
// (raster dimensions and steps TBD; expect 2x2 or 3x3)
// no nodding ("hold" periods and repetition) 2.13 repeated_raster_with_hold
// nodding ("hold" periods and no repetition) 2.12 nodding_in_raster
// UPDATE: Nodding always used ==> nodding_in_raster
//
// ==== "large"
// Can be RASTER or SCAN (freeze mode is based upon a SCANning PointMode)
// RASTER
// no nodding ("hold" periods and repetition) 2.13 repeated_raster_with_hold
// nodding ("hold" periods and no repetition) 2.12 nodding_in_raster
// UPDATE: Nodding not used ==> raster_pointing
//
// SCAN
// There is no nodding and no chopping. "Hold" periods are allowed (mode 2.14) 
// Leg length is restricted to 20 degrees. 
//
// Dependencies  : 
//
// Preconditions : 
//
// Comments      : Almost identical to PacsPhoto. Maid differences:
//                 - accept (from XHspot) the following variables:
//                   - nholdIN User defined "nhold", overrides CAL values
//                   - confphotoparams Non-standard CONF_PHOTOparams CAL file
//                   - obcpparams Non standard OBCP3params (point source) or 
//                     OBCP4params (small source) CAL files
//                 - Calls two PV dedicated AOT scripts (search _PV in code).
//                   These scripts accept confphotoparams and obcpparams  
// 
// History       : 0.1  19-may-2008 DAC PV version based on PacsPhoto.def
//                 - Added name of OBCP3params and CONF_PHOT_params files as
//                   input parameters. Activated "nhold" logic
//                 0.2 20-may-2008 DAC
//                 -  Mostly editorial changes (useful for the AOT version
//                    as well)
//                 0.3 21-may-2008 DAC
//                  - Make nhold an input variable, ignore values in CAL files
//                    (not for the AOT version, where "nhold" in CAL files
//                     seems more adequate)
//                 0.4 18-jul-2008 DAC 
//                    - Add OFF option to the SCAN mode
//                    - Remove unused mapScanConstrXX
//                    - Remove unused chopAvoidXX
//                    - Remove unused mapRasterConstrXX
//                    - Prompt user for
//                         - raoff, decoff     (needed for OFF)
//                         - gain              (in CONF_PHOT_params)
//                         - comp_mode         (in CONF_PHOT_params)
//                         - nb_main_loops     (in OBCP3params,OBCP4params)
//                         - nb_rdouts_plateau (in OBCP3params, OBCP4params)
//                         - max_dither        (in OBCP3params)
//                         - nhold             (in OBCP3params,OBCP4params)
//                         - nb_SRC_REF        (in OBCP4params)
//                         - nb_CS1_CS2        (in OBCP4params)
//                         - kOFF              user defined OFF repetition
//                    All user defined variables will overwrite values obtained
//                    from the associated CAL-U tables. Code *may* anounce
//                    such and such value but the actual numerical value will
//                    be the one given by the user.
//                 0.5  9-oct-2008 DAC Use line_scan_with_off_pointing to allow OFF positions
//		   0.6 23-apr-2009 VD SPR 6482
//		   1.0 VD/TM SCR 1292: no OBCP running during scan legs: only
//                        WriteBBID and OBCP2 then delayed WriteEndID
//                 1.1 29-jul-2009 VD remove OBCP2.. PACS-1845
//                 2.0 03-aug-2009 VD SPR: PACS-1891: state machine trying to run OBCP 7 in OFF position: removed
//                                         Same logic in OFF as for Line
//                                         ADDED red/blue Hspot distinction for Gain
//                                         ADDED 1sec in tfh ???? I don't understand!!!
//
{int,int,int,double,{string,double,double,double,double,double,double}[]} obs PacsCal_PacsPhotoDAC {
    string blue = "blue1" in ["blue1","blue2"];
    int repFactor = 1 in [1,1500]; // Repeat factor: i.e. nb of nods or rasters
    string source = "point" in ["point","small","largeRaster","largeScan","none"]; // Source size/Obs type
    string mapScanSpeed = "high" in ["high","medium","low"]; // Scan rate
    double mapScanLegLength = 30.0 in [1.0,1200.0]; //Scan leg [arcmin]
    int mapScanNumLegs = 2 in [1,1500]; //Number of scan legs
    string mapScanAngleRef = "inst" in ["sky","inst","i+c","s+c"];
    double mapScanAngle = 0.0 in [0.0,360.0];
    double mapScanCrossScan = 2.0 in [2.0,480.0]; // Scan separation [arcsec]
    bool mapScanHomCoverage = true;
    bool mapScanSquare = false;
    double pointStep = 2.0 in [2.0,480.0];
    double lineStep = 2.0 in [2.0,480.0];
    string mapRasterAngleRef = "inst" in ["inst","i+c"];
    int m = 2 in [2,100];
    int n = 1 in [1,100];
    bool dither = false;
    int naifid = 0; //RA,DEC or SSO
    double fluxPntBlu = 116.0 in [0.0,2.0E7]; // Flux density in blue band mJy
    double fluxPntRed = 150.0 in [0.0,2.0E7]; // Flux density in red band mJy
    double fluxExtBlu = 116.0 in [0.0,2.0E7]; // Flux in blue band MJy/sr
    double fluxExtRed = 40.0 in [0.0,2.0E7]; // Flux in red band MJy/sr
    int obsOverhead = 180; // Slew overhead
    /*  Block of new user prompted variables      */
    int gain_red = 1 in [0,1]; //Gain (red channel): 0:HI, 1:LO
    int gain_blu = 1 in [0,1]; //Gain (blue channel): 0:HI, 1:LO
    int comp_mode_red = 0; //Compression algorithm (red channel)
    int comp_mode_blu = 0; //Compression algorithm (blue channel)
    int nb_main_loops = 1; //Outermost counter in OBCP3
    int nb_rdouts_plateau = 15; //NbRDouts/plateau (must be 4*n-1)
    int max_dither = 1060; //Dithering for OBCP3
    int nhold = 0; //How often perform a CAL observations
    int kOFF = 0; //How often perform the OFF observation
    int nb_SRC_REF = 38; //Nb of SRC/REF chopper cycles
    int nb_CS1_CS2 = 0; //Number of CS1/CS2 chopper cycles 
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    double raoff = 0.0; //Where OFF will be performed
    double decoff = 0.0; //Where OFF will be performed
    bool refSelected = false; // OFF position needed
    /*  End block of new user prompted variables             */
    /* End of input section */
}{
    // Begin "pointing" section
    // Overall "verbosity"
    bool verbose = true;
    // New nodding_pointing variable
    bool startAtOFF = false;
    // Conversion to deprecated variables
    bool noddingSel = true;
    if(source == "largeRaster") {
        string largeOptions = "raster";
        bool mapRasterSel = true;
        noddingSel = false;
    }
    if(source == "largeScan") {
        largeOptions = "scan";
        mapRasterSel = false;
        noddingSel = false;
    }
    int mapRasterNumCycles = repFactor;
    // Useful variables
    // Bolo size: Short Size, i.e. 32 pixels and Long Size [arcsec]
    double boloSSize = 1.75 * 60.0;
    double boloLSize = 3.5 * 60.0;
    double boloArea = boloSSize * boloLSize;
    // 
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // Pointing mode has not been established yet
    int pointCase = 0;
    // Determine the pointing mode
    if(source == "point") {
        //     Variable needed to obtain choper throw from CAl-U
        string srcID = "pointSRC";
        //     Just for completiness, define a 1x1 raster
        m = 1;
        n = 1;
        //     Fine pointing without nodding is disallowed (pointCase remain null)
        if(!noddingSel) {
            string pointMode = "basic_fine_pointing";
            string shortDesc = "Point source (no nodding)";
            // not allowed           pointCase        = 11;
        } else {
            pointMode = "nodding_pointing";
            shortDesc = "Point source (nodding and chopping)";
            pointCase = 12;
            string yzoffsetROW = "P" + pointCase;
        }
    }
    if(source == "small") {
        srcID = "smallSRC";
        //   Obtain the size of the raster from CAL-U "SMALL_SRC_params"
        m = ilookup("SMALL_SRC_params","PHOT","mRast");
        n = ilookup("SMALL_SRC_params","PHOT","nRast");
        pointStep = dlookup("SMALL_SRC_params","PHOT","pointStep");
        lineStep = dlookup("SMALL_SRC_params","PHOT","lineStep");
        if(!noddingSel) {
            pointMode = "raster_pointing";
            shortDesc = " Small source (no nodding)";
            //         not allowed
            //           pointCase = 21;
        } else {
            pointMode = "nodding_raster_pointing";
            shortDesc = "Small source (nodding and chopping)";
            pointCase = 22;
            yzoffsetROW = "P" + pointCase;
        }
    }
    // Large source in Raster Mode
    if(source == "largeRaster") {
        srcID = "largeSRC";
        if(!noddingSel) {
            pointMode = "raster_pointing";
            shortDesc = "Large source, raster mode (chopping and no nodding)";
            pointCase = 31;
            yzoffsetROW = "P" + pointCase;
        } else {
            pointMode = "nodding_in_raster";
            shortDesc = "Large source, raster mode (chopping and nodding)";
            //         not allowed
            //           pointCase = 32;
        }
    }
    // Large source in Scan Mode
    if(source == "largeScan") {
        srcID = "largeSRC";
        pointMode = "line_scan_pointing";
        shortDesc = "Large source, line scan mode (no chopping)";
        //     For consistency
        m = 1;
        n = mapScanNumLegs;
        pointCase = 33;
        yzoffsetROW = "P" + pointCase;
    }
    // If pointCase is still 0, then something went wrong with the PointMode logic...
    if(pointCase == 0) {
        error("NODDING is incompatible with source: " + source);
    }
    // The pointing mode has been established. Continue with other input data
    // from HSPOT
    if(verbose) {
        debug_print("================> PointMode: " + pointMode);
    }
    //
    // confPHOT arrays (red and blu) compared to confSPEC
    //                       PHOT name         SPEC name
    // confPHOTred{ 0}       gain              capa_red;
    // confPHOTred{ 1}       N/A               nb_rdouts_ramp_red;
    // confPHOTred{ 2}       N/A               nb_rdouts_subramp_red;
    // confPHOTred{ 3}       same              comp_mode_red;
    // confPHOTred{ 4}       same              glitch_det_red;
    // confPHOTred{ 5}       ??                ramp_fit_alg_red;
    // confPHOTred{ 6        ??                nb_raw_red;
    // confPHOTred{ 7}       N/A               bias_r_red;
    // confPHOTred{ 8}       N/A               bias_d_red;
    //
    // Define confOBCP array.
    // NOTE: the conf arrays are inherited from PacsSpec, where the [0] element
    // represented the default values, and the [n] element represented values
    // to be used with the n-th wavelength. Here - PHOT - [0] still represents
    // the default values and [1] values corresponding to the chosen filter.
    // Could even use [1] and [2] for blue1 and blue2.... but will not!
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confPHOTblu and confPHOTred
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,0,0,0,0,0,0,0,0}];
    // Define paramsPHOT, a "tuple of tuples"
    // Estimator module returns {confPHOTblu,confPHOTred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // including a new section for Low Gain implementation SCR4196
    bool isBrightPacs = false;
    string calUFile = "isBrightPacsTrigger";
    // section defining triggering Fluxes (to be read in CALU table)
    double fluxPntRedTriggerLowGain = dlookup(calUFile,"Red","fluxPntTrigger");
    if(blue == "blue1") {
        double fluxPntBluTriggerLowGain = dlookup(calUFile,"Blue","fluxPntTrigger");
    } else {
        if(blue == "blue2") {
            fluxPntBluTriggerLowGain = dlookup(calUFile,"Green","fluxPntTrigger");
        }
    }
    double fluxExtRedTriggerLowGain = dlookup(calUFile,"Red","fluxExtTrigger");
    if(blue == "blue1") {
        double fluxExtBluTriggerLowGain = dlookup(calUFile,"Blue","fluxExtTrigger");
    } else {
        if(blue == "blue2") {
            fluxExtBluTriggerLowGain = dlookup(calUFile,"Green","fluxExtTrigger");
        }
    }
    // section test 
    if(fluxPntRedTriggerLowGain <= fluxPntRed || fluxPntBluTriggerLowGain <= fluxPntBlu || fluxExtRedTriggerLowGain <= fluxExtRed || fluxExtBluTriggerLowGain <= fluxExtBlu) {
        isBrightPacs = true;
    }
    // Obtain default values for "Prime" mode
    paramsPHOT = PacsPhotDefaults(srcID,"Prime",isBrightPacs,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    confPHOTred[0] = paramsPHOT{1};
    confOBCP[0] = paramsPHOT{2};
    // Intercept confPHOT and confOBCP with user given parameters
    // GAIN
    confPHOTblu[0]{0} = gain_blu;
    confPHOTred[0]{0} = gain_red;
    // Compression mode    
    confPHOTblu[0]{3} = comp_mode_blu;
    confPHOTred[0]{3} = comp_mode_red;
    // There is no useful confOBCP in PhotDefaults    
    // Now comes the module to estimate PACS parameters as a function of the
    // exposure time given by the user.
    // paramsPHOText (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,repeat_factor,nhold,dummy2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsPHOText = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for given HSPOT input. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("++Photo: confOBCP[0]: " + confOBCP[0]);
    }
    paramsPHOText = PacsPhotEstimatorOBCPn(pointCase,blue,repFactor,paramsPHOT,noddingSel,dither,verbose);
    // Copy estimates to respective tuples
    confPHOTblu[1] = paramsPHOText{0};
    confPHOTred[1] = paramsPHOText{1};
    confOBCP[1] = paramsPHOText{2};
    int nb_nods = paramsPHOText{3}{0};
    int repeat_factor = paramsPHOText{3}{1};
    // nhold is user defined
    //  int nhold         = paramsPHOText{3}{2}; 
    // Intercept confOBCP with user given values
    confOBCP[1]{0} = nb_main_loops;
    confOBCP[1]{1} = max_dither;
    if(!dither) {
        confOBCP[1]{1} = 0;
    }
    confOBCP[1]{2} = 1;
    confOBCP[1]{3} = nb_SRC_REF;
    confOBCP[1]{4} = nb_rdouts_plateau;
    confOBCP[1]{5} = nb_CS1_CS2;
    ///////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source.
    // We have to collect the duration of all TCs that will be released after the
    // PointingRequest 
    // First TC is associated with setting OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // Will call PacsPhotSlewCal to perform AOT prologue and CAL during
    // slew (with prologue):
    bool doProlog = true;
    int timeSlewCalProlog = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue));
    if(verbose) {
        debug_print("Duration of SlewCalProlog: " + timeSlewCalProlog);
    }
    // Cal during "hold" cycles" (no prologue)
    doProlog = false;
    int timeSlewCal = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue));
    if(verbose) {
        debug_print("Duration of SlewCal: " + timeSlewCal);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsPhotCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsPhotCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // Duration of any nod leg or staring observation
    // Use OBCP3 for point source
    // Use OBCP4 for all others, except scan mode
    if(pointCase == 11 || pointCase == 12) {
        int timeOBS = duration(PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        if(verbose) {
            debug_print("TimeOBS OBCP3: " + timeOBS);
        }
    }
    if(pointCase == 22 || pointCase == 31) {
        timeOBS = duration(PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        if(verbose) {
            debug_print("TimeOBS OBCP4: " + timeOBS);
        }
    }
    if(pointCase == 33) {
        //    Estimate how long OBCP7 has to run to cover a scan leg
        //    Scan speed (CAL-U FILE in new version??). Default is "low": 10 arcsec/sec
        double rate = 10.0;
        if(mapScanSpeed == "medium") {
            rate = 20.0;
        }
        if(mapScanSpeed == "high") {
            rate = 60.0;
        }
        double timeLEG = mapScanLegLength * 60.0 / rate;
        int tWrite = duration(PacsBbWriteIdBB());
        int tWriteEnd = imax(1,duration(PacsBbWriteEndBB()));
        //       int timeSetOBCP2 = duration(OBCP_TimeSynch3());
        timeOBS = iceil(timeLEG);
    }
    if(verbose) {
        debug_print("confOBCP[1]: " + confOBCP[1]);
        debug_print("==> Duration OBCP: " + timeOBS + " [sec] per nod; pointCase: " + pointCase);
    }
    // Finally deal with PHOT_aot_epilogue and WriteEndID
    int timeEpilogue = duration(PHOT_aot_epilogue());
    debug_print("PHOT_aot_epilogue: " + timeEpilogue);
    int timeEndID = duration(WriteEndID());
    timeEpilogue = timeEpilogue + timeEndID;
    if(verbose) {
        debug_print("Duration aot_epilogue: " + timeEpilogue);
    }
    // We have all elements to issue a Pointing Request and generate TCs
    // - duration of SlewCAL
    // - duration of OBS (one pointing)
    // - nb of nods or nb of raster points
    // - nhold
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    //  The nodding step has been estimated already (PacsPhotDefaults). However,
    //  there are no provisions to carry that information here. Easiest is to
    //  read again the relevant CAL-U table
    //  Read nod amplitude [arcsec]
    double nodThrow = dlookup("PHOT_CHOP_params",srcID,"NOD");
    max_dither = confOBCP[1]{1};
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("TimeSlewCal   : " + timeSlewCal);
        debug_print("TimeOBS       : " + timeOBS);
        debug_print("m/n           : " + m + "/" + n);
        debug_print("nb_nods/repeat_factor/nhold: " + nb_nods + "/" + repeat_factor + "/" + nhold);
        debug_print("NOD amplitude for " + srcID + ": " + nodThrow + " [arcsec]");
        int chpSRC = confOBCP[1]{12};
        int chpREF1 = confOBCP[1]{13};
        int chpREF2 = confOBCP[1]{14};
        debug_print("#### CHOP SRC/REF1/REF2: " + chpSRC + "/" + chpREF1 + "/" + chpREF2);
        debug_print("CHOP dither: " + max_dither);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Issue pointing request
    // Virtual aperture
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("##Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("##skewCorrec : " + skewCorrec);
    }
    // SCAN/RASTER orientation for "scan map" and "chopped raster"
    // RASTER defines mapRasterAngleRef   = "inst" in ["inst", "i+c"];
    // SCAN defines   mapScanAngleRef = "sky" in ["sky", "inst", "s+c", "i+c"]; 
    // By default S/C moves in instrument coordinates
    bool useINST = true;
    if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
        useINST = false;
    }
    // Act according to pointCase
    // POINT source, i.e. 3.4 nodding_pointing
    if(pointCase == 12) {
        //  Issue pointing request (when possible use JBr's variable names for clarity)
        //  SlewCal during slew
        string ib = "P01_0";
        int tslewmin = timeSetOBSID + timeSlewCalProlog;
        int tih = 0;
        int tfh = timeEpilogue;
        bool fixed = false;
        double pattnod = 0.0 + skewCorrec;
        int nnods = nb_nods;
        int tp = timeOBS;
        int tloadslewmin = 0;
        int nload = 0;
        int thold = timeSlewCal;
        //  int nhold        Already defined
        //  Do not start at nod position
        startAtOFF = false;
        int[] fromPntReq = nodding_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nnods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
        if(verbose) {
            debug_print("##### nodding_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tss = fromPntReq[2];
        tload = fromPntReq[3];
    }
    // SMALL source or LARGE raster with nodding
    if(pointCase == 22 || pointCase == 32) {
        //  "nodding_raster_pointing" (3.6 in Pointing document)
        ib = "P01_0";
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        tih = 0;
        tfh = timeEpilogue;
        double patt = 0.0;
        //  Chopper moves along -Y-axis
        pattnod = 270.0 + skewCorrec;
        //  Chop nodThrow was already established
        //  nodThrow = From CAL-U table
        //      For small source there is no OFF
        int k = 0;
        fixed = false;
        int nrepeat = repeat_factor;
        double d1 = pointStep;
        double d2 = lineStep;
        thold = timeSlewCal;
        tp = timeOBS;
        nnods = nb_nods;
        //  New arguments for pointing request; will be dealt with next iteration
        int top = 0;
        nrepeat = repeat_factor;
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nnods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
        if(verbose) {
            debug_print("##### nodding_in_raster_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
    }
    // SMALL or LARGE source with no nodding 
    if(pointCase == 21 || pointCase == 31) {
        //      For large source user given OFF frequency
        if(pointCase == 31) {
            k = kOFF;
        }
        //  raster_pointing (mode 3.5)
        ib = "P01_0";
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        tih = 0;
        tfh = timeEpilogue;
        //  Perform raster in instrument coordinates
        fixed = false;
        //SPR-2431 Raster lines along y-axis
        patt = 90.0;
        d1 = pointStep;
        d2 = lineStep;
        tp = timeOBS;
        nrepeat = repeat_factor;
        thold = timeSlewCal;
        //DAC   From CAL file    nhold   = 0;
        //      If no OFF requested set top to zero; else equal to current OBCP
        if(kOFF == 0) {
            top = 0;
        } else {
            top = tp;
        }
        fromPntReq = raster_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
        if(verbose) {
            debug_print("##### raster_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        trep = fromPntReq[4];
        tsop = fromPntReq[5];
    }
    if(pointCase == 33) {
        //   line_scan_pointing. Keep (most of) JBr's variable names
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        // Scan speed (CAL-U FILE in new version??). Default is "low": 10 arcsec/sec
        rate = 10.0;
        if(mapScanSpeed == "medium") {
            rate = 20.0;
        }
        if(mapScanSpeed == "high") {
            rate = 60.0;
        }
        //  Case of homogeneous coverage
        double pi = 3.1415926535;
        //  degrees to radians    
        double dtor = 0.0;
        double rtod = 0.0;
        double halfDiag = 0.0;
        double halfDiagAngle = 0.0;
        dtor = 2.0 * pi / 360.0;
        rtod = 1.0 / dtor;
        halfDiag = sqrt(boloSSize * boloSSize + boloLSize * boloLSize) / 2.0;
        halfDiagAngle = atan(boloSSize / boloLSize) * rtod;
        // Add further constraint from RV (SPR-2889)
        // Add SPR-2699 further logic: mapScanAngleRef overrides ScanHom and ScanSquare
        if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
            mapScanHomCoverage = false;
            mapScanSquare = false;
        }
        //  Could simplify logic after SPR-2699 (mapScanHomCoverage cannot be true
        //  unless inst or i+c have been specified)
        if(mapScanHomCoverage == true && (mapScanAngleRef == "inst" || mapScanAngleRef == "i+c")) {
            mapScanCrossScan = halfDiag * (abs(sin(dtor * (mapScanAngle + 90.0 - halfDiagAngle))) + abs(cos(dtor * (90.0 - halfDiagAngle - mapScanAngle + 90.0))));
            if(verbose) {
                debug_print("New mapScancCross: " + mapScanCrossScan);
            }
        }
        // Case of square map request
        if(mapScanSquare == true && mapScanHomCoverage == true) {
            mapScanNumLegs = iceil(60.0 * (mapScanLegLength / mapScanCrossScan));
            if(verbose) {
                debug_print("New mapScanNumLegs: " + mapScanNumLegs);
            }
        }
        ib = "P01_0";
        tih = 0;
        tfh = timeEpilogue;
        //   Use instrument coordinates unless HSPOT says otherwise
        fixed = false;
        if(useINST == false) {
            fixed = true;
        }
        patt = mapScanAngle;
        n = mapScanNumLegs;
        d1 = 60.0 * mapScanLegLength;
        d2 = mapScanCrossScan;
        thold = timeSlewCal;
        nrepeat = repFactor;
        if(verbose) {
            debug_print("Map reference: " + mapScanAngleRef + "=" + fixed);
        }
        // Major change: Use scan with off. It is not possible not to have an OFF or else use a different
        // pointing request
        //      Perform OBCP7 during OFF
        //      If no OFF requested use original pointing request
        if(kOFF == 0) {
            fromPntReq = line_scan_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,n,d1,d2,rate,thold,nhold,nrepeat);
            tobs = fromPntReq[0];
            tslew = fromPntReq[1];
            tacc = fromPntReq[2];
            tdec = fromPntReq[3];
            tl = fromPntReq[4];
            tll = fromPntReq[5];
            trep = fromPntReq[6];
            int tend = fromPntReq[7];
        } else {
            top = timeOBS;
            k = kOFF;
            tloadmin = 0;
            nload = 0;
            // In this pointing, nhold is bound by nrepeat
            if(nhold > nrepeat) {
                nhold = nrepeat;
            }
            fromPntReq = line_scan_with_off_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,n,d1,d2,rate,k,top,raoff,decoff,nrepeat,thold,nhold,tloadmin,nload);
            tobs = fromPntReq[0];
            tslew = fromPntReq[1];
            tacc = fromPntReq[2];
            tdec = fromPntReq[3];
            tl = fromPntReq[4];
            tll = fromPntReq[5];
            tsop = fromPntReq[6];
            tload = fromPntReq[7];
            tend = fromPntReq[8];
        }
        //Info from API (nomenclature from Jon Br)
        if(verbose) {
            debug_print("##### line_scan_with_off_and_hold");
        }
        if(verbose) {
            debug_print("##### rate: " + rate + " arcsec/sec");
        }
        //   Here we calculate how long it takes to scan a line [sec]
        //   int scanTime = iceil(d1/rate);
        //   The "consistent" way of doing this is to rely on PntReq information
        int scanTime = tl;
        //   Gather the overheads
        int scanOVER = tacc + tdec;
    }
    if(verbose) {
        debug_print("PointReq:  " + fromPntReq + " for pointCase: " + pointCase);
        debug_print("PointMode: " + pointMode);
    }
    // End of "pointing" section
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
        debug_print("++++++++++++++++++++++++ State Machine");
    }
    // Initialize some "global" variables
    int totalOBStime = 0;
    int totalOBSover = 0;
    int totalCALtime = 0;
    int totalCALover = 0;
    int nbSCANlegs = 0;
    // Issue TCs
    int[] state = [0];
    int nbOBS = 0;
    while(state[0] >= 0) {
        state = next_state();
        //// STATE = SLEW
        if(state[0] == 1) {
            if(verbose) {
                int tNOW = time();
                debug_print("=== SLEW/CAL starts at: " + tNOW);
            }
            //     Set OBSID
            WriteOBSID($OBSID);
            doProlog = true;
            // ON TARGET SLEW
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            int[] calTime = PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue);
            totalCALtime = totalCALtime + calTime[3];
            totalCALover = totalCALover + calTime[0];
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW/CAL ends at: " + tNOW);
                debug_print("    TotalCalTime: " + totalCALtime);
            }
        } else {
            //// STATE = INIT_HOLD
            if(state[0] == 2) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== INIT_HOLD starts at: " + tNOW);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("=== INIT_HOLD ends at: " + tNOW);
                }
            } else {
                //// STATE = POINT
                if(state[0] == 3) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== POINT starts at: " + tNOW);
                    }
                    if(pointCase == 12) {
                        //       Observation includes chopping
                        int[] obsTime = PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                    } else {
                        //       Observation does includes chopping
                        obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                    }
                    totalOBStime = totalOBStime + obsTime[1] + obsTime[2];
                    totalOBSover = totalOBSover + obsTime[0];
                    nbOBS = nbOBS + 1;
                    if(verbose) {
                        debug_print("POINT: POINTobs: " + nbOBS);
                        tNOW = time();
                        debug_print("=== POINT ends at: " + tNOW);
                    }
                } else {
                    //// STATE = CAL_HOLD
                    if(state[0] == 6) {
                        doProlog = false;
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== CAL-HOLD starts at: " + tNOW);
                        }
                        calTime = PacsPhotSlewCal(false,confPHOTblu,confPHOTred,confOBCP,doProlog,blue);
                        totalCALtime = totalCALtime + calTime[3];
                        totalCALover = totalCALover + calTime[0];
                        if(verbose) {
                            debug_print("Accumulated CALtime: " + totalCALtime);
                            tNOW = time();
                            debug_print("=== CAL-HOLD ends at: " + tNOW);
                        }
                    } else {
                        //// STATE = NOD
                        if(state[0] == 7) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== NOD starts at: " + tNOW);
                            }
                            if(pointCase == 12) {
                                //       Observation includes chopping
                                obsTime = PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                            } else {
                                //       Observation does includes chopping
                                obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                            }
                            totalOBStime = totalOBStime + obsTime[1] + obsTime[2];
                            totalOBSover = totalOBSover + obsTime[0];
                            nbOBS = nbOBS + 1;
                            if(verbose) {
                                debug_print("NOD: NODobs: " + nbOBS);
                                tNOW = time();
                                debug_print("=== NOD ends at: " + tNOW);
                            }
                        } else {
                            //// STATE = LINE
                            if(state[0] == 8) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== SCAN starts at: " + tNOW);
                                }
                                PacsBbWriteIdBB();
                                //                                OBCP_TimeSynch3();
                                int tDelay = fromPntReq[4] - tWriteEnd;
                                delay(tDelay);
                                PacsBbWriteEndBB();
                                totalOBStime = totalOBStime + scanTime;
                                totalOBSover = totalOBSover + scanTime + scanOVER;
                                nbSCANlegs = nbSCANlegs + 1;
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== SCAN mode, leg: " + nbSCANlegs);
                                    debug_print("    TotalOBSTime: " + totalOBStime);
                                    debug_print("    tacctdec    : " + scanOVER);
                                    debug_print("=== SCAN ends at: " + tNOW);
                                }
                            } else {
                                /// STATE = OFF
                                if(state[0] == 4) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== OFF starts at: " + tNOW);
                                    }
                                    //                               If raster, repeat OBCP4
                                    if(pointCase == 31) {
                                        //       Observation does includes chopping
                                        obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                                    }
                                    //                  if Line ...
                                    if(pointCase == 33) {
                                        PacsBbWriteIdBB();
                                        tDelay = fromPntReq[4] - tWriteEnd;
                                        delay(tDelay);
                                        PacsBbWriteEndBB();
                                    }
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== OFF ends at: " + tNOW);
                                    }
                                } else {
                                    //// STATE = FINAL_HOLD
                                    if(state[0] == 5) {
                                        if(verbose) {
                                            tNOW = time();
                                            debug_print("=== FinalHOLD starts at: " + tNOW);
                                        }
                                        PHOT_aot_epilogue();
                                        WriteEndID();
                                        if(verbose) {
                                            tNOW = time();
                                            debug_print("=== FinalHOLD ends at: " + tNOW);
                                        }
                                    } else {
                                        //// STATE = END
                                        if(state[0] == -1) {
                                            tNOW = time();
                                            if(verbose) {
                                                debug_print("=== END state; time now: " + tNOW);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    int overOBS = totalOBSover - totalOBStime;
    int overCAL = totalCALover - totalCALtime;
    if(verbose) {
        debug_print("+++ OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("    totalOBStime :" + totalOBStime);
        debug_print("    totalOBSover :" + overOBS);
        debug_print("    totalCALtime :" + totalCALtime);
        debug_print("    totalCALover :" + overCAL);
    }
    // Time considerations
    // The "science" part of the observations lasts tobs seconds (tobs from
    // PointReq[0])
    // Time on source is totalOBStime. Hence
    int instrumentAndObservationOverhead = tobs - totalOBStime;
    // Begin "calculation" and report section
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "ObsMode: <B>" + shortDesc + "</B>";
    lineCnt = lineCnt + 1;
    // More pointing information
    if(pointCase == 12) {
        msgLine[lineCnt] = "<p>Chopper throw: " + nodThrow + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        double mapArea = boloArea;
        msgLine[lineCnt] = "<p>PHOTO footprint: " + dformat(boloLSize,2) + " x " + dformat(boloSSize,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>PHOTO area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    if(pointCase == 21 || pointCase == 31 || pointCase == 22) {
        msgLine[lineCnt] = "<p>Raster points/lines: " + m + "/" + n + "</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Step size: " + d1 + " x " + d2 + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        //   Mapped region
        double sizeL = boloLSize + double(m - 1) * d1;
        double sizeS = boloSSize + double(n - 1) * d2;
        mapArea = sizeL * sizeS;
        msgLine[lineCnt] = "<p>PHOTO observed size: " + dformat(sizeL,2) + " x " + dformat(sizeS,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>PHOTO observed area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    if(pointCase == 33) {
        msgLine[lineCnt] = "<p>ScanLeg: " + d1 + " [arcsec]; number of legs: " + n + "; leg separation: " + dformat(d2,1) + " [arcsec], scan speed: " + dformat(rate,2) + " [arcsec/sec]</p>";
        lineCnt = lineCnt + 1;
        //  For the mapped area assume that we scan along the Large side of bolo
        //  Size along scan line
        sizeL = d1 + boloSSize;
        //  Size covered by successive legs
        sizeS = boloLSize + double(n - 1) * d2;
        msgLine[lineCnt] = "<p>PHOTO observed size: " + dformat(sizeL,2) + " x " + dformat(sizeS,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        mapArea = sizeL * sizeS;
        msgLine[lineCnt] = "<p>PHOTO observed area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    // Nodding pattern
    msgLine[lineCnt] = "<h3> Nod pattern (as applicable)</h3>";
    lineCnt = lineCnt + 1;
    if(nb_nods == 0) {
        if(pointCase != 33) {
            msgLine[lineCnt] = " No nodding, S/C stays at nominal position<";
        } else {
            msgLine[lineCnt] = " No nodding, S/C is in line scan mode<";
        }
        lineCnt = lineCnt + 1;
    }
    if(nb_nods == 1) {
        msgLine[lineCnt] = "   A->B ";
        lineCnt = lineCnt + 1;
    }
    if(nb_nods == 2) {
        msgLine[lineCnt] = "   A->B B->A ";
        lineCnt = lineCnt + 1;
    }
    if(nb_nods > 2) {
        int aux1 = nb_nods - 2;
        msgLine[lineCnt] = "   A->B B->A and " + aux1 + " more A->B or B->A leg(s) ";
        lineCnt = lineCnt + 1;
    }
    // Add dithering bla-bla
    msgLine[lineCnt] = "<h3> Dithering information</h3>";
    lineCnt = lineCnt + 1;
    if(dither && pointCase == 12) {
        int half_dither = max_dither / 2;
        msgLine[lineCnt] = "<p> Three position spatial dithering performed with the chopper (" + max_dither + " and " + half_dither + " chopper engineering units)</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Dithering information is not applicable.</p>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "<h3> Duration information</h3>";
    lineCnt = lineCnt + 1;
    tNOW = time();
    msgLine[lineCnt] = "<p>AOT duration (w/overheads): " + tNOW + " [sec]</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p><I>(AOT duration comprises 'on-sky' plus setup and CAL during slew)</I></p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Breakdown of AOT duration:</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul><li>On-sky time (w/overheads): " + tobs + " [sec]</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>(actual on-sky time: " + totalOBStime + " [sec])</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Setup and CAL during slew (w/overheads): " + tslew + " [sec]</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>(actual calibration time: " + totalCALtime + " [sec])</li></ul>";
    lineCnt = lineCnt + 1;
    // The charged obsOverhead is the MAX between tslew, nominalOverhead 
    if(tslew > obsOverhead) {
        obsOverhead = tslew;
    }
    int tcharged = tobs + obsOverhead;
    msgLine[lineCnt] = "<p><b>AOT cost</b> (includes time to slew to source): " + tobs + " + " + obsOverhead + " = " + tcharged + " [sec]</p>";
    lineCnt = lineCnt + 1;
    // On-SRC time calculations start here
    // Uses new algorithm: on-SRC = totalOBStime*boloArea/mapArea
    // OBS times above is for all pointings. For a raster, have to divide
    // by number of raster positions, i.e. m*n
    if(pointCase != 33) {
        //   If steps are smaller than boloXSize, same sky will be seen several times
        //   Compute Short and Long dimension number of sightings (assume source is
        //   placed to maximize number of sightings, i.e. at the proper edge of bolo)
        // NOTE: exchanged pointStep and lineStep as suggested by Roland V.
        int nbShort = iceil(boloSSize / lineStep);
        //   Cannot be larger than m
        if(nbShort > m) {
            nbShort = m;
        }
        int nbLong = iceil(boloLSize / pointStep);
        //   Cannot be larger than n
        if(nbLong > n) {
            nbLong = n;
        }
        if(verbose) {
            debug_print("nbShort/nbLong: " + nbShort + "/" + nbLong);
        }
        //   Time per raster point
        double auxTIMEold = double(totalOBStime * nbShort * nbLong) / double(m * n);
        double auxTIME = double(totalOBStime) * boloArea / mapArea;
        //   Small source is a special case where by design the SRC is always in view
        if(pointCase == 22) {
            auxTIME = auxTIMEold;
        }
    } else {
        //   elementary integration time [sec] will be computed as "transit" time
        //   of the source across the BOLO detector
        //   Case of scan leg size smaller than boloSize
        double sizeAux = boloSSize;
        if(d1 <= boloSSize) {
            sizeAux = d1;
        }
        //   Assume source is 1st seen on row=1; each successive scan may see again
        //   the same sky region if mapScanCrossScan is smaller than bolo width.
        //   The number of times the same sky is scanned again:
        if(mapScanCrossScan != 0.0) {
            int nbCross = iceil(boloLSize / mapScanCrossScan);
            if(verbose) {
                debug_print("nbCross: " + nbCross);
            }
        } else {
            nbCross = repFactor;
        }
        //   nbCross cannot be larger than mapScanNumLegs
        if(nbCross > mapScanNumLegs) {
            nbCross = mapScanNumLegs;
        }
        if(verbose) {
            debug_print("nbCross: " + nbCross);
        }
        //   The "crossing time"
        double crossTime = sizeAux / rate;
        if(verbose) {
            debug_print("crossTime: " + crossTime);
        }
        //   AuxTime is "crossing time" * number of crossings * repFactor
        auxTIMEold = double(repFactor * nbCross) * crossTime;
        auxTIME = double(totalOBStime) * boloArea / mapArea;
    }
    if(verbose) {
        debug_print("AuxTIMEold: " + auxTIMEold + " [sec]");
        debug_print("AuxTIME   : " + auxTIME + " [sec]");
    }
    // Pass the pointing mode to RMS (may need it for SRC,REF considerations)
    double[] pixRMS = PacsPhotNoiseRMS(pointCase,blue,auxTIME);
    msgLine[lineCnt] = "<h3> Sensitivity information </h3>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Effective on-sky time (one spatial resolution element) : " + dformat(auxTIME,1) + " [sec]</p>";
    lineCnt = lineCnt + 1;
    // Point source or extended source
    if(pointCase == 11 || pointCase == 12) {
        msgLine[lineCnt] = "<p>Point RMS (red): " + dformat(pixRMS[0],1) + " [mJy]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Point RMS (blu): " + dformat(pixRMS[1],1) + " [mJy]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Point RMS (red): " + dformat(pixRMS[0],1) + " [mJy]; extended RMS " + dformat(pixRMS[2],2) + " [MJy/sr]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Point RMS (blu): " + dformat(pixRMS[1],1) + " [mJy]; extended RMS " + dformat(pixRMS[3],2) + " [MJy/sr]</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("PACS Photometer AOT",lineCnt,msgLine);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    // Everything below is new request from RV. Use variable names consistent
    // with input variables in PacsPhoto.def
    // Return demanded tuples
    // ID for band blue1 
    string bandBlue = "60-85";
    if(blue == "blue2") {
        bandBlue = "85-130";
    }
    double pntRMSBlue = pixRMS[1];
    // Watch out for infinite division!!
    // Better watch out for silly limits (SPR-2627)
    if(pntRMSBlue > 0.0010) {
        double pntSNBlu = fluxPntBlu / pntRMSBlue;
    } else {
        pntSNBlu = 0.0;
    }
    string bandRed = "130-210";
    double pntRMSRed = pixRMS[0];
    if(pntRMSRed > 0.0010) {
        double pntSNRed = fluxPntRed / pntRMSRed;
    } else {
        pntSNRed = 0.0;
    }
    double extRMSBlue = pixRMS[3];
    // Watch out for infinite division!!
    if(extRMSBlue > 0.0010) {
        double extSNBlu = fluxExtBlu / extRMSBlue;
    } else {
        extSNBlu = 0.0;
    }
    double extRMSRed = pixRMS[2];
    if(extRMSRed > 0.0010) {
        double extSNRed = fluxExtRed / extRMSRed;
    } else {
        extSNRed = 0.0;
    }
    {string,double,double,double,double,double,double}[] noiseSummary = [{bandBlue,fluxPntBlu,pntSNBlu,pntRMSBlue,fluxExtBlu,extSNBlu,extRMSBlue},{bandRed,fluxPntRed,pntSNRed,pntRMSRed,fluxExtRed,extSNRed,extRMSRed}];
    if(verbose) {
        debug_print("NoiseSumm: " + noiseSummary);
        debug_print("OBStime/CALtime/Overhead/chopthrow: " + totalOBStime + "/" + totalCALtime + "/" + instrumentAndObservationOverhead + "/" + nodThrow);
    }
    //  return {totalOBStime,totalCALtime,instrumentAndObservationOverhead,

    return {totalOBStime,fromPntReq[1],instrumentAndObservationOverhead,nodThrow,noiseSummary};
}

/////////////////////////////////////////////////////////////////////////////
/// $Id
/////////////////////////////////////////////////////////////////////////////
// Purpose       : Main module for PacsPhoto AOT
// CUS author    : DAC
// Script file   : PacsCal_PacsPhotoDAClowSpeed.txt
// Return values
// Description   : 
// This AOT has to cater to three different source morphologies:
// "point", "small", and "large". Each mode requires its own pointing modes.
// Available pointing modes (reference is to JBr's document):
// NOTE: All modes include operations during SLEW and operations at end of OBS.
// NOTE: Updated based on e-mail from MS dated 3-Dec-2005 (denoted UPDATE)
// NOTE: Updated after Saclay meeting
// ==== "point"
// no nodding                         2.1  fine_pointing
// nodding (includes "hold" periods)  3.4  nodding_pointing
// UPDATE: Nodding is always needed ==> eliminate fine_pointing
//
// ==== "small"
// (raster dimensions and steps TBD; expect 2x2 or 3x3)
// no nodding ("hold" periods and repetition) 2.13 repeated_raster_with_hold
// nodding ("hold" periods and no repetition) 2.12 nodding_in_raster
// UPDATE: Nodding always used ==> nodding_in_raster
//
// ==== "large"
// Can be RASTER or SCAN (freeze mode is based upon a SCANning PointMode)
// RASTER
// no nodding ("hold" periods and repetition) 2.13 repeated_raster_with_hold
// nodding ("hold" periods and no repetition) 2.12 nodding_in_raster
// UPDATE: Nodding not used ==> raster_pointing
//
// SCAN
// There is no nodding and no chopping. "Hold" periods are allowed (mode 2.14) 
// Leg length is restricted to 20 degrees. 
//
// Dependencies  : 
//
// Preconditions : 
//
// Comments      : Almost identical to PacsPhoto. Maid differences:
//                 - accept (from XHspot) the following variables:
//                   - nholdIN User defined "nhold", overrides CAL values
//                   - confphotoparams Non-standard CONF_PHOTOparams CAL file
//                   - obcpparams Non standard OBCP3params (point source) or 
//                     OBCP4params (small source) CAL files
//                 - Calls two PV dedicated AOT scripts (search _PV in code).
//                   These scripts accept confphotoparams and obcpparams  
// 
// History       : 0.1  19-may-2008 DAC PV version based on PacsPhoto.def
//                 - Added name of OBCP3params and CONF_PHOT_params files as
//                   input parameters. Activated "nhold" logic
//                 0.2 20-may-2008 DAC
//                 -  Mostly editorial changes (useful for the AOT version
//                    as well)
//                 0.3 21-may-2008 DAC
//                  - Make nhold an input variable, ignore values in CAL files
//                    (not for the AOT version, where "nhold" in CAL files
//                     seems more adequate)
//                 0.4 18-jul-2008 DAC 
//                    - Add OFF option to the SCAN mode
//                    - Remove unused mapScanConstrXX
//                    - Remove unused chopAvoidXX
//                    - Remove unused mapRasterConstrXX
//                    - Prompt user for
//                         - raoff, decoff     (needed for OFF)
//                         - gain              (in CONF_PHOT_params)
//                         - comp_mode         (in CONF_PHOT_params)
//                         - nb_main_loops     (in OBCP3params,OBCP4params)
//                         - nb_rdouts_plateau (in OBCP3params, OBCP4params)
//                         - max_dither        (in OBCP3params)
//                         - nhold             (in OBCP3params,OBCP4params)
//                         - nb_SRC_REF        (in OBCP4params)
//                         - nb_CS1_CS2        (in OBCP4params)
//                         - kOFF              user defined OFF repetition
//                    All user defined variables will overwrite values obtained
//                    from the associated CAL-U tables. Code *may* anounce
//                    such and such value but the actual numerical value will
//                    be the one given by the user.
//                 0.5  9-oct-2008 DAC Use line_scan_with_off_pointing to allow OFF positions
//
//                 Started from PacsCal_PacsPhotoDAC and inntroduced a new scan speed:
//                 "verylow" = 5 arcsec/s
//		   0.6 VD: introduced continuous scan speed set-up
//		   0.7 23-apr-2009 VD SPR 6482
//		   1.0 30-jun-2009 VD/TM SCR 1292: no OBCP running during scan legs: only
//                        WriteBBID and OBCP2 then delayed WriteEndID
//                 1.1 29-jul-2009 VD remove OBCP2, PACS-1845
//
{int,int,int,double,{string,double,double,double,double,double,double}[]} obs PacsCal_PacsPhotoDACSlowScan {
    string blue = "blue1" in ["blue1","blue2"];
    int repFactor = 1 in [1,1500]; // Repeat factor: i.e. nb of nods or rasters
    string source = "point" in ["point","small","largeRaster","largeScan","none"]; // Source size/Obs type
    /*     string mapScanSpeed = "high" in ["high","medium","low","verylow"]; // Scan rate */
    bool scanSpeedDefault = false; // use default Scan Speed 10.0 arcsec/sec
    double mapScanSpeed = 5.0; // Scan speed in arsec/sec
    double mapScanLegLength = 30.0 in [1.0,1200.0]; //Scan leg [arcmin]
    int mapScanNumLegs = 2 in [1,1500]; //Number of scan legs
    string mapScanAngleRef = "inst" in ["sky","inst","i+c","s+c"];
    double mapScanAngle = 0.0 in [0.0,360.0];
    double mapScanCrossScan = 2.0 in [2.0,480.0]; // Scan separation [arcsec]
    bool mapScanHomCoverage = true;
    bool mapScanSquare = false;
    double pointStep = 2.0 in [2.0,480.0];
    double lineStep = 2.0 in [2.0,480.0];
    string mapRasterAngleRef = "inst" in ["inst","i+c"];
    int m = 2 in [2,100];
    int n = 1 in [1,100];
    bool dither = false;
    int naifid = 0; //RA,DEC or SSO
    double fluxPntBlu = 116.0 in [0.0,2.0E7]; // Flux density in blue band mJy
    double fluxPntRed = 150.0 in [0.0,2.0E7]; // Flux density in red band mJy
    double fluxExtBlu = 116.0 in [0.0,2.0E7]; // Flux in blue band MJy/sr
    double fluxExtRed = 40.0 in [0.0,2.0E7]; // Flux in red band MJy/sr
    int obsOverhead = 180; // Slew overhead
    /*  Block of new user prompted variables      */
    int gain_red = 1 in [0,1]; //Gain: 0:HI, 1:LO
    int gain_blu = 1 in [0,1]; //Gain: 0:HI, 1:LO
    int comp_mode_red = 0; //Compression algorithm (red channel)
    int comp_mode_blu = 0; //Compression algorithm (blue channel)
    int nb_main_loops = 1; //Outermost counter in OBCP3
    int nb_rdouts_plateau = 15; //NbRDouts/plateau (must be 4*n-1)
    int max_dither = 1060; //Dithering for OBCP3
    int nhold = 0; //How often perform a CAL observations
    int kOFF = 0; //How often perform the OFF observation
    int nb_SRC_REF = 38; //Nb of SRC/REF chopper cycles
    int nb_CS1_CS2 = 0; //Number of CS1/CS2 chopper cycles 
    double ra = 0.0 in [0.0,360.0]; // RA of Target
    double dec = 0.0 in [-90.0,90.0]; // DEC of Target
    double raoff = 0.0; //Where OFF will be performed
    double decoff = 0.0; //Where OFF will be performed
    bool refSelected = false; // OFF position needed
    /*  End block of new user prompted variables             */
    /* End of input section */
}{
    // Begin "pointing" section
    // Overall "verbosity"
    bool verbose = true;
    // New nodding_pointing variable
    bool startAtOFF = false;
    // Conversion to deprecated variables
    bool noddingSel = true;
    if(source == "largeRaster") {
        string largeOptions = "raster";
        bool mapRasterSel = true;
        noddingSel = false;
    }
    if(source == "largeScan") {
        largeOptions = "scan";
        mapRasterSel = false;
        noddingSel = false;
    }
    int mapRasterNumCycles = repFactor;
    // Useful variables
    // Bolo size: Short Size, i.e. 32 pixels and Long Size [arcsec]
    double boloSSize = 1.75 * 60.0;
    double boloLSize = 3.5 * 60.0;
    double boloArea = boloSSize * boloLSize;
    // 
    // Set messages for HTML format
    message("<html>");
    message("<body>");
    // Pointing mode has not been established yet
    int pointCase = 0;
    // Determine the pointing mode
    if(source == "point") {
        //     Variable needed to obtain choper throw from CAl-U
        string srcID = "pointSRC";
        //     Just for completiness, define a 1x1 raster
        m = 1;
        n = 1;
        //     Fine pointing without nodding is disallowed (pointCase remain null)
        if(!noddingSel) {
            string pointMode = "basic_fine_pointing";
            string shortDesc = "Point source (no nodding)";
            // not allowed           pointCase        = 11;
        } else {
            pointMode = "nodding_pointing";
            shortDesc = "Point source (nodding and chopping)";
            pointCase = 12;
            string yzoffsetROW = "P" + pointCase;
        }
    }
    if(source == "small") {
        srcID = "smallSRC";
        //   Obtain the size of the raster from CAL-U "SMALL_SRC_params"
        m = ilookup("SMALL_SRC_params","PHOT","mRast");
        n = ilookup("SMALL_SRC_params","PHOT","nRast");
        pointStep = dlookup("SMALL_SRC_params","PHOT","pointStep");
        lineStep = dlookup("SMALL_SRC_params","PHOT","lineStep");
        if(!noddingSel) {
            pointMode = "raster_pointing";
            shortDesc = " Small source (no nodding)";
            //         not allowed
            //           pointCase = 21;
        } else {
            pointMode = "nodding_raster_pointing";
            shortDesc = "Small source (nodding and chopping)";
            pointCase = 22;
            yzoffsetROW = "P" + pointCase;
        }
    }
    // Large source in Raster Mode
    if(source == "largeRaster") {
        srcID = "largeSRC";
        if(!noddingSel) {
            pointMode = "raster_pointing";
            shortDesc = "Large source, raster mode (chopping and no nodding)";
            pointCase = 31;
            yzoffsetROW = "P" + pointCase;
        } else {
            pointMode = "nodding_in_raster";
            shortDesc = "Large source, raster mode (chopping and nodding)";
            //         not allowed
            //           pointCase = 32;
        }
    }
    // Large source in Scan Mode
    if(source == "largeScan") {
        srcID = "largeSRC";
        pointMode = "line_scan_pointing";
        shortDesc = "Large source, line scan mode (no chopping)";
        //     For consistency
        m = 1;
        n = mapScanNumLegs;
        pointCase = 33;
        yzoffsetROW = "P" + pointCase;
    }
    // If pointCase is still 0, then something went wrong with the PointMode logic...
    if(pointCase == 0) {
        error("NODDING is incompatible with source: " + source);
    }
    // The pointing mode has been established. Continue with other input data
    // from HSPOT
    if(verbose) {
        debug_print("================> PointMode: " + pointMode);
    }
    //
    // confPHOT arrays (red and blu) compared to confSPEC
    //                       PHOT name         SPEC name
    // confPHOTred{ 0}       gain              capa_red;
    // confPHOTred{ 1}       N/A               nb_rdouts_ramp_red;
    // confPHOTred{ 2}       N/A               nb_rdouts_subramp_red;
    // confPHOTred{ 3}       same              comp_mode_red;
    // confPHOTred{ 4}       same              glitch_det_red;
    // confPHOTred{ 5}       ??                ramp_fit_alg_red;
    // confPHOTred{ 6        ??                nb_raw_red;
    // confPHOTred{ 7}       N/A               bias_r_red;
    // confPHOTred{ 8}       N/A               bias_d_red;
    //
    // Define confOBCP array.
    // NOTE: the conf arrays are inherited from PacsSpec, where the [0] element
    // represented the default values, and the [n] element represented values
    // to be used with the n-th wavelength. Here - PHOT - [0] still represents
    // the default values and [1] values corresponding to the chosen filter.
    // Could even use [1] and [2] for blue1 and blue2.... but will not!
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    // Define confPHOTblu and confPHOTred
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,0,0,0,0,0,0,0,0}];
    // Define paramsPHOT, a "tuple of tuples"
    // Estimator module returns {confPHOTblu,confPHOTred,confOBCP}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsPHOT = {clone(confPHOTblu[0]),clone(confPHOTred[0]),clone(confOBCP[0])};
    // including a new section for Low Gain implementation SCR4196
    bool isBrightPacs = false;
    string calUFile = "isBrightPacsTrigger";
    // section defining triggering Fluxes (to be read in CALU table)
    double fluxPntRedTriggerLowGain = dlookup(calUFile,"Red","fluxPntTrigger");
    if(blue == "blue1") {
        double fluxPntBluTriggerLowGain = dlookup(calUFile,"Blue","fluxPntTrigger");
    } else {
        if(blue == "blue2") {
            fluxPntBluTriggerLowGain = dlookup(calUFile,"Green","fluxPntTrigger");
        }
    }
    double fluxExtRedTriggerLowGain = dlookup(calUFile,"Red","fluxExtTrigger");
    if(blue == "blue1") {
        double fluxExtBluTriggerLowGain = dlookup(calUFile,"Blue","fluxExtTrigger");
    } else {
        if(blue == "blue2") {
            fluxExtBluTriggerLowGain = dlookup(calUFile,"Green","fluxExtTrigger");
        }
    }
    // section test 
    if(fluxPntRedTriggerLowGain <= fluxPntRed || fluxPntBluTriggerLowGain <= fluxPntBlu || fluxExtRedTriggerLowGain <= fluxExtRed || fluxExtBluTriggerLowGain <= fluxExtBlu) {
        isBrightPacs = true;
    }
    // Obtain default values for "Prime" mode
    paramsPHOT = PacsPhotDefaults(srcID,"Prime",isBrightPacs,verbose);
    // Array [0] of paramsPHOT contains the default values; array [1]
    // will contain the values based on HSPOT input. Array [1] is a copy of [0];
    // only elements depending on HSPOT will be updated
    // Copy default values to individual "conf" tuples
    confPHOTblu[0] = paramsPHOT{0};
    confPHOTred[0] = paramsPHOT{1};
    confOBCP[0] = paramsPHOT{2};
    // Intercept confPHOT and confOBCP with user given parameters
    // GAIN
    confPHOTblu[0]{0} = gain_blu;
    confPHOTred[0]{0} = gain_red;
    // Compression mode    
    confPHOTblu[0]{3} = comp_mode_blu;
    confPHOTred[0]{3} = comp_mode_red;
    // There is no useful confOBCP in PhotDefaults    
    // Now comes the module to estimate PACS parameters as a function of the
    // exposure time given by the user.
    // paramsPHOText (for extended) includes possible Pointing info (for
    // instance nb_nods).
    // Current "ext" contains: {nb_nods,repeat_factor,nhold,dummy2}
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} paramsPHOText = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0}};
    // Establish observing conditions for given HSPOT input. Estimate algorithm
    // also needs to know if nodding is allowed or not
    if(verbose) {
        debug_print("++Photo: confOBCP[0]: " + confOBCP[0]);
    }
    paramsPHOText = PacsPhotEstimatorOBCPn(pointCase,blue,repFactor,paramsPHOT,noddingSel,dither,verbose);
    // Copy estimates to respective tuples
    confPHOTblu[1] = paramsPHOText{0};
    confPHOTred[1] = paramsPHOText{1};
    confOBCP[1] = paramsPHOText{2};
    int nb_nods = paramsPHOText{3}{0};
    int repeat_factor = paramsPHOText{3}{1};
    // nhold is user defined
    //  int nhold         = paramsPHOText{3}{2}; 
    // Intercept confOBCP with user given values
    confOBCP[1]{0} = nb_main_loops;
    confOBCP[1]{1} = max_dither;
    if(!dither) {
        confOBCP[1]{1} = 0;
    }
    confOBCP[1]{2} = 1;
    //confOBCP[1]{2} = 1;
    confOBCP[1]{3} = nb_SRC_REF;
    confOBCP[1]{4} = nb_rdouts_plateau;
    confOBCP[1]{5} = nb_CS1_CS2;
    ///////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////
    // Start computations for the "pre-calibration" cycle. This cycle to be
    // performed during the slew to the source.
    // We have to collect the duration of all TCs that will be released after the
    // PointingRequest 
    // First TC is associated with setting OBSID
    int timeSetOBSID = duration(WriteOBSID($OBSID));
    // Will call PacsPhotSlewCal to perform AOT prologue and CAL during
    // slew (with prologue):
    bool doProlog = true;
    int timeSlewCalProlog = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue));
    if(verbose) {
        debug_print("Duration of SlewCalProlog: " + timeSlewCalProlog);
    }
    // Cal during "hold" cycles" (no prologue)
    doProlog = false;
    int timeSlewCal = duration(PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue));
    if(verbose) {
        debug_print("Duration of SlewCal: " + timeSlewCal);
    }
    // Compute now the time needed to perform a single pointed OBS, i.e. a
    // single nod visit.
    //
    // Call PacsPhotCommand with all obtained parameters to get the
    // duration of observation (needed to issue Pointing Requests)
    // PacsPhotCommand generates all the TCs needed to perform either a 
    // Staring observation or any leg of a Raster observation.
    // Duration of any nod leg or staring observation
    // Use OBCP3 for point source
    // Use OBCP4 for all others, except scan mode
    if(pointCase == 11 || pointCase == 12) {
        int timeOBS = duration(PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        if(verbose) {
            debug_print("TimeOBS OBCP3: " + timeOBS);
        }
    }
    if(pointCase == 22 || pointCase == 31) {
        timeOBS = duration(PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose));
        if(verbose) {
            debug_print("TimeOBS OBCP4: " + timeOBS);
        }
    }
    if(pointCase == 33) {
        //    Estimate how long OBCP7 has to run to cover a scan leg
        //    Scan speed (CAL-U FILE in new version??). Default is "low": 10 arcsec/sec
        if(scanSpeedDefault) {
            double rate = 10.0;
        } else {
            rate = mapScanSpeed;
        }
        //        if(mapScanSpeed == "medium") {
        //            rate = 20.0;
        //        }
        //        if(mapScanSpeed == "high") {
        //            rate = 60.0;
        //        }
        //        if(mapScanSpeed == "verylow") {
        //            rate = 5.0;
        //        }
        double timeLEG = mapScanLegLength * 60.0 / rate;
        int tWrite = duration(PacsBbWriteIdBB());
        int tWriteEnd = duration(PacsBbWriteEndBB());
        //      int timeSetOBCP2 = duration(OBCP_TimeSynch3());
        timeOBS = iceil(timeLEG);
    }
    if(verbose) {
        debug_print("confOBCP[1]: " + confOBCP[1]);
        debug_print("==> Duration OBCP: " + timeOBS + " [sec] per nod; pointCase: " + pointCase);
    }
    // Finally deal with PHOT_aot_epilogue and WriteEndID
    int timeEpilogue = duration(PHOT_aot_epilogue());
    int timeEndID = duration(WriteEndID());
    timeEpilogue = timeEpilogue + timeEndID;
    if(verbose) {
        debug_print("Duration aot_epilogue: " + timeEpilogue);
    }
    // We have all elements to issue a Pointing Request and generate TCs
    // - duration of SlewCAL
    // - duration of OBS (one pointing)
    // - nb of nods or nb of raster points
    // - nhold
    // Define variables used to collect return values from PointReq
    // (Jon Brumfit's nomenclature)
    int tobs = 0;
    int tslew = 0;
    int tss = 0;
    int tload = 0;
    int tpp = 0;
    int tll = 0;
    int tnod = 0;
    int tsop = 0;
    int trep = 0;
    int tacc = 0;
    int tdec = 0;
    int tl = 0;
    int tlh = 0;
    //  The nodding step has been estimated already (PacsPhotDefaults). However,
    //  there are no provisions to carry that information here. Easiest is to
    //  read again the relevant CAL-U table
    //  Read nod amplitude [arcsec]
    double nodThrow = dlookup("PHOT_CHOP_params",srcID,"NOD");
    max_dither = confOBCP[1]{1};
    if(verbose) {
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("TimeSlewCal   : " + timeSlewCal);
        debug_print("TimeOBS       : " + timeOBS);
        debug_print("m/n           : " + m + "/" + n);
        debug_print("nb_nods/repeat_factor/nhold: " + nb_nods + "/" + repeat_factor + "/" + nhold);
        debug_print("NOD amplitude for " + srcID + ": " + nodThrow + " [arcsec]");
        int chpSRC = confOBCP[1]{12};
        int chpREF1 = confOBCP[1]{13};
        int chpREF2 = confOBCP[1]{14};
        debug_print("#### CHOP SRC/REF1/REF2: " + chpSRC + "/" + chpREF1 + "/" + chpREF2);
        debug_print("CHOP dither: " + max_dither);
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
        debug_print("++++++++++++++++++++++++++++++++++++++++++++++");
    }
    // Issue pointing request
    // Virtual aperture
    // Get x, y offsets and skewCorrec from the offset CALU file
    string offsetCALU = "PACSyzoffsets";
    double yoffset = dlookup(offsetCALU,yzoffsetROW,"yoffset");
    double zoffset = dlookup(offsetCALU,yzoffsetROW,"zoffset");
    double skewCorrec = dlookup(offsetCALU,yzoffsetROW,"skewCorrec");
    if(verbose) {
        debug_print("##Y/Z offsets: " + yoffset + "/" + zoffset);
        debug_print("##skewCorrec : " + skewCorrec);
    }
    // SCAN/RASTER orientation for "scan map" and "chopped raster"
    // RASTER defines mapRasterAngleRef   = "inst" in ["inst", "i+c"];
    // SCAN defines   mapScanAngleRef = "sky" in ["sky", "inst", "s+c", "i+c"]; 
    // By default S/C moves in instrument coordinates
    bool useINST = true;
    if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
        useINST = false;
    }
    // Act according to pointCase
    // POINT source, i.e. 3.4 nodding_pointing
    if(pointCase == 12) {
        //  Issue pointing request (when possible use JBr's variable names for clarity)
        //  SlewCal during slew
        string ib = "P01_0";
        int tslewmin = timeSetOBSID + timeSlewCalProlog;
        int tih = 0;
        int tfh = timeEpilogue;
        bool fixed = false;
        double pattnod = 0.0 + skewCorrec;
        int nnods = nb_nods;
        int tp = timeOBS;
        int tloadslewmin = 0;
        int nload = 0;
        int thold = timeSlewCal;
        //  int nhold        Already defined
        //  Do not start at nod position
        startAtOFF = false;
        int[] fromPntReq = nodding_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,pattnod,yoffset,zoffset,nnods,nodThrow,tp,tp,tloadslewmin,nload,thold,nhold,startAtOFF);
        if(verbose) {
            debug_print("##### nodding_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tss = fromPntReq[2];
        tload = fromPntReq[3];
    }
    // SMALL source or LARGE raster with nodding
    if(pointCase == 22 || pointCase == 32) {
        //  "nodding_raster_pointing" (3.6 in Pointing document)
        ib = "P01_0";
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        tih = 0;
        tfh = timeEpilogue;
        double patt = 0.0;
        //  Chopper moves along -Y-axis
        pattnod = 270.0 + skewCorrec;
        //  Chop nodThrow was already established
        //  nodThrow = From CAL-U table
        //      For small source there is no OFF
        int k = 0;
        fixed = false;
        int nrepeat = repeat_factor;
        double d1 = pointStep;
        double d2 = lineStep;
        thold = timeSlewCal;
        tp = timeOBS;
        nnods = nb_nods;
        //  New arguments for pointing request; will be dealt with next iteration
        int top = 0;
        nrepeat = repeat_factor;
        int trepeatmin = 0;
        int tloadmin = 0;
        nload = 0;
        fromPntReq = nodding_raster_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,thold,nhold,pattnod,nodThrow,nnods,k,top,raoff,decoff,nrepeat,trepeatmin,tloadmin,nload);
        if(verbose) {
            debug_print("##### nodding_in_raster_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tss = fromPntReq[3];
        tll = fromPntReq[4];
        tnod = fromPntReq[5];
        tload = fromPntReq[6];
        tsop = fromPntReq[7];
        trep = fromPntReq[8];
    }
    // SMALL or LARGE source with no nodding 
    if(pointCase == 21 || pointCase == 31) {
        //      For large source user given OFF frequency
        if(pointCase == 31) {
            k = kOFF;
        }
        //  raster_pointing (mode 3.5)
        ib = "P01_0";
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        tih = 0;
        tfh = timeEpilogue;
        //  Perform raster in instrument coordinates
        fixed = false;
        //SPR-2431 Raster lines along y-axis
        patt = 90.0;
        d1 = pointStep;
        d2 = lineStep;
        tp = timeOBS;
        nrepeat = repeat_factor;
        thold = timeSlewCal;
        //DAC   From CAL file    nhold   = 0;
        //      If no OFF requested set top to zero; else equal to current OBCP
        if(kOFF == 0) {
            top = 0;
        } else {
            top = tp;
        }
        fromPntReq = raster_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,nrepeat,thold,nhold,k,top,raoff,decoff);
        if(verbose) {
            debug_print("##### raster_pointing");
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tpp = fromPntReq[2];
        tll = fromPntReq[3];
        trep = fromPntReq[4];
        tsop = fromPntReq[5];
    }
    if(pointCase == 33) {
        //   line_scan_pointing. Keep (most of) JBr's variable names
        tslewmin = timeSetOBSID + timeSlewCalProlog;
        // Scan speed (CAL-U FILE in new version??). Default is "low": 10 arcsec/sec
        if(scanSpeedDefault) {
            rate = 10.0;
        } else {
            rate = mapScanSpeed;
        }
        //        if(mapScanSpeed == "medium") {
        //            rate = 20.0;
        //        }
        //        if(mapScanSpeed == "high") {
        //            rate = 60.0;
        //        }
        //        if(mapScanSpeed == "verylow") {
        //            rate = 5.0;
        //        }
        //  Case of homogeneous coverage
        double pi = 3.1415926535;
        //  degrees to radians    
        double dtor = 0.0;
        double rtod = 0.0;
        double halfDiag = 0.0;
        double halfDiagAngle = 0.0;
        dtor = 2.0 * pi / 360.0;
        rtod = 1.0 / dtor;
        halfDiag = sqrt(boloSSize * boloSSize + boloLSize * boloLSize) / 2.0;
        halfDiagAngle = atan(boloSSize / boloLSize) * rtod;
        // Add further constraint from RV (SPR-2889)
        // Add SPR-2699 further logic: mapScanAngleRef overrides ScanHom and ScanSquare
        if(mapScanAngleRef == "sky" || mapScanAngleRef == "s+c") {
            mapScanHomCoverage = false;
            mapScanSquare = false;
        }
        //  Could simplify logic after SPR-2699 (mapScanHomCoverage cannot be true
        //  unless inst or i+c have been specified)
        if(mapScanHomCoverage == true && (mapScanAngleRef == "inst" || mapScanAngleRef == "i+c")) {
            mapScanCrossScan = halfDiag * (abs(sin(dtor * (mapScanAngle + 90.0 - halfDiagAngle))) + abs(cos(dtor * (90.0 - halfDiagAngle - mapScanAngle + 90.0))));
            if(verbose) {
                debug_print("New mapScancCross: " + mapScanCrossScan);
            }
        }
        // Case of square map request
        if(mapScanSquare == true && mapScanHomCoverage == true) {
            mapScanNumLegs = iceil(60.0 * (mapScanLegLength / mapScanCrossScan));
            if(verbose) {
                debug_print("New mapScanNumLegs: " + mapScanNumLegs);
            }
        }
        ib = "P01_0";
        tih = 0;
        tfh = timeEpilogue;
        //   Use instrument coordinates unless HSPOT says otherwise
        fixed = false;
        if(useINST == false) {
            fixed = true;
        }
        patt = mapScanAngle;
        n = mapScanNumLegs;
        d1 = 60.0 * mapScanLegLength;
        d2 = mapScanCrossScan;
        thold = timeSlewCal;
        nrepeat = repFactor;
        if(verbose) {
            debug_print("Map reference: " + mapScanAngleRef + "=" + fixed);
        }
        // Major change: Use scan with off. It is not possible not to have an OFF or else use a different
        // pointing request
        //      Perform OBCP7 during OFF
        //      If no OFF requested use original pointing request
        if(kOFF == 0) {
            fromPntReq = line_scan_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,n,d1,d2,rate,thold,nhold,nrepeat);
        } else {
            top = timeOBS;
            k = kOFF;
            tloadmin = 0;
            nload = 0;
            // In this pointing, nhold is bound by nrepeat
            if(nhold > nrepeat) {
                nhold = nrepeat;
            }
            fromPntReq = line_scan_with_off_pointing(true,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,n,d1,d2,rate,k,top,raoff,decoff,nrepeat,thold,nhold,tloadmin,nload);
        }
        //Info from API (nomenclature from Jon Br)
        tobs = fromPntReq[0];
        tslew = fromPntReq[1];
        tacc = fromPntReq[2];
        tdec = fromPntReq[3];
        tl = fromPntReq[4];
        tll = fromPntReq[5];
        trep = fromPntReq[6];
        if(verbose) {
            debug_print("##### line_scan_with_off_and_hold");
        }
        if(verbose) {
            debug_print("##### rate: " + rate + " arcsec/sec");
        }
        //   Here we calculate how long it takes to scan a line [sec]
        //   int scanTime = iceil(d1/rate);
        //   The "consistent" way of doing this is to rely on PntReq information
        int scanTime = tl;
        //   Gather the overheads
        int scanOVER = tacc + tdec;
    }
    if(verbose) {
        debug_print("PointReq:  " + fromPntReq + " for pointCase: " + pointCase);
        debug_print("PointMode: " + pointMode);
    }
    // End of "pointing" section
}{
    ///////////////////////// start of "commanding" section //////////////////////
    if(verbose) {
        debug_print("++++++++++++++++++++++++ Start Command Section");
        debug_print("++++++++++++++++++++++++ with PointMode " + pointMode);
        debug_print("++++++++++++++++++++++++ State Machine");
    }
    // Initialize some "global" variables
    int totalOBStime = 0;
    int totalOBSover = 0;
    int totalCALtime = 0;
    int totalCALover = 0;
    int nbSCANlegs = 0;
    // Issue TCs
    int[] state = [0];
    int nbOBS = 0;
    while(state[0] >= 0) {
        state = next_state();
        //// STATE = SLEW
        if(state[0] == 1) {
            if(verbose) {
                int tNOW = time();
                debug_print("=== SLEW/CAL starts at: " + tNOW);
            }
            //     Set OBSID
            WriteOBSID($OBSID);
            doProlog = true;
            // ON TARGET SLEW
            if(tslew > tslewmin) {
                delay(tslew - tslewmin);
            }
            // Now, execute the standard calibration block pushed to the end of the slew
            tNOW = time();
            if(verbose) {
                debug_print("SLEW_CAL starts at   " + tNOW);
            }
            int[] calTime = PacsPhotSlewCal(verbose,confPHOTblu,confPHOTred,confOBCP,doProlog,blue);
            totalCALtime = totalCALtime + calTime[3];
            totalCALover = totalCALover + calTime[0];
            if(verbose) {
                tNOW = time();
                debug_print("=== SLEW/CAL ends at: " + tNOW);
                debug_print("    TotalCalTime: " + totalCALtime);
            }
        } else {
            //// STATE = INIT_HOLD
            if(state[0] == 2) {
                if(verbose) {
                    tNOW = time();
                    debug_print("=== INIT_HOLD starts at: " + tNOW);
                }
                if(verbose) {
                    tNOW = time();
                    debug_print("=== INIT_HOLD ends at: " + tNOW);
                }
            } else {
                //// STATE = POINT
                if(state[0] == 3) {
                    if(verbose) {
                        tNOW = time();
                        debug_print("=== POINT starts at: " + tNOW);
                    }
                    if(pointCase == 12) {
                        //       Observation includes chopping
                        int[] obsTime = PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                    } else {
                        //       Observation does includes chopping
                        obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                    }
                    totalOBStime = totalOBStime + obsTime[1] + obsTime[2];
                    totalOBSover = totalOBSover + obsTime[0];
                    nbOBS = nbOBS + 1;
                    if(verbose) {
                        debug_print("POINT: POINTobs: " + nbOBS);
                        tNOW = time();
                        debug_print("=== POINT ends at: " + tNOW);
                    }
                } else {
                    //// STATE = CAL_HOLD
                    if(state[0] == 6) {
                        doProlog = false;
                        if(verbose) {
                            tNOW = time();
                            debug_print("=== CAL-HOLD starts at: " + tNOW);
                        }
                        calTime = PacsPhotSlewCal(false,confPHOTblu,confPHOTred,confOBCP,doProlog,blue);
                        totalCALtime = totalCALtime + calTime[3];
                        totalCALover = totalCALover + calTime[0];
                        if(verbose) {
                            debug_print("Accumulated CALtime: " + totalCALtime);
                            tNOW = time();
                            debug_print("=== CAL-HOLD ends at: " + tNOW);
                        }
                    } else {
                        //// STATE = NOD
                        if(state[0] == 7) {
                            if(verbose) {
                                tNOW = time();
                                debug_print("=== NOD starts at: " + tNOW);
                            }
                            if(pointCase == 12) {
                                //       Observation includes chopping
                                obsTime = PacsPhotCommandOBCP3(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                            } else {
                                //       Observation does includes chopping
                                obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                            }
                            totalOBStime = totalOBStime + obsTime[1] + obsTime[2];
                            totalOBSover = totalOBSover + obsTime[0];
                            nbOBS = nbOBS + 1;
                            if(verbose) {
                                debug_print("NOD: NODobs: " + nbOBS);
                                tNOW = time();
                                debug_print("=== NOD ends at: " + tNOW);
                            }
                        } else {
                            //// STATE = LINE
                            if(state[0] == 8) {
                                if(verbose) {
                                    tNOW = time();
                                    debug_print("=== SCAN starts at: " + tNOW);
                                }
                                PacsBbWriteIdBB();
                                //                            OBCP_TimeSynch3();
                                int tDelay = fromPntReq[4] - tWrite;
                                delay(tDelay);
                                PacsBbWriteEndBB();
                                totalOBStime = totalOBStime + scanTime;
                                totalOBSover = totalOBSover + scanTime + scanOVER;
                                nbSCANlegs = nbSCANlegs + 1;
                                tNOW = time();
                                if(verbose) {
                                    debug_print("=== SCAN mode, leg: " + nbSCANlegs);
                                    debug_print("    TotalOBSTime: " + totalOBStime);
                                    debug_print("    tacctdec    : " + scanOVER);
                                    debug_print("=== SCAN ends at: " + tNOW);
                                }
                            } else {
                                /// STATE = OFF
                                if(state[0] == 4) {
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== OFF starts at: " + tNOW);
                                    }
                                    //                               If raster, repeat OBCP4
                                    if(pointCase == 31) {
                                        //       Observation does includes chopping
                                        obsTime = PacsPhotCommandOBCP4(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                                    }
                                    //                               If scan, repeat OBCP7
                                    if(pointCase == 33) {
                                        //       Observation does includes chopping
                                        obsTime = PacsPhotCommandOBCP7(confPHOTblu[1],confPHOTred[1],confOBCP[1],verbose);
                                    }
                                    if(verbose) {
                                        tNOW = time();
                                        debug_print("=== OFF ends at: " + tNOW);
                                    }
                                } else {
                                    //// STATE = FINAL_HOLD
                                    if(state[0] == 5) {
                                        if(verbose) {
                                            tNOW = time();
                                            debug_print("=== FinalHOLD starts at: " + tNOW);
                                        }
                                        PHOT_aot_epilogue();
                                        WriteEndID();
                                        if(verbose) {
                                            tNOW = time();
                                            debug_print("=== FinalHOLD ends at: " + tNOW);
                                        }
                                    } else {
                                        //// STATE = END
                                        if(state[0] == -1) {
                                            tNOW = time();
                                            if(verbose) {
                                                debug_print("=== END state; time now: " + tNOW);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int timeObsEnd = time();
    int overOBS = totalOBSover - totalOBStime;
    int overCAL = totalCALover - totalCALtime;
    if(verbose) {
        debug_print("+++ OBS ends at " + timeObsEnd + "; NbOBS: " + nbOBS);
        debug_print("    totalOBStime :" + totalOBStime);
        debug_print("    totalOBSover :" + overOBS);
        debug_print("    totalCALtime :" + totalCALtime);
        debug_print("    totalCALover :" + overCAL);
    }
    // Time considerations
    // The "science" part of the observations lasts tobs seconds (tobs from
    // PointReq[0])
    // Time on source is totalOBStime. Hence
    int instrumentAndObservationOverhead = tobs - totalOBStime;
    // Begin "calculation" and report section
    string[] msgLine = [" "];
    int lineCnt = 0;
    msgLine[lineCnt] = "ObsMode: <B>" + shortDesc + "</B>";
    lineCnt = lineCnt + 1;
    // More pointing information
    if(pointCase == 12) {
        msgLine[lineCnt] = "<p>Chopper throw: " + nodThrow + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        double mapArea = boloArea;
        msgLine[lineCnt] = "<p>PHOTO footprint: " + dformat(boloLSize,2) + " x " + dformat(boloSSize,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>PHOTO area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    if(pointCase == 21 || pointCase == 31 || pointCase == 22) {
        msgLine[lineCnt] = "<p>Raster points/lines: " + m + "/" + n + "</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Step size: " + d1 + " x " + d2 + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        //   Mapped region
        double sizeL = boloLSize + double(m - 1) * d1;
        double sizeS = boloSSize + double(n - 1) * d2;
        mapArea = sizeL * sizeS;
        msgLine[lineCnt] = "<p>PHOTO observed size: " + dformat(sizeL,2) + " x " + dformat(sizeS,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>PHOTO observed area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    if(pointCase == 33) {
        msgLine[lineCnt] = "<p>ScanLeg: " + d1 + " [arcsec]; number of legs: " + n + "; leg separation: " + dformat(d2,1) + " [arcsec], scan speed: " + dformat(rate,2) + " [arcsec/sec]</p>";
        lineCnt = lineCnt + 1;
        //  For the mapped area assume that we scan along the Large side of bolo
        //  Size along scan line
        sizeL = d1 + boloSSize;
        //  Size covered by successive legs
        sizeS = boloLSize + double(n - 1) * d2;
        msgLine[lineCnt] = "<p>PHOTO observed size: " + dformat(sizeL,2) + " x " + dformat(sizeS,2) + " [arcsec]</p>";
        lineCnt = lineCnt + 1;
        mapArea = sizeL * sizeS;
        msgLine[lineCnt] = "<p>PHOTO observed area: " + dformat(mapArea,0) + " [arcsec2]</p>";
        lineCnt = lineCnt + 1;
    }
    // Nodding pattern
    msgLine[lineCnt] = "<h3> Nod pattern (as applicable)</h3>";
    lineCnt = lineCnt + 1;
    if(nb_nods == 0) {
        if(pointCase != 33) {
            msgLine[lineCnt] = " No nodding, S/C stays at nominal position<";
        } else {
            msgLine[lineCnt] = " No nodding, S/C is in line scan mode<";
        }
        lineCnt = lineCnt + 1;
    }
    if(nb_nods == 1) {
        msgLine[lineCnt] = "   A->B ";
        lineCnt = lineCnt + 1;
    }
    if(nb_nods == 2) {
        msgLine[lineCnt] = "   A->B B->A ";
        lineCnt = lineCnt + 1;
    }
    if(nb_nods > 2) {
        int aux1 = nb_nods - 2;
        msgLine[lineCnt] = "   A->B B->A and " + aux1 + " more A->B or B->A leg(s) ";
        lineCnt = lineCnt + 1;
    }
    // Add dithering bla-bla
    msgLine[lineCnt] = "<h3> Dithering information</h3>";
    lineCnt = lineCnt + 1;
    if(dither && pointCase == 12) {
        int half_dither = max_dither / 2;
        msgLine[lineCnt] = "<p> Three position spatial dithering performed with the chopper (" + max_dither + " and " + half_dither + " chopper engineering units)</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Dithering information is not applicable.</p>";
        lineCnt = lineCnt + 1;
    }
    msgLine[lineCnt] = "<h3> Duration information</h3>";
    lineCnt = lineCnt + 1;
    tNOW = time();
    msgLine[lineCnt] = "<p>AOT duration (w/overheads): " + tNOW + " [sec]</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p><I>(AOT duration comprises 'on-sky' plus setup and CAL during slew)</I></p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Breakdown of AOT duration:</p>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<ul><li>On-sky time (w/overheads): " + tobs + " [sec]</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>(actual on-sky time: " + totalOBStime + " [sec])</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>Setup and CAL during slew (w/overheads): " + tslew + " [sec]</li>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<li>(actual calibration time: " + totalCALtime + " [sec])</li></ul>";
    lineCnt = lineCnt + 1;
    // The charged obsOverhead is the MAX between tslew, nominalOverhead 
    if(tslew > obsOverhead) {
        obsOverhead = tslew;
    }
    int tcharged = tobs + obsOverhead;
    msgLine[lineCnt] = "<p><b>AOT cost</b> (includes time to slew to source): " + tobs + " + " + obsOverhead + " = " + tcharged + " [sec]</p>";
    lineCnt = lineCnt + 1;
    // On-SRC time calculations start here
    // Uses new algorithm: on-SRC = totalOBStime*boloArea/mapArea
    // OBS times above is for all pointings. For a raster, have to divide
    // by number of raster positions, i.e. m*n
    if(pointCase != 33) {
        //   If steps are smaller than boloXSize, same sky will be seen several times
        //   Compute Short and Long dimension number of sightings (assume source is
        //   placed to maximize number of sightings, i.e. at the proper edge of bolo)
        // NOTE: exchanged pointStep and lineStep as suggested by Roland V.
        int nbShort = iceil(boloSSize / lineStep);
        //   Cannot be larger than m
        if(nbShort > m) {
            nbShort = m;
        }
        int nbLong = iceil(boloLSize / pointStep);
        //   Cannot be larger than n
        if(nbLong > n) {
            nbLong = n;
        }
        if(verbose) {
            debug_print("nbShort/nbLong: " + nbShort + "/" + nbLong);
        }
        //   Time per raster point
        double auxTIMEold = double(totalOBStime * nbShort * nbLong) / double(m * n);
        double auxTIME = double(totalOBStime) * boloArea / mapArea;
        //   Small source is a special case where by design the SRC is always in view
        if(pointCase == 22) {
            auxTIME = auxTIMEold;
        }
    } else {
        //   elementary integration time [sec] will be computed as "transit" time
        //   of the source across the BOLO detector
        //   Case of scan leg size smaller than boloSize
        double sizeAux = boloSSize;
        if(d1 <= boloSSize) {
            sizeAux = d1;
        }
        //   Assume source is 1st seen on row=1; each successive scan may see again
        //   the same sky region if mapScanCrossScan is smaller than bolo width.
        //   The number of times the same sky is scanned again:
        if(mapScanCrossScan != 0.0) {
            int nbCross = iceil(boloLSize / mapScanCrossScan);
            if(verbose) {
                debug_print("nbCross: " + nbCross);
            }
        } else {
            nbCross = repFactor;
        }
        //   nbCross cannot be larger than mapScanNumLegs
        if(nbCross > mapScanNumLegs) {
            nbCross = mapScanNumLegs;
        }
        if(verbose) {
            debug_print("nbCross: " + nbCross);
        }
        //   The "crossing time"
        double crossTime = sizeAux / rate;
        if(verbose) {
            debug_print("crossTime: " + crossTime);
        }
        //   AuxTime is "crossing time" * number of crossings * repFactor
        auxTIMEold = double(repFactor * nbCross) * crossTime;
        auxTIME = double(totalOBStime) * boloArea / mapArea;
    }
    if(verbose) {
        debug_print("AuxTIMEold: " + auxTIMEold + " [sec]");
        debug_print("AuxTIME   : " + auxTIME + " [sec]");
    }
    // Pass the pointing mode to RMS (may need it for SRC,REF considerations)
    double[] pixRMS = PacsPhotNoiseRMS(pointCase,blue,auxTIME);
    msgLine[lineCnt] = "<h3> Sensitivity information </h3>";
    lineCnt = lineCnt + 1;
    msgLine[lineCnt] = "<p>Effective on-sky time (one spatial resolution element) : " + dformat(auxTIME,1) + " [sec]</p>";
    lineCnt = lineCnt + 1;
    // Point source or extended source
    if(pointCase == 11 || pointCase == 12) {
        msgLine[lineCnt] = "<p>Point RMS (red): " + dformat(pixRMS[0],1) + " [mJy]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Point RMS (blu): " + dformat(pixRMS[1],1) + " [mJy]</p>";
        lineCnt = lineCnt + 1;
    } else {
        msgLine[lineCnt] = "<p>Point RMS (red): " + dformat(pixRMS[0],1) + " [mJy]; extended RMS " + dformat(pixRMS[2],2) + " [MJy/sr]</p>";
        lineCnt = lineCnt + 1;
        msgLine[lineCnt] = "<p>Point RMS (blu): " + dformat(pixRMS[1],1) + " [mJy]; extended RMS " + dformat(pixRMS[3],2) + " [MJy/sr]</p>";
        lineCnt = lineCnt + 1;
    }
    PacsMessageCenter("PACS Photometer AOT",lineCnt,msgLine);
    // Close messages for HTML format
    message("</html>");
    message("</body>");
    // Everything below is new request from RV. Use variable names consistent
    // with input variables in PacsPhoto.def
    // Return demanded tuples
    // ID for band blue1 
    string bandBlue = "60-85";
    if(blue == "blue2") {
        bandBlue = "85-130";
    }
    double pntRMSBlue = pixRMS[1];
    // Watch out for infinite division!!
    // Better watch out for silly limits (SPR-2627)
    if(pntRMSBlue > 0.0010) {
        double pntSNBlu = fluxPntBlu / pntRMSBlue;
    } else {
        pntSNBlu = 0.0;
    }
    string bandRed = "130-210";
    double pntRMSRed = pixRMS[0];
    if(pntRMSRed > 0.0010) {
        double pntSNRed = fluxPntRed / pntRMSRed;
    } else {
        pntSNRed = 0.0;
    }
    double extRMSBlue = pixRMS[3];
    // Watch out for infinite division!!
    if(extRMSBlue > 0.0010) {
        double extSNBlu = fluxExtBlu / extRMSBlue;
    } else {
        extSNBlu = 0.0;
    }
    double extRMSRed = pixRMS[2];
    if(extRMSRed > 0.0010) {
        double extSNRed = fluxExtRed / extRMSRed;
    } else {
        extSNRed = 0.0;
    }
    {string,double,double,double,double,double,double}[] noiseSummary = [{bandBlue,fluxPntBlu,pntSNBlu,pntRMSBlue,fluxExtBlu,extSNBlu,extRMSBlue},{bandRed,fluxPntRed,pntSNRed,pntRMSRed,fluxExtRed,extSNRed,extRMSRed}];
    if(verbose) {
        debug_print("NoiseSumm: " + noiseSummary);
        debug_print("OBStime/CALtime/Overhead/chopthrow: " + totalOBStime + "/" + totalCALtime + "/" + instrumentAndObservationOverhead + "/" + nodThrow);
    }
    //  return {totalOBStime,totalCALtime,instrumentAndObservationOverhead,

    return {totalOBStime,fromPntReq[1],instrumentAndObservationOverhead,nodThrow,noiseSummary};
}

// Missionphase  : PACS FM Test
//
// Purpose       : Switch on of bolometer groups
//
// Author        : T. Mueller
//
// File          : PHOT_switchon_groups
// Arguments     : none
//                 
//
// Description   : This script will switch on the different groups
//                 of the instrument. BOLC will start in "HK only" mode.
//                              
// Comments      :  Coded based on PhFPU UM, Draft 5
//                          SCR PACS-1866
//
// Version       : 1.1
// History       : 1.0 / 08-Nov-2006 initial version by TM
//                    1.1 / 08-Nov-2006 TM: autonomy function 17 added
//                    1.1.1 14-nov-2006 Disable autonomy function for time being
//                    1.2 17-nov-2006 Enable AF with delay after switchon
//                    1.3 09-apr-2007 disable AFs before starting
//                 1.0 Modified from PHOT_switchon_groups and keep G5 and 6 off
// 
procedure PHOT_switchon_1234 {
}{
    // disable AF 12, AF 15, AF 17
    // disable AF 12 (to check for the protection biases)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_BIAS","DISABLE");
    // disable AF 15 (to check for the VSS currents of groups and BUs)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_I_RO","DISABLE");
    // disable AF 17 (to check for group power)
    Pacs_DPU_SET_FUNCT("EVENT_BOL_V_PWR","DISABLE");
    //
    delay(2);
    // PC103420 "DMC_SEND_COMMAND_BOLC" SEND COMMAND TO BOL CONTROLLER
    //         PP071420 "BOLOMETER_COMMAND"
    //
    // # Execute BOLC initialisation
    // # for CQM we switched on everything at once, now group by
    // # group starting with 1
    // 
    // # Switch-on group 1 The corresponding bits
    // # are (2^0)=1, which is 1 in hex.
    // tcsend PC103420 {PP071420 0x0A000001 LO}
    // waittime 1.0
    int operand = 0xa000001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2. The corresponding bits
    // # are (2^0+2^1)=3, which is 3 in hex.
    // tcsend PC103420 {PP071420 0x0A000003 LO}
    // waittime 1.0
    operand = 0xa000003;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3. The corresponding bits
    // # are (2^0+2^1+2^2)=7, which is 7 in hex.
    // tcsend PC103420 {PP071420 0x0A000007 LO}
    // waittime 1.0
    operand = 0xa000007;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // # Switch-on groups 1,2,3,4. The corresponding bits
    // # are (2^0+2^1+2^2+2^3)=15, which is F in hex.
    // tcsend PC103420 {PP071420 0x0A00000F LO}
    // waittime 1.0
    operand = 0xa00000f;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    //delay(1);
    // # Switch-on groups 1,2,3,4,5. The corresponding bits
    // # are (2^0+2^1+2^2+2^3+2^4)=31, which is 1F in hex.
    // tcsend PC103420 {PP071420 0x0A00001F LO}
    // waittime 1.0
    //operand = 0xa00001f;
    //Pacs_DMC_SEND_COMMAND_BOLC(operand);
    //delay(1);
    // # Switch-on groups 1,2,3,4,5,6. The corresponding bits
    // # are (2^0+2^1+2^2+2^3+2^4+2^5)=63, which is 3F in hex.
    // tcsend PC103420 {PP071420 0x0A00003F LO}
    // waittime 1.0
    //operand = 0xa00003f;
    //Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(8);
    //------------------------------------
    // autonomy function
    //------------------------------------
    // autonomy function 17 "generate_event_pwr" checks the
    // HK entries: PC_PWR_ANA_P_#, PC_PWR_ANA_N_# and PC_PWR_DIG_#,
    // with # = [1,2,3,4,5,6,7]
    //Pacs_DPU_SET_FUNCT("EVENT_BOL_V_PWR","ENABLE");
    // Wait another 2 sec
    delay(2);
    //
    //-----------------
    // End of Procedure
    //-----------------
}

// $Id: SPEC_spu_setup.txt,v 1.6 2007/08/09 15:40:11 dcesarsk Exp $
//
// Missionphase  : PACS ILT
//
// Purpose       : Condition SPU for SPECtroscopy observations
//                  
// TCL author    : Thomas Mueller
// TCL file      : tm_spec_spu_setup.tcl, version 1.3
//                    SetupSpectroscopyWEplusFPUsim.tcl v2.8
// CUS author    : Diego Cesarsky
// Script file   : SPEC_spu_setup.txt 
//
// Input arguments
// Type Name           Default   Description
// int  comp_mode_blu  16        Compression mode Default=16; double=17;
//                               lossless=20; transp=23; 4sec reset=24; 
//                               buffer_mode=25, noise=33
// int  comp_mode_red  16        As above for RED
// int  nb_samp_subramp_blu 64   Number of samples per sub-ramp 
//                               (>=4 and <= readouts per ramp)
// int  nb_samp_subramp_red 64   As above for RED
// int  spu_nraw_blu     3       Number of raw channels transmitted by SPU
// int  spu_nraw_red     3       As above for RED
// int  glitch_det       1       Glitch detection; 0=on; 1=off
// int  ramp_fit_alg     1       Ramp fit algorithm: 0=LstSq fit,1=mean value
// bool startSPU      true       Start SPU after setting values
//
// Description   : Sets values for compression mode,
//                 threshold values (glitch, chopper, grating), raw 
//                 channel transmission, sub-ramp and detector
//                 constants, load DPU time and restart SPU. Script
//                 sets its own delays [sec] and returns the total
//                 duration in milliseconds. This version addresses
//                 BLU and RED; could make a BLU only and RED only version
//                 The call sequence to this module is as follows:
//  PacsXXXXSpec->PacsSpecDefault->
//  PacsSpecSlewCal->SPEC_aot_prologue->SPEC_spu_setup 
//                  
// Dependencies  : PACS TCs
//
// Preconditions :
//                 
// Comments      : Based on V1.3 of TM's tm_spu_setup.tcl. Both
//                 SPUS and SPUL are initialized to same set of parameters
//
// Version         1.0
// History       : 0.1 13-Aug-2004 First creation
// 0.2  8-Oct-2004 Added separate variables for SPUL and
//                                 SPUS. Return duration.
//                                 Editorial changes (DAC)
// 0.3 12-Oct-2004 Reviewed after simplification of 
//                                 SPEC_spu_reset. Remove
//                                 redundant/useless TCs. Removed "delay"
//                                 statements
// 0.4 13-Oct-2004 Error in Pacs_SPUx_RAW_CHAN_TRAN_MODE:
//                                 second parameter should be spuX_nraw.
//                                 Added boolean START to be able to use
//                                 this procedure in SPEC_orbit_prologue
//                                 which DOES NOT start the SPU 
// 0.5 21-Oct-2004 Moved xx_RAW_CHAN_TRAN_MODE below 
//                                 WRT_DET_CST_SPEC to follow HF's setup script
// 0.6 18-Mar-2005 Redone to follow line by line TM's script,
//                                 Added several comments
// 0.7 10-Apr-2006 Parameter set has been changed for
//                 Pacs_SPUL_WRT_DET_CST_SPEC and      (RV)
//                 Pacs_SPUS_WRT_DET_CST_SPEC commands (comply w/SPU HLSW v12.1)
//                 "spu_par" has been changed, new parameters have been added:
//                  - "reor", Reordering algorithm
//                  - "llcs", Lossless compression algorith
//                  - "ords", Range for the PACS codec
//                 Changes based on SetupSpectroscopyWEplusFPUsim.tcl v2.8
// 0.8  3-jul-2006 Remove duration references
// 0.9  9-aug-2006 update of WRT_DET_CST_SPEC
// 0.91  29-aug-2006 TM: update of WRT_DET_CST_SPEC (SPU OBSW V12.8), new default values
// 0.92  06-dec-2006 TM: update of WRT_DET_CST_SPEC (SPU OBSW V12.8.1), new default values
// 1.0   28-mar-2007 DAC Update for SPU V13.x
// 1.1   24-mar-2009 DAC Update after SPU UM 13.95a
// 2.0   17-jun-2009 DAC Introduced reading of CONF_SPEC_param but for time 
//                       being I have no solution how to choose one row rather
//                       than other. Used row name will be hard coded here
//                       row = "Normal0" in CONF_SPEC_param
// 2.1   06-jul-2009 VD  de-hardcode comp_mode                      
//             
procedure SPEC_spu_setup {
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 16; // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 16; // Nb of red samples per sub-ramp
    int nb_raw_spu_blu = 3; // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3; // Nb of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1; // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true; // Start SPU or not [true,false]
}{
    // Spectro "Ottensamer" block is now read off CONF_SPEC_param
    string calU = "CONF_SPEC_param";
    string rowName = "Normal0";
    string rowRED = "" + rowName + "RED";
    string rowBLU = "" + rowName + "BLU";
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    // Set the SPU compression modes
    // (TC arguments are defined as type {int}[], cf. definition of
    //  Pacs_DMC_WRT_SPU_TRAN_MODE; hence define comp_par accordingly)
    comp_mode_red = ilookup(calU,rowRED,"cmp_mde");
    comp_mode_blu = ilookup(calU,rowBLU,"cmp_mde");
    {int}[] comp_par = [{comp_mode_blu},{comp_mode_red}];
    // The "checksum" function needs an array as argument, hence use elements
    // of comp_par cast as an array:                      
    int[] aux = [comp_mode_blu,comp_mode_red];
    int check_sum = checksum("int",aux);
    // Issue the TC
    Pacs_DMC_WRT_SPU_TRAN_MODE(comp_par,check_sum);
    // Setting of start index of raw channels for SPUS and SPUL
    string spus_obs_mode = "SPEC";
    string spul_obs_mode = "SPEC";
    int spus_startraw = ilookup(calU,rowRED,"st_ind");
    int spul_startraw = ilookup(calU,rowBLU,"st_ind");
    Pacs_SPUS_RAW_CHAN_TRAN_MODE(spus_obs_mode,nb_raw_spu_blu,spus_startraw);
    Pacs_SPUL_RAW_CHAN_TRAN_MODE(spul_obs_mode,nb_raw_spu_red,spul_startraw);
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    int ppf = ilookup(calU,rowBLU,"ppf");
    // PPP: Pre-Processing Parameter
    int ppp = ilookup(calU,rowBLU,"ppp");
    // Threshold for glitch detection in spectroscopy
    int tfs = ilookup(calU,rowBLU,"tfs");
    // Threshold for chopper position deviation in spectroscopy
    int tcs = ilookup(calU,rowBLU,"tcs");
    // Threshold for grating deviation
    int tgd = ilookup(calU,rowBLU,"tgd");
    // Readouts per SubRamp readback
    int rsrr = nb_samp_subramp_blu;
    // Glitch detection for spectroscopy
    int gdfs = glitch_det;
    // Ramp fitting algorithm
    int rfal = ramp_fit_alg;
    // Sorting algorithm
    int soal = ilookup(calU,rowBLU,"soal");
    // lossless compression algorithm (0,1,2,3,4)
    int lcal = ilookup(calU,rowBLU,"lcal");
    // PACS Codec Order (3,4)
    int pcod = ilookup(calU,rowBLU,"pcod");
    // New 13.95a values are
    int rndb = ilookup(calU,rowBLU,"rndb");
    int rnds = ilookup(calU,rowBLU,"rnds");
    int fixrc = ilookup(calU,rowBLU,"fixrc");
    int dpre = ilookup(calU,rowBLU,"dpre");
    int dpost = ilookup(calU,rowBLU,"dpost");
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    {int}[] spu_par = Array2grp_1(aux);
    // and issue TC to "Short" SPU
    Pacs_SPUS_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    // Spectro "Ottensamer" block ("L" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    ppf = ilookup(calU,rowRED,"ppf");
    // PPP: Pre-Processing Parameter
    ppp = ilookup(calU,rowRED,"ppp");
    // Threshold for glitch detection in spectroscopy
    tfs = ilookup(calU,rowRED,"tfs");
    // Threshold for chopper position deviation in spectroscopy
    tcs = ilookup(calU,rowRED,"tcs");
    // Threshold for grating deviation
    tgd = ilookup(calU,rowRED,"tgd");
    // Readouts per SubRamp readback
    rsrr = nb_samp_subramp_red;
    // Glitch detection for spectroscopy
    gdfs = glitch_det;
    // Ramp fitting algorithm
    rfal = ramp_fit_alg;
    // Sorting algorithm
    soal = ilookup(calU,rowRED,"soal");
    // lossless compression algorithm (0,1,2,3,4)
    lcal = ilookup(calU,rowRED,"lcal");
    // PACS Codec Order (3,4)
    pcod = ilookup(calU,rowRED,"pcod");
    // New 13.95a values are
    rndb = ilookup(calU,rowRED,"rndb");
    rnds = ilookup(calU,rowRED,"rnds");
    fixrc = ilookup(calU,rowRED,"fixrc");
    dpre = ilookup(calU,rowRED,"dpre");
    dpost = ilookup(calU,rowRED,"dpost");
    // Spare elements: 8 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfs,tcs,tgd,rsrr,gdfs,rfal,soal,lcal,pcod,rndb,rnds,fixrc,dpre,dpost,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    spu_par = Array2grp_1(aux);
    // and issue TC to "Long" SPU
    Pacs_SPUL_WRT_DET_CST_SPEC(spu_par,check_sum);
    delay(1);
    // Send time stamps
    // DMC_WRT_TIME: Write the time sent by the DPU into the DMC buffer
    // (No action on this one?)
    // DPU sends the time to DEC/MEC
    Pacs_DPU_SEND_TIME();
    // DMC_SET_TIME: Set the time previously written by the write time command
    Pacs_DMC_SET_TIME();
    // Start reduction/compression if commanded to do so
    if(startSPU) {
        Pacs_SPUS_START_REDUCT_COMPR();
        Pacs_SPUL_START_REDUCT_COMPR();
    }
    sync();
}

// Missionphase  : FM ILT
//
// Purpose	: Homes the grating and performs moves to Min->Max->Min positions
//
// Author	: Pierre Royer
// CUS script	: PR
// CVS file	: 
//
// Arguments	: homing_mode : 0 for homing on low grating values (ENG -> "POSITIVE")
//		   1 for homing on high grating values (ENG -> "NEGATIVE")
// Description	: 
//                  
// Dependencies : 
//
// Preconditions : PACS is switched on
//	    The grating controller is SWON and ENABLED
//	    (e.g. SetupSpectroscopyEQMIMT takes care for it)
//
// Comments	: The grating health check only makes sense with high frequency diag HK
//
// Version	: 1.0
//               
// History	: 1.0 14-Jun-2006 Creation, based on SPEC_Gra_Healthcheck
//
block PACS_Spec_Gra_Healthcheck_BB PACS 175 {
    string homing_mode = "POSITIVE"; // HOMING_MODE : 0 for "POSITIVE" (homing at low grating positions), 1 for 'NEGATIVE" 
}{
    // Register start of BB
    WriteBBID($BBID);
    // HOME_GRATING (everything initialized already => DMC_HOME_GRATING used directly)
    Pacs_DMC_HOME_GRAT(homing_mode);
    delay(70);
    // MOVE_GRATING     ~center -> Min -> Max -> Min -> ~center
    Pacs_DMC_MOVE_GRAT_ABS_RAW(500000);
    delay(5);
    Pacs_DMC_MOVE_GRAT_ABS_RAW(115000);
    delay(25);
    Pacs_DMC_MOVE_GRAT_ABS_RAW(990000);
    delay(49);
    Pacs_DMC_MOVE_GRAT_ABS_RAW(115000);
    delay(49);
    Pacs_DMC_MOVE_GRAT_ABS_RAW(500000);
    delay(25);
}

// Mission phase : PV Phase
//
// Purpose : PCD req.1.1.18 for the PV Phase
//           Measure the level of the electronical cross-talk
//
// Author : Koryo Okumura
//
// Version : Mon Feb 16 2009
//
// CUS script : procedure Phot_crossTalk
//
// Argument :
//   string select = "init" in ["init","lowIVSS","nominalIVSS","highIVSS","final"]; // Select an option to define IVSS current
//   string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Sequencer is activated
//   + Instrument is in safe mode
//
// Description :
//   According to "select", this sets a set of IVSSs before a scan mapping
//   - init :
//     + Set a given filter green (ginit) or blue (binit)
//     + Set the biases group by group
//     + Set the chopper on the optical center
//   - in general :
//     + set VGG for 6 buffer units to set approximately I_VSS at the value
//       (WARNING : the values in HK are those commanded plus GRND_BU!!!)
//     + Do a small scan map to cover almost whole area of the detector
//   - final :
//     + The biases are set following a given bias table
//
// Dependencies : Commissioning and PV data for the nominal setting of biases
//
// Comments : None
//
procedure Phot_crossTalk {
    string select = "ginit" in ["binit","ginit","lowIVSS","nominalIVSS","highIVSS","final"]; // Select an option to define IVSS current
    string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
    string setting = "DIRECT" in ["DIRECT","DDCS"]; // Operating mode
}{
    if(select == "ginit" || select == "binit") {
        //
        //**************
        // Select Filter
        //**************
        //
        if(select == "binit") {
            // Select Filter B (70 microns)
            PHOT_fltw_move("POS B");
        } else {
            // Select Filter A (100 microns)
            PHOT_fltw_move("POS A");
        }
        //
        //*************************************************
        // Set the biases and start SPU, then set the gain
        //*************************************************
        //
        PHOT_change_biases(startBiasTable,setting,"HIGH");
        //
        //**********************************************
        // Set the PACS chopper at the position 664
        //**********************************************
        //
        Pacs_DMC_MOVE_CHOP_ABS(664);
        //
        // sync the bus
        sync();
    }
    double[] vggs = [1.115,1.114,1.118,1.118,1.13,1.13];
    if(select == "lowIVSS") {
        vggs = [1.12,1.119,1.123,1.123,1.135,1.135];
        Pacs_BOLC_SET_VGG_G1(vggs[0]);
        Pacs_BOLC_SET_VGG_G2(vggs[1]);
        Pacs_BOLC_SET_VGG_G3(vggs[2]);
        Pacs_BOLC_SET_VGG_G4(vggs[3]);
        Pacs_BOLC_SET_VGG_G5(vggs[4]);
        Pacs_BOLC_SET_VGG_G6(vggs[5]);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a scan map
        //
        // sync the bus
        sync();
    }
    if(select == "nominalIVSS") {
        vggs = [1.115,1.114,1.118,1.118,1.13,1.13];
        Pacs_BOLC_SET_VGG_G1(vggs[0]);
        Pacs_BOLC_SET_VGG_G2(vggs[1]);
        Pacs_BOLC_SET_VGG_G3(vggs[2]);
        Pacs_BOLC_SET_VGG_G4(vggs[3]);
        Pacs_BOLC_SET_VGG_G5(vggs[4]);
        Pacs_BOLC_SET_VGG_G6(vggs[5]);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a scan map
        //
        // sync the bus
        sync();
    }
    if(select == "highIVSS") {
        vggs = [1.11,1.109,1.113,1.113,1.125,1.125];
        Pacs_BOLC_SET_VGG_G1(vggs[0]);
        Pacs_BOLC_SET_VGG_G2(vggs[1]);
        Pacs_BOLC_SET_VGG_G3(vggs[2]);
        Pacs_BOLC_SET_VGG_G4(vggs[3]);
        Pacs_BOLC_SET_VGG_G5(vggs[4]);
        Pacs_BOLC_SET_VGG_G6(vggs[5]);
        // Wait for 60 s for stabilization
        delay(60);
        // Now start a scan map
        //
        // sync the bus
        sync();
    }
    if(select == "final") {
        //********************************
        // Epilogue : Set the end biases
        //********************************
        PHOT_change_biases(endBiasTable,"DIRECT","LOW");
        //
        // sync the bus
        sync();
    }
}

// CVS comments  : $Id:
// Missionphase  : Operations
//
// Purpose       : Estimate several PACS parameters for each spectral
//                 range specified by the HSPOT user
//
// CUS author    : DAC
// Script file   : PacsRangeSpecEstimatorOBCP35.txt
//
// Input arguments
// type           name       Description
//
// Return values
// Type    Description
// tuple  {confSPECblu,confSPECred,confOBCP,{extension}}
//
// Description   : 
//
// Dependencies  : 
//
// Preconditions :
//
// Comments      : 
// 
// History       : 0.1 21-jun-2005 DAC Based on PacsLineSpecEstimator
// 		 : 1.0 28-apr-2010 VD OBCP28
// 		 : 2.0 14-may-2010 PHS-1418 VD nb_up_down fct of calU and rangeRepeat
//
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsRangeSpecEstimatorOBCP28 {
    /* rangeSPOT from HSPOT (but already sorted                            */
    {string,double,double,int,double,double,double,string,string,double} rangeSPOT = {"",0.0,0.0,0,0.0,0.0,0.0,"","",0.0};
    /* rangeInfo tuple derived from HSPOT                                  */
    {string,int,int,int,int,double,double} rangeInfo = {"NONE",0,0,0,0,0.0,0.0};
    /* union of SPECconf and OBCPconf                                      */
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    /* nodding yes/no needed to double/not OBCP duration                  */
    bool noddingSel = false;
    /* good old verbose                                                   */
    bool verbose = true; // Print bla-bla
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    // Gather information pertaining to the current range
    int order = rangeInfo{1};
    if(order == 7) {
        order = 23;
    }
    int grat_start_pos = rangeInfo{2};
    int grat_stop_pos = rangeInfo{3};
    int grat_step_up = rangeInfo{4};
    int nb_rdouts_ramp = confSPECblu{1};
    // Use different CAL files if RANGE or SED
    bool sedOBS = false;
    if(rangeInfo{0} == "SED") {
        sedOBS = true;
    }
    // Compute number of steps to go from grat_start_pos to grat_stop_pos stepping
    // by "grat_step_up" steps
    double aux_step = double(grat_stop_pos - grat_start_pos) / double(grat_step_up);
    int nb_grat_step_up = iround(abs(aux_step));
    // step_size may be negative...
    if(grat_stop_pos < grat_start_pos) {
        grat_step_up = -grat_step_up;
    }
    if(verbose) {
        debug_print("OBCP28: order/startGRAT/stopGRAT/stepGRAT/nbSTEP " + order + "/" + grat_start_pos + "/" + grat_stop_pos + "/" + grat_step_up + "/" + nb_grat_step_up);
    }
    // SCR-3663 Do not allow less than 16 steps
    if(nb_grat_step_up < 16) {
        error("Input range results in only " + nb_grat_step_up + " grating steps; minimum number of steps is 16. Increase range");
    }
    // Update corresponding elements of confOBCP
    int nb_grat_step_dn = nb_grat_step_up;
    int grat_step_dn = -grat_step_up;
    // Get "duration related" parameters from OBCP28params U-CAL table
    string calNAME = "OBCP28params";
    // The acces key is the grating order (times 10 for SED mode!)
    string key = "" + order;
    // SED rows are (completely arbitrarily!) called 20 and 30   
    if(sedOBS) {
        key = "" + 10 * order;
    }
    // There is a row per order; it lists main OBCP parameters
    //     int nb_up_down       = ilookup(calNAME,key,"nb_up_down");
    //   User desired repeat factor for current line replaces nb_up_down
    int quantum_up_down = ilookup(calNAME,key,"nb_up_down");
    int nb_up_down = rangeSPOT{3} * quantum_up_down;
    //   Don't allow null number of repetitions
    if(nb_up_down == 0) {
        nb_up_down = quantum_up_down;
    }
    int nb_SRC_OFF = 0;
    int nb_ramps_grat_pos = ilookup(calNAME,key,"nb_ramps_grat_pos");
    int nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    int nb_ramps_cs = ilookup(calNAME,key,"nb_ramps_cs");
    //   Need nb_rdouts (different according to faintLines)
    int nb_rdouts = confSPECblu{1};
    // Estimate the OBS time for this rangeInfo
    int[] dureeOBCP28 = PacsDureeOBCP28(nb_up_down,nb_grat_step_up,nb_ramps_grat_pos,nb_CS1_CS2,nb_ramps_cs,nb_rdouts_ramp);
    if(verbose) {
        debug_print("++Duration DMC: " + dureeOBCP28);
    }
    // Return SRC+REF (used to be total duration)
    int quantumOBStime = dureeOBCP28[1] + dureeOBCP28[2];
    // Get the "quantum" OBS time for the current order. OBCP duration doubles if 
    // nodding is allowed
    int nodFactor = 1;
    int nb_nods = 1;
    if(noddingSel) {
        nodFactor = 2;
    } else {
        nb_nods = 0;
    }
    quantumOBStime = nodFactor * quantumOBStime;
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    if(noddingSel) {
        msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + rangeSPOT{1} + "/" + rangeSPOT{2} + " [&micro;m] range repeated " + nb_up_down + " time(s)</p>";
    } else {
        msgLine[lineCnt] = "<p>Estimated SRC+CalSrce time: " + quantumOBStime + " [sec] for " + rangeSPOT{1} + "-" + rangeSPOT{2} + " [&micro;m] range repeated " + nb_up_down + " time(s)</p>";
    }
    if(verbose) {
        debug_print("OBCP28: SRC+REF minimum " + quantumOBStime + " [sec] for " + rangeSPOT{1} + " - " + rangeSPOT{2} + " [&micro;m] range with " + nb_up_down + " repetition(s)");
    }
    lineCnt = lineCnt + 1;
    // Alessandra SRC-3513 would come here. Compute velocity range with respect 
    // to WaveRef line (last entry in rangeSPOT)
    // Light speed km/sec
    double clight = 300000.0;
    // Just in case WaveRef is null
    if(abs(rangeSPOT{9}) > 1.0E-4) {
        //    Velocity at each end-of-range
        double vblu = clight * (rangeSPOT{1} - rangeSPOT{9}) / rangeSPOT{9};
        double vred = clight * (rangeSPOT{2} - rangeSPOT{9}) / rangeSPOT{9};
        if(verbose) {
            debug_print("OBCP28: RANGE VELOCITY: " + dformat(vblu,1) + "/" + dformat(vred,1));
        }
        msgLine[lineCnt] = "<p>Velocity range from WaveRef = " + dformat(rangeSPOT{9},2) + " [&micro;m]; blue/red: " + dformat(vblu,1) + "/" + dformat(vred,1) + " km/sec</p>";
        lineCnt = lineCnt + 1;
    }
    // Some more Pointing parameters (auxN just in case I need more...)
    int aux2 = 0;
    int aux3 = 0;
    // Pack information into proper tuples
    confOBCP{0} = nb_up_down;
    confOBCP{1} = grat_step_up;
    confOBCP{2} = grat_step_dn;
    confOBCP{3} = nb_SRC_OFF;
    confOBCP{4} = nb_ramps_grat_pos;
    confOBCP{5} = nb_CS1_CS2;
    confOBCP{6} = nb_grat_step_up;
    confOBCP{7} = nb_grat_step_dn;
    confOBCP{8} = grat_start_pos;
    //    confOBCP { 9}  =   grat_start_time  ;
    //    confOBCP {10}  =   grat_def_pos     ;
    //    confOBCP {11}  =   grat_def_time    ;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    //   confSPECred{ 0} =  capa_red;
    //   confSPECred{ 1} =  nb_rdouts;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    int comp_mode_red = 16;
    confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    //   confSPECblu{ 0} =  capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    int comp_mode_blu = 16;
    confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    string msgLabel = "Observing time for " + rangeSPOT{0};
    PacsMessageCenter(msgLabel,lineCnt,msgLine);
    // Debug info
    if(verbose) {
        debug_print("RangeEstimatorOBCP28 duration: " + quantumOBStime);
        debug_print("confOBCP: " + confOBCP);
    }

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,nb_up_down,quantumOBStime,aux3}};
}

// CVS comments  : $Id: PacsRangeSpecEstimatorOBCP27.txt,v 1.1 2008/05/26 15:12:49 vanessad Exp $
// Missionphase  : Operations
//
// Purpose       : Estimate several PACS parameters for each spectral
//                 range specified by the HSPOT user
//
// CUS author    : DAC
// Script file   : PacsRangeSpecEstimatorOBCP27.txt 
//
// Input arguments
// type           name       Description
//
// Return values
// Type    Description
// tuple  {confSPECblu,confSPECred,confOBCP,{extension}}
//
// Description   : 
//
// Dependencies  : 
//
// Preconditions :
//
// Comments      : 
// 
// History       : 0.1 21-jun-2005 DAC Based on PacsLineSpecEstimator
// 1.0 15-sep-2005 Adapted for "OBS" CUS scripts
// 1.1 16-sep-2005 Added gratSTEP to rangeInfo, moved "density" and "grating"
//                 to PacsRangeSpecCheckFillRange
// 2.0 11-oct-2005 Added userOBStime logic
// 2.1 13-oct-2005 Amended noddingSel logic
// 2.2 17-oct-2005 Amended nb_nods logic (see PacsLineSpecEstimatorOBCP27)
// 2.3 24-oct-2005 Add HTML tags
// 2.4 11-apr-2006 Defined comp_mode_xxx here since != for SPEC and PHOT
// 2.5 12-may-2006 Added logic for negative step_size; return quantumOBS in
//                 hitherto unused return auxiliar
// 2.6 22-jun-2006 "ranges" now contains lineWidth
// 3.0 17-jan-2007 "Improved" messages
// 3.1 14-feb-2007 Return quantumOBS based only on SRC+REF
// 4.0  2-mar-2007 Amended for raster w/OFF. Raster w/OFF is performed when
//                 noddingSel = false. The OBCP parameters are the same as
//                 with/nodding; only the chopper position changes: SRC and CS1
// 5.0 15-apr-2007 Define ranges as created by HSPOT
// 5.1  4-may-2007 Added faint_lines
// 5.2 22-aug-2007 Implemented SCR-3513 (velocity range)
//                 Exchanged vred and vblu
// 5.3 17-oct-2007 SCR-3663 "Do not allow less than 16 grating steps"
{{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int},{int,int,int,int}} procedure PacsRangeSpecEstimatorOBCP27 {
    /* rangeSPOT from HSPOT (but already sorted                            */
    {string,double,double,int,double,double,double,string,string,double} rangeSPOT = {"",0.0,0.0,0,0.0,0.0,0.0,"","",0.0};
    /* rangeInfo tuple derived from HSPOT                                  */
    {string,int,int,int,int,double,double} rangeInfo = {"NONE",0,0,0,0,0.0,0.0};
    /* union of SPECconf and OBCPconf                                      */
    {{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int},{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}} paramsSPECdef = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    /* nodding yes/no needed to double/not OBCP duration                  */
    bool noddingSel = false;
    /* good old verbose                                                   */
    bool verbose = true; // Print bla-bla
}{
    // Define local copy of confXXX tuples
    {int,int,int,int,int,int,int,int,int} confSPECblu = clone(paramsSPECdef{0});
    {int,int,int,int,int,int,int,int,int} confSPECred = clone(paramsSPECdef{1});
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int} confOBCP = clone(paramsSPECdef{2});
    // Gather information pertaining to the current range
    int order = rangeInfo{1};
    int grat_start_pos = rangeInfo{2};
    int grat_stop_pos = rangeInfo{3};
    int grat_step_up = rangeInfo{4};
    // Use different CAL files if RANGE or SED
    bool sedOBS = false;
    if(rangeInfo{0} == "SED") {
        sedOBS = true;
    }
    // Compute number of steps to go from grat_start_pos to grat_stop_pos stepping
    // by "grat_step_up" steps
    double aux_step = double(grat_stop_pos - grat_start_pos) / double(grat_step_up);
    int nb_grat_step_up = iround(abs(aux_step));
    // step_size may be negative...
    if(grat_stop_pos < grat_start_pos) {
        grat_step_up = -grat_step_up;
    }
    if(verbose) {
        debug_print("OBCP27: order/startGRAT/stopGRAT/stepGRAT/nbSTEP " + order + "/" + grat_start_pos + "/" + grat_stop_pos + "/" + grat_step_up + "/" + nb_grat_step_up);
    }
    // SCR-3663 Do not allow less than 16 steps
    if(nb_grat_step_up < 16) {
        error("Input range results in only " + nb_grat_step_up + " grating steps; minimum number of steps is 16. Increase range");
    }
    // Update corresponding elements of confOBCP
    int nb_grat_step_dn = nb_grat_step_up;
    int grat_step_dn = -grat_step_up;
    // Get "duration related" parameters from OBCP27params U-CAL table
    string calNAME = "OBCP27params";
    // The acces key is the grating order (times 10 for SED mode!)
    string key = "" + order;
    // SED rows are (completely arbitrarily!) called 20 and 30   
    if(sedOBS) {
        key = "" + 10 * order;
    }
    // There is a row per order; it lists main OBCP parameters
    //     int nb_up_down       = ilookup(calNAME,key,"nb_up_down");
    //   User desired repeat factor for current line replaces nb_up_down
    int nb_up_down = rangeSPOT{3};
    //   Don't allow null number of repetitions
    if(nb_up_down == 0) {
        nb_up_down = 1;
    }
    int nb_SRC_OFF = ilookup(calNAME,key,"nb_SRC_OFF");
    int nb_ramps_plateau = ilookup(calNAME,key,"nb_ramps_plateau");
    int nb_CS1_CS2 = ilookup(calNAME,key,"nb_CS1_CS2");
    //   Need nb_rdouts (different according to faintLines)
    int nb_rdouts = confSPECblu{1};
    // Estimate the OBS time for this rangeInfo
    int[] dureeOBCP27 = PacsDureeOBCP27(nb_up_down,nb_grat_step_up,nb_ramps_plateau,nb_CS1_CS2,nb_SRC_OFF,nb_rdouts);
    if(verbose) {
        debug_print("++Duration DMC: " + dureeOBCP27);
    }
    // Return SRC+REF (used to be total duration)
    int quantumOBStime = dureeOBCP27[1] + dureeOBCP27[2];
    // Get the "quantum" OBS time for the current order. OBCP duration doubles if 
    // nodding is allowed
    int nodFactor = 1;
    int nb_nods = 1;
    if(noddingSel) {
        nodFactor = 2;
    } else {
        nb_nods = 0;
    }
    quantumOBStime = nodFactor * quantumOBStime;
    // Inform user
    string[] msgLine = [" "];
    int lineCnt = 0;
    if(noddingSel) {
        msgLine[lineCnt] = "<p>Estimated SRC+REF time: " + quantumOBStime + " [sec] for " + rangeSPOT{1} + "/" + rangeSPOT{2} + " [&micro;m] range repeated " + nb_up_down + " time(s)</p>";
    } else {
        msgLine[lineCnt] = "<p>Estimated SRC+CalSrce time: " + quantumOBStime + " [sec] for " + rangeSPOT{1} + "-" + rangeSPOT{2} + " [&micro;m] range repeated " + nb_up_down + " time(s)</p>";
    }
    if(verbose) {
        debug_print("OBCP27: SRC+REF minimum " + quantumOBStime + " [sec] for " + rangeSPOT{1} + " - " + rangeSPOT{2} + " [&micro;m] range with " + nb_up_down + " repetition(s)");
    }
    lineCnt = lineCnt + 1;
    // Alessandra SRC-3513 would come here. Compute velocity range with respect 
    // to WaveRef line (last entry in rangeSPOT)
    // Light speed km/sec
    double clight = 300000.0;
    // Just in case WaveRef is null
    if(abs(rangeSPOT{9}) > 1.0E-4) {
        //    Velocity at each end-of-range
        double vblu = clight * (rangeSPOT{1} - rangeSPOT{9}) / rangeSPOT{9};
        double vred = clight * (rangeSPOT{2} - rangeSPOT{9}) / rangeSPOT{9};
        if(verbose) {
            debug_print("OBCP27: RANGE VELOCITY: " + dformat(vblu,1) + "/" + dformat(vred,1));
        }
        msgLine[lineCnt] = "<p>Velocity range from WaveRef = " + dformat(rangeSPOT{9},2) + " [&micro;m]; blue/red: " + dformat(vblu,1) + "/" + dformat(vred,1) + " km/sec</p>";
        lineCnt = lineCnt + 1;
    }
    // Some more Pointing parameters (auxN just in case I need more...)
    int aux2 = 0;
    int aux3 = 0;
    // Pack information into proper tuples
    confOBCP{0} = nb_up_down;
    confOBCP{1} = grat_step_up;
    confOBCP{2} = grat_step_dn;
    confOBCP{3} = nb_SRC_OFF;
    confOBCP{4} = nb_ramps_plateau;
    confOBCP{5} = nb_CS1_CS2;
    confOBCP{6} = nb_grat_step_up;
    confOBCP{7} = nb_grat_step_dn;
    confOBCP{8} = grat_start_pos;
    //    confOBCP { 9}  =   grat_start_time  ;
    //    confOBCP {10}  =   grat_def_pos     ;
    //    confOBCP {11}  =   grat_def_time    ;
    //    confOBCP {12}  =   chop_pos_SRC     ;
    //    confOBCP {13}  =   chop_pos_REF1    ;
    //    confOBCP {14}  =   chop_pos_REF2    ;
    //    confOBCP {15}  =   chop_pos_CS1     ;
    //    confOBCP {16}  =   chop_pos_CS2     ;
    //    confOBCP {17}  =   chop_def         ;
    confOBCP{19} = order;
    //   confSPECred{ 0} =  capa_red;
    //   confSPECred{ 1} =  nb_rdouts;
    //   confSPECred{ 2} =  nb_rdouts_subramp_red;
    int comp_mode_red = 16;
    confSPECred{3} = comp_mode_red;
    //   confSPECred{ 4} =  glitch_det_red;
    //   confSPECred{ 5} =  ramp_fit_alg_red;
    //   confSPECred{ 6  =  nb_raw_red;
    //   confSPECred{ 7} =  bias_r_red;
    //   confSPECred{ 8} =  bias_d_red;
    //   confSPECblu{ 0} =  capa_blu;
    //   confSPECblu{ 1} =  nb_rdouts;
    //   confSPECblu{ 2} =  nb_rdouts_subramp_blu;
    int comp_mode_blu = 16;
    confSPECblu{3} = comp_mode_blu;
    //   confSPECblu{ 4} =  glitch_det_blu;
    //   confSPECblu{ 5} =  ramp_fit_alg_blu;
    //   confSPECblu{ 6  =  nb_raw_blu;
    //   confSPECblu{ 7} =  bias_r_blu;
    //   confSPECblu{ 8} =  bias_d_blu;
    // Pass messages to user
    string msgLabel = "Observing time for " + rangeSPOT{0};
    PacsMessageCenter(msgLabel,lineCnt,msgLine);
    // Debug info
    if(verbose) {
        debug_print("RangeEstimatorOBCP27 duration: " + quantumOBStime);
    }

    return {confSPECblu,confSPECred,confOBCP,{nb_nods,nb_up_down,quantumOBStime,aux3}};
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
//
// Purpose       :  Check the Amplitude of the Grating inductosyn by running a loop over it
//
// CUS author    : PR
//
// Input arguments none
// type    name         description
//
// Preconditions : PACS in SAFE MODE, or Spectroscopy Mode
//	    In any case, Controller of the Calibration Sources MUST BE OFF
//                 
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0  12-Jul-2007 PR
// 		  2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
//
obs PacsEng_Spec_Gra_IST_Ampl {
    /* Needed variables to call PacsEng_Spec_Gra_IST_Ampl                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Gra_IST_Ampl                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Gra_IST_Ampl()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Gra_IST_Ampl();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : PV Phase
//
// Purpose : PCD req.1.1.1bis for the PV Phase
//           Measure the responsivity with a 8x4 raster on a point source (not SSO):
//           Noise is measured after the 8x4 raster at the off pointing position during "timeOFF".
//
// Author : Koryo Okumura
//
// Version : Wed Jul 29 12:15:01 EDT 2009
//
// CUS script : obs PacsCal_Phot_highGainBiasDirect_Fix
//
// Argument :
//   string select = "ginit" in ["ginit","g1_0","g1_3","g1_6","g1_7","g1_8","g1_9","g2_0","g2_1","g2_2","g2_3","g2_4","g2_5","g2_6","g2_7","g2_8","g2_9","g3_0","g3_1","g3_3","g3_5","binit","b1_0","b1_3","b1_6","b1_7","b1_8","b1_9","b2_0","b2_1","b2_2","b2_3","b2_4","b2_5","b2_6","b2_7","b2_8","b2_9","b3_0","b3_1","b3_3","b3_5","final"]; // Select a configuration or initialize or finalize
//   double ra = 70.7235; // RA 4h42m53.64s
//   double dec = 36.1148; // Dec +36d06m53.4s
//   double raoff = 70.82; // OFF position RA coordinaten
//   double decoff = 36.21; // OFF position Dec coordinate
//   bool refSelected = true; // OFF position needed
//   int measure_time = 120; // measure time in seconds
//   int timeOFF = 480; // time of noise measurement in seconds on the OFF position
//   string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
//   string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
//   string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
//   int nLoops1 = 30; // number of CSs cycles during slew
//   int nLoops5 = 30; // number of CSs cycles during final hold
//   int readouts_plateau = 64; // number of readouts per chopper plateau
//   string calGain = "HIGH" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
//   string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
//   bool chop = true; // Chopping within FOV during the raster
//   bool verbose = true;
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + PHOT_orbit_prologue is executed (then more than the minimum requirement below is fullfilled):
//     - Bolometers are biased
//     - Sequencer is activated
//
// Description : PacsCal script of Phot_highGainBiasDirect
//   init + During the slew, CSs are measured through 2 filters
//        + Set a filter corresponding to the given seqNum
//        + Set the biases group by group
//   if no_chop
//        + Set the chopper on the optical center
//        + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group corresponding to the selected bias
//        + Do a 4x9 raster measurement
//   if chop
//        + 4 basic biases (VH, VL, VRL, VH-BLIND) are set group by group corresponding to the selected bias
//        + Do a 4x8 raster with chopped measurement
//        + After the raster, noise measurement during 4xmeasure_time
//   then + After the raster, CSs and sky are measured through 2 filters
//   stop + The biases are set following a given bias table
//
// Dependencies : Commissioning and PV data at low gain of PCD req.1.1.1
// Comment : SCR PACS-1872
//
// Comments : generated by IA script : cus_PVph_highGainBias(1)
//
obs PacsCal_Phot_highGainBiasDirect_Fix {
    string select = "ginit" in ["ginit","g1_0","g1_3","g1_6","g1_7","g1_8","g1_9","g2_0","g2_1","g2_2","g2_3","g2_4","g2_5","g2_6","g2_7","g2_8","g2_9","g3_0","g3_1","g3_3","g3_5","binit","b1_0","b1_3","b1_6","b1_7","b1_8","b1_9","b2_0","b2_1","b2_2","b2_3","b2_4","b2_5","b2_6","b2_7","b2_8","b2_9","b3_0","b3_1","b3_3","b3_5","final"]; // Select a configuration
    double ra = 70.7235; // RA 4h42m53.64s
    double dec = 36.1148; // Dec +36d06m53.4s
    double raoff = 70.82; // OFF position RA coordinaten
    double decoff = 36.21; // OFF position Dec coordinate
    bool refSelected = true; // OFF position needed
    int measure_time = 120; // measure time in seconds per pointing
    int timeOFF = 480; // time of noise measurement in seconds on the OFF position
    string startBiasTable = "BOLObias_standard_high"; // Bias table containing the initial values
    string endBiasTable = "BOLObias_standard_high"; // Bias table containing the final values
    string calBiasTable = "BOLObias_standard_high"; // Bias table used during calibration blocks
    int nLoops1 = 30; // number of CSs cycles during slew
    int nLoops5 = 30; // number of CSs cycles during final hold
    int readouts_plateau = 64; // number of readouts per chopper plateau
    string calGain = "HIGH" in ["NO_CHANGE","LOW","HIGH"]; // Gain of calibration blocks, the same as OBS if NO_CHANGE
    string calMode = "NO_CHANGE" in ["NO_CHANGE","DIRECT","DDCS"]; // Mode of calibration blocks, the same as OBS if NO_CHANGE
    bool chop = true; // Chopping within FOV during the raster
    bool verbose = true;
}{
    bool execute = true;
    int nRdts = readouts_plateau - 1;
    int timeOBSID = imax(1,duration(WriteOBSID($OBSID)));
    int timeEndID = imax(1,duration(WriteEndID()));
    int timeChgBias = duration(PHOT_change_biases(endBiasTable,calMode,calGain));
    int timeBckBias = 0;
    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,"DIRECT","HIGH"));
    }
    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,calMode,"HIGH"));
    }
    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
        timeBckBias = duration(PHOT_change_biases(startBiasTable,"DIRECT",calGain));
    }
    int timeCal3CPR1 = duration(OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644));
    int tNewSetup = duration(Phot_highGainBiasDirect(select,startBiasTable,endBiasTable));
    int tslewmin = 0;
    int tih = 0;
    int tfh = 0;
    // Use PHOTOMETER virtual aperture
    string ib = "P01_0";
    // SSO tracking object number
    int naifid = 0;
    // yoffset [arcsec]
    double yoffset = 0.0;
    // zoffset [arcsec] : Finally we do not risk to provoke the opposite correction
    double zoffset = 0.0;
    // Duration of "stable" pointing in seconds
    int tp = 0;
    //Issue PointReq
    int[] ts = [0];
    if(select == "ginit" || select == "binit" || select == "final") {
        // Several arguments needed for "basic_fine_pointing"
        // time to set OBSID and biases then PacsPhotSlewCal
        // Minimum slew time
        if(select == "final") {
            timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
        } else {
            if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT","HIGH"));
            }
            if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,"DIRECT",calGain));
            }
            if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,"HIGH"));
            }
            if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                timeChgBias = duration(PHOT_change_biases(calBiasTable,calMode,calGain));
            }
        }
        tslewmin = timeOBSID + timeChgBias + timeCal3CPR1 + tNewSetup;
        if(verbose) {
            debug_print("Tslewmin: " + tslewmin);
        }
        // Initial hold
        tih = 0;
        // Final hold
        tfh = timeEndID;
        // Duration of "stable" pointing in seconds
        tp = 1;
        //Issue PointReq
        ts = basic_fine_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,yoffset,zoffset,tp);
    } else {
        // Several arguments needed for "basic_raster_pointing"
        // time to set and reset BBID
        int timeBBID = imax(1,duration(TMMarker601()) + duration(TMMarker600()));
        // time to set OBSID and biases then PacsPhotSlewCal
        int timeCal3CPR5 = duration(OBCP_chopped_photometry(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,644));
        // Minimum slew time
        tslewmin = timeOBSID + timeChgBias + timeBckBias + tNewSetup + timeCal3CPR1;
        if(verbose) {
            debug_print("Tslewmin: " + tslewmin);
        }
        // Initial hold
        tih = 0;
        // Final hold
        tfh = timeChgBias + timeCal3CPR5 + timeEndID;
        // Fixed in the sky coordinates
        bool fixed = false;
        // Orientation angle (degrees)
        double patt = 0.0;
        // Number of pointings in a leg
        int m = 4;
        // Number of legs
        int n = 8;
        // Angular distance (arcsec) between 2 pointings
        double d1 = 26.0;
        // Angular distance (arcsec) between 2 legs
        double d2 = 26.5;
        // Duration of "stable" pointing in seconds
        if(chop) {
            int nLoops = measure_time * 40 / (2 * readouts_plateau);
            tp = duration(OBCP_chopped_photometry(0,0,nRdts,0,0,nLoops,1,-6578,7756,0,0,644));
            // Positive pointing offset for chopping to get negative chopper position offset
            yoffset = 105.0;
        } else {
            tp = measure_time;
        }
        // Go to OFF position every k pointings (not relevant with SSO tracking)
        int k = m * n;
        // time in seconds on the OFF position (not relevant with SSO tracking)
        int top = timeOFF + timeBBID;
        //Issue PointReq
        ts = basic_raster_pointing(execute,tslewmin,tih,tfh,ib,naifid,ra,dec,fixed,patt,yoffset,zoffset,m,n,d1,d2,tp,k,top,raoff,decoff);
    }
}{
    int tNOW = time();
    int[] state = [0];
    if(select == "ginit" || select == "binit" || select == "final") {
        //  Start the sequence
        while(state[0] >= 0) {
            state = next_state();
            tNOW = time();
            if(state[0] == 1) {
                if(verbose) {
                    debug_print("SLEW starts at " + tNOW);
                }
                // Set OBSID
                WriteOBSID($OBSID);
                data_rate(120.0);
                // Set biases and start SPU
                if(select == "final") {
                    PHOT_change_biases(calBiasTable,calMode,calGain);
                } else {
                    if(calMode == "NO_CHANGE" && calGain == "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,"DIRECT","HIGH");
                    }
                    if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,"DIRECT",calGain);
                    }
                    if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,calMode,"HIGH");
                    }
                    if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                        PHOT_change_biases(calBiasTable,calMode,calGain);
                    }
                }
                //************************************
                //  Call the Phot_highGainBiasDirect
                //************************************
                Phot_highGainBiasDirect(select,startBiasTable,endBiasTable);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                tNOW = time();
                if(verbose) {
                    debug_print("SLEW ends at   " + tNOW);
                }
            }
            if(state[0] == 2) {
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 3) {
                tNOW = time();
                if(verbose) {
                    debug_print("POINT starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("POINT ends at     " + tNOW);
                }
            }
            if(state[0] == 5) {
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD starts at   " + tNOW);
                }
                // Write EndID
                data_rate(0.0);
                WriteEndID();
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD ends at     " + tNOW);
                }
            }
        }
    } else {
        int finalChop = 0;
        //  Start the sequence
        while(state[0] >= 0) {
            state = next_state();
            tNOW = time();
            if(state[0] == 1) {
                if(verbose) {
                    debug_print("SLEW starts at " + tNOW);
                }
                // Set OBSID
                WriteOBSID($OBSID);
                data_rate(120.0);
                // Set biases and start SPU
                PHOT_change_biases(calBiasTable,calMode,calGain);
                //*******************************
                // Configure for the measurement
                //*******************************
                if(calMode != "NO_CHANGE" && calGain != "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,"DIRECT","HIGH");
                }
                if(calMode == "NO_CHANGE" && calGain != "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,calMode,"HIGH");
                }
                if(calMode != "NO_CHANGE" && calGain == "NO_CHANGE") {
                    PHOT_change_biases(startBiasTable,"DIRECT",calGain);
                }
                //************************************
                //  Call the Phot_highGainBiasDirect
                //************************************
                Phot_highGainBiasDirect(select,startBiasTable,endBiasTable);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops1,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                tNOW = time();
                if(verbose) {
                    debug_print("SLEW ends at   " + tNOW);
                }
            }
            if(state[0] == 2) {
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD starts at   " + tNOW);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("INITIAL_HOLD ends at     " + tNOW);
                }
            }
            if(state[0] == 3) {
                tNOW = time();
                if(verbose) {
                    debug_print("POINT starts at   " + tNOW);
                }
                if(chop) {
                    //*********************************
                    // 2 positions chopping in the FOV
                    //*********************************
                    OBCP_chopped_photometry(0,0,nRdts,0,0,nLoops,1,-6578,7756,0,0,-6578);
                }
                tNOW = time();
                if(verbose) {
                    debug_print("POINT ends at     " + tNOW);
                }
            }
            if(state[0] == 4) {
                tNOW = time();
                if(verbose) {
                    debug_print("OFF pointing starts at   " + tNOW);
                }
                //********************************
                // OFF position noise measurement
                //********************************
                TMMarker601();
                delay(timeOFF);
                TMMarker600();
                tNOW = time();
                if(verbose) {
                    debug_print("OFF pointing ends at     " + tNOW);
                }
            }
            if(state[0] == 5) {
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD starts at   " + tNOW);
                }
                // Set biases and start SPU
                PHOT_change_biases(calBiasTable,calMode,calGain);
                //***************************************************
                // 3 chopper positions measurement through 2 filters
                //***************************************************
                OBCP_chopped_photometry(nLoops5,664,nRdts,-21350,21200,1,0,0,0,0,0,644);
                // Write EndID
                data_rate(0.0);
                WriteEndID();
                tNOW = time();
                if(verbose) {
                    debug_print("FINAL_HOLD ends at     " + tNOW);
                }
            }
        }
    }
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
//
// Purpose       :  EMC preparation
//                  
//                 
//
// TCL author    : HF
// TCL file      : 
// CUS author    : HF 
// Script file   : SPEC_Prepare_EMC.txt 
//
// Input arguments none
// type    name         description
//
// Return values
// Type    Name      Default      Description
//
// Description   :  Sets chopper, grating and the SPU
//                            
//                           
//                            
//                  
// Dependencies  : 
//
// Preconditions : PACS must be on and configured for spectroscopy
//                             
//                 
// Comments      : 
// 
// Version	 : 2.0
// History       : 1.0 29-Mar-2005 creation by HF
// 		  2.0 25-mar-2008 VDP Translated from IST to PV phase syntax
//
//
obs PacsEng_Spec_Prepare_EMC {
    /* Needed variables to call PacsEng_Spec_Prepare_EMC                        */
    int comp_mode_blu = 16; // Compression mode blue channel
    int comp_mode_red = 16; // Compression mode red channel
    int nb_samp_subramp_blu = 64; // Nb of blue samples per sub-ramp 
    int nb_samp_subramp_red = 64; // Nb of red samples per sub-ramp 
    int nb_raw_spu_blu = 3; // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3; // Nb of raw channels transmitted by SPUL
    int glitch_det = 1; // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 0; // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true; // Start SPU or not [true,false]
    int chop_pos = -21350; // Chopper position
    int grat_pos = 500000; // Grating position
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Spec_Prepare_EMC                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(Pacs_Spec_Prepare_EMC(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU,chop_pos,grat_pos)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            Pacs_Spec_Prepare_EMC(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU,chop_pos,grat_pos);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_DPU_DMC_Setup {
    /* No variables to call PacsEng_Phot_DPU_DMC_Setup                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_DPU_DMC_Setup                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_DPU_DMC_Setup()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_DPU_DMC_Setup();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// CVS comments  : $Id: PacsSpecCommandOBCP32.txt,v 1.1 2007/10/25 12:16:47 dcesarsk Exp $ 
// Purpose       : Issue FreqSwitch PACS commands at each stable pointing in 
//                 order to observe all the HSPOT defined spectral lines
//
// CUS author    : DAC
//
// Input arguments
// Type                                                 Description
// {int,int,int,int,int,int,int,int,int}[] confSPECblu  BLUE SPU parameters
// {int,int,int,int,int,int,int,int,int}[] confSPECred  RED  SPU parameters
// {int,int,int,int,int,int,int,int,int,int,int,
//  int,int,int,int,int,int,int,int,int}[] confOBCP     OBCP parameters
// bool verbose                                         Print debug information
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per spectral line
// Description   : Loops over all wavelengths at current stable pointing; sends
//                 start OBCP telecommand per spectral line
// IMPORTANT NOTE: the duration for the first stable pointing could have been
//                 different than that for the following points, due to the
//                 fact that we start from the default configuration whereas for
//                 any subsequent point, we start from where we ended at
//                 point-1. All OBCPs dealing with the grating will leave the
//                 grating at the position used for the 1st line/range.
//
// Dependencies  : 
//
// Preconditions :
// Comments      : OBCP tuples have slightly different contents than for
//                 non switched OBCPs. See PacsSpecEstimatorOBCP32 for
//                 more details
// Version       : 0.1
// History       : 
// 0.1 DAC  18-oct-2007 First version based on PacsSpecCommandOBCP22
// 1.0 VD 19-feb-2009 version for new implementation of WS base on ABBA mode
//
int[][] procedure PacsSpecCommandOBCP32_PV {
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    bool verbose = true; // Print debug information
}{
    // Create array of durations; one duration per line
    int[][] time_array = [[0,0,0,0,0]];
    // Grating was left at 1st line by SlewCal
    int grat_def_pos = confOBCP[1]{8};
    // How many lines are we supposed to observe? confOBCP[0] is default tuple;
    // bonafide lines are described by confOBCP[1,2...])
    int nbLines = length(confOBCP) - 1;
    if(verbose) {
        debug_print("Comm.OBCP32:Starting SpecCommandOBCP32 with NbLines:" + nbLines);
        debug_print("Comm.OBCP32:Grating at position:" + grat_def_pos);
    }
    // ========================= LOOP on lines ===============================
    for(int lineNb = 1 .. nbLines) {
        //  Initialise time_array
        time_array[lineNb - 1] = [0,0,0,0,0];
        //  Long sequence to "unpack" contents of tuples
        //  Both SPECs
        int nb_rdouts_ramp_blu = confSPECblu[lineNb]{1};
        int comp_mode_blu = confSPECblu[lineNb]{3};
        int comp_mode_red = confSPECred[lineNb]{3};
        // OBCP
        //  - Switch cycles (includes userREPfactr)
        int nb_switch_cycles = confOBCP[lineNb]{0};
        //  - OBCP32 is based on relative moves (to REF1 and to REF2)
        //        int jumpREF1 = confOBCP[lineNb]{1};
        ///        int jumpREF2 = confOBCP[lineNb]{2};
        int switch_param4 = confOBCP[lineNb]{1};
        int switch_param6 = confOBCP[lineNb]{2};
        int switch_param7 = confOBCP[lineNb]{10};
        int switch_param8 = confOBCP[lineNb]{11};
        //  - Number of ramps per grating position
        int nb_ramps_grat = confOBCP[lineNb]{4};
        //  - Number of dither cycles (better be odd number)
        int ditherCount = confOBCP[lineNb]{7};
        //  - Nominal grating position for observed line 
        int grat_pos_LINE = confOBCP[lineNb]{8};
        //  - Relative displacement of the ensemble LINE-REF1-LINE-REF2 per dither
        //    cycle
        int ditherSize = confOBCP[lineNb]{9};
        int chop_pos_SRC = confOBCP[lineNb]{12};
        int detector = confOBCP[lineNb]{18};
        //  This module is invoked at start of a stable pointing. Herein, OBCP32
        //  is called once per spectral line. 
        //
        //  Grating performs LINE-REF1-LINE-REF2. The DMC internal loop will
        //  shift the "switching" pattern by ditherSize each time around the loop.
        //  Perform the internal loop such that pattern starts at one extreme
        //  position and then it moves to the end position, going through the
        //  "nominal" grating position for LINE
        //  The offset to the extreme position of oscillating pattern is
        int halfDither = ditherSize * (ditherCount - 1) / 2;
        //  The DMC sequence is coded in such a way that the LINE is placed at
        //  LINE -> grat_pos + ditherSize(P2) + param4(P#4)
        //  To see the LINE in the first DMC loop: 
        // grat_pos = nominal@line - param4(P4) - ditherSize(P2)
        int gratPos = grat_pos_LINE - switch_param4 - ditherSize;
        //  Further move the grating -halfDither step so that 1/2 way into the loop
        //  will go through the nominal position
        gratPos = gratPos - halfDither;
        //  Before OBCP grating is parked at grat_def_pos (1st line nominal setting)
        int steps_start = grat_def_pos - gratPos;
        //  Time needed to get there [msec]
        int grat_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("Comm.OBCP32:GratStart from/to: " + grat_def_pos + "/" + gratPos);
            debug_print("Comm.OBCP32:GratStartTime: " + grat_time + " [msec]");
        }
        //  At the end of the OBCP, the grating finishes at
        int grat_end = gratPos + ditherSize + 2 * halfDither;
        //  We would like to leave it ready for the next line
        if(lineNb < nbLines) {
            grat_def_pos = confOBCP[lineNb + 1]{8};
        } else {
            grat_def_pos = confOBCP[1]{8};
        }
        //  Number of steps to go to grat_def_pos
        int steps_end = grat_end - grat_def_pos;
        //  Time needed to get there [msec]
        int grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("Comm.OBCP32:GratEnd from/to: " + grat_end + "/" + grat_def_pos);
            debug_print("Comm.OBCP32:GratEndTime: " + grat_def_time + " [msec]");
        }
        //  Start the OBCP now. Watch out the signs of the params. Here chosen
        //DACOBCP32	
        //        int[] timeOBCP = OBCP_wave_switch(ditherCount,ditherSize,nb_switch_cycles,switch_param4,nb_ramps_grat,switch_param6,switch_param7,switch_param8,detector,comp_mode_blu,comp_mode_red,gratPos,chop_pos_SRC,grat_time,grat_def_pos,chop_pos_SRC,grat_def_time,nb_rdouts_ramp_blu);
        int[] timeOBCP = [0,0,0,0,0];
        //  This OBCP is rather confusing; print enough debugging information
        if(verbose) {
            debug_print("Comm.OBCP32: NominalLine: " + grat_pos_LINE);
            debug_print("Comm.OBCP32: halfDither : " + halfDither);
            debug_print("Comm.OBCP32: ditherCount: " + ditherCount);
            debug_print("Comm.OBCP32: P#2        : " + ditherSize);
            debug_print("Comm.OBCP32: P#3        : " + nb_switch_cycles);
            debug_print("Comm.OBCP32: P#4        : " + switch_param4);
            debug_print("Comm.OBCP32: P#6        : " + switch_param6);
            debug_print("Comm.OBCP32: P#7        : " + switch_param7);
            debug_print("Comm.OBCP32: P#8        : " + switch_param8);
            debug_print("Comm.OBCP32: gratPos    : " + gratPos);
            debug_print("Comm.OBCP32: gratDefPos : " + grat_def_pos);
            debug_print("Comm.OBCP32: chopSrc    : " + chop_pos_SRC);
            debug_print("Comm.OBCP32: gratTime   : " + grat_time);
            debug_print("Comm.OBCP32: gratDefTime: " + grat_def_time);
            //    Call PacsDebug with only one inner loop!!
            PacsDebug_wave_switch_PV(gratPos,ditherCount,1,ditherSize,switch_param4,switch_param6,switch_param7,switch_param8);
        }
        //  Compute duration for ensemble of dithered cycles
        for(int loop4 = 0 .. 4) {
            time_array[lineNb - 1][loop4] = time_array[lineNb - 1][loop4] + timeOBCP[loop4];
        }
        // End of nbLines loop
    }
    // time_array indeces are [wavelength][mode]     
    if(verbose) {
        debug_print("Comm.CmdOBCP32 returns " + time_array);
    }
    // Add sync()
    sync();

    return time_array;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_GeGa_SFT_Init_Cold {
    /* No variables to call PacsEng_GeGa_SFT_Init_Cold                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_GeGa_SFT_Init_Cold                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_GeGa_SFT_Init_Cold()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_GeGa_SFT_Init_Cold();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : EQM IMT
//
// Purpose       : Close Launch Lock
//                  
// Author        : Helmut Feuchtgruber
// CUS script    : HF
// CVS file      : CloseLLock.txt
//
// Arguments     : none 
//
// Description   : 
//                  
// Dependencies  : 
//
// Preconditions : PACS is on or in the equivalent of SAFE mode
//                 
// Comments      : At the end PACS will still be in No Prime HK mode
//
// Version       : 1.0 30-Mar-2005 Creation by HF
//                     1.1 11-Apr-2006 HF, adapted to FM DMC User Manual
//                      1.2 12-Apr-2006 HF, include degraded mode operations
//                      1.3 12-Apr-2007 HF, ise standard CONF_grating procedure
// History       : 
//               :
int procedure CloseLLock {
    int lock_mode = 18; // use motors: 2=motor 1, 16 =motor 2, 18 = both motors
}{
    // Tally total duration [milliseconds]
    int duration_msec = 0;
    // Set HK list
    Pacs_DPU_SET_HK_LIST("SPEC","BOTH Array");
    // Synchronize on Det otherwise homing will not work
    Pacs_DMC_SYNCHRONIZE_ON_DET_RAW(4);
    // configure the grating  
    CONF_grating("CONFGrat","FMILT");
    // Move the grating to a central position
    Pacs_DMC_MOVE_GRAT_ABS(496000);
    // Disable the grating controller
    Pacs_DMC_DISABLE_GRAT_CONT();
    delay(2);
    // Unlock the grating launch lock
    Pacs_DMC_LOCK_GRAT(lock_mode);
    delay(12);
    duration_msec = duration_msec + 12000;
    // Switch off grating controller
    Pacs_DMC_SWOF_GRAT_CONT();
    // Set HK list
    Pacs_DPU_SET_HK_LIST("NO_PRIME","BOTH Array");
    sync();

    return duration_msec;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Purpose : Reduced NEP measurements for the new sequencer test
//           Search for the optimum bias with 11 values
//           using the high gain
//
// Author : Koryo Okumura
//
//
// Argument :
//    int response_measure_time = 60; // response measure time in seconds
//    int noise_measure_time = 120; // noise measure time in seconds
//    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//   + Instrument is in safe mode
//
// Description : OBS script of PHOT_redArray_DDCS_IST
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_oldSeq_IST(0)
//
// Version 	: 1.0 
// History	: 0.1 Fri Oct 05 12:00:34 CEST 2007
// 		: 1.0 translated into PV script VDP
//
obs PacsEng_Phot_redArray_DDCS_IST {
    /* Needed variables to call PacsEng_Phot_redArray_DDCS_IST                        */
    int response_measure_time = 60; // response measure time in seconds
    int noise_measure_time = 120; // noise measure time in seconds
    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_redArray_DDCS_IST                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PHOT_redArray_DDCS_IST(response_measure_time,noise_measure_time,biasFile)));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PHOT_redArray_DDCS_IST(response_measure_time,noise_measure_time,biasFile);
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Missionphase  : CQM
//
// Purpose       : CONFigure the servo grating loop using parameters read from
//                 a CAL-U file
//                  
// Author        : Diego A. Cesarsky / Pierre Royer
// CUS script    : Diego A. Cesarsky / Pierre Royer
//
// Arguments     : This version reads the ROW calUrow of the -calUname CAL-U file
// string calUname  Name of the CAL-U table
// string calUrow   Name of the ROW containing the desired controler params
//
// Description   : Reads grating controler parameters from a named row (viz.
// IMTwarm, IMTcold, ORBpv1, etc.) of a CAL-U table (default is "GRATconfig"),
// 
// Dependencies  : 
//
// Preconditions :
//
// Comments      : 
//
// Version       : 0.2
// History       : 0.1 26-Jan-2006 Creation by DAC
//		   0.2 12-Jun-2006 Read Rows instead of columns
//                 0.3 13-jun-2006 Renamed CALU table
//               :
block PACS_Spec_Gra_Conf_Calu PACS 171 {
    string calUname = "CONFGrat";
    string calUrow = "DMCUM";
}{
    // Read the demanded column of the given table.
    // Rows 0 to 8
    int word0 = ilookup(calUname,calUrow,"Kp");
    int word1 = ilookup(calUname,calUrow,"Ki");
    int word2 = ilookup(calUname,calUrow,"Kd");
    int word3 = ilookup(calUname,calUrow,"Kf");
    int word4 = ilookup(calUname,calUrow,"Rate");
    int word5 = ilookup(calUname,calUrow,"AccLimit");
    int word6 = ilookup(calUname,calUrow,"OutputLimit");
    int word7 = ilookup(calUname,calUrow,"Scaling");
    int word8 = ilookup(calUname,calUrow,"ErrorLimit");
    // Create the parameter list tuple
    {int}[] params = [{word0},{word1},{word2},{word3},{word4},{word5},{word6},{word7},{word8}];
    // Create the array for the checksum function
    int[] aux = [word0,word1,word2,word3,word4,word5,word6,word7,word8];
    int chksum = checksum("int",aux);
    // Send the TC
    Pacs_DMC_WRT_GRAT_CONF_PAR(params,chksum);
    delay(1);
    // Mark End of Block
    WriteEndBB();
}

// CVS comments  : $Id:
// Purpose       : Invoke  PACS aot prologue to start the science data flow  
//                 
//
// CUS author    : DAC
// Script file   : Pacs_PHOT_aot_Prologue
//
// Input arguments
// Type                      Description
//
// Return values
// Type    Name      Default      Description
//
// Description   : Perform AOT prologue
//
// Dependencies  : 
//
// Preconditions :
//                 
// Comments      : 
// 
// History       : 0.1 SCR 7005
int[] procedure Pacs_PHOT_aot_Prologue {
    bool verbose = true; // Debug_print or not 
    {int,int,int,int,int,int,int,int,int}[] confPHOTblu = [{0,64,0,0,0,0,0,0,0}]; // BLUE SPU parameters
    {int,int,int,int,int,int,int,int,int}[] confPHOTred = [{0,64,0,0,0,0,0,0,0}]; // RED  SPU parameters
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]; // OBCP parameters
    string filter = "blue2"; // PHOT filter
}{
    // Array to collect OBCP times per line
    int duree_num = 0;
    int duree_SRC = 0;
    int duree_REF = 0;
    int duree_CAL = 0;
    int duree_OVR = 0;
    int time_start = time();
    int[] totalDUREE = [0,0,0,0,0];
    // Table of filter wheel positions as per MIB
    // Actually originally not blue1 = SW = POS B, and blue2 = LW = POS A for
    // the photmeter
    if(filter == "blue1") {
        string filterID = "POS B";
    }
    if(filter == "blue2") {
        filterID = "POS A";
    }
    // Long sequence to "unpack" default values from tuples
    int gain_blu = confPHOTblu[0]{0};
    int comp_mode_blu = confPHOTblu[0]{3};
    int nb_raw_blu = confPHOTblu[0]{6};
    int gain_red = confPHOTred[0]{0};
    int comp_mode_red = confPHOTred[0]{3};
    int nb_raw_red = confPHOTred[0]{6};
    int filterPOS = confOBCP[0]{19};
    if(gain_blu == 1 && gain_red == 1) {
        string set_gain = "LOW";
    } else {
        if(gain_blu == 0 || gain_red == 0) {
            set_gain = "HIGH";
        }
    }
    totalDUREE = PHOT_aot_prologue(set_gain,comp_mode_blu,comp_mode_red,nb_raw_blu,nb_raw_red,verbose);
    // Turn the filter wheel
    int timeFLTW = PHOT_fltw_move(filterID);
    //  increment total duration and overheads
    totalDUREE[0] = totalDUREE[0] + timeFLTW;
    totalDUREE[4] = totalDUREE[4] + timeFLTW;
    // Tally total durations
    for(int loop0 = 0 .. 4) {
        totalDUREE[loop0] = totalDUREE[loop0];
    }
    if(verbose) {
        debug_print("***** PHOT AOT prologue (switch on science data) requires " + totalDUREE[0] + " [sec]");
    }
    // Leave bus scheduler in a known state (SP1707)
    sync();

    return totalDUREE;
}

// $Id$
// Missionphase  : PACS PV Phase
//
//
// Version       : 0.1
//
// Purpose       : Schedule the associated CUS procedure
//
// CUS author    : DAC
//
// Input arguments
// type    name         description
//
// Return values
// Type    Name        Description
//
// Description   : Set/resets OBSID, calls associated procedure
//
// Dependencies  : see associated procedure
//
// Preconditions : see associated procedure
//
// Comments      :
// 
// History       : 0.1 22-mar-2006
// History       : 0.1  11-feb-2008  Converted into Eng OBS by VDP
//
obs PacsEng_Phot_Cold_Startinputsignal {
    /* No variables to call PacsEng_Phot_Cold_Startinputsignal                        */
    /* string fltPOS = "POS A"; //Filter wheel position 0="POS A", 1="POS B" */
    /* End of needed variables for PacsEng_Phot_Cold_Startinputsignal                     */
}{
    // Four arguments needed for "no_pointing"
    // 1. Execute the pointing request
    bool execute = true;
    // 2. Initial hold
    //    Write OBSID during initial hold
    int tih = duration(WriteOBSID($OBSID));
    // 3. Final hold
    //    Declare OBS finished during final hold
    int tfh = duration(WriteEndID());
    // 4. Duration of "stable" pointing
    int tp = imax(1,duration(PACS_Phot_Cold_Startinputsignal()));
    // Issue PointReq
    int[] ts = no_pointing(execute,tih,tfh,tp);
}{
    // Start observation.
    // STATE_MACHINE logic. 
    // OBSID is handled during initial and final hold times. Otherwise, consider
    // only stable pointing
    int[] state = [0];
    while(state[0] >= 0) {
        state = next_state();
        if(state[0] == 2) {
            //        Declare start of OBS
            WriteOBSID($OBSID);
            data_rate(120.0);
        }
        if(state[0] == 3) {
            //        Call the required procedure
            PACS_Phot_Cold_Startinputsignal();
        }
        if(state[0] == 5) {
            //        Declare end of OBS
            data_rate(0.0);
            WriteEndID();
        }
    }
    // End of observation
}

// Mission phase : ILT at Garching
//
// Purpose :
//   Reduced NEP measurements for the new sequencer test
//
// Author : Koryo Okumura
//
// CUS script : procedure PHOT_redArray_direct_IST
//
// Argument :
//    int response_measure_time = 60; // response measure time in seconds
//    int noise_measure_time = 120; // noise measure time in seconds
//    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
//
// Check before executing :
//   + Cooler is recycled
//   + BOLC is ON
//
// Description :
//   + First, all 24 biases are set group by group
//   + Loop over 11 sets of 4 baisc biases (VH, VL, VRL, VH-BLIND) are set group by group
//   + Set PACS chopper on CS1 to measure the noise
//   + Loop over 11 sets of 4 baisc biases (VH, VL, VRL, VH-BLIND) are set group by group
//
// Dependencies : ILT data at low gain of PCD req.1.1.1
//
// Comments : generated by IA script : cus_oldSeq_IST(1)
//
// Version : Thu Oct 04 20:19:05 CEST 2007
//
procedure PHOT_redArray_direct_IST {
    int response_measure_time = 60; // response measure time in seconds
    int noise_measure_time = 120; // noise measure time in seconds
    string biasFile = "BOLObias_ILT_2pW_nominal_high"; // Bias table file containing the initial values
}{
    int operand = 0;
    int posCS1 = -21500;
    int posCS2 = 21500;
    //*********************************
    // Apply the old sequencer setting
    //*********************************
    //
    PACS_Phot_Sequencer_Setup();
    //
    //*******************************
    // Select Filter A (110 microns)
    //*******************************
    //
    PHOT_fltw_move("POS A");
    //
    //***********************************************
    //***********************************************
    //
    //	Bias setting of the detectors
    //
    //***********************************************
    //***********************************************
    //
    PHOT_set_bias_volt(biasFile,1);
    PHOT_set_bias_volt(biasFile,2);
    PHOT_set_bias_volt(biasFile,3);
    PHOT_set_bias_volt(biasFile,4);
    PHOT_set_bias_volt(biasFile,5);
    PHOT_set_bias_volt(biasFile,6);
    //
    //********************************************************
    // Sequence mode : blocking on VDEC_X for the direct mode
    //********************************************************
    //
    // Set all groups bol bias 09 (CKRLH) to 0.0 volt (0)
    Pacs_DMC_SEND_COMMAND_BOLC(0x90000);
    // Set all groups bol bias 12 (VDECX-L) to 2.0 volt (2298)
    Pacs_DMC_SEND_COMMAND_BOLC(0xc08fa);
    //
    //**************************
    // Sequence mode : Sref_only
    //**************************
    //
    // Stop SPU
    PACS_Phot_SPU_Reset();
    delay(1);
    // Set seq mode Sref_only (hexadecimal value to avoid the commanding confusion)
    //Pacs_BOLC_SET_SEQ_MODE("Sref_only");
    //# P 09 01 00 01
    operand = 0x9010001;
    Pacs_DMC_SEND_COMMAND_BOLC(operand);
    delay(1);
    // Start SPU with default photometry mode
    PACS_Phot_SPU_Setup();
    delay(1);
    // Set gain high
    Pacs_BOLC_SET_GAIN("HIGH");
    //
    //**********************************************
    // Set the PACS chopper at the central position
    //**********************************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(0);
    //
    //**********************************************************************
    //                       Response Measurement
    // Expected fluxes : 1.7 and 2.0pW on the blue
    //               and 5.3 and 6.2pW on the red
    //**********************************************************************
    //
    TMMarker600();
    //***********************************************************
    // Bias 1 (Vh-Vl)blue = 1.0 Volts, (Vh-Vl)red = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G1(0.99);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.2875928897414196 Volts
    Pacs_BOLC_SET_VRL_G1(0.2875928897414196);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.78435816010763 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.78435816010763);
    // Set group 2 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G2(0.99);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.2976890643549285 Volts
    Pacs_BOLC_SET_VRL_G2(0.2976890643549285);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.7946385038224304 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.7946385038224304);
    // Set group 3 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G3(0.99);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.2921869021406959 Volts
    Pacs_BOLC_SET_VRL_G3(0.2921869021406959);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.8111181679623898 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.8111181679623898);
    // Set group 4 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G4(0.99);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.2833032550752384 Volts
    Pacs_BOLC_SET_VRL_G4(0.2833032550752384);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.8038951101792082 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.8038951101792082);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3346340277410602 Volts
    Pacs_BOLC_SET_VRL_G5(0.3346340277410602);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8466792279676985 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8466792279676985);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.32636237036822335 Volts
    Pacs_BOLC_SET_VRL_G6(0.32636237036822335);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8367532617835844 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8367532617835844);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)blue = 1.2 Volts, (Vh-Vl)red = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G1(1.19);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.3577080013822565 Volts
    Pacs_BOLC_SET_VRL_G1(0.3577080013822565);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9420622421434064 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9420622421434064);
    // Set group 2 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G2(1.19);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.36696811904468774 Volts
    Pacs_BOLC_SET_VRL_G2(0.36696811904468774);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9515329512935697 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9515329512935697);
    // Set group 3 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G3(1.19);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.3640303856110917 Volts
    Pacs_BOLC_SET_VRL_G3(0.3640303856110917);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9482056457093682 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9482056457093682);
    // Set group 4 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G4(1.19);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3523579205628669 Volts
    Pacs_BOLC_SET_VRL_G4(0.3523579205628669);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9603646239045185 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9603646239045185);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4064368830411808 Volts
    Pacs_BOLC_SET_VRL_G5(0.4064368830411808);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8950576820742784 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8950576820742784);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.39643145192214363 Volts
    Pacs_BOLC_SET_VRL_G6(0.39643145192214363);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8837201139355604 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8837201139355604);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)blue = 1.4 Volts, (Vh-Vl)red = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.3525857926230986 Volts
    Pacs_BOLC_SET_VH_G1(1.3525857926230986);
    // Set group 1 bol bias 02 (VL) to -0.047414207376901184 Volts
    Pacs_BOLC_SET_VL_G1(-0.047414207376901184);
    // Set group 1 bol bias 03 (VRL) to 0.3926244201072773 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926244201072773);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.976547929868054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.976547929868054);
    // Set group 2 bol bias 01 (VH) to 1.3374255283716547 Volts
    Pacs_BOLC_SET_VH_G2(1.3374255283716547);
    // Set group 2 bol bias 02 (VL) to -0.06257447162834509 Volts
    Pacs_BOLC_SET_VL_G2(-0.06257447162834509);
    // Set group 2 bol bias 03 (VRL) to 0.38802799053825054 Volts
    Pacs_BOLC_SET_VRL_G2(0.38802799053825054);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9723540060682856 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9723540060682856);
    // Set group 3 bol bias 01 (VH) to 1.341267296137658 Volts
    Pacs_BOLC_SET_VH_G3(1.341267296137658);
    // Set group 3 bol bias 02 (VL) to -0.058732703862341994 Volts
    Pacs_BOLC_SET_VL_G3(-0.058732703862341994);
    // Set group 3 bol bias 03 (VRL) to 0.38970189090896923 Volts
    Pacs_BOLC_SET_VRL_G3(0.38970189090896923);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9735810667835696 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9735810667835696);
    // Set group 4 bol bias 01 (VH) to 1.352746675150765 Volts
    Pacs_BOLC_SET_VH_G4(1.352746675150765);
    // Set group 4 bol bias 02 (VL) to -0.04725332484923491 Volts
    Pacs_BOLC_SET_VL_G4(-0.04725332484923491);
    // Set group 4 bol bias 03 (VRL) to 0.3856108728986011 Volts
    Pacs_BOLC_SET_VRL_G4(0.3856108728986011);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9932003720526934 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9932003720526934);
    // Set group 5 bol bias 01 (VH) to 1.320583197395035 Volts
    Pacs_BOLC_SET_VH_G5(1.320583197395035);
    // Set group 5 bol bias 02 (VL) to -0.07941680260496485 Volts
    Pacs_BOLC_SET_VL_G5(-0.07941680260496485);
    // Set group 5 bol bias 03 (VRL) to 0.4116095244710064 Volts
    Pacs_BOLC_SET_VRL_G5(0.4116095244710064);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055742088043621 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055742088043621);
    // Set group 6 bol bias 01 (VH) to 1.3562697990163495 Volts
    Pacs_BOLC_SET_VH_G6(1.3562697990163495);
    // Set group 6 bol bias 02 (VL) to -0.04373020098365052 Volts
    Pacs_BOLC_SET_VL_G6(-0.04373020098365052);
    // Set group 6 bol bias 03 (VRL) to 0.43594530124025854 Volts
    Pacs_BOLC_SET_VRL_G6(0.43594530124025854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.011921670046162 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.011921670046162);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)blue = 1.6 Volts, (Vh-Vl)red = 1.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4783736198117614 Volts
    Pacs_BOLC_SET_VH_G1(1.4783736198117614);
    // Set group 1 bol bias 02 (VL) to -0.12162638018823857 Volts
    Pacs_BOLC_SET_VL_G1(-0.12162638018823857);
    // Set group 1 bol bias 03 (VRL) to 0.392515090355521 Volts
    Pacs_BOLC_SET_VRL_G1(0.392515090355521);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9764399412468519 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9764399412468519);
    // Set group 2 bol bias 01 (VH) to 1.4615686869832905 Volts
    Pacs_BOLC_SET_VH_G2(1.4615686869832905);
    // Set group 2 bol bias 02 (VL) to -0.13843131301670974 Volts
    Pacs_BOLC_SET_VL_G2(-0.13843131301670974);
    // Set group 2 bol bias 03 (VRL) to 0.3878839845398352 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878839845398352);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9722117106846373 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9722117106846373);
    // Set group 3 bol bias 01 (VH) to 1.4655563032867613 Volts
    Pacs_BOLC_SET_VH_G3(1.4655563032867613);
    // Set group 3 bol bias 02 (VL) to -0.13444369671323875 Volts
    Pacs_BOLC_SET_VL_G3(-0.13444369671323875);
    // Set group 3 bol bias 03 (VRL) to 0.38996914633068824 Volts
    Pacs_BOLC_SET_VRL_G3(0.38996914633068824);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9738455591218464 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9738455591218464);
    // Set group 4 bol bias 01 (VH) to 1.4803815567917744 Volts
    Pacs_BOLC_SET_VH_G4(1.4803815567917744);
    // Set group 4 bol bias 02 (VL) to -0.11961844320822568 Volts
    Pacs_BOLC_SET_VL_G4(-0.11961844320822568);
    // Set group 4 bol bias 03 (VRL) to 0.3860593630979322 Volts
    Pacs_BOLC_SET_VRL_G4(0.3860593630979322);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9936441996882226 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9936441996882226);
    // Set group 5 bol bias 01 (VH) to 1.3828510880972673 Volts
    Pacs_BOLC_SET_VH_G5(1.3828510880972673);
    // Set group 5 bol bias 02 (VL) to -0.11714891190273273 Volts
    Pacs_BOLC_SET_VL_G5(-0.11714891190273273);
    // Set group 5 bol bias 03 (VRL) to 0.4109562973201683 Volts
    Pacs_BOLC_SET_VRL_G5(0.4109562973201683);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055094312734005 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055094312734005);
    // Set group 6 bol bias 01 (VH) to 1.4187389541758537 Volts
    Pacs_BOLC_SET_VH_G6(1.4187389541758537);
    // Set group 6 bol bias 02 (VL) to -0.08126104582414631 Volts
    Pacs_BOLC_SET_VL_G6(-0.08126104582414631);
    // Set group 6 bol bias 03 (VRL) to 0.4349651037009118 Volts
    Pacs_BOLC_SET_VRL_G6(0.4349651037009118);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0109400872654906 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0109400872654906);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)blue = 1.7 Volts, (Vh-Vl)red = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.542293926761549 Volts
    Pacs_BOLC_SET_VH_G1(1.542293926761549);
    // Set group 1 bol bias 02 (VL) to -0.15770607323845098 Volts
    Pacs_BOLC_SET_VL_G1(-0.15770607323845098);
    // Set group 1 bol bias 03 (VRL) to 0.3926294451860477 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926294451860477);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9765528932845227 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9765528932845227);
    // Set group 2 bol bias 01 (VH) to 1.5247596019367946 Volts
    Pacs_BOLC_SET_VH_G2(1.5247596019367946);
    // Set group 2 bol bias 02 (VL) to -0.17524039806320546 Volts
    Pacs_BOLC_SET_VL_G2(-0.17524039806320546);
    // Set group 2 bol bias 03 (VRL) to 0.3878550325870832 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878550325870832);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9721831025166574 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9721831025166574);
    // Set group 3 bol bias 01 (VH) to 1.5286400044176514 Volts
    Pacs_BOLC_SET_VH_G3(1.5286400044176514);
    // Set group 3 bol bias 02 (VL) to -0.1713599955823485 Volts
    Pacs_BOLC_SET_VL_G3(-0.1713599955823485);
    // Set group 3 bol bias 03 (VRL) to 0.3901485670988867 Volts
    Pacs_BOLC_SET_VRL_G3(0.3901485670988867);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9740231261405279 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9740231261405279);
    // Set group 4 bol bias 01 (VH) to 1.5451742923820575 Volts
    Pacs_BOLC_SET_VH_G4(1.5451742923820575);
    // Set group 4 bol bias 02 (VL) to -0.15482570761794245 Volts
    Pacs_BOLC_SET_VL_G4(-0.15482570761794245);
    // Set group 4 bol bias 03 (VRL) to 0.3871858356177216 Volts
    Pacs_BOLC_SET_VRL_G4(0.3871858356177216);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9947589297629622 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9947589297629622);
    // Set group 5 bol bias 01 (VH) to 1.4463934011524333 Volts
    Pacs_BOLC_SET_VH_G5(1.4463934011524333);
    // Set group 5 bol bias 02 (VL) to -0.15360659884756683 Volts
    Pacs_BOLC_SET_VL_G5(-0.15360659884756683);
    // Set group 5 bol bias 03 (VRL) to 0.4101701125060366 Volts
    Pacs_BOLC_SET_VRL_G5(0.4101701125060366);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.054314719447538 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.054314719447538);
    // Set group 6 bol bias 01 (VH) to 1.4826068632993925 Volts
    Pacs_BOLC_SET_VH_G6(1.4826068632993925);
    // Set group 6 bol bias 02 (VL) to -0.11739313670060761 Volts
    Pacs_BOLC_SET_VL_G6(-0.11739313670060761);
    // Set group 6 bol bias 03 (VRL) to 0.4338779750444286 Volts
    Pacs_BOLC_SET_VRL_G6(0.4338779750444286);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.009851264439135 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.009851264439135);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)blue = 1.8 Volts, (Vh-Vl)red = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.60690529764583 Volts
    Pacs_BOLC_SET_VH_G1(1.60690529764583);
    // Set group 1 bol bias 02 (VL) to -0.19309470235416992 Volts
    Pacs_BOLC_SET_VL_G1(-0.19309470235416992);
    // Set group 1 bol bias 03 (VRL) to 0.39257168553053945 Volts
    Pacs_BOLC_SET_VRL_G1(0.39257168553053945);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9987180645064364 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9987180645064364);
    // Set group 2 bol bias 01 (VH) to 1.5888225493633414 Volts
    Pacs_BOLC_SET_VH_G2(1.5888225493633414);
    // Set group 2 bol bias 02 (VL) to -0.2111774506366586 Volts
    Pacs_BOLC_SET_VL_G2(-0.2111774506366586);
    // Set group 2 bol bias 03 (VRL) to 0.387719891228717 Volts
    Pacs_BOLC_SET_VRL_G2(0.387719891228717);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9720495652990864 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9720495652990864);
    // Set group 3 bol bias 01 (VH) to 1.5926816774791708 Volts
    Pacs_BOLC_SET_VH_G3(1.5926816774791708);
    // Set group 3 bol bias 02 (VL) to -0.20731832252082927 Volts
    Pacs_BOLC_SET_VL_G3(-0.20731832252082927);
    // Set group 3 bol bias 03 (VRL) to 0.39036266684895493 Volts
    Pacs_BOLC_SET_VRL_G3(0.39036266684895493);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.974235015140725 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.974235015140725);
    // Set group 4 bol bias 01 (VH) to 1.6103713769916332 Volts
    Pacs_BOLC_SET_VH_G4(1.6103713769916332);
    // Set group 4 bol bias 02 (VL) to -0.1896286230083667 Volts
    Pacs_BOLC_SET_VL_G4(-0.1896286230083667);
    // Set group 4 bol bias 03 (VRL) to 0.38763171869999546 Volts
    Pacs_BOLC_SET_VRL_G4(0.38763171869999546);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9952001524800798 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9952001524800798);
    // Set group 5 bol bias 01 (VH) to 1.575230733402161 Volts
    Pacs_BOLC_SET_VH_G5(1.575230733402161);
    // Set group 5 bol bias 02 (VL) to -0.22476926659783908 Volts
    Pacs_BOLC_SET_VL_G5(-0.22476926659783908);
    // Set group 5 bol bias 03 (VRL) to 0.40838061675412257 Volts
    Pacs_BOLC_SET_VRL_G5(0.40838061675412257);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.052540349440553 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.052540349440553);
    // Set group 6 bol bias 01 (VH) to 1.6128643450774607 Volts
    Pacs_BOLC_SET_VH_G6(1.6128643450774607);
    // Set group 6 bol bias 02 (VL) to -0.1871356549225394 Volts
    Pacs_BOLC_SET_VL_G6(-0.1871356549225394);
    // Set group 6 bol bias 03 (VRL) to 0.4319097861053989 Volts
    Pacs_BOLC_SET_VRL_G6(0.4319097861053989);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.007881605555887 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.007881605555887);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)blue = 2.0 Volts, (Vh-Vl)red = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.739376176417995 Volts
    Pacs_BOLC_SET_VH_G1(1.739376176417995);
    // Set group 1 bol bias 02 (VL) to -0.2606238235820051 Volts
    Pacs_BOLC_SET_VL_G1(-0.2606238235820051);
    // Set group 1 bol bias 03 (VRL) to 0.3921536831520859 Volts
    Pacs_BOLC_SET_VRL_G1(0.3921536831520859);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9760829613086472 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9760829613086472);
    // Set group 2 bol bias 01 (VH) to 1.719809813472755 Volts
    Pacs_BOLC_SET_VH_G2(1.719809813472755);
    // Set group 2 bol bias 02 (VL) to -0.28019018652724503 Volts
    Pacs_BOLC_SET_VL_G2(-0.28019018652724503);
    // Set group 2 bol bias 03 (VRL) to 0.38744168454874117 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744168454874117);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9717746579976725 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9717746579976725);
    // Set group 3 bol bias 01 (VH) to 1.7343527587435847 Volts
    Pacs_BOLC_SET_VH_G3(1.7343527587435847);
    // Set group 3 bol bias 02 (VL) to -0.2656472412564153 Volts
    Pacs_BOLC_SET_VL_G3(-0.2656472412564153);
    // Set group 3 bol bias 03 (VRL) to 0.4017790445564455 Volts
    Pacs_BOLC_SET_VRL_G3(0.4017790445564455);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9855314406558735 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9855314406558735);
    // Set group 4 bol bias 01 (VH) to 1.7440573141484068 Volts
    Pacs_BOLC_SET_VH_G4(1.7440573141484068);
    // Set group 4 bol bias 02 (VL) to -0.2559426858515932 Volts
    Pacs_BOLC_SET_VL_G4(-0.2559426858515932);
    // Set group 4 bol bias 03 (VRL) to 0.38894738596666634 Volts
    Pacs_BOLC_SET_VRL_G4(0.38894738596666634);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.996502027278406 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.996502027278406);
    // Set group 5 bol bias 01 (VH) to 1.6403549621270441 Volts
    Pacs_BOLC_SET_VH_G5(1.6403549621270441);
    // Set group 5 bol bias 02 (VL) to -0.25964503787295584 Volts
    Pacs_BOLC_SET_VL_G5(-0.25964503787295584);
    // Set group 5 bol bias 03 (VRL) to 0.4071234038646236 Volts
    Pacs_BOLC_SET_VRL_G5(0.4071234038646236);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051293864758269 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051293864758269);
    // Set group 6 bol bias 01 (VH) to 1.6787311020540112 Volts
    Pacs_BOLC_SET_VH_G6(1.6787311020540112);
    // Set group 6 bol bias 02 (VL) to -0.22126889794598872 Volts
    Pacs_BOLC_SET_VL_G6(-0.22126889794598872);
    // Set group 6 bol bias 03 (VRL) to 0.4305158637367362 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305158637367362);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0064867220677454 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0064867220677454);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)blue = 2.3 Volts, (Vh-Vl)red = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.9636608873020274 Volts
    Pacs_BOLC_SET_VH_G1(1.9636608873020274);
    // Set group 1 bol bias 02 (VL) to -0.3363391126979725 Volts
    Pacs_BOLC_SET_VL_G1(-0.3363391126979725);
    // Set group 1 bol bias 03 (VRL) to 0.40278769107629514 Volts
    Pacs_BOLC_SET_VRL_G1(0.40278769107629514);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9865763456310306 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9865763456310306);
    // Set group 2 bol bias 01 (VH) to 1.927696912686972 Volts
    Pacs_BOLC_SET_VH_G2(1.927696912686972);
    // Set group 2 bol bias 02 (VL) to -0.37230308731302775 Volts
    Pacs_BOLC_SET_VL_G2(-0.37230308731302775);
    // Set group 2 bol bias 03 (VRL) to 0.3858403551587576 Volts
    Pacs_BOLC_SET_VRL_G2(0.3858403551587576);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9924144642105024 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9924144642105024);
    // Set group 3 bol bias 01 (VH) to 1.9431226670014545 Volts
    Pacs_BOLC_SET_VH_G3(1.9431226670014545);
    // Set group 3 bol bias 02 (VL) to -0.35687733299854535 Volts
    Pacs_BOLC_SET_VL_G3(-0.35687733299854535);
    // Set group 3 bol bias 03 (VRL) to 0.4024839037666154 Volts
    Pacs_BOLC_SET_VRL_G3(0.4024839037666154);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9862268670149914 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9862268670149914);
    // Set group 4 bol bias 01 (VH) to 1.9579270398291708 Volts
    Pacs_BOLC_SET_VH_G4(1.9579270398291708);
    // Set group 4 bol bias 02 (VL) to -0.3420729601708289 Volts
    Pacs_BOLC_SET_VL_G4(-0.3420729601708289);
    // Set group 4 bol bias 03 (VRL) to 0.3906771012878555 Volts
    Pacs_BOLC_SET_VRL_G4(0.3906771012878555);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.99821351608857 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.99821351608857);
    // Set group 5 bol bias 01 (VH) to 1.7079035410760286 Volts
    Pacs_BOLC_SET_VH_G5(1.7079035410760286);
    // Set group 5 bol bias 02 (VL) to -0.29209645892397146 Volts
    Pacs_BOLC_SET_VL_G5(-0.29209645892397146);
    // Set group 5 bol bias 03 (VRL) to 0.405804322083024 Volts
    Pacs_BOLC_SET_VRL_G5(0.405804322083024);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0499861292550787 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0499861292550787);
    // Set group 6 bol bias 01 (VH) to 1.7476622867412348 Volts
    Pacs_BOLC_SET_VH_G6(1.7476622867412348);
    // Set group 6 bol bias 02 (VL) to -0.2523377132587652 Volts
    Pacs_BOLC_SET_VL_G6(-0.2523377132587652);
    // Set group 6 bol bias 03 (VRL) to 0.429562228366719 Volts
    Pacs_BOLC_SET_VRL_G6(0.429562228366719);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.005532468489443 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.005532468489443);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)blue = 2.6 Volts, (Vh-Vl)red = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2151628880310112 Volts
    Pacs_BOLC_SET_VH_G1(2.2151628880310112);
    // Set group 1 bol bias 02 (VL) to -0.3848371119689889 Volts
    Pacs_BOLC_SET_VL_G1(-0.3848371119689889);
    // Set group 1 bol bias 03 (VRL) to 0.41342338183313837 Volts
    Pacs_BOLC_SET_VRL_G1(0.41342338183313837);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0193446104924915 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0193446104924915);
    // Set group 2 bol bias 01 (VH) to 2.1588489399994213 Volts
    Pacs_BOLC_SET_VH_G2(2.1588489399994213);
    // Set group 2 bol bias 02 (VL) to -0.4411510600005787 Volts
    Pacs_BOLC_SET_VL_G2(-0.4411510600005787);
    // Set group 2 bol bias 03 (VRL) to 0.3838811209851186 Volts
    Pacs_BOLC_SET_VRL_G2(0.3838811209851186);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9682559687629309 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9682559687629309);
    // Set group 3 bol bias 01 (VH) to 2.1867239063317037 Volts
    Pacs_BOLC_SET_VH_G3(2.1867239063317037);
    // Set group 3 bol bias 02 (VL) to -0.4132760936682966 Volts
    Pacs_BOLC_SET_VL_G3(-0.4132760936682966);
    // Set group 3 bol bias 03 (VRL) to 0.4136603871411812 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136603871411812);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9973179392427267 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9973179392427267);
    // Set group 4 bol bias 01 (VH) to 2.20827452044462 Volts
    Pacs_BOLC_SET_VH_G4(2.20827452044462);
    // Set group 4 bol bias 02 (VL) to -0.39172547955538 Volts
    Pacs_BOLC_SET_VL_G4(-0.39172547955538);
    // Set group 4 bol bias 03 (VRL) to 0.4039414339062088 Volts
    Pacs_BOLC_SET_VRL_G4(0.4039414339062088);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.011301244644244 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.011301244644244);
    // Set group 5 bol bias 01 (VH) to 1.7875017871866707 Volts
    Pacs_BOLC_SET_VH_G5(1.7875017871866707);
    // Set group 5 bol bias 02 (VL) to -0.31249821281332946 Volts
    Pacs_BOLC_SET_VL_G5(-0.31249821281332946);
    // Set group 5 bol bias 03 (VRL) to 0.41576367399178094 Volts
    Pacs_BOLC_SET_VRL_G5(0.41576367399178094);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.037668873916454 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.037668873916454);
    // Set group 6 bol bias 01 (VH) to 1.8172008318899895 Volts
    Pacs_BOLC_SET_VH_G6(1.8172008318899895);
    // Set group 6 bol bias 02 (VL) to -0.2827991681100106 Volts
    Pacs_BOLC_SET_VL_G6(-0.2827991681100106);
    // Set group 6 bol bias 03 (VRL) to 0.42845474144203777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42845474144203777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.004424303719793 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.004424303719793);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)blue = 2.9 Volts, (Vh-Vl)red = 2.3 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.517666343337925 Volts
    Pacs_BOLC_SET_VH_G1(2.517666343337925);
    // Set group 1 bol bias 02 (VL) to -0.382333656662075 Volts
    Pacs_BOLC_SET_VL_G1(-0.382333656662075);
    // Set group 1 bol bias 03 (VRL) to 0.4351367995957048 Volts
    Pacs_BOLC_SET_VRL_G1(0.4351367995957048);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9965703186107444 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9965703186107444);
    // Set group 2 bol bias 01 (VH) to 2.4353683146246183 Volts
    Pacs_BOLC_SET_VH_G2(2.4353683146246183);
    // Set group 2 bol bias 02 (VL) to -0.4646316853753816 Volts
    Pacs_BOLC_SET_VL_G2(-0.4646316853753816);
    // Set group 2 bol bias 03 (VRL) to 0.39230855172448975 Volts
    Pacs_BOLC_SET_VRL_G2(0.39230855172448975);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9765832317921543 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9765832317921543);
    // Set group 3 bol bias 01 (VH) to 2.4565430314555052 Volts
    Pacs_BOLC_SET_VH_G3(2.4565430314555052);
    // Set group 3 bol bias 02 (VL) to -0.4434569685444947 Volts
    Pacs_BOLC_SET_VL_G3(-0.4434569685444947);
    // Set group 3 bol bias 03 (VRL) to 0.4116559215687209 Volts
    Pacs_BOLC_SET_VRL_G3(0.4116559215687209);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175436768747823 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175436768747823);
    // Set group 4 bol bias 01 (VH) to 2.4726040303622487 Volts
    Pacs_BOLC_SET_VH_G4(2.4726040303622487);
    // Set group 4 bol bias 02 (VL) to -0.4273959696377513 Volts
    Pacs_BOLC_SET_VL_G4(-0.4273959696377513);
    // Set group 4 bol bias 03 (VRL) to 0.3940712295914811 Volts
    Pacs_BOLC_SET_VRL_G4(0.3940712295914811);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.023793793137234 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.023793793137234);
    // Set group 5 bol bias 01 (VH) to 1.9226793871045598 Volts
    Pacs_BOLC_SET_VH_G5(1.9226793871045598);
    // Set group 5 bol bias 02 (VL) to -0.37732061289544 Volts
    Pacs_BOLC_SET_VL_G5(-0.37732061289544);
    // Set group 5 bol bias 03 (VRL) to 0.40093587460771146 Volts
    Pacs_BOLC_SET_VRL_G5(0.40093587460771146);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.022938134951507 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.022938134951507);
    // Set group 6 bol bias 01 (VH) to 1.9672658597937258 Volts
    Pacs_BOLC_SET_VH_G6(1.9672658597937258);
    // Set group 6 bol bias 02 (VL) to -0.332734140206274 Volts
    Pacs_BOLC_SET_VL_G6(-0.332734140206274);
    // Set group 6 bol bias 03 (VRL) to 0.4263945599495246 Volts
    Pacs_BOLC_SET_VRL_G6(0.4263945599495246);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.002362975913312 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.002362975913312);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)blue = 3.2 Volts, (Vh-Vl)red = 2.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.847199981495237 Volts
    Pacs_BOLC_SET_VH_G1(2.847199981495237);
    // Set group 1 bol bias 02 (VL) to -0.3528000185047631 Volts
    Pacs_BOLC_SET_VL_G1(-0.3528000185047631);
    // Set group 1 bol bias 03 (VRL) to 0.4347941377293029 Volts
    Pacs_BOLC_SET_VRL_G1(0.4347941377293029);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.018449774761696 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.018449774761696);
    // Set group 2 bol bias 01 (VH) to 2.7602559944480873 Volts
    Pacs_BOLC_SET_VH_G2(2.7602559944480873);
    // Set group 2 bol bias 02 (VL) to -0.43974400555191273 Volts
    Pacs_BOLC_SET_VL_G2(-0.43974400555191273);
    // Set group 2 bol bias 03 (VRL) to 0.4036708891743245 Volts
    Pacs_BOLC_SET_VRL_G2(0.4036708891743245);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.0099936291338243 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.0099936291338243);
    // Set group 3 bol bias 01 (VH) to 2.805732095961401 Volts
    Pacs_BOLC_SET_VH_G3(2.805732095961401);
    // Set group 3 bol bias 02 (VL) to -0.3942679040385992 Volts
    Pacs_BOLC_SET_VL_G3(-0.3942679040385992);
    // Set group 3 bol bias 03 (VRL) to 0.4339248022480186 Volts
    Pacs_BOLC_SET_VRL_G3(0.4339248022480186);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175166229478236 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175166229478236);
    // Set group 4 bol bias 01 (VH) to 2.8132260321912117 Volts
    Pacs_BOLC_SET_VH_G4(2.8132260321912117);
    // Set group 4 bol bias 02 (VL) to -0.3867739678087883 Volts
    Pacs_BOLC_SET_VL_G4(-0.3867739678087883);
    // Set group 4 bol bias 03 (VRL) to 0.4141623922109569 Volts
    Pacs_BOLC_SET_VRL_G4(0.4141623922109569);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.0213933637092976 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.0213933637092976);
    // Set group 5 bol bias 01 (VH) to 2.1145200531318697 Volts
    Pacs_BOLC_SET_VH_G5(2.1145200531318697);
    // Set group 5 bol bias 02 (VL) to -0.38547994686813014 Volts
    Pacs_BOLC_SET_VL_G5(-0.38547994686813014);
    // Set group 5 bol bias 03 (VRL) to 0.4292977832137159 Volts
    Pacs_BOLC_SET_VRL_G5(0.4292977832137159);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.006817368773259 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.006817368773259);
    // Set group 6 bol bias 01 (VH) to 2.1293608950052523 Volts
    Pacs_BOLC_SET_VH_G6(2.1293608950052523);
    // Set group 6 bol bias 02 (VL) to -0.3706391049947475 Volts
    Pacs_BOLC_SET_VL_G6(-0.3706391049947475);
    // Set group 6 bol bias 03 (VRL) to 0.4231555942593115 Volts
    Pacs_BOLC_SET_VRL_G6(0.4231555942593115);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9769002872568586 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9769002872568586);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for response_measure_time (s) with 0.5 Hz chopper
    TMMarker601();
    OBCP_chopped_photometry(0,0,39,0,0,response_measure_time / 2,1,posCS1,posCS2,0,0,0);
    TMMarker600();
    //
    //
    //************************************************************************
    //                           Noise Measurement
    // Expected fluxes : 1.7pW on the blue and 5.3pW on the red detector
    //************************************************************************
    //
    //*****************************
    // Set the PACS chopper on CS1
    //*****************************
    //
    Pacs_DMC_MOVE_CHOP_ABS(posCS1);
    //
    //***********************************************************
    // Bias 1 (Vh-Vl)blue = 1.0 Volts, (Vh-Vl)red = 1.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G1(0.99);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.2875928897414196 Volts
    Pacs_BOLC_SET_VRL_G1(0.2875928897414196);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.78435816010763 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.78435816010763);
    // Set group 2 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G2(0.99);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.2976890643549285 Volts
    Pacs_BOLC_SET_VRL_G2(0.2976890643549285);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.7946385038224304 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.7946385038224304);
    // Set group 3 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G3(0.99);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.2921869021406959 Volts
    Pacs_BOLC_SET_VRL_G3(0.2921869021406959);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.8111181679623898 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.8111181679623898);
    // Set group 4 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G4(0.99);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.2833032550752384 Volts
    Pacs_BOLC_SET_VRL_G4(0.2833032550752384);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.8038951101792082 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.8038951101792082);
    // Set group 5 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G5(0.99);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.3346340277410602 Volts
    Pacs_BOLC_SET_VRL_G5(0.3346340277410602);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8466792279676985 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8466792279676985);
    // Set group 6 bol bias 01 (VH) to 0.99 Volts
    Pacs_BOLC_SET_VH_G6(0.99);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.32636237036822335 Volts
    Pacs_BOLC_SET_VRL_G6(0.32636237036822335);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8367532617835844 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8367532617835844);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 2 (Vh-Vl)blue = 1.2 Volts, (Vh-Vl)red = 1.2 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G1(1.19);
    // Set group 1 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G1(-0.01);
    // Set group 1 bol bias 03 (VRL) to 0.3577080013822565 Volts
    Pacs_BOLC_SET_VRL_G1(0.3577080013822565);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9420622421434064 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9420622421434064);
    // Set group 2 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G2(1.19);
    // Set group 2 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G2(-0.01);
    // Set group 2 bol bias 03 (VRL) to 0.36696811904468774 Volts
    Pacs_BOLC_SET_VRL_G2(0.36696811904468774);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9515329512935697 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9515329512935697);
    // Set group 3 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G3(1.19);
    // Set group 3 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G3(-0.01);
    // Set group 3 bol bias 03 (VRL) to 0.3640303856110917 Volts
    Pacs_BOLC_SET_VRL_G3(0.3640303856110917);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9482056457093682 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9482056457093682);
    // Set group 4 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G4(1.19);
    // Set group 4 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G4(-0.01);
    // Set group 4 bol bias 03 (VRL) to 0.3523579205628669 Volts
    Pacs_BOLC_SET_VRL_G4(0.3523579205628669);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9603646239045185 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9603646239045185);
    // Set group 5 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G5(1.19);
    // Set group 5 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G5(-0.01);
    // Set group 5 bol bias 03 (VRL) to 0.4064368830411808 Volts
    Pacs_BOLC_SET_VRL_G5(0.4064368830411808);
    // Set group 5 bol bias 20 (VH_BLIND) to 1.8950576820742784 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(1.8950576820742784);
    // Set group 6 bol bias 01 (VH) to 1.19 Volts
    Pacs_BOLC_SET_VH_G6(1.19);
    // Set group 6 bol bias 02 (VL) to -0.01 Volts
    Pacs_BOLC_SET_VL_G6(-0.01);
    // Set group 6 bol bias 03 (VRL) to 0.39643145192214363 Volts
    Pacs_BOLC_SET_VRL_G6(0.39643145192214363);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.8837201139355604 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.8837201139355604);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 3 (Vh-Vl)blue = 1.4 Volts, (Vh-Vl)red = 1.4 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.3525857926230986 Volts
    Pacs_BOLC_SET_VH_G1(1.3525857926230986);
    // Set group 1 bol bias 02 (VL) to -0.047414207376901184 Volts
    Pacs_BOLC_SET_VL_G1(-0.047414207376901184);
    // Set group 1 bol bias 03 (VRL) to 0.3926244201072773 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926244201072773);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.976547929868054 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.976547929868054);
    // Set group 2 bol bias 01 (VH) to 1.3374255283716547 Volts
    Pacs_BOLC_SET_VH_G2(1.3374255283716547);
    // Set group 2 bol bias 02 (VL) to -0.06257447162834509 Volts
    Pacs_BOLC_SET_VL_G2(-0.06257447162834509);
    // Set group 2 bol bias 03 (VRL) to 0.38802799053825054 Volts
    Pacs_BOLC_SET_VRL_G2(0.38802799053825054);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9723540060682856 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9723540060682856);
    // Set group 3 bol bias 01 (VH) to 1.341267296137658 Volts
    Pacs_BOLC_SET_VH_G3(1.341267296137658);
    // Set group 3 bol bias 02 (VL) to -0.058732703862341994 Volts
    Pacs_BOLC_SET_VL_G3(-0.058732703862341994);
    // Set group 3 bol bias 03 (VRL) to 0.38970189090896923 Volts
    Pacs_BOLC_SET_VRL_G3(0.38970189090896923);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9735810667835696 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9735810667835696);
    // Set group 4 bol bias 01 (VH) to 1.352746675150765 Volts
    Pacs_BOLC_SET_VH_G4(1.352746675150765);
    // Set group 4 bol bias 02 (VL) to -0.04725332484923491 Volts
    Pacs_BOLC_SET_VL_G4(-0.04725332484923491);
    // Set group 4 bol bias 03 (VRL) to 0.3856108728986011 Volts
    Pacs_BOLC_SET_VRL_G4(0.3856108728986011);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9932003720526934 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9932003720526934);
    // Set group 5 bol bias 01 (VH) to 1.320583197395035 Volts
    Pacs_BOLC_SET_VH_G5(1.320583197395035);
    // Set group 5 bol bias 02 (VL) to -0.07941680260496485 Volts
    Pacs_BOLC_SET_VL_G5(-0.07941680260496485);
    // Set group 5 bol bias 03 (VRL) to 0.4116095244710064 Volts
    Pacs_BOLC_SET_VRL_G5(0.4116095244710064);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055742088043621 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055742088043621);
    // Set group 6 bol bias 01 (VH) to 1.3562697990163495 Volts
    Pacs_BOLC_SET_VH_G6(1.3562697990163495);
    // Set group 6 bol bias 02 (VL) to -0.04373020098365052 Volts
    Pacs_BOLC_SET_VL_G6(-0.04373020098365052);
    // Set group 6 bol bias 03 (VRL) to 0.43594530124025854 Volts
    Pacs_BOLC_SET_VRL_G6(0.43594530124025854);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.011921670046162 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.011921670046162);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 4 (Vh-Vl)blue = 1.6 Volts, (Vh-Vl)red = 1.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.4783736198117614 Volts
    Pacs_BOLC_SET_VH_G1(1.4783736198117614);
    // Set group 1 bol bias 02 (VL) to -0.12162638018823857 Volts
    Pacs_BOLC_SET_VL_G1(-0.12162638018823857);
    // Set group 1 bol bias 03 (VRL) to 0.392515090355521 Volts
    Pacs_BOLC_SET_VRL_G1(0.392515090355521);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9764399412468519 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9764399412468519);
    // Set group 2 bol bias 01 (VH) to 1.4615686869832905 Volts
    Pacs_BOLC_SET_VH_G2(1.4615686869832905);
    // Set group 2 bol bias 02 (VL) to -0.13843131301670974 Volts
    Pacs_BOLC_SET_VL_G2(-0.13843131301670974);
    // Set group 2 bol bias 03 (VRL) to 0.3878839845398352 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878839845398352);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9722117106846373 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9722117106846373);
    // Set group 3 bol bias 01 (VH) to 1.4655563032867613 Volts
    Pacs_BOLC_SET_VH_G3(1.4655563032867613);
    // Set group 3 bol bias 02 (VL) to -0.13444369671323875 Volts
    Pacs_BOLC_SET_VL_G3(-0.13444369671323875);
    // Set group 3 bol bias 03 (VRL) to 0.38996914633068824 Volts
    Pacs_BOLC_SET_VRL_G3(0.38996914633068824);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9738455591218464 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9738455591218464);
    // Set group 4 bol bias 01 (VH) to 1.4803815567917744 Volts
    Pacs_BOLC_SET_VH_G4(1.4803815567917744);
    // Set group 4 bol bias 02 (VL) to -0.11961844320822568 Volts
    Pacs_BOLC_SET_VL_G4(-0.11961844320822568);
    // Set group 4 bol bias 03 (VRL) to 0.3860593630979322 Volts
    Pacs_BOLC_SET_VRL_G4(0.3860593630979322);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9936441996882226 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9936441996882226);
    // Set group 5 bol bias 01 (VH) to 1.3828510880972673 Volts
    Pacs_BOLC_SET_VH_G5(1.3828510880972673);
    // Set group 5 bol bias 02 (VL) to -0.11714891190273273 Volts
    Pacs_BOLC_SET_VL_G5(-0.11714891190273273);
    // Set group 5 bol bias 03 (VRL) to 0.4109562973201683 Volts
    Pacs_BOLC_SET_VRL_G5(0.4109562973201683);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.055094312734005 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.055094312734005);
    // Set group 6 bol bias 01 (VH) to 1.4187389541758537 Volts
    Pacs_BOLC_SET_VH_G6(1.4187389541758537);
    // Set group 6 bol bias 02 (VL) to -0.08126104582414631 Volts
    Pacs_BOLC_SET_VL_G6(-0.08126104582414631);
    // Set group 6 bol bias 03 (VRL) to 0.4349651037009118 Volts
    Pacs_BOLC_SET_VRL_G6(0.4349651037009118);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0109400872654906 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0109400872654906);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 5 (Vh-Vl)blue = 1.7 Volts, (Vh-Vl)red = 1.6 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.542293926761549 Volts
    Pacs_BOLC_SET_VH_G1(1.542293926761549);
    // Set group 1 bol bias 02 (VL) to -0.15770607323845098 Volts
    Pacs_BOLC_SET_VL_G1(-0.15770607323845098);
    // Set group 1 bol bias 03 (VRL) to 0.3926294451860477 Volts
    Pacs_BOLC_SET_VRL_G1(0.3926294451860477);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9765528932845227 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9765528932845227);
    // Set group 2 bol bias 01 (VH) to 1.5247596019367946 Volts
    Pacs_BOLC_SET_VH_G2(1.5247596019367946);
    // Set group 2 bol bias 02 (VL) to -0.17524039806320546 Volts
    Pacs_BOLC_SET_VL_G2(-0.17524039806320546);
    // Set group 2 bol bias 03 (VRL) to 0.3878550325870832 Volts
    Pacs_BOLC_SET_VRL_G2(0.3878550325870832);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9721831025166574 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9721831025166574);
    // Set group 3 bol bias 01 (VH) to 1.5286400044176514 Volts
    Pacs_BOLC_SET_VH_G3(1.5286400044176514);
    // Set group 3 bol bias 02 (VL) to -0.1713599955823485 Volts
    Pacs_BOLC_SET_VL_G3(-0.1713599955823485);
    // Set group 3 bol bias 03 (VRL) to 0.3901485670988867 Volts
    Pacs_BOLC_SET_VRL_G3(0.3901485670988867);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9740231261405279 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9740231261405279);
    // Set group 4 bol bias 01 (VH) to 1.5451742923820575 Volts
    Pacs_BOLC_SET_VH_G4(1.5451742923820575);
    // Set group 4 bol bias 02 (VL) to -0.15482570761794245 Volts
    Pacs_BOLC_SET_VL_G4(-0.15482570761794245);
    // Set group 4 bol bias 03 (VRL) to 0.3871858356177216 Volts
    Pacs_BOLC_SET_VRL_G4(0.3871858356177216);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9947589297629622 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9947589297629622);
    // Set group 5 bol bias 01 (VH) to 1.4463934011524333 Volts
    Pacs_BOLC_SET_VH_G5(1.4463934011524333);
    // Set group 5 bol bias 02 (VL) to -0.15360659884756683 Volts
    Pacs_BOLC_SET_VL_G5(-0.15360659884756683);
    // Set group 5 bol bias 03 (VRL) to 0.4101701125060366 Volts
    Pacs_BOLC_SET_VRL_G5(0.4101701125060366);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.054314719447538 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.054314719447538);
    // Set group 6 bol bias 01 (VH) to 1.4826068632993925 Volts
    Pacs_BOLC_SET_VH_G6(1.4826068632993925);
    // Set group 6 bol bias 02 (VL) to -0.11739313670060761 Volts
    Pacs_BOLC_SET_VL_G6(-0.11739313670060761);
    // Set group 6 bol bias 03 (VRL) to 0.4338779750444286 Volts
    Pacs_BOLC_SET_VRL_G6(0.4338779750444286);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.009851264439135 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.009851264439135);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 6 (Vh-Vl)blue = 1.8 Volts, (Vh-Vl)red = 1.8 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.60690529764583 Volts
    Pacs_BOLC_SET_VH_G1(1.60690529764583);
    // Set group 1 bol bias 02 (VL) to -0.19309470235416992 Volts
    Pacs_BOLC_SET_VL_G1(-0.19309470235416992);
    // Set group 1 bol bias 03 (VRL) to 0.39257168553053945 Volts
    Pacs_BOLC_SET_VRL_G1(0.39257168553053945);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9987180645064364 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9987180645064364);
    // Set group 2 bol bias 01 (VH) to 1.5888225493633414 Volts
    Pacs_BOLC_SET_VH_G2(1.5888225493633414);
    // Set group 2 bol bias 02 (VL) to -0.2111774506366586 Volts
    Pacs_BOLC_SET_VL_G2(-0.2111774506366586);
    // Set group 2 bol bias 03 (VRL) to 0.387719891228717 Volts
    Pacs_BOLC_SET_VRL_G2(0.387719891228717);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9720495652990864 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9720495652990864);
    // Set group 3 bol bias 01 (VH) to 1.5926816774791708 Volts
    Pacs_BOLC_SET_VH_G3(1.5926816774791708);
    // Set group 3 bol bias 02 (VL) to -0.20731832252082927 Volts
    Pacs_BOLC_SET_VL_G3(-0.20731832252082927);
    // Set group 3 bol bias 03 (VRL) to 0.39036266684895493 Volts
    Pacs_BOLC_SET_VRL_G3(0.39036266684895493);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.974235015140725 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.974235015140725);
    // Set group 4 bol bias 01 (VH) to 1.6103713769916332 Volts
    Pacs_BOLC_SET_VH_G4(1.6103713769916332);
    // Set group 4 bol bias 02 (VL) to -0.1896286230083667 Volts
    Pacs_BOLC_SET_VL_G4(-0.1896286230083667);
    // Set group 4 bol bias 03 (VRL) to 0.38763171869999546 Volts
    Pacs_BOLC_SET_VRL_G4(0.38763171869999546);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.9952001524800798 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.9952001524800798);
    // Set group 5 bol bias 01 (VH) to 1.575230733402161 Volts
    Pacs_BOLC_SET_VH_G5(1.575230733402161);
    // Set group 5 bol bias 02 (VL) to -0.22476926659783908 Volts
    Pacs_BOLC_SET_VL_G5(-0.22476926659783908);
    // Set group 5 bol bias 03 (VRL) to 0.40838061675412257 Volts
    Pacs_BOLC_SET_VRL_G5(0.40838061675412257);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.052540349440553 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.052540349440553);
    // Set group 6 bol bias 01 (VH) to 1.6128643450774607 Volts
    Pacs_BOLC_SET_VH_G6(1.6128643450774607);
    // Set group 6 bol bias 02 (VL) to -0.1871356549225394 Volts
    Pacs_BOLC_SET_VL_G6(-0.1871356549225394);
    // Set group 6 bol bias 03 (VRL) to 0.4319097861053989 Volts
    Pacs_BOLC_SET_VRL_G6(0.4319097861053989);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.007881605555887 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.007881605555887);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 7 (Vh-Vl)blue = 2.0 Volts, (Vh-Vl)red = 1.9 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.739376176417995 Volts
    Pacs_BOLC_SET_VH_G1(1.739376176417995);
    // Set group 1 bol bias 02 (VL) to -0.2606238235820051 Volts
    Pacs_BOLC_SET_VL_G1(-0.2606238235820051);
    // Set group 1 bol bias 03 (VRL) to 0.3921536831520859 Volts
    Pacs_BOLC_SET_VRL_G1(0.3921536831520859);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9760829613086472 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9760829613086472);
    // Set group 2 bol bias 01 (VH) to 1.719809813472755 Volts
    Pacs_BOLC_SET_VH_G2(1.719809813472755);
    // Set group 2 bol bias 02 (VL) to -0.28019018652724503 Volts
    Pacs_BOLC_SET_VL_G2(-0.28019018652724503);
    // Set group 2 bol bias 03 (VRL) to 0.38744168454874117 Volts
    Pacs_BOLC_SET_VRL_G2(0.38744168454874117);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9717746579976725 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9717746579976725);
    // Set group 3 bol bias 01 (VH) to 1.7343527587435847 Volts
    Pacs_BOLC_SET_VH_G3(1.7343527587435847);
    // Set group 3 bol bias 02 (VL) to -0.2656472412564153 Volts
    Pacs_BOLC_SET_VL_G3(-0.2656472412564153);
    // Set group 3 bol bias 03 (VRL) to 0.4017790445564455 Volts
    Pacs_BOLC_SET_VRL_G3(0.4017790445564455);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9855314406558735 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9855314406558735);
    // Set group 4 bol bias 01 (VH) to 1.7440573141484068 Volts
    Pacs_BOLC_SET_VH_G4(1.7440573141484068);
    // Set group 4 bol bias 02 (VL) to -0.2559426858515932 Volts
    Pacs_BOLC_SET_VL_G4(-0.2559426858515932);
    // Set group 4 bol bias 03 (VRL) to 0.38894738596666634 Volts
    Pacs_BOLC_SET_VRL_G4(0.38894738596666634);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.996502027278406 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.996502027278406);
    // Set group 5 bol bias 01 (VH) to 1.6403549621270441 Volts
    Pacs_BOLC_SET_VH_G5(1.6403549621270441);
    // Set group 5 bol bias 02 (VL) to -0.25964503787295584 Volts
    Pacs_BOLC_SET_VL_G5(-0.25964503787295584);
    // Set group 5 bol bias 03 (VRL) to 0.4071234038646236 Volts
    Pacs_BOLC_SET_VRL_G5(0.4071234038646236);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.051293864758269 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.051293864758269);
    // Set group 6 bol bias 01 (VH) to 1.6787311020540112 Volts
    Pacs_BOLC_SET_VH_G6(1.6787311020540112);
    // Set group 6 bol bias 02 (VL) to -0.22126889794598872 Volts
    Pacs_BOLC_SET_VL_G6(-0.22126889794598872);
    // Set group 6 bol bias 03 (VRL) to 0.4305158637367362 Volts
    Pacs_BOLC_SET_VRL_G6(0.4305158637367362);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.0064867220677454 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.0064867220677454);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 8 (Vh-Vl)blue = 2.3 Volts, (Vh-Vl)red = 2.0 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 1.9636608873020274 Volts
    Pacs_BOLC_SET_VH_G1(1.9636608873020274);
    // Set group 1 bol bias 02 (VL) to -0.3363391126979725 Volts
    Pacs_BOLC_SET_VL_G1(-0.3363391126979725);
    // Set group 1 bol bias 03 (VRL) to 0.40278769107629514 Volts
    Pacs_BOLC_SET_VRL_G1(0.40278769107629514);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9865763456310306 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9865763456310306);
    // Set group 2 bol bias 01 (VH) to 1.927696912686972 Volts
    Pacs_BOLC_SET_VH_G2(1.927696912686972);
    // Set group 2 bol bias 02 (VL) to -0.37230308731302775 Volts
    Pacs_BOLC_SET_VL_G2(-0.37230308731302775);
    // Set group 2 bol bias 03 (VRL) to 0.3858403551587576 Volts
    Pacs_BOLC_SET_VRL_G2(0.3858403551587576);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9924144642105024 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9924144642105024);
    // Set group 3 bol bias 01 (VH) to 1.9431226670014545 Volts
    Pacs_BOLC_SET_VH_G3(1.9431226670014545);
    // Set group 3 bol bias 02 (VL) to -0.35687733299854535 Volts
    Pacs_BOLC_SET_VL_G3(-0.35687733299854535);
    // Set group 3 bol bias 03 (VRL) to 0.4024839037666154 Volts
    Pacs_BOLC_SET_VRL_G3(0.4024839037666154);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9862268670149914 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9862268670149914);
    // Set group 4 bol bias 01 (VH) to 1.9579270398291708 Volts
    Pacs_BOLC_SET_VH_G4(1.9579270398291708);
    // Set group 4 bol bias 02 (VL) to -0.3420729601708289 Volts
    Pacs_BOLC_SET_VL_G4(-0.3420729601708289);
    // Set group 4 bol bias 03 (VRL) to 0.3906771012878555 Volts
    Pacs_BOLC_SET_VRL_G4(0.3906771012878555);
    // Set group 4 bol bias 20 (VH_BLIND) to 1.99821351608857 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(1.99821351608857);
    // Set group 5 bol bias 01 (VH) to 1.7079035410760286 Volts
    Pacs_BOLC_SET_VH_G5(1.7079035410760286);
    // Set group 5 bol bias 02 (VL) to -0.29209645892397146 Volts
    Pacs_BOLC_SET_VL_G5(-0.29209645892397146);
    // Set group 5 bol bias 03 (VRL) to 0.405804322083024 Volts
    Pacs_BOLC_SET_VRL_G5(0.405804322083024);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.0499861292550787 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.0499861292550787);
    // Set group 6 bol bias 01 (VH) to 1.7476622867412348 Volts
    Pacs_BOLC_SET_VH_G6(1.7476622867412348);
    // Set group 6 bol bias 02 (VL) to -0.2523377132587652 Volts
    Pacs_BOLC_SET_VL_G6(-0.2523377132587652);
    // Set group 6 bol bias 03 (VRL) to 0.429562228366719 Volts
    Pacs_BOLC_SET_VRL_G6(0.429562228366719);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.005532468489443 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.005532468489443);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 9 (Vh-Vl)blue = 2.6 Volts, (Vh-Vl)red = 2.1 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.2151628880310112 Volts
    Pacs_BOLC_SET_VH_G1(2.2151628880310112);
    // Set group 1 bol bias 02 (VL) to -0.3848371119689889 Volts
    Pacs_BOLC_SET_VL_G1(-0.3848371119689889);
    // Set group 1 bol bias 03 (VRL) to 0.41342338183313837 Volts
    Pacs_BOLC_SET_VRL_G1(0.41342338183313837);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.0193446104924915 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.0193446104924915);
    // Set group 2 bol bias 01 (VH) to 2.1588489399994213 Volts
    Pacs_BOLC_SET_VH_G2(2.1588489399994213);
    // Set group 2 bol bias 02 (VL) to -0.4411510600005787 Volts
    Pacs_BOLC_SET_VL_G2(-0.4411510600005787);
    // Set group 2 bol bias 03 (VRL) to 0.3838811209851186 Volts
    Pacs_BOLC_SET_VRL_G2(0.3838811209851186);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9682559687629309 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9682559687629309);
    // Set group 3 bol bias 01 (VH) to 2.1867239063317037 Volts
    Pacs_BOLC_SET_VH_G3(2.1867239063317037);
    // Set group 3 bol bias 02 (VL) to -0.4132760936682966 Volts
    Pacs_BOLC_SET_VL_G3(-0.4132760936682966);
    // Set group 3 bol bias 03 (VRL) to 0.4136603871411812 Volts
    Pacs_BOLC_SET_VRL_G3(0.4136603871411812);
    // Set group 3 bol bias 20 (VH_BLIND) to 1.9973179392427267 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(1.9973179392427267);
    // Set group 4 bol bias 01 (VH) to 2.20827452044462 Volts
    Pacs_BOLC_SET_VH_G4(2.20827452044462);
    // Set group 4 bol bias 02 (VL) to -0.39172547955538 Volts
    Pacs_BOLC_SET_VL_G4(-0.39172547955538);
    // Set group 4 bol bias 03 (VRL) to 0.4039414339062088 Volts
    Pacs_BOLC_SET_VRL_G4(0.4039414339062088);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.011301244644244 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.011301244644244);
    // Set group 5 bol bias 01 (VH) to 1.7875017871866707 Volts
    Pacs_BOLC_SET_VH_G5(1.7875017871866707);
    // Set group 5 bol bias 02 (VL) to -0.31249821281332946 Volts
    Pacs_BOLC_SET_VL_G5(-0.31249821281332946);
    // Set group 5 bol bias 03 (VRL) to 0.41576367399178094 Volts
    Pacs_BOLC_SET_VRL_G5(0.41576367399178094);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.037668873916454 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.037668873916454);
    // Set group 6 bol bias 01 (VH) to 1.8172008318899895 Volts
    Pacs_BOLC_SET_VH_G6(1.8172008318899895);
    // Set group 6 bol bias 02 (VL) to -0.2827991681100106 Volts
    Pacs_BOLC_SET_VL_G6(-0.2827991681100106);
    // Set group 6 bol bias 03 (VRL) to 0.42845474144203777 Volts
    Pacs_BOLC_SET_VRL_G6(0.42845474144203777);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.004424303719793 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.004424303719793);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 10 (Vh-Vl)blue = 2.9 Volts, (Vh-Vl)red = 2.3 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.517666343337925 Volts
    Pacs_BOLC_SET_VH_G1(2.517666343337925);
    // Set group 1 bol bias 02 (VL) to -0.382333656662075 Volts
    Pacs_BOLC_SET_VL_G1(-0.382333656662075);
    // Set group 1 bol bias 03 (VRL) to 0.4351367995957048 Volts
    Pacs_BOLC_SET_VRL_G1(0.4351367995957048);
    // Set group 1 bol bias 20 (VH_BLIND) to 1.9965703186107444 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(1.9965703186107444);
    // Set group 2 bol bias 01 (VH) to 2.4353683146246183 Volts
    Pacs_BOLC_SET_VH_G2(2.4353683146246183);
    // Set group 2 bol bias 02 (VL) to -0.4646316853753816 Volts
    Pacs_BOLC_SET_VL_G2(-0.4646316853753816);
    // Set group 2 bol bias 03 (VRL) to 0.39230855172448975 Volts
    Pacs_BOLC_SET_VRL_G2(0.39230855172448975);
    // Set group 2 bol bias 20 (VH_BLIND) to 1.9765832317921543 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(1.9765832317921543);
    // Set group 3 bol bias 01 (VH) to 2.4565430314555052 Volts
    Pacs_BOLC_SET_VH_G3(2.4565430314555052);
    // Set group 3 bol bias 02 (VL) to -0.4434569685444947 Volts
    Pacs_BOLC_SET_VL_G3(-0.4434569685444947);
    // Set group 3 bol bias 03 (VRL) to 0.4116559215687209 Volts
    Pacs_BOLC_SET_VRL_G3(0.4116559215687209);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175436768747823 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175436768747823);
    // Set group 4 bol bias 01 (VH) to 2.4726040303622487 Volts
    Pacs_BOLC_SET_VH_G4(2.4726040303622487);
    // Set group 4 bol bias 02 (VL) to -0.4273959696377513 Volts
    Pacs_BOLC_SET_VL_G4(-0.4273959696377513);
    // Set group 4 bol bias 03 (VRL) to 0.3940712295914811 Volts
    Pacs_BOLC_SET_VRL_G4(0.3940712295914811);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.023793793137234 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.023793793137234);
    // Set group 5 bol bias 01 (VH) to 1.9226793871045598 Volts
    Pacs_BOLC_SET_VH_G5(1.9226793871045598);
    // Set group 5 bol bias 02 (VL) to -0.37732061289544 Volts
    Pacs_BOLC_SET_VL_G5(-0.37732061289544);
    // Set group 5 bol bias 03 (VRL) to 0.40093587460771146 Volts
    Pacs_BOLC_SET_VRL_G5(0.40093587460771146);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.022938134951507 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.022938134951507);
    // Set group 6 bol bias 01 (VH) to 1.9672658597937258 Volts
    Pacs_BOLC_SET_VH_G6(1.9672658597937258);
    // Set group 6 bol bias 02 (VL) to -0.332734140206274 Volts
    Pacs_BOLC_SET_VL_G6(-0.332734140206274);
    // Set group 6 bol bias 03 (VRL) to 0.4263945599495246 Volts
    Pacs_BOLC_SET_VRL_G6(0.4263945599495246);
    // Set group 6 bol bias 20 (VH_BLIND) to 2.002362975913312 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(2.002362975913312);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
    //***********************************************************
    // Bias 11 (Vh-Vl)blue = 3.2 Volts, (Vh-Vl)red = 2.5 Volts
    //***********************************************************
    // Set group 1 bol bias 01 (VH) to 2.847199981495237 Volts
    Pacs_BOLC_SET_VH_G1(2.847199981495237);
    // Set group 1 bol bias 02 (VL) to -0.3528000185047631 Volts
    Pacs_BOLC_SET_VL_G1(-0.3528000185047631);
    // Set group 1 bol bias 03 (VRL) to 0.4347941377293029 Volts
    Pacs_BOLC_SET_VRL_G1(0.4347941377293029);
    // Set group 1 bol bias 20 (VH_BLIND) to 2.018449774761696 Volts
    Pacs_BOLC_SET_VH_BLIND_G1(2.018449774761696);
    // Set group 2 bol bias 01 (VH) to 2.7602559944480873 Volts
    Pacs_BOLC_SET_VH_G2(2.7602559944480873);
    // Set group 2 bol bias 02 (VL) to -0.43974400555191273 Volts
    Pacs_BOLC_SET_VL_G2(-0.43974400555191273);
    // Set group 2 bol bias 03 (VRL) to 0.4036708891743245 Volts
    Pacs_BOLC_SET_VRL_G2(0.4036708891743245);
    // Set group 2 bol bias 20 (VH_BLIND) to 2.0099936291338243 Volts
    Pacs_BOLC_SET_VH_BLIND_G2(2.0099936291338243);
    // Set group 3 bol bias 01 (VH) to 2.805732095961401 Volts
    Pacs_BOLC_SET_VH_G3(2.805732095961401);
    // Set group 3 bol bias 02 (VL) to -0.3942679040385992 Volts
    Pacs_BOLC_SET_VL_G3(-0.3942679040385992);
    // Set group 3 bol bias 03 (VRL) to 0.4339248022480186 Volts
    Pacs_BOLC_SET_VRL_G3(0.4339248022480186);
    // Set group 3 bol bias 20 (VH_BLIND) to 2.0175166229478236 Volts
    Pacs_BOLC_SET_VH_BLIND_G3(2.0175166229478236);
    // Set group 4 bol bias 01 (VH) to 2.8132260321912117 Volts
    Pacs_BOLC_SET_VH_G4(2.8132260321912117);
    // Set group 4 bol bias 02 (VL) to -0.3867739678087883 Volts
    Pacs_BOLC_SET_VL_G4(-0.3867739678087883);
    // Set group 4 bol bias 03 (VRL) to 0.4141623922109569 Volts
    Pacs_BOLC_SET_VRL_G4(0.4141623922109569);
    // Set group 4 bol bias 20 (VH_BLIND) to 2.0213933637092976 Volts
    Pacs_BOLC_SET_VH_BLIND_G4(2.0213933637092976);
    // Set group 5 bol bias 01 (VH) to 2.1145200531318697 Volts
    Pacs_BOLC_SET_VH_G5(2.1145200531318697);
    // Set group 5 bol bias 02 (VL) to -0.38547994686813014 Volts
    Pacs_BOLC_SET_VL_G5(-0.38547994686813014);
    // Set group 5 bol bias 03 (VRL) to 0.4292977832137159 Volts
    Pacs_BOLC_SET_VRL_G5(0.4292977832137159);
    // Set group 5 bol bias 20 (VH_BLIND) to 2.006817368773259 Volts
    Pacs_BOLC_SET_VH_BLIND_G5(2.006817368773259);
    // Set group 6 bol bias 01 (VH) to 2.1293608950052523 Volts
    Pacs_BOLC_SET_VH_G6(2.1293608950052523);
    // Set group 6 bol bias 02 (VL) to -0.3706391049947475 Volts
    Pacs_BOLC_SET_VL_G6(-0.3706391049947475);
    // Set group 6 bol bias 03 (VRL) to 0.4231555942593115 Volts
    Pacs_BOLC_SET_VRL_G6(0.4231555942593115);
    // Set group 6 bol bias 20 (VH_BLIND) to 1.9769002872568586 Volts
    Pacs_BOLC_SET_VH_BLIND_G6(1.9769002872568586);
    // Wait for 120 s for stabilization
    delay(120);
    // Measurement for noise_measure_time seconds
    TMMarker602();
    delay(noise_measure_time);
    TMMarker600();
}

// File          : PACS_Spec_Curing_OBS.cus
// Missionphase  : PACS FM ILT tests
//
// Purpose       : Buffer Transmission mode staring measurement for the spectrometer
//
// Author        : P. Royer
//
// Arguments     : CRE setup arguments, grating & fw positions, staring time 
//
// Prerequisite  : configuration of all mechanisms (spec_aot_prologue or spec_orbit_prologue)
//
// Dependencies : SPEC_cre_setup
//                        SPEC_spu_setup
//	     SPEC_spu_reset
//	     SPEC_fltw_move
//	     OBCP_SAFE
//
// Description   : CRE setup (parametrized)
//                       SPU setup (Buffer transmission mode)
//                       Position chopper (BB2), FW & Grating (parametrized)
//	    staring
//                       spu_reset
//                       OBCP_SAFE()
//
// Comments      : Makes use of atomic commands for mechanisms
//                        Returns the instrument to SAFE_MODE
//
// Version       : 1.1
// History       : 1.0 / 12-Mar-2008 initial version by PR
//	 1.1 / 03-Jul-2008 removed call to SAFE MODE OBCP in the end
//
//  -----------------------------------
// @author P. Royer
// @date today
// @version 1.1
// @purpose Buffer transmission mode obs, with fixed grating
// @comment - 
//
procedure PACS_Spec_BufferTransmission_Stare {
    int ramp_len_red = 64; // Red ramps length
    int ramp_len_blu = 64; // Blue ramps length
    double bias_d_red = 0.07 in [0.0,1.0]; // BIAS_D for red spectro  (0-1V)
    double bias_d_blu = 0.21 in [0.0,1.0]; // BIAS_D for blue spectro (0-1V)
    int capa_red = 8; // Capacitor red (0=0.1pF,8=0.2pF,4=0.4pF,12=1pF)
    int capa_blu = 8; // Capacitor blue (0=0.1pF,8=0.2pF,4=0.4pF,12=1pF)
    int grat_pos = 500000; // Grating position during the observation (fixed)
    string filter_pos = "POS B" in ["POS A","POS B"]; // FW position during the observation (fixed)
    int chop_pos = 21200; // Chopper Position (default 21200 = CS2)
    int stare_time = 7200; // Idle time in buffer transmission mode
}{
    // Internal parameters
    // -------------------
    //int chop_pos_BB1 = -21350;
    //int chop_pos_BB2 = 21200;
    double bias_r_red = 0.011;
    // in [0.0,1.0]; // BIAS_R for red spectro  (0-1V)
    double bias_r_blu = 0.011;
    // in [0.0,1.0]; // BIAS_R for blue spectro (0-1V)
    //
    // CRE SETUP
    // NOTE: capa_xxx is added to cre_ctrl_xx within SPEC_cre_setup
    //
    int cre_ctrl_red = 386;
    int cre_ctrl_blu = 386;
    SPEC_cre_setup(cre_ctrl_red,cre_ctrl_blu,ramp_len_red,ramp_len_blu,bias_d_red,bias_r_red,bias_d_blu,bias_r_blu,capa_red,capa_blu);
    //
    // DPU SETUP -> BURST MODE
    //
    Pacs_DPU_SET_BUS_LIST("ENABLE");
    //
    // SPU SETUP
    //
    int comp_mode_blu = 0x19;
    // Compression mode blue channel: BUFFER TRANSMISSION
    int comp_mode_red = 0x19;
    // Compression mode red channel: BUFFER TRANSMISSION
    int nb_samp_subramp_blu = 16;
    // Nb of blue samples per sub-ramp
    int nb_samp_subramp_red = 16;
    // Nb of red samples per sub-ramp
    int nb_raw_spu_blu = 3;
    // Nb of raw channels transmitted by SPUS
    int nb_raw_spu_red = 3;
    // Nb of raw channels transmitted by SPUL
    int glitch_det = 1;
    // Glitch detection; 0=on; 1=off
    int ramp_fit_alg = 1;
    // Ramp fit algorithm [0=LstSq;1=mean value]
    bool startSPU = true;
    // Start SPU or not [true,false]
    SPEC_spu_setup(comp_mode_blu,comp_mode_red,nb_samp_subramp_blu,nb_samp_subramp_red,nb_raw_spu_blu,nb_raw_spu_red,glitch_det,ramp_fit_alg,startSPU);
    delay(5);
    //
    // MECHANISMS
    //
    // CHOPPER -> BB1
    //PACS_Chop_Move_Abs(chop_pos_BB1);
    Pacs_DMC_MOVE_CHOP_ABS_RAW(chop_pos);
    delay(1);
    // GRATING & FW
    // move FW first because it demands to disable the grating -> grating might move freely
    SPEC_fltw_move(filter_pos);
    // Contains its own delay
    Pacs_DMC_MOVE_GRAT_ABS_RAW(grat_pos);
    delay(15);
    //
    // ACTUAL OBSERVING/STARING TIME
    //
    delay(stare_time);
    //
    // CHOPPER -> DEFAULT
    //PACS_Chop_Move_Abs(0);
    Pacs_DMC_MOVE_CHOP_ABS_RAW(664);
    delay(1);
    //
    // SPU RESET
    //
    PACS_Spec_SPU_Reset();
    delay(1);
    //
    // DPU SETUP -> CANCEL BURST MODE
    //
    Pacs_DPU_SET_BUS_LIST("DISABLE");
    //
    // CRE SETTINGS WERE CHANGED -> PACS TO SAFE MODE FOR SECURITY
    // OBCP_SAFE();
    //
    // SYNC
    //= = =
    sync();
}

// Missionphase  : AOT validation
//
// Purpose	: Setup SPU for photometry data flow
//
// Author	: VDP / Bart Vandenbussche
//
// Arguments	: 
//
// Description	: Configures photometry compression /reduction mode and (optionally) starts 
//                     reduction/compression and GAIN
//                  
// Dependencies : 
//
// Comments	:
//
// Version	: 2.0
//               
// History	: 1.0 created from PHOT_spu_setup
// 		      needed to set Gain for LowGain obs 
//		      implementation: SCR4196 i.e. gain and bit rounding
//		      compression mode etc..
//		  2.0 25-feb-2009 VD implement decimation new SPU function
//                2.1 24-mar-2009 DAC Renamed spr1 & spr2 to rnd & rnds;
//                                syncd to syncdel as per SPU UM 13.95a 
//
int procedure PHOT_spu_gain_setup {
    string set_gain = "LOW" in ["HIGH","LOW"]; // Gain Blue settings: default = LOW
    int comp_mode_blu = 0; //  Compression blue: default=0, double=1, half=2, lossless=4, transp=7, buffer=9
    int comp_mode_red = 0; //  Compression blue: default=0, double=1, half=2, lossless=4, transp=7, buffer=9
    int nraw_blu = 3; // Number of raw channels transmitted in the blue SPU
    int nraw_red = 3; // Number of raw channels transmitted in the red SPU
    bool startSPU = true; // Start SPU or not [true,false]
}{
    string calU = "CONF_PHOT_params";
    if(set_gain == "LOW") {
        string col_calU = "BrightPacs";
    } else {
        if(set_gain == "HIGH") {
            col_calU = "Prime";
        }
    }
    int duration_msec = 0;
    // Stop the Long and Short SPUs
    Pacs_SPUS_STOP_REDUCT_COMPR();
    Pacs_SPUL_STOP_REDUCT_COMPR();
    // Set gain
    Pacs_BOLC_SET_GAIN(set_gain);
    // Set the SPU compression modes
    int[] aux = [comp_mode_blu,comp_mode_red];
    int check_sum = checksum("int",aux);
    // Issue the TC
    {int}[] comp_par = Array2grp_1(aux);
    Pacs_DMC_WRT_SPU_TRAN_MODE(comp_par,check_sum);
    // Setting of start index of raw channels for SPUS and SPUL
    string spus_obs_mode = "PHOT";
    string spul_obs_mode = "PHOT";
    int spus_startraw = ilookup(calU,"startraw_blu",col_calU);
    int spul_startraw = ilookup(calU,"startraw_red",col_calU);
    Pacs_SPUS_RAW_CHAN_TRAN_MODE(spus_obs_mode,nraw_blu,spus_startraw);
    Pacs_SPUL_RAW_CHAN_TRAN_MODE(spul_obs_mode,nraw_red,spul_startraw);
    // Photo "Ottensamer" block ("S" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    int ppf = ilookup(calU,"pre_proc_f_blu",col_calU);
    // PPP: Pre-Processing Parameter
    int ppp = ilookup(calU,"pre_proc_p_blu",col_calU);
    // Threshold for glitch detection in photometry
    int tfp = ilookup(calU,"glitch_thres_blu",col_calU);
    // Threshold for chopper position deviation in photometry
    int tcp = ilookup(calU,"chop_dev_thres_blu",col_calU);
    // Glitch detection for photometry (1: no glitch detection)
    int gdfp = ilookup(calU,"glitch_det_blu",col_calU);
    // Override samples to average
    int navg = ilookup(calU,"navg_blu",col_calU);
    int rnd = ilookup(calU,"rnd_blu",col_calU);
    // resolution reduction parameter 2 RND!!!
    //    int spr1 = 0; defined as function of the set_gain value
    // resolution reduction parameter 3
    int rnds = ilookup(calU,"rnds_blu",col_calU);
    // Lossless scheme
    int scm = ilookup(calU,"scm_blu",col_calU);
    // lossless compression algoithm (0,1,2,3,4)
    int lcal = ilookup(calU,"lcal_blu",col_calU);
    // PACS Codec Order (3,4)
    int pcod = ilookup(calU,"pcod_blu",col_calU);
    // PACS Decimation
    // discard samples at the beginning of each averaged groups
    int dpre = ilookup(calU,"dpre_blu",col_calU);
    // discard samples at the nd of each averaged groups
    int dpost = ilookup(calU,"dpost_blu",col_calU);
    int syncdel = ilookup(calU,"syncdel_blu",col_calU);
    // Spare elements: 10 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfp,tcp,gdfp,navg,rnd,rnds,scm,lcal,pcod,dpre,dpost,syncdel,0,0,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    {int}[] spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUS_WRT_DET_CST_PHOT(spu_par,check_sum);
    delay(1);
    // Photo "Ottensamer" block ("L" SPU)
    // PPF: Pre-Processing Flag (0: no PP, 1: addition, 2: subtraction, 
    //                           3: multiplication, 4: division)
    ppf = ilookup(calU,"pre_proc_f_red",col_calU);
    // PPP: Pre-Processing Parameter
    ppp = ilookup(calU,"pre_proc_p_red",col_calU);
    // Threshold for glitch detection in photometry
    tfp = ilookup(calU,"glitch_thres_red",col_calU);
    // Threshold for chopper position deviation in photometry
    tcp = ilookup(calU,"chop_dev_thres_red",col_calU);
    // Glitch detection for photometry (1: no glitch detection)
    gdfp = ilookup(calU,"glitch_det_red",col_calU);
    // Override samples to average
    navg = ilookup(calU,"navg_red",col_calU);
    rnd = ilookup(calU,"rnd_red",col_calU);
    // resolution reduction parameter 2 RND!!!
    //    int spr1 = 0; defined as function of the set_gain value
    // resolution reduction parameter 3
    rnds = ilookup(calU,"rnds_red",col_calU);
    // Lossless scheme
    scm = ilookup(calU,"scm_red",col_calU);
    // lossless compression algoithm (0,1,2,3,4)
    lcal = ilookup(calU,"lcal_red",col_calU);
    // PACS Codec Order (3,4)
    pcod = ilookup(calU,"pcod_red",col_calU);
    // PACS Decimation
    // discard samples at the beginning of each averaged groups
    dpre = ilookup(calU,"dpre_red",col_calU);
    // discard samples at the nd of each averaged groups
    dpost = ilookup(calU,"dpost_red",col_calU);
    syncdel = ilookup(calU,"syncdel_red",col_calU);
    // Spare elements: 10 spare element; hardcoded as 0,0,... in operand
    // Create operand
    aux = [ppf,ppp,tfp,tcp,gdfp,navg,rnd,rnds,scm,lcal,pcod,dpre,dpost,syncdel,0,0,0,0,0,0,0,0,0,0];
    check_sum = checksum("int",aux);
    // Convert to grp_1 syntax
    spu_par = Array2grp_1(aux);
    // Issue TC
    Pacs_SPUL_WRT_DET_CST_PHOT(spu_par,check_sum);
    delay(1);
    // Send time stamps
    // DMC_WRT_TIME: Write the time sent by the DPU into the DMC buffer
    // (No action on this one?)
    // DPU sends the time to DEC/MEC
    Pacs_DPU_SEND_TIME();
    // DMC_SET_TIME: Set the time previously written by the write time command
    Pacs_DMC_SET_TIME();
    // Start reduction/compression if commanded to do so
    if(startSPU) {
        Pacs_SPUS_START_REDUCT_COMPR();
        Pacs_SPUL_START_REDUCT_COMPR();
    }

    return duration_msec;
}

// CVS comments  : $Id:
// Purpose       : Issue FreqSwitch PACS commands at each stable pointing in 
//                 order to observe all the HSPOT defined spectral lines
//
// CUS author    : VD & DAC
//
// Input arguments
// Type                                                 Description
// {int,int,int,int,int,int,int,int,int}[] confSPECblu  BLUE SPU parameters
// {int,int,int,int,int,int,int,int,int}[] confSPECred  RED  SPU parameters
// {int,int,int,int,int,int,int,int,int,int,int,
//  int,int,int,int,int,int,int,int,int}[] confOBCP     OBCP parameters
// bool verbose                                         Print debug information
//
// Return values
// Type     Name         Description
// int[][5] time_array   The 5 times (TOT,SRC,REF,CAL,OVR) per spectral line
// Description   : Loops over all wavelengths at current stable pointing; sends
//                 start OBCP telecommand per spectral line
// IMPORTANT NOTE: the duration for the first stable pointing could have been
//                 different than that for the following points, due to the
//                 fact that we start from the default configuration whereas for
//                 any subsequent point, we start from where we ended at
//                 point-1. All OBCPs dealing with the grating will leave the
//                 grating at the position used for the 1st line/range.
//
// Dependencies  : 
//
// Preconditions :
// Comments      : OBCP tuples have slightly different contents than for
//                 non switched OBCPs. See PacsSpecEstimatorOBCP32 for
//                 more details
// Version       : 0.1
// History       : 0.1 17-sep-2009 VD adapted from SpecCommandOBCP32 
//                                 PHS-1119
//               : 0.2 21-sep-2009 VD. Updates from RV... wrong parameters combination
//               : 0.3 22-sep-2009 updates PHS-1119
//                                     P2=P10
//                                     P3 = 5*P5 = -P11
//                                     P5= P3/5 =P7=P8=P9= -P12= -P13= -P14= -P15
//
int[][] procedure PacsSpecCommandOBCP32_unChop {
    {int,int,int,int,int,int,int,int,int}[] confSPECblu = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int}[] confSPECred = [{0,0,0,0,0,0,0,0,0}];
    {int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}[] confOBCP = [{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}];
    bool verbose = true; // Print debug information
}{
    // Create array of durations; one duration per line
    int[][] time_array = [[0,0,0,0,0]];
    // Grating was left at 1st line by SlewCal
    int grat_def_pos = confOBCP[1]{8};
    // How many lines are we supposed to observe? confOBCP[0] is default tuple;
    // bonafide lines are described by confOBCP[1,2...])
    int nbLines = length(confOBCP) - 1;
    if(verbose) {
        debug_print("Comm.UnChopOBCP32:Starting SpecCommandOBCP32 with NbLines:" + nbLines);
        debug_print("Comm.UnChopOBCP32:Grating at position:" + grat_def_pos);
    }
    // ========================= LOOP on lines ===============================
    for(int lineNb = 1 .. nbLines) {
        //  Initialise time_array
        time_array[lineNb - 1] = [0,0,0,0,0];
        //      Long sequence to "unpack" contents of tuples
        //      Both SPECs
        int nb_rdouts_ramp_blu = confSPECblu[lineNb]{1};
        int comp_mode_blu = confSPECblu[lineNb]{3};
        int comp_mode_red = confSPECred[lineNb]{3};
        //     OBCP
        //  - Switch cycles (includes userREPfactr)
        int nb_up_dn = confOBCP[lineNb]{0};
        //  - OBCP32 is based on relative moves 
        int jumpAtoB = confOBCP[lineNb]{1};
        // P7
        int nbABBA = confOBCP[lineNb]{2};
        // P4
        //  - Number of ramps per grating position
        int nb_ramps_grat = confOBCP[lineNb]{4};
        // P6
        //  - Number of dither cycles (better be odd number)
        int ditherCount = confOBCP[lineNb]{7};
        //P2
        //  - Nominal grating position for observed line 
        //    confOBCP{8} includes offset offLine of table OBCP32params:
        //    GratStartPos = grat_pos_LINE + offLine, i.e. nominal position + offLine
        int grat_pos_LINE = confOBCP[lineNb]{8};
        //  - Relative displacement of the ensemble LINE-REF1-LINE-REF2 per dither
        //    cycle
        int ditherSize = confOBCP[lineNb]{9};
        // P3
        int chop_pos_SRC = confOBCP[lineNb]{17};
        int detector = confOBCP[lineNb]{18};
        //      This module is invoked at start of a stable pointing. Herein, OBCP32
        //      is called once per spectral line. 
        // gratPos is computed the same as in OBCP27
        int gratPos = grat_pos_LINE - (ditherSize + nbABBA * (4 * jumpAtoB) / 2);
        //      Last correction: move the grating back by 1/2 jumpAtoB:
        //       gratPos = gratPos - jumpAtoB / 2;
        //      Before OBCP grating is parked at grat_def_pos (1st line nominal setting)
        int steps_start = grat_def_pos - gratPos;
        //  Time needed to get there [msec]
        int grat_time = SPEC_grat_time(steps_start);
        if(verbose) {
            debug_print("Comm.UnChopped OBCP32:GratStart from/to: " + grat_def_pos + "/" + gratPos);
            debug_print("Comm.UnChopped OBCP32:GratStartTime: " + grat_time + " [msec]");
        }
        //  At the end of the OBCP, the grating finishes at
        //       int totalDither = (ditherCount - 1) * ditherSize;
        int totalDither = ditherCount * ditherSize;
        int grat_end = gratPos + ditherCount * ditherSize;
        //  We would like to leave it ready for the next line
        if(lineNb < nbLines) {
            grat_def_pos = confOBCP[lineNb + 1]{8};
        } else {
            grat_def_pos = confOBCP[1]{8};
        }
        //  Number of steps to go to grat_def_pos
        int steps_end = grat_end - grat_def_pos;
        //  Time needed to get there [msec]
        int grat_def_time = SPEC_grat_time(steps_end);
        if(verbose) {
            debug_print("Comm.UnChopped OBCP32:GratEnd from/to: " + grat_end + "/" + grat_def_pos);
            debug_print("Comm.UnChopped OBCP32:GratEndTime: " + grat_def_time + " [msec]");
        }
        //
        //  Start the OBCP now.
        // Name params as in OBCP document
        // P1 = nb_up_dn
        int param1 = confOBCP[lineNb]{0};
        // P2 = Nb shifts up EQUAL Nb shifts down    	
        //        int param2 = confOBCP[lineNb]{7};
        //        int nb_grat_step = confOBCP[lineNb]{7};        
        int param2 = confOBCP[lineNb]{7};
        int param10 = param2;
        // P3 dither amplitude up EQUAL dither amplitude down (sign!)
        int param3 = confOBCP[lineNb]{9};
        int param11 = -param3;
        // P4 = Nb ABBA cycles
        int param4 = confOBCP[lineNb]{2};
        // P5  relative move after P3; symmetrical of P12 going down  	
        int param5 = confOBCP[lineNb]{1};
        int param12 = -param5;
        // P6 Nb ramps per grating position
        int param6 = confOBCP[lineNb]{4};
        // P7 Actual wavelength switch, i.e. from A to B; P9 from B to A (up cycle)
        int param7 = confOBCP[lineNb]{1};
        // param7 = param5;
        int param9 = param5;
        // P8 relative move after 1st B (up; same for down)
        int param8 = param5;
        int param14 = -param5;
        // P13 Actual wavelength switch, i.e. from A to B; P15 from B to A (down cycle)
        int param13 = -param5;
        int param15 = -param5;
        // Call OBCP_wave_switch
        int[] timeOBCP = OBCP_wave_switch(param1,param2,param3,param4,param5,param6,param7,param8,param9,param10,param11,param12,param13,param14,param15,detector,comp_mode_blu,comp_mode_red,gratPos,chop_pos_SRC,grat_time,grat_def_pos,chop_pos_SRC,grat_def_time,nb_rdouts_ramp_blu);
        //  This OBCP is rather confusing; print enough debugging information
        if(verbose) {
            debug_print("Comm.UnChop OBCP32: NominalLine: " + grat_pos_LINE);
            debug_print("Comm.UnChopOBCP32: totalDither: " + totalDither);
            debug_print("Comm.UnChopOBCP32: ditherCount: " + ditherCount);
            debug_print("Comm.UnChopOBCP32: up_down: " + param1);
            debug_print("Comm.UnChopOBCP32: P#2        : " + param2);
            debug_print("Comm.UnChopOBCP32: P#3        : " + ditherSize);
            debug_print("Comm.UnChopOBCP32: P#4        : " + param4);
            debug_print("Comm.UnChopOBCP32: P#6        : " + param6);
            debug_print("Comm.UnChopOBCP32: P#5        : " + param5);
            debug_print("Comm.UnChopOBCP32: P#7        : " + param7);
            debug_print("Comm.UnChopOBCP32: P#8        : " + param8);
            debug_print("Comm.UnChopOBCP32: P#9        : " + param9);
            debug_print("Comm.UnChopOBCP32: gratPos    : " + gratPos);
            debug_print("Comm.UnChopOBCP32: gratDefPos : " + grat_def_pos);
            debug_print("Comm.UnChopOBCP32: chopSrc    : " + chop_pos_SRC);
            debug_print("Comm.UnChopOBCP32: gratTime   : " + grat_time);
            debug_print("Comm.UnChopOBCP32: gratDefTime: " + grat_def_time);
            //    Call PacsDebug with only one inner loop!!
            PacsDebug_wave_switch_unChop(gratPos,param2,param1,param3,param4,param6,param7,param8);
        }
        //  Compute duration for ensemble of dithered cycles
        for(int loop4 = 0 .. 4) {
            time_array[lineNb - 1][loop4] = time_array[lineNb - 1][loop4] + timeOBCP[loop4];
        }
        // End of nbLines loop
    }
    // time_array indeces are [wavelength][mode]     
    if(verbose) {
        debug_print("Comm.UnChopCmdOBCP32 returns " + time_array);
    }
    // Add sync()
    sync();

    return time_array;
}

