function handles = create_surf(handles)
area_data = handles.data.area_data;
if isfield(handles.data, 'h_surf');
% If the ribbon plots have already been created, this function is just
% being called to set the visibility because the user has moved the
% slider bar. Set the visibility of the layers according to the
% settings on the slider bar and checkbox
cur_layer_val = round(get(handles.scrollLayer,'Value'));
if get(handles.chkShowLayerOnly,'Value') == 1
vis_ind = cur_layer_val;
else
vis_ind = 1:cur_layer_val;
end
set(handles.data.h_surf,'Visible','off');
set(handles.data.h_surf(vis_ind,:),'Visible','on');
else
% Set up surface plotting base grids
x = (1:size(area_data,1))';
y = (1:size(area_data,3));
[x,y] = meshgrid(x,y);
x = x';
y = y';
%xi = 1:0.5:size(area_data,1);
xi = 1:size(area_data,1);
%yi = 1:0.5:size(area_data,3);
yi = 1:size(area_data,3);
[XI,YI] = meshgrid(xi,yi);
% Select the top axes
axes(handles.ax3D);
cla
% cc = ones(size(XI));
for cur_layer = 1:size(area_data,2)
z = reshape(area_data(:,cur_layer,:),size(area_data,1),size(area_data,3));
if cur_layer > 1
% The line below is included to space the surfaces verticallyslightly
% This is done so that data points that actually touch do not
% "corrupt" the surfaces. It isn't strictly correct to do this,
% but it makes the surfaces look much better
z(z == 0) = 70;
z = z + z_last;
end
z_last = z;
ZI = griddata(x,y,z,XI,YI);
xp = XI(1,:);
zp = ZI';
% Create the ribbon plot
h_surf(cur_layer,:) = ribbon(xp,zp);
set(h_surf(cur_layer,:),'CData',cur_layer*ones(size(zp,1),2));
hold on;
end
% Turn off the black edge of the ribbon plots
set(h_surf,'edgecolor','none');
set(h_surf,'SpecularColorReflectance',0.3)
% Add lighting
light('Position',[1 1 0.2],'Style','infinite');
lighting phong
ylim(handles.ax3D,[0 48])
set(handles.ax3D,'YTick',[0:4:48]);
set(handles.ax3D,'XTick',[1:size(area_data,2)]);
set(handles.ax3D,'XtickLabel',1:size(area_data,3));
set(handles.ax3D,'XtickLabel',handles.data.disp_dates);
set(handles.ax3D,'fontsize',8);
zlabel('MW')
view(37.5,30)
axis tight
handles.data.h_surf = h_surf;
% Create day slider plane
x_p = repmat(1,4,1);
y_p = [1 48 48 1];
z_max = max(max(z));
z_p = [0 0 z_max z_max];
handles.data.h_day_slider = patch(x_p,y_p,z_p,[0.5 0.5 0.5],'FaceAlpha',0.2);
% Create period slider plane
x_p = [1 size(area_data,3) size(area_data,3) 1];
y_p = repmat(1,4,1);
% z_max = max(max(z));
handles.data.h_period_slider = patch(x_p,y_p,z_p,[0.5 0.5 0.5],'FaceAlpha',0.2);
set(handles.ax3D,'climmode','manual')
end