function WCs_avail_profile( inDir , outDir , WC_nums , avg_pd_min , flag_v2_std_or_mc , flag_act_hgts_or_equal_bars )
%WCs_horiz_avail_profile Uses a horizontal bar chart to plot the
%availability of the WCs in the vertical.
%   Uses a horizontal bar chart to plot the availability of the WCs in the vertical.

% Author: Paul T. Quelet
% 
% Last Update Noted: 21 April 2015
% 
% Made with Matlab 2014b
% IMPORTANT NOTE: GRAPHICS WILL NOT WORK WITH EARLIER VERSIONS OF CODE
% 
% Example function call:
% WCs_avail_profile( 'E:\XPIA_Research\XPIA_Dataviewer_Matlab_Plot_Codes\WLS7\WC_calc_output\' , 'E:\XPIA_Research\XPIA_Dataviewer_Matlab_Plot_Codes\WLS7\WC_calc_output\' , 2 : 4 , 2 , 'mc' , 'act_hgts' )
%
% =============================================================================================
% INPUT                         DESCRIPTION                            TYPE        UNITS
% ---------------------------------------------------------------------------------------------

% inDir                         Input directory                         string      (none)
% outDir                        Output directory                        string      (none)
% WC_nums                       Wind Cube Numbers                       double      (none)
% avg_pd_min averaging period                                           double      [minutes]
% flag_v2_std_or_mc             'std' for standard files                string
%                               'mc'  for motion compensated files (normal)
% flag_act_hgts_or_equal_bars   'act_hgts' for actual heights           string
%                               'equal_bars' for equally sized bars     
% =========================================================================

%% Set WindCube Parameters

fss                                 = 'FontSize';

fontsize                            = 16 ;

curr_exper_abbr                     = 'XPIA' ;

% Other experiments string abbreviations include the following:
% 'BLADE' , 'NWTC' , 'CWEX11' , 'TWICS' , 'TODS' , 'CWEX13' , 'LUMEX'

%% Load relvant data from WindCubes

for j_wc = WC_nums
    
    % Assign information base upon Wind Cube Number:
    
    switch j_wc
        case 1
            WCnum                   = 49 ;
            WCnum_str               = num2str( WCnum ) ;
        case 2
            WCnum                   = 61 ;
            WCnum_str               = num2str( WCnum ) ;
        case 3
            WCnum                   = 68 ;
            WCnum_str               = num2str( WCnum ) ;
        case 4
            WCnum                   = 16 ;
            WCnum_str               = num2str( WCnum ) ;
    end
    
    load( strcat( inDir , curr_exper_abbr , '_' , WCnum_str, '_' , num2str( avg_pd_min ) , 'min_avg_' , flag_v2_std_or_mc , '.mat' ) )
    
    % Get the relevant variables and store from each WindCube
    
    switch j_wc
        case 1
%             Avail_49                = Avail ;
%             dn_49                   = datenum( double( WC_datevec ) ) ;
%             alt_49                  = alt ; 
        case 2
            Avail_61                = Avail ;
            % dn_61                   = datenum( double( WC_datevec ) ) ;
            alt_61                  = alt ; 
        case 3
            Avail_68                = Avail ;
            % dn_68                   = datenum( double( WC_datevec ) ) ;  
            % alt_68                  = alt ; 
        case 4
            Avail_16                = Avail ;
            % dn_16                   = datenum( double( WC_datevec ) ) ;  
            alt_16                  = alt ; 
    end
    
end % (j_wc) End loop over WindCube Numbers

%% Calculate average availability

% Take the mean over the columns to have 1 x num_heights values (use nanmean in case there are any NaN):

mean_Avail_61                    = nanmean( Avail_61 , 1 ) ; 
mean_Avail_68                    = nanmean( Avail_68 , 1 ) ; 
mean_Avail_16                    = nanmean( Avail_16 , 1 ) ; 

%% Create Vertical Heights Profile

if     strcmp( flag_act_hgts_or_equal_bars , 'act_hgts' ) == 1

heights_profile = [alt_61( 1 )      ; alt_16( 2 )  ; ... %  40m                         then  50m, WC 16
                   alt_61( 2 : 6  ) ; alt_16( 8 )  ; ... %  60m,  80m, 100m, 120m, 140m then 150m, WC 16  
                   alt_61( 7 : 10 ) ;            ] ;     % 160m, 180m, 200m, 220m

elseif strcmp( flag_act_hgts_or_equal_bars , 'equal_bars' ) == 1
    
   heights_profile = linspace( 40 , 260 , 12 )' ; % 40m to 260m by 20m increments, but "mislabel" to what the heights really are 

end
               
%% Create Vertical Profile Matrix

% Want to have a matrix corresponding to unique heights in the rows but WC's in the columns
% Matrix should be 12 x 3 for now, given specfied heights and WCs

mean_Avail_matrix = [ mean_Avail_61( 1 )'     , mean_Avail_68( 1 )'     , mean_Avail_16( 1 )'       ; ... %  40m
                      NaN                     , NaN                     , mean_Avail_16( 2 )'       ; ... %  50m
                      mean_Avail_61( 2 : 6 )' , mean_Avail_68( 2 : 6 )' , mean_Avail_16( 3 : 7  )'  ; ... %  60m,  80m, 100m, 120m, 140m 
                      NaN                     , NaN                     , mean_Avail_16( 8 )'       ; ... % 150m
                      mean_Avail_61( 7 : 9 )' , mean_Avail_68( 7 : 9 )' , mean_Avail_16( 9 : 11 )'  ; ... % 160m, 180m, 200m 
                      mean_Avail_61( 10 )'    , mean_Avail_68( 10 )'    , NaN                        ] ;  % 220m 
                     
%% Create mean Horizontal Bar Chart

% Initialize a new figure maximized with a name:
                
figure1                             = figure( 'Name' , 'WCs_avail_profile_mean' , 'units' , 'normalized' , 'outerposition', [ 0 0 1 1 ]);

% Create the axes:

axes1                               = axes( 'Parent',figure1 );


% Create the horizontal bar chart:

hand_bar_chart                      = barh( heights_profile , mean_Avail_matrix , 'hist') ;

% Set colors based on handle (Matlab 2014b and further style)

hand_bar_chart(1).FaceColor         = 'r' ; % WC61
hand_bar_chart(2).FaceColor         = 'b' ; % WC68
hand_bar_chart(3).FaceColor         = 'g' ; % WC16

hand_bar_chart(1).EdgeColor         = 'k' ; % WC61
hand_bar_chart(2).EdgeColor         = 'k' ; % WC68
hand_bar_chart(3).EdgeColor         = 'k' ; % WC16

% Create axes:

y_min_fig                           = 30 ;
if     strcmp( flag_act_hgts_or_equal_bars , 'act_hgts' ) == 1
    y_max_fig                       = 230 ;
    ylim( [ y_min_fig y_max_fig ] ) ;
elseif strcmp( flag_act_hgts_or_equal_bars , 'equal_bars' ) == 1
    y_max_fig                       = 270 ;
    set( axes1 , 'YTickLabel', { '40','50','60','80','100','120','140','150','160','180','200','220' },...
                 'YTick'     , [  40 60 80 100 120 140 160 180 200 220 240 260 ] ) ;
	ylim( [ y_min_fig y_max_fig ] ) ;
end

% Put the box on:
box( axes1, 'on' ) ;

% Create xlabel
xlabel( 'Percent Available', fss , fontsize ) ;

% Create ylabel
ylabel( 'Measurement Heights [m]', fss , fontsize  ) ;

% Create title
title('WCs Percent Available vs. Height', fss , fontsize );

% Create legend ordered other way around labels:

legend_labels_list_strs             = { 'WC61 (NCAR)' 'WC68 (CU)' 'WC16 (NRG)' }; % legend labels list
legend_order                        = [3 2 1];
hand_leg                            = legend( hand_bar_chart( legend_order ) , legend_labels_list_strs{ legend_order } ) ;
set( hand_leg , fss , fontsize ) 

%% Save mean Horizontal Bar Chart

% Save the plot created:

saveas( gcf , strcat( outDir , strcat( 'WCs_avail_profile_mean_' , flag_act_hgts_or_equal_bars ) ) , 'png' ) ;

end % End of the WCs_avail_profile function