%data should come in 2 column format, where 2nd column is counts and 1st is dates
function out = fillingap(data)

[rows cols] = size(data);
out = [];
for i=1:rows-1
    if dategapdetection(data(i,1),data(i+1,1))==1
        miss_dates = nogapcalendar(data(i,1),data(i+1,1));
  %      index_now = (1:i)';
        index_miss = (1:length(miss_dates))';
  %      X = [ones(i,1)  exp(- index_now)  index_now.*exp(- index_now)];
  %      coeff=X\data(1:i,2)
  %      new_values = floor([ones(size(index_miss))  exp(- index_miss) index_miss.*exp(- index_miss)]*coeff);
        trend = (data(i+1,2) - data(i,2))/(length(miss_dates)+1);
        new_values = floor(ones(size(index_miss))*data(i,2)+index_miss*trend);
        out = [out; miss_dates new_values];
    else
        out = [out;data(i,:)];
    end;
    
end;
figure;
plot(out(:,2));
findperiod(out);