function [datehourconverted, discharge, byyear]=processMCFDQ(filename, titlename, cutoffforcolor)
%invoke me with 
% processMCFDQ('mkel.txt','ibw @ Mckellips',50)

[date,hour,gage,discharge]=textread(filename,'%s %s %f %f');

datehour=strcat(date, 'space',hour);
datehourclean=strrep(datehour,'space',' ');
datehourconverted=datenum(char(datehourclean))./365.24;

figure(1)
clf
plot(datehourconverted.*365.24, discharge, 'b-')
hold on
plot([min(datehourconverted.*365.24) max(datehourconverted.*365.24)], [cutoffforcolor cutoffforcolor],'k-')
datetick('x')
xlabel('year')
ylabel('discharge (cfs)')
title(titlename)
axis([min(datehourconverted.*365.24) max(datehourconverted.*365.24) 0 max(discharge)])


byyear=[];
number_of_years=floor(max(datehourconverted))-floor(min(datehourconverted))+1;
for i=1:number_of_years
year=floor(min(datehourconverted))+(i-1);
yearmatrix=floor(datehourconverted)==year;
yearloc=find(yearmatrix);
years=ones(length(yearloc),1).*year;
byyear=[byyear;[years,((datehourconverted(yearloc)-year).*365),discharge(yearloc)]];
end

figure(2)
clf
plot(byyear(:,2),byyear(:,3),'b.')
hold on 
plot([0 365], [cutoffforcolor cutoffforcolor],'k-')
xlabel('Day of year')
ylabel('discharge (cfs)')
title(titlename)
axis([0 365 0 max(byyear(:,3))])

figure(3)
clf
plot3(byyear(:,1),byyear(:,2),byyear(:,3),'b.')
xlabel('year')
ylabel('Day of year')
zlabel('discharge (cfs)')
title(titlename)
axis([min(byyear(:,1))-0.5 max(byyear(:,1))-0.5 0 365 0 max(byyear(:,3))])

figure(4)
clf
hold on
sizeyear=0.5;
sizepoy=1/(365*24*60/5); %should be 5 minutes
for i=1:length(byyear)
    y=[byyear(i,1)-sizeyear, byyear(i,1)-sizeyear, byyear(i,1)+sizeyear, byyear(i,1)+sizeyear];
    x=[byyear(i,2)-sizepoy, byyear(i,2)+sizepoy,byyear(i,2)+sizepoy,byyear(i,2)-sizepoy];
    z=[byyear(i,3),byyear(i,3),byyear(i,3),byyear(i,3)];
    if byyear(i,3)<=cutoffforcolor
        color='w';
    else
    color=byyear(i,3);
end
    patch(x,y,color, 'EdgeColor','none')
end
colormap jet
colorbar
axis([0 365 1987.5 2003.5])
ylabel('year')
xlabel('Day of year')
title([titlename,' Q>',num2str(cutoffforcolor),'cfs'])


