Created
February 16, 2012 14:22
-
-
Save mgmarino/1845176 to your computer and use it in GitHub Desktop.
Split Geant4 VRML files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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