def save( self, aFileName = None ): if aFileName is not None: self.setFileName( aFileName ) # open the file aOutputFile = open(self.theFileName,'w') # writes header aOutputFile.write(self.getHeaderString()) aOutputFile.close() TableIO.writeArray( self.theFileName, self.theData, 1 )
def save(self, aFileName=None): if aFileName is not None: self.setFileName(aFileName) # open the file aOutputFile = open(self.theFileName, 'w') # writes header aOutputFile.write(self.getHeaderString()) aOutputFile.close() TableIO.writeArray(self.theFileName, self.theData, 1)
def load( self, aFileName = None ): if aFileName is not None: self.setFileName( aFileName ) def readOneLineData( aInputFile, aKey ): aBuff = aInputFile.readline() if aBuff.find( aKey ) != 0: raise "Error: %s is not ECD format. '%s' line can't be found." %aKey return aBuff[len(aKey):].strip() if( len(self.theFileName) == 0): raise "Error: empty filename." # open the file aInputFile = open(self.theFileName,'r') # read header #FIXME: do not depend on the order of header elements # -------------------------------------------------------- # [1] read DATA: # -------------------------------------------------------- self.setDataName( readOneLineData(aInputFile,'#DATA:') ) # -------------------------------------------------------- # [2] read SIZE: # -------------------------------------------------------- # ignore SIZE: readOneLineData(aInputFile,'#SIZE:') # -------------------------------------------------------- # [3] read LABEL: # -------------------------------------------------------- self.setLabel( readOneLineData(aInputFile,'#LABEL:') ) # -------------------------------------------------------- # [4] read NOTE: # -------------------------------------------------------- self.setNote( readOneLineData(aInputFile,'#NOTE:') ) # -------------------------------------------------------- # [5] read some lines before matrix data # -------------------------------------------------------- # read matrix while(1): # while 1 aBuff = aInputFile.readline() # if EOF is found, breaks this loop. if aBuff == '': break # if separator is found, breaks this loop. if aBuff.find( '#----------------------' ) == 0: break # end of while 1 # ---------------------------------------------------------- # [6] reads matrix data # ---------------------------------------------------------- #close the file aInputFile.close() self.setData( TableIO.readTableAsArray( self.theFileName, '#' ) )
def load(self, aFileName=None): if aFileName is not None: self.setFileName(aFileName) def readOneLineData(aInputFile, aKey): aBuff = aInputFile.readline() if aBuff.find(aKey) != 0: raise "Error: %s is not ECD format. '%s' line can't be found." % aKey return aBuff[len(aKey):].strip() if (len(self.theFileName) == 0): raise "Error: empty filename." # open the file aInputFile = open(self.theFileName, 'r') # read header #FIXME: do not depend on the order of header elements # -------------------------------------------------------- # [1] read DATA: # -------------------------------------------------------- self.setDataName(readOneLineData(aInputFile, '#DATA:')) # -------------------------------------------------------- # [2] read SIZE: # -------------------------------------------------------- # ignore SIZE: readOneLineData(aInputFile, '#SIZE:') # -------------------------------------------------------- # [3] read LABEL: # -------------------------------------------------------- self.setLabel(readOneLineData(aInputFile, '#LABEL:')) # -------------------------------------------------------- # [4] read NOTE: # -------------------------------------------------------- self.setNote(readOneLineData(aInputFile, '#NOTE:')) # -------------------------------------------------------- # [5] read some lines before matrix data # -------------------------------------------------------- # read matrix while (1): # while 1 aBuff = aInputFile.readline() # if EOF is found, breaks this loop. if aBuff == '': break # if separator is found, breaks this loop. if aBuff.find('#----------------------') == 0: break # end of while 1 # ---------------------------------------------------------- # [6] reads matrix data # ---------------------------------------------------------- #close the file aInputFile.close() self.setData(TableIO.readTableAsArray(self.theFileName, '#'))