introduced delimiter option (default = tab) for ascii table output, use space for geometry files

This commit is contained in:
Martin Diehl 2013-12-17 08:16:29 +00:00
parent 7b9d76cdcc
commit 2f1db8f69a
9 changed files with 15 additions and 17 deletions

View File

@ -229,21 +229,21 @@ class ASCIItable():
return self.data.shape return self.data.shape
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def data_write(self): def data_write(self, delimiter='\t'):
if len(self.data) == 0: return if len(self.data) == 0: return
if isinstance(self.data[0],list): if isinstance(self.data[0],list):
return self.output_write(['\t'.join(map(str,items)) for items in self.data]) return self.output_write([delimiter.join(map(str,items)) for items in self.data])
else: else:
return self.output_write('\t'.join(map(str,self.data))) return self.output_write(delimiter.join(map(str,self.data)))
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def data_writeArray(self,format='%g'): def data_writeArray(self,format='%g',delimiter = '\t'):
import numpy import numpy
''' '''
write whole numpy array data write whole numpy array data
''' '''
return numpy.savetxt(self.__IO__['out'], self.data, fmt=format, delimiter='\t') return numpy.savetxt(self.__IO__['out'], self.data, fmt=format, delimiter=delimiter)
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def data_append(self, def data_append(self,

View File

@ -212,7 +212,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------ # --- write microstructure information ------------------------------------------------------------
formatwidth = int(math.floor(math.log10(microstructure_cropped.max())+1)) formatwidth = int(math.floor(math.log10(microstructure_cropped.max())+1))
theTable.data = microstructure_cropped.reshape((newInfo['grid'][0],newInfo['grid'][1]*newInfo['grid'][2]),order='F').transpose() theTable.data = microstructure_cropped.reshape((newInfo['grid'][0],newInfo['grid'][1]*newInfo['grid'][2]),order='F').transpose()
theTable.data_writeArray('%%%ii'%(formatwidth)) theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization -------------------------------------------------------------------------- #--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN': if file['name'] != 'STDIN':

View File

@ -247,7 +247,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------ # --- write microstructure information ------------------------------------------------------------
formatwidth = 1+int(math.log10(newInfo['microstructures'])) formatwidth = 1+int(math.log10(newInfo['microstructures']))
theTable.data = indices.reshape(info['grid'][1]*info['grid'][2],info['grid'][0]) theTable.data = indices.reshape(info['grid'][1]*info['grid'][2],info['grid'][0])
theTable.data_writeArray('%%%ii'%(formatwidth)) theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization -------------------------------------------------------------------------- #--- output finalization --------------------------------------------------------------------------

View File

@ -222,7 +222,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------ # --- write microstructure information ------------------------------------------------------------
formatwidth = int(math.floor(math.log10(microstructure.max())+1)) formatwidth = int(math.floor(math.log10(microstructure.max())+1))
theTable.data = microstructure[0:info['grid'][0],0:info['grid'][1],0:info['grid'][2]].reshape(numpy.prod(info['grid']),order='F').transpose() theTable.data = microstructure[0:info['grid'][0],0:info['grid'][1],0:info['grid'][2]].reshape(numpy.prod(info['grid']),order='F').transpose()
theTable.data_writeArray('%%%ii'%(formatwidth)) theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization -------------------------------------------------------------------------- #--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN': if file['name'] != 'STDIN':

View File

@ -132,7 +132,7 @@ for file in files:
theTable.head_write() theTable.head_write()
theTable.output_flush() theTable.output_flush()
# --- write packed microstructure information ------------------------------------------------------------ # --- write packed microstructure information -----------------------------------------------------
type = '' type = ''
former = -1 former = -1
start = -1 start = -1
@ -161,8 +161,7 @@ for file in files:
'to': ['%i to %i'%(former-reps+1,former)], 'to': ['%i to %i'%(former-reps+1,former)],
'of': ['%i of %i'%(reps,former)], 'of': ['%i of %i'%(reps,former)],
}[type] }[type]
theTable.data_write() theTable.data_write(delimiter=' ')
# file['output'].write(output)
type = '.' type = '.'
start = current start = current
reps = 1 reps = 1
@ -173,9 +172,8 @@ for file in files:
'to': ['%i to %i'%(former-reps+1,former)], 'to': ['%i to %i'%(former-reps+1,former)],
'of': ['%i of %i'%(reps,former)], 'of': ['%i of %i'%(reps,former)],
}[type] }[type]
theTable.data_write() theTable.data_write(delimiter=' ')
theTable.output_flush() theTable.output_flush()
# file['output'].write(output+'\n')
#--- output finalization -------------------------------------------------------------------------- #--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN': if file['name'] != 'STDIN':

View File

@ -204,7 +204,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------ # --- write microstructure information ------------------------------------------------------------
formatwidth = int(math.floor(math.log10(microstructure.max())+1)) formatwidth = int(math.floor(math.log10(microstructure.max())+1))
theTable.data = microstructure.reshape((newInfo['grid'][0],newInfo['grid'][1]*newInfo['grid'][2]),order='F').transpose() theTable.data = microstructure.reshape((newInfo['grid'][0],newInfo['grid'][1]*newInfo['grid'][2]),order='F').transpose()
theTable.data_writeArray('%%%ii'%(formatwidth)) theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization -------------------------------------------------------------------------- #--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN': if file['name'] != 'STDIN':

View File

@ -187,7 +187,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------ # --- write microstructure information ------------------------------------------------------------
formatwidth = int(math.floor(math.log10(substituted.max())+1)) formatwidth = int(math.floor(math.log10(substituted.max())+1))
theTable.data = substituted.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose() theTable.data = substituted.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose()
theTable.data_writeArray('%%%ii'%(formatwidth)) theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization -------------------------------------------------------------------------- #--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN': if file['name'] != 'STDIN':

View File

@ -159,7 +159,7 @@ for file in files:
theTable.data = microstructure theTable.data = microstructure
else: else:
theTable.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose() theTable.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose()
theTable.data_writeArray('%%%ii'%(formatwidth)) theTable.data_writeArray('%%%ii'%(formatwidth),delimiter = ' ')
#--- output finalization -------------------------------------------------------------------------- #--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN': if file['name'] != 'STDIN':

View File

@ -177,7 +177,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------ # --- write microstructure information ------------------------------------------------------------
formatwidth = int(math.floor(math.log10(microstructure.max())+1)) formatwidth = int(math.floor(math.log10(microstructure.max())+1))
theTable.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose() theTable.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose()
theTable.data_writeArray('%%%ii'%(formatwidth)) theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization -------------------------------------------------------------------------- #--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN': if file['name'] != 'STDIN':