-------------------------------------------------------------------------------
--                                                                           --
--                          Experiment Source Code                           --
--              Delta NMR Experiment & Machine Control Interface             --
--                                                                           --
--                     Copyright (c) 2021 JEOL Ltd                           --
--                            All Rights Reserved                            --
--                                                                           --
-------------------------------------------------------------------------------
-- HELP.eng: double_cp_2d
-- Category: solids, ultrafast mas, 2D, heteronuclear correlation
-- Modified from double_cp_2d.jxp (Matsunaga)

header
    filename    => "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     =>  250[ppm];
    y_points    =>  32;

    include "acquisition_solid";

    y_acq_time      =?  y_points / y_sweep;
    y_resolution    =?  1 / y_acq_time;
    y_dwell         =?  1 / x_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_amp_pulse   => 100[%], 0[%]->100[%] : 10[m%];
    irr_width_90    => irr90;
    irr_amp_pulse   => 100[%];

CP1_Setup   =? "#Setup first CP#";

    obs_shape_cp     = "RAMP_cp";
    contact_time     => 4[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    => 4[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;

-------- constant of RF intensity ---------
obs_nu	=	0.25/x90;

-------- SLAP (SLAP_obs.jxi)---------
block_slap		=? "#SLAP#";
slap_ofs		=>	1.2[ppm];	--irradiation offset
obs_nu_CW		=>	10[kHz];	--intensity of CW
slap_ad_nu1		=>	obs_nu_CW*1.41;	--intensity of adrot
slap_ad_nua		=>	1[kHz];		--rotation frequency of ad rot
obs_amp_CW		=?	obs_nu_CW /obs_nu*100[%], 0[%]->100[%] : 0.01[%];
slap_ad_amp		=?	slap_ad_nu1 /obs_nu*100[%], 0[%]->100[%] : 0.01[%];
obs_width_slap	=?	1 / slap_ad_nua;
time_cw			=>	10[ms];
time_slap		=>	50[ms];
lp_slap			=?	upper (time_slap / obs_width_slap);

macro SLAP_obs (time_CW, lp_slap, obs_width_slap, obs_atn, obs_amp_CW, slap_ad_amp, slap_ofs) is
	time_cw, (OBS.GATE, OBS.ATN.obs_atn, OBS.AMP.obs_amp_CW, OBS.PHS.{0}, OBS.OFFSET.slap_ofs);
	loop lp_slap times
		obs_width_slap, (OBS.GATE, OBS.ATN.obs_atn, OBS.SHAPE.{"adrot_PM", "SLAP"}, OBS.PHS.{0}, OBS.OFFSET.slap_ofs);
	end loop;
end SLAP_obs;
--------------------------------------

IRRdec_Setup =? "#Setup IRR dec#";

    irr_noise   =? "WALTZ";
    irr_pwidth  => 10[us];
    irr_amp_dec => 1[%];

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;

--  HORROR_Setup =? "#Setup HORROR#";
--  
--  tau_rr      => 5[ms];
--  obs_amp_rr  => 10[%];

MISC_Setup  =? "#Setup Miscellaneous#";

    t1          => 0[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,  help "relaxation_delay+x_acq_time";

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

    obs_phs_prep        =   {4(  0),4(180)};
    obs_phs_cp1         =   { 90};
    obs_phs_dec         =   {  0};
    obs_phs_cp2         =   {2(  0),2(180)};
--  obs_phs_rrx         =   {  0};
--  obs_phs_rry         =   { 90};

    irr_phs_cp1         =   {{  0,180},{ 90,270}}.ystep(180%2);
    irr_phs_store       =   { 90};
    irr_phs_restore     =   {270};
    irr_phs_cp2         =   {  0};
    irr_phs_dec         =   {  0};

    obs_phs_acq         =   {  0,180,180,  0,180,  0,  0,180}.ystep(180%2);

    include "pulse_solid";

    module_config = "solid_sample";

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);

    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_store,  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);
    
    ------------ SLAP ------------
    SLAP_obs (time_CW, lp_slap, obs_width_slap, obs_atn, obs_amp_CW, slap_ad_amp, slap_ofs);
    ------------------------------

    irr_width_90,   (irr.gate,  irr.phs.irr_phs_restore,    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);

    on(irr.GATE, irr.PHS.irr_phs_dec, irr.AMP.irr_amp_dec, irr.ATN.irr_atn, irr.noise.irr_noise);
    acq( dead_time, delay, obs_phs_acq );
    off(irr.gate);

end pulse;
