def splitZA(fIn, l, yi, workDir, format): ZA = int(l[:6]) if (verbose != 0): print 'splitting ZA %5d' % ZA ZA_ = ZA target = endlZA.endlZA(ZA, yi, workDir=workDir) while (ZA == ZA_): l, data = getData(fIn, l, ZA) yo = int(data[0][9:12]) C = int(data[1][:2]) I = int(data[1][2:5]) S = int(data[1][5:8]) tmpFile = os.path.join(outDir, 'yo%2.2dc%2.2di%3.3ds%3.3d' % (yo, C, I, S)) fTmp = open(tmpFile, 'w') fTmp.write(''.join(data)) fTmp.close() endlData = endlFile.endlFile(0, os.path.basename(tmpFile), tmpFile, ZA, yi) endlData.read() file = target.findFile(yo=yo, C=C, I=I, S=S) if (file is None): file = target.addFile(yo=yo, C=C, I=I, S=S, printWarnings=False) if (format is not None): endlData[0].setFormat(format) file.addEndlData(endlData[0]) os.remove(tmpFile) if (l == ''): break ZA_ = int(l[:6]) target.save() return (l)
def addZA(self, ZA, suffix=""): """Adds a new empty endlZA class to self and returns a reference to it. Also see readZA.""" sZA = endlmisc.strZASuffix(ZA, suffix) for z in self.zas: if (z.sZA == sZA): raise Exception( "\nError in endlProject.addZA: za = %s already present in this endlProject" % sZA) z = endlZA.endlZA(ZA, self.yi, database=None, workDir=self.workDir, suffix=suffix, readOnly=self.readOnly, bdflsFile=self.bdflsFile) self.zas.append(z) return z
def readZA(self, ZA, database=None, suffix=""): """Reads in ZA from database, creating a new endlZA in self. If database = None, the database from self is used. Also see addZA.""" sZA = endlmisc.strZASuffix(ZA, suffix) for z in self.zas: if (z.sZA == sZA): endlmisc.printWarning( "za = %s already present in this endlProject" % sZA) return z if (database == None): database = self.database z = endlZA.endlZA(ZA, self.yi, database=database, workDir=self.workDir, suffix=suffix, readOnly=self.readOnly, bdflsFile=self.bdflsFile) self.zas.append(z) return z