%----------------------------------------------------------
% main program
% -set user defined variables for use by functions
% -calls other routines
% -make some plots
% -output any data
%
% include some header comments to say what program does
% and how to use it
%
% split processing chunks into functions
% the program is then logically split into small steps
%
% do all plotting in this main program
%
%----------------------------------------------------------
% 29/1/15	NAT	Original Version
%----------------------------------------------------------

% clear all old variables and close all old figure windows
clear all
close all

% set input file names
f1 = 'datafile1.dat';
f2 = 'datafile2.dat';

% read in data files
% NOTE: use the same routine for both files
% only the order of variables matters when calling functions
% not what they are called.
[x1,n1] = fread1col(f1);
[x2,n2] = fread1col(f2);

% process the data in some way
% fcalcQ is just x1 times x2 in this simple function
[y] = fcalcQ(x1,x2);

% plot the processed output
plot(y,'-ok')
hold on
plot(x1,'-or')
plot(x2,'-og')
hold off
legend('Q (product of two files)',f1,f2)
xlabel('Data point number')
  
% write out the value of y
fo = 'y.dat';
fwrite1col(fo,y,n1);
