function draw_modsimrand_fig
%DRAW_MODSIMRAND_FIG Function to draw figure window for modsimrand function
%    DRAW_MODSIMRAND_FIG is executed from within modsimrand_plot callback function.
%
%   Draws a figure window with two axes plots to show PN sequence and
%   and corresponding histogram plots. The figure gets updated on each
%   invocation of modsimrand_plot.m callback function from within modelsim.

%   Copyright 2003-2009 The MathWorks, Inc.

%   Note that the contents of this file were extracted from
%   GUIDE generated modsimrand.m and tuned to our need.
%   

% draw modsimrand figure window and mark it visible

h1 = figure(...
    'Units','characters',...
    'CloseRequestFcn','modsimrand(''ModsimrandFig_CloseRequestFcn'',gcf,[],guidata(gcf))',...
    'Color',[0.831372549019608 0.815686274509804 0.784313725490196],...
    'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
    'DoubleBuffer','on',...
    'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
    'MenuBar','none',...
    'Name','modsimrand',...
    'NumberTitle','off',...
    'PaperPosition',get(0,'defaultfigurePaperPosition'),...
    'Position',[74 38 127 51],...
    'Visible','off',...
    'Renderer',get(0,'defaultfigureRenderer'),...
    'RendererMode','manual',...
    'Resize','off',...
    'Tag','ModsimrandFig',...
    'UserData',zeros(1,0));

% move it to onscreen location
movegui(h1); 
set(h1, 'Visible', 'on');

setappdata(h1, 'GUIDEOptions', struct(...
    'active_h', 1, ...
    'taginfo', struct(...
    'figure', 2, ...
    'axes', 3, ...
    'pushbutton', 6, ...
    'popupmenu', 3, ...
    'togglebutton', 2, ...
    'text', 7, ...
    'edit', 3, ...
    'frame', 2, ...
    'checkbox', 2), ...
    'override', 1, ...
    'release', 13, ...
    'resize', 'none', ...
    'accessibility', 'on', ...
    'mfile', 1, ...
    'callbacks', 1, ...
    'singleton', 1, ...
    'syscolorfig', 1));

h2 = axes(...
    'Parent',h1,...
    'ALim',get(0,'defaultaxesALim'),...
    'ALimMode','manual',...
    'CameraPosition',[0.5 0.5 9.16025403784439],...
    'CameraPositionMode','manual',...
    'CameraTarget',[0.5 0.5 0.5],...
    'CameraTargetMode','manual',...
    'CameraUpVector',[0 1 0],...
    'CameraUpVectorMode','manual',...
    'CameraViewAngle',6.60861036031192,...
    'CameraViewAngleMode','manual',...
    'CLim',get(0,'defaultaxesCLim'),...
    'CLimMode','manual',...
    'Color',get(0,'defaultaxesColor'),...
    'ColorOrder',get(0,'defaultaxesColorOrder'),...
    'DataAspectRatio',get(0,'defaultaxesDataAspectRatio'),...
    'DataAspectRatioMode','manual',...
    'PlotBoxAspectRatio',get(0,'defaultaxesPlotBoxAspectRatio'),...
    'PlotBoxAspectRatioMode','manual',...
    'Position',[0.0737833594976452 0.45166163141994 0.676609105180534 0.253776435045317],...
    'TickDir',get(0,'defaultaxesTickDir'),...
    'TickDirMode','manual',...
    'XColor',get(0,'defaultaxesXColor'),...
    'XLim',get(0,'defaultaxesXLim'),...
    'XLimMode','manual',...
    'XTick',[0 0.2 0.4 0.6 0.8 1],...
    'XTickLabel',{ '0  ' '0.2' '0.4' '0.6' '0.8' '1  ' },...
    'XTickLabelMode','manual',...
    'XTickMode','manual',...
    'YColor',get(0,'defaultaxesYColor'),...
    'YLim',get(0,'defaultaxesYLim'),...
    'YLimMode','manual',...
    'YTick',[0 0.2 0.4 0.6 0.8 1],...
    'YTickLabel',{ '0  ' '0.2' '0.4' '0.6' '0.8' '1  ' },...
    'YTickLabelMode','manual',...
    'YTickMode','manual',...
    'ZColor',get(0,'defaultaxesZColor'),...
    'ZLim',get(0,'defaultaxesZLim'),...
    'ZLimMode','manual',...
    'ZTick',[0 0.5 1],...
    'ZTickLabel','',...
    'ZTickLabelMode','manual',...
    'ZTickMode','manual',...
    'Tag','StartupPlot',...
    'UserData',999234);

h3 = get(h2,'title');

set(h3,...
    'Parent',h2,...
    'Color',[0 0 0],...
    'HorizontalAlignment','center',...
    'Position',[0.494047619047619 1.03869047619048 1.00005459937205],...
    'VerticalAlignment','bottom',...
    'HandleVisibility','off');

h4 = get(h2,'xlabel');

set(h4,...
    'Parent',h2,...
    'Color',[0 0 0],...
    'HorizontalAlignment','center',...
    'Position',[0.494047619047619 -0.139880952380953 1.00005459937205],...
    'VerticalAlignment','cap',...
    'HandleVisibility','off');

h5 = get(h2,'ylabel');

set(h5,...
    'Parent',h2,...
    'Color',[0 0 0],...
    'HorizontalAlignment','center',...
    'Position',[-0.172619047619048 0.491071428571429 1.00005459937205],...
    'Rotation',90,...
    'VerticalAlignment','bottom',...
    'HandleVisibility','off');

h6 = get(h2,'zlabel');

set(h6,...
    'Parent',h2,...
    'Color',[0 0 0],...
    'HorizontalAlignment','right',...
    'Position',[-1.06547619047619 2.15178571428571 1.00005459937205],...
    'HandleVisibility','off',...
    'Visible','off');

h8 = axes(...
    'Parent',h1,...
    'ALim',get(0,'defaultaxesALim'),...
    'ALimMode','manual',...
    'CameraPosition',[0.5 0.5 9.16025403784439],...
    'CameraPositionMode','manual',...
    'CameraTarget',[0.5 0.5 0.5],...
    'CameraTargetMode','manual',...
    'CameraUpVector',[0 1 0],...
    'CameraUpVectorMode','manual',...
    'CameraViewAngle',6.60861036031192,...
    'CameraViewAngleMode','manual',...
    'CLim',get(0,'defaultaxesCLim'),...
    'CLimMode','manual',...
    'Color',get(0,'defaultaxesColor'),...
    'ColorOrder',get(0,'defaultaxesColorOrder'),...
    'DataAspectRatio',get(0,'defaultaxesDataAspectRatio'),...
    'DataAspectRatioMode','manual',...
    'PlotBoxAspectRatio',get(0,'defaultaxesPlotBoxAspectRatio'),...
    'PlotBoxAspectRatioMode','manual',...
    'Position',[0.0737833594976452 0.0740181268882175 0.668759811616955 0.253776435045317],...
    'TickDir',get(0,'defaultaxesTickDir'),...
    'TickDirMode','manual',...
    'XColor',get(0,'defaultaxesXColor'),...
    'XLim',get(0,'defaultaxesXLim'),...
    'XLimMode','manual',...
    'XTick',[0 0.2 0.4 0.6 0.8 1],...
    'XTickLabel',{ '0  ' '0.2' '0.4' '0.6' '0.8' '1  ' },...
    'XTickLabelMode','manual',...
    'XTickMode','manual',...
    'YColor',get(0,'defaultaxesYColor'),...
    'YLim',get(0,'defaultaxesYLim'),...
    'YLimMode','manual',...
    'YTick',[0 0.2 0.4 0.6 0.8 1],...
    'YTickLabel',{ '0  ' '0.2' '0.4' '0.6' '0.8' '1  ' },...
    'YTickLabelMode','manual',...
    'YTickMode','manual',...
    'ZColor',get(0,'defaultaxesZColor'),...
    'ZLim',get(0,'defaultaxesZLim'),...
    'ZLimMode','manual',...
    'ZTick',[0 0.5 1],...
    'ZTickLabel','',...
    'ZTickLabelMode','manual',...
    'ZTickMode','manual',...
    'Tag','HistoPlot',...
    'UserData',zeros(1,0));

h9 = get(h8,'title');

set(h9,...
    'Parent',h8,...
    'Color',[0 0 0],...
    'HorizontalAlignment','center',...
    'Position',[0.49702380952381 1.03869047619048 1.00005459937205],...
    'VerticalAlignment','bottom',...
    'HandleVisibility','off');

h10 = get(h8,'xlabel');

set(h10,...
    'Parent',h8,...
    'Color',[0 0 0],...
    'HorizontalAlignment','center',...
    'Position',[0.49702380952381 -0.139880952380952 1.00005459937205],...
    'VerticalAlignment','cap',...
    'HandleVisibility','off');

h11 = get(h8,'ylabel');

set(h11,...
    'Parent',h8,...
    'Color',[0 0 0],...
    'HorizontalAlignment','center',...
    'Position',[-0.169642857142857 0.491071428571429 1.00005459937205],...
    'Rotation',90,...
    'VerticalAlignment','bottom',...
    'HandleVisibility','off');

h12 = get(h8,'zlabel');

set(h12,...
    'Parent',h8,...
    'Color',[0 0 0],...
    'HorizontalAlignment','right',...
    'Position',[-1.05059523809524 3.63988095238095 1.00005459937205],...
    'HandleVisibility','off',...
    'Visible','off');

h17 = uicontrol(...
    'Parent',h1,...
    'Units','characters',...
    'FontSize',10,...
    'HorizontalAlignment','left',...
    'ListboxTop',0,...
    'Position',[99.8 20.8461538461538 26 12],...
    'String',{ 'Plots the integer ' 'values produced ' 'during the first ' '2400 cycles after ' 'a reset.  ' '' },...
    'Style','text',...
    'Tag','text3');

h18 = uicontrol(...
    'Parent',h1,...
    'Units','characters',...
    'FontSize',10,...
    'HorizontalAlignment','left',...
    'ListboxTop',0,...
    'Position',[99.8 3.38461538461539 26 12.6923076923077],...
    'String',{ 'Plots the distribution' 'of values produced' 'by the generator after ' 'the startup period. ' 'This will approach' '(statistically) a flat' 'response for a good ' 'PN generator.' '' },...
    'Style','text',...
    'Tag','text4');

h19 = uicontrol(...
    'Parent',h1,...
    'Units','characters',...
    'FontSize',10,...
    'HorizontalAlignment','left',...
    'ListboxTop',0,...
    'Position', [8 41 90 7],...
    'Style','frame',...
    'Tag','text4');

h20 = uicontrol(...
    'Parent',h1,...
    'Units','characters',...
    'FontSize',10,...
    'HorizontalAlignment','left',...
    'ListboxTop',0,...
    'Position',[10 42 85 5],...
    'String',{ 'This example illustrates the mechanism of hooking up ModelSim with '...
               'MATLAB. Each invocation of ''modsimrand_plot'' callback function ' ...
               'from modelsim updates the following PN sequence and histogram plots' },...
    'Style','text',...
    'Tag','text4');


handles = guihandles(h1);

fixtag = get(handles.StartupPlot,'Tag');
axes(handles.StartupPlot);
plot([1 1]);
title('PN Sequence Startup');
xlabel('Time (# simulator steps)');
set(handles.StartupPlot,'Tag',fixtag);

fixtag = get(handles.HistoPlot,'Tag');
edges = linspace(0,2^32,26);
axes(handles.HistoPlot);
% bar(edges,zeros(1,26),'histc');
bar(edges,zeros(1,26),'histc')
title('Histogram of PN Sequence');
xlabel('Bins of generated random numbers');
set(handles.HistoPlot,'Tag',fixtag);

end




% --- Executes when user attempts to close ModsimrandFig.
function ModsimrandFig_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to ModsimrandFig (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure
delete(hObject);

end
