#Do CNC, UVMOT, and field ramps
s, toENDBFIELD = highfield_uvmot.go_to_highfield(s)

#Allow time for free evaporation (also helps provide buffer to reload the analog chs)
buffer=10.0 #Time needed to re-latch the trigger for the AOUTS
if EVAP.free < buffer + toENDBFIELD :
    print 'Need at list ' + str(buffer) + 'ms of EVAP.free evap before evaporation can be triggered'
    print 'Currently ramps end at %f , and EVAP.free is %f' % (toENDBFIELD,EVAP.free)
    exit(1)
s.wait(EVAP.free)


#Do Evap
if int(EVAP.use_field_ramp) == 1:
    bfield, odtpow, ENDEVAP, cpowend, ipganalog= odt.odt_evap_field(EVAP.scale)
else:
    odtpow, ENDEVAP, cpowend, ipganalog = odt.odt_evap(EVAP.scale)
    bfield = wfm.wave('bfield',FESHBACH.bias,EVAP.evapss)
    bfield.extend(odtpow.dt())
#Use the EVAP.image time equal to EVAP.image times EVAP.scale for the sequence after the part.
EVAP.image = EVAP.image *EVAP.scale    


#Ramp the field to the zerocrossing
bfield.linear(ZEROCROSS.zcbias,ZEROCROSS.zcrampdt)
bfield.appendhold(ZEROCROSS.zcdt)
odtpow.extend(bfield.dt())
ipganalog.extend(bfield.dt())

if free < buffer + toENDBFIELD :
    print 'Need at list ' + str(buffer) + 'ms of free evap before evaporation can be triggered'
    print 'Currently ramps end at %f , and free is %f' % (toENDBFIELD,free)
    exit(1)
s.wait(free)


evap_ss = float(report['EVAP']['evapss'])
bias = float(report['FESHBACH']['bias'])
zcrampdt = float(report['ZEROCROSS']['zcrampdt'])
zcdt = float(report['ZEROCROSS']['zcdt'])
zcbias = float(report['ZEROCROSS']['zcbias'])

#add bfield ramp up during evap#
if (int(report['EVAP']['use_field_ramp'])):
    bfield, odtpow, ENDEVAP, cpowend, ipganalog= odt.odt_evap_field(image)#,odtpow_test,odtpow_test2 
    
else:
    odtpow, ENDEVAP, cpowend, ipganalog = odt.odt_evap(image)
    bfield = wfm.wave('bfield',bias,evap_ss)
    bfield.extend(odtpow.dt())
    

bfield.linear(zcbias,zcrampdt)
bfield.appendhold(zcdt)
odtpow.extend(bfield.dt())
ipganalog.extend(bfield.dt())


#add odt ramp up#
if int(report['EVAP']['use_odt_lock']) == 1: 
# Do CNC, UVMOT, and field ramps
s, toENDBFIELD = highfield_uvmot.go_to_highfield(s)

# Allow time for free evaporation (also helps provide buffer to reload the analog chs)
buffer = 10.0  # Time needed to re-latch the trigger for the AOUTS
if EVAP.free < buffer + toENDBFIELD:
    print "Need at list " + str(buffer) + "ms of EVAP.free evap before evaporation can be triggered"
    print "Currently ramps end at %f , and EVAP.free is %f" % (toENDBFIELD, EVAP.free)
    exit(1)
s.wait(EVAP.free)


# Do Evap
if int(EVAP.use_field_ramp) == 1:
    bfield, odtpow, ENDEVAP, cpowend, ipganalog = odt.odt_evap_field(EVAP.scale)
else:
    odtpow, ENDEVAP, cpowend, ipganalog = odt.odt_evap(EVAP.scale)
    bfield = wfm.wave("bfield", FESHBACH.bias, EVAP.evapss)
    bfield.extend(odtpow.dt())
# Use the EVAP.image time equal to EVAP.image times EVAP.scale for the sequence after the part.
EVAP.image = EVAP.image * EVAP.scale


# Ramp the field to the zerocrossing
bfield.linear(ZEROCROSS.zcbias, ZEROCROSS.zcrampdt)
bfield.appendhold(ZEROCROSS.zcdt)
odtpow.extend(bfield.dt())
ipganalog.extend(bfield.dt())