% Main_WC_script.m

% Run the suite of codes over the WindCubes to update data, calculations,
% and plots.
% 
% By:           Paul T. Quelet
% Last updated: 18 June 2015
%
%

%% I. Clear things out for a fresh start:

clear       % All variables
close all   % All figures
clc         % Clear the command window

%% II. Set user defined parameters:

% Echo to the user:

str_user_def_params                 = [ 'Set user defined parameters.', char(10) ];
disp( str_user_def_params ) ;

% Set the main home directory:

main_dir                            = 'E:\XPIA_Research\XPIA_Dataviewer_Matlab_Plot_Codes\WLS7\' ; 

% Wind Cube Numbers:
% 1 is WC49 v1
% 2 is WC61 v1
% 3 is WC68 v1
% 4 is WC16 v2

WC_nums                             = 2 : 4 ; 

% Averaging period in minutes:

avg_prd_minutes                     = 2 ; % The default is 2-minutes, which has become the CU standard

% Months of data plotted over:
% 2 is Feb., 3 is March, 4 is April, etc.

month_num                           = 3 ; 

%% III. Set the Flags (On/Off):

% Scripts:

flag_read_WC_data                   = 1 ; % Read in new WC data this time? (1 = yes, 0 = no)

flag_perform_WC_calc                = 0 ; % Recalculate the WC related meteorological variables ? (1 = yes, 0 = no)

flag_plot_daily_contour             = 0 ; % Make new plots of contours? (1 = yes, 0 = no)

% Particular Plots or plot options:

flag_I_Data_Avail_make_plot         = 0 ; % Make Turbulence Intensity and Availability Plot this time? (1 = yes, 0 = no)

flag_WS_WDir_make_plot              = 0 ; % Make Wind Speed & Wind Direction Plot this time? (1 = yes, 0 = no)

flag_I_Data_Avail_6_Panel_make_plot = 1 ; % Make Turbulence Intensity and Availability 6 Panel Plot this time? (1 = yes, 0 = no)

flag_WS_WDir_6_Panel_make_plot      = 1 ; % Make Wind Speed & Wind Direction 6 Panel Plot this time? (1 = yes, 0 = no)

flag_6_Panel_single_cbars           = 0 ; % Make 6 Panel Plots with single colorbars? (1 = yes, 0 = no)

%% IV. Set script Input and Output Directories:

flag_file_or_dir                    = 'dir' ; % 'file' or 'dir' for single file or entire directory

flag_sta_or_rtd                     = 'rtd' ; % 'sta'  or 'rtd' for types of files read in

flag_v2_std_or_mc                   = 'mc' ; % 'std' for standard files (no motion compensation), 'mc' for normal motion compensated files

% Setup the input directory depending upon the data type and file structure:

switch flag_sta_or_rtd
    case 'sta'
        inDir_load                  = main_dir ;
    case 'rtd'
        % http://www.mathworks.com/matlabcentral/answers/39435-find-if-a-folder-already-exists-and-act-depending-on-the-result
        folder_name_1               = fullfile( 'C:\Users\Paulster\Documents\' ) ;
        folder_name_2               = fullfile( 'C:\Users\paqu8639\Documents\' ) ;
        if     exist( folder_name_1 , 'dir' )
            inDir_load              = 'C:\Users\Paulster\Documents\' ;
        elseif exist( folder_name_2 , 'dir' )
            inDir_load              = 'C:\Users\paqu8639\Documents\' ;
        else
            error( 'Folder with RTD data not found on current system C: drive.' ) ; 
        end
end

outDir_load                         = strcat( main_dir , 'WC_load_output\'      ) ; 

% Calculations Input Values:

inDir_calc                          = strcat( main_dir , 'WC_load_output\'      ) ; 

outDir_calc                         = strcat( main_dir , 'WC_calc_output\'      ) ; 

% Daily contour plot Input Values:

inDir_daily_pcolor                  = strcat( main_dir , 'WC_calc_output\'      ) ; 

outDir_daily_pcolor                 = strcat( main_dir , 'WC_dataviewer_plots\' ) ;

%% V. Load WC Data:

if flag_read_WC_data == 1
    
    str_load_WC_data = [ 'Load Wind Cube Data...', char(10) ];
    disp( str_load_WC_data ) ;
    
    if     isequal( WC_nums , 2 : 4 ) % If all three wind cubes are in the file...
        load_WLS7_WLS866( inDir_load , outDir_load , WC_nums , flag_file_or_dir , flag_sta_or_rtd , flag_v2_std_or_mc ) ;
    elseif isequal( WC_nums , 2 : 3 )  % If two wind cubes are in the file...
        load_WLS7_WLS866( inDir_load , outDir_load , WC_nums , flag_file_or_dir , flag_sta_or_rtd , flag_v2_std_or_mc ) ;
    elseif isequal( WC_nums , 4     )  % If one wind cube is in the file...
        load_WLS7_WLS866( inDir_load , outDir_load , WC_nums , flag_file_or_dir , flag_sta_or_rtd , flag_v2_std_or_mc ) ;    
    else
        error( 'No read in configuration for such a choice of windcube numbers.' ) ;
    end
    
end

%% VI. Calculate WC Variables:

if flag_perform_WC_calc == 1
    
    str_calc_vars = [ 'Calculating variables...', char(10) ];
    disp( str_calc_vars ) ;
    
    WC_calc( inDir_calc , outDir_calc , WC_nums , avg_prd_minutes , flag_v2_std_or_mc ) ;
    
end

%% VII. Create Daily Contour Plots:

if flag_plot_daily_contour == 1
    
    str_daily_cont_plots = [ 'Generate daily contour plots...', char(10) ];
    disp( str_daily_cont_plots ) ;
    
    WC_daily_pcolor( inDir_daily_pcolor , outDir_daily_pcolor , ...
                        WC_nums , avg_prd_minutes , flag_v2_std_or_mc , month_num , ...
                        flag_I_Data_Avail_make_plot , flag_WS_WDir_make_plot , flag_I_Data_Avail_6_Panel_make_plot , flag_WS_WDir_6_Panel_make_plot , flag_6_Panel_single_cbars ) ;
    
end

%% VIII. End of the Script

% end