%
% function sm_data = calc_season_mean(data,textdata,monthdate)
% calculate seasonal mean
%
function sm_data = calc_season_mean(data,textdata,monthdate)

for ii = 1:length(textdata)
    dates(ii) = str2num(textdata{ii});
end
[newdates1,ind1] = sort(dates);
newdata1 = data(ind1,:);

mo = numel(monthdate)-1;
meso = size(data,2);
sm_data = nan(mo,meso);

for ii = 1:meso
    newdata = newdata1(:,ii);
    ind = find(~isnan(newdata));
    newdata = newdata(ind);
    newdates = newdates1(ind);
    for im = 1:mo
        index = find(newdates >= monthdate{im} & newdates < monthdate{im+1});
        sm_data(im,ii) = mean(newdata(index));
    end
end

return