function DM_savegrid

global data

ButtonName = questdlg('Are you sure you want to save the new grid?', ...
                         'Save Grid?', ...
                         'Yes', 'No','No');
   switch ButtonName,
     case 'Yes',
        %I = find(strcmp({data.params.data.name},'depfile'));
        filename = 'bathy_dune.dep';
        znew = data.znew;
        save([data.pname filename],'znew','-ASCII')
        
        %Save dune position as a txt
        crest_line = getPosition(data.duneline);
        crest_line = interp1(crest_line(:,2),crest_line(:,1),data.y(:,1)); %Interp crest line 2 grid
        I = find(~isnan(crest_line));
        points_xb = [crest_line(I) data.y(I,1)];
        points = unrotate_points(points_xb,data.alfa,[data.xori data.yori],'degs');
        points = [points data.duneheight*ones(size(points(:,1)))];
            
        fid = fopen([data.pname 'Dune_Crest_Position.txt'],'w+');
        fprintf(fid,'X	Y	Z\r\n');
        fprintf(fid,'%.2f	%.2f	%.2f\r\n',points');
        fclose(fid);    
        msgbox('Grid file and dune crest position saved!')
       case 'No'
   end % switch