diff --git a/@MyDaq/MyDaq.m b/@MyDaq/MyDaq.m
new file mode 100644
index 0000000..e009bac
--- /dev/null
+++ b/@MyDaq/MyDaq.m
@@ -0,0 +1,107 @@
+classdef MyDaq < handle
+    properties
+        Gui;
+        Reference;
+        Data;
+        Background;
+        Instruments;
+        Cursors;
+        Fits;
+        Parser;
+        save_dir;
+        session_name;
+        file_name;
+        enable_gui;
+    end
+    
+    properties (Dependent=true)
+        save_path;
+        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, ...
+                eventdata));
+            set(this.Gui.SessionName,'Callback',...
+                @(hObject, eventdata) sessionNameCallback(this, hObject, ...
+                eventdata));
+            set(this.Gui.FileName,'Callback',...
+                @(hObject, eventdata) fileNameCallback(this, hObject, ...
+                eventdata));
+        end
+        
+        function saveDirCallback(this, hObject, ~)
+            %Modify this at some point to use uiputfile instead
+            this.save_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;
+        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
new file mode 100644
index 0000000..d4bc364
--- /dev/null
+++ b/@MyDaq/initRt.m
@@ -0,0 +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);
+
+end
\ No newline at end of file
diff --git a/@MyDaq/initUhq.m b/@MyDaq/initUhq.m
new file mode 100644
index 0000000..0bac3cf
--- /dev/null
+++ b/@MyDaq/initUhq.m
@@ -0,0 +1,13 @@
+function initUhq(this)
+
+set(this.Gui.InstrumentMenu,'String',{'Select the device',...
+    'Oscilloscope 1 (Tektronix DPO 4034)',...
+    'Spectrum Analyzer (Agilent MXA)',...
+    'UHF Lock-in Amplifier (Zurich Instrument)',...
+    'Network Analyzer (Agilent NA)',...
+    'Auto Ringdown (Agilent NA)'});
+
+this.save_dir='W:\Measurement Campaigns\';
+set(this.Gui.SaveDir,'String',this.save_dir);
+
+end
\ No newline at end of file
diff --git a/@MyFit/MyFit.m b/@MyFit/MyFit.m
index fe4b718..387b287 100644
--- a/@MyFit/MyFit.m
+++ b/@MyFit/MyFit.m
@@ -1,286 +1,286 @@
 classdef MyFit < handle
     properties
         Gui
         Data;
         Fit;
         Parser;
         fit_name='linear'
         init_params=[];
         scale_init=[];
         lim_lower;
         lim_upper;
         FitStruct;
         Fitdata;
         coeffs;
         enable_gui=1;
         enable_plot;
         plot_handle;
         hline_init;
     end
     
     properties (Dependent=true)
         fit_function;
         fit_tex;
         fit_params;
         fit_param_names;
         valid_fit_names;
         n_params;
         scaled_params;
         init_param_fun;
     end
     
     events 
         NewFit;
     end
     
     methods
         function this=MyFit(varargin)
             createFitStruct(this);
             createParser(this);
             parse(this.Parser,varargin{:});
             parseInputs(this);
             if ismember('Data',this.Parser.UsingDefaults) &&...
                     ~ismember('x',this.Parser.UsingDefaults) &&...
                     ~ismember('y',this.Parser.UsingDefaults)
                 
                 this.Data.x=this.Parser.Results.x;
                 this.Data.y=this.Parser.Results.y;
             end
             
             if ~isempty(this.Data.x) || ~isempty(this.Data.y)
                 genInitParams(this);
             else
                 this.init_params=ones(1,this.n_params);
             end
             
             this.scale_init=ones(1,this.n_params);
             
             if this.enable_gui
                 createGui(this);
             end         
         end
         
         %Creates the GUI of MyFit
         createGui(this);
         
         function delete(this)
             if this.enable_gui
                 set(this.Gui.Window,'CloseRequestFcn','');
                 %Deletes the figure
                 delete(this.Gui.Window);
                 %Removes the figure handle to prevent memory leaks
                 this.Gui=[];
             end
         end
 
         %Close figure callback simply calls delete function for class
         function closeFigure(this,~,~)
             delete(this);
         end
         
         function createParser(this)
             p=inputParser;
             addParameter(p,'fit_name','linear',@ischar)
             addParameter(p,'Data',MyTrace());
             addParameter(p,'Fit',MyTrace());
             addParameter(p,'x',[]);
             addParameter(p,'y',[]);
             addParameter(p,'enable_gui',1);
             addParameter(p,'enable_plot',0);
             addParameter(p,'plot_handle',[]);
             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 fitTrace(this)
             this.Fit.x=linspace(min(this.Data.x),max(this.Data.x),1e3);
             switch this.fit_name
                 case 'linear'
                     this.coeffs=polyfit(this.Data.x,this.Data.y,1);
                     this.Fit.y=polyval(this.coeffs,this.Fit.x);
                 case 'quadratic'
                     this.coeffs=polyfit(this.Data.x,this.Data.y,2);
                     this.Fit.y=polyval(this.coeffs,this.Fit.x);
                 case {'exponential','gaussian','lorentzian'}
                     doFit(this);
                     this.coeffs=coeffvalues(this.Fitdata);
                     this.Fit.y=this.Fitdata(this.Fit.x);
                 otherwise
                     doFit(this);
                     this.Fit.y=this.Fitdata(this.Fit.x);
                     this.coeffs=coeffvalues(this.Fitdata);
             end
             
             this.init_params=this.coeffs;
             this.scale_init=ones(1,this.n_params);
             triggerNewFit(this);
             if this.enable_gui; updateGui(this); end
             if this.enable_plot; plotFit(this); end
         end
         
         function doFit(this)
             this.Fitdata=fit(this.Data.x,this.Data.y,this.fit_function,...
                 'Lower',this.lim_lower,'Upper',this.lim_upper,...
                 'StartPoint',this.init_params);
         end
         
         function triggerNewFit(this)
             notify(this,'NewFit');
         end
         
         function plotFit(this)
             plot(this.plot_handle,this.Fit.x,this.Fit.y);
         end
         
         function createFitStruct(this)
             %Adds fits
             addFit(this,'linear','a*x+b','$$ax+b$$',{'a','b'},...
                 {'Gradient','Offset'})
             addFit(this,'quadratic','a*x^2+b*x+c','$$ax^2+bx+c$$',...
                 {'a','b','c'},{'Quadratic coeff.','Linear coeff.','Offset'});
             addFit(this,'gaussian','a*exp(-((x-c)/b)^2/2)+d',...
                 '$$ae^{-\frac{(x-c)^2}{2b^2}}+d$$',{'a','b','c','d'},...
                 {'Amplitude','Width','Center','Offset'});
             addFit(this,'lorentzian','a/(pi)*(b/2/((x-c)^2+(b/2)^2))+d',...
-                '$$\frac{a}{1+\frac{b/2}{(x-c)^2+(b/2)^2}}+d$$',{'a','b','c','d'},...
+                '$$\frac{a}{\pi}{\frac{b/2}{(x-c)^2+(b/2)^2}}+d$$',{'a','b','c','d'},...
                 {'Amplitude','Width','Center','Offset'});
             addFit(this,'exponential','a*exp(b*x)+c',...
                 '$$ae^{bx}+c$$',{'a','b','c'},...
                 {'Amplitude','Rate','Offset'});
         end
         
         function updateGui(this)
             %Converts the scale variable to the value between 0 and 100
             %necessary for the slider
             slider_vals=25*log10(this.scale_init)+50;
             for i=1:this.n_params
                 set(this.Gui.(sprintf('edit_%s',this.fit_params{i})),...
                     'String',sprintf('%3.3e',this.scaled_params(i)));
                 set(this.Gui.(sprintf('slider_%s',this.fit_params{i})),...
                     'Value',slider_vals(i));
             end
         end
         
         %Adds a fit to the list of fits
         function addFit(this,fit_name,fit_function,fit_tex,fit_params,...
                 fit_param_names)
             this.FitStruct.(fit_name).fit_function=fit_function;
             this.FitStruct.(fit_name).fit_tex=fit_tex;
             this.FitStruct.(fit_name).fit_params=fit_params;
             this.FitStruct.(fit_name).fit_param_names=fit_param_names;
             %Generates the anonymous fit function from the above
             args=['@(x,', strjoin(fit_params,','),')'];
             anon_fit_fun=str2func(vectorize([args,fit_function]));
             this.FitStruct.(fit_name).anon_fit_fun=anon_fit_fun;         
         end
         
         function genInitParams(this)
             switch this.fit_name
                 case 'exponential'
                     [this.init_params,this.lim_lower,this.lim_upper]=...
                     initParamExponential(this.Data.x,this.Data.y);
                 case 'gaussian'
                     [this.init_params,this.lim_lower,this.lim_upper]=...
                     initParamGaussian(this.Data.x,this.Data.y);
                 case 'lorentzian'
                     [this.init_params,this.lim_lower,this.lim_upper]=...
                         initParamLorentzian(this.Data.x,this.Data.y);
                 otherwise
                     this.init_params=ones(1,this.n_params);
             end
         end
         function slider_Callback(this, param_ind, hObject, ~)
             %Gets the value from the slider
             scale=get(hObject,'Value');
             %Updates the scale with a new value
             this.scale_init(param_ind)=10^((scale-50)/25);
             %Updates the edit box with the new value from the slider
-            set(this.Gui.(sprintf('edit_%s',this.fit_params{param_ind})),...
+            set(this.Gui.(sprintf('Edit_%s',this.fit_params{param_ind})),...
                 'String',sprintf('%3.3e',this.scaled_params(param_ind)));
             if this.enable_plot; plotInitFun(this); end
 
         end
         
         function edit_Callback(this, hObject, ~)
             init_param=str2double(get(hObject,'String'));
             tag=get(hObject,'Tag');
             %Finds the index where the fit_param name begins (convention is
             %after the underscore)
             fit_param=tag((strfind(tag,'_')+1):end);
             param_ind=strcmp(fit_param,this.fit_params);
             %Updates the slider to be such that the scaling is 1
-            set(this.Gui.(sprintf('slider_%s',fit_param)),...
+            set(this.Gui.(sprintf('Slider_%s',fit_param)),...
                 'Value',50);
             %Updates the correct initial parameter
             this.init_params(param_ind)=init_param;
             if this.enable_plot; plotInitFun(this); end
         end
         
         function plotInitFun(this)
             %Substantially faster than any alternative - generating 
             %anonymous functions is very cpu intensive. 
             x_vec=linspace(min(this.Data.x),max(this.Data.x),1000);
             input_cell=num2cell(this.scaled_params);
             y_vec=feval(this.FitStruct.(this.fit_name).anon_fit_fun,x_vec,...
                 input_cell{:});
             if isempty(this.hline_init)
                 this.hline_init=plot(this.plot_handle,x_vec,y_vec);
             else
                 set(this.hline_init,'XData',x_vec,'YData',y_vec);
             end
         end
         
         function set.fit_name(this,fit_name)
             assert(ischar(fit_name),'The fit name must be a string');
             this.fit_name=lower(fit_name);
         end
         
         function valid_fit_names=get.valid_fit_names(this)
             valid_fit_names=fieldnames(this.FitStruct);
         end
         
         function fit_function=get.fit_function(this)
             assert(ismember(this.fit_name,this.valid_fit_names),...
                 '%s is not a supported fit name',this.fit_name);
             fit_function=this.FitStruct.(this.fit_name).fit_function;
         end
         
         function fit_tex=get.fit_tex(this)
             assert(ismember(this.fit_name,this.valid_fit_names),...
                 '%s is not a supported fit name',this.fit_name);
             fit_tex=this.FitStruct.(this.fit_name).fit_tex;
         end
         
         function fit_params=get.fit_params(this)
             assert(ismember(this.fit_name,this.valid_fit_names),...
                 '%s is not a supported fit name',this.fit_name);
             fit_params=this.FitStruct.(this.fit_name).fit_params;
         end
         
         function fit_param_names=get.fit_param_names(this)
             assert(ismember(this.fit_name,this.valid_fit_names),...
                 '%s is not a supported fit name',this.fit_name);
             fit_param_names=this.FitStruct.(this.fit_name).fit_param_names;
         end
         
         function scaled_params=get.scaled_params(this)
             scaled_params=this.scale_init.*this.init_params;
         end
         
         function n_params=get.n_params(this)
             n_params=length(this.fit_params);
         end
 
     end
 end
\ No newline at end of file
diff --git a/@MyFit/createGui.m b/@MyFit/createGui.m
index 33adfe4..2baf448 100644
--- a/@MyFit/createGui.m
+++ b/@MyFit/createGui.m
@@ -1,131 +1,129 @@
 function createGui(this)
 
 %Makes the fit name have the first letter capitalized
 fit_name=[upper(this.fit_name(1)),this.fit_name(2:end)];
 
 %Defines the colors for the Gui
 rgb_blue=[0.5843-0.4,0.8157-0.4,1];
 rgb_white=[1,1,1];
 
 %Width of the edit boxes in the GUI
 edit_width=120;
 
 %Name sets the title of the window, NumberTitle turns off the FigureN text
 %that would otherwise be before the title, MenuBar is the menu normally on
 %the figure, toolbar is the toolbar normally on the figure.
 %HandleVisibility refers to whether gcf, gca etc will grab this figure.
 this.Gui.Window = figure('Name', 'MyFit', 'NumberTitle', 'off', ...
     'MenuBar', 'none', 'Toolbar', 'none', 'HandleVisibility', 'off',...
     'Units','Pixels','Position',[500,500,edit_width*this.n_params,400]);
 %Sets the close function (runs when x is pressed) to be class function
 set(this.Gui.Window, 'CloseRequestFcn',...
     @(hObject,eventdata) closeFigure(this, hObject,eventdata));
 %The main vertical box. The four main panes of the GUI are stacked in the
 %box. We create these four boxes first so that we do not need to redraw
 %them later
 this.Gui.MainVbox=uix.VBox('Parent',this.Gui.Window,'BackgroundColor','w');
 %The title box
 this.Gui.Title=annotation(this.Gui.MainVbox,'textbox',[0.5,0.5,0.3,0.3],...
     'String',fit_name,'Units','Normalized',...
     'HorizontalAlignment','center','VerticalAlignment','middle',...
     'FontSize',16,'BackgroundColor',rgb_white);
 %Displays the fitted equation
 this.Gui.Equation=annotation(this.Gui.MainVbox,'textbox',[0.5,0.5,0.3,0.3],...
     'String',this.fit_tex,...
     'Units','Normalized','Interpreter','LaTeX',...
     'HorizontalAlignment','center','VerticalAlignment','middle',...
     'FontSize',20,'BackgroundColor',rgb_white);
 %Creates an HBox for extracted parameters and user interactions with GUI
 this.Gui.UserHbox=uix.HBox('Parent',this.Gui.MainVbox,'BackgroundColor',rgb_white);
 
 %Creates the HBox for the fitting parameters
 this.Gui.FitHbox=uix.HBox('Parent',this.Gui.MainVbox);
 
 %Sets the heights and minimum heights of the four vertical boxes. -1 means
 %it resizes with the window
 set(this.Gui.MainVbox,'Heights',[40,-1,-1,100],'MinimumHeights',[40,80,50,100]);
 
 %Here we create the save panel in the GUI.
 this.Gui.SavePanel=uix.BoxPanel( 'Parent', this.Gui.UserHbox,...
     'Padding',0,'BackgroundColor', rgb_white,...
     'Title','Save Panel','TitleColor',rgb_blue);
 %Here we create the panel for the useful parameters
 this.Gui.UserPanel=uix.BoxPanel( 'Parent', this.Gui.UserHbox,...
     'Padding',0,'BackgroundColor', 'w',...
     'Title','Calculated parameters','TitleColor',rgb_blue);
 
 %This makes the buttons that go inside the savepanel
 this.Gui.SaveVbox=uix.VBox('Parent',this.Gui.SavePanel,'BackgroundColor',...
     rgb_white);
 this.Gui.SaveButton=uicontrol('Parent',this.Gui.SaveVbox,...
     'style','pushbutton','Background','w','String','Save Fit');
 set(this.Gui.SaveVbox,'Heights',[25]);
 
 this.Gui.UserVbox=uix.VBox('Parent',this.Gui.UserPanel,'BackgroundColor',...
     rgb_white);
 switch this.fit_name
     case 'exponential'
         this.Gui.QHbox=uix.HBox('Parent',this.Gui.UserVbox,...
             'BackgroundColor',rgb_white);
         this.Gui.FreqLabel=annotation(this.Gui.QHbox,'textbox',[0.5,0.5,0.3,0.3],...
             'String','Frequency (MHz)','Units','Normalized',...
             'HorizontalAlignment','center','VerticalAlignment','middle',...
             'FontSize',10,'BackgroundColor',rgb_white);
 
         this.Gui.EditFreq=uicontrol('Parent',this.Gui.QHbox,...
             'Style','edit','String',1,'HorizontalAlignment','Right',...
             'FontSize',10,'Tag','EditFreq');
         set(this.Gui.QHbox,'Widths',[-4,-2]);
         set(this.Gui.UserVbox,'Heights',[25]);
 end
 
 %We first make the BoxPanels to speed up the process. Otherwise everything
 %in the BoxPanel must be redrawn every time we make a new one.
 panel_str=cell(1,this.n_params);
 for i=1:this.n_params
     %Generates the string for the panel handle
-    panel_str{i}=sprintf('panel_%s',this.fit_params{i});
+    panel_str{i}=sprintf('Panel_%s',this.fit_params{i});
     %Creates the panels
     this.Gui.(panel_str{i})=uix.BoxPanel( 'Parent', this.Gui.FitHbox ,...
         'Padding',0,'BackgroundColor', 'w',...
         'Title',sprintf('%s (%s)',this.fit_param_names{i},this.fit_params{i}),...
         'TitleColor',rgb_blue);
 end
 
 %Loops over number of parameters to create a fit panel for each one
 for i=1:this.n_params
     %Generates the string for the vbox handle
-    vbox_str=sprintf('vbox_%s',this.fit_params{i});
+    vbox_str=sprintf('Vbox_%s',this.fit_params{i});
     %Generates the string for the slider handle
-    slider_str=sprintf('slider_%s',this.fit_params{i});
+    slider_str=sprintf('Slider_%s',this.fit_params{i});
     %Generates string for edit panels
-    edit_str=sprintf('edit_%s',this.fit_params{i});
+    edit_str=sprintf('Edit_%s',this.fit_params{i});
     
     %Creates the vbox inside the panel that allows stacking
-    this.Gui.(sprintf('vbox_%s',this.fit_params{i})) =uix.VBox( 'Parent', ...
+    this.Gui.(vbox_str) =uix.VBox( 'Parent', ...
         this.Gui.(panel_str{i}),'Padding',0,'BackgroundColor', 'w');
     
     %Generates edit box for fit parameters
     this.Gui.(edit_str)=uicontrol('Parent',this.Gui.(vbox_str),...
         'Style','edit','String',sprintf('%3.3e',this.init_params(i)),...
         'FontSize',14,'Tag',edit_str,'HorizontalAlignment','Right',...
         'Callback',...
         @(hObject,eventdata) edit_Callback(this, hObject, eventdata));
     %Generates java-based slider. Looks nicer than MATLAB slider
-    this.Gui.(sprintf('slider_%s',this.fit_params{i}))=...
-        uicomponent('Parent',this.Gui.(vbox_str),'style',...
-        'jslider','pos',[0,0,95,45],'Value',72,'Orientation',0,...
-        'MajorTickSpacing',20,'MinorTickSpacing',5,...
-        'Paintlabels',0,'PaintTicks',1,'Value',50,'Background',...
-        java.awt.Color.white);
+    this.Gui.(slider_str)=uicomponent('Parent',this.Gui.(vbox_str),...
+        'style','jslider','pos',[0,0,95,45],'Value',72,'Orientation',0,...
+        'MajorTickSpacing',20,'MinorTickSpacing',5,'Paintlabels',0,...
+        'PaintTicks',1,'Value',50,'Background',java.awt.Color.white);
     
     %Sets up callbacks for the slider
     this.Gui.([slider_str,'_callback'])=handle(this.Gui.(slider_str),...
         'CallbackProperties');
     this.Gui.([slider_str,'_callback']).StateChangedCallback = ....
         @(hObject, eventdata) slider_Callback(this,i,hObject,eventdata);
     %Sets heights and minimum heights for the elements in the fit vbox
     set(this.Gui.(vbox_str),'Heights',[30,55],'MinimumHeights',[30,55])
 end
 
 end
\ No newline at end of file
diff --git a/@MyNa/MyNa.m b/@MyNa/MyNa.m
index 733896a..188a9e9 100644
--- a/@MyNa/MyNa.m
+++ b/@MyNa/MyNa.m
@@ -1,113 +1,113 @@
 classdef MyNa < MyInstrument
     properties (SetAccess=protected, GetAccess=public)
         ifbw;
         start_freq;
         stop_freq;
         cent_freq;
         span;
         power;
         Trace;
     end
 
     methods
         function this=MyNa(name, interface, address, varargin)
             this@MyInstrument(name, interface, address,varargin{:});
             createCommandList(this);
             createCommandParser(this);
             if this.enable_gui; initGui(this); end
         end
         
         function createCommandList(this)
             addCommand(this,'cent_freq','SENS:FREQ:CENT %d',...
                 'default',1.5e6,'attributes',{{'numeric'}},'write_flag',true);
             addCommand(this,'start_freq','SENS:FREQ:START %d',...
                 'default',1e6,'attributes',{{'numeric'}},'write_flag',true);
             addCommand(this,'stop_freq','SENS:FREQ:STOP %d',...
                 'default',2e6,'attributes',{{'numeric'}},'write_flag',true);
             addCommand(this,'span','SENS:FREQ:SPAN %d',...
                 'default',1e6,'attributes',{{'numeric'}},'write_flag',true);
             addCommand(this,'power','SOUR:POW:LEV:IMM:AMPL %d',...
                 'default',1,'attributes',{{'numeric'}},'write_flag',true);
 
         end
         
         function initGui(this)
             set(this.Gui.reinit, 'Callback',...
                 @(hObject, eventdata) reinitCallback(this, hObject,...
                 eventdata));
             set(this.Gui.start_freq, 'Callback',...
                 @(hObject, eventdata) start_freqCallback(this, hObject,...
                 eventdata));
             set(this.Gui.stop_freq, 'Callback',...
                 @(hObject, eventdata) stop_freqCallback(this, hObject,...
                 eventdata));
             set(this.Gui.cent_freq, 'Callback',...
                 @(hObject, eventdata) cent_freqCallback(this, hObject,...
                 eventdata));
             set(this.Gui.span, 'Callback',...
                 @(hObject, eventdata) spanCallback(this, hObject,...
                 eventdata));
             set(this.Gui.ifbw, 'Callback',...
                 @(hObject, eventdata) rbwCallback(this, hObject,...
                 eventdata));
             set(this.Gui.fetch_single, 'Callback',...
                 @(hObject, eventdata) fetchCallback(this, hObject,...
                 eventdata));
             set(this.Gui.average_no, 'Callback',...
                 @(hObject, eventdata) average_noCallback(this, hObject,...
                 eventdata));
             set(this.Gui.enable_avg, 'Callback',...
                 @(hObject, eventdata) enable_avgCallback(this, hObject,...
                 eventdata));
         end
         
-        function start_freqCallback(this, hObject, eventdata)
+        function start_freqCallback(this, hObject, ~)
             this.start_freq=str2double(get(hObject,'String'))*1e6;
             openDevice(this);
             writeProperty(this,'start_freq',this.start_freq);
             readStatus(this);
             closeDevice(this);
         end
         
-        function stop_freqCallback(this, hObject, eventdata)
+        function stop_freqCallback(this, hObject, ~)
             this.stop_freq=str2double(get(hObject,'String'))*1e6;
             openDevice(this);
             writeProperty(this,'stop_freq',this.stop_freq);
             readStatus(this);
             closeDevice(this);
         end
         
-        function cent_freqCallback(this, hObject, eventdata)
+        function cent_freqCallback(this, hObject, ~)
             this.cent_freq=str2double(get(hObject,'String'))*1e6;
             openDevice(this);
             writeProperty(this,'cent_freq',this.cent_freq);
             readStatus(this);
             closeDevice(this);
         end
-        function spanCallback(this, hObject, eventdata)
+        function spanCallback(this, hObject, ~)
             this.span=str2double(get(hObject,'String'))*1e6;
             openDevice(this);
             writeProperty(this,'span',this.span);
             readStatus(this)
             closeDevice(this);
         end
         
-        function ifbwCallback(this, hObject, eventdata)
+        function ifbwCallback(this, hObject, ~)
             this.ifbw=str2double(get(hObject,'String'))*1e3;
             openDevice(this);
             writeProperty(this,'ifbw',this.ifbw);
             closeDevice(this);
         end
         
-        function average_noCallback(this, hObject, eventdata)
+        function average_noCallback(this, hObject, ~)
             this.average_no=str2double(get(hObject,'String'));
             %Writes the average_no to the device only if averaging is
             %enabled
             openDevice(this);
             writeProperty(this,'average_no',this.average_no);
             closeDevice(this);
         end
         
         
     end
 end
diff --git a/@MyScope/MyScope.m b/@MyScope/MyScope.m
index abd673d..22951a8 100644
--- a/@MyScope/MyScope.m
+++ b/@MyScope/MyScope.m
@@ -1,113 +1,113 @@
 classdef MyScope <MyInstrument
     properties
         Trace;
         channel;
     end
     
     methods
         function this=MyScope(name, interface, address, varargin)
             this@MyInstrument(name, interface, address, varargin{:});
             if this.enable_gui; initGui(this); end
             createCommandList(this);
             createCommandParser(this);
             switch interface
                 case 'TCPIP'
                     connectTCPIP(this);
                 case 'USB'
                     connectUSB(this);
             end
         end
         
         function connectTCPIP(this)
             this.Device= visa('ni',...
                 sprintf('TCPIP0::%s::inst0::INSTR',this.address));
             set(this.Device,'InputBufferSize',1e6);
             set(this.Device,'Timeout',2);
         end
         
         function connectUSB(this)
             this.Device=visa('ni',sprintf('USB0::%s::INSTR',this.address));
             set(this.Device,'InputBufferSize',1e6);
             set(this.Device,'Timeout',2);
         end
                 
         function initGui(this)
             set(this.Gui.channel_select, 'Callback',...
                 @(hObject, eventdata) channel_selectCallback(this, ...
                 hObject,eventdata));
             set(this.Gui.fetch_single, 'Callback',...
                 @(hObject, eventdata) fetch_singleCallback(this, ...
                 hObject,eventdata));
             set(this.Gui.cont_read, 'Callback',...
                 @(hObject, eventdata) cont_readCallback(this, ...
                 hObject,eventdata));
         end
         
-        function channel_selectCallback(this, hObject, eventdata)
+        function channel_selectCallback(this, hObject, ~)
             this.channel=get(hObject,'Value');
         end
         
-        function fetch_singleCallback(this,hObject,eventdata)
+        function fetch_singleCallback(this,~,~)
             readTrace(this);
         end
         
-        function cont_readCallback(this, hObject, eventdata)
+        function cont_readCallback(this, hObject, ~)
             while get(hObject,'Value')
                 readTrace(this)
             end
         end
         
          function createCommandList(this)
              addCommand(this,'channel','DATa:SOUrce CH%d','default',1,...
                  'attributes',{{'numeric'}},'write_flag',true);
          end
     end
     
     methods 
         function set.channel(this, channel)
             if any(channel==1:4)
                 this.channel=channel;
             else
                 this.channel=1;
                 warning('Select a channel from 1 to 4')
             end
             %Sets the gui if the gui is enabled
             if this.enable_gui 
                 set(this.Gui.channel_select,'Value',this.channel);
             end
         end
         
         function readTrace(this)
             openDevice(this);
             %Sets the channel to be read
             writeProperty(this,'channel',this.channel);
             %Sets the encoding of the data
             fprintf(this.Device,'DATa:ENCdg ASCIi');
             
             % Reading the units of x and y
             unit_y = strtrim(query(this.Device,'WFMOutpre:YUNit?'));
             unit_x = strtrim(query(this.Device,'WFMOutpre:XUNit?'));
 
             % Reading the vertical spacing between points
-            step_y = str2num(query(this.Device,'WFMOutpre:YMUlt?'));
+            step_y = str2num(query(this.Device,'WFMOutpre:YMUlt?')); %#ok<ST2NM>
             
             % Reading the y axis data
-            y= str2num(query(this.Device,'CURVe?'))*step_y;
+            y= str2num(query(this.Device,'CURVe?'))*step_y; %#ok<ST2NM>
             n_points=length(y);
             % Reading the horizontal spacing between points
-            x_step=str2num(query(this.Device,'WFMOutpre:XINcr?'));
+            x_step=str2num(query(this.Device,'WFMOutpre:XINcr?'));%#ok<ST2NM>
             %Reads where the zero of the x-axis is
-            x_zero=str2num(query(this.Device,'WFMOutpre:XZEro?'));
+            x_zero=str2num(query(this.Device,'WFMOutpre:XZEro?'));%#ok<ST2NM>
             
             % Calculating the x axis
             x=linspace(x_zero,x_zero+x_step*(n_points-1),n_points);
             closeDevice(this)
             this.Trace=MyTrace('name','ScopeTrace','x',x,'y',y,'unit_x',unit_x(2),...
                 'unit_y',unit_y(2),'name_x','Time','name_y','Voltage');
             %Triggers the event for acquired data
             triggerNewData(this);
             
             this.Trace.plotTrace(this.plot_handle);
         end
     end
 end
\ No newline at end of file
diff --git a/GUIs/GuiDaq.fig b/GUIs/GuiDaq.fig
new file mode 100644
index 0000000..7188788
Binary files /dev/null and b/GUIs/GuiDaq.fig differ
diff --git a/GUIs/GuiDaq.m b/GUIs/GuiDaq.m
new file mode 100644
index 0000000..1d8e064
--- /dev/null
+++ b/GUIs/GuiDaq.m
@@ -0,0 +1,1413 @@
+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
+
+% 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)
+
+
+% --- Executes during object creation, after setting all properties.
+function SaveDir_CreateFcn(hObject, eventdata, handles)
+% hObject    handle to SaveDir (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,'\']);
+
+
+
+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)
+% 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
+
+
+% --- 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
+ 
+
+
+% --- 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');
+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=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