function DM_load_data(handles)

%function data = DM_load_data;
%
%Function that is called when press load data pushbutton
%
%Created by Mitchell Harley 01/02/2012
%Last edited
%27/08/2014

clear data

global data_path
global last_data_path
global data

if isempty(last_data_path)|~ischar(last_data_path)
   init_data_path=data_path;
else
   init_data_path=last_data_path;
end

%Get filename
[fname,pname]=uigetfile([init_data_path '*.txt'],...
       'Load params.txt file');

%Error message if no data selected
if isnumeric(fname)|isnumeric(pname)
   %errordlg('No file selected','No File')
   return
else
    last_data_path=pname;
    data.pname=pname;
    data.fname=fname;

    %Read params file
    params = xb_read_params([pname fname]);
    data.params = params;

    %Load Data
    I = find(strcmp({params.data.name},'depfile'));
    data.z = load([pname params.data(I).value]);
    I = find(strcmp({params.data.name},'xfile'));
    data.x = load([pname params.data(I).value]);
    I = find(strcmp({params.data.name},'yfile'));
    data.y = load([pname params.data(I).value]);
    I = find(strcmp({params.data.name},'alfa'));
    data.alfa = params.data(I).value;
    I = find(strcmp({params.data.name},'xori'));
    data.xori = params.data(I).value;
    I = find(strcmp({params.data.name},'yori'));
    data.yori = params.data(I).value;

%     %Remove fake edges from grid
%     I = find(diff(data.z(:,floor(size(data.z,2)/2)))==0); %Find indices along an arbitrary column where values are the same
%     I = [I;max(I)+1];
%     J = find(diff(I)~=1);
%     I(J+1)=[];
%     data.z(I,:) = [];
%     data.x(I,:) = [];
%     data.y(I,:) = [];
%     data.remove_indices = I;
    
    %Set initial values for other stuff
    data.handles.contour.nodune = [];
    data.handles.contour.dune = [];
    data.handles.profile_line.dune = [];
    data.handles.profile_line.nodune = [];
    data.real_world = 0;
    data.duneheight = 3;
    data.dunewidth = 4;
    data.startheight = 0;
    data.duneline = [];
    data.duneslope_sea = 0.25;
    data.duneslope_land = 0.75;
    data.digoption = 1; %Default is cut + fixed dune height
    data.profile_lim_min = -3;
    data.profile_lim_max = 5;
    DM_plot_nodune(handles)
end



