CombineParallelOutFiles Namespace Reference

Functions

def main ()
 

Function Documentation

◆ main()

def CombineParallelOutFiles.main ( )
21 def main():
22  # checks if the combined outfile already exists
23  out_file_name = sys.argv[1]
24 
25  #if os.path.isfile(out_file_name):
26  # raise Exception("file " + out_file_name + " already exists; remove first")
27 
28  # find the out files of all the cores
29  files = sorted([file for file in os.listdir(".") if file.startswith(out_file_name) and not file==out_file_name])
30 
31  print("Combining %d out files: " % len(files) + ", ".join(files))
32 
33  # For all files
34  particles=[]
35  header = ""
36  for file in files:
37  # Open the file and mold it into a list of lists of all the 'words' in the file
38  file0 = open(file)
39  file0 = file0.readlines()
40  # ignore empty files
41  if not file0:
42  continue
43  if not header:
44  header=file0[0]
45  file0.pop(0)
46  file0.pop()
47  particles.extend([line.split() for line in file0])
48  print("found %d particles (including duplicates)" % len(particles))
49 
50  # sort by id
51  particles = sorted(particles, key=operator.itemgetter(2))
52  # remove duplicates (same id)
53  id = -1
54  for i in range(len(particles) - 2, -1, -1):
55  # check if id and time stamp agrees
56  if particles[i][2]==particles[i+1][2]:
57  # remove it
58  particles.pop(i+1)
59  print("found %d particles (after removing duplicates)" % len(particles))
60 
61  # sort by time stamp (convert time to float, otherwise it sorts alphabetically)
62  for p in particles:
63  p[0] = float(p[0])
64  particles2 = sorted(particles, key=operator.itemgetter(0))
65  for p in particles:
66  p[0] = str(p[0])
67 
68  # Finally, write everything to the combined out file
69  out_file = open(out_file_name, 'w')
70  out_file.write("".join(header))
71  out_file.write("\n".join([" ".join(p) for p in particles2]))
72  print("written %s" % out_file_name)
73 
74 
def main()
Definition: CombineParallelOutFiles.py:21
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet print(const Packet &a)
Definition: GenericPacketMath.h:1166
str
Definition: compute_granudrum_aor.py:141

References Eigen::internal.print(), and compute_granudrum_aor.str.