shortened code for opening input file list

This commit is contained in:
Philip Eisenlohr 2015-03-06 17:04:44 +00:00
parent 37e40fdf79
commit 639b030c65
1 changed files with 10 additions and 20 deletions

View File

@ -74,28 +74,18 @@ toRadians = np.pi/180.0 if options.degrees else 1.0
pole = np.array(options.pole) pole = np.array(options.pole)
pole /= np.linalg.norm(pole) pole /= np.linalg.norm(pole)
#--- setup file handles -------------------------------------------------------------------------- # --- loop over input files -------------------------------------------------------------------------
files = []
if filenames == []: if filenames == []:
files.append({'name':'STDIN', filenames = ['STDIN']
'input':sys.stdin,
'output':sys.stdout,
'croak':sys.stderr,
})
else:
for name in filenames:
if os.path.exists(name):
files.append({'name':name,
'croak':sys.stdout,
})
#--- loop over input files ------------------------------------------------------------------------ for name in filenames:
for file in files: if name == 'STDIN':
if file['name'] != 'STDIN': file = {'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout, 'croak':sys.stderr}
file['input'] = open(file['name']) file['croak'].write('\033[1m'+scriptName+'\033[0m\n')
file['output'] = open(file['name']+'_tmp','w') else:
if not os.path.exists(name): continue
file['croak'].write('\033[1m' + scriptName + '\033[0m' + (': '+file['name'] if file['name'] != 'STDIN' else '') + '\n') file = {'name':name, 'input':open(name), 'output':open(name+'_tmp','w'), 'croak':sys.stderr}
file['croak'].write('\033[1m'+scriptName+'\033[0m: '+file['name']+'\n')
table = damask.ASCIItable(file['input'],file['output'],buffered = False) # make unbuffered ASCII_table table = damask.ASCIItable(file['input'],file['output'],buffered = False) # make unbuffered ASCII_table
table.head_read() # read ASCII header info table.head_read() # read ASCII header info