% Function: ComputeSigmaLnSaColForEQListAndPeriodListAndFindOptPeriod.m
% -------------------
% This function loops and computes the sigmaLn of the Sa,col for a list of
% EQs and a list of periods.  It also returns the period with the lowest
% sigmaLn(Sa,col) and the asscociated lowest sigmaLn.
%
% Author: Curt Haselton 
% Date Written: 9-26-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[SaCol_sigmaLn_LIST, periodWithLowestSigmaLn, smallestSigmaLn] = ComputeSigmaLnSaColForEQListAndPeriodListAndFindOptPeriod(currentEQRecordLIST, periodLIST, currentDampRatToUseForSaCol, originalTOneUsedWhenAnalysesWereRun, originalDampRatForSaTOneUsedWhenAnalysesWereRun, outputFolderName)

% Initialize results
    SaCol_sigmaLn_LIST = zeros(1, length(periodLIST));
    periodWithLowestSigmaLn = -1.0;;    
    smallestSigmaLn = 10000.0;   % Just large, so it will be replaced when a smaller value is found

% Loop for the periods and compute the sigmaLn(Sa,col) for each period
    for periodIndex = 1:length(periodLIST)
        currentPeriodToUseForSaCol = periodLIST(periodIndex)
        
        % Retrieve the sigmaLn for this period...
        [SaCol_mean, SaCol_sigma, SaCol_COV, SaCol_median, SaCol_meanLn, SaCol_sigmaLn] = ComputeStatsForSaColForAListOfEQsAndAPeriod(currentEQRecordLIST, currentPeriodToUseForSaCol, currentDampRatToUseForSaCol, originalTOneUsedWhenAnalysesWereRun, originalDampRatForSaTOneUsedWhenAnalysesWereRun, outputFolderName);

        % Save the result in the vector for all periods
        SaCol_sigmaLn_LIST(periodIndex) = SaCol_sigmaLn;
        
        % If the current sigmaLn is lower that the lowest before, then save
        % the results for this period
        if(SaCol_sigmaLn < smallestSigmaLn)
            smallestSigmaLn = SaCol_sigmaLn;
            periodWithLowestSigmaLn = currentPeriodToUseForSaCol;
        end

    end




