def _read(self, path): """Parses the contents of the file at the given path. """ # parse the contents of the file ('U' deals with newlines cross-platformly) with open(path, 'rU') as scene_file: scene = scene_file.read() # parse out the inital comment version, scene = scene.partition('\n')[::2] self.version = sscanf(version, MasFile._sVersionFormatting); # parse out the units specifier units, scene = scene.partition('\n')[::2] self.units = sscanf(units, MasFile._sUnitsFormatting); # read all of the available blocks for block_name, cls in MasFile._sBlocks: # extract the block from the file block, scene = self._extractBlock(block_name, scene) # get blocks attribute name attribute_name = self._getAttrbuteName(block_name) # set attribute with block if block: setattr(self, attribute_name, cls(block)) else: setattr(self, attribute_name, None)
def LineParser(line): cmd = line.split(' ', 1)[0] operator = "" rightOp = "" if cmd.rstrip('\n') in Vars and cmd == line: print VarValues[Vars.index(cmd.rstrip('\n'))] elif cmd == "string": data = scanf.sscanf(line,"string %s = %s") NewVar(data[0],data[1]) elif cmd == "int": data = scanf.sscanf(line,"int %s = %d") NewVar(data[0],data[1]) elif cmd.find("("): fcmd = "" try: fcmd = line.split('(', 1)[0] except: pass if fcmd in __builtin__funcs: data = CaptureFunctionParams(line) __builtin__funcs[fcmd](data) else: #user defined function pass pass try: if line.split(' ', 1)[1][0] == '=': data = GetDataFromLine(line) add_operation(data) except: pass pass
def ReadHexFile(self): print "Reading HexFile" extAddr = 0 lines = self.file.readlines() for line in lines: (byteCount, addr, recordType) = sscanf(line[1:], "%2x%4x%2x") if (recordType == 0): addr = (addr + extAddr) / 2 for count in range(0, byteCount*2, 4): if addr < 0xF80000: bInserted = self.memory[addr/(FlashMem.PM_ROW_SIZE*2)].InsertData(addr,line[9+count:13+count]) else: print "Configuration Codes - Address: 0x%x, Data: %s" %(addr, line[9+count:13+count]) if bInserted is True: #print "Hex File: 0x%x Address: %s" %(addr, line[9+count:13+count]) addr = addr + 1 else: print "Bad HexFile: 0x%x Address out of range: %s" %(addr, line[9+count:13+count]) elif (recordType == 1): "It means EOF, just do nothing" elif (recordType == 4): extAddr = sscanf(line[9:], "%4x") extAddr = extAddr[0] << 16 else: print "Unknown hex record type" return
def __init__(self, filename): lm = self.lm = lineManager(filename) self.mesh = sscanf(lm.getLine(0), 'mesh: [ %d, %d, %d ]') self.nqpoint, = sscanf(lm.getLine(1), 'nqpoint: %d') self.natom, = sscanf(lm.getLine(2), 'natom: %d') self.nbranch = 3 * self.natom self.lenatom = 4 self.leneigvec = self.natom * self.lenatom + 1 self.lenbranch = self.leneigvec + 2 self.lenband = self.lenbranch * self.nbranch + 1 self.lenqpoint = self.lenband + 3
def _parseHeader(self, header): """Cloth node header may contain cloth name. """ named = "cloth %s" anonymous = "cloth" # check if cloth named try: (self.name,) = sscanf(header, named) except IncompleteCaptureError, e: sscanf(header, anonymous) self.name = None
def _parseHeader(self, header): """Spring node header may contain spring name. """ named = "spring %s" anonymous = "spring" # check if spring named try: (self.name,) = sscanf(header, named) except IncompleteCaptureError, e: sscanf(header, anonymous) self.name = None
def _parseHeader(self, header): """Material node header may contain material name. """ named = "material %s" anonymous = "material" # check if material named try: (self.name,) = sscanf(header, named) except IncompleteCaptureError, e: sscanf(header, anonymous) self.name = None
def _parseHeader(self, header): """Geometry node header may contain geometry name. """ named = "geometry %s" anonymous = "geometry" # check if geometry named try: (self.name,) = sscanf(header, named) except IncompleteCaptureError, e: sscanf(header, anonymous) self.name = None
def _parseHeader(self, header): """Hair node header may contain hair name. """ named = "hair %s" anonymous = "hair" # check if hair named try: (self.name,) = sscanf(header, named) except IncompleteCaptureError, e: sscanf(header, anonymous) self.name = None
def processIncTx(s, txpp, N=-1, t=-1): endtime = dict() starttime = dict() tList = [] lines = s.split('\n') scheduleTime = dict() for line in lines: if 'timestampIE ' in line: info = eval(line.split('timestampIE')[1]) endtime[info[0]] = info[1] if 'timestampIB ' in line: info = eval(line.split('timestampIB')[1]) starttime[info[0]] = info[1] if 'waits for' in line: if 'now is' in line: tl = scanf.sscanf(line, '%s out: %d waits for %f now is %f') else: tl = scanf.sscanf(line, '%s out: %d waits for %f') scheduleTime[tl[1]] = tl[2] if 'proposing' in line: tl = scanf.sscanf(line, '%s out: [%d] proposing %d transactions') if txpp!=tl[2]: print "\n\n!!!!!!!!!!!!! File Inconsistent\n\n" return uniqueScheduleTime = set(scheduleTime.values()) print uniqueScheduleTime if len(uniqueScheduleTime) != 1: print "\n\n!!!!!!!!!!!!! Starting Time Unsynced\n\n" return maxLatency = 0 for key, value in endtime.items(): print key, starttime[key], value, value - starttime[key] tList.append(value - starttime[key]) if value - starttime[key] > maxLatency: maxLatency = value - starttime[key] if N < 0 or t < 0 or 3*t < N: # infer N, t N = len(starttime.keys()) t = N/4 # follows the convention that 4t = N print 'N', N, 't', t if len(endtime) < N - t: print "!!!!!!!!!!!!! Census Unfinished" return print '(N-t) finishing at', sorted(endtime.values())[N-t-1] - min(starttime.values()) print '(N/2) finishing at', sorted(endtime.values())[N/2] - min(starttime.values()) print 'max', maxLatency print 'avg', sum(tList) / len(tList) print 'range', max(endtime.values()) - min(starttime.values()) return sorted(endtime.values())[N-t-1] - min(starttime.values())
def energyForce(self): self.getVaspRun_vasp() forces = parseVasprun('forces') stress = parseVasprun('stress') c = shell_exec("grep TOTEN OUTCAR|tail -1") energy = sscanf(c, "free energy TOTEN = %f eV")[0] return forces, stress, energy
def qposition(self, iqp, i=False): lm = self.lm iline = 4 + iqp * self.lenqpoint if i: return iline return sscanf( lm.getLine(iline), '- q-position: [ %f, %f, %f ]')
def parseReg(inwords): ''' see if this is something like 0x12 : 0x234 esle return none''' try: (reg,data)=sscanf(inwords,"%x:%x") except IncompleteCaptureError: reg=data=None return (reg,data)
def kkappa(self): dirs=ls('shengold*') from aces.scanf import sscanf from aces.graph import fig,pl import matplotlib as mpl mpl.rcParams['axes.color_cycle']=['#e24a33','#2A749A','#988ed5'] us=[] for d in dirs: f=shell_exec('grep ngrid %s/CONTROL'%d) ks=sscanf(f," ngrid(:)=%d %d %d") f=np.loadtxt('%s/BTE.kappa_tensor'%d) print ks if len(f.shape)==2: x=f[-1] else: x=f x=x[1:].reshape([3,3]) print x us.append([ks,x]) with fig('kkappa_64nn.png',legend=True): p1=filter(lambda u: u[0][0]==64,us) k1=[] k2=[] k3=[] ks=[] for u in p1: ks.append(u[0][1]) k1.append(u[1][0,0]) k2.append(u[1][1,1]) k3.append(u[1][2,2]) f=np.argsort(ks) ks=np.array(ks)[f];k1=np.array(k1)[f];k2=np.array(k2)[f];k3=np.array(k3)[f]; pl.plot(ks,k1,markersize=30,linestyle='--',markeredgecolor='w',marker=".",label="${\kappa_{xx}}$") pl.plot(ks,k2,markersize=15,linestyle='--',markeredgecolor='w',marker="v",label="${\kappa_{yy}}$") pl.plot(ks,k3,markersize=15,linestyle='--',markeredgecolor='w',marker="^",label="${\kappa_{zz}}$") pl.ylim([0,0.35]) pl.xlim([0,np.array(ks).max()+1]) pl.xlabel("$Nq_y$ and $Nq_z$") pl.ylabel("Themal Conductivity (W/mK)") with fig('kkappa_n44.png',legend=True): p1=filter(lambda u: u[0][1]==4,us) k1=[] k2=[] k3=[] ks=[] for u in p1: ks.append(u[0][0]) k1.append(u[1][0,0]) k2.append(u[1][1,1]) k3.append(u[1][2,2]) f=np.argsort(ks) ks=np.array(ks)[f];k1=np.array(k1)[f];k2=np.array(k2)[f];k3=np.array(k3)[f]; pl.plot(ks,k1,markersize=30,linestyle='--',markeredgecolor='w',marker=".",label="${\kappa_{xx}}$") pl.plot(ks,k2,markersize=15,linestyle='--',markeredgecolor='w',marker="v",label="${\kappa_{yy}}$") pl.plot(ks,k3,markersize=15,linestyle='--',markeredgecolor='w',marker="^",label="${\kappa_{zz}}$") pl.ylim([0,0.35]) pl.xlim([0,np.array(ks).max()+100]) pl.xlabel("$Nq_x$") pl.ylabel("Themal Conductivity (W/mK)")
def InsertData(self, address, data): # debug("... 0x%06x, 0x%06x" %(address, self.address) ) if (address < self.address) or (address >= (self.address + self.PM_ROW_SIZE*2)): return False if self.empty is True: if self.type is self.PROGRAM: self.buffer = array.array('c', chr(0xff)*self.PM_ROW_SIZE*3) else: self.buffer = array.array('c', chr(0xff)*3) self.empty = False addr = address - self.address # debug( "address received: 0x%06x, self.address: 0x%06x" %(address, self.address)) # debug("At 0x%06x, %s is inserted" %(address, data) ) (value,) = sscanf(data, "%4x") if addr%2 is 0: self.buffer[(addr>>1)*3 + 0] = chr((value >> 8) & 0x00FF) self.buffer[(addr>>1)*3 + 1] = chr(value & 0x00FF) else: self.buffer[(addr>>1)*3 + 2] = chr((value >> 8) & 0x00FF) # print "Data at Address: 0x%x Data: 0x%02x%02x%02x" %(addr-1, # ord(self.buffer[(addr>>1)*3+2]), # ord(self.buffer[(addr>>1)*3+1]), ord(self.buffer[(addr>>1)*3])) return True
def GetDataFromLine(line): data = tuple() try: #try until proper capture from scanf data = scanf.sscanf(line,"%s = %s + %s") except: pass try: data = scanf.sscanf(line,"%s = %d + %s") except: pass try: data = scanf.sscanf(line,"%s = %s + %d") except: pass return data pass
def parseReg(inwords): ''' see if this is something like 0x12 : 0x234 esle return none''' try: (reg, data) = sscanf(inwords, "%x:%x") except IncompleteCaptureError: reg = data = None return (reg, data)
def kmfp(self): def ff(p,x): #return p[0]*(1.0-np.exp(-x**p[2]/p[1])) return 1.0/(p[1]/x+1/p[0])-p[2] #return p[0]*p[1]**x def fit(x,z,p0,tt): def errorfunc(p,x,z): return tt(p,x)-z from scipy.optimize import leastsq solp, ier = leastsq(errorfunc, p0, args=(x,z), Dfun=None, full_output=False, ftol=1e-9, xtol=1e-9, maxfev=100000, epsfcn=1e-10, factor=0.1) return solp dirs=ls('shengold*') from aces.scanf import sscanf from aces.graph import fig,pl us=[] for d in dirs: f=shell_exec('grep ngrid %s/CONTROL'%d) ks=sscanf(f," ngrid(:)=%d %d %d") if(ks[1]!=4):continue f=np.loadtxt('%s/BTE.cumulative_kappa_scalar'%d) us.append([ks,f]) with fig('reduce_mfp.png',legend=True,ncol=1): for i,u in enumerate(us): if i <3:continue ks,f=u x,y=f[:,0],f[:,1] pl.semilogx(x,y,label="Nx= %d "%ks[0],linewidth=2) ks,f=us[-1] x,y=f[:,0],f[:,1] #fil=(x>0) #p=fit(x[fil],y[fil],[1,1,1],ff) #y1=ff(p,x) #pl.semilogx(x,y1,label="fit of Nx= %d "%ks[0],linewidth=2) pl.xlabel('Cutoff Mean Free Path for Phonons (Angstrom)') pl.ylabel('Thermal Conductivity (W/mK)') pl.grid(True) with fig('kappa_inv_mpf_inv.png',legend=True,ncol=1): ks,f=us[-1] fil=x>.5 x,y=f[fil,0],f[fil,1] xx=1/x;yy=1/y pl.plot(xx,yy,linewidth=3,c='red',label="Nx=1024") def ll(p,x): return p[0]*x+p[1] fil=xx>xx.max()/4 p=fit(xx[fil],yy[fil],[1,1,1],ll) pl.plot(xx,ll(p,xx),lw=3,ls='dashed',label="Fitted") pl.xlabel('1/L (1/Angstrom)') pl.ylabel('$1/\\kappa_L$ (mK/W)') pl.grid(True)
def frequency(self, iqp, ibr, i=False): lm = self.lm iline = self.qposition(iqp, i=True) + 3 + ibr * self.lenbranch + 1 if i: return iline freq, = sscanf(lm.getLine(iline), ' frequency: %f') return freq
def checkLatency(): ''' PING 52.49.163.101 (52.49.163.101) 56(84) bytes of data. 64 bytes from 52.49.163.101: icmp_seq=1 ttl=45 time=141 ms --- 52.49.163.101 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 141.722/141.722/141.722/0.000 ms ''' resDict = [] totLen = len(env.hosts) for destination in env.hosts: waste = BytesIO() with hide('output', 'running'): res = run('ping -c 3 %s' % destination, stdout=waste, stderr=waste).strip().split('\n')[1].strip() # print repr(res) lat = scanf.sscanf( res, '%d bytes from %s icmp_seq=%d ttl=%d time=%f ms')[-1] resDict.append(lat) print ' '.join([ env.host_string, str(sorted(resDict)[int(math.ceil(totLen * 0.75))]), str(sum(resDict) / len(resDict)) ])
def atom(self, iqp, ibr, ia): lm = self.lm pos = np.zeros(3, dtype=np.complex) iline = self.frequency(iqp, ibr, True) + 2 + self.lenatom * ia + 1 lm.moveto(iline) for i in range(3): x1, x2 = sscanf(lm.nextLine(), ' - [ %f, %f ]') pos[i] = x1 + 1j * x2 return pos
def __init__(this, path_ini): if not os.path.exists(path_ini): err = "file [%s] doesn't exist" % path_ini log.WriteError(err) raise Exception, err ini_parser = ConfigParser.ConfigParser() ini_parser.read(path_ini) this.exchg_info = {} this.contract_exchg_sub = {} for exg_id in xrange(1, 20): session_name = "Exchange%d" % exg_id if not ini_parser.has_section(session_name): break info = exchange_info() # 交易所名字 info.name = ini_parser.get(session_name, "name") info.sub_name = ini_parser.get(session_name, "sub_name") for end_date_id in xrange(1, 10): option_name = "end_date%d" % end_date_id if not ini_parser.has_option(session_name, option_name): break end_date = int(ini_parser.get(session_name, option_name)) info.end_date_set.append(end_date) info.stage_time[end_date] = [] info.stage_min_times[end_date] = [] for time_id in xrange(1, 10): sub_option_name = "time%d%d" % (end_date_id, time_id) if not ini_parser.has_option(session_name, sub_option_name): break time_str = ini_parser.get(session_name, sub_option_name) time_arr = scanf.sscanf(time_str, "%d-%d") info.stage_time[end_date].append(time_arr) time_tick = this.make_min_time(time_arr[0], time_arr[1]) info.stage_min_times[end_date].extend(time_tick) this.exchg_info[info.sub_name] = info for var_id in xrange(1, 100): option_name = "var%d" % var_id if not ini_parser.has_option(session_name, option_name): break var_name = ini_parser.get(session_name, option_name) this.contract_exchg_sub[var_name] = info.sub_name
def _parseAttributeScanf(self, line, formatting): """Use scanf to parse the data from the line. Formatting can be a single entry or a list of entrys. If multiple entrys are available the first matching entry will be returned. """ # multiple entrys if isinstance(formatting, list): for scanf_format in formatting: try: # print "<<<----", scanf_format, line return sscanf(line, scanf_format) except IncompleteCaptureError, e: pass
def __init__(self, block): """Initialize self with scene data. """ super(AntBlock, self).__init__() # parse the entry using regex pattern match = re.match(AntBlock._sPattern, block) self.type = match.group('type') self.mode = match.group('mode') self.program = match.group('program') self.id = int(match.group('id')) self.cdl = match.group('cdl') self.apf = match.group('apf') self.frame = int(match.group('frame')) # parse variable data variableData = match.group('vars').split(' ') names = variableData[0::2] values = variableData[1::2] # use dictionary to manage variables self.variables = {} self._varOrder = names for name, value in zip(names, values): if name not in self.variables: self.variables[name], = sscanf(value, "%f") else: raise ValueError("Duplicate variable name '%s' found, ant %s from %s" % \ (name, self.id, self.cdl)) # parse transform transform = match.group('transform') formatting = AntBlock._sTransformFormatting.replace('%g', '%f') (tx, ty, tz, rx, ry, rz) = sscanf(transform, formatting) self.tx, self.ty, self.tz = tx, ty, tz self.rx, self.ry, self.rz = rx, ry, rz
def _read(self, path): """Parses the contents of the file at the given path. """ # parse the contents of the file ('U' deals with newlines cross-platformly) with open(path, 'rU') as agent_file: scene = agent_file.read() # parse out the inital comment version, scene = scene.partition('\n')[::2] self.version = sscanf(version, CdlFile._sVersionFormatting) # eat single newline scene = scene.partition('\n')[2] # parse out the units specifier units, scene = scene.partition('\n')[::2] self.units = sscanf(units, CdlFile._sUnitsFormatting) # eat single newline scene = scene.partition('\n')[2] # parse object block self.object_block = ObjectBlock(scene)
def checkLatency(): ''' PING 52.49.163.101 (52.49.163.101) 56(84) bytes of data. 64 bytes from 52.49.163.101: icmp_seq=1 ttl=45 time=141 ms --- 52.49.163.101 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 141.722/141.722/141.722/0.000 ms ''' resDict = [] totLen = len(env.hosts) for destination in env.hosts: waste = BytesIO() with hide('output', 'running'): res = run('ping -c 3 %s' % destination, stdout=waste, stderr=waste).strip().split('\n')[1].strip() # print repr(res) lat = scanf.sscanf(res, '%d bytes from %s icmp_seq=%d ttl=%d time=%f ms')[-1] resDict.append(lat) print ' '.join([env.host_string, str(sorted(resDict)[int(math.ceil(totLen * 0.75))]), str(sum(resDict) / len(resDict))])
def do(): Csv.writer(...) print ", ".join(["sent time", "received time", "delta or aggressor", "type", "SSN", "ISN", "bid depth", "bid volume", "bid price", "ask depth", "ask volume", "ask price"]) with open(InputFileName) as input_file: index_line = 0 formated_str = "" oneRow = [] for line in input_file: if line == "\n": index_line = 1 print '' continue if index_line == 0: pass elif index_line == 1: # add oneRow to output file Cvs.writer(oneRow, ....) OneRow = [] #print(line) num_segments = len(line.split(" ")) #print num_segments if num_segments == 9: header1, header2, header3, header4, ssn, isn, sent, recv, indx = s.sscanf(line, "%s %s %s %s SSN:%s ISN:%s Sent:%s Received:%s (%d)") header = header1 + header2 + header3 + header4 elif num_segments == 7: header1, header2, ssn, isn, sent, recv, indx = s.sscanf(line, "%s %s SSN:%s ISN:%s Sent:%s Received:%s (%d)") header = header1 + header2 elif num_segments == 15: header1, header2, header3, header4, ssn, isn, sent, recv, indx = s.sscanf(line, "%s %s %s %s SSN:%s ISN:%s Sent:%s Received:%s %s") indx = " ".join(line.split()[-7:]) header = header1 + header2 + header3 + header4 elif num_segments == 14: header1, header2, header3, header4, ssn, isn, sent, recv, indx = s.sscanf(line, "%s %s %s %s SSN:%s ISN:%s Sent:%s Received:%s %s") indx = " ".join(line.split()[-6:]) header = header1 + header2 + header3 + header4 elif num_segments == 13: header1, header2, ssn, isn, sent, recv, indx = s.sscanf(line, "%s %s SSN:%s ISN:%s Sent:%s Received:%s %s") indx = " ".join(line.split()[-7:]) header = header1 + header2 elif num_segments == 12: header1, header2, ssn, isn, sent, recv, indx = s.sscanf(line, "%s %s SSN:%s ISN:%s Sent:%s Received:%s %s") indx = " ".join(line.split()[-6:]) header = header1 + header2
def parse(file): count = 1 last_abs_cpu = 0 last_abs_real = 0 printed_last = 1 for line in file: line = line.strip() try: tuple = scanf.sscanf(line, "%d: %f %f") count, abs_cpu, abs_real = tuple if abs_cpu > last_abs_cpu: rel_cpu = abs_cpu - last_abs_cpu last_abs_cpu = abs_cpu else: rel_cpu = abs_cpu if abs_real > last_abs_real: rel_real = abs_real - last_abs_real last_abs_real = abs_real else: rel_real = abs_real printed_last = 0 print str(count / 1000) + "k: ", str(rel_cpu), " ", str(rel_real) except: if line.endswith("."): if not printed_last: print_stats(last_abs_cpu, last_abs_real, count) last_abs_cpu = 0 last_abs_real = 0 printed_last = 1 print line #except StandardError, e: #print "Error: ", line, e if not printed_last: print_stats(last_abs_cpu, last_abs_real, count) last_abs_cpu = 0 last_abs_real = 0
def walk_sub_dir(cur_dir, sub_dir): map_report_per_area = {} sub_path = cur_dir + '\\' + sub_dir for root, dirs, files in os.walk(sub_path): for file_name in files: file_path = root + '\\' + file_name fp = open(file_path, "rb") if None == fp: log.WriteError('%s can\'t be opened' % file_path) continue empty_index_first = file_name.find(' ') empty_index_second = file_name.find(' ', empty_index_first + 1) date = file_name[empty_index_first + 1:empty_index_second] map_report_per_area[date] = {} line = fp.readline() while (len(line) > 0): user_info = scanf.sscanf(line, "%s %s %s %s %s %d %s %d %d %d") key = "android%u" % (user_info[7]) if 53 == user_info[8]: key = "java%u" % (user_info[7]) if map_report_per_area[date].has_key(key): map_report_per_area[date][ key] = map_report_per_area[date].get(key) + 1 else: map_report_per_area[date][key] = 1 line = fp.readline() fp.close() return map_report_per_area
def getIffinderInfo(stdoutFile, stderrFile): # extract data from stderr file stderrContent = stderrFile.read() stderrData = scanf.sscanf(stderrContent, stderrFormat) # extract data from stdout file commentCounter = 0 routerNameToIPs = {} for line in stdoutFile.readlines(): # look for commment lines if commentCounter > 2: break if line[0] == "#": commentCounter += 1 continue # read router info splitLine = line.split("\t") ipList = getList(splitLine[1]) routerNameToIPs[splitLine[0]] = ipList # reduce to relevant data disagreements = stderrData[13] return disagreements, routerNameToIPs
import scanf days = [] f = open("IFL0.TXT", "rt") if f: l = f.readline() while l: try: y, m, d = scanf.sscanf(l, "%d/%d/%d") days.append(y * 10000 + m * 100 + d) except Exception, e: pass l = f.readline() f.close() f = open("days.txt", "wt") for day in days: f.write("%d\n" % day) f.close()
import aces.tools as tl from scanf import sscanf from aces.graph import fig, pl, setLegend data = [] kappa = [] i = -1 for lx, procs, nodes in [(1, 4, 1), (2, 4, 1), (3, 6, 1), (5, 6, 1), (9, 12, 1), (13, 12, 3)]: i += 1 dir = "sl/nx/" + str(i) p = np.loadtxt(dir + '/tempAve.txt', skiprows=1) x = np.linspace(0, 1, len(p)) data.append([x, p[:, 3], 'nx=' + str(lx)]) dt = p[10:, 3] - p[:-10, 3] p = tl.shell_exec('tail -1 %s/result.txt' % dir) k, = sscanf(p, 'kappa_src=%f') dt = np.sort(np.abs(dt))[-lx:].mean() kappa.append([lx, k, dt]) # dataT=p[30,3]-p[20,3] # j=(p[:,4]*p[:,2]).sum()/p[:,2].sum() # kapitza.append([dT,np.abs(j)/dataT]) # kapitza=np.array(kapitza) i = -1 for lx, procs, nodes in [(17, 12, 1), (24, 12, 2)]: i += 1 dir = "sl/nx2/" + str(i) p = np.loadtxt(dir + '/tempAve.txt', skiprows=1) x = np.linspace(0, 1, len(p)) data.append([x, p[:, 3], 'nx=' + str(lx)])
input = [0] accel_data = [0] last_gyro_angle = 0.0 gyro_data = [0] count_data = [0] last_angle = 0.0 fd = open(filename, 'r') sensor_offset = 0.5 potenc_ampl = 11.8 # alpha = 0.005 for line in fd: # data = sc.sscanf( line , "#S:%d#R:%d#I:%d#A:%d#G:%d" ) data = sc.sscanf(line, "#S:%d#R:%d#I:%d") fulltime += 2.5 / 1000 time.append(fulltime) sens_data.append(data[0] / angle_multiplyer + sensor_offset) real_data.append(data[1] / potenc_ampl) input.append(data[2] / angle_multiplyer) # accel_data.append(data[3]/angle_multiplyer) # last_gyro_angle += data[4]/angle_multiplyer # gyro_data.append(last_gyro_angle) # count_data.append( (1 - alpha)*(last_angle + data[4]/angle_multiplyer) + alpha*(data[3]/angle_multiplyer) ); last_angle = data[0] / angle_multiplyer fig = plt.figure() # fig.subplots_adjust(right=0.99, left=0.04, top=0.98, bottom=0.06) plt.plot(time, input, 'm-', label='Inpt')
def parse(file): cmins_old = { "Inserting": 0.0, "Searching": 0.0, "Deleting": 0.0, "Reinserting": 0.0, "Antisearch": 0.0 } rmins_old = { "Inserting": 0.0, "Searching": 0.0, "Deleting": 0.0, "Reinserting": 0.0, "Antisearch": 0.0 } cmindiff = { "Inserting": 0.0, "Searching": 0.0, "Deleting": 0.0, "Reinserting": 0.0, "Antisearch": 0.0 } rmindiff = { "Inserting": 0.0, "Searching": 0.0, "Deleting": 0.0, "Reinserting": 0.0, "Antisearch": 0.0 } apcs_old = { "Inserting": 0.0, "Searching": 0.0, "Deleting": 0.0, "Reinserting": 0.0, "Antisearch": 0.0 } aprs_old = { "Inserting": 0.0, "Searching": 0.0, "Deleting": 0.0, "Reinserting": 0.0, "Antisearch": 0.0 } apcsdiff = { "Inserting": 0.0, "Searching": 0.0, "Deleting": 0.0, "Reinserting": 0.0, "Antisearch": 0.0 } aprsdiff = { "Inserting": 0.0, "Searching": 0.0, "Deleting": 0.0, "Reinserting": 0.0, "Antisearch": 0.0 } for line in file: line = line.strip() if line.startswith("Size"): act, cnt = scanf.sscanf(line, "%s = %d") print "Now", nice_float(cnt), "items in BTree" elif line.startswith("INSERTING") or line.startswith("SEARCH") \ or line.startswith("DELETE") or line.startswith("ANTISEARCH") \ or line.startswith("REINSERTING"): try: act, cnt, ticks, times = scanf.sscanf(line,\ "%s %d %*d: %*s %*s (%d) %*s %*s (%d)") if act == "SEARCH": act = "Searching" elif act == "INSERTING": act = "Inserting" elif act == "DELETE": act = "Deleting" elif act == "ANTISEARCH": act = "Antisearch" elif act == "REINSERTING": act = "Reinserting" csecs = ticks / 10E5 cmins = csecs / 60.0 apcs = cnt / csecs cmindiff[act] = cmins - cmins_old[act] apcsdiff[act] = apcs - apcs_old[act] cmins_old[act], apcs_old[act] = cmins, apcs rsecs = times / 10E6 rmins = rsecs / 60.0 aprs = cnt / rsecs rmindiff[act] = rmins - rmins_old[act] aprsdiff[act] = aprs - aprs_old[act] rmins_old[act], aprs_old[act] = rmins, aprs print act, nice_int(cnt), ": C",\ round_float(cmins), "min ",\ "("+ round_float(cmindiff[act]) +"min) ",\ round_float(apcs), "ps ",\ "("+ round_float(apcsdiff[act]) +"ps) " print act, nice_int(cnt), ": R",\ round_float(rmins), "min ",\ "("+ round_float(rmindiff[act]) +"min) ",\ round_float(aprs), "ps ",\ "("+ round_float(aprsdiff[act]) +"ps) " except StandardError, e: print line print "Error: ", line, e else: print line
def get_full_time(self, time): (hour, minute, sec) = scanf.sscanf(time, '%d:%d:%f') return sec + minute * 60 + hour*60*60
def get_relative_time(self, time): (hour, minute, sec) = scanf.sscanf(time, '%d:%d:%f') time = sec + minute * 60 + hour*60*60 ret = self.key_time + (time - self.proc_mon_key_time) * time_convert return int(ret)
def GetSecondsFromDatailTime(time): (hour, minute, sec) = scanf.sscanf(time, '%d:%d:%f') return sec + minute * 60 + hour*60*60
def getGrid(self): s = shell_exec("grep ngrid CONTROL") from scanf import sscanf grids = sscanf(s, "ngrid(:)=%d %d %d") return grids
f = open('dataFDES.cnf', 'r') contents = f.read() f.close() nAt = 0 for row in contents.split("\n"): if 'atom:' in row: nAt = nAt + 1 s = 'Numer of atoms ' + repr(nAt) print s for row in contents.split("\n"): if 'image_size_x:' in row: scanfTemp = scanf.sscanf(row, 'image_size_x: %d' ) nx = scanfTemp[0] if 'image_size_y:' in row: scanfTemp = scanf.sscanf(row, 'image_size_y: %d' ) ny = scanfTemp[0] if 'image_size_z:' in row: scanfTemp = scanf.sscanf(row, 'image_size_z: %d' ) nz = scanfTemp[0] s = 'Image size ' + repr(nx) + ' ' + repr(ny) + ' ' + repr(nz) print s atomsArray = np.zeros(nAt* 6) atomsArray = atomsArray.astype(np.float32) atomsArray_p = atomsArray.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
def kmfp(self): def ff(p, x): # return p[0]*(1.0-np.exp(-x**p[2]/p[1])) return 1.0 / (p[1] / x + 1 / p[0]) - p[2] # return p[0]*p[1]**x def fit(x, z, p0, tt): def errorfunc(p, x, z): return tt(p, x) - z from scipy.optimize import leastsq solp, ier = leastsq( errorfunc, p0, args=(x, z), Dfun=None, full_output=False, ftol=1e-9, xtol=1e-9, maxfev=100000, epsfcn=1e-10, factor=0.1) return solp dirs = ls('shengold*') from aces.scanf import sscanf from aces.graph import fig, pl us = [] for d in dirs: f = shell_exec('grep ngrid %s/CONTROL' % d) ks = sscanf(f, " ngrid(:)=%d %d %d") if (ks[1] != 4): continue f = np.loadtxt('%s/BTE.cumulative_kappa_scalar' % d) us.append([ks, f]) with fig('reduce_mfp.png', legend=True, ncol=1): for i, u in enumerate(us): if i < 3: continue ks, f = u x, y = f[:, 0], f[:, 1] pl.semilogx(x, y, label="Nx= %d " % ks[0], linewidth=2) ks, f = us[-1] x, y = f[:, 0], f[:, 1] # fil=(x>0) # p=fit(x[fil],y[fil],[1,1,1],ff) # y1=ff(p,x) # pl.semilogx(x,y1,label="fit of Nx= %d "%ks[0],linewidth=2) pl.xlabel('Cutoff Mean Free Path for Phonons (Angstrom)') pl.ylabel('Thermal Conductivity (W/mK)') pl.grid(True) with fig('kappa_inv_mpf_inv.png', legend=True, ncol=1): ks, f = us[-1] fil = x > .5 x, y = f[fil, 0], f[fil, 1] xx = 1 / x yy = 1 / y pl.plot(xx, yy, linewidth=3, c='red', label="Nx=1024") def ll(p, x): return p[0] * x + p[1] fil = xx > xx.max() / 4 p = fit(xx[fil], yy[fil], [1, 1, 1], ll) pl.plot(xx, ll(p, xx), lw=3, ls='dashed', label="Fitted") pl.xlabel('1/L (1/Angstrom)') pl.ylabel('$1/\\kappa_L$ (mK/W)') pl.grid(True)
sqlfile.write(writeLine) else: sqlfile.write(',\n') old_table=tableName if string.replace(col_name,' ','') == '': continue ##print col_name col_name=string.replace(string.replace(col_name,' ',''),'-','_') writeLine=col_name if col_type == 'CHAR' or col_type == 'char' or tran_flag=='A' or tran_flag=='D' or tran_flag=='C' or tran_flag=='T' \ or tran_flag=='L' or tran_flag=='B': writeLine=writeLine+' varchar2(%d)'%col_length else: #判断数字的小数位数 p=re.compile("\.9\([0-9]*\)") m=p.findall(col_copybook) if len(m) == 0: writeLine=writeLine+' number(%d)'%col_length elif len(m) == 1: point_length=scanf.sscanf(m[0],".9(%d)") writeLine=writeLine+' number(%d,%d)'%(col_length,point_length[0]) else: print col_name print "read copybook err" continue if sh.cell_value(i,16) == 'Y': index_pk_list.append(col_name) sqlfile.write(writeLine) sqlfile.close()
#!/usr/bin/env python import scanf scanf = scanf.Scanf() scanf.make('%s - %d %s, %d %s') print scanf.sscanf('/usr/sbin/sendmail - 0 errors, 4 warnings')
def _parseHeader(self, header): """Segment node header may contain segment name. """ formatting = "standin %s" (self.name,) = sscanf(header, formatting)
help="dry run") (opts, args) = parser.parse_args() print args data_dir = args[0] pretty_fmt_str = args[1] datfilename = os.path.abspath(args[2]) dry_run = opts.dry_run format_str = re.sub("{channel}|{trial}", "%d", pretty_fmt_str) print format_str in_dtype = np.dtype(">i2") out_dtype = np.int16 in_data_dir = lambda filename: join(data_dir, filename) n_bytes = in_dtype.itemsize get_first = lambda filename: sscanf(filename, format_str)[0] get_second = lambda filename: sscanf(filename, format_str)[1] get_channel0, get_trial0 = (get_first, get_second) if pretty_fmt_str.index( "channel") < pretty_fmt_str.index("trial") else (get_second, get_first) def is_right_type(filename): try: sscanf(filename, format_str) return True except Exception: return False orig_dir = os.path.abspath(os.curdir) os.chdir(data_dir)
Formatting can be a single entry or a list of entrys. If multiple entrys are available the first matching entry will be returned. """ # multiple entrys if isinstance(formatting, list): for scanf_format in formatting: try: # print "<<<----", scanf_format, line return sscanf(line, scanf_format) except IncompleteCaptureError, e: pass # single entry else: return sscanf(line, formatting) # problem if none of the formats worked raise IncompleteCaptureError("Format error for %s" % line) # -------------------------------------------------------------------------- def parseAttributes(self, block, scanf_list, special_list={}, skip_list=[]): """Parses block for attributes using the formatting. """ # remove trailing newlines block = block.strip("\n") # create a hash of the attributes for easy lookup scanf_map, order = self._createAttributeFormattingMap(scanf_list)
def _parseHeader(self, header): """Segment node header may contain segment name. """ formatting = "afield %s %s" (self.type, self.name) = sscanf(header, formatting)
for root, dirs, files in os.walk(system_info.profit_dir): for name in files: index = name.rfind("_") contract = name[0:index] path = os.path.join(root, name) fp_profit = open(path, "rb") print path line = fp_profit.readline() sysID = 1 while(len(line) > 0): # print line profit = scanf.sscanf(line, "%d %d %f %f %f %f %d") dir_str = "买入" if profit[1] == 0 else "卖出" sql = "insert into %s values('%s','%s','',%d, '开',%u,%u,'%s',%f,%f,%f,%f,%u);" % (system_info.db_table, system_info.name, contract, sysID, profit[0]/10000,profit[0]%10000*100,dir_str,profit[2],profit[3],profit[4],profit[5], profit[6]) if profit[3] != 0: sql = "insert into %s values('%s','%s','',%d, '平',%u,%u,'%s',%f,%f,%f,%f,%u);" % (system_info.db_table, system_info.name, contract, sysID, profit[0]/10000,profit[0]%10000*100,dir_str,profit[2],profit[3],profit[4],profit[5], profit[6]) # db_execute.Execute(sql) fp_sql.write(sql) fp_sql.write("\n") line = fp_profit.readline()
def getGrid(self): s=shell_exec("grep ngrid CONTROL") from scanf import sscanf grids=sscanf(s,"ngrid(:)=%d %d %d") return grids
def is_right_type(filename): try: sscanf(filename, format_str) return True except Exception: return False
"thread_num"], "tid_list", trace_mem[ad]["tid_list"] for tid in trace_mem[ad]: if tid != "thread_num" and tid != "tid_list": print "==>tid", tid, "optag", trace_mem[ad][tid]["optag"] for it in trace_mem[ad][tid]["trace_list"]: print "====>", it file_lock_handler = open("file_lock.log", "r") each_line = True while each_line: each_line = file_lock_handler.readline() #print each_line if each_line: tid, op, time, callsite_v, entry_v = scanf.sscanf( each_line, "tid:%d,op:%c,time:%d,callsite_v:0x%x,entry_v:0x%x") #print tid, op, time, hex(callsite_v), hex(entry_v) ''' trace_mem = {"addr1": addr_dict1, "addr2":addr_dict2} addr_dict = {"thread_num":2, "tid_list":tid_list, "tid1":tid_dict1, "tid2": tid_dict2} tid_list = [tid1,tid2] tid_dict = {"optag": 2, "trace_list": tlist} # optag: 0,R; 1,W; 2,R&W tlist = [trace1, trace2]