No BSD License  

Highlights from
WEACLIM

from WEACLIM by Vincent Moron
WEACLIM analyses, transforms and generate daily time series (of rainfall) for downscaling studies

[x_rand]=swg(choice,value,n,p01,p11,param,nsim,out);
function [x_rand]=swg(choice,value,n,p01,p11,param,nsim,out);

% [x_rand]=swg(choice,value,n,p01,p11,param,thres,nsim,out);
% 
% Stochastic Weather Generator for rainfall (first-order markov chain is 
% used to generate the occurence of rainfall and gamma distribution to 
% simulate rain amounts during wet days). 
%
% Inputs
% 'choice' ; 'gamma', 'weibull' or 'mixed_exponential';
% 'value' : real number to initiate the random sequence (if > 0, the seeds
% is initiated to the value; otherwise, it is changed from the clock)
% 'n' : integer number = length of simulated time series 
% 'p01' and 'p11' : real number that are respectively the
% probability transition from state 0 to state 1 and the persistance of
% state 1 
% 'param' : vector of two real number giving the shape and scale parameters 
% of the gamma distribution (if choice ='gamma'), vector of three real
% number giving the parameters of the mixed exponential distribution (alpha
% and two means) if choice='mixed_exponential', and vector of two real 
% number giving the shape and scale parameters of weibull distribution
% (if choice ='weibull').
% 'nsim' : integer number = number of simulation. 
% 'out' : character string = name of the output file
%
% Outputs
% 'x_rand' : matrice of n rows and nsim columns giving the simulated
% sequences
%
% Vincent Moron
% November 2004
% revision 1 (nov 2005) : the random is changed into 'seed' method

if(value>0);
    rand('seed',value);
    randn('seed',value);
else
    rand('seed',sum(100*clock));
    randn('seed',sum(100*clock));
end

[x_rand]=markov_chain_1(value,n,p01,p11,nsim);

% simulation of the quantity of rainfall
for i=1:nsim
    a=find(x_rand(:,i)==1);
    if strcmp(choice,'gamma');
        ZZ=gamrnd(param(1),param(2),length(a),1);
    elseif strcmp(choice,'mixed_exponential');
        ZZ=mixed_exp_rnd(value,length(a),param(1),param(2),param(3));
    elseif strcmp(choice,'weibull');
        ZZ=wblrnd(param(2),param(1),length(a),1);
    end
    x_rand(a,i)=ZZ;
end

write_ascii(out,x_rand);


        
    

Contact us at files@mathworks.com