% GUIhist
% Function to create a histogram
% for the MODIS GUI
% Copyright by Jasmine S Nahorniak, Oregon State University.
% Feb 25 2000

function GUIhist(data);

GUIbutton('Pushbutton3','PLOTTING','on');

% find filename for title 
files=get(findobj('Tag','Listbox1'),'String');
choice=get(findobj('Tag','Listbox1'),'Value');
cellfile=files(choice,:);
classfile=class(cellfile);
if classfile(1:4)=='char'
  file=cellfile;
else
  file=cat(1,cellfile{:});  % convert to string
end
good=find(file~='_');  % remove underscores from filenames
file=file(good);

% extract selected data
histdata=data{choice};

% get the min and max values from the boxes
mindata=str2num(get(findobj('Tag','EditText1'),'String'));
maxdata=str2num(get(findobj('Tag','EditText6'),'String'));

% remove unwanted data for histogram
bad=find(histdata<mindata);
histdata(bad)=NaN;
bad=find(histdata>maxdata);
histdata(bad)=NaN;

szdata=size(histdata);

histdata=reshape(histdata,szdata(:,1)*szdata(:,2),1);
diffdata=abs(diff(histdata));
gooddiff=find(diffdata~=0);
mindiff=min(diffdata(gooddiff));
step=floor(((maxdata-mindata)/100)/mindiff)*mindiff;
if step==0,
   step=mindiff;
end 
nn=histc(histdata,[mindata:step:maxdata+step]);

figure
set(gcf,'Units','normalized','Position',[0.5 0 0.5 0.4])
set(gcf,'Tag','histfigure')
%hist(histdata,100)
bar([mindata:step:maxdata+step],nn,'histc')
title(file)

GUIbutton('Pushbutton3','histogram','off');
