@@ -80,8 +80,14 @@ local function save_all (elm, mflw, lw_)
80
80
atfill(elm, mflw, lw)
81
81
end
82
82
83
- local function save_elm (elm, mflw, lw_)
84
- if not is_implicit(elm) then save_all(elm, mflw, lw_) end
83
+ local function save_imp (elm, mflw, lw_)
84
+ if is_implicit(elm) then return end
85
+ save_all(elm, mflw, lw_)
86
+ end
87
+
88
+ local function save_obs (elm, mflw, lw_)
89
+ if not is_observed(elm) then return end
90
+ save_all(elm, mflw, lw_)
85
91
end
86
92
87
93
local function make_mtable (self)
@@ -117,17 +123,20 @@ local function make_mflow (self)
117
123
local iter, state, init = sequ:siter(range, nturn, sdir)
118
124
119
125
-- build mtable
120
- local save, nofill, implicit in self
126
+ local save, nofill, observe, implicit in self
121
127
assert(is_boolean(save) or is_callable(save),
122
128
"invalid save (boolean or callable expected)")
123
129
assert(is_boolean(nofill) , "invalid nofill (boolean expected)")
130
+ assert(is_boolean(observe) , "invalid observe (boolean expected)")
124
131
assert(is_boolean(implicit), "invalid implicit (boolean expected)")
125
132
126
133
-- saving data
127
134
local mtbl, fill
128
135
if save then
129
136
mtbl = make_mtable(self)
130
- fill = is_callable(save) and save or implicit and save_all or save_elm
137
+ fill = is_callable(save) and save or -- precedence matters!
138
+ observe == true and save_obs or
139
+ implicit == false and save_imp or save_all
131
140
else
132
141
fill = fnone
133
142
end
@@ -238,33 +247,42 @@ local function exec (self)
238
247
return mtbl, mflw
239
248
end
240
249
241
- local survey = command 'survey' {
242
- sequence=nil, -- sequence (required) (mflw)
243
- range=nil, -- range of tracking (iter)
244
- title=nil, -- title of mtable (mtbl)
245
- sdir=1, -- s-direction of tracking (1 or -1) (mflw)
246
-
247
- s0=0, -- initial s (mflw)
248
- X0={0,0,0}, -- initial coordinates x, y, z (mflw)
249
- A0={0,0,0}, -- initial angles theta, phi, psi (mflw)
250
+ local _na -- not applicable (see track or twiss)
250
251
251
- nturn=1, -- number of turns (iter)
252
- nstep=-1, -- number of elements to track (iter)
253
- nslice=1, -- number of slice for each element (mflw)
254
-
255
- save=true, -- create mtable and set fill to save data (mtbl)
256
- nofill=false, -- disable filling at the end of an element (mflw)
257
- implicit=true, -- save also implicit elements (mtbl)
258
-
259
- atentry=nil, -- action to call when entering an element (mflw)
260
- atslice=nil, -- action to call after each element slices (mflw)
261
- atexit=nil, -- action to call when exiting an element (mflw)
262
- atfill=nil, -- action to call when filling a mtable row (mflw)
252
+ local survey = command 'survey' {
253
+ beam=_na, -- N/A (mflw)
254
+ sequence=nil, -- sequence (required) (mflw)
255
+ range=nil, -- range of tracking (iter)
256
+ title=nil, -- title of mtable (mtbl)
257
+ sdir=1, -- s-direction of tracking (1 or -1) (mflw)
258
+
259
+ s0=0, -- initial s (mflw)
260
+ X0={0,0,0}, -- initial coordinates x, y, z (mflw)
261
+ A0={0,0,0}, -- initial angles theta, phi, psi (mflw)
262
+
263
+ mapdef=_na, -- N/A (mflw)
264
+ mapsave=false, -- save W in the mtable (mflw)
265
+
266
+ nturn=1, -- number of turns (iter)
267
+ nstep=-1, -- number of elements to track (iter)
268
+ nslice=1, -- number of slice for each element (mflw)
269
+ method=_na, -- N/A (mflw)
270
+ totalpath=_na, -- N/A (mflw)
271
+
272
+ save=true, -- create mtable and set fill to save data (mtbl)
273
+ nofill=false, -- disable filling at the end of an element (mflw)
274
+ observe=false, -- save only observed elements (mtbl)
275
+ implicit=true, -- save also implicit elements (mtbl)
276
+
277
+ atentry=nil, -- action to call when entering an element (mflw)
278
+ atslice=nil, -- action to call after each element slices (mflw)
279
+ atexit=nil, -- action to call when exiting an element (mflw)
280
+ atfill=nil, -- action to call when filling a mtable row (mflw)
263
281
264
282
mflow=nil, -- current mflow, exclusive with other attributes except nstep
265
283
266
- exec=exec, -- command to execute upon children creation
267
- } :set_readonly() -- reference survey command is readonly
284
+ exec=exec, -- command to execute upon children creation
285
+ } :set_readonly() -- reference survey command is readonly
268
286
269
287
-- end ------------------------------------------------------------------------o
270
288
return { survey = survey }
0 commit comments