Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

compositiongui(varargin)
function varargout = compositiongui(varargin)
% COMPOSITIONGUI M-file for compositiongui.fig
%      COMPOSITIONGUI, by itself, creates a new COMPOSITIONGUI or raises the existing
%      singleton*.
%
%      H = COMPOSITIONGUI returns the handle to a new COMPOSITIONGUI or the handle to
%      the existing singleton*.
%
%      COMPOSITIONGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in COMPOSITIONGUI.M with the given input arguments.
%
%      COMPOSITIONGUI('Property','Value',...) creates a new COMPOSITIONGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before compositiongui_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to compositiongui_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 compositiongui

% Last Modified by GUIDE v2.5 28-Jul-2009 17:27:12

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @compositiongui_OpeningFcn, ...
                   'gui_OutputFcn',  @compositiongui_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 compositiongui is made visible.
function compositiongui_OpeningFcn(hObject, eventdata, handles, mainGuiHandle, mainGuiHandles)
% 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 compositiongui (see VARARGIN)

% checks the number of arguments
error(nargchk(5, 5, nargin))

% stashes the main GUI handles in the handles structure
handles.mainGuiHandle = mainGuiHandle;
handles.mainGuiHandles = mainGuiHandles;

% Update handles structure
guidata(hObject, handles)

% gets the object config and types
objectConfig = getappdata(mainGuiHandle, 'objectConfig');
objectTypes = getappdata(mainGuiHandle, 'objectTypes');

% pre-allocates a maximum number of pumps
maxPumps = 4;
pumps = NaN(maxPumps, 1);

% for each instrument
for m = 1:maxPumps
    % is it connected and is it a pump? - defined by the presence of the
    % writeFlow command
    if getappdata(mainGuiHandle, sprintf('collectDataFlag%d', m)) && ~isempty(objectTypes(objectConfig(m).type).writeFlowCommand)
        % add it to the list
        pumps(m) = m;
    end
end

% pulls out the NaNs to give a list of the instruments numbers which are
% pumps
pumps = pumps(~isnan(pumps));

% saves it to appdata
setappdata(hObject, 'pumps', pumps)

% for each pump
for n = 1:4
    % defines the fields
    pump = sprintf('pump%d', n);
    include = sprintf('include%d', n);
    density = sprintf('density%d', n);
    molarMass = sprintf('molarMass%d', n);
    efficiency = sprintf('efficiency%d', n);
    
    % are there enough pumps?
    if numel(pumps) >= n
        % gets the name
        set(handles.(pump), 'String', objectConfig(pumps(n)).name)
        
        % is it normally included?
        if isfield(objectConfig(pumps(n)).persistentData, 'include') && any(objectConfig(pumps(n)).persistentData.include == [0, 1])
            % fills the include checkbox
            set(handles.(include), 'Value', objectConfig(pumps(n)).persistentData.include)
            
        else
            % saves some dummy data there
            objectConfig(pumps(n)).persistentData.include = 1;
            set(handles.(include), 'Value', 1)
        end

        % is the density there?
        if isfield(objectConfig(pumps(n)).persistentData, 'density')
            % fills the density box
            set(handles.(density), 'String', num2str(objectConfig(pumps(n)).persistentData.density))
            
        else
            % saves some dummy data there
            objectConfig(pumps(n)).persistentData.density = 1;
            set(handles.(density), 'String', '1')
        end

        % the molar mass?
        if isfield(objectConfig(pumps(n)).persistentData, 'molarMass')
            % fills the density box
            set(handles.(molarMass), 'String', num2str(objectConfig(pumps(n)).persistentData.molarMass))
            
        else
            % saves some dummy data there and fills the box
            objectConfig(pumps(n)).persistentData.molarMass = 44.01;
            set(handles.(molarMass), 'String', '44.01')
        end

        % the efficiency?
        if isfield(objectConfig(pumps(n)).persistentData, 'efficiency')
            % fills the efficiency box
            set(handles.(efficiency), 'String', num2str(objectConfig(pumps(n)).persistentData.efficiency))
            
        else
            % saves some dummy data
            objectConfig(pumps(n)).persistentData.efficiency = 100;
            set(handles.(efficiency), 'String', '100')
        end
    else
        % disable the rest of the fields
        set([   handles.(include),...
                handles.(density),...
                handles.(molarMass),...
                handles.(efficiency),...
                handles.(sprintf('flow%d', n)),...
                handles.(sprintf('molarFraction%d', n)),...
                handles.(sprintf('massFraction%d', n))], 'Enable', 'off')
    end
end

% updates all of the flow rates
updateFlowButton_Callback(handles.updateFlowButton, eventdata, handles)

% for the rheodyne gas type
if isfield(objectConfig(9).persistentData, 'gasType')
    % fills the gas type menu
    set(handles.gasTypeMenu, 'Value', objectConfig(9).persistentData.gasType)
    
else
    % saves some dummy data (set to excluded)
    objectConfig(9).persistentData.gasType = 1;
end

% for the rheodyne loop size
if isfield(objectConfig(9).persistentData, 'loopSize')
    % fills the gas type menu
    set(handles.loopSize, 'String', sprintf('%.2f', objectConfig(9).persistentData.loopSize))
    
else
    % saves some dummy data
    objectConfig(9).persistentData.loopSize = 10;
end

% saves it back to appdata
setappdata(mainGuiHandle, 'objectConfig', objectConfig)

% gets the current switching time
updateSwitchingTimeButton_Callback(handles.updateSwitchingTimeButton, eventdata, handles)

% gets some more config
guiConfig = getappdata(mainGuiHandle, 'guiConfig');

% looks for the gas pressure channel in the guiConfig
if isfield(guiConfig, 'gasPressureChannel')
    % use that for the menu
    gasPressureChannel = guiConfig.gasPressureChannel;
    
else
    % sets it to 1
    gasPressureChannel = 1;
    guiConfig.gasPressureChannel = gasPressureChannel;
end

% if its not empty, then apply it
if isempty(gasPressureChannel)
    % set it to 1
    gasPressureChannel = 1;
end

% changes the menu
set(handles.gasPressureChannel, 'Value', gasPressureChannel)

% fills the gas pressure boxes
gasPressureChannel_Callback(handles.gasPressureChannel, eventdata, handles)

% gets the tc08 config
tc08Config = getappdata(mainGuiHandle, 'tc08Config');

% looks for the system pressure channel in the guiConfig
if isfield(guiConfig, 'systemPressureChannel')
    % use that for the menu
    systemPressureChannel = guiConfig.systemPressureChannel;
    
else
    % tries to find the system pressure
    systemPressureChannel = any(find(~cellfun('isempty', strfind(lower({tc08Config.name}), 'system'))));
    guiConfig.systemPressureChannel = systemPressureChannel;
end

% if its not empty, then apply it
if isempty(systemPressureChannel) || ~systemPressureChannel
    % set it to 1
    systemPressureChannel = 1;
end

% saves the updated config to appdata
setappdata(mainGuiHandle, 'guiConfig', guiConfig)

% changes the menu
set(handles.systemPressureChannel, 'Value', systemPressureChannel)

% fills the system pressure boxes
systemPressureChannel_Callback(handles.systemPressureChannel, eventdata, handles)

% runs the callback to calculate the composition
calculateComposition(hObject, handles)



% --- Designed to be run by all of the initial edit boxes to prevent text entry
function checkNumericCallback(callingObject, eventdata, handles)
% callingObject handle to the calling object
% eventdata     reserved - to be defined in a future version of MATLAB
% handles       structure with handles and user data (see GUIDATA)

% parses contents
newNumber = str2double(get(callingObject, 'String'));

% checks contents to see if they are numeric, finite, real and greater than
% or equal to 0
if ~isnewnumberbetween(newNumber, 0, Inf)
    % brings up an error dialog
    warntooltip(hObject, 'Must enter a finite real number greater than or equal to 0.')
    
    % clears the box
    set(callingObject, 'String', '')
    
else
    % re-runs the composition callback
    calculateComposition(getfigure(callingObject), handles)
end


% --- Designed to be run by all of the initial edit boxes to prevent text entry
function checkEfficiencyCallback(callingObject, eventdata, handles)
% callingObject handle to the calling object
% eventdata     reserved - to be defined in a future version of MATLAB
% handles       structure with handles and user data (see GUIDATA)

% parses contents
newNumber = str2double(get(callingObject, 'String'));

% checks contents to see if they are greater than 100
if ~isnumberbetween(newNumber, 0, 100)
    % brings up an error dialog
    warntooltip(hObject, 'Must enter a finite real number less than or equal to 100.')
    
    % clears the box
    set(callingObject, 'String', '100')
    
else
    % re-runs the composition callback
    calculateComposition(getfigure(callingObject), handles)
end


% --- Run by any part of the GUI to calculate the compositions
function calculateComposition(parent, handles)
% callingObject handle to calling object
% eventdata     reserved - to be defined in a future version of MATLAB
% handles       structure with handles and user data (see GUIDATA)

% pre-allocates
include = NaN(4, 1);
density = NaN(4, 1);
molarMass = NaN(4, 1);
efficiency = NaN(4, 1);
flow = NaN(4, 1);
validPumps = zeros(4, 1);

% gets the pumps from appdata
pumps = getappdata(parent, 'pumps');

% for each pump, fetches everything
for m = 1:4
    % gets everything
    include(m) = get(handles.(sprintf('include%d', m)), 'Value');
    density(m) = str2double(get(handles.(sprintf('density%d', m)), 'String'));
    molarMass(m) = str2double(get(handles.(sprintf('molarMass%d', m)), 'String'));
    efficiency(m) = str2double(get(handles.(sprintf('efficiency%d', m)), 'String'));
    flow(m) = str2double(get(handles.(sprintf('flow%d', m)), 'String'));

    % checks them if they should be included, or if any of the values are
    % dodgy
    if include(m) || all(~isnan([include(m), density(m), molarMass(m), efficiency(m), flow(m)]))
        % flag it as being OK but changing the 0 to the instrument number
        %validPumps(m) = pumps(m);
        validPumps(m) = 1;
    end
end

% calculates some things
massFlow = flow .* density .* (efficiency / 100);
molarFlow = massFlow ./ molarMass;

% converts the indexes into logical ones
validPumps = logical(validPumps);

% total is the ones that are valid
totalMassFlow = sum(massFlow(validPumps));
totalMolarFlow = sum(molarFlow(validPumps));

% gets the rheodyne stuff
gasType = get(handles.gasTypeMenu, 'Value');
loopSize = str2double(get(handles.loopSize, 'String')) / 1000;
switchingTime = str2double(get(handles.switchingTime, 'String'));
gasPressure = str2double(get(handles.gasPressure, 'String'));
systemPressure = str2double(get(handles.systemPressure, 'String'));

% depending on the gas type, define the densities
switch gasType
    case 1
        % this is excluded, so set it to NaN
        gasInputDensity = NaN;
        gasOutputDensity = NaN;
        gasMolarMass = NaN;
        
        % also clear out the other fields
        set([handles.gasMolarFraction, handles.gasMassFraction], 'String', '')
        
    case 2
        % this is for hydrogen
        gasInputDensity = -3.9858E-08 * gasPressure^2 + 8.1240E-05 * gasPressure + 6.1868E-05;
        gasOutputDensity = -3.9858E-08 * systemPressure^2 + 8.1240E-05 * systemPressure + 6.1868E-05;
        gasMolarMass = 2.02;
        
    case 3
        % this is for oxygen
        gasInputDensity = -1.199E-07 * gasPressure^2 + 1.417E-03 * gasPressure - 4.679E-03;
        gasOutputDensity = -1.199E-07 * systemPressure^2 + 1.417E-03 * systemPressure - 4.679E-03;
        gasMolarMass = 15.994;
end

% and the rest
effectiveGasDensity = gasInputDensity - gasOutputDensity;
valveSwitchesPerMinute = 60 / switchingTime;
effectiveGasFlow = valveSwitchesPerMinute * loopSize;
effectiveGasMassFlow = effectiveGasFlow * effectiveGasDensity;
effectiveGasMolarFlow = effectiveGasMassFlow / gasMolarMass;

% was the rheodyne involved?
if all(~isnan([gasInputDensity, gasOutputDensity, gasMolarMass]))
    % adds those on to the pumps totals
    totalMassFlow = totalMassFlow + effectiveGasMassFlow;
    totalMolarFlow = totalMolarFlow + effectiveGasMolarFlow;

    % fill those boxex
    set(handles.gasMolarFraction, 'String', num2str((effectiveGasMolarFlow / totalMolarFlow) * 100, '%.2f'))
    set(handles.gasMassFraction, 'String', num2str((effectiveGasMassFlow / totalMassFlow) * 100, '%.2f'))
end

% for each pump again...
for n = 1:4
    % was it allowed in?
    if validPumps(n)
        % fill their boxes
        set(handles.(sprintf('molarFraction%d', n)), 'String', num2str((molarFlow(n) / totalMolarFlow) * 100, '%.2f'))
        set(handles.(sprintf('massFraction%d', n)), 'String', num2str((massFlow(n) / totalMassFlow) * 100, '%.2f'))
        
    else
        % empty the boxes
        set(handles.(sprintf('molarFraction%d', n)), 'String', '')
        set(handles.(sprintf('massFraction%d', n)), 'String', '')
    end
end


% --- Outputs from this function are returned to the command line.
function compositiongui_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)



function pump1_Callback(hObject, eventdata, handles)
% hObject    handle to pump1 (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 pump1 as text
%        str2double(get(hObject,'String')) returns contents of pump1 as a double


% --- Executes during object creation, after setting all properties.
function pump1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pump1 (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 pump2_Callback(hObject, eventdata, handles)
% hObject    handle to pump2 (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 pump2 as text
%        str2double(get(hObject,'String')) returns contents of pump2 as a double


% --- Executes during object creation, after setting all properties.
function pump2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pump2 (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 pump3_Callback(hObject, eventdata, handles)
% hObject    handle to pump3 (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 pump3 as text
%        str2double(get(hObject,'String')) returns contents of pump3 as a double


% --- Executes during object creation, after setting all properties.
function pump3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pump3 (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 pump4_Callback(hObject, eventdata, handles)
% hObject    handle to pump4 (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 pump4 as text
%        str2double(get(hObject,'String')) returns contents of pump4 as a double


% --- Executes during object creation, after setting all properties.
function pump4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pump4 (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 include1.
function include1_Callback(hObject, eventdata, handles)
% hObject    handle to include1 (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 include1

% re-runs the composition callback
calculateComposition(getfigure(hObject), handles)


% --- Executes on button press in include2.
function include2_Callback(hObject, eventdata, handles)
% hObject    handle to include2 (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 include2

% re-runs the composition callback
calculateComposition(getfigure(hObject), handles)


% --- Executes on button press in include3.
function include3_Callback(hObject, eventdata, handles)
% hObject    handle to include3 (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 include3

% re-runs the composition callback
calculateComposition(getfigure(hObject), handles)


% --- Executes on button press in include4.
function include4_Callback(hObject, eventdata, handles)
% hObject    handle to include4 (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 include4

% re-runs the composition callback
calculateComposition(getfigure(hObject), handles)



function density1_Callback(hObject, eventdata, handles)
% hObject    handle to density1 (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 density1 as text
%        str2double(get(hObject,'String')) returns contents of density1 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function density1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to density1 (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 density2_Callback(hObject, eventdata, handles)
% hObject    handle to density2 (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 density2 as text
%        str2double(get(hObject,'String')) returns contents of density2 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function density2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to density2 (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 density3_Callback(hObject, eventdata, handles)
% hObject    handle to density3 (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 density3 as text
%        str2double(get(hObject,'String')) returns contents of density3 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function density3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to density3 (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 density4_Callback(hObject, eventdata, handles)
% hObject    handle to density4 (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 density4 as text
%        str2double(get(hObject,'String')) returns contents of density4 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function density4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to density4 (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 flow1_Callback(hObject, eventdata, handles)
% hObject    handle to flow1 (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 flow1 as text
%        str2double(get(hObject,'String')) returns contents of flow1 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function flow1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to flow1 (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 flow2_Callback(hObject, eventdata, handles)
% hObject    handle to flow2 (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 flow2 as text
%        str2double(get(hObject,'String')) returns contents of flow2 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function flow2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to flow2 (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 flow3_Callback(hObject, eventdata, handles)
% hObject    handle to flow3 (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 flow3 as text
%        str2double(get(hObject,'String')) returns contents of flow3 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function flow3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to flow3 (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 flow4_Callback(hObject, eventdata, handles)
% hObject    handle to flow4 (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 flow4 as text
%        str2double(get(hObject,'String')) returns contents of flow4 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function flow4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to flow4 (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 updateFlowButton.
function updateFlowButton_Callback(hObject, eventdata, handles)
% hObject    handle to updateFlowButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% gets the flow rates for all the pumps (also run on startup)

% gets the pump instrument numbers
pumps = getappdata(getfigure(hObject), 'pumps');

% for each pump
for m = 1:4
    % is the pump defined?
    if numel(pumps) >= m
        % fetches the current flow rate from the main GUI
        set(handles.(sprintf('flow%d', m)), 'String', get(handles.mainGuiHandles.(sprintf('flow%d', pumps(m))), 'String'))
    end
end


function molarFraction1_Callback(hObject, eventdata, handles)
% hObject    handle to molarFraction1 (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 molarFraction1 as text
%        str2double(get(hObject,'String')) returns contents of molarFraction1 as a double


% --- Executes during object creation, after setting all properties.
function molarFraction1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to molarFraction1 (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 molarFraction2_Callback(hObject, eventdata, handles)
% hObject    handle to molarFraction2 (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 molarFraction2 as text
%        str2double(get(hObject,'String')) returns contents of molarFraction2 as a double


% --- Executes during object creation, after setting all properties.
function molarFraction2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to molarFraction2 (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 molarFraction3_Callback(hObject, eventdata, handles)
% hObject    handle to molarFraction3 (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 molarFraction3 as text
%        str2double(get(hObject,'String')) returns contents of molarFraction3 as a double


% --- Executes during object creation, after setting all properties.
function molarFraction3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to molarFraction3 (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 moleFraction4_Callback(hObject, eventdata, handles)
% hObject    handle to moleFraction4 (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 moleFraction4 as text
%        str2double(get(hObject,'String')) returns contents of moleFraction4 as a double


% --- Executes during object creation, after setting all properties.
function moleFraction4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to moleFraction4 (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 efficiency1_Callback(hObject, eventdata, handles)
% hObject    handle to efficiency1 (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 efficiency1 as text
%        str2double(get(hObject,'String')) returns contents of efficiency1 as a double

% checks it for validity
checkEfficiencyCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function efficiency1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to efficiency1 (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 efficiency2_Callback(hObject, eventdata, handles)
% hObject    handle to efficiency2 (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 efficiency2 as text
%        str2double(get(hObject,'String')) returns contents of efficiency2 as a double

% checks it for validity
checkEfficiencyCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function efficiency2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to efficiency2 (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 efficiency3_Callback(hObject, eventdata, handles)
% hObject    handle to efficiency3 (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 efficiency3 as text
%        str2double(get(hObject,'String')) returns contents of efficiency3 as a double

% checks it for validity
checkEfficiencyCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function efficiency3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to efficiency3 (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 efficiency4_Callback(hObject, eventdata, handles)
% hObject    handle to efficiency4 (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 efficiency4 as text
%        str2double(get(hObject,'String')) returns contents of efficiency4 as a double

% checks it for validity
checkEfficiencyCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function efficiency4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to efficiency4 (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 molarMass1_Callback(hObject, eventdata, handles)
% hObject    handle to molarMass1 (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 molarMass1 as text
%        str2double(get(hObject,'String')) returns contents of molarMass1 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function molarMass1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to molarMass1 (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 molarMass2_Callback(hObject, eventdata, handles)
% hObject    handle to molarMass2 (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 molarMass2 as text
%        str2double(get(hObject,'String')) returns contents of molarMass2 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function molarMass2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to molarMass2 (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 molarMass3_Callback(hObject, eventdata, handles)
% hObject    handle to molarMass3 (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 molarMass3 as text
%        str2double(get(hObject,'String')) returns contents of molarMass3 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function molarMass3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to molarMass3 (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 molarMass4_Callback(hObject, eventdata, handles)
% hObject    handle to molarMass4 (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 molarMass4 as text
%        str2double(get(hObject,'String')) returns contents of molarMass4 as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function molarMass4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to molarMass4 (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 massFraction1_Callback(hObject, eventdata, handles)
% hObject    handle to massFraction1 (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 massFraction1 as text
%        str2double(get(hObject,'String')) returns contents of massFraction1 as a double


% --- Executes during object creation, after setting all properties.
function massFraction1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to massFraction1 (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 massFraction2_Callback(hObject, eventdata, handles)
% hObject    handle to massFraction2 (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 massFraction2 as text
%        str2double(get(hObject,'String')) returns contents of massFraction2 as a double


% --- Executes during object creation, after setting all properties.
function massFraction2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to massFraction2 (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 massFraction3_Callback(hObject, eventdata, handles)
% hObject    handle to massFraction3 (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 massFraction3 as text
%        str2double(get(hObject,'String')) returns contents of massFraction3 as a double


% --- Executes during object creation, after setting all properties.
function massFraction3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to massFraction3 (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 massFraction4_Callback(hObject, eventdata, handles)
% hObject    handle to massFraction4 (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 massFraction4 as text
%        str2double(get(hObject,'String')) returns contents of massFraction4 as a double


% --- Executes during object creation, after setting all properties.
function massFraction4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to massFraction4 (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 gasTypeMenu.
function gasTypeMenu_Callback(hObject, eventdata, handles)
% hObject    handle to gasTypeMenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns gasTypeMenu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from gasTypeMenu

% recalculate again
calculateComposition(getfigure(hObject), handles)


% --- Executes during object creation, after setting all properties.
function gasTypeMenu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to gasTypeMenu (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 gasPressureChannel.
function gasPressureChannel_Callback(hObject, eventdata, handles)
% hObject    handle to gasPressureChannel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns gasPressureChannel contents as cell array
%        contents{get(hObject,'Value')} returns selected item from gasPressureChannel

% fills the other boxes from the main GUI

% gets the new channel
newChannel = get(hObject, 'Value');

% only does this if its not a NaN
if ~isnan(newChannel)
    % fills the pressure and the units
    set(handles.gasPressure, 'String', get(handles.mainGuiHandles.(sprintf('picoValue%d', newChannel)), 'String'))
    set(handles.gasPressureUnits, 'String', get(handles.mainGuiHandles.(sprintf('picoUnits%d', newChannel)), 'String'))
    
    % re-runs the composition callback
    calculateComposition(getfigure(hObject), handles)
end


% --- Executes during object creation, after setting all properties.
function gasPressureChannel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to gasPressureChannel (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 systemPressureChannel.
function systemPressureChannel_Callback(hObject, eventdata, handles)
% hObject    handle to systemPressureChannel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns systemPressureChannel contents as cell array
%        contents{get(hObject,'Value')} returns selected item from systemPressureChannel

% gets the new channel
newChannel = get(hObject, 'Value');

% only does this if its not a NaN
if ~isnan(newChannel)
    % fills the pressure and the units
    set(handles.systemPressure, 'String', get(handles.mainGuiHandles.(sprintf('picoValue%d', newChannel)), 'String'))
    set(handles.systemPressureUnits, 'String', get(handles.mainGuiHandles.(sprintf('picoUnits%d', newChannel)), 'String'))
    
    % re-runs the composition callback
    calculateComposition(getfigure(hObject), handles)
end


% --- Executes during object creation, after setting all properties.
function systemPressureChannel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to systemPressureChannel (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



function gasPressure_Callback(hObject, eventdata, handles)
% hObject    handle to gasPressure (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 gasPressure as text
%        str2double(get(hObject,'String')) returns contents of gasPressure as a double

% checks its OK
checkNumeric(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function gasPressure_CreateFcn(hObject, eventdata, handles)
% hObject    handle to gasPressure (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 gasPressureUnits_Callback(hObject, eventdata, handles)
% hObject    handle to gasPressureUnits (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 gasPressureUnits as text
%        str2double(get(hObject,'String')) returns contents of gasPressureUnits as a double


% --- Executes during object creation, after setting all properties.
function gasPressureUnits_CreateFcn(hObject, eventdata, handles)
% hObject    handle to gasPressureUnits (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 systemPressure_Callback(hObject, eventdata, handles)
% hObject    handle to systemPressure (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 systemPressure as text
%        str2double(get(hObject,'String')) returns contents of systemPressure as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function systemPressure_CreateFcn(hObject, eventdata, handles)
% hObject    handle to systemPressure (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 systemPressureUnits_Callback(hObject, eventdata, handles)
% hObject    handle to systemPressureUnits (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 systemPressureUnits as text
%        str2double(get(hObject,'String')) returns contents of systemPressureUnits as a double


% --- Executes during object creation, after setting all properties.
function systemPressureUnits_CreateFcn(hObject, eventdata, handles)
% hObject    handle to systemPressureUnits (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 gasMolarFraction_Callback(hObject, eventdata, handles)
% hObject    handle to gasMolarFraction (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 gasMolarFraction as text
%        str2double(get(hObject,'String')) returns contents of gasMolarFraction as a double


% --- Executes during object creation, after setting all properties.
function gasMolarFraction_CreateFcn(hObject, eventdata, handles)
% hObject    handle to gasMolarFraction (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 gasMassFraction_Callback(hObject, eventdata, handles)
% hObject    handle to gasMassFraction (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 gasMassFraction as text
%        str2double(get(hObject,'String')) returns contents of gasMassFraction as a double


% --- Executes during object creation, after setting all properties.
function gasMassFraction_CreateFcn(hObject, eventdata, handles)
% hObject    handle to gasMassFraction (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 loopSize_Callback(hObject, eventdata, handles)
% hObject    handle to loopSize (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 loopSize as text
%        str2double(get(hObject,'String')) returns contents of loopSize as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function loopSize_CreateFcn(hObject, eventdata, handles)
% hObject    handle to loopSize (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 switchingTime_Callback(hObject, eventdata, handles)
% hObject    handle to switchingTime (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 switchingTime as text
%        str2double(get(hObject,'String')) returns contents of switchingTime as a double

% checks it for validity
checkNumericCallback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function switchingTime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to switchingTime (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 updateSwitchingTimeButton.
function updateSwitchingTimeButton_Callback(hObject, eventdata, handles)
% hObject    handle to updateSwitchingTimeButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% if its running then use the switching time, otherwise not
if get(handles.mainGuiHandles.rheodyneStart, 'Value')
    % sets the switching time
    switchingTime = '0';
    
else
    % get it from the main GUI
    switchingTime = get(handles.mainGuiHandles.rheodyneTimerPeriod, 'String');    
end

% applies it
set(handles.switchingTime, 'String', switchingTime)


% --- Executes when user attempts to close compositiongui.
function compositiongui_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to compositiongui (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% saves everything to appdata

% gets the structures
objectConfig = getappdata(handles.mainGuiHandle, 'objectConfig');
pumps = getappdata(hObject, 'pumps');

% for each pump
for m = 1:numel(pumps)
    % is it a NaN?
    if ~isnan(pumps(m))    
        % stashes the details away
        objectConfig(pumps(m)).persistentData.include = get(handles.(sprintf('include%d', m)), 'Value');
        objectConfig(pumps(m)).persistentData.density = str2double(get(handles.(sprintf('density%d', m)), 'String'));
        objectConfig(pumps(m)).persistentData.molarMass = str2double(get(handles.(sprintf('molarMass%d', m)), 'String'));
        objectConfig(pumps(m)).persistentData.efficiency = str2double(get(handles.(sprintf('efficiency%d', m)), 'String'));
    end
end

% some rheodyne stuff
objectConfig(9).persistentData.gasType = get(handles.gasTypeMenu, 'Value');
objectConfig(9).persistentData.loopSize = str2double(get(handles.loopSize, 'String'));

% saves that
setappdata(handles.mainGuiHandle, 'objectConfig', objectConfig)

% the other part
guiConfig = getappdata(handles.mainGuiHandle, 'guiConfig');

% and the rest
guiConfig.gasPressureChannel = get(handles.gasPressureChannel, 'Value');
guiConfig.systemPressureChannel = get(handles.systemPressureChannel, 'Value');

% saves that back
setappdata(handles.mainGuiHandle, 'guiConfig', guiConfig)

% Hint: delete(hObject) closes the figure
delete(hObject);

Contact us