% Procedure: Driver_PlotSigmaLnSaColVSPeriodForMultRecordSets.m
% -------------------
% This procedure plots the sigmaLn(Sa,col) for multiple record sets and a
% list of periods.
%
% 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[void] = Driver_PlotSigmaLnSaColVSPeriodForMultRecordSets(outputFolderName, currentFundPeriodOfSDOF, originalTOneUsedWhenAnalysesWereRun, originalDampRatForSaTOneUsedWhenAnalysesWereRun, currentDampRatToUseForSaCol, periodLISTForCalcs, recordSetsLIST, periodThatRecordSetsWereSelectedForLIST, markerTypeForPlotsLIST_indivPoints, markerTypeForPlotsLIST_lognormalFit, legendEntriesLIST)


% Define the name of the output folder for the current analysis (I can do
% this in a loop later if needed)
%     outputFolderName = '(SDOF_EQandCycDisp_v.3)_(TOne_1.00,Duct_4.00,PostK_-0.10)';
%     currentFundPeriodOfSDOF = 1.0;
    
% Loop for all of the records and lists and 
    clear periodWithLowestSigmaLnLIST smallestSigmaLnLIST;

    for recordLISTIndex = 1:length(recordSetsLIST)
        currentEQRecordLIST = recordSetsLIST{recordLISTIndex};
        currentMarkerTypeForPlot = markerTypeForPlotsLIST_indivPoints{recordLISTIndex};

        % Call the function to compute for this record set
        [SaCol_sigmaLn_LIST, periodWithLowestSigmaLn, smallestSigmaLn] = ComputeSigmaLnSaColForEQListAndPeriodListAndFindOptPeriod(currentEQRecordLIST, periodLISTForCalcs, currentDampRatToUseForSaCol, originalTOneUsedWhenAnalysesWereRun, originalDampRatForSaTOneUsedWhenAnalysesWereRun, outputFolderName);
        
        % Plot the results for this record set
        PlotSigmaLnSaColVSNormalizedPeriod(SaCol_sigmaLn_LIST, periodLISTForCalcs, currentFundPeriodOfSDOF, currentMarkerTypeForPlot);
        hold on
        
        % Display/save results
        recordLISTIndex;
        periodLISTForCalcs;
        currentFundPeriodOfSDOF;
        SaCol_sigmaLn_LIST_allRecSets{recordLISTIndex} = SaCol_sigmaLn_LIST;
        periodWithLowestSigmaLnLIST(recordLISTIndex) = periodWithLowestSigmaLn;
        smallestSigmaLnLIST(recordLISTIndex) = smallestSigmaLn;

    end
    
    % Add the legend and hold off
    legend(legendEntriesLIST);
    
    % Save plot and the results
    currentFolder_temp = [pwd];
    cd ..;
    cd ..;
    cd Output;
    cd(outputFolderName);
    
        % Save the plot as a .fig file - THIS folder
        plotName = sprintf('SigmaLnVSPeriodForAllRecordSets.fig');
        hgsave(plotName);
        % Export the plot as a .emf file (Matlab book page 455) - THIS folder
        exportName = sprintf('SigmaLnVSPeriodForAllRecordSets.emf');
        print('-dmeta', exportName);
    
    hold off
    
    % Save results that were used for this plot
    fileName = sprintf('SigmaLnVSPeriodResults.mat');
    save(fileName, 'periodLISTForCalcs', 'currentFundPeriodOfSDOF', 'SaCol_sigmaLn_LIST_allRecSets', 'periodWithLowestSigmaLnLIST', 'smallestSigmaLnLIST', 'outputFolderName', 'recordSetsLIST', 'periodThatRecordSetsWereSelectedForLIST');
    
    cd(currentFolder_temp);
    
    

















