% by Quanwei Li
% 
% This script calls HFProbDist(t_ar) multiple times and writes data into
% files
% 
% h = HFProbDist(t_ar)
% 
% h returns the histogram data
% 
% t_ar: integration time in second
%
% See HFProbDist.m for the function details
%
% See Supplementary Information Section VII.A for Numerical simulation methodology

%%
% clear all; 
% clc;
f = get(0,'Format');
format short;

%% Define repeat number and integration time for each repeat
N = 2; % repeat numbers
Time = 1800; % integration time for each repeat (second)

%% For loop to call HFProbDist(t_ar) and write data into files
for i = 1:N
    t0 = clock;

    h_temp = HFProbDist(Time);

    % Results output
    filename_temp = sprintf('HFProbDist_HistResults_t_%d_s_%d',Time,i);
    ResultsName_temp = strcat(filename_temp,'.txt');
 
    fpout = fopen(ResultsName_temp,'W');
    fprintf(fpout,'%i\t%i\n', h_temp');
    fclose(fpout);

    fprintf('\nFinished %d of %d ...\nTime used:\t', i, N);
    t1 = etime(clock, t0);
    fprintf('%f (s).\n', t1);
end

fprintf('\n\nJob finished!\n\n');
