Ejemplo n.º 1
0
	def setElements(self, els):
		'''Set the list self.elements, and the link e.container'''
		self.elements=els
		for e in self.elements:
			e.container=self
		if not os.environ.get("MIEN_NO_VERIFY_XML"):
			ns=[e.name() for e in self.elements]
			bnc=[notinname.search(n) for n in ns]
			if any(bnc):
				self.report('warning: fixing illegal names')
				ind=nonzero1d(bnc)
				for i in ind:
					on=ns[i]
					nn=notinname.sub('_', on)
					ns[i]=nn
					self.elements[i].attributes['Name']=nn
					self.elements[i].update_refs()				
			us=set(ns)
			if len(us)==len(ns):
				return
			self.report('warning: non unique names')
			sibs=[]
			for i, n in enumerate(ns[:]):
				if n in sibs:
					nn=uniqueName(n, sibs)
					self.elements[i].attributes['Name']=nn
					self.elements[i].update_refs()
					sibs.append(nn)
				else:	
					sibs.append(n)
Ejemplo n.º 2
0
def writeMDElement(f, path, data, header):
	h=repr(header)
	if data==None or type(data)!=ArrayType or len(data.shape)==0 or not any(data.shape):
		#print type(data)
		dlen=0
	else:
		dat=data
		dti=dat.dtype.str
		if len(dti)!=3:
			dti="{"+dti[0]+dat.dtype.char
		sh=dat.shape
		dat=ravel(dat).tostring()
		dlen=len(dat)
	cat=struct.pack("<IIQ", len(path), len(h), dlen)
	f.write(cat)
	f.write(str(path))
	f.write(h)
	if not dlen:
		return
	pc="<3sI"+"Q"*len(sh)
	pc=[pc, dti, len(sh)]
	pc.extend(list(sh))
	dh=apply(struct.pack, pc)
	f.write(dh)		
	f.write(dat)