function [] = modifyELCOMbathy(filename, dbfilename) %% Use system background color for GUI components panelColor = get(0,'DefaultUicontrolBackgroundColor'); %% ------------ Callback Functions --------------- % Figure resize function function figResize(src,evt) fpos = get(f,'Position'); botPanelHeight = min([fpos(4)*8/35 6]); set(botPanel,'Position',... [1/20 1/20 fpos(3)-.1 botPanelHeight]) set(topPanel,'Position',... [1/20 botPanelHeight+1/20 fpos(3)-.1 fpos(4)-botPanelHeight-.1]) end % Bottom panel resize function function botPanelResize(src, evt) bpos = get(botPanel,'Position'); xspace = bpos(3)*1/120; xbutSize = bpos(3)*8/120; xfieldSize = bpos(3)*12/120; ybot = bpos(4)*1/8; ytop = bpos(4)*4/8; ysize = 2; thisX = xspace; set(popUp,'Position',... [thisX ybot xfieldSize ysize]) set(popUpLabel,'Position',... [thisX ytop xfieldSize ysize]) thisX = thisX +xfieldSize+xspace; set(resetButton,'Position',... [thisX ytop xbutSize ysize]) set(resetAllButton,'Position',... [thisX ybot xbutSize ysize]) thisX = thisX +xbutSize+xspace; set(saveButton,'Position',... [thisX ybot xbutSize ysize]) set(resetCaxisButton,'Position',... [thisX ytop xbutSize ysize]) thisX = thisX +xbutSize+xspace; set(getCurtainButton,'Position',... [thisX ytop xbutSize ysize]) set(clearCurtainButton,'Position',... [thisX ybot xbutSize ysize]) thisX = thisX +xbutSize+xspace; %set(gridButton,'Position',... % [thisX ybot xbutSize ysize]) set(regridButton,'Position',... [thisX ytop xbutSize ysize]) thisX = thisX +xbutSize+xspace; set(gridButton,'Position',... [thisX ybot xbutSize ysize]) set(zoomButton,'Position',... [thisX ytop xbutSize ysize]) thisX = thisX +xbutSize+xspace; set(iTextField,'Position',... [thisX ybot xbutSize ysize]) set(iTextLabel,'Position',... [thisX ytop xbutSize ysize]) thisX = thisX +xbutSize+xspace; set(jTextField,'Position',... [thisX ybot xbutSize ysize]) set(jTextLabel,'Position',... [thisX ytop xbutSize ysize]) thisX = thisX +xbutSize+xspace; set(depthTextField,'Position',... [thisX ybot xbutSize ysize]) set(depthTextLabel,'Position',... [thisX ytop xbutSize ysize]) thisX = thisX +xbutSize+xspace; set(cMinTextField,'Position',... [thisX ybot xbutSize ysize]) set(cMinTextLabel,'Position',... [thisX ytop xbutSize ysize]) thisX = thisX +xbutSize+xspace; set(cMaxTextField,'Position',... [thisX ybot xbutSize ysize]) set(cMaxTextLabel,'Position',... [thisX ytop xbutSize ysize]) thisX = thisX +xbutSize+xspace; set(depthChangeTextField,'Position',... [thisX ybot xbutSize ysize]) set(depthChangeTextLabel,'Position',... [thisX ytop xbutSize ysize]) end % Plot Bathymetry function function plotNewBathymetry(xlimits,ylimits) cla(a) b = pcolorBathy(a,y,x,plotData,dy1,dx1); set (a,'ydir','reverse') set (b,'ButtonDownFcn',@axisCallback) if (nargin == 2) set(a, 'xlim', xlimits) set(a, 'ylim', ylimits) %axis (a,'equal') else axis (a,'equal') end button_state = get(gridButton,'Value'); if button_state == get(gridButton,'Max') set(gridButton,'String','Grid off') shading (a,'faceted') elseif button_state == get(gridButton,'Min') shading (a,'flat') set(gridButton,'String','Grid on') end end function [b ]= pcolorBathy(a, x,y,data,dx1,dy1); % % Plots a pcolor plot but shows full matrix % NB: Default pcolor does not show last row or column % Assumes x and y are cell centered values % % Get location of grid faces nx = length(x); ny = length(y); x_new = zeros(nx+1,1); y_new = zeros(ny+1,1); xNew(1) = x(1)-0.5*dx1; for i = 1:nx xNew(i+1) = 2*x(i)-xNew(i); end yNew(1) = y(1)-0.5*dy1; for i = 1:ny yNew(i+1) = 2*y(i)-yNew(i); end % Add extra column and row to matrix dataNew = zeros (ny+1,nx+1); dataNew(:,:) = NaN; dataNew (1:ny,1:nx) = data; % Plot data b= pcolor (a,xNew,yNew,dataNew); % Default shading flat shading (a,'flat') cb = colorbar('peer',a); hold(a,'on') plot (a, x(lastCurtCell(2)), y(lastCurtCell(1)),'wx') % Plot datablock if loaded if (~isempty(sets)) for ss = 1:length(sets) if strcmp(sets(ss).Type,'CURTAIN_2D') jTmp = sets(ss).locn(:,1); iTmp = sets(ss).locn(:,2); plot (a, x(iTmp), y(jTmp),'wx-') end if strcmp(sets(ss).Type,'PROFILE_1D') jTmp = sets(ss).locn(:,1); iTmp = sets(ss).locn(:,2); plot (a, x(iTmp), y(jTmp),'wo') end end end end; %% Callback for axis function axisCallback(src,evt) % Get loaction LOC = get(a,'currentpoint'); [tmp ii] = min(abs(x- (LOC(1,2)))); [tmp jj] = min(abs(y- (LOC(1,1)))); set(iTextField,'String',num2str(ii)) set(jTextField,'String',num2str(jj)) % Get mouse command selected_cmd = get(popUp,'Value'); % Make the GUI axes current and create plot axes(a) xlimits = get(gca,'xlim'); ylimits = get(gca,'ylim'); switch selected_cmd case 1 % DISPLAY bath_pt = newBath(ii,jj); set(depthTextField,'String',num2str(bath_pt)) case 2 % land Cell newBath(ii,jj) = bathStruct.land_value; bath_pt = newBath(ii,jj); set(depthTextField,'String',num2str(bath_pt)) plotData(ii,jj) = NaN; case 3 % open Cell newBath(ii,jj) = bathStruct.open_value; bath_pt = newBath(ii,jj); set(depthTextField,'String',num2str(bath_pt)) plotData(ii,jj) = NaN; case 4 % make deeper bath_pt = plotData(ii,jj); if (~isnan(bath_pt)) delta = str2num(get(depthChangeTextField,'String')); newBath(ii,jj) = newBath(ii,jj)-delta; set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); end case 5 % make shallower bath_pt = plotData(ii,jj); if (~isnan(bath_pt)) delta = str2num(get(depthChangeTextField,'String')); newBath(ii,jj) = newBath(ii,jj)+delta; set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); end case 6 % interpolate in x dir bath_pt_m1 = plotData(ii-1,jj); bath_pt_p1 = plotData(ii+1,jj); if (~isnan(bath_pt_m1)) if (~isnan(bath_pt_p1)) newBath(ii,jj) = (bath_pt_m1+bath_pt_p1)/2.0; set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); else newBath(ii,jj) = (bath_pt_m1); set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); end else if (~isnan(bath_pt_p1)) newBath(ii,jj) = (bath_pt_p1); set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); else % both land or open end end case 7 % interpolate in y dir bath_pt_m1 = plotData(ii,jj-1); bath_pt_p1 = plotData(ii,jj+1); if (~isnan(bath_pt_m1)) if (~isnan(bath_pt_p1)) newBath(ii,jj) = (bath_pt_m1+bath_pt_p1)/2.0; set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); else newBath(ii,jj) = (bath_pt_m1); set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); end else if (~isnan(bath_pt_p1)) newBath(ii,jj) = (bath_pt_p1); set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); else % both land or open end end case 8 % interpolate in NW -> SE dir bath_pt_m1 = plotData(ii-1,jj-1); bath_pt_p1 = plotData(ii+1,jj+1); if (~isnan(bath_pt_m1)) if (~isnan(bath_pt_p1)) newBath(ii,jj) = (bath_pt_m1+bath_pt_p1)/2.0; set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); else newBath(ii,jj) = (bath_pt_m1); set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); end else if (~isnan(bath_pt_p1)) newBath(ii,jj) = (bath_pt_p1); set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); else % both land or open end end case 9 % interpolate in SW -> NE dir bath_pt_m1 = plotData(ii+1,jj-1); bath_pt_p1 = plotData(ii-1,jj+1); if (~isnan(bath_pt_m1)) if (~isnan(bath_pt_p1)) newBath(ii,jj) = (bath_pt_m1+bath_pt_p1)/2.0; set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); else newBath(ii,jj) = (bath_pt_m1); set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); end else if (~isnan(bath_pt_p1)) newBath(ii,jj) = (bath_pt_p1); set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); else % both land or open end end case 10 % avg surrounding cells sumBath = 0; nBath = 0; for ix=-1:1 for jx=-1:1 if (i ~= 0 && j ~=0) bath_pt = plotData(ii+ix,jj+jx); if (~isnan(bath_pt)) sumBath = sumBath+bath_pt; nBath = nBath+1; end end end end if (nBath ~=0) newBath(ii,jj) = sumBath/nBath; set(depthTextField,'String',num2str(newBath(ii,jj))) plotData(ii,jj) = newBath(ii,jj); end case 11 % add to cells curtainCells = [curtainCells; ii jj 0 0]; bath_pt = newBath(ii,jj); set(depthTextField,'String',num2str(bath_pt)) lastCurtCell = [ii jj]; case 12 % move left ix = ii; jx = jj; plotData(ix,jx) while ~isnan(plotData(ix,jx)) plotData(ix,jx-1) = plotData(ix,jx); newBath(ix,jx-1) = newBath(ix,jx); jx = jx+1; end plotData(ix,jx-1) = plotData(ix,jx); newBath(ix,jx-1) = newBath(ix,jx); case 13 % move right ix = ii; jx = jj; plotData(ix,jx) while ~isnan(plotData(ix,jx)) plotData(ix,jx+1) = plotData(ix,jx); newBath(ix,jx+1) = newBath(ix,jx); jx = jx-1; end plotData(ix,jx+1) = plotData(ix,jx); newBath(ix,jx+1) = newBath(ix,jx); case 14 % move up ix = ii; jx = jj; plotData(ix,jx) while ~isnan(plotData(ix,jx)) plotData(ix-1,jx) = plotData(ix,jx); newBath(ix-1,jx) = newBath(ix,jx); ix = ix+1; end plotData(ix-1,jx) = plotData(ix,jx); newBath(ix-1,jx) = newBath(ix,jx); case 15 % move down ix = ii; jx = jj; plotData(ix,jx) while ~isnan(plotData(ix,jx)) plotData(ix+1,jx) = plotData(ix,jx); newBath(ix+1,jx) = newBath(ix,jx); ix = ix-1; end plotData(ix+1,jx) = plotData(ix,jx); newBath(ix+1,jx) = newBath(ix,jx); end plotNewBathymetry(xlimits,ylimits); end % axisCallback %% Callbakc for i and j text fields function ijTextFieldCallback(src,evt) ii = str2num(get(iTextField,'String')); jj = str2num(get(jTextField,'String')); bath_pt = newBath(ii,jj); set(depthTextField,'String',num2str(bath_pt)) end %% Callbakc for i and j text fields function cMinMaxTextFieldCallback(src,evt) cmin = str2num(get(cMinTextField,'String')); cmax = str2num(get(cMaxTextField,'String')); set(a,'Clim',[cmin cmax]) cb = colorbar('peer',a); end %% Callback for resetCaxisButton function resetCaxisButtonCallback(src,evt) cmin = min(min(plotData)); cmax = max(max(plotData)); set(a,'Clim',[cmin cmax]) cb = colorbar('peer',a); end %% Callback for axis function depthTextFieldCallback(src,evt) % Get loaction ii = str2num(get(iTextField,'String')); jj = str2num(get(jTextField,'String')); bath_pt = str2num(get(depthTextField,'String')); % Make the GUI axes current and create plot axes(a) xlimits = get(gca,'xlim'); ylimits = get(gca,'ylim'); newBath(ii,jj) = bath_pt; plotData(ii,jj) = bath_pt; plotNewBathymetry(xlimits,ylimits); end % depthTextFieldCallback %% Callback for reset function resetButtonCallback(src,evt) % Get loaction ii = str2num(get(iTextField,'String')); jj = str2num(get(jTextField,'String')); bath_pt = oldBath(ii,jj); set(depthTextField,'String',num2str(bath_pt)) % Make the GUI axes current and create plot axes(a) xlimits = get(gca,'xlim'); ylimits = get(gca,'ylim'); newBath(ii,jj) = bath_pt; plotData(ii,jj) = bath_pt; if (bath_pt == bathStruct.land_value | ... bath_pt == bathStruct.open_value); plotData(ii,jj) = NaN; end plotNewBathymetry(xlimits,ylimits); end % resetButtonCallback %% Callback for resetAll function resetAllButtonCallback(src,evt) % Get loaction ii = str2num(get(iTextField,'String')); jj = str2num(get(jTextField,'String')); bath_pt = oldBath(ii,jj); set(depthTextField,'String',num2str(bath_pt)) % Make the GUI axes current and create plot axes(a) xlimits = get(gca,'xlim'); ylimits = get(gca,'ylim'); newBath = oldBath; plotData = oldBath; % Remove land and open bc cells pts = find(oldBath == bathStruct.land_value | ... oldBath == bathStruct.open_value); plotData(pts) = NaN; plotNewBathymetry(xlimits,ylimits); end % resetAllButtonCallback %% Callback for save function saveButtonCallback(src,evt) % Get loaction bathStruct.bathData = newBath; [filename, pathname] = uiputfile('*.dat', 'Save-file'); if isequal(filename,0) | isequal(pathname,0) disp('User pressed cancel') else writeELCOMbathy(fullfile(pathname, filename),bathStruct); end end % saveButtonCallback function regridButtonCallback(src,evt) prompt={'minDX','minDY','maxDX','maxDY','small DX region','small DY region','plaidRate'}; name='Re Grid'; numlines=1; defaultanswer={'100','100','250','250','[35000 40000]','[0 2000]','1.1'}; options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; info=inputdlg(prompt,name,numlines,defaultanswer,options); if ~isempty(info) %see if user hit cancel setptr(gcf,'watch') fields = {'minDX','minDY','maxDX','maxDY','smallDXregion','smallDYregion','plaidRate'}; info = cell2struct(info,fields); minDX = str2num(info.minDX); minDY = str2num(info.minDY); maxDX = str2num(info.maxDX); maxDY = str2num(info.maxDY); smallDXregion = str2num(info.smallDXregion); smallDYregion = str2num(info.smallDYregion); plaidRate = str2num(info.plaidRate); if isempty(bathStruct.dx) xdist = bathStruct.x_rows*bathStruct.x_grid; else xdist = sum(bathStruct.dx); end if isempty(bathStruct.dy) ydist = bathStruct.y_columns*bathStruct.y_grid; else ydist = sum(bathStruct.dy); end if ~isempty(smallDXregion) if length(smallDXregion) ~=2 errordlg('small DX region needs to be empty of length 2') return end [dx] = generatePlaid(minDX,maxDX,plaidRate,smallDXregion,xdist); else dx = minDX; end if ~isempty(smallDYregion) if length(smallDYregion) ~=2 errordlg('small DY region needs to be empty of length 2') return end [dy] = generatePlaid(minDY,maxDY,plaidRate,smallDYregion,ydist); else dy = minDY; end method = 'linear'; [bathStructNew] = reGridBathy(bathStruct,dx,dy,method); bathStruct = bathStructNew; oldBath = (bathStruct.bathData); plotData = oldBath; newBath = oldBath; x = []; y = []; % Sort out x and y if ~isempty(bathStruct.dx) dx1 = bathStruct.dx(1); x(1) = bathStruct.dx(1)/2.0; for i =2:bathStruct.x_rows x(i) = x(i-1)+bathStruct.dx(i-1)/2.0+bathStruct.dx(i)/2.0; end else dx1 = bathStruct.x_grid; x(1) = bathStruct.x_grid/2.0; for i =2:bathStruct.x_rows x(i) = x(i-1)+bathStruct.x_grid; end end if ~isempty(bathStruct.dy) dy1 = bathStruct.dy(1); y(1) = bathStruct.dy(1)/2.0; for i =2:bathStruct.y_columns y(i) = y(i-1)+bathStruct.dy(i-1)/2.0+bathStruct.dy(i)/2.0; end else dy1 = bathStruct.y_grid; y(1) = bathStruct.y_grid/2.0; for i =2:bathStruct.y_columns y(i) = y(i-1)+bathStruct.y_grid; end end % Remove land and open bc cells pts = find(oldBath == bathStruct.land_value | ... oldBath == bathStruct.open_value); plotData(pts) = NaN; curtainCells = [0 0 0 0]; lastCurtCell = [1 1]; plotNewBathymetry(); setptr(gcf,'arrow') end end %% Callback for grid function gridButtonCallback(hObject, eventdata, handles) button_state = get(hObject,'Value'); if button_state == get(hObject,'Max') set(hObject,'String','Grid off') shading (a,'faceted') elseif button_state == get(hObject,'Min') shading (a,'flat') set(hObject,'String','Grid on') end end % gridButtonCallback %% Callback for zoom function zoomButtonCallback(hObject, eventdata, handles) button_state = get(hObject,'Value'); if button_state == get(hObject,'Max') set(hObject,'String','Zoom off') zoom (f,'on') elseif button_state == get(hObject,'Min') zoom (f,'off') set(hObject,'String','Zoom on') end end % zoomButtonCallback %% Callback for getCurtain function getCurtainButtonCallback(src,evt) if size(curtainCells,1) < 3 disp('Select at lease two curtainpoints') return end dxFactor = .5; curtainCells2 = [ 0 0 0 0]; for cc = 3:size(curtainCells,1) i1 = curtainCells(cc-1,1); j1 = curtainCells(cc-1,2); i2 = curtainCells(cc,1); j2 = curtainCells(cc,2); nPts = max([abs(i1-i2),abs(j1-j2)])*100; x1 = x(i1); x2 = x(i2); y1 = y(j1); y2 = y(j2); diffX = x2-x1; diffY = y2-y1; for n = 0:nPts xN(n+1) = x1+(n/nPts)*diffX; yN(n+1) = y1+(n/nPts)*diffY; end if i2(xx-0.5*dxFactor*dxx) & xN<(xx+0.5*dxFactor*dxx) & ... yN>(yy-0.5*dxFactor*dyy) & yN<(yy+0.5*dxFactor*dyy)) curtainCells2 = [curtainCells2; ii jj 0 0]; continue end % Check if we pass through both x faces [tmp, loc1] = min(abs(xN-(xx-0.5*dxx))); [tmp, loc2] = min(abs(xN-(xx+0.5*dxx))); if yN(loc1)>(yy-0.5*dyy) & yN(loc1)<(yy+0.5*dyy) & ... yN(loc2)>(yy-0.5*dyy) & yN(loc2)<(yy+0.5*dyy) curtainCells2 = [curtainCells2; ii jj 0 0]; continue end % Check if we pass through both y faces [tmp, loc1] = min(abs(yN-(yy-0.5*dyy))); [tmp, loc2] = min(abs(yN-(yy+0.5*dyy))); if xN(loc1)>(xx-0.5*dxx) & xN(loc1)<(xx+0.5*dxx) & ... xN(loc2)>(xx-0.5*dxx) & xN(loc2)<(xx+0.5*dxx) curtainCells2 = [curtainCells2; ii jj 0 0]; continue end end end end curtainCells2 ncells = size(curtainCells2,1) - 1 plot (a, x(curtainCells2(2:ncells,1)), y(curtainCells2(2:ncells,2)),'wx-') end % %% Callback for getCurtain function clearCurtainButtonCallback(src,evt) curtainCells = [ 0 0 0 0]; end function [dx] = generatePlaid(minDX,maxDX,plaidRate,smallRegion,xdist) % function [bathStruct] = generatePlaid(minDX,maxDX,plaidRate,smallRegion,xdist) % % Generate an array of plaid dx for use with modifyELCOMbathyGridSize % % Inputs: % minDX : minimum value of dx for the gris % maxDX : maximum value of dx for the grid % plaidRate : the rate to increase from min DX to max DX % smallRegion : a 1x2 array for region to contain small dx values e: [0 4000] % xdist : the total distance required. % % Outputs % dx : the array of dx values % % Uses: % % Written by C. Dallimore 20 July 06 % % get an array of dx for the varying width region i=1; plaidDX(i) = plaidRate*minDX; while plaidDX < maxDX plaidDX(i+1) = plaidRate*plaidDX(i); i = i+1; end plaidDX = plaidDX(1:i-1); plaidDist = sum(plaidDX); % initailise dx=[]; % Do we need maxDX cells before the small dx region if smallRegion(1)-plaidDist <0 % Do we need varying cells before the small dx region n = 0; plaidDistTmp = 0; while smallRegion(1) - plaidDistTmp > 0 n = n+1; plaidDistTmp=plaidDistTmp+plaidDX(n); end for i =1:length(plaidDX) dx(i)=plaidDX(length(plaidDX)-i+1); end % Fill in the small dx region thisX = n; while sum(dx) < smallRegion(2) thisX = thisX+1; dx(thisX) = minDX; end % Move out from small dx region with varying width cells until we get to maxDX % then fill to we get to xdist n = 1; while sum(dx) < xdist thisX = thisX +1; if n > length(plaidDX) dx(thisX)=maxDX; else dx(thisX)=plaidDX(n); end n = n+1; end else % Fill with maxDX until we get close enough to small region to use varying cells thisX =1; while sum(dx)+plaidDist length(plaidDX) dx(thisX)=maxDX; else dx(thisX)=plaidDX(n); end n = n+1; end end end function [bathStructNew] = reGridBathy(bathStruct,dxNew,dyNew,method) bath = (bathStruct.bathData); % Set land and open bc cells to the maximum height plus a small number pts = find(bath == bathStruct.land_value | ... bath == bathStruct.open_value); % First set land cells to NaN in case Land value is greater than the maximum height bath(pts) = NaN; minHeight = min(min(bath)); maxHeight = max(max(bath)); maxHeight+(maxHeight-minHeight)/100; bath(pts) = maxHeight+(maxHeight-minHeight)/100; % set up x and y array for old file x_old = zeros(bathStruct.x_rows,1); y_old = zeros(bathStruct.y_columns,1); if ~isempty(bathStruct.dx) x_old(1) = bathStruct.dx(1)/2; for i =2:bathStruct.x_rows x_old(i) = x_old(i-1)+(bathStruct.dx(i)+bathStruct.dx(i-1))/2; end else x_old(:) = bathStruct.x_grid/2+(0:bathStruct.x_rows-1)*bathStruct.x_grid; end if ~isempty(bathStruct.dy) y_old(1) = bathStruct.dy(1)/2; for i =2:bathStruct.y_columns y_old(i) = y_old(i-1)+(bathStruct.dy(i)+bathStruct.dy(i-1))/2; end else y_old(:) = bathStruct.y_grid/2+(0:bathStruct.y_columns-1)*bathStruct.y_grid; end % set up x and y array for new file maxX = max(x_old); if length(dxNew) ==1 i = 1; x_new(i) = dxNew/2; while x_new(i) < maxX i = i+1; x_new(i) = x_new(i-1)+dxNew; end else x_new(1) = dxNew(1)/2; for i =2:length(dxNew) x_new(i) = x_new(i-1)+(dxNew(i)+dxNew(i-1))/2; end end maxY = max(y_old); if length(dyNew) ==1 i = 1; y_new(i) = dyNew/2; while y_new(i) < maxY i = i+1; y_new(i) = y_new(i-1)+dyNew; end else y_new(1) = dyNew(1)/2; for i =2:length(dyNew) y_new(i) = y_new(i-1)+(dyNew(i)+dyNew(i-1))/2; end end % Interpolate the data using meshgrid [X,Y]=meshgrid(x_new,y_new); bath_new=griddata(x_old,y_old,bath',X,Y,method); % Set point above the old max to land value pts = find(bath_new > maxHeight | isnan(bath_new)); bath_new(pts) = bathStruct.land_value; % Setup the new structure bathStructNew = bathStruct; bathStructNew.bathData=bath_new'; bathStructNew.x_grid=dxNew(1); bathStructNew.y_grid=dyNew(1); if length(dxNew) ==1 bathStructNew.dx=[]; else bathStructNew.dx=dxNew; end if length(dxNew) ==1 bathStructNew.dy=[]; else bathStructNew.dy=dyNew; end bathStructNew.x_rows = length(x_new); bathStructNew.y_columns = length(y_new); end %% ------------ GUI layout --------------- %% Set up the figure and defaults f = figure('Units','characters',... 'Position',[30 30 120 35],... 'Color',panelColor,... 'HandleVisibility','callback',... 'IntegerHandle','off',... 'Renderer','painters',... 'Toolbar','none',... 'Menubar','none',... 'NumberTitle','off',... 'Name',filename,... 'ResizeFcn',@figResize); %% Create the bottom uipanel botPanel = uipanel('BorderType','etchedin',... 'BackgroundColor',panelColor,... 'Units','characters',... 'Position',[1/20 1/20 119.9 8],... 'Parent',f,... 'ResizeFcn',@botPanelResize); %% Create the center panel topPanel = uipanel('bordertype','etchedin',... 'Units','characters',... 'Position', [1/20 8 119.9 67],... 'Parent',f); %% Add an axes to the center panel a = axes('parent',topPanel); % Get Bathymetry from file bathStruct = readELCOMbathy(filename); if (nargin >1) [grps,sets]=readELCOMdatablock(dbfilename); else grps=[]; sets=[]; end %% Add popup and label popUpLabel = uicontrol(f,'Style','text','Units','characters',... 'Position',[10 4 20 2],... 'String','Mouse Button Action',... 'BackgroundColor',panelColor,... 'Parent',botPanel); popUp = uicontrol(f,'Style','popupmenu','Units','characters',... 'Position',[10 2 20 2],... 'BackgroundColor','white',... 'TooltipString','Controls action on mouse click', ... 'String',{'Display','Land Cell','Open Cell','Deepen','Raise', ... 'Interpolate in X-dir','Interpolate in Y-dir',... 'Interpolate in NW-SE dir','Interpolate in NE-SW dir', ... 'Avg Surrounding cells',... 'Add to curtain cell',... 'Move Left',... 'Move Right',... 'Move Up',... 'Move Down'},... 'Parent',botPanel); %% Add save buttons saveButton = uicontrol(f,'Style','pushbutton','Units','characters',... 'Position',[50 2 20 2],... 'String','Save',... 'TooltipString','Save to new file', ... 'Parent',botPanel,... 'Callback',@saveButtonCallback); %% Add reset buttons resetButton = uicontrol(f,'Style','pushbutton','Units','characters',... 'Position',[50 2 20 2],... 'String','Reset',... 'TooltipString','Reset Depth of Current ij cell', ... 'Parent',botPanel,... 'Callback',@resetButtonCallback); %% Add reset buttons resetAllButton = uicontrol(f,'Style','pushbutton','Units','characters',... 'Position',[70 2 20 2],... 'String','Reset All',... 'TooltipString','Reset Depth of all cell', ... 'Parent',botPanel,... 'Callback',@resetAllButtonCallback); %% Add i,j,depth info buttons iTextLabel = uicontrol(f,'Style','text','Units','characters',... 'Position',[10 4 20 2],... 'String','i',... 'BackgroundColor',panelColor,... 'Parent',botPanel); iTextField= uicontrol(f,'Style','edit','Units','characters',... 'Position',[70 2 20 2],... 'String','1',... 'Parent',botPanel,... 'Callback',@ijTextFieldCallback); jTextLabel = uicontrol(f,'Style','text','Units','characters',... 'Position',[10 4 20 2],... 'String','j',... 'BackgroundColor',panelColor,... 'Parent',botPanel); jTextField= uicontrol(f,'Style','edit','Units','characters',... 'Position',[70 2 20 2],... 'String','1',... 'Parent',botPanel,... 'Callback',@ijTextFieldCallback); depthTextLabel = uicontrol(f,'Style','text','Units','characters',... 'Position',[10 4 20 2],... 'String','Depth',... 'BackgroundColor',panelColor,... 'Parent',botPanel); depthTextField= uicontrol(f,'Style','edit','Units','characters',... 'Position',[70 2 20 2],... 'String',num2str(bathStruct.land_value),... 'Parent',botPanel,... 'Callback',@depthTextFieldCallback); depthChangeTextLabel = uicontrol(f,'Style','text','Units','characters',... 'Position',[10 4 20 2],... 'String','Depth Change',... 'BackgroundColor',panelColor,... 'Parent',botPanel); depthChangeTextField= uicontrol(f,'Style','edit','Units','characters',... 'Position',[70 2 20 2],... 'String','1',... 'TooltipString','Amount for deepen/raise', ... 'Parent',botPanel); %% Add get curtain button getCurtainButton = uicontrol(f,'Style','pushbutton','Units','characters',... 'Position',[70 2 20 2],... 'String','Get Curt',... 'TooltipString','Get all cells between curtain points', ... 'Parent',botPanel,... 'Callback',@getCurtainButtonCallback); %% Add clear curtain button clearCurtainButton = uicontrol(f,'Style','pushbutton','Units','characters',... 'Position',[70 2 20 2],... 'String','Clear Curt',... 'TooltipString','Clear curtain points', ... 'Parent',botPanel,... 'Callback',@clearCurtainButtonCallback); % Add zoom toggle button regridButton= uicontrol(f,'Style','toggle','Units','characters',... 'Position',[70 2 20 2],... 'String','Re-Grid',... 'Parent',botPanel,... 'TooltipString','Regrid the bathymetry', ... 'Callback',@regridButtonCallback); % Add grid toggle button gridButton= uicontrol(f,'Style','toggle','Units','characters',... 'Position',[70 2 20 2],... 'String','Grid on',... 'TooltipString','Toggle Grid', ... 'Parent',botPanel,... 'Callback',@gridButtonCallback); % Add zoom toggle button zoomButton= uicontrol(f,'Style','toggle','Units','characters',... 'Position',[70 2 20 2],... 'String','Zoom on',... 'Parent',botPanel,... 'TooltipString','Toggle Zoom', ... 'Callback',@zoomButtonCallback); oldBath = (bathStruct.bathData); plotData = oldBath; newBath = oldBath; % Sort out x and y if ~isempty(bathStruct.dx) dx1 = bathStruct.dx(1); x(1) = bathStruct.dx(1)/2.0; for i =2:bathStruct.x_rows x(i) = x(i-1)+bathStruct.dx(i-1)/2.0+bathStruct.dx(i)/2.0; end else dx1 = bathStruct.x_grid; x(1) = bathStruct.x_grid/2.0; for i =2:bathStruct.x_rows x(i) = x(i-1)+bathStruct.x_grid; end end if ~isempty(bathStruct.dy) dy1 = bathStruct.dy(1); y(1) = bathStruct.dy(1)/2.0; for i =2:bathStruct.y_columns y(i) = y(i-1)+bathStruct.dy(i-1)/2.0+bathStruct.dy(i)/2.0; end else dy1 = bathStruct.y_grid; y(1) = bathStruct.y_grid/2.0; for i =2:bathStruct.y_columns y(i) = y(i-1)+bathStruct.y_grid; end end % Remove land and open bc cells pts = find(oldBath == bathStruct.land_value | ... oldBath == bathStruct.open_value); plotData(pts) = NaN; % Add caxis text fields cMinTextLabel = uicontrol(f,'Style','text','Units','characters',... 'Position',[10 4 20 2],... 'String','Cmin',... 'BackgroundColor',panelColor,... 'Parent',botPanel); cMinTextField= uicontrol(f,'Style','edit','Units','characters',... 'Position',[70 2 20 2],... 'String',num2str(min(min(plotData))),... 'Parent',botPanel,... 'Callback',@cMinMaxTextFieldCallback); cMaxTextLabel = uicontrol(f,'Style','text','Units','characters',... 'Position',[10 4 20 2],... 'String','Cmax',... 'BackgroundColor',panelColor,... 'Parent',botPanel); cMaxTextField= uicontrol(f,'Style','edit','Units','characters',... 'Position',[70 2 20 2],... 'String',num2str(max(max(plotData))),... 'Parent',botPanel,... 'Callback',@cMinMaxTextFieldCallback); %% Add reset caxis buttons resetCaxisButton = uicontrol(f,'Style','pushbutton','Units','characters',... 'Position',[70 2 20 2],... 'String','Reset CLIM',... 'Parent',botPanel,... 'Callback',@resetCaxisButtonCallback); curtainCells = [0 0 0 0]; lastCurtCell = [1 1]; plotNewBathymetry(); %maximise figure set (f, 'position',get(0,'screensize')) end % uipanel1