-------------------------------------------------------------------------------
--                                                                           --
--                          Experiment Source Code                           --
--              Delta NMR Experiment & Machine Control Interface             --
--                                                                           --
--                     Copyright (c) 2009 JEOL Ltd                           --
--                            All Rights Reserved                            --
--                                                                           --
-------------------------------------------------------------------------------
-- HELP.eng: Saturation recovery for 1H T1 in combination with Cross Polarization and RINEPT
-- Category: solids, 1D standard, cpmas


header
    filename        => "HETCOR-CP-RINEPT";
    sample_id       => "";
    comment         => "HETCOR";
    process         =  "1d_solid.list";
    auto_dwell      =  TRUE;
    auto_filter     =  TRUE;
    auto_gain       => FALSE;
    filter_limit    => 8;
    force_dual_mode =  FALSE;
    decimation_rate =  0;
    force_tune      => FALSE;
    save_aborted    =  TRUE;
    vector          =  TRUE;
    x_pulse         =  0.1[us];
    mod_save        => 0;
end header;

instrument
    recvr_gain     => 50;
    autoshim_track =  "AUTOSHIM OFF";
    lock_osc_state =  "2H OSC OFF";
end instrument;

acquisition
    x_domain     => "Carbon13";
    x_offset     => 100[ppm];
    x_sweep      => 400[ppm];
    x_points     => 512;
    scans        => 16;
    x_prescans   => 4;
    mod_return   => 1;
    y_domain     => "Proton";
    y_offset     => 0[ppm];
    x_acq_time   =? x_points / x_sweep;
    x_resolution =? 1 / x_acq_time;
    x_dwell      =? 1 / x_sweep;
end acquisition;

pulse
    collect COMPLEX,OBS COMPLEX,IRR;

    macro acq( dead_time, delay, phase ) is
        dead_time, OBS.PHS.0;
        delay, (OBS.PHS.0, RCV.GATE);
        acquire (OBS.PHS.0, RCV.PHS.phase);
    end acq;

    initial_wait        =  10[ms];
    irr_setup           =? "#Setup IRR#";
    irr_domain          =  y_domain, help "decoupled nucleus";
    irr_offset          =  y_offset, help "decoupler offset";
    irr_width_90        => 1.6[us], help "90deg pulse width for excitation pulse";
    irr_width_180       => 3.2[us];
    irr_amp_pulse       => 100[%];
    irr_atn             => irratn, help "attenuator of x_pulse";
    pmlg_setup          =? "#Setup PMLG#";
    
irr_width_lg90          => irr90, help "90deg pulse width for lg_amp";
    irr_width_lg            =  irr_width_lg90 * 4 * SQRT(2) / SQRT(3);
    irr_amp_lg              => 100[%], 0[%]->100[%]:0.01[%], help "set ampliper for PMLG";

    PMLGn                   =? 3, help "PMLGn pulse divided into 3 steps";
    irr_width_lg_element    => irr_width_lg / PMLGn;
    irr_width_lg_e_round    =? round(irr_width_lg_element / 5[ns]) * 5[ns];
-
    bef_trig_1              =  2000[ns];
    bef_trig_2              =  1500[ns];
    t_trig                  =  1400[ns];
    aft_trig                =  1200[ns];
    t_w                     =  bef_trig_1 + bef_trig_2 + t_trig + aft_trig;

    y_setup             =? "-----------Setup Y Dimension-----------";
    Scale_factor_y          => 0.47, help "Theoretical Scaling Factor";
    Scale_y_sweep           =  1 / Scale_factor_y;
    Scale_x_sweep           =  1;

    lg_loop                 => 2, 0->100:1, help "loop number for PMLG";
    cycle_time_y            =  (irr_width_lg_e_round * 2 * PMLGn + t_w) * 2 * lg_loop;
    y_sweep                 =  1/cycle_time_y;

    get_freq = "pulse_service::get_freq_value";
    scaled_y_sweep       =? y_sweep / scale_factor_y * (1[Mppm] / _get_freq( y_domain ));

    y_points                => 64;
    acq_time_y              =? y_points * cycle_time_y;


    cp_setup            =? "#Setup CP#";
    prep_pulse          =  "TRUE";
    irr_shape_cp        =  "constant_cp";
    irr_amp_prep        => 100[%], 0[%]->100[%] : 0.01[%], help "amplitude of excitation pulse";
    obs_shape_cp        => "RAMP_cp", ("constant_cp", "RAMP_cp"), help "CP shape for obs channel";
    contact_time        => 0.2[ms], 10[us]->20[ms] : 10[us], help "contact time";
    irr_amp_cp          => 51[%], 0[%]->80[%] : 0.01[%], help "CP amplitude of irr channel";
    obs_amp_cp          => 64[%], 0[%]->80[%] : 0.01[%], help "CP amplitude of obs channel";
    when obs_shape_cp = "ramp_cp" do
        obs_amp_grad        => -3[%], -100[%]->100[%] : 0.1[%], help "obs CP sweep range (-obs_amp_grad/2->+obs_amp_grad)";
    end when;
    obs_width_90        => 2[us];
    obs_width_180       => 4[us];
    obs_amp_pulse       => 100[%];

RFDR_Setup =? "#Setup RFDR#";
   RFDRflag  => FALSE;
 when RFDRflag do
    RFDRcycle => 100;
    mas_freq   =>  10[kHz];
    MixTime   =RFDRcycle*16/mas_freq;
    irr_amp_rfdr   => 100[%], 0[%]->100[%] : 10[m%];
    irr_width_rfdr    => irr90*2;
    tauRFDR   =?  (1/mas_freq - irr_width_rfdr)/2;
    RFDRMixingTime =? RFDRcycle/mas_freq*16;
  end when;
  tauNOE => 10[ms];

    obs_atn             => xatn, help "attenuator of x_pulse";
 
    tau1                => 0.5[ms];
    tau2                => 0.5[ms];

    dec_setup           =? "#Setup Decoupling#";
    irr_dec_offset      => 0[ppm], help "offset for decoupling";
    irr_noise           => "CW", ("CW", "SPINAL64", "TPPM", "XiX"), help "decoupling sequence";
    irr_amp_dec         => 60[%], 0[%]->100[%] : 0.01[%], help "amplitude of decoupling";
    irr_amp_dec2        =>60[%], 0[%]->100[%] : 0.01[%], help "amplitude of decoupling";
    when irr_noise = "SPINAL64" or irr_noise = "TPPM" do
        irr_width_nominal90 => 2.5[us], help "modulation pulse width for decoupling";
    end when;
    when irr_noise = "TPPM" do
        irr_phs_tppm        => 15[deg], help "TPPM Decoupling Phase: between -irr_phs_tppm and +irr_phs_tppm";
    end when;
    when irr_noise = "XiX" do
        irr_width_xix       => 50[us], help "XiX modulation pulse width: should be optimized around 1.85*tr";
    end when;
    irr_pwidth          =  if irr_noise = "CW"
                           then 0[us]
                           else if irr_noise = "XiX"
                           then irr_width_xix
                           else irr_width_nominal90;

    misc_setup          =? "-----------Setup MISC -----------";
    relaxation_delay    => 10[s], help "inter-pulse delay";
    repetition_time     =? relaxation_delay + x_acq_time, help "relaxation_delay+x_acq_time";
    irr_phs_lg          =  {0};
    irr_phs_prep        =  ({{0, 180}, {90, 270}}).ystep(180 % 2);
    obs_phs_dec         =  {0};
    irr_phs_pmlg        =  {0};
    irr_phs_cp          =  {270};
    obs_phs_cp          =  {2(270)};
    irr_phs_dec         =  {270};
    obs_phs_acq1        =  ({0, 180}).ystep(180 % 2);
    irr_phs_store       =  {180};
    irr_phs_restore     =  {16(0), 16(180)};
    obs_phs_180_1       =  {2(0), 2(180)};
    irr_phs_180_1       =  {2(0), 2(180)};
    obs_phs_90_1        =  {8(0), 8(90), 8(180), 8(270)};
    irr_phs_90_1        =  {4(90), 4(270)};
    obs_phs_180_2       =  {2(0), 2(180), 2(0), 2(180), 2(90), 2(270), 2(90), 2(270)};
    irr_phs_180_2       =  {2(0), 2(180)};
    obs_phs_acq2        =  ({2(90, 270), 2(270, 90), 2(180, 0), 2(0, 180)}).ystep(180 % 2);
    irr_phs_rfdr        =  {0};
    dead_time           =  if not auto_dwell
                           then 0.5 / x_sweep
                           else 0[us];
    delay               =  if not auto_dwell
                           then 0.5 / x_sweep
                           else 0[us];
    module_config       =  "solid_sample continuous_fid";

begin
    initial_wait;
    relaxation_delay;
    irr_width_90, (IRR.GATE, IRR.PHS.irr_phs_prep, IRR.AMP.irr_amp_pulse, IRR.ATN.irr_atn);
    parallel
        justify center
            loop ystep {0->512:1} times
        loop lg_loop times
            t_w;
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+ 34.6, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+103.9, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+173.2, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+353.2, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+283.9, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+214.6, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            t_w;
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+ 34.6+180, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+103.9+180, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+173.2+180, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+353.2+180, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+283.9+180, irr.amp.irr_amp_lg, irr.atn.irr_atn);
            irr_width_lg_e_round, (irr.gate, irr.phs.irr_phs_lg+214.6+180, irr.amp.irr_amp_lg, irr.atn.irr_atn);
        end loop;
    end loop;
        justify center
            obs_width_180, (OBS.GATE, OBS.PHS.obs_phs_dec, OBS.AMP.obs_amp_pulse, OBS.ATN.obs_atn);
    end parallel;
    contact_time, (IRR.GATE, IRR.PHS.irr_phs_cp, IRR.SHAPE.{irr_shape_cp, "irr"}, IRR.ATN.irr_atn, OBS.GATE, OBS.PHS.obs_phs_cp, OBS.SHAPE.{obs_shape_cp, "obs"}, OBS.ATN.obs_atn);
    on (IRR.GATE, IRR.PHS.irr_phs_dec, IRR.AMP.irr_amp_dec, IRR.ATN.irr_atn);
    acq( dead_time, delay, obs_phs_acq1 );
    off IRR.GATE;
    irr_width_90, (IRR.GATE, IRR.PHS.irr_phs_store, IRR.AMP.irr_amp_pulse, IRR.ATN.irr_atn);
--------Starting RFDR or NOE --------------------------------
when RFDRflag do
	loop RFDRcycle times
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 0,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 90,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 0,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
    tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 90,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 90,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 180,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 90,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 180,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 180,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 270,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 180,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 270,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 270,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 0,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 270,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
   tauRFDR;
   irr_width_rfdr,   (irr.gate,  irr.phs.irr_phs_rfdr + 270,   irr.amp.irr_amp_rfdr,  irr.atn.irr_atn);
   tauRFDR;
  end loop;
-------------RFDR ------------------------------
else do tauNOE;
end when;

    irr_width_90, (IRR.GATE, IRR.PHS.irr_phs_restore, IRR.AMP.irr_amp_pulse, IRR.ATN.irr_atn);
    parallel
        justify center
            tau1;
            irr_width_180, (IRR.GATE, IRR.PHS.irr_phs_180_1, IRR.AMP.irr_amp_pulse, IRR.ATN.irr_atn);
            tau1;
        justify center
            obs_width_180, (OBS.GATE, OBS.PHS.obs_phs_180_1, OBS.AMP.obs_amp_pulse, OBS.ATN.obs_atn);
    end parallel;
    parallel
        justify center
            irr_width_90, (IRR.GATE, IRR.PHS.irr_phs_90_1, IRR.AMP.irr_amp_pulse, IRR.ATN.irr_atn);
        justify center
            obs_width_90, (OBS.GATE, OBS.PHS.obs_phs_90_1, OBS.AMP.obs_amp_pulse, OBS.ATN.obs_atn);
    end parallel;
    parallel
        justify center
            tau2;
            irr_width_180, (IRR.GATE, IRR.PHS.irr_phs_180_2, IRR.AMP.irr_amp_pulse, IRR.ATN.irr_atn);
            tau2;
        justify center
            obs_width_180, (OBS.GATE, OBS.PHS.obs_phs_180_2, OBS.AMP.obs_amp_pulse, OBS.ATN.obs_atn);
    end parallel;
    on (IRR.GATE, IRR.AMP.irr_amp_dec2, IRR.ATN.irr_atn);
    acq( dead_time, delay, obs_phs_acq2 );
    off IRR.GATE;
end pulse;