diff --git a/@MyDaq/MyDaq.m b/@MyDaq/MyDaq.m index e009bac..a10cae0 100644 --- a/@MyDaq/MyDaq.m +++ b/@MyDaq/MyDaq.m @@ -1,107 +1,141 @@ classdef MyDaq < handle properties + %Contains Gui handles Gui; + %Contains Reference trace (MyTrace object) Reference; + %Contains Data trace (MyTrace object) Data; + %Contains Background trace (MyTrace object) Background; + %Cell containing MyInstrument objects Instruments; + %Cell containing Cursor objects Cursors; + %Cell containing MyFit objects Fits; + %Input parser Parser; - save_dir; + + base_dir; session_name; file_name; enable_gui; end properties (Dependent=true) - save_path; + save_dir; main_plot; end methods function this=MyDaq(varargin) createParser(this); parse(this.Parser,varargin{:}); parseInputs(this); if this.enable_gui this.Gui=guihandles(eval('GuiDaq')); initGui(this); end initDaq(this) end function createParser(this) p=inputParser; addParameter(p,'enable_gui',1); this.Parser=p; end %Sets the class variables to the inputs from the inputParser. function parseInputs(this) for i=1:length(this.Parser.Parameters) %Takes the value from the inputParser to the appropriate %property. if isprop(this,this.Parser.Parameters{i}) this.(this.Parser.Parameters{i})=... this.Parser.Results.(this.Parser.Parameters{i}); end end end function initDaq(this) computer_name=getenv('computername'); switch computer_name case 'LPQM1PCLAB2' initRt(this); case 'LPQM1PC18' initUhq(this); otherwise error('Please create an initialization function for this computer') end this.Reference=MyTrace; this.Data=MyTrace; this.Background=MyTrace; end function initGui(this) - set(this.Gui.SaveDir,'Callback',... - @(hObject, eventdata) saveDirCallback(this, hObject, ... + set(this.Gui.BaseDir,'Callback',... + @(hObject, eventdata) baseDirCallback(this, hObject, ... eventdata)); set(this.Gui.SessionName,'Callback',... @(hObject, eventdata) sessionNameCallback(this, hObject, ... eventdata)); set(this.Gui.FileName,'Callback',... @(hObject, eventdata) fileNameCallback(this, hObject, ... eventdata)); + set(this.Gui.SaveData,'Callback',... + @(hObject, eventdata) saveDataCallback(this, hObject, ... + eventdata)); + set(this.Gui.SaveRef,'Callback',... + @(hObject, eventdata) saveRefCallback(this, hObject, ... + eventdata)); end - function saveDirCallback(this, hObject, ~) + function saveDataCallback(this, ~, ~) + if get(this.Gui.AutoName,'Value') + date_time = datestr(now,'yyyy-mm-dd_HH.MM.SS'); + else + date_time=''; + end + + savefile=[this.file_name,date_time]; + save(this.Data,'save_dir',this.save_dir,'name',savefile) + end + + function saveRefCallback(this, ~, ~) + if get(this.Gui.AutoName,'Value') + date_time = datestr(now,'yyyy-mm-dd_HH.MM.SS'); + else + date_time=''; + end + + savefile=[this.file_name,date_time]; + save(this.Ref,'save_dir',this.save_dir,'name',savefile) + end + + function baseDirCallback(this, hObject, ~) %Modify this at some point to use uiputfile instead - this.save_dir=get(hObject,'String'); + this.base_dir=get(hObject,'String'); end function sessionNameCallback(this, hObject, ~) this.session_name=get(hObject,'String'); end function fileNameCallback(this, hObject,~) this.file_name=get(hObject,'String'); end - - function set.save_dir(this, save_dir) - this.save_dir=save_dir; + + function save_dir=get.save_dir(this) + save_dir=[this.base_dir,datestr(now,'yyyy-mm-dd '),... + this.session_name,'\']; end - function save_path=get.save_path(this) - save_path=[this.save_dir,this.session_name,'\',this.file_name,... - '.txt']; - end function main_plot=get.main_plot(this) main_plot=this.Gui.figure1.CurrentAxes; end end end \ No newline at end of file diff --git a/@MyDaq/initRt.m b/@MyDaq/initRt.m index d4bc364..cb8cd41 100644 --- a/@MyDaq/initRt.m +++ b/@MyDaq/initRt.m @@ -1,12 +1,12 @@ function initRt(this) set(this.Gui.InstrumentMenu,'String',{'Select the device',... 'RT Oscilloscope 1 (Tektronix DPO 4034)',... 'UHF Lock-in Amplifier (Zurich Instrument)',... 'RT Spectrum Analyzer (RSA)',... 'Oscilloscope 2 (Agilent DSO7034A)',... 'Network Analyzer (Agilent E5061B)'}); -this.save_dir='M:\Measurement Campaigns\'; -set(this.Gui.SaveDir,'String',this.save_dir); +this.base_dir='M:\Measurement Campaigns\'; +set(this.Gui.BaseDir,'String',this.base_dir); end \ No newline at end of file diff --git a/@MyTrace/MyTrace.m b/@MyTrace/MyTrace.m index 26b904a..83a1691 100644 --- a/@MyTrace/MyTrace.m +++ b/@MyTrace/MyTrace.m @@ -1,274 +1,275 @@ classdef MyTrace < handle properties x=[]; y=[]; name='placeholder'; Color='b'; Marker='.'; LineStyle='-' MarkerSize=6; Parser; name_x='x'; name_y='y'; unit_x=''; unit_y=''; save_dir=''; load_path=''; end properties (Dependent=true) label_x; label_y; end methods function this=MyTrace(varargin) createParser(this); parse(this.Parser,varargin{:}); parseInputs(this,true); if ~ismember('load_path',this.Parser.UsingDefaults) loadTrace(this,this.load_path); end end %Creates the input parser for the class. Includes default values %for all optional parameters. function createParser(this) p=inputParser; addParameter(p,'name','placeholder'); addParameter(p,'x',[]); addParameter(p,'y',[]); addParameter(p,'Color','b'); addParameter(p,'Marker','none'); addParameter(p,'LineStyle','-'); addParameter(p,'MarkerSize',6); addParameter(p,'unit_x','x'); addParameter(p,'unit_y','y'); addParameter(p,'name_x','x'); addParameter(p,'name_y','y'); %Default save folder is the current directory upon %instantiation addParameter(p,'save_dir',pwd); addParameter(p,'load_path',''); this.Parser=p; end %Defines the save function for the class. Saves the data with %column headers as label_x and label_y function save(this,varargin) %Allows all options of the class as inputs for the save %function, to change the name or save directory. parse(this.Parser,varargin{:}); parseInputs(this,false); %Creates save directory if it does not exist if ~exist(this.save_dir,'dir') mkdir(this.save_dir) end %Creates a file name out of the name of the class and the save %directory filename=[this.save_dir,'\',this.name,'.txt']; %Creates the file fileID=fopen(filename,'w'); %Finds appropriate column width cw=max([length(this.label_y),length(this.label_x)]); + if cw<9; cw=9; end %Makes a format string with the correct column width. %% makes %a % symbol in sprintf, thus if cw=14, below is %14s\t%14s\r\n. %\r\n prints a carriage return, ensuring linebreak in NotePad. fprintf(fileID,sprintf('%%%ds\t%%%ds\r\n',cw,cw),... this.label_x, this.label_y); %Saves in scientific notation with correct column width defined %above. Again if cw=14, we get %14.3e\t%14.3e\r\n fprintf(fileID,sprintf('%%%d.3e\t%%%d.3e\r\n',cw,cw),... - [this.x; this.y]); + [this.x, this.y]'); fclose(fileID); end function loadTrace(this, file_path) if ~exist(this.load_path,'file') error('File does not exist, please choose a different load path') end load_data=tdfread(file_path); this.load_path=file_path; data_labels=fieldnames(load_data); %Code for left bracket ind_start=strfind(data_labels, '0x28'); %Code for right bracket ind_stop=strfind(data_labels, '0x29'); col_name={'x','y'}; for i=1:2 if ~isempty(ind_start) && ~isempty(ind_stop) %Extracts the data labels from the file this.(sprintf('unit_%s',col_name{i}))=... data_labels{i}((ind_start{i}+4):(ind_stop{i}-1)); this.(sprintf('name_%s',col_name{i}))=... data_labels{i}(1:(ind_start{i}-2)); end %Loads the data into the trace this.(col_name{i})=load_data.(data_labels{i}); end end %Sets the class variables to the inputs from the inputParser. Can %be used to reset class to default values if default_flag=true. function parseInputs(this, default_flag) for i=1:length(this.Parser.Parameters) %Sets the value if there was an input or if the default %flag is on. The default flag is used to reset the class to %its default values. if default_flag || ~any(ismember(this.Parser.Parameters{i},... this.Parser.UsingDefaults)) this.(this.Parser.Parameters{i})=... this.Parser.Results.(this.Parser.Parameters{i}); end end end %Plots the trace on the given axes, using the class variables to %define colors, markers, lines and labels. Takes all optional %parameters of the class as inputs. function plotTrace(this,plot_axes,varargin) assert(exist('plot_axes','var') && ... isa(plot_axes,'matlab.graphics.axis.Axes'),... 'Please input axes to plot in.') assert(isequal(size(this.x), size(this.y)) || ... (isvector(this.x) && isvector(this.y) && ... numel(this.x) == numel(this.y)),... 'The length of x and y must be identical to make a plot') parse(this.Parser,varargin{:}) parseInputs(this,false); plot(plot_axes,this.x,this.y,'Color',this.Color,'LineStyle',... this.LineStyle,'Marker',this.Marker,... 'MarkerSize',this.MarkerSize) xlabel(plot_axes,this.label_x,'Interpreter','LaTeX'); ylabel(plot_axes,this.label_y,'Interpreter','LaTeX'); set(plot_axes,'TickLabelInterpreter','LaTeX'); end %Set function for Color. Checks if it is a valid color. function set.Color(this, Color) assert(iscolor(Color),... '%s is not a valid MATLAB default color or RGB triplet',... Color); this.Color=Color; end %Set function for Marker. Checks if it is a valid %marker style. function set.Marker(this, Marker) assert(ismarker(Marker),... '%s is not a valid MATLAB MarkerStyle',Marker); this.Marker=Marker; end %Set function for x, checks if it is a vector of doubles. function set.x(this, x) assert(isnumeric(x),... 'Data must be of class double'); this.x=x(:); end %Set function for y, checks if it is a vector of doubles. function set.y(this, y) assert(isnumeric(y),... 'Data must be of class double'); this.y=y(:); end %Set function for LineStyle, checks if input is a valid line style. function set.LineStyle(this, LineStyle) assert(isline(LineStyle),... '%s is not a valid MATLAB LineStyle',LineStyle); this.LineStyle=LineStyle; end %Set function for MarkerSize, checks if input is a positive number. function set.MarkerSize(this, MarkerSize) assert(isnumeric(MarkerSize) && MarkerSize>0,... 'MarkerSize must be a numeric value greater than zero'); this.MarkerSize=MarkerSize; end %Set function for name, checks if input is a string. function set.name(this, name) assert(ischar(name),'Name must be a string, not a %s',... class(name)); this.name=name; end %Set function for unit_x, checks if input is a string. function set.unit_x(this, unit_x) assert(ischar(unit_x),'Unit must be a string, not a %s',... class(unit_x)); this.unit_x=unit_x; end %Set function for unit_y, checks if input is a string function set.unit_y(this, unit_y) assert(ischar(unit_y),'Unit must be a string, not a %s',... class(unit_y)); this.unit_y=unit_y; end %Set function for name_x, checks if input is a string function set.name_x(this, name_x) assert(ischar(name_x),'Name must be a string, not a %s',... class(name_x)); this.name_x=name_x; end %Set function for name_y, checks if input is a string function set.name_y(this, name_y) assert(ischar(name_y),'Name must be a string, not a %s',... class(name_y)); this.name_y=name_y; end function set.load_path(this, load_path) assert(ischar(load_path),'File path must be a string, not a %s',... class(load_path)); this.load_path=load_path; end %Get function for label_x, creates label from name_x and unit_x. function label_x=get.label_x(this) label_x=sprintf('%s (%s)', this.name_x, this.unit_x); end %Get function for label_y, creates label from name_y and unit_y. function label_y=get.label_y(this) label_y=sprintf('%s (%s)', this.name_y, this.unit_y); end function sum=plus(a,b) checkArithmetic(a,b); sum=MyTrace('x',a.x,'y',a.y+b.y,'unit_x',a.unit_x,... 'unit_y',a.unit_y,'name_x',a.name_x,'name_y',a.name_y); end function sum=minus(a,b) checkArithmetic(a,b); sum=MyTrace('x',a.x,'y',a.y-b.y,'unit_x',a.unit_x,... 'unit_y',a.unit_y,'name_x',a.name_x,'name_y',a.name_y); end function checkArithmetic(a,b) assert(isa(a,'MyTrace') && isa(b,'MyTrace'),... ['Both objects must be of type MyTrace to add,',... 'here they are type %s and %s'],class(a),class(b)); assert(strcmp(a.unit_x, b.unit_x) && strcmp(a.unit_y,b.unit_y),... 'The MyTrace classes must have the same units for arithmetic'); assert(length(a.x)==length(a.y) && length(a.x)==length(a.y),... 'The length of x and y must be equal for arithmetic'); assert(all(a.x==b.x),... 'The MyTrace objects must have identical x-axis for arithmetic') end end end \ No newline at end of file diff --git a/GUIs/GuiDaq.fig b/GUIs/GuiDaq.fig index 7188788..69ddbd6 100644 Binary files a/GUIs/GuiDaq.fig and b/GUIs/GuiDaq.fig differ diff --git a/GUIs/GuiDaq.m b/GUIs/GuiDaq.m index 1d8e064..38d776f 100644 --- a/GUIs/GuiDaq.m +++ b/GUIs/GuiDaq.m @@ -1,1413 +1,1309 @@ function varargout = GuiDaq(varargin) % GUIDAQ MATLAB code for GuiDaq.fig % GUIDAQ, by itself, creates a new GUIDAQ or raises the existing % singleton*. % % H = GUIDAQ returns the handle to a new GUIDAQ or the handle to % the existing singleton*. % % GUIDAQ('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GUIDAQ.M with the given input arguments. % % GUIDAQ('Property','Value',...) creates a new GUIDAQ or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before GuiDaq_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to GuiDaq_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help GuiDaq -% Last Modified by GUIDE v2.5 20-Oct-2017 12:22:18 +% Last Modified by GUIDE v2.5 20-Oct-2017 13:53:17 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @GuiDaq_OpeningFcn, ... 'gui_OutputFcn', @GuiDaq_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before GuiDaq is made visible. function GuiDaq_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to GuiDaq (see VARARGIN) % Choose default command line output for GuiDaq handles.output = hObject; clc %NEED TO PUT IN SELECTION HERE. OPTIONS FOR DRIVE LETTER setappdata(0,'h_main_plot',gcf); setappdata(gcf,'x_data',0); setappdata(gcf,'y_data',0); setappdata(gcf,'x_ref',0); setappdata(gcf,'y_ref',0); setappdata(gcf,'x_analyze',0); setappdata(gcf,'y_analyze',0); setappdata(gcf,'x_analyze_done',0); % Data which has been analyze in x axis setappdata(gcf,'y_analyze_done',0); % Data which has been analyze in y axis setappdata(gcf,'general_plot_update',@update_axes); setappdata(gcf,'x_label','dummy x'); setappdata(gcf,'y_label','dummy y'); setappdata(gcf,'Vertical_curs',[]); % Object which contain the vertical cursor setappdata(gcf,'Horizontal_curs',[]);% Object which contain the Horizontal cursor setappdata(gcf,'Vertical_ref_curs',[]); % Object which contain the vertical cursor for reference setappdata(gcf,'Vertical_ref_state',0); % Status of vertial cursor for reference setappdata(gcf,'x_BG',0); setappdata(gcf,'y_BG',0); setappdata(gcf,'V1',[]); % Value of vertical V1 cursor setappdata(gcf,'V2',[]); % Value of vertical V2 cursor setappdata(gcf,'H1',[]); % Value of Horizontal H1 cursor setappdata(gcf,'H2',[]); % Value of Horizontal H2 cursor setappdata(gcf,'Hcursor_toggle_state',0);% flag which shows the Horizontal curcor state setappdata(gcf,'Vcursor_toggle_state',0);% flag which shows the Vertical curcor state setappdata(gcf,'error_flag',0); % a flag to show or not show the fitted data setappdata(gcf,'overwite_flag',0); setappdata(gcf,'y_log_flag',0); % a flag log scale in y axis setappdata(gcf,'x_log_flag',0); % a flag log scale in x axis setappdata(gcf,'show_data',1); % a flag to show or not show the data setappdata(gcf,'show_ref',0); % a flag to show or not show the ref setappdata(gcf,'show_fit_flag',0); % a flag to show or not show the fitted data setappdata(gcf,'fit_meta_data',0); % a variable to store the analysis meta data setappdata(gcf,'fit_meta_data_name',''); % a variable to store the analysis meta names setappdata(gcf,'fit_meta_data_text_position',[0,0]); % a variable to store position of the text 1-> topleft, 2->topright, 3->bottomleft, 4->bottomright setappdata(gcf,'folder_path',''); % this variable contains the path for the session setappdata(gcf,'ring_down_frequency',1e6); % a global variable to store the central frequency of ringdown experement setappdata(gcf,'Signle_Lorentizan_P1',0); % Signle Lorentzian fit coeff P1 setappdata(gcf,'Signle_Lorentizan_P2',0); % Signle Lorentzian fit coeff P2 setappdata(gcf,'Signle_Lorentizan_P3',0); % Signle Lorentzian fit coeff P3 setappdata(gcf,'Signle_Lorentizan_C',0); % Signle Lorentzian fit coeff C setappdata(gcf,'Vpi',2); % Default value for Vpi of EOM setappdata(gcf,'g0',20000); set(handles.num_int,'Enable','off'); set(handles.num_int,'Value',1); update_axes % Update handles structure guidata(hObject, handles); % UIWAIT makes GuiDaq wait for user response (see UIRESUME) % uiwait(handles.figure1); function nothig(varargin) % --- Outputs from this function are returned to the command line. function varargout = GuiDaq_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on selection change in InstrumentMenu. function InstrumentMenu_Callback(hObject, eventdata, handles) % hObject handle to InstrumentMenu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns InstrumentMenu contents as cell array % contents{get(hObject,'Value')} returns selected item from InstrumentMenu device_no=get(hObject,'Value'); device_list=get(hObject,'String'); device_name=device_list{device_no}; switch device_name case 'Select the device' % updating global variables and updating the plot h_main_plot=getappdata(0,'h_main_plot'); setappdata(h_main_plot,'x_data',0); setappdata(h_main_plot,'y_data',0); setappdata(h_main_plot,'x_label','dummy x'); setappdata(h_main_plot,'y_label','dummy y'); update_axes=getappdata(h_main_plot,'update_axes'); feval(update_axes); case 'RT Oscilloscope 1 (Tektronix DPO 4034)' Oscilloscope_Tektronix_RT; case 'Oscilloscope 1 (Tektronix DPO 4034)' Oscilloscope_Tektronix; case 'Spectrum Analyzer (Agilent MXA)' MXA_Signal_Analyzer; case 'Network Analyzer (Agilent NA)' NA_Network_Analyzer; case 'UHF Lock-in Amplifier (Zurich Instrument)' UHF_Zurich_Instrument; case 'Auto Ringdown (Agilent NA)' Ringdown_Auto_NA; case 'Oscilloscope 2 (Agilent DSO7034A)' Oscilloscope_Agilent case 'RT Spectrum Analyzer (RSA)' RSA_Signal_Analyzer end % --- Executes during object creation, after setting all properties. function InstrumentMenu_CreateFcn(hObject, eventdata, handles) % hObject handle to InstrumentMenu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in Vertical_cursor. function Vertical_cursor_Callback(hObject, eventdata, handles) % hObject handle to Vertical_cursor (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of Vertical_cursor h_main_plot=getappdata(0,'h_main_plot'); VC_state=get(hObject,'Value'); setappdata(h_main_plot,'Vcursor_toggle_state',VC_state); axes=findobj(h_main_plot,'type','axes'); if(VC_state==1) Vertical_curs=Vertical_cursors(axes); setappdata(h_main_plot,'Vertical_curs',Vertical_curs); set(hObject, 'BackGroundColor',[0,1,.2]); set(handles.V1_Edit,'enable','on' ) set(handles.V2_Edit,'enable','on' ) set(handles.V1_V2_Edit,'enable','on' ) elseif(VC_state==0) Vertical_curs=getappdata(h_main_plot,'Vertical_curs'); Vertical_curs.off(); set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); set(handles.V1_Edit,'enable','inactive' ) set(handles.V2_Edit,'enable','inactive' ) set(handles.V1_V2_Edit,'enable','inactive' ) set(handles.V1_Edit,'string','' ) set(handles.V2_Edit,'string','' ) set(handles.V1_V2_Edit,'string','' ) end % --- Executes on button press in Horizontal_cursor. function Horizontal_cursor_Callback(hObject, eventdata, handles) % hObject handle to Horizontal_cursor (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of Horizontal_cursor h_main_plot=getappdata(0,'h_main_plot'); VC_state=get(hObject,'Value'); setappdata(h_main_plot,'Hcursor_toggle_state',VC_state); axes=findobj(h_main_plot,'type','axes'); if(VC_state==1) Horizontal_curs=Horizontal_cursors(axes); setappdata(h_main_plot,'Horizontal_curs',Horizontal_curs); set(hObject, 'BackGroundColor',[0,1,.2]); set(handles.H1_Edit,'enable','on' ) set(handles.H2_Edit,'enable','on' ) set(handles.H2_H1_Edit,'enable','on' ) elseif(VC_state==0) Horizontal_curs=getappdata(h_main_plot,'Horizontal_curs'); Horizontal_curs.off(); set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); set(handles.H1_Edit,'enable','inactive' ) set(handles.H2_Edit,'enable','inactive' ) set(handles.H2_H1_Edit,'enable','inactive' ) set(handles.H1_Edit,'string','' ) set(handles.H2_Edit,'string','' ) set(handles.H2_H1_Edit,'string','' ) end % --- Executes on button press in Center_cursor. function Center_cursor_Callback(hObject, eventdata, handles) % hObject handle to Center_cursor (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) h_main_plot=getappdata(0,'h_main_plot'); Hcursor_toggle_state=getappdata(h_main_plot,'Hcursor_toggle_state'); if (Hcursor_toggle_state==1) Horizontal_curs=getappdata(h_main_plot,'Horizontal_curs'); Horizontal_curs.off(); Horizontal_curs.add(); end Vcursor_toggle_state=getappdata(h_main_plot,'Vcursor_toggle_state'); if (Vcursor_toggle_state==1) Vertical_curs=getappdata(h_main_plot,'Vertical_curs'); Vertical_curs.off(); Vertical_curs.add(); end Vertical_ref_state=getappdata(h_main_plot,'Vertical_ref_state'); if (Vertical_ref_state==1) Vertical_ref_curs=getappdata(h_main_plot,'Vertical_ref_curs'); Vertical_ref_curs.off(); Vertical_ref_curs.add(); end axes=findobj(h_main_plot,'type','axes'); function V1_Edit_Callback(hObject, eventdata, handles) % hObject handle to V1_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of V1_Edit as text % str2double(get(hObject,'String')) returns contents of V1_Edit as a double % Hint: get(hObject,'Value') returns toggle state of Vertical_cursor h_main_plot=getappdata(0,'h_main_plot'); axes=findobj(h_main_plot,'type','axes'); Vertical_curs=getappdata(h_main_plot,'Vertical_curs'); v_curs_val=Vertical_curs.val(); Vertical_curs.off(); v_curs_val(1)=str2num(get(hObject,'String')); Vertical_curs.add(v_curs_val); % --- Executes during object creation, after setting all properties. function V1_Edit_CreateFcn(hObject, eventdata, handles) % hObject handle to V1_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function V2_Edit_Callback(hObject, eventdata, handles) % hObject handle to V2_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of V2_Edit as text % str2double(get(hObject,'String')) returns contents of V2_Edit as a double h_main_plot=getappdata(0,'h_main_plot'); axes=findobj(h_main_plot,'type','axes'); Vertical_curs=getappdata(h_main_plot,'Vertical_curs'); v_curs_val=Vertical_curs.val(); Vertical_curs.off(); v_curs_val(2)=str2num(get(hObject,'String')); Vertical_curs.add(v_curs_val); % --- Executes during object creation, after setting all properties. function V2_Edit_CreateFcn(hObject, eventdata, handles) % hObject handle to V2_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function V1_V2_Edit_Callback(hObject, eventdata, handles) % hObject handle to V1_V2_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of V1_V2_Edit as text % str2double(get(hObject,'String')) returns contents of V1_V2_Edit as a double % --- Executes during object creation, after setting all properties. function V1_V2_Edit_CreateFcn(hObject, eventdata, handles) % hObject handle to V1_V2_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function H1_Edit_Callback(hObject, eventdata, handles) % hObject handle to H1_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of H1_Edit as text % str2double(get(hObject,'String')) returns contents of H1_Edit as a double h_main_plot=getappdata(0,'h_main_plot'); axes=findobj(h_main_plot,'type','axes'); Horizontal_curs=getappdata(h_main_plot,'Horizontal_curs'); h_curs_val=Horizontal_curs.val(); Horizontal_curs.off(); h_curs_val(1)=str2num(get(hObject,'String')); Horizontal_curs.add(h_curs_val); % --- Executes during object creation, after setting all properties. function H1_Edit_CreateFcn(hObject, eventdata, handles) % hObject handle to H1_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function H2_Edit_Callback(hObject, eventdata, handles) % hObject handle to H2_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of H2_Edit as text % str2double(get(hObject,'String')) returns contents of H2_Edit as a double h_main_plot=getappdata(0,'h_main_plot'); axes=findobj(h_main_plot,'type','axes'); Horizontal_curs=getappdata(h_main_plot,'Horizontal_curs'); h_curs_val=Horizontal_curs.val(); Horizontal_curs.off(); h_curs_val(2)=str2num(get(hObject,'String')); Horizontal_curs.add(h_curs_val); % --- Executes during object creation, after setting all properties. function H2_Edit_CreateFcn(hObject, eventdata, handles) % hObject handle to H2_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function H2_H1_Edit_Callback(hObject, eventdata, handles) % hObject handle to H2_H1_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of H2_H1_Edit as text % str2double(get(hObject,'String')) returns contents of H2_H1_Edit as a double % --- Executes during object creation, after setting all properties. function H2_H1_Edit_CreateFcn(hObject, eventdata, handles) % hObject handle to H2_H1_Edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in Analyze_list. function Analyze_list_Callback(hObject, eventdata, handles) % hObject handle to Analyze_list (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns Analyze_list contents as cell array % contents{get(hObject,'Value')} returns selected item from Analyze_list h_main_plot=getappdata(0,'h_main_plot'); analysis_routine_number=get(hObject,'Value'); axes=findobj(h_main_plot,'type','axes'); switch analysis_routine_number case 5 Vertical_ref_curs=Vertical_cursors_ref(axes); setappdata(h_main_plot,'Vertical_ref_curs',Vertical_ref_curs); setappdata(h_main_plot,'Vertical_ref_state',1); set(findall(handles.RecordPanel, '-property', 'visible'), 'visible', 'off'); set(handles.num_int,'Enable','off' ); %Cases which use recording panel case 9 set(findall(handles.RecordPanel, '-property', 'visible'), 'visible', 'on'); set(handles.num_int,'Enable','off' ); %Cases which use numerical integration panel case 6 set(handles.num_int,'Enable','on' ); otherwise Vertical_ref_curs=getappdata(h_main_plot,'Vertical_ref_curs'); setappdata(h_main_plot,'Vertical_ref_state',0); if ~isempty(Vertical_ref_curs) Vertical_ref_curs.off(); end set(handles.num_int,'Enable','off' ); set(findall(handles.RecordPanel, '-property', 'visible'), 'visible', 'off'); end % setappdata(h_main_plot,'Vcursor_toggle_state',VC_ref_state); % --- Executes during object creation, after setting all properties. function Analyze_list_CreateFcn(hObject, eventdata, handles) % hObject handle to Analyze_list (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in Trace. function Trace_Callback(hObject, eventdata, handles) % hObject handle to Trace (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns Trace contents as cell array % contents{get(hObject,'Value')} returns selected item from Trace % --- Executes during object creation, after setting all properties. function Trace_CreateFcn(hObject, eventdata, handles) % hObject handle to Trace (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in Analyse. function Analyse_Callback(hObject, eventdata, handles) % hObject handle to Analyse (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) h_main_plot=getappdata(0,'h_main_plot'); if(get(handles.Trace,'Value')==1) x_data=getappdata(h_main_plot,'x_data'); y_data=getappdata(h_main_plot,'y_data'); setappdata(h_main_plot,'x_analyze',x_data); setappdata(h_main_plot,'y_analyze',y_data); x_analyze=x_data; y_analyze=y_data; else x_ref=getappdata(h_main_plot,'x_ref'); y_ref=getappdata(h_main_plot,'y_ref'); setappdata(h_main_plot,'x_analyze',x_ref); setappdata(h_main_plot,'y_analyze',y_ref); x_analyze=x_ref; y_analyze=y_ref; end % check if the verital cursor is on Vcursor_toggle_state=getappdata(h_main_plot,'Vcursor_toggle_state'); if (Vcursor_toggle_state==1) % set the left and right cursor from the cursor lines Vertical_curs=getappdata(h_main_plot,'Vertical_curs'); v_curs_val=Vertical_curs.val(); setappdata(h_main_plot,'V1',v_curs_val(1)); setappdata(h_main_plot,'V2',v_curs_val(2)); else % set the left and right to limits of the data setappdata(h_main_plot,'V1',min(x_analyze)); setappdata(h_main_plot,'V2',max(x_analyze)); end % check if the Hriozontal cursor is on Hcursor_toggle_state=getappdata(h_main_plot,'Hcursor_toggle_state'); if (Hcursor_toggle_state==1) % set the up and down cursor from the cursor lines Horizontal_curs=getappdata(h_main_plot,'Horizontal_curs'); H_curs_val=Horizontal_curs.val(); setappdata(h_main_plot,'H1',H_curs_val(1)); setappdata(h_main_plot,'H2',H_curs_val(2)); else % set the up and down to limits of the data setappdata(h_main_plot,'H1',min(y_analyze)); setappdata(h_main_plot,'H2',max(y_analyze)); end switch get(handles.Analyze_list,'Value') case 2 knife_edge_calibration; case 3 Single_Lorentzian_fit; case 4 Lorentzian_interference_fit; case 5 Double_Lorentzian_fit; case 6 g0_calibration; case 7 Calibration_Vpi; case 8 Long_range_laser_sweep; case 9 Exponencial_fit; case 10 Resonant_Heating case 11 Resonant_Heating_cal; case 12 T_measurement; end % --- Executes on button press in Data_to_ref. function Data_to_ref_Callback(hObject, eventdata, handles) % hObject handle to Data_to_ref (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) h_main_plot=getappdata(0,'h_main_plot'); x_data=getappdata(h_main_plot,'x_data'); y_data=getappdata(h_main_plot,'y_data'); setappdata(gcf,'x_ref',x_data); setappdata(gcf,'y_ref',y_data); update_axes % --- Executes on button press in Show_Data. function Show_Data_Callback(hObject, eventdata, handles) % hObject handle to Show_Data (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of Show_Data h_main_plot=getappdata(0,'h_main_plot'); show_data=get(hObject,'Value'); setappdata(h_main_plot,'show_data',show_data); if(show_data==1) set(hObject, 'BackGroundColor',[0,1,.2]); elseif(show_data==0) set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); end update_axes % --- Executes on button press in Show_Ref. function Show_Ref_Callback(hObject, eventdata, handles) % hObject handle to Show_Ref (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of Show_Ref h_main_plot=getappdata(0,'h_main_plot'); show_ref=get(hObject,'Value'); setappdata(h_main_plot,'show_ref',show_ref); if show_ref set(hObject, 'BackGroundColor',[0,1,.2]); else set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); end update_axes %Placeholder -function SaveDir_Callback(hObject, eventdata, handles) +function BaseDir_Callback(hObject, eventdata, handles) % --- Executes during object creation, after setting all properties. -function SaveDir_CreateFcn(hObject, eventdata, handles) -% hObject handle to SaveDir (see GCBO) +function BaseDir_CreateFcn(hObject, eventdata, handles) +% hObject handle to BaseDir (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in open_folder. function open_folder_Callback(hObject, eventdata, handles) % hObject handle to open_folder (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Here we open the file and store its name and path for next steps folder_name = uigetdir('C:\Users\ghadimi\Desktop'); -set(handles.SaveDir,'string',[folder_name,'\']); +set(handles.BaseDir,'string',[folder_name,'\']); function SessionName_Callback(hObject, eventdata, handles) % hObject handle to SessionName (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of SessionName as text % str2double(get(hObject,'String')) returns contents of SessionName as a double % --- Executes during object creation, after setting all properties. function SessionName_CreateFcn(hObject, eventdata, handles) % hObject handle to SessionName (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function FileName_Callback(hObject, eventdata, handles) %Placeholder % --- Executes during object creation, after setting all properties. function FileName_CreateFcn(hObject, eventdata, handles) % hObject handle to FileName (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end -% --- Executes on button press in Auto_Naming. -function Auto_Naming_Callback(hObject, eventdata, handles) -% hObject handle to Auto_Naming (see GCBO) +% --- Executes on button press in AutoName. +function AutoName_Callback(hObject, eventdata, handles) +% hObject handle to AutoName (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) -% Hint: get(hObject,'Value') returns toggle state of Auto_Naming +% Hint: get(hObject,'Value') returns toggle state of AutoName -% --- Executes on button press in Save_Data. -function Save_Data_Callback(hObject, eventdata, handles) -% hObject handle to Save_Data (see GCBO) -% eventdata reserved - to be defined in a future version of MATLAB -% handles structure with handles and user data (see GUIDATA) -h_main_plot=getappdata(0,'h_main_plot'); - -auto_name_flag=get(handles.Auto_Naming,'value'); -if(auto_name_flag==1) - date_time = datestr(now,'yyyy-mm-dd_HH.MM.SS'); -else - date_time=''; -end -file_name=get(handles.FileName,'string'); -file_name=[file_name,date_time]; - -Session_name=get(handles.SessionName,'string'); -Session_name=[datestr(now,'yyyy-mm-dd '),Session_name]; -folder_name=get(handles.SaveDir,'string'); - -mkdir(folder_name,Session_name) - - -x_data=getappdata(h_main_plot,'x_data')'; -y_data=getappdata(h_main_plot,'y_data')'; -% We need to make sure the data in a column and not row -if ~iscolumn(x_data) - x_data=x_data'; - end - if ~iscolumn(y_data) - y_data=y_data'; - end - -data=[x_data,y_data]; - -setappdata(h_main_plot,'folder_path',[folder_name,Session_name]); -path=[folder_name,Session_name,'\',file_name,'.txt']; - - - if (exist(path)~=0) - setappdata(h_main_plot,'error_flag',1); - Overwite_Error; - while(getappdata(h_main_plot,'error_flag')==1) - pause(0.01); - end - if(getappdata(h_main_plot,'overwite_flag')==1) - save(path,'data','-ascii'); - setappdata(h_main_plot,'overwite_flag',0); - end - else - save(path,'data','-ascii'); - end - - - -% --- Executes on button press in Save_Ref. -function Save_Ref_Callback(hObject, eventdata, handles) -% hObject handle to Save_Ref (see GCBO) -% eventdata reserved - to be defined in a future version of MATLAB -% handles structure with handles and user data (see GUIDATA) -h_main_plot=getappdata(0,'h_main_plot'); - -auto_name_flag=get(handles.Auto_Naming,'value'); -if(auto_name_flag==1) - date_time = datestr(now,'yyyy-mm-dd_HH.MM.SS'); -else - date_time=''; -end -file_name=get(handles.FileName,'string'); -file_name=[file_name,date_time]; - -Session_name=get(handles.SessionName,'string'); -Session_name=[datestr(now,'yyyy-mm-dd '),Session_name]; -folder_name=get(handles.SaveDir,'string'); - -mkdir(folder_name,Session_name) - - -x_ref=getappdata(h_main_plot,'x_ref')'; -y_ref=getappdata(h_main_plot,'y_ref')'; -% We need to make sure the data in a column and not row -if ~iscolumn(x_ref) - x_ref=x_ref'; - end - if ~iscolumn(y_ref) - y_ref=y_ref'; - end -ref=[x_ref,y_ref]; - -setappdata(h_main_plot,'folder_path',[folder_name,Session_name]); -path=[folder_name,Session_name,'\',file_name,'.txt']; - - - - if (exist(path,'file')~=0) - setappdata(h_main_plot,'error_flag',1); - Overwite_Error; - while(getappdata(h_main_plot,'error_flag')==1) - pause(0.01); - end - if(getappdata(h_main_plot,'overwite_flag')==1) - save(path,'ref','-ascii'); - setappdata(h_main_plot,'overwite_flag',0); - end - else - save(path,'ref','-ascii'); - end - +%Callback now defined in class MyDaq. +function SaveData_Callback(hObject, eventdata, handles) +%Callback now defined in class MyDaq +function SaveRef_Callback(hObject, eventdata, handles) % --- Executes on button press in load_file. function load_file_Callback(hObject, eventdata, handles) % hObject handle to load_file (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) -folder_name=get(handles.SaveDir,'string'); +folder_name=get(handles.BaseDir,'string'); if(isempty(folder_name)) warning('Please input a valid folder name for loading a trace'); folder_name=pwd; end try [FileName,PathName]=uigetfile('.txt','Select the trace',folder_name); full_path=[PathName,FileName]; data_file=load(full_path'); catch error('Please select a valid file'); end h_main_plot=getappdata(0,'h_main_plot'); if (get(handles.Load_data,'value')==1) setappdata(h_main_plot,'x_data',data_file(:,1)); setappdata(h_main_plot,'y_data',data_file(:,2)); %Makes the trace visible when loaded set(handles.Show_Data,'Value',1); setappdata(h_main_plot,'show_data',1); set(handles.Show_Data, 'BackGroundColor',[0,1,.2]); else setappdata(h_main_plot,'x_ref',data_file(:,1)); setappdata(h_main_plot,'y_ref',data_file(:,2)); %Makes the trace visible when loaded set(handles.Show_Ref,'Value',1); setappdata(h_main_plot,'show_ref',1); set(handles.Show_Ref, 'BackGroundColor',[0,1,.2]); end update_axes % --- Executes on mouse press over figure background, over a disabled or % --- inactive control, or over an mainplot background. function figure1_WindowButtonDownFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(gcf,'WindowButtonUpFcn',@nothig) % -------------------------------------------------------------------- function Untitled_1_Callback(hObject, eventdata, handles) % hObject handle to Untitled_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Save_figure_Callback(hObject, eventdata, handles) % hObject handle to Save_figure (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Load the main data object of this analysis h_main_plot=getappdata(0,'h_main_plot'); % Store the data trace x_data=getappdata(h_main_plot,'x_data'); y_data=getappdata(h_main_plot,'y_data'); % Store the ref trace x_ref=getappdata(h_main_plot,'x_ref'); y_ref=getappdata(h_main_plot,'y_ref'); % Store the labels of the plot x_label=getappdata(h_main_plot,'x_label'); y_label=getappdata(h_main_plot,'y_label'); % Store the flags used to enable/disable data and ref in plot show_data=getappdata(h_main_plot,'show_data'); show_ref=getappdata(h_main_plot,'show_ref'); % Choosing the file name and its destinaiton -% folder_name=get(handles.SaveDir,'string'); % The pre assumption of the folder path +% folder_name=get(handles.BaseDir,'string'); % The pre assumption of the folder path folder_name=getappdata(h_main_plot,'folder_path'); [FileName,PathName] = uiputfile('*.jpg','Save as',folder_name); % Defining a new figure made temprory for export ftmp = figure; % Depend on the status of the show flags plot the data and ref traces if (show_data==1 && show_ref==0) plot(x_data,y_data,'b') elseif ((show_data==0 && show_ref==1)) plot(x_ref,y_ref,'k') elseif ((show_data==1 && show_ref==1)) plot(x_ref,y_ref,'k') hold on plot(x_data,y_data,'b') hold off else plot(0,0) end % Check if the show analyzed data flag is on, plot the analyzed data show_fit_flag=getappdata(h_main_plot,'show_fit_flag'); % a flag to show or not show the fitted data if(show_fit_flag==1) hold on x_analyze_done=getappdata(h_main_plot,'x_analyze_done'); % Data which has been analyze in x axis y_analyze_done=getappdata(h_main_plot,'y_analyze_done'); % Data which has been analyze in y axis plot(x_analyze_done,y_analyze_done,'r') hold off fit_meta_data=getappdata(h_main_plot,'fit_meta_data'); % a variable to store the analysis meta data fit_meta_data_name=getappdata(h_main_plot,'fit_meta_data_name'); % a variable to store the analysis meta data text_position=getappdata(h_main_plot,'fit_meta_data_text_position'); % a variable to store position of the text fo meta data (first is x and second y) str=[fit_meta_data_name(:,:) num2str(fit_meta_data(:),4) ]; text_opj=text(0,0,str,'Fontsize',14 ,'BackgroundColor',[1 1 1],'EdgeColor','red',... 'VerticalAlignment','top',... 'HorizontalAlignment','left'); buffer=1/50; % set the text position set(text_opj,'units','normalized'); fit_meta_data_text_position=getappdata(h_main_plot,'fit_meta_data_text_position'); if(fit_meta_data_text_position==1) set(text_opj,'Position',[ buffer,1-buffer]); set(text_opj,'HorizontalAlignment','Left'); set(text_opj,'VerticalAlignment','Top'); elseif(fit_meta_data_text_position==2) set(text_opj,'Position',[1-buffer, 1- buffer]); set(text_opj,'HorizontalAlignment','Right'); set(text_opj,'VerticalAlignment','Top'); elseif(fit_meta_data_text_position==3) set(text_opj,'Position',[buffer, buffer]); set(text_opj,'HorizontalAlignment','Left'); set(text_opj,'VerticalAlignment','Bottom'); elseif(fit_meta_data_text_position==4) set(text_opj,'Position',[1-buffer, buffer]); set(text_opj,'HorizontalAlignment','Right'); set(text_opj,'VerticalAlignment','Bottom'); end end % Enableing the grid grid on; % Putting the x and y lables xlabel(x_label); ylabel(y_label); new_axes=findobj(ftmp,'type','axes'); % Check if the X and Y axis should be linear or log scale if(getappdata(h_main_plot,'y_log_flag')==1) set(new_axes,'yscale','log'); else set(new_axes,'yscale','linear'); end if(getappdata(h_main_plot,'x_log_flag')==1) set(new_axes,'xscale','log'); else set(new_axes,'xscale','linear'); end if(getappdata(h_main_plot,'y_log_flag')==1) % Now ploting the cursors: % check to see if the there is Horizontal cursors or not Hcursor_toggle_state=getappdata(h_main_plot,'Hcursor_toggle_state'); if (Hcursor_toggle_state==1) Horizontal_curs=getappdata(h_main_plot,'Horizontal_curs'); h_curs_val=Horizontal_curs.val(); % store the value of the horizontal cursor Horizontal_cursors(new_axes,h_curs_val); % Make new cursors in the same position end % check to see if the there is Vertical cursors or not Vcursor_toggle_state=getappdata(h_main_plot,'Vcursor_toggle_state'); if (Vcursor_toggle_state==1) Vertical_curs=getappdata(h_main_plot,'Vertical_curs'); v_curs_val=Vertical_curs.val(); % store the value of the horizontal cursor Vertical_cursors(new_axes,v_curs_val); % Make new cursors in the same position end end % Definig an style for exported image myStyle = hgexport('factorystyle'); myStyle.Format = 'jpg'; myStyle.Width = 8; myStyle.Height = 4; myStyle.Resolution = 600; myStyle.Units = 'inch'; % myStyle.FixedFontSize = 12; % Exporting the image hgexport(ftmp,[PathName,FileName] ,myStyle,'Format','jpeg') % Deleting the figure delete(ftmp); % --- Executes on button press in Log_y. function Log_y_Callback(hObject, eventdata, handles) % hObject handle to Log_y (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of Log_y h_main_plot=getappdata(0,'h_main_plot'); setappdata(h_main_plot,'y_log_flag',get(hObject,'Value')); if(get(hObject,'Value')==1) set(hObject, 'BackGroundColor',[0,1,.2]); elseif(get(hObject,'Value')==0) set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); end update_axes % --- Executes on button press in Log_x. function Log_x_Callback(hObject, eventdata, handles) % hObject handle to Log_x (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of Log_x h_main_plot=getappdata(0,'h_main_plot'); setappdata(h_main_plot,'x_log_flag',get(hObject,'Value')); if(get(hObject,'Value')==1) set(hObject, 'BackGroundColor',[0,1,.2]); elseif(get(hObject,'Value')==0) set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); end update_axes % --- Executes on button press in Clear_fit. function Clear_fit_Callback(hObject, eventdata, handles) % hObject handle to Clear_fit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % import the main data object h_main_plot=getappdata(0,'h_main_plot'); % Check if the show analyzed data flag is on, turn it off or Vise versa show_fit_flag=getappdata(h_main_plot,'show_fit_flag'); % a flag to show or not show the fitted data if(show_fit_flag==1) setappdata(h_main_plot,'show_fit_flag',0); % reset the flag to zero end update_axes % This is the main function of this window which update the axis with the % proper plots (ref or data) and cursors function update_axes % First we load the main object of this program which store all variables % and functions used to communicate with general plot window h_main_plot=getappdata(0,'h_main_plot'); % First we check is the status flag for Horizontal cursor is off or on and % if it is on, we Hcursor_toggle_state=getappdata(h_main_plot,'Hcursor_toggle_state'); if (Hcursor_toggle_state==1) Horizontal_curs=getappdata(h_main_plot,'Horizontal_curs'); h_curs_val=Horizontal_curs.val(); Horizontal_curs.off(); end Vcursor_toggle_state=getappdata(h_main_plot,'Vcursor_toggle_state'); if (Vcursor_toggle_state==1) Vertical_curs=getappdata(h_main_plot,'Vertical_curs'); v_curs_val=Vertical_curs.val(); Vertical_curs.off(); end Vertical_ref_state=getappdata(h_main_plot,'Vertical_ref_state'); if (Vertical_ref_state==1) Vertical_ref_curs=getappdata(h_main_plot,'Vertical_ref_curs'); v_ref_curs_val=Vertical_ref_curs.val(); Vertical_ref_curs.off(); end x_data=getappdata(h_main_plot,'x_data'); y_data=getappdata(h_main_plot,'y_data'); x_ref=getappdata(h_main_plot,'x_ref'); y_ref=getappdata(h_main_plot,'y_ref'); x_label=getappdata(h_main_plot,'x_label'); y_label=getappdata(h_main_plot,'y_label'); show_data=getappdata(h_main_plot,'show_data'); show_ref=getappdata(h_main_plot,'show_ref'); axes=findobj(h_main_plot,'type','axes'); if (show_data==1 && show_ref==0) plot(axes,x_data,y_data,'b') elseif ((show_data==0 && show_ref==1)) plot(axes,x_ref,y_ref,'k') elseif ((show_data==1 && show_ref==1)) plot(axes,x_ref,y_ref,'k') hold(axes, 'on'); plot(axes,x_data,y_data,'b') hold(axes, 'off'); else plot(axes,0,0) end % Check if the show analyzed data flag is on, plot the analyzed data show_fit_flag=getappdata(h_main_plot,'show_fit_flag'); % a flag to show or not show the fitted data if(show_fit_flag==1) hold(axes, 'on'); x_analyze_done=getappdata(h_main_plot,'x_analyze_done'); % Data which has been analyze in x axis y_analyze_done=getappdata(h_main_plot,'y_analyze_done'); % Data which has been analyze in y axis plot(axes,x_analyze_done,y_analyze_done,'r') hold(axes, 'off'); end xlabel(axes,x_label); ylabel(axes,y_label); if(getappdata(h_main_plot,'y_log_flag')==1); set(axes,'yscale','log'); end if(getappdata(h_main_plot,'x_log_flag')==1); set(axes,'xscale','log'); end if (Hcursor_toggle_state==1) Horizontal_curs=Horizontal_cursors(axes,h_curs_val); setappdata(h_main_plot,'Horizontal_curs',Horizontal_curs); end if (Vcursor_toggle_state==1) Vertical_curs=Vertical_cursors(axes,v_curs_val); setappdata(h_main_plot,'Vertical_curs',Vertical_curs); end if (Vertical_ref_state==1) Vertical_ref_curs=Vertical_cursors_ref(axes,v_ref_curs_val); setappdata(h_main_plot,'Vertical_ref_curs',Vertical_ref_curs); end % --- Executes on button press in record. function record_Callback(hObject, eventdata, handles) % hObject handle to record (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %Takes the data from the fit try h_main_plot=getappdata(0,'h_main_plot'); fit_meta_data=getappdata(h_main_plot,'fit_meta_data'); f=fit_meta_data(1); lw=fit_meta_data(2); Q=fit_meta_data(3); catch error('No fit parameters found') end %Standardized save path save_path=[handles.Drive_Letter,':\Measurement Campaigns\']; %Checks if a session name and file name is given if ~isstr(get(handles.SessionName,'string')) error('No session name given') elseif ~isstr(get(handles.FileName,'string')) error('No file name given') end %Puts the date in front of the session name session_name=[datestr(now,'yyyy-mm-dd '),... get(handles.SessionName,'string'),'\']; %Makes the path if it does not exist if ~exist([save_path,session_name],'dir') mkdir(save_path,session_name); end %Full path final_path=[save_path,session_name,'Q factor','.txt']; %Creates the file if it does not exist, otherwise opens the file if ~exist(final_path,'file') fileID=fopen(final_path,'w'); %Creates headers in the file fmt=['%s\t%s\t%s\t\t%s\t%s\t\r\n']; fprintf(fileID,fmt,'Beam#','f(MHz)','Q(10^6)','Q*f(10^14)','lw'); else fileID=fopen(final_path,'a'); end %Formatting string fmt=['%s\t%3.3f\t%3.3f\t\t%3.3f\t\t%3.3f\r\n']; tag=get(handles.edit_tag,'string'); fprintf('Data saved in %s',final_path); %Reshapes the data in appropriate units fprintf(fileID,fmt,tag{1},f/1e6,Q/1e6,Q*f/1e14,lw); fclose(fileID); function edit_tag_Callback(hObject, eventdata, handles) % hObject handle to edit_tag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_tag as text % str2double(get(hObject,'String')) returns contents of edit_tag as a double % --- Executes during object creation, after setting all properties. function edit_tag_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_tag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in Data_to_BG. function Data_to_BG_Callback(hObject, eventdata, handles) % hObject handle to Data_to_BG (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) h_main_plot=getappdata(0,'h_main_plot'); setappdata(h_main_plot,'y_BG',getappdata(h_main_plot,'y_data')); setappdata(h_main_plot,'y_BG_mean',mean(getappdata(h_main_plot,'y_data'))); % --- Executes on button press in Ref_to_BG. function Ref_to_BG_Callback(hObject, eventdata, handles) % hObject handle to Ref_to_BG (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) h_main_plot=getappdata(0,'h_main_plot'); setappdata(h_main_plot,'y_BG',getappdata(h_main_plot,'y_ref')); setappdata(h_main_plot,'y_BG_mean',mean(getappdata(h_main_plot,'y_ref'))); % --- Executes on button press in Clear_BG. function Clear_BG_Callback(hObject, eventdata, handles) % hObject handle to Clear_BG (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) h_main_plot=getappdata(0,'h_main_plot'); setappdata(h_main_plot,'y_BG',0); setappdata(h_main_plot,'y_BG_mean',1); % --- Executes on button press in Subtract_BG. function Subtract_BG_Callback(hObject, eventdata, handles) % hObject handle to Subtract_BG (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of Subtract_BG h_main_plot=getappdata(0,'h_main_plot'); if (get(hObject,'Value')==1) set(hObject, 'BackGroundColor',[0,1,.2]); y_data=getappdata(h_main_plot,'y_data')-getappdata(h_main_plot,'y_BG'); else set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); y_data=getappdata(h_main_plot,'y_data')+getappdata(h_main_plot,'y_BG'); end setappdata(h_main_plot,'y_data',y_data); update_axes % --- Executes on button press in togglebutton9. function togglebutton9_Callback(hObject, eventdata, handles) % hObject handle to togglebutton9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of togglebutton9 % --- Executes on button press in num_int. function num_int_Callback(hObject, eventdata, handles) % hObject handle to num_int (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of num_int