function [hrstr] = get_str_avg(minstr)
%
% get hourly average from nominally 1 minute data
% minstr must contain mday and must not contain
% direction (use vectors (md2vect) instead)
% 20080729:
% to do 2-minute data, move the creation of the
% 2-d array to the top, and interp that first.

onemin = 1/(60 * 24);
mday=minstr.mday;
pts=1:length(mday);
fno=fieldnames(minstr);
inarr=ones(length(mday),length(fno));
for i=1:size(fno,1)
    field_name=fno{i};
    cmd=[...
        'inarr(:,' num2str(i) ')=  minstr.' field_name '(pts);' ];
    % disp(['cmd is ' cmd])
    eval(cmd);
end

% grid/interp to 1 minute
% yi = interp1(x,Y,xi,method)
myd = minstr.mday(pts(1)):onemin:minstr.mday(pts(end));
% fprintf('length myd %d size m
warning off all
min_arr=interp1(minstr.mday,inarr, myd,'linear');
warning on all
dv=datevec(myd);  % size of dv is npts,6
% number of points

np = length(myd);
if (np  < 60),
    fprintf('less than an hour, cannot average\n');
    hrstr = [];
else
    % find first,last, to have actual hourly averages
    stp=find(dv(:,5) == 0,1,'first');
    ept=find(dv(:,5) == 59,1,'last');
    pts=stp:1:ept;
    if (length(pts)  < 60),
        fprintf('less than an hour, cannot average\n');
        hrstr = [];
    else
        % fprintf('start %d end %d length\n',stp,ept,length(pts));
        % truncate all the fields, place into an array
        % want the data array to be [np,nv] = size(dd);
        min_arr=min_arr(pts,:);

        % now have truncated minute data, get hourly values
        [np,nv] = size(min_arr);
        nhrs = floor(np/60);
        npts=nhrs*60;

        hr_arr=ones(nhrs,nv);
        %hryday = reshape(myd(1:npts),60,nhrs);
        for ii=1:nv,
            vv=min_arr(1:npts,ii);
            tmp = reshape(vv,60,nhrs);
            hr_arr(:,ii) = mean(tmp)';
        end
        % now, back to a struct
        for i=1:size(fno,1)
            field_name=fno{i};
            cmd=['hrstr.' field_name ' =  hr_arr(:,' num2str(i) ');' ];
            eval(cmd);
        end
        % does not work:hrstr.yday=mean(hryday)';
    end
end



