-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakeOutputLog.py
More file actions
executable file
·77 lines (66 loc) · 2.59 KB
/
MakeOutputLog.py
File metadata and controls
executable file
·77 lines (66 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
#
# Make's OutputLog file from enzo files in the directory tree.
#
import fnmatch
import os
import shutil
import glob
import sys
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-H","--Hierarchy",dest="hierarchy",action="store_true",default=False,
help="takes list of hierarchy files")
parser.add_option("-b","--backup",dest="backup",action="store_true",default=False,
help="Backup old outputlog in OldOutputLog")
parser.add_option("-o","--output",dest="output",action="store",default="OutputLog",
help="Name of output log file")
(options,args)=parser.parse_args()
OutputLog = options.output
if glob.glob(OutputLog) != [] and not options.backup:
print("OutputLog written. Please remove existing file before running.")
sys.exit(0)
if glob.glob(OutputLog) != [] and options.backup:
n_backup = len(glob.glob('*%s*'%(OutputLog)))
shutil.move(OutputLog,'%s.backup%s'%(OutputLog,n_backup))
if 1:
#Hunt for *.hierarchy files (easier to search than parameter files)
matches = []
output_list=[]
if len(args) == 0:
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, '*.hierarchy'):
print("filename",filename)
matches.append(os.path.join(root, filename.split('.')[0]))
else:
if options.hierarchy:
for hierarchy in args:
matches.append(hierarchy.split('.')[0])
print(hierarchy.split('.'))
for PF in matches:
inptr = open(PF,'r')
nSuccess = 0
for line in inptr:
if line.startswith('InitialCycleNumber'):
nSuccess += 1
cycle = int(line.split("=")[1].strip())
if line.startswith('InitialTime'):
nSuccess += 1
time = float(line.split("=")[1].strip())
if line.startswith('CurrentTimeIdentifier'):
nSuccess += 1
EpochTime = float(line.split("=")[1].strip())
print(EpochTime)
if nSuccess == 3:
#fptr.write( "DATASET WRITTEN %s %8d %18.16e\n"%(PF, cycle, time))
output_list.append([PF,cycle,time,EpochTime])
break
inptr.close()
if nSuccess != 3:
print("Error parsing", PF)
#write output sorted by sim time
fptr= open(OutputLog,'w')
for p in sorted(output_list, key=lambda item:item[2]):
fptr.write( "DATASET WRITTEN %s %8d %18.16e %f\n"%(p[0], p[1],p[2],p[3]))
fptr.close()
#end