21 You need to provide command line arguments:
22 - In case of restart files of the form myRestartFile.restart0, etc.:
23 ./CombineParallelRestartFiles.py myRestartFile.restart
24 - In case of restart files of the form myRestartFile.restart0.123456, etc:
25 ./CombineParallelRestartFiles.py myRestartFile.restart 123456
30 restart_file_base = sys.argv[1]
31 files = sorted([file
for file
in os.listdir(
".")
if file.startswith(restart_file_base)])
35 out_file_name_base = sys.argv[3]
36 if restart_file_base==out_file_name_base:
37 raise Exception(
"Name of out-file should not be same as in-file")
39 out_file_name_base =
"combined" + restart_file_base
40 out_file_name = out_file_name_base
45 restart_file_number = sys.argv[2]
46 files = sorted([file
for file
in files
if file.endswith(
"."+restart_file_number)])
47 out_file_name +=
"."+restart_file_number
50 out_file = open(out_file_name,
'w')
59 footer_written =
False
63 file0 = open(files[0])
64 file0 = file0.readlines()
67 while 'Particles ' not in file0[index_particles]:
68 if 'restartFile name ' in file0[index_particles]:
70 i = file0[index_particles].find(
" name ")
71 j = file0[index_particles].find(
" fileType ")
72 file0[index_particles] = file0[index_particles][:i+6] + out_file_name_base + file0[index_particles][j:]
74 if 'numberOfProcessors ' in file0[index_particles]:
75 i = file0[index_particles].find(
'numberOfProcessors ')
78 file0[index_particles] = file0[index_particles][:i] +
'\n'
81 header.append(file0[index_particles])
88 print (
"reading %s" % file)
89 file0 = file0.readlines()
90 file0_split = [line.split()
for line
in file0]
93 index_particles_end = index_particles +
int(file0_split[index_particles][1]) + 1
94 for i
in range(index_particles + 1, index_particles_end):
95 particles.append(file0[i])
97 id =
int(file0_split[i][2])
98 while id>=len(isParticle): isParticle.append(
False)
102 index_interactions_end = index_particles_end +
int(file0_split[index_particles_end][1]) + 1
103 for i
in range(index_particles_end + 1, index_interactions_end):
104 p =
int(file0_split[i][2])
105 q =
int(file0_split[i][3])
108 if (p<0
or (p<len(isParticle)
and isParticle[p]))
and (q<0
or (q<len(isParticle)
and isParticle[q])):
109 interactions.append(file0[i])
112 if not footer_written:
113 footer_written =
True
114 for i
in range(index_interactions_end, len(file0_split)):
115 footer.append(file0[i])
118 out_file.write(
"".join(header))
119 out_file.write(
"Particles " +
str(len(particles)) +
"\n")
120 out_file.write(
"".join(particles))
121 out_file.write(
"Interactions " +
str(len(interactions)) +
"\n")
122 out_file.write(
"".join(interactions))
123 out_file.write(
"".join(footer))
124 print(
"written %d particles, %d interactions to %s" % (len(particles), len(interactions), out_file.name))
def main()
Definition: CombineParallelRestartFiles.py:18
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet print(const Packet &a)
Definition: GenericPacketMath.h:1166
str
Definition: compute_granudrum_aor.py:141