EGS Brachy
An egs++ user code for rapid brachytherapy calculations
Loading...
Searching...
No Matches
gen_media.py
Go to the documentation of this file.
1import os
2
3root = os.path.join("..", "lib")
4abs_root = os.path.abspath(root)
5media_file = os.path.join(abs_root, "media", "material.dat")
6muen_dir = os.path.join(abs_root, "muen")
7
9
10 data = open(media_file, "r")
11
12 media = []
13 cur_media = []
14 for line in data:
15 line = line.strip()
16 if not line or line.startswith("#"):
17 continue
18
19 if line.lower().startswith("medium") and cur_media:
20 name = cur_media.pop(0).split("=")[1].strip()
21 media.append("<dt>%s</dt><dd>%s</dd>" % (name, "<br/>".join(cur_media)))
22 cur_media = []
23
24 cur_media.append(" "+line)
25
26 if cur_media:
27 name = cur_media.pop(0).split("=")[1].strip()
28 media.append("<dt>%s</dt><dd>%s</dd>" % (name, "<br/>".join(cur_media)))
29
30 return "<dl>%s</dl>" % "\n".join(sorted(media))
31
32
34
35 files = []
36 doc = ""
37 for f in os.listdir(muen_dir):
38 if not f.endswith(".muendat"):
39 continue
40
41
42 data = open(os.path.join(muen_dir, f), "r").read().split("\n")
43
44 muens = []
45 idx = 0
46 while idx < len(data):
47 line = data[idx]
48 if line.lower().startswith("muen values for medium"):
49 muen = line.split("=")[1].strip()
50 muens.append("<dt>%s</dt><dd>%s<br/>%s</dd>" % (muen, data[idx+1], data[idx+2]))
51 idx += 3
52 else:
53 idx += 1
54
55 doc += "\subsection %s %s\n" %(f.replace(".",""), f)
56 doc += "**File Location:** %s\n" % (os.path.relpath(os.path.join(muen_dir, f)))
57 doc += "<dl>%s</dl>" % "\n".join(sorted(muens))
58
59
60 return doc
61
62
63
64def gen_docs(fname):
65
66 params = {
67 "materials": get_pegsless_materials(),
68 "muen": get_muen()
69 }
70
71 docs = """@anchor egs_brachy_media_lib
72
73[TOC]
74
75egs_brachy Media & Muen Data
76============================
77
78
79\section pegsless Pegsless run materials
80
81The current list of media available for pegsless runs is as follows:
82
83{materials}
84
85\section materials Materials with Muen data
86
87
88The current list of media with muen data available for scoring dose with the
89tracklength estimator is as follows:
90
91{muen}
92
93""".format(**params)
94
95
96 open(fname, "w").write(docs)
97
98if __name__ == "__main__":
99 outfile = "media.md"
100 gen_docs(outfile)
string join(const vector< string > &v, string delim)
Definition ginfo.cpp:56
get_pegsless_materials()
Definition gen_media.py:8