Beispiel #1
0
def tuisavefile(filename):
	"""
	Save the Energyplus file
	"""
	global data
	Prompt='Would you like to save this file ?'
	Action = tui1.RadioButtons("Choose an action",( ("Save",1),("Save As",2),("Quit",3) ))
	if Action==3:
		return
	if Action==1:
		mylib1.writeStr2File(filename,`data`)
		return
	Prompt='Choose new file name:'
	filename=tui1.TextEntry(Prompt)
	mylib1.writeStr2File(filename,`data`)
def Mtabstr2doestr(st1):
    seperator='$=================='
    ls=string.split(st1,seperator)

    #this removes all the tabs that excel
    #puts after the seperator and before the next line
    for n in range(0,len(ls)):
        ls[n]=string.lstrip(ls[n])
    st2=''
    for n in range(0,len(ls)):
        alist=tabstr2list(ls[n])
        st2=st2+list2doe(alist)

    lss=string.split(st2,'..')
    mylib1.writeStr2File('forfinal.txt',st2)#for debugging
    print len(lss)


    st3=tree2doe(st2)
    lsss=string.split(st3,'..')
    print len(lsss)
    return st3
import mylib1,mylib2
def tabfile2doefile(tabfile,doefile):
    alist=tabfile2list(tabfile)
    str=list2doe(alist)
    mylib1.writeStr2File(doefile,str)
def extractidddata(fname,debug=False):
	"""
	extracts all the needed information out of the idd file
	if debug is True, it generates a series of text files.
	Each text file is incrementally different. You can do a diff 
	see what the change is
	"""
	st=mylib2.readfile(fname)
	(nocom,nocom1,blocklst)=get_nocom_vars(st)
	
	
	st=nocom
	st1=removeblanklines(st)
	if debug:
		mylib1.writeStr2File('nocom2.txt',st1)
	
	
	#find the groups and the start object of the group
	#find all the group strings
	groupls=[]
	ls=st1.splitlines()
	for el in ls:
		lss=el.split()
		if lss[0].upper()=='\\group'.upper():
			groupls.append(el)
	
	
	#find the var just after each item in groupls
	groupstart=[]
	for i in range(len(groupls)):
		ii=ls.index(groupls[i])
		groupstart.append([ls[ii],ls[ii+1]])
	
	#remove the group commentline
	for el in groupls:
		ls.remove(el)
	
	if debug:
		st1='\n'.join(ls)
		mylib1.writeStr2File('nocom3.txt',st1)
	
	#strip each line
	for i in range(len(ls)):
		ls[i]=ls[i].strip()
	
	if debug:
		st1='\n'.join(ls)
		mylib1.writeStr2File('nocom4.txt',st1)
	
	#ensure that each line is a comment or variable
	#find lines that don't start with a comment
	#if this line has a comment in it
	#	then move the comment to a new line below
	lss=[]
	for i in range(len(ls)):
		#find lines that don't start with a comment
		if ls[i][0]!='\\':
			#if this line has a comment in it
			pt=ls[i].find('\\')
			if pt!=-1:
				#then move the comment to a new line below
				lss.append(ls[i][:pt].strip())
				lss.append(ls[i][pt:].strip())
			else:
				lss.append(ls[i])
		else:
			lss.append(ls[i])
	
	
	ls=lss[:]
	if debug:
		st1='\n'.join(ls)
		mylib1.writeStr2File('nocom5.txt',st1)
	
	#need to make sure that each line has only one variable - as in WindowGlassSpectralData,
	lss=[]
	for el in ls:
		# if the line is not a comment
		if el[0]!='\\':
			#test for more than one var
			ll=el.split(',')
			if ll[-1]=='':
				tmp=ll.pop()
			for elm in ll:
				if elm[-1]==';':
					lss.append(elm.strip())
				else:
					lss.append((elm+',').strip())
		else:
			lss.append(el)
	
	ls_debug=ls[:] # needed for the next debug - 'nocom7.txt'
	ls=lss[:]
	if debug:
		st1='\n'.join(ls)
		mylib1.writeStr2File('nocom6.txt',st1)
	
	if debug:
		#need to make sure that each line has only one variable - as in WindowGlassSpectralData,
		#this is same as above.
		# but the variables are put in without the ';' and ','
		#so we can do a diff between 'nocom7.txt' and 'nocom8.txt'. Should be identical
		lss_debug=[]
		for el in ls_debug:
			# if the line is not a comment
			if el[0]!='\\':
				#test for more than one var
				ll=el.split(',')
				if ll[-1]=='':
					tmp=ll.pop()
				for elm in ll:
					if elm[-1]==';':
						lss_debug.append(elm[:-1].strip())
					else:
						lss_debug.append((elm).strip())
			else:
				lss_debug.append(el)
		
		ls_debug=lss_debug[:]
		st1='\n'.join(ls_debug)
		mylib1.writeStr2File('nocom7.txt',st1)
	
	
	#replace each var with '=====var======'
	#join into a string,
	#split using '=====var====='
	for i in range(len(lss)):
		#if the line is not a comment
		if lss[i][0]!='\\':
			lss[i]='=====var====='
	
	st2='\n'.join(lss)
	lss=st2.split('=====var=====\n')
	lss.pop(0) # the above split generates an extra item at start
	
	if debug:
		fname='nocom8.txt'
		f=open(fname,'wb')
		k=0
		for i in range(len(blocklst)):
			for j in range(len(blocklst[i])):
				f.write(blocklst[i][j]+'\n')
				f.write(lss[k])
				k=k+1
		
		f.close()
	
	#map the structure of the comments -(this is 'lss' now) to 
	#the structure of blocklst - blocklst is a nested list
	#make lss a similar nested list
	k=0
	lst=[]
	for i in range(len(blocklst)):
		lst.append([])
		for j in range(len(blocklst[i])):
			lst[i].append(lss[k])
			k=k+1
	
	
	if debug:
		fname='nocom9.txt'
		f=open(fname,'wb')
		k=0
		for i in range(len(blocklst)):
			for j in range(len(blocklst[i])):
				f.write(blocklst[i][j]+'\n')
				f.write(lst[i][j])
				k=k+1
		
		f.close()
			
	
	
	#break up multiple line comment so that it is a list
	for i in range(len(lst)):
		for j in range(len(lst[i])):
			lst[i][j]=lst[i][j].splitlines()
			# remove the '\'
			for k in range(len(lst[i][j])):
				lst[i][j][k]=lst[i][j][k][1:]
	commlst=lst
	
	
	#copied with minor modifications from readidd2_2.py -- which has been erased ha !
	c=lst
	lss=[]
	for i in range(0,len(c)):
		ls=[]
		for j in range(0,len(c[i])):
			it=c[i][j]
			dt={}
			for el in it:
				if len(el.split())==0:
					break
				dt[el.split()[0]]=[]
			
			for el in it:
				if len(el.split())==0:
					break
				dt[el.split()[0]].append(string.join(el.split()[1:]))
				                
			
			ls.append(dt)
		
		lss.append(ls)
	commdct=lss
	
	return blocklst,commlst,commdct