% This is the foward model for calculating postseismic time-series. Models rate-state 
% friction afterslip (using hot friction approximation) with the option of
% including distributive viscous flow at depth below an elastic plate --
% note the stresses in the elastic plate due to viscous flow are not
% coupled to slip on the fault (this can be done but requires some more
% coding)
%
% NOTE: uncomment the line under "viscoelastic relaxation" if you want to
% include viscous flow and uncomment the line under "with viscous flow" and
% comment out the line under "without viscous flow"

%define number of afterslip patches and number of sites
nafterpatches=size(pm,1);
numsites=size(xysites,1);

%coseismic stress change
costress=stressG*coslip;

%afterslip
[allslips,alltimes]=get_slip_hotfriction(prerate,costress,nafterpatches,stressG,stopt,sigAmB);

%viscoelastic relaxation -- Ux,Uy,Uz are displacements in x,y,z directions
%[Ux,Uy,Uz]=get_viscous_multitimes(coslip,H,stopt,tR,xysites',pm);

%construct the modeled time-series --NOTE: this solves for annual and
%   semi-annual seasonal noise terms - this can be turned off for any site
%   in the code by changing the parameter NOTcontinuous
%with viscous flow
[dhat_series,dhatseries]=get_dhat_series_withflow(codisps,east_pos,north_pos,up_pos,inter_east,inter_north,inter_up,teq,allslips,dispG,alltimes,InvertSeries,Ux,Uy,Uz,stopt)
%without viscous flow
%[dhat_series,dhatseries]=get_dhat_series_noflow(codisps,east_pos,north_pos,up_pos,inter_east,inter_north,inter_up,teq,allslips,dispG,alltimes,InvertSeries)


%Finally, plot the time-series and the model
plot_series_fit

