changed manual input/output close to class method
This commit is contained in:
parent
28a7c4c727
commit
c7837e1f66
|
@ -115,7 +115,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -92,7 +92,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -129,6 +129,6 @@ for file in files:
|
|||
# ------------------------------------------ output result ---------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
file['output'].close() # close output ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -149,6 +149,6 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
file['output'].close() # close output ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -124,6 +124,6 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
file['output'].close() # close output ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -88,7 +88,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -94,7 +94,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -172,6 +172,6 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
file['output'].close() # close output ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -104,7 +104,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -199,6 +199,6 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
file['output'].close() # close output ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -148,7 +148,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -120,7 +120,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -100,7 +100,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -111,7 +111,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -168,7 +168,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -93,7 +93,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -375,7 +375,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -80,7 +80,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -138,7 +138,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -133,7 +133,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
file['output'].close() # close output ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
os.rename(file['name']+'_tmp',\
|
||||
os.path.join(os.path.dirname(file['name']),prefix+os.path.basename(file['name'])))
|
||||
|
|
|
@ -72,7 +72,7 @@ for file in files:
|
|||
skip = int(file['input'].readline().split()[0])
|
||||
for i in xrange(skip): headers = file['input'].readline().split()
|
||||
data = np.loadtxt(file['input'],usecols=np.array(options.data+((options.weight,) if options.weight != None else ()))-1)
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
|
||||
for i in (0,1): # check data range for x and y
|
||||
if (range[i] == 0.0).all(): range[i] = [data[:,i].min(),data[:,i].max()]
|
||||
|
@ -113,7 +113,7 @@ for file in files:
|
|||
file['output'].write('1\thead\n')
|
||||
file['output'].write('bin_%s\tbin_%s\tz\n'%(headers[options.data[0]-1],headers[options.data[1]-1]))
|
||||
np.savetxt(file['output'],result)
|
||||
file['output'].close() # close output ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',\
|
||||
os.path.join(os.path.dirname(file['name']),prefix+os.path.basename(file['name'])))
|
||||
|
|
|
@ -125,7 +125,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
file['output'].close() # close output ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
os.rename(file['name']+'_tmp',\
|
||||
os.path.join(os.path.dirname(file['name']),prefix+os.path.basename(file['name'])))
|
||||
|
|
|
@ -98,7 +98,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -48,7 +48,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -95,7 +95,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -148,7 +148,7 @@ for file in files:
|
|||
undeformedCentroids[x,y,z] = numpy.array(map(float,table.data[columnUndeformed:columnUndeformed+3]),'d')
|
||||
defgrad[x,y,z] = numpy.array(map(float,table.data[columnDefgrad:columnDefgrad+9]),'d').reshape(3,3)
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
|
||||
|
||||
# ------------------------------------------ process value field ----------------------------
|
||||
|
|
|
@ -166,4 +166,4 @@ myColormap = Colormap(leftColor,rightColor)
|
|||
for file in files:
|
||||
outColormap = myColormap.export(file['name'],file['outtype'],options.steps,list(options.trim))
|
||||
file['output'].write(outColormap)
|
||||
file['output'].close()
|
||||
table.output_close()
|
||||
|
|
|
@ -90,6 +90,6 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
file['output'].close() # close output ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -110,7 +110,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush()
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -103,7 +103,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -103,7 +103,7 @@ for file in files:
|
|||
# ------------------------------------------ output result -----------------------------------------
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table (works for stdin)
|
||||
file['output'].close() # close output ASCII table (works for stdout)
|
||||
table.input_close() # close input ASCII table (works for stdin)
|
||||
table.output_close() # close output ASCII table (works for stdout)
|
||||
if file['name'] != 'STDIN':
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -59,4 +59,4 @@ for file in files:
|
|||
outputAlive and table.output_flush()
|
||||
|
||||
if file['name'] != 'STDIN':
|
||||
file['input'].close()
|
||||
table.input_close()
|
||||
|
|
|
@ -98,7 +98,7 @@ for file in files:
|
|||
|
||||
table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
if file['name'] != 'STDIN':
|
||||
file['output'].close() # close output ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -188,6 +188,6 @@ for file in files:
|
|||
# ------------------------------------------ close file handles ---------------------------------------
|
||||
|
||||
for file in files:
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
if file['name'] != 'STDIN':
|
||||
file['output'].close() # close output ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
|
|
|
@ -119,7 +119,7 @@ for file in files:
|
|||
|
||||
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
if file['name'] != 'STDIN':
|
||||
file['output'].close # close output ASCII table
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -127,7 +127,7 @@ for file in files:
|
|||
elif datatype == 'scalar':
|
||||
array[datatype][label].InsertNextValue(float(theData[0]))
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
|
||||
# ------------------------------------------ add data ---------------------------------------
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ for file in files:
|
|||
elif datatype == 'scalar':
|
||||
array[datatype][label].InsertNextValue(float(theData[0]))
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
|
||||
# ------------------------------------------ add data ---------------------------------------
|
||||
|
||||
|
|
|
@ -112,4 +112,4 @@ for file in files:
|
|||
writer.SetInputData(Polydata)
|
||||
writer.Write()
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
|
|
|
@ -134,4 +134,4 @@ for file in files:
|
|||
writer.SetInputData(uGrid)
|
||||
writer.Write()
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
|
|
|
@ -223,6 +223,6 @@ for file in files:
|
|||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
file['input'].close()
|
||||
file['output'].close()
|
||||
table.input_close()
|
||||
table.output_close()
|
||||
os.rename(file['name']+'_tmp',file['name'])
|
||||
|
|
|
@ -217,6 +217,6 @@ for file in files:
|
|||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
file['input'].close()
|
||||
file['output'].close()
|
||||
table.input_close()
|
||||
table.output_close()
|
||||
os.rename(file['name']+'_tmp',file['name'])
|
||||
|
|
|
@ -208,7 +208,7 @@ for file in files:
|
|||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
file['output'].close()
|
||||
table.output_close()
|
||||
os.rename(file['name']+'_tmp',os.path.splitext(file['name'])[0] + \
|
||||
{True: '_material.config',
|
||||
False:'.geom'}[options.config])
|
||||
|
|
|
@ -284,4 +284,4 @@ for file in files:
|
|||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
file['input'].close()
|
||||
table.input_close()
|
||||
|
|
|
@ -192,4 +192,4 @@ else:
|
|||
|
||||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
file['output'].close()
|
||||
table.output_close()
|
||||
|
|
|
@ -143,7 +143,7 @@ for file in files:
|
|||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
file['output'].close()
|
||||
table.output_close()
|
||||
os.rename(file['name']+'_tmp',os.path.splitext(file['name'])[0] + \
|
||||
{True: '_material.config',
|
||||
False:'.geom'}[options.config])
|
||||
|
|
|
@ -266,8 +266,8 @@ for file in files:
|
|||
#--- output finalization --------------------------------------------------------------------------
|
||||
|
||||
if file['name'] != 'STDIN':
|
||||
file['input'].close()
|
||||
file['output'].close()
|
||||
table.input_close()
|
||||
table.output_close()
|
||||
os.rename(file['name']+'_tmp',os.path.splitext(file['name'])[0] + \
|
||||
{True: '_material.config',
|
||||
False:'.geom'}[options.config])
|
||||
|
|
|
@ -1,31 +1,14 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 no BOM -*-
|
||||
|
||||
import os,sys,string,re,math,numpy
|
||||
import os,sys,string,re,math
|
||||
import numpy as np
|
||||
from optparse import OptionParser
|
||||
import damask
|
||||
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
||||
|
||||
scriptID = '$Id$'
|
||||
scriptName = scriptID.split()[1]
|
||||
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
class extendedOption(Option):
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
||||
# taken from online tutorial http://docs.python.org/library/optparse.html
|
||||
|
||||
ACTIONS = Option.ACTIONS + ("extend",)
|
||||
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
||||
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
||||
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
||||
|
||||
def take_action(self, action, dest, opt, value, values, parser):
|
||||
if action == "extend":
|
||||
lvalue = value.split(",")
|
||||
values.ensure_value(dest, []).extend(lvalue)
|
||||
else:
|
||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
# MAIN
|
||||
|
@ -47,29 +30,20 @@ mappings = {
|
|||
'microstructures': lambda x: int(x),
|
||||
}
|
||||
|
||||
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """
|
||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||
compress geometry files with ranges "a to b" and/or multiples "n of x".
|
||||
""" + string.replace(scriptID,'\n','\\n')
|
||||
)
|
||||
""", version = scriptID)
|
||||
|
||||
(options, filenames) = parser.parse_args()
|
||||
|
||||
#--- setup file handles ---------------------------------------------------------------------------
|
||||
# ------------------------------------------ setup file handles ---------------------------------------
|
||||
files = []
|
||||
if filenames == []:
|
||||
files.append({'name':'STDIN',
|
||||
'input':sys.stdin,
|
||||
'output':sys.stdout,
|
||||
'croak':sys.stderr,
|
||||
})
|
||||
files.append({'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout, 'croak':sys.stderr})
|
||||
else:
|
||||
for name in filenames:
|
||||
if os.path.exists(name):
|
||||
files.append({'name':name,
|
||||
'input':open(name),
|
||||
'output':open(name+'_tmp','w'),
|
||||
'croak':sys.stdout,
|
||||
})
|
||||
files.append({'name':name, 'input':open(name), 'output':open(name+'_tmp','w'), 'croak':sys.stderr})
|
||||
|
||||
#--- loop over input files ------------------------------------------------------------------------
|
||||
for file in files:
|
||||
|
@ -82,9 +56,9 @@ for file in files:
|
|||
|
||||
#--- interpret header ----------------------------------------------------------------------------
|
||||
info = {
|
||||
'grid': numpy.zeros(3,'i'),
|
||||
'size': numpy.zeros(3,'d'),
|
||||
'origin': numpy.zeros(3,'d'),
|
||||
'grid': np.zeros(3,'i'),
|
||||
'size': np.zeros(3,'d'),
|
||||
'origin': np.zeros(3,'d'),
|
||||
'homogenization': 0,
|
||||
'microstructures': 0,
|
||||
}
|
||||
|
@ -111,10 +85,10 @@ for file in files:
|
|||
'homogenization: %i\n'%info['homogenization'] + \
|
||||
'microstructures: %i\n'%info['microstructures'])
|
||||
|
||||
if numpy.any(info['grid'] < 1):
|
||||
if np.any(info['grid'] < 1):
|
||||
file['croak'].write('invalid grid a b c.\n')
|
||||
continue
|
||||
if numpy.any(info['size'] <= 0.0):
|
||||
if np.any(info['size'] <= 0.0):
|
||||
file['croak'].write('invalid size x y z.\n')
|
||||
continue
|
||||
|
||||
|
@ -179,11 +153,10 @@ for file in files:
|
|||
|
||||
|
||||
# ------------------------------------------ output result ---------------------------------------
|
||||
|
||||
outputAlive and theTable.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
file['input'].close() # close input ASCII table
|
||||
file['output'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
table.output_close() # close input ASCII table
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -219,7 +219,7 @@ for file in files:
|
|||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
file['input'].close()
|
||||
file['output'].close()
|
||||
table.input_close()
|
||||
table.output_close()
|
||||
os.rename(file['name']+'_tmp',file['name'])
|
||||
|
||||
|
|
|
@ -188,6 +188,6 @@ for file in files:
|
|||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
file['input'].close()
|
||||
file['output'].close()
|
||||
table.input_close()
|
||||
table.output_close()
|
||||
os.rename(file['name']+'_tmp',file['name'])
|
||||
|
|
|
@ -162,6 +162,6 @@ for file in files:
|
|||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
file['input'].close() # close input ASCII table
|
||||
file['output'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
table.output_close() # close input ASCII table
|
||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||
|
|
|
@ -181,7 +181,7 @@ for file in files:
|
|||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
file['input'].close()
|
||||
file['output'].close()
|
||||
table.input_close()
|
||||
table.output_close()
|
||||
os.rename(file['name']+'_tmp',file['name'])
|
||||
|
||||
|
|
|
@ -189,6 +189,6 @@ for file in files:
|
|||
|
||||
outputDead or theTable.output_flush() # just in case of buffered ASCII table
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
if file['name'] != 'STDIN':
|
||||
file['output'].close() # close output ASCII table
|
||||
table.output_close() # close output ASCII table
|
|
@ -177,6 +177,6 @@ for file in files:
|
|||
theTable.data_writeArray()
|
||||
theTable.output_flush()
|
||||
|
||||
file['input'].close() # close input ASCII table
|
||||
table.input_close() # close input ASCII table
|
||||
if file['name'] != 'STDIN':
|
||||
file['output'].close() # close output ASCII table
|
||||
table.output_close() # close output ASCII table
|
||||
|
|
Loading…
Reference in New Issue