#Script imported from: MgE_plus.xml #Parameters """ E1 = 710 E2 = 720 TIME = 1 #min DELAY = 10.0 #s MODE = 'CIRC +' OFFSET = -9.0 FOLDER = '2015_04/20150417' FILE = 'Fe_plus' ALPHA=0 """ print "\nStarting energy scan - Parameters: ", print E1,E2,TIME,DELAY,MODE ,OFFSET ,FOLDER ,FILE ,ALPHA start = time.localtime() folder = os.path.expanduser("~/Data1/") + FOLDER + "/"; def getNewestFile(): global folder import glob try: return max(glob.iglob(folder+'/*.txt'), key=os.path.getctime) except: return None newest = getNewestFile() #Pre-actions wait_beam() if MODE is not None: pol_mode.write(MODE) #caput('X07MA-ID:MODE', MODE) #TODO: CAPUT time.sleep(1.0) #TODO: Needed? if MODE == 'LINEAR': if ALPHA is not None: pol_angle.write(ALPHA) #TODO: CAPUT #pol_done.waitValue("DONE") #TODO: NEEDED? if OFFSET is not None: pol_offset.write(OFFSET) #TODO: CAPUT #pol_done.waitValue("DONE") caput('E1', E1) caput('E2', E2) caput('TIME', TIME) caput('FOLDER', FOLDER) set_energy (E1) caput('FILE', FILE) time.sleep(0.1) open_valve() open_valve(0.0) #TODO: WHY WRITING AGAIN??? time.sleep(DELAY) caput('START', '1') #Post-actions wait_channel('START', 'STOP', type = 's') time.sleep(2.0) print "Finished Energy scan" #File convertion newName = folder + time.strftime("%Y%m%d_%H%M_", start) + FILE + "_0000.txt"; name = getNewestFile() if name == newest: raise Exception("Data file not created") if not os.path.isfile(name): raise Exception("Data file not found: " + name) convert_file(name, newName) print("Success")