# -*- coding: iso-8859-1 -*-

def experiment(): # 'go setup' routine
    
    pars = {}
    pars['P90'] = 2.5e-6		# 90-degree pulse length (s)
    pars['RD'] = 1              	# delay between scans (s)
    pars['SW'] = 100e3			# spectrum window (Hz)
    pars['SI'] = 1*1024			# number of acquisition points
    pars['DEAD1'] = 10e-6		# receiver dead time (s)  

    while True:
        yield gs_experiment(pars)       


def gs_experiment(pars):
    e=Experiment()

    # read in variables:
    P90 = pars['P90']      
    RD =  pars['RD']
    SI =  pars['SI']
    SW =  pars['SW']
    DEAD1 =  pars['DEAD1'] 

    if P90 > 20e-6:
        raise Exception("Pulse too long!!!")

    e.ttl_pulse(2e-6, value=1)		# unblank RF amplifier
    e.ttl_pulse(P90, value=3)		# apply 90-degree pulse
    e.wait(DEAD1)			# wait for receiver dead time
    e.record(SI, SW, sensitivity=2)	# acquire signal
    e.wait(RD)				# wait for next scan

    # write experiment parameters:  
    for key in pars.keys():
        e.set_description(key, pars[key])

    return e