function [dhat_series,dhatseries]=get_dhat_series_noflow(codisps,east_pos,north_pos,up_pos,inter_east,inter_north,inter_up,teq,allslips,seriesG,alltimes,invertSERIES)

%OUTPUTS:
%dhatseries is vector with all the time-series data. For example, if there
%   are N sites and m observations per site then dhatseries is a 3*N*m x 1
%   vector (the 3 is for the three components (east,north,up). dhatersies is
%   then of the form (m east positions,m north positions, m up positions, ...)
%dhat_series is a 3*numsites cell array of model time-series --
%   dhat_series{3*k-2} are east positions, dhat_series{3*k-1} are north
%   positions, and dhat_series{3*k} are up positions

%INPUTS:
%codisps is 2*numsites x 1 vector of coseismic displacements
%east_pos, north_pos, up_pos are numsites x 1 vectors of positions before
%   the earthquake -- note use NaN if the position before the earthquake
%   is not known and this program will solve for the initial position
%east_pos, north_pos, up_pos are numsites x 1 vectors of positions before
%   the earthquake
%inter_east, inter_north, inter_up are numsites x 1 vectors of positions before
%   the earthquake


%cumslip is cumulative slip at every time incremement
cumslip=cumsum(allslips,2);

for k=1:size(cumslip,2); disps(:,k)=seriesG*cumslip(:,k); end

east_pos_temp=east_pos;index=isnan(east_pos_temp);east_pos_temp(index)=0;
north_pos_temp=north_pos;index=isnan(north_pos_temp);north_pos_temp(index)=0;
up_pos_temp=up_pos;index=isnan(up_pos_temp);up_pos_temp(index)=0;
for k=1:size(seriesG,1)/3
    dhat_series{3*k-2}=codisps(3*k-2)+east_pos_temp(k)+(invertSERIES{k,1}(:,1)-teq)*inter_east(k)+interp1(alltimes,disps(3*k-2,:),invertSERIES{k,1}(:,1)-teq);
    dhat_series{3*k-1}=codisps(3*k-1)+north_pos_temp(k)+(invertSERIES{k,2}(:,1)-teq)*inter_north(k)+interp1(alltimes,disps(3*k-1,:),invertSERIES{k,2}(:,1)-teq);   
    dhat_series{3*k}=codisps(3*k)+up_pos_temp(k)+(invertSERIES{k,3}(:,1)-teq)*inter_up(k)+interp1(alltimes,disps(3*k,:),invertSERIES{k,3}(:,1)-teq);   
end

%enter any sitenumbers here that are not continuous data and should not
%include seasonal terms -- for example, if the 3rd and 28th sites are
%campaign sites, enter NOTcontinuous=[3,28]
NOTcontinuous=[];


%calculate seasonal term coefficients
% A*sin(2*pi*t)+B*cos(2*pi*t)+C*sin(4*pi*t)+D*cos(4*pi*t)
for k=1:size(seriesG,1)/3
    d_temp1=invertSERIES{k,1}(:,2);  %east component
    d_temp2=invertSERIES{k,2}(:,2);  %north component
    d_temp3=invertSERIES{k,3}(:,2);  %up component
    times1=invertSERIES{k,1}(:,1)-teq;
    times2=invertSERIES{k,2}(:,1)-teq;
    times3=invertSERIES{k,3}(:,1)-teq;
    dhat_temp1=dhat_series{3*k-2};
    dhat_temp2=dhat_series{3*k-1};
    dhat_temp3=dhat_series{3*k};
    
    if sum(k==NOTcontinuous)>0
    
        G1=ones(size(dhat_temp1));
        G2=ones(size(dhat_temp2));
        G3=ones(size(dhat_temp3));
        if isnan(east_pos(k))
            coeffs1=G1\(d_temp1-dhat_temp1);
        else
            coeffs1=0;
        end
        if isnan(north_pos(k))
            coeffs2=G2\(d_temp2-dhat_temp2);
        else
            coeffs2=0;
        end
        if isnan(up_pos(k))
            coeffs3=G3\(d_temp3-dhat_temp3);
        else
            coeffs3=0;
        end
    
    else
        
        if isnan(east_pos(k))
            G1=[ones(size(dhat_temp1)) sin(2*pi*times1) cos(2*pi*times1) sin(4*pi*times1) cos(4*pi*times1)];
        else
            G1=[sin(2*pi*times1) cos(2*pi*times1) sin(4*pi*times1) cos(4*pi*times1)];
        end
        if isnan(north_pos(k))
            G2=[ones(size(dhat_temp2)) sin(2*pi*times2) cos(2*pi*times2) sin(4*pi*times2) cos(4*pi*times2)];
        else
            G2=[sin(2*pi*times2) cos(2*pi*times2) sin(4*pi*times2) cos(4*pi*times2)];
        end    
        if isnan(up_pos(k))
            G3=[ones(size(dhat_temp3)) sin(2*pi*times3) cos(2*pi*times3) sin(4*pi*times3) cos(4*pi*times3)];
        else
            G3=[sin(2*pi*times3) cos(2*pi*times3) sin(4*pi*times3) cos(4*pi*times3)];
        end    
        coeffs1=G1\(d_temp1-dhat_temp1);
        coeffs2=G2\(d_temp2-dhat_temp2);
        coeffs3=G3\(d_temp3-dhat_temp3);
    
    end
  
    
    dhat_series{3*k-2}=dhat_series{3*k-2}+G1*coeffs1;
    dhat_series{3*k-1}=dhat_series{3*k-1}+G2*coeffs2;
    dhat_series{3*k}=dhat_series{3*k}+G3*coeffs3;
    
   
  
end

dhatseries=[];


for k=1:size(seriesG,1); dhatseries=[dhatseries;dhat_series{k}];end


