diff --git a/@MyDaq/MyDaq.m b/@MyDaq/MyDaq.m index 712cd56..1513d8b 100644 --- a/@MyDaq/MyDaq.m +++ b/@MyDaq/MyDaq.m @@ -1,1047 +1,1047 @@ % Acquisition and analysis program that receives data from Collector. Can % also be used for analysis of previously acquired traces. classdef MyDaq < handle properties %Contains GUI handles Gui %Main figure Figure %main axes main_plot %Contains Reference trace (MyTrace object) Ref %Contains Data trace (MyTrace object) Data %Contains Background trace (MyTrace object) Background %List of all the programs with run files ProgramList= MyProgramDescriptor.empty() %Struct containing Cursor objects Cursors=struct() %Struct containing Cursor labels CrsLabels=struct() %Struct containing MyFit objects Fits=struct() %Input parser for class constructor ConstructionParser %Struct for listeners Listeners=struct() %Sets the colors of fits, data and reference fit_color='k' data_color='b' ref_color='r' bg_color='c' default_ext='.txt' % default data file extension end properties (Dependent=true) save_dir open_fits open_crs end properties (Dependent=true, SetAccess=private, GetAccess=public) %Properties for saving files base_dir session_name filename % File name is always returned with extension end methods (Access=public) %% Class functions %Constructor function function this=MyDaq(varargin) %We grab the guihandles from a GUI made in Guide. this.Gui=guihandles(eval('GuiDaq')); %Assign the handle of main figure to a property for %compatibility with Matalb apps this.Figure = this.Gui.figure1; this.main_plot = this.Gui.figure1.CurrentAxes; % Parse inputs p=inputParser; addParameter(p,'collector_handle',[]); this.ConstructionParser=p; parse(p, varargin{:}); %Sets a listener to the collector if ~isempty(p.Results.collector_handle) this.Listeners.Collector.NewDataWithHeaders=... addlistener(p.Results.collector_handle,... 'NewDataWithHeaders',... @(~,eventdata) acquireNewData(this,eventdata)); else errordlg(['No collector handle was supplied. ',... 'DAQ will be unable to acquire data'],... 'Error: No collector'); end % Initialize traces this.Ref=MyTrace(); this.Data=MyTrace(); this.Background=MyTrace(); %The list of instruments is automatically populated from the %run files. Select programs that are enabled and can produce %traces. FullProgList = getIcPrograms(); ind = [FullProgList.enabled] & [FullProgList.data_source]; this.ProgramList = FullProgList(ind); %This function sets all the callbacks for the GUI. If a new %button is made, the associated callback must be put in the %initGui function initGui(this); % Initialize the menu based on the available programs set(this.Gui.InstrMenu,'String',[{'Select the application'},... {this.ProgramList.title}]); % Add a property to the menu for storing the program file % names if ~isprop(this.Gui.InstrMenu, 'ItemsData') addprop(this.Gui.InstrMenu, 'ItemsData'); end set(this.Gui.InstrMenu,'ItemsData',0:length(this.ProgramList)); % Add Data, Ref and Bg traces in the proper order on the plot % as empty lines. hold(this.main_plot,'on'); this.Background.hlines{1}=line(this.main_plot, ... 'XData',[],'YData',[],'Color',this.bg_color); this.Ref.hlines{1}=line(this.main_plot, ... 'XData',[],'YData',[],'Color',this.ref_color); this.Data.hlines{1}=line(this.main_plot, ... 'XData',[],'YData',[],'Color',this.data_color); %Initializes saving locations this.base_dir=getLocalSettings('measurement_base_dir'); this.session_name='placeholder'; this.filename='placeholder'; end function delete(this) %Deletes the MyFit objects and their listeners cellfun(@(x) deleteListeners(this,x), this.open_fits); structfun(@(x) delete(x), this.Fits); %Deletes other listeners if ~isempty(fieldnames(this.Listeners)) cellfun(@(x) deleteListeners(this, x),... fieldnames(this.Listeners)); end %A class destructor should never through errors, so enclose the %attempt to close figure into try-catch structure try this.Gui.figure1.CloseRequestFcn=''; %Deletes the figure delete(this.Gui.figure1); %Removes the figure handle to prevent memory leaks this.Gui=[]; catch end end end methods (Access=private) %Sets callback functions for the GUI initGui(this) %Executes when the GUI is closed function closeFigure(this,~,~) delete(this); end %Updates fits function updateFits(this) %Pushes data into fits in the form of MyTrace objects, so that %units etc follow. Also updates user supplied parameters. for i=1:length(this.open_fits) switch this.open_fits{i} case {'Linear','Quadratic','Gaussian',... 'Exponential','Beta'} this.Fits.(this.open_fits{i}).Data=... getFitData(this,'VertData'); case {'Lorentzian','DoubleLorentzian'} this.Fits.(this.open_fits{i}).Data=... getFitData(this,'VertData'); %Here we push the information about line spacing %into the fit object if the reference cursors are %open. Only for Lorentzian fits. if isfield(this.Cursors,'VertRef') ind=findCursorData(this,'Data','VertRef'); this.Fits.(this.open_fits{i}).CalVals.line_spacing=... range(this.Data.x(ind)); end case {'G0'} this.Fits.G0.MechTrace=getFitData(this,'VertData'); this.Fits.G0.CalTrace=getFitData(this,'VertRef'); end end end % If vertical cursors are on, takes only data within cursors. If %the cursor is not open, it takes all the data from the selected %trace in the analysis trace selection dropdown function Trace=getFitData(this,varargin) %Parses varargin input p=inputParser; addOptional(p,'name','',@ischar); parse(p,varargin{:}) name=p.Results.name; %Finds out which trace the user wants to fit. trc_opts=this.Gui.SelTrace.String; trc_str=trc_opts{this.Gui.SelTrace.Value}; % Note the use of copy here! This is a handle %class, so if normal assignment is used, this.Fits.Data and %this.(trace_str) will refer to the same object, causing roblems. %Name input is the name of the cursor to be used to extract data. Trace=copy(this.(trc_str)); %If the cursor is open for the trace we are analyzing, we take %only the data enclosed by the cursor. if isfield(this.Cursors,name) ind=findCursorData(this, trc_str, name); Trace.x=this.(trc_str).x(ind); Trace.y=this.(trc_str).y(ind); end end %Finds data between named cursors in the given trace function ind=findCursorData(this, trc_str, name) crs_pos=sort([this.Cursors.(name){1}.Location,... this.Cursors.(name){2}.Location]); ind=(this.(trc_str).x>crs_pos(1) & this.(trc_str).x