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
# ------------------------------------------------------------------
def data_write(self):
def data_write(self, delimiter='\t'):
if len(self.data) == 0: return
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:
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
'''
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,

View File

@ -212,7 +212,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------
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_writeArray('%%%ii'%(formatwidth))
theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN':

View File

@ -247,7 +247,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------
formatwidth = 1+int(math.log10(newInfo['microstructures']))
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 --------------------------------------------------------------------------

View File

@ -222,7 +222,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------
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_writeArray('%%%ii'%(formatwidth))
theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN':

View File

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

View File

@ -204,7 +204,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------
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_writeArray('%%%ii'%(formatwidth))
theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN':

View File

@ -187,7 +187,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------
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_writeArray('%%%ii'%(formatwidth))
theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN':

View File

@ -159,7 +159,7 @@ for file in files:
theTable.data = microstructure
else:
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 --------------------------------------------------------------------------
if file['name'] != 'STDIN':

View File

@ -177,7 +177,7 @@ for file in files:
# --- write microstructure information ------------------------------------------------------------
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_writeArray('%%%ii'%(formatwidth))
theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN':