% run_valley_locator_test.m

% ******************************************************************

%  Script to run the valley_locator.m function
%  Configured for a single input RES data file to test functionality

% *******************************************************************

clear
close all

% Sets data directory and specific file name **change if needed**
Dir = '/Users/guy/Documents/Machine_Learning/Greenland/valley_extraction/data/';
filename = 'Data_20190405_04.csv';

% EPSG projection number (3413 = NH polar stereographic - matches BedMachine)
epsg = 3413;

% Run valley_locator.m function, extracting valley locations and morphometrics
fullFileName = fullfile(Dir, filename);
fprintf(1, 'Now reading %s\n', filename);
[date, seg, X, Y, Etop, Efloor, D, W, R, V, C, N, profiles] = valley_locator(fullFileName,epsg);

% Plot some example valley profiles and label their morphometrics
figure(1)
for i = 1:4
    subplot(2,2,i)
    plot(profiles(:,1,i),profiles(:,2,i),'-k')
    xlabel('Distance [m]')
    ylabel('Elevation [m]')
    title(['D = ' num2str(round(D(i),0)) ' m; W = ' ...
        num2str(round(W(i),0)) ' m; V = ' ...
        num2str(round(V(i),3)) ' ; C = ' ...
        num2str(round(C(i),3))])
end