166
# Returns a list of datasets, either a named dataset, or the
167
# last datasets from the stack
168
def latest_datasets(opts)
171
warn { "Cannot use both which and number" }
173
datasets = [ specified_dataset(opts) ]
175
nb = opts['number'] || 2
177
raise "Not enough datasets on the stack"
179
datasets = @stack[(- nb).. -2]
160
185
# Appends a set of commands to the dataset hook
161
186
def add_to_dataset_hook(commands)
179
# Pops the last _n_ datasets off the stack and pushes back the
180
def concatenate_datasets(n = 2)
204
# Add all the given datasets to the current one.
205
def concatenate_datasets(datasets, name = nil)
182
207
raise "Nothing on the stack" unless ds
185
raise "Not enough datasets on the stack" unless ds2
214
@named_datasets[name] = ds if name
191
# Merges the last datasets into a new one.
217
# Merges one or more datasets into the last one.
194
def merge_datasets(n = 2, columns = [0], precision = nil)
219
# The last dataset of the stack is overwritten.
220
def merge_datasets_into_last(datasets, columns = [0], precision = nil)
196
222
raise "Nothing on the stack" unless ds
197
datasets = @stack[-1..-(n-1)]
198
223
ds.merge_datasets_in(datasets, columns, precision)
204
229
return @stack.last
232
# Displays the contents of the stack
234
STDERR.puts "Stack contents"
236
# Swap the named dataset stuff
237
## @todo Maybe a hash pair should be maintained in permanence ?
239
for k,v in @named_datasets
246
name = "(named: '#{name}')"
251
pref = sprintf("#%-2d %-3d:", i, - @stack.size + i)
253
STDERR.puts " * #{pref} #{ds.name} -- #{ds.ys.size + 1} columns #{name}"
286
337
ConcatLastCommand =
287
Cmd.new("join-datasets", nil, "--join-datasets",
288
[], {'number' => CmdArg.new('integer')}) do |plotmaker, opts|
289
nb = opts['number'] || 2
290
plotmaker.data_stack.concatenate_datasets(nb)
338
Cmd.new("join-datasets", "-j", "--join-datasets",
341
'number' => CmdArg.new('integer'),
342
'which' => CmdArg.new('stored-dataset'),
343
'name' => CmdArg.new('text')
344
}) do |plotmaker, opts|
345
stack = plotmaker.data_stack
346
datasets = stack.latest_datasets(opts)
347
stack.concatenate_datasets(datasets, opts['name'])
293
350
ConcatLastCommand.describe("Concatenates the last datasets on the stack",
294
351
<<EOH, DataStackGroup)
295
352
Pops the last two (or number, if it is specified) datasets from the
296
353
stack, concatenates them (older last) and push them back onto the
354
stack. The name option can be used to give a name to the new dataset.
358
Cmd.new("apply-formula", nil, "--apply-formula",
359
[CmdArg.new('text')],
361
'which' => CmdArg.new('stored-dataset'),
362
'name' => CmdArg.new('text'),
363
}) do |plotmaker, formula, opts|
364
ds = plotmaker.data_stack.specified_dataset(opts)
365
newds = ds.apply_formulas(formula)
366
plotmaker.data_stack.add_datasets([newds], opts)
369
ApplyLastCommand.describe("Applies a formula to the last dataset",
370
<<EOH, DataStackGroup)
371
Applies a formula to the last dataset (or the named one)
375
Cmd.new("show-stack", nil, "--show-stack",
378
) do |plotmaker, opts|
379
plotmaker.data_stack.show
382
ShowStackCommand.describe("Displays the content of the stack",
383
<<EOH, DataStackGroup)
384
Displays the current contents of the dataset stack.
386
Mostly used for debugging when operations like {command: merge-datasets}
387
or {command: join-datasets} don't work as expected.
391
## @todo Add column selection ?
301
392
MergeToLastCommand =
302
393
Cmd.new("merge-datasets", nil, "--merge-datasets",
303
[], {'number' => CmdArg.new('integer')}) do |plotmaker, opts|
304
nb = opts['number'] || 2
306
plotmaker.data_stack.merge_datasets(nb)
396
'number' => CmdArg.new('integer'),
397
'which' => CmdArg.new('stored-dataset')
399
) do |plotmaker, opts|
400
stack = plotmaker.data_stack
401
datasets = stack.latest_datasets(opts)
402
plotmaker.data_stack.merge_datasets_into_last(datasets)
309
MergeToLastCommand.describe("....",
310
<<EOH, DataStackGroup)
405
MergeToLastCommand.describe("Merge datasets based on X column",
406
<<EOH, DataStackGroup)
407
This commands merges data with matching X values from a dataset (by
408
default the one before the last) into the last one. Data points that
409
have no corresponding X value in the current dataset are simply
412
This can be used to build 3D datasets for {cmd: xyz-map} or
413
{cmd: xy-parametric}.
314
416
XYReglinCommand =
326
428
XYReglinCommand.describe("....",
327
429
<<EOH, DataStackGroup)
432
This command will get documented some day.
436
ComputeContourCommand =
437
Cmd.new("compute-contour", nil, "--compute-contour",
438
[CmdArg.new("float")], {
439
'which' => CmdArg.new('stored-dataset')
440
}) do |plotmaker, level, opts|
441
stack = plotmaker.data_stack
442
ds = stack.specified_dataset(opts)
443
f = ds.make_contour(level)
444
newds = Dataset.new("Contour #{level}", [f.x, f.y])
445
stack.store_dataset(newds, true)
448
ComputeContourCommand.describe("computes the contour and push it to data stack",
449
<<EOH, DataStackGroup)
450
Computes the contour at the given level for the given dataset (or the
451
last on the stack if none is specified) and pushes it onto the data
454
You can further manipulate it as usual.
331
457
SetDatasetHookCommand =