-------------------------------------------------------------------------------
--                                                                           --
--                          Experiment Source Code                           --
--              Delta NMR Experiment & Machine Control Interface             --
--                                                                           --
--                     Copyright (c) 2015 JEOL Ltd                           --
--                            All Rights Reserved                            --
--                                                                           --
-------------------------------------------------------------------------------
-- HELP.eng: double_cp_2d
-- Category: solids, ultrafast mas, 2D, heteronuclear correlation and homonuclear correlation.
-- By Rongchun Zhang, 2021/06/28
header
    filename    => "DQ_SQ_R18_double_cp_2d";
    sample_id   => "";
    comment     => "double_cp_2d";
    process     = "2d_solid.list";
    include "header_solid";
end header;

instrument
    include "instrument_solid";
end instrument;

acquisition
    x_domain    =>  "Proton";
    x_offset    =>  5[ppm];
    x_sweep     =>  100[kHz];
    x_points    =>  1024;
    scans       =>  8;
    x_prescans  =>  0;
    mod_return  =>  2;

    y_domain    =>  "Carbon13";
    y_offset    =>  100[ppm];
    y_sweep     =>  35[kHz], help "rotor-synchronization";
    y_points    =>  32;

    include "acquisition_solid";

    y_acq_time      =?  y_points / y_sweep;
    y_resolution    =?  1 / y_acq_time;
    y_dwell         =?  1 / y_sweep;

end acquisition;

pulse
    collect COMPLEX,OBS COMPLEX,IRR;
    initial_wait    =   10.0[ms];

    irr_domain      = y_domain , help "decoupled nucleus";
    irr_offset      = y_offset , help "decoupler offset";

Pulse_Setup =? "#Setup hard pulses#";

    obs_width_90    => x90;
    obs_width_180   => x90*2;
    obs_amp_pulse   => 100[%], 0[%]->100[%] : 10[m%];
    irr_width_90    => irr90;
    irr_width_180   => irr90*2;
    irr_amp_pulse   => 100[%];

CP1_Setup   =? "#Setup first CP#";

    obs_shape_cp     = "RAMP_cp";
    contact_time     => 2[ms], 0[us]->20[ms] : 10[us], help "contact time";
    obs_amp_cp       => 30[%], 0[%]->100[%] : 10[m%], help "CP amplitude of irr channel";
    obs_amp_grad     => 10[%], -100[%]->100[%] : 0.1[%], help "irr CP sweep range (-irr_amp_grad/2->+irr_amp_grad)";

    irr_shape_cp     = "RAMP_cp";
    irr_amp_cp       => 30[%], 0[%]->100[%] : 10[m%], help "amplitude of obs channel";
    irr_amp_grad     => 1[%], -100[%]->100[%] : 0.1[%], help "obs CP sweep range (-obs_amp_grad/2->+obs_amp_grad)";

CP2_Setup   =? "#Setup second CP#";

    obs_shape_cp2    = "RAMP_cp2";
    contact_time2    => 0.5[ms], 0[us]->20[ms] : 10[us], help "contact time";
    obs_amp_cp2      => obs_amp_cp, 0[%]->100[%] : 10[m%], help "CP amplitude of irr channel";
    obs_amp_grad2    => -obs_amp_grad;

    irr_shape_cp2    =  "RAMP_cp2";
    irr_amp_cp2      => irr_amp_cp, 0[%]->100[%] : 10[m%], help "amplitude of obs channel";
    irr_amp_grad2    => -irr_amp_grad;

OBSdec_Setup =? "#Setup OBS dec#";

    obs_noise       => "CW", ("CM", "CW", "SPINAL64", "SPINAL64_vp", "swfTPPM", "TPPM", "XiX"), help "decoupling sequence";
    obs_amp_dec     => 5[%], 0[%]->100[%] : 10[m%], help "amplitude of decoupling";
    when obs_noise /= "CW" and obs_noise /= "XIX" do
        obs_width_nominal90 => x90 * 100[%] / obs_amp_dec, help "modulation pulse width for decoupling";
    end when;
    when obs_noise = "CM" or obs_noise = "SPINAL64_vp" or obs_noise = "swfTPPM" or obs_noise = "TPPM" do
        obs_phs_tppm        => 15[deg], help "decoupling sequence phase modulation";
    end when;
    when obs_noise = "XiX" do
        obs_width_xix       => 50[us], help "XiX modulation pulse width: should be optimized around 1.85*tr";
    end when;
    obs_pwidth          =  if obs_noise = "CW"
                           then 0[us]
                           else if obs_noise = "XiX"
                           then obs_width_xix
                           else obs_width_nominal90;

R18_Setup =? "#Setup R18_1^7 sequence#";

spinning_freq       => 60 [kHz];
    number_large_N      =>  18;
    number_n        =>  1;
    number_nu       =>  7;
    number_RN       =>  1;
    obs_amp_RN      =>  0[%];
    obs_phs_RN_p        =   180*number_nu/number_large_N;
    obs_phs_RN_m        =   -obs_phs_RN_p;
    obs_width_RN        =   (number_n/spinning_freq)/number_large_N;
    recoupling          =?  number_RN*number_n/spinning_freq;
 
    z_filter        =>  100[us],0[ns]   ->  500[ms]  :   20[ns],     help "total echo time";

HORROR_Setup =? "#Setup HORROR#";

    tau_rr      => 1[ms], 0[us]->100[ms] : 10[us];
    obs_amp_rr  => 10[%];

MISC_Setup  =? "#Setup Miscellaneous#";

t1 => 0.1[us];

    SATURATION  = FALSE;
    when SATURATION do
        obs_width_sat       =>  x90;
        obs_amp_sat         => 100[%],  0[%]->100[%]:0.01[%], help "amp for pre-saturation pulses";
        sat_term            => 1[s], help "saturation time";
        sat_pulse_interval  => 10[ms], help "interval of saturation pulse";
        sat_loop        =? round(sat_term/(sat_pulse_interval+obs_width_90)), help "loop of saturation pulse";
    end when;

    relaxation_delay    =>  5[s],                           help "inter-pulse delay";
    repetition_time     =?  relaxation_delay + x_acq_time + y_acq_time,  help "relaxation_delay+x_acq_time";

    obs_atn             =>  xatn,   help "attenuator of obs";
    irr_atn             =>  irratn, help "attenuator of irr";

    obs_phs_prep        =   {0};
    obs_phs_cp1         =   { 90};
    obs_phs_dec         =   {90};
    obs_phs_cp2         =   {2(90),2(270)};
    obs_phs_store       =   {180};
    obs_phs_read        =   {4(0),4(120),4(240)};
    obs_phs_rrx        = {0};
    obs_phs_rry       = {90};

    irr_phs_cp1         =   {90};
    irr_phs_store       =   {180};
    irr_phs_restore     =   {{0,180},{90,270}}.ystep(180%2);
    irr_phs_cp2         =   {90};
    irr_phs_dec         =   {0};
    irr_phs_befHORROR   =   {180};
    irr_phs_aftHORROR   =   {0};
    obs_phs_exc     =   {  0..270:90, 45..315:90}.ystep(90%2);
    obs_phs_rec     =   {  0};

    obs_phs_acq1        =   {2(0,180),2(120,300),2(240, 60)}.ystep(180%2);
     obs_phs_acq2        =  {  90,270,270, 90}.ystep(180%2);



    include "pulse_solid";

    module_config = "solid_sample continuous_fid";

begin
    initial_wait;

    when SATURATION do
        loop sat_loop times
            sat_pulse_interval;
            obs_width_sat,(obs.gate, obs.phs.0, obs.amp.obs_amp_sat, obs.atn.obs_atn);
        end loop;
    end when;

    relaxation_delay;

    obs_width_90,   (obs.gate,  obs.phs.obs_phs_prep,   obs.amp.obs_amp_pulse,  obs.atn.obs_atn);

    contact_time, (obs.GATE, obs.PHS.obs_phs_cp1, obs.shape.{obs_shape_cp, "obs"}, obs.ATN.obs_atn,
                   irr.GATE, irr.PHS.irr_phs_cp1, irr.SHAPE.{irr_shape_cp, "irr"}, irr.ATN.irr_atn);

    align center
    irr_width_90, (irr.gate, irr.phs.irr_phs_store, irr.amp.irr_amp_pulse, irr.atn.irr_atn);
    obs_width_90, (obs.gate, obs.phs.obs_phs_store, obs.amp.obs_amp_pulse, obs.atn.obs_atn);
    end align;  
 
    z_filter;

    loop number_RN times
    loop number_large_N/2 times
    obs_width_RN,   (obs.gate,  obs.phs.(obs_phs_RN_p+obs_phs_exc), obs.amp.obs_amp_RN, obs.atn.obs_atn);
    obs_width_RN,   (obs.gate,  obs.phs.(obs_phs_RN_m+obs_phs_exc), obs.amp.obs_amp_RN, obs.atn.obs_atn);
    end loop;
    end loop;

   t1 ystep 1/y_sweep;

    loop number_RN times
    loop number_large_N/2 times
    obs_width_RN,   (obs.gate,  obs.phs.(obs_phs_RN_p+obs_phs_rec), obs.amp.obs_amp_RN, obs.atn.obs_atn);
    obs_width_RN,   (obs.gate,  obs.phs.(obs_phs_RN_m+obs_phs_rec), obs.amp.obs_amp_RN, obs.atn.obs_atn);
    end loop;
    end loop;


   obs_width_90,   (obs.gate,  obs.phs.obs_phs_read,   obs.amp.obs_amp_pulse,  obs.atn.obs_atn);

    acq(dead_time, delay, obs_phs_acq1 );

    irr_width_90,   (irr.gate,  irr.phs.irr_phs_restore,    irr.amp.irr_amp_pulse,  irr.atn.irr_atn);

   t1 ystep 1/y_sweep, (obs.GATE, obs.PHS.obs_phs_dec, obs.AMP.obs_amp_dec, obs.ATN.obs_atn, obs.noise.obs_noise);

    irr_width_90,   (irr.gate,  irr.phs.irr_phs_befHORROR,    irr.amp.irr_amp_pulse,  irr.atn.irr_atn);

    tau_rr, (OBS.GATE, OBS.PHS.obs_phs_rrx, OBS.AMP.obs_amp_rr, OBS.ATN.obs_atn);
    tau_rr, (OBS.GATE, OBS.PHS.obs_phs_rry, OBS.AMP.obs_amp_rr, OBS.ATN.obs_atn);
    tau_rr, (OBS.GATE, OBS.PHS.obs_phs_rrx, OBS.AMP.obs_amp_rr, OBS.ATN.obs_atn);
    tau_rr, (OBS.GATE, OBS.PHS.obs_phs_rry, OBS.AMP.obs_amp_rr, OBS.ATN.obs_atn);

    irr_width_90,   (irr.gate,  irr.phs.irr_phs_aftHORROR,    irr.amp.irr_amp_pulse,  irr.atn.irr_atn);


    contact_time2, (obs.GATE, obs.PHS.obs_phs_cp2, obs.shape.{obs_shape_cp2, "obs"}, obs.ATN.obs_atn,
                    irr.GATE, irr.PHS.irr_phs_cp2, irr.SHAPE.{irr_shape_cp2, "irr"}, irr.ATN.irr_atn);
    
    
    acq( dead_time, delay, obs_phs_acq2 );
   

end pulse;