-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacro.el
98 lines (89 loc) · 3.29 KB
/
macro.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;; Set some global variables
(setq resolution-msc_id "msc")
(setq resolution-filestem (format "testbeam_%s_wo_" resolution-msc_id))
(setq resolution-geometry-file "mac/geometry_testbeam.mac")
;; Execute the entire set of things
(defun resolution-execute-one(ladderres dof)
(interactive "nLadder Resolution: \nnDof: ")
(resolution-change-ladder-res ladderres)
(resolution-change-dof dof)
(resolution-copy-macro-files)
(resolution-run-all)
(let ((outputfile (format "%d_%d_%s.out" ladderres dof resolution-msc_id)))
(resolution-analyze outputfile)))
;; Adjust ladder resolution
(defun resolution-change-ladder-res(ladderres)
(interactive "nLadder Resolution: ")
(find-file resolution-geometry-file)
(beginning-of-buffer)
(if (re-search-forward "\\(ladderResolution \\)\\([0-9]+\\)" nil t)
(replace-match (format "\\1%d" ladderres)))
(save-buffer)
(kill-buffer))
;; Adjust degrees of freedom
(defun resolution-change-dof(dof)
(interactive "nDegrees of freedom: ")
(find-file resolution-geometry-file)
(beginning-of-buffer)
(if (re-search-forward "\\(SetFixedDof \\)\\([0-9]+\\)" nil t)
(replace-match (format "\\1%d" dof)))
(save-buffer)
(kill-buffer))
;; Transfer changes in first file to all files
(defun resolution-copy-macro-files()
(interactive)
(let ((num 2))
(while (<= num 10)
(let ((newfile (format "mac/%s%d.mac" resolution-filestem num)))
(copy-file (format "mac/%s0.mac" resolution-filestem) newfile t)
(find-file newfile)
(beginning-of-buffer)
(while (re-search-forward "\\(wo_\\|WithoutLayer \\)0" nil t)
(replace-match (format "\\1%d" num)))
(save-buffer)
(kill-buffer)
(setq num (1+ num))))))
;; Execute resolution program for all files
(defun resolution-run-all()
(interactive)
(let ((num 0))
(while (<= num 10)
(unless (= num 1)
(let ((macro (format "mac/%s%d.mac" resolution-filestem num)))
(shell-command (format "resolution %s&" macro))))
(setq num (1+ num)))))
;; Execute analysis program and store results in one output file
(defun resolution-analyze(outputname)
(interactive "MOutput File: ")
(find-file outputname)
(erase-buffer)
(let ((num 0))
(while (<= num 10)
(unless (= num 1)
(let ((resultfile (format "results/%s%d.root" resolution-filestem num)))
(with-temp-buffer
(shell-command (format "analysis/single_run %s" resultfile) (current-buffer))
(beginning-of-buffer)
(if (re-search-forward (format "^y%d.*rms = \\([0-9]+\.[0-9]+\\)" num) nil t)
(let ((resolution (match-string 1)))
(princ (format "%s\n" resolution) (get-buffer outputname)))))))
(setq num (1+ num))))
(switch-to-buffer outputname)
(save-buffer))
(defun resolution-execute-all()
(interactive)
(resolution-execute-one 10 4)
(resolution-execute-one 10 5)
(resolution-execute-one 10 6)
(resolution-execute-one 10 7)
(resolution-execute-one 10 8)
(resolution-execute-one 20 4)
(resolution-execute-one 20 5)
(resolution-execute-one 20 6)
(resolution-execute-one 20 7)
(resolution-execute-one 20 8)
(resolution-execute-one 30 4)
(resolution-execute-one 30 5)
(resolution-execute-one 30 6)
(resolution-execute-one 30 7)
(resolution-execute-one 30 8))