spectral_geomPack is now formatting depending on necessary digits (via additional header information)
This commit is contained in:
parent
e75fc26942
commit
0cb983606f
|
@ -15,6 +15,8 @@ def writeKey(outType, begin, counter):
|
|||
c=str(begin)+'\n'
|
||||
file['output'].write(c)
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
class extendedOption(Option):
|
||||
# -----------------------------
|
||||
|
@ -51,7 +53,7 @@ parser.add_option('-p','--pack', dest='pack', action='store_true', \
|
|||
parser.add_option('-u','--unpack', dest='unpack', action='store_true', \
|
||||
help='unpack input file [%default]')
|
||||
parser.add_option('-l','--linelength', dest='lineLength',type='int', nargs=1, \
|
||||
help='length of line, 0 for auto (resolution[0]) [%default]')
|
||||
help='length of line, leave blank for auto (FPs in x direction)')
|
||||
|
||||
|
||||
parser.set_defaults(pack = False)
|
||||
|
@ -74,6 +76,7 @@ else:
|
|||
|
||||
# ------------------------------------------ loop over input files ---------------------------------------
|
||||
for file in files:
|
||||
digits=2
|
||||
counter = 1
|
||||
begin = -1
|
||||
outType = ''
|
||||
|
@ -86,6 +89,7 @@ for file in files:
|
|||
currentLine+=1
|
||||
if('head' in line): headNumber=int(words[0])+1
|
||||
if(currentLine<=headNumber):
|
||||
if('maxgraincount'==words[0].lower()): digits = 1+int(math.log10(int(words[1])))
|
||||
if(words[0].lower()=='resolution' and words[1].lower()=='a' and options.lineLength==0):
|
||||
options.lineLength = int(words[2].lower())
|
||||
file['output'].write(line)
|
||||
|
@ -98,7 +102,7 @@ for file in files:
|
|||
|
||||
for word in line.split():
|
||||
wordsWritten += 1
|
||||
file['output'].write(word+{True:'\n',False:' '}[wordsWritten%options.lineLength == 0]) # newline every options.linelength words
|
||||
file['output'].write(word.zfill(digits)+{True:'\n',False:' '}[wordsWritten%options.lineLength == 0]) # newline every options.linelength words
|
||||
|
||||
if options.pack: # packing the geometry file
|
||||
numbers=line.split()
|
||||
|
@ -109,7 +113,7 @@ for file in files:
|
|||
if current == last+1 and current==begin+counter:
|
||||
counter+=1
|
||||
outType = 'range'
|
||||
elif current == begin:
|
||||
elif current == begin and current == last:
|
||||
counter+=1
|
||||
outType = 'copy'
|
||||
else:
|
||||
|
@ -118,7 +122,11 @@ for file in files:
|
|||
outType= 'none'
|
||||
begin = current
|
||||
|
||||
|
||||
writeKey(outType, begin, counter) # just for packing (last line), outType not defined for unpacking
|
||||
|
||||
|
||||
file['output'].close()
|
||||
file['input'].close()
|
||||
os.rename(file['name']+'_tmp',file['name'])
|
||||
|
||||
|
|
Loading…
Reference in New Issue