function DiagRun(varargin); % Function: DiagRun % Author: Daniel Enderton % % Input Fields: % % Field Type (Brief) Description % ----------------------------------------------------------------------- % page cell array Experiment and plot information (Required) % pagename string Page name (title and output file) (Required) % % OutputDir string Output directory name (Optional) % LoadData 0/1 Load data (Optional) % LoadGridData 0/1 Load grid data (Optional) % DumpData 0/1 Save plotting data (Optional) % SavePlots 0/1 Save plot (Optional) % DiagDebug 0/1 Print debug flags (Optional) % % Descripton: % This is the top level function of the cubed-sphere coupled-model % diagnostics package. The function guides the diagnostics through % loading (including averaging and slicing) and then plotting of the % data. The defaults of the optional parameters are in DiagRunDefaults. % % Sample function call is as follows (page and pagename appropriately % defined): % % >> DiagRun(page,pagename,'LoadData',1); % >> DiagRun(page,pagename,'LoadData',1,'OutputDir','~/'); % Load DiagRun default parameters and general diagnostics parameters. DiagRunDefaults; DiagGenParam; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Read in function arguements % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Read in list of possible parameters. diagrunparam = ReadVariables('DiagRunDefaults.m'); diagplotparam = ReadVariables('DiagPlotDefaults.m'); % Rudimentary checks to make sure that the page and pagemane fields are % there and that they are the correct classes. if length(varargin) < 2 error('There must be at least two input arguements.') else if isequal(class(varargin{1}),'cell') page = varargin{1}; else error('''page'' must be cell array.'); end if isequal(class(varargin{2}),'char') pagename = varargin{2}; else error('''pagename'' must be a string.'); end end % Read in optional parameters, overriding the defaults if they are DiagRun % parameters and saving the DiagPlot parameters to pass along to the % DiagPlot function later on. plotparam = {}; iplotparam = 1; for iarg = 3:2:length(varargin) if ismember(varargin{iarg},diagrunparam) if isstr(varargin{iarg+1}) eval([varargin{iarg},'=''',num2str(varargin{iarg+1}),''';']) else eval([varargin{iarg},'=',num2str(varargin{iarg+1}),';']) end elseif ismember(varargin{iarg},diagplotparam) plotparam{iplotparam} = lower(varargin{iarg}); plotparam{iplotparam+1} = varargin{iarg+1}; iplotparam = iplotparam + 2; else error(['Unrecognized DiagRun setting: ',lower(varargin{iarg})]); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Function body % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Determine number of plots for this page. nplot = length(page); % Here would be a nice place to implement a function to verify that the % experiment field, slicing, averaging, and plot configuration information % is all self-consistent. % If the loaddata options is set to 0, the loading, averaging and slicing % of the data will be bypassed and the data to be plotted will be pulled % from the 'dump.mat' file. This options is here almost entirely for the % purpose of fine-tuning your plots with the 'DiagPlot' function (also good % for testing modifications to DiagPlot!). If the setting is set to 1, % then after the loading, averaging, and slicing the data to be plotted is % automatically saved to 'DiagDump.mat' so you so not have to load the % exact same data next time is you so desire. if LoadData %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Load data (calls DiagAverage and DiagSlice % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for inplot = 1:nplot ntrl = length(page{inplot}); if ntrl ~= 1, ntrl = ntrl - 1; end for intrl = 1:ntrl ExpInfo = page{inplot}{intrl}; % Required Fields. fln = ExpInfo{ifln}; % FieldName (Required) trl = ExpInfo{itrl}; % Experiment (Required) dat = ExpInfo{idat}; % DataType (Required) dad = ExpInfo{idad}; % DataDir (Required) grd = ExpInfo{igrd}; % GridDir (Required) itr = ExpInfo{iitr}; % Iterations (Required) tst = ExpInfo{itst}; % TimeStep (Required) flu = ExpInfo{iflu}; % Fluid (Required) ddf = ExpInfo{iddf}; % DataFormat (Required) gdf = ExpInfo{igdf}; % GridFormat (Required) avg = ExpInfo{iavg}; % Averaging (Required) slc = ExpInfo{islc}; % SliceType (Required) pst = ExpInfo{ipst}; % PlotStyle (Required) % Set panel settings to default values, override with optional % settings. for param = diagrunparam eval([param{1},'Temp=',param{1},';']); end for iarg = 14:2:length(ExpInfo) if ismember(ExpInfo{iarg},diagrunparam) iparam=ExpInfo{iarg+1}; if isstr(iparam), fparam=['''',iparam,'''']; elseif prod(size(iparam))>1, fparam=mat2str(iparam); else fparam=num2str(iparam); end eval([ExpInfo{iarg},'Temp=',fparam,';']); end end % Make DiagLoad function call. disp(['Loading - Experiment: ',trl,'; Field: ',fln]); [data{inplot}{intrl}, xax{inplot}{intrl},... yax{inplot}{intrl},time{inplot}{intrl},... pltslc{inplot}{intrl}] = ... DiagLoad(fln,trl,dat,dad,grd,itr,tst,flu,ddf,gdf,avg,... slc,pst,LoadGridData,DiagDebug,GridSuffixTemp,... ZcordFileTemp,IndexTemp,DimTemp,VectorTemp,MateTemp,... GradsTemp,Year0IterTemp,SecPerYearTemp,MonthsTemp,... FieldNameTemp); % Save panel data for outside use. if DumpData datadump = data{inplot}{intrl}; xaxdump = xax{inplot}{intrl}; yaxdump = yax{inplot}{intrl}; timedump = time{inplot}{intrl}; pltslcdump = pltslc{inplot}{intrl}; save(['Data',pagename,fln,flu,'.mat'],'datadump',... 'xaxdump','yaxdump','timedump','pltslcdump'); end end end save('DiagDump.mat','data','xax','yax','time','pltslc'); else load('DiagDump.mat'); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Plot Data % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Now to make the actual plots. Basically, all of the information is % passed to the 'DiagPlot' functions, and things get a bit hairy in % there. Hopefully the comments in the function, and its supporting % scripts will help you to make sense of this as needed. disp(['Plotting results:']); DiagPlot(pagename,page,data,xax,yax,time,pltslc,... OutputDir,LoadGridData,SavePlots,DiagDebug);