##################### Convert_File function ############################# def convert_file(input_file_name, output_file_name): sep = "\t" line_sep = "\r\n" field = caget('X11MA-XMCD:Ireadout') with open(input_file_name) as inp: lines = inp.readlines() with open(output_file_name, "wb") as out: out.write("Energy" + sep + "Io" + sep + "CADC2" + sep + "CADC3" + sep + "Mag" + line_sep) s = sep + " " #File format has a space before numeric values for line in lines[1:]: line = line.strip() if line=="": break try: (Ecrbk,CADC1, CADC2, NORM, CADC3, CADC4, MCurr, cffrbk, ID1Erbk, ID2Erbk, vTime) = line.split(" ") out.write(Ecrbk + s + CADC1 + s + CADC2 + s + CADC3 + s + str(field) +line_sep) except: traceback.print_exc() ##################### Plotting function ############################# task = None running = False def _startPlot(type): global running sep = "\t" line_sep = "\r\n" print "Starting plot: type " + str(type) running = True p = plot(None,name="Energy")[0] s = p.getSeries(0) cur = 0 time.sleep(3.0) t_start = time.time() t_end = time.time() + TIME*60.0 while running: try: if (otf_start.read() == 0 or time.time() > t_end): break e = energy.read() if (abs(e-cur)) > 0.1: v = abs((keithley_2a.read() / ((keithley_1a if (type==1) else keithley_3a).read() ))) s.appendData(e,v) cur = e except: pass print "Done Plotting" def startPlot(type = 1): global task task = fork((_startPlot,(type,)),) def stopPlot(): global task, running running = False ret = join(task) ##################### Switch Polarization function ############################# def switchpol(activeID, runtype): global pol_str if activeID == 1: caput(ID1_OFF,OFFSET1) caput(ID2_OFF,OFFSET2-40) #detune ID2 if runtype in ["+/-", "+"]: pol_str = "circ +" elif runtype in ["LH/LV", "LH"]: pol_str = "Lin. Horizontal" elif activeID == 2: caput(ID1_OFF,OFFSET1-40) #detune ID1 caput(ID2_OFF,OFFSET2) if runtype in ["+/-", "-"]: pol_str = "circ -" elif runtype in ["LH/LV", "LV"]: pol_str = "Lin. Vertical" else: raise Exception("Invalid parameter") pol_str = None def get_pol_str(): return pol_str