@@ -265,23 +265,39 @@ MAD_SET_TERM = " \
265
265
266
266
]]
267
267
268
+ local kill_sids = {}
269
+ local function kill_plots()
270
+ pause("Closing plots, ")
271
+ for sid, term in pairs(kill_sids) do
272
+ gplot:set_sid(sid)
273
+ gplot:printf("set term %s close", term)
274
+ end
275
+ end
276
+
277
+ local kill_atexit = \ atexit(kill_plots)
268
278
-- dump header and set terminal to script file
269
279
local function setup_cmd (self)
270
- local output, scrdump in self
271
- local file, fname = get_tmpfile(self. sid)
272
- gplot:set_sid(self. sid)
280
+ local output, default, scrdump, font, fontsize, sid, term, close_plots in self
281
+ local file, fname = get_tmpfile(sid)
282
+ gplot:set_sid(sid)
273
283
file:write(init_cmd % self)
274
284
275
- self.font = self. font or ""
276
- self.fontsize = self. fontsize or ""
285
+ self.font = font or ""
286
+ self.fontsize = fontsize or ""
277
287
278
288
if is_nil(output) then
279
289
file:write("@MAD_INC_WID\n")
280
- file:write("MAD_TERM = \"set term ${term} MAD_WID size ${wsizex},\z
281
- ${wsizey} enhanced font '${font},${fontsize}'\"\n" % self)
282
- elseif is_number(output) then
283
- file:write("MAD_TERM = \"set term ${term} ${output} size ${wsizex},\z
284
- ${wsizey} enhanced font '${font},${fontsize}'\"\n" % self)
290
+ output = "MAD_WID" -- So as not to mutate the object
291
+ end
292
+ if is_number(output) or output == "MAD_WID" then
293
+ file:write(
294
+ ("MAD_TERM = \"set term ${term} " .. output .. " size ${wsizex},\z
295
+ ${wsizey} enhanced font '${font},${fontsize}'\"\n") % self
296
+ )
297
+ if close_plots then
298
+ runonce(kill_atexit)
299
+ kill_sids[sid] = term
300
+ end
285
301
elseif is_string(output) then
286
302
local ext = output:sub(-3, -1)
287
303
if ext == "png" then
@@ -1019,6 +1035,7 @@ local plot = command "plot" {
1019
1035
1020
1036
-- output
1021
1037
output = nil, -- ("filename") -> pdf | number -> wid
1038
+ close_plots = true, -- boolean, close all plots on exit of MAD-NG or not
1022
1039
scrdump = nil, -- ("filename")
1023
1040
1024
1041
-- title
0 commit comments