#!/usr/bin/env octave-cli

# Run with -i switch to run interactively

args = argv();
dry_run = false;
interactive = false;

for a = args'
	if strcmp(a, "--force-gui")
		break;
		#disp("Running from GUI");
	elseif strcmp(a, "-i")
		disp("interactive");
		interactive = true;
	elseif strcmp(a, "-n")
		disp("dry-run");
		dry_run = true;
	elseif (! strncmp(a, "-", 1) && exist(a{1}, "file"))
		disp("found file");
		filename = a{1};
	endif
endfor

if (! exist("filename", "var"))
	disp("No file specified, exiting");
	return;
endif

graphics_toolkit gnuplot;
disp(["Current graphics toolkit: " graphics_toolkit]);

# Values from Abarcus
values = csvread(filename);
time = values(:, 1);
draw = values(:, 2);
Ep_staff = values(:, 3);
Ep_stringtop = values(:, 4);
Ep_stringbot = values(:, 5);

clf;
hold on;
	plot(time, z_abarcus);
	plot(time, z_analytic, "r");
	xlabel("t[s]");
	ylabel("z[m]");
	axis([0, 30, -0.1, 0.1]);
	legend("numericky model (Abarcus)", "analyticke reseni");
	grid on;
	box off;
hold off;

if ! dry_run
	output = strrep(filename, ".csv", "");
	print(output, "-deps", "-color");
endif

if interactive
	pause;
endif
