function [hdata] =get_avg(dd);

% get hourly average from nominally 1 minute data
% not for directions, see avg_wind.m for those
% or use md2vect
% dd is [npts,nvar]

% number of points, number of variables
[np,nv] = size(dd);
if (np  < 60),
    fprintf('less than an hour, cannot average\n');
    hdata = [];
else,
    % first make sure you have 60 points per hour
    stp=min(find(dd(:,5) == 0));
    ept=max(find(dd(:,5) == 59));
    pts=stp:1:ept;
    if (length(pts)  < 60),
        fprintf('less than an hour, cannot average\n');
        hdata = [];
    else
        % fprintf('start %d end %d length\n',stp,ept,length(pts));

        dd=dd(pts,:);
        yday=datenum(dd(:,3),dd(:,1),dd(:,2),dd(:,4),dd(:,5),dd(:,6))...
            -datenum(dd(1,3),1,0);

        onemin = 1/(60 * 24);
        myd = yday(1):onemin:yday(end);        % minute yearday    (1439 points)
        minutedata=interp1(yday, dd, myd);     % minute data array (1439 points)

        %YI = INTERP1(X,Y,XI)

        % now have minute data, get hourly values

        [np,nv] = size(minutedata);
        nhrs = floor(np/60);
        npts=nhrs*60;

        hdata=ones(nhrs,nv-5);
        tmp = reshape(myd(1:npts),60,nhrs);
        hdata(:,1) = mean(tmp)';
        for ii=1:nv-6,
            vv=minutedata(1:npts,ii+6);
            tmp = reshape(vv,60,nhrs);
            hdata(:,ii+1) = mean(tmp)';
        end
    end
end

