%   [T,m]=Max_credM_GRT(Td,Tu,dT,Mmin,lamb,eps,b,Mmax)

%EVALUATES THE MAXIMUM CREDIBLE MAGNITUDE VALUES USING THE UPPER-BOUNDED 
%   G-R LED MAGNITUDE DISTRIBUTION MODEL. 
%
% AUTHOR: S. Lasocki 06/2014 within IS-EPOS project.
%
% DESCRIPTION: The assumption on the upper-bounded Gutenberg-Richter 
% relation leads to the upper truncated exponential distribution to model 
% magnitude distribution from and above the catalog completness level 
% Mmin. The shape parameter of this distribution, consequently the G-R
% b-value and the end-point of the distriobution Mmax as well as the
% activity rate of M>=Mmin events are calculated at start-up of the 
% stationary hazard assessment services in the upper-bounded 
% Gutenberg-Richter estimation mode.
% 
% The maximum credible magnitude values are calculated for periods of 
% length starting from Td up to Tu with step dT.
%
% INPUT:
%   Td - starting period length for maximum credible magnitude calculations
%   Tu - ending period length for maximum credible magnitude calculations
%   dT - period length step for maximum credible magnitude calculations
%   Mmin - lower bound of the distribution - catalog completeness level
%   lamb - mean activity rate for events M>=Mmin
%   eps - length of the round-off interval of magnitudes.
%   b - Gutenberg-Richter b-value
%   Mmax - upper limit of magnitude distribution
%
% OUTPUT:
%   T - vector of independent variable (period lengths) T=(Td:dT:Tu)
%   m - vector of maximum credible magnitudes of the same length as T
%
% LICENSE
%     This file is a part of the IS-EPOS e-PLATFORM.
%
%     This is free software: you can redistribute it and/or modify it under 
%     the terms of the GNU General Public License as published by the Free 
%     Software Foundation, either version 3 of the License, or 
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 

function [T,m]=Max_credM_GRT(Td,Tu,dT,Mmin,lamb,eps,b,Mmax)

% -------------- VALIDATION RULES -------------  K_21NOV2016
 if dT<=0;error('Time Step must be greater than 0');end
%----------------------------------------------------------

T=(Td:dT:Tu)';
beta=b*log(10);
mian=(1-exp(-beta*(Mmax-Mmin+eps/2)));
m=Mmin-eps/2-1/beta*log((1-(1-1./(lamb*T))*mian));
end

