| 1 | 
function DiagRun(varargin); | 
| 2 | 
 | 
| 3 | 
% Function: DiagRun | 
| 4 | 
% Author:   Daniel Enderton | 
| 5 | 
% | 
| 6 | 
% Input Fields: | 
| 7 | 
% | 
| 8 | 
%   Field        Type        (Brief) Description | 
| 9 | 
%   ----------------------------------------------------------------------- | 
| 10 | 
%   page         cell array  Experiment and plot information     (Required) | 
| 11 | 
%   pagename     string      Page name (title and output file)   (Required) | 
| 12 | 
% | 
| 13 | 
%   OutputDir    string      Output directory name               (Optional) | 
| 14 | 
%   LoadData     0/1         Load data                           (Optional) | 
| 15 | 
%   LoadGridData 0/1         Load grid data                      (Optional) | 
| 16 | 
%   DumpData     0/1         Save plotting data                  (Optional) | 
| 17 | 
%   SavePlots    0/1         Save plot                           (Optional) | 
| 18 | 
%   DiagDebug    0/1         Print debug flags                   (Optional) | 
| 19 | 
% | 
| 20 | 
% Descripton: | 
| 21 | 
%   This is the top level function of the cubed-sphere coupled-model | 
| 22 | 
%   diagnostics package.  The function guides the diagnostics through | 
| 23 | 
%   loading (including averaging and slicing) and then plotting of the | 
| 24 | 
%   data.  The defaults of the optional parameters are in DiagRunDefaults. | 
| 25 | 
% | 
| 26 | 
%   Sample function call is as follows (page and pagename appropriately | 
| 27 | 
%   defined): | 
| 28 | 
% | 
| 29 | 
%   >> DiagRun(page,pagename,'LoadData',1); | 
| 30 | 
%   >> DiagRun(page,pagename,'LoadData',1,'OutputDir','~/'); | 
| 31 | 
 | 
| 32 | 
 | 
| 33 | 
% Load DiagRun default parameters and general diagnostics parameters.  | 
| 34 | 
DiagRunDefaults; | 
| 35 | 
DiagGenParam; | 
| 36 | 
 | 
| 37 | 
 | 
| 38 | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 39 | 
%                      Read in function arguements                        % | 
| 40 | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 41 | 
 | 
| 42 | 
% Read in list of possible parameters. | 
| 43 | 
diagrunparam  = ReadVariables('DiagRunDefaults.m'); | 
| 44 | 
diagplotparam = ReadVariables('DiagPlotDefaults.m'); | 
| 45 | 
 | 
| 46 | 
% Rudimentary checks to make sure that the page and pagemane fields are | 
| 47 | 
% there and that they are the correct classes. | 
| 48 | 
if length(varargin) < 2 | 
| 49 | 
    error('There must be at least two input arguements.') | 
| 50 | 
else | 
| 51 | 
    if isequal(class(varargin{1}),'cell') | 
| 52 | 
        page = varargin{1}; | 
| 53 | 
    else | 
| 54 | 
        error('''page'' must be cell array.'); | 
| 55 | 
    end | 
| 56 | 
    if isequal(class(varargin{2}),'char') | 
| 57 | 
        pagename = varargin{2}; | 
| 58 | 
    else | 
| 59 | 
        error('''pagename'' must be a string.'); | 
| 60 | 
    end | 
| 61 | 
end | 
| 62 | 
 | 
| 63 | 
% Read in optional parameters, overriding the defaults if they are DiagRun | 
| 64 | 
% parameters and saving the DiagPlot parameters to pass along to the | 
| 65 | 
% DiagPlot function later on. | 
| 66 | 
plotparam = {}; | 
| 67 | 
iplotparam = 1; | 
| 68 | 
for iarg = 3:2:length(varargin) | 
| 69 | 
    if ismember(varargin{iarg},diagrunparam) | 
| 70 | 
        if isstr(varargin{iarg+1}) | 
| 71 | 
            eval([varargin{iarg},'=''',num2str(varargin{iarg+1}),''';']) | 
| 72 | 
        else | 
| 73 | 
            eval([varargin{iarg},'=',num2str(varargin{iarg+1}),';']) | 
| 74 | 
        end | 
| 75 | 
    elseif ismember(varargin{iarg},diagplotparam) | 
| 76 | 
        plotparam{iplotparam} = lower(varargin{iarg}); | 
| 77 | 
        plotparam{iplotparam+1} = varargin{iarg+1}; | 
| 78 | 
        iplotparam = iplotparam + 2; | 
| 79 | 
    else | 
| 80 | 
        error(['Unrecognized DiagRun setting:  ',lower(varargin{iarg})]); | 
| 81 | 
    end | 
| 82 | 
end | 
| 83 | 
 | 
| 84 | 
 | 
| 85 | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 86 | 
%                             Function body                               % | 
| 87 | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 88 | 
 | 
| 89 | 
% Determine number of plots for this page. | 
| 90 | 
nplot = length(page); | 
| 91 | 
     | 
| 92 | 
% Here would be a nice place to implement a function to verify that the | 
| 93 | 
% experiment field, slicing, averaging, and plot configuration information | 
| 94 | 
% is all self-consistent. | 
| 95 | 
 | 
| 96 | 
 | 
| 97 | 
% If the loaddata options is set to 0, the loading, averaging and slicing | 
| 98 | 
% of the data will be bypassed and the data to be plotted will be pulled | 
| 99 | 
% from the 'dump.mat' file.  This options is here almost entirely for the | 
| 100 | 
% purpose of fine-tuning your plots with the 'DiagPlot' function (also good | 
| 101 | 
% for testing modifications to DiagPlot!).  If the setting is set to 1, | 
| 102 | 
% then after the loading, averaging, and slicing the data to be plotted is | 
| 103 | 
% automatically saved to 'DiagDump.mat' so you so not have to load the | 
| 104 | 
% exact same data next time is you so desire. | 
| 105 | 
if LoadData | 
| 106 | 
     | 
| 107 | 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 108 | 
    %              Load data (calls DiagAverage and DiagSlice             % | 
| 109 | 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 110 | 
    for inplot = 1:nplot | 
| 111 | 
        ntrl = length(page{inplot}); if ntrl ~= 1, ntrl = ntrl - 1; end | 
| 112 | 
        for intrl = 1:ntrl | 
| 113 | 
            ExpInfo = page{inplot}{intrl}; | 
| 114 | 
             | 
| 115 | 
            % Required Fields. | 
| 116 | 
                        fln = ExpInfo{ifln};  % FieldName    (Required) | 
| 117 | 
                        trl = ExpInfo{itrl};  % Experiment   (Required) | 
| 118 | 
                        dat = ExpInfo{idat};  % DataType     (Required) | 
| 119 | 
                        dad = ExpInfo{idad};  % DataDir      (Required) | 
| 120 | 
                        grd = ExpInfo{igrd};  % GridDir      (Required) | 
| 121 | 
                        itr = ExpInfo{iitr};  % Iterations   (Required) | 
| 122 | 
                        tst = ExpInfo{itst};  % TimeStep     (Required) | 
| 123 | 
                        flu = ExpInfo{iflu};  % Fluid        (Required) | 
| 124 | 
                        ddf = ExpInfo{iddf};  % DataFormat   (Required) | 
| 125 | 
            gdf = ExpInfo{igdf};  % GridFormat   (Required)      | 
| 126 | 
                        avg = ExpInfo{iavg};  % Averaging    (Required) | 
| 127 | 
                        slc = ExpInfo{islc};  % SliceType    (Required) | 
| 128 | 
                        pst = ExpInfo{ipst};  % PlotStyle    (Required) | 
| 129 | 
             | 
| 130 | 
            % Set panel settings to default values, override with optional | 
| 131 | 
            % settings. | 
| 132 | 
            for param = diagrunparam | 
| 133 | 
                eval([param{1},'Temp=',param{1},';']); | 
| 134 | 
            end | 
| 135 | 
                        for iarg = 14:2:length(ExpInfo) | 
| 136 | 
                if ismember(ExpInfo{iarg},diagrunparam) | 
| 137 | 
                    iparam=ExpInfo{iarg+1}; | 
| 138 | 
                    if isstr(iparam), fparam=['''',iparam,'''']; | 
| 139 | 
                    elseif prod(size(iparam))>1, fparam=mat2str(iparam); | 
| 140 | 
                    else fparam=num2str(iparam); end | 
| 141 | 
                    eval([ExpInfo{iarg},'Temp=',fparam,';']); | 
| 142 | 
                end | 
| 143 | 
                        end | 
| 144 | 
             | 
| 145 | 
 | 
| 146 | 
            % Make DiagLoad function call. | 
| 147 | 
            disp(['Loading - Experiment:  ',trl,';  Field:  ',fln]); | 
| 148 | 
            [data{inplot}{intrl}, xax{inplot}{intrl},... | 
| 149 | 
              yax{inplot}{intrl},time{inplot}{intrl},... | 
| 150 | 
              pltslc{inplot}{intrl}] = ... | 
| 151 | 
                DiagLoad(fln,trl,dat,dad,grd,itr,tst,flu,ddf,gdf,avg,... | 
| 152 | 
                         slc,pst,LoadGridData,DiagDebug,GridSuffixTemp,... | 
| 153 | 
                         ZcordFileTemp,IndexTemp,DimTemp,VectorTemp,MateTemp,... | 
| 154 | 
                         GradsTemp,Year0IterTemp,SecPerYearTemp,MonthsTemp,... | 
| 155 | 
                         FieldNameTemp); | 
| 156 | 
 | 
| 157 | 
            % Save panel data for outside use. | 
| 158 | 
            if DumpData | 
| 159 | 
                datadump = data{inplot}{intrl}; | 
| 160 | 
                xaxdump = xax{inplot}{intrl}; | 
| 161 | 
                yaxdump = yax{inplot}{intrl}; | 
| 162 | 
                timedump = time{inplot}{intrl}; | 
| 163 | 
                pltslcdump = pltslc{inplot}{intrl}; | 
| 164 | 
                save(['Data',pagename,fln,flu,'.mat'],'datadump',... | 
| 165 | 
                     'xaxdump','yaxdump','timedump','pltslcdump'); | 
| 166 | 
            end | 
| 167 | 
        end | 
| 168 | 
    end | 
| 169 | 
    save('DiagDump.mat','data','xax','yax','time','pltslc'); | 
| 170 | 
else | 
| 171 | 
    load('DiagDump.mat');  | 
| 172 | 
end | 
| 173 | 
 | 
| 174 | 
 | 
| 175 | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 176 | 
%                             Plot Data                               % | 
| 177 | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 178 | 
 | 
| 179 | 
% Now to make the actual plots.  Basically, all of the information is | 
| 180 | 
% passed to the 'DiagPlot' functions, and things get a bit hairy in | 
| 181 | 
% there.  Hopefully the comments in the function, and its supporting | 
| 182 | 
% scripts will help you to make sense of this as needed. | 
| 183 | 
disp(['Plotting results:']); | 
| 184 | 
DiagPlot(pagename,page,data,xax,yax,time,pltslc,... | 
| 185 | 
         OutputDir,LoadGridData,SavePlots,DiagDebug); |