% Procedure: PrintCollapseRiskForAPeriodForEpsilonAndNonEpsilonGMSets.m
% -------------------
% This procedure simply opens the results file and prints the P[col | 2 in
% 50] and MAF of Collapse (for both the non-epsilon set and the epsilon set
% selected based on that period).  The function also return the results,
% but we are not using the results in the main script right now.
%
% I checked this function against what is in the files
% and it is returning the information correctly!
%
% Author: Curt Haselton 
% Date Written: 9-28-05
%
% Sources of Code: Some information was taken from Paul Cordovas processing file called "ProcessData.m".
%
% Functions and Procedures called: none
%
% Variable definitions: 
%
% Units: Whatever OpenSees is using - just be consistent!
%
% -------------------
function[probOfCollapse_nonEpsilonSet, mafOfCollapse_nonEpsilonSet, probOfCollapse_epsilonSet, mafOfCollapse_epsilonSet] = PrintCollapseRiskForAPeriodForEpsilonAndNonEpsilonGMSets(currentPeriodIndex, currentPeriodForColRiskCalcs, outputFolderName);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Open the file that has the fitten lognormal collapse CDF for the IM of this period
% (for all EQ sets)
    % Go to the output folder
    currentDir = [pwd];
    cd ..;
    cd ..;
    cd Output;
    cd(outputFolderName);
    
    % Make the file name and open the file
    fileName = sprintf('CollapseProbAndMAF_IMUsedAtT=%.2f.mat', currentPeriodForColRiskCalcs);
    load(fileName);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Print the P[col | 2 in 50] and MAF of Collapse for the non-epsilon set
% (i.e. index 1) and epsilon sets
    % Display the period
    currentPeriodForColRiskCalcs;
    temp = sprintf('Period fof record selection: T = %.2f...', currentPeriodForColRiskCalcs);
    disp(temp);

    % Non-epsilon set
    nonEpsilonSetIndex = 1; % i.e. this set is the first in the list
    probOfCollapse_nonEpsilonSet = probOfCollapseAtTwoPercentInFifty_AllGMSetsForCurrentPeriod(nonEpsilonSetIndex);
    mafOfCollapse_nonEpsilonSet = MAFofCollapse_AllGMSetsForCurrentPeriod(nonEpsilonSetIndex);
    disp('Non-epsilon set:')
    temp1 = sprintf('P[col | 2 in 50] = %.3f', probOfCollapse_nonEpsilonSet);
    disp(temp1);
    temp2 = sprintf('MAF[col] = %.8f', mafOfCollapse_nonEpsilonSet);
    disp(temp2);    

    % Epsilon set for this period
    probOfCollapse_epsilonSet = probOfCollapseAtTwoPercentInFifty_AllGMSetsForCurrentPeriod(currentPeriodIndex);
    mafOfCollapse_epsilonSet = MAFofCollapse_AllGMSetsForCurrentPeriod(currentPeriodIndex);
    disp('Epsilon selected set:')
    temp1 = sprintf('P[col | 2 in 50] = %.3f', probOfCollapse_epsilonSet);
    disp(temp1);
    temp2 = sprintf('MAF[col] = %.8f', mafOfCollapse_epsilonSet);
    disp(temp2);    

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Back to the original folder
cd(currentDir);

