Skip to content

Instantly share code, notes, and snippets.

@mgmarino
Created February 16, 2012 14:22
Show Gist options
  • Select an option

  • Save mgmarino/1845176 to your computer and use it in GitHub Desktop.

Select an option

Save mgmarino/1845176 to your computer and use it in GitHub Desktop.
Split Geant4 VRML files
import sys
import re
def split_g4_vrml_file(afile):
one_string = open(afile).read()
split_string = one_string.split('#')
file_output_list = {}
camera = ""
temp = re.compile("---------- (.*)")
obj_name = re.compile("(.*): (.*)\..*")
for line in split_string:
match_it = temp.match(line)
if not match_it: continue
output = match_it.group(1)
if output == "CAMERA":
camera = "#" + line
continue
if camera == "":
print "ERROR - Camera", output
break
# Now get the name of the object
match_it = obj_name.match(output)
if not match_it:
print "ERROR - Name", output
break
file_output_list[match_it.group(2) + ".wrl"] = \
camera + "#" + line
return file_output_list
if __name__ == '__main__':
out_list = split_g4_vrml_file(sys.argv[1])
for file_name, content in out_list.items():
open(file_name, "w").write(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment