def read_dcm_func():
get_bytes=request.get_data()
dcm_dicts={}
dcm_names_str = str(get_bytes, encoding='utf-8')
dcm_names_dict = json.loads(dcm_names_str)
for key in dcm_names_dict.keys():
dcm_name=dcm_names_dict[key]
print(dcm_name)
dcm_dict=read_DCM(dcm_name)
dcm_dicts.update(dcm_dict)
pprint.pprint(dcm_dicts)
return jsonify(dcm_dicts)
def read_DCM(dcm_file):
this_dcm={}
with open(dcm_file,'rb') as t:
tt=t.read()
tt=str(tt, encoding='utf-8')
matchObj =re.findall( 'FESTWERT[\s\S]*?END',tt)
if matchObj:
for part in matchObj:
lines=re.split("\n",part)
if lines[0]:
words=re.split("\s+",lines[0])
name=words[1]
if lines[-2]:
words=re.split("\s+",lines[-2])
value=words[2]
this_dcm[name]=eval(value)
with open(dcm_file,'rb') as t:
tt=t.read()
tt=str(tt, encoding='utf-8')
matchObj =re.findall( 'KENNLINIE[\S\s]*?END',tt)
if matchObj:
for part in matchObj:
X=[]
Z=[]
lines=re.split("\n",part)
if lines[0]:
words=re.split("\s+",lines[0])
name=words[1]
for line in lines:
words=re.split("\s+",line)
if(len(words)>1):
if("ST" in words[1]):
for x in words[2:len(words)-1]:
X.append(eval(x))
if(words[1]=="WERT"):
for z in words[2:len(words)-1]:
Z.append(eval(z))
curve={}
curve['x']=X
curve['z']=Z
this_dcm[name]=curve
return this_dcm
一次读取多个dcm,返回一个字典
转载上一篇:文件的读写及其相关
下一篇:scala 第三方包和打jar包
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章