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.

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

% Last Modified by GUIDE v2.5 27-Nov-2009 18:59:22

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

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

% stashes away the main gui handles
handles.plotRampGuiHandle = plotRampGuiHandle;
handles.plotRampGuiHandles = plotRampGuiHandles;

% stores the window handle in the ramps gui appdata shutting it down
% cleanly
setappdata(handles.plotRampGuiHandle, 'advRampWindowHandle', hObject)

% collects the add button boxes together for easier control
handles.allAddButtons = [   handles.addToEnd;...
                            handles.addBefore;...
                            handles.addAfter];
                        
% Update handles structure
guidata(hObject, handles)

% populates ramp list
populateRampList(hObject, eventdata, handles)

% runs the ramp list callback to update the boxes below it, based on the
% current selection
rampList_Callback(handles.rampList, eventdata, handles)


% --- Outputs from this function are returned to the command line.
function advplotrampgui_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 is for populating the ramp list using the advList
function populateRampList(hObject, eventdata, handles)

% fetches the advList
advList = getappdata(handles.plotRampGuiHandle, 'advList');

% if its empty...
if isempty(advList)
    % simply empty the ramp list
    set(handles.rampList, 'String', '')
    
    % disable the remove button
    set(handles.remove, 'Enable', 'off')

else
    % enables the remove button
    set(handles.remove, 'Enable', 'on')
    
    % splits it up (and converts time into minutes)
    startParameter = advList(:, 1);
    endParameter = advList(:, 2);
    incrementParameter = advList(:, 3);
    time = advList(:, 4) / 60;

    % figure out what device this is
    objectNumber = str2double(get(handles.plotRampGuiHandles.objectNumber, 'String'));

    % if this is an audio Rheodyne
    if objectNumber == 9
        % define the units straight away
        units = 's';

    else
        % retrieve objectConfig and types
        objectConfig = getappdata(handles.plotRampGuiHandles.mainGuiHandle, 'objectConfig');
        objectTypes = getappdata(handles.plotRampGuiHandles.mainGuiHandle, 'objectTypes');

        % get the class of the object
        objectClass = objectTypes(objectConfig(objectNumber).type).class;

        % decide on the units
        switch objectClass
            case 'pump'
                units = 'mLmin-1';

            case 'bpr'
                units = 'bar';

            case 'temp'
                units = 'C';

            case 'valve'
                units = 's';

            otherwise
                units = '';
        end
    end

    % pre-allocates the string
    listString = cell(size(advList, 1), 1);

    % for each step (row) in the list
    for m = 1:size(advList, 1)
        % defines the time units depending on the time
        if time == 1
            % defines it singularly
            timeUnits = 'min';
            
        else
            % defines it plural
            timeUnits = 'mins';
        end
        
        % if the start and end are the same its a hold
        if startParameter(m) == endParameter(m)
            % forms the line
            listString{m} = sprintf('Hold for %.4g %s at %.4g %s.', time(m), timeUnits, startParameter(m), units);

        else
            % its a ramp
            listString{m} = sprintf('Ramp from %.4g to %.4g %s in %.4g %s increments over %.4g %s.', startParameter(m), endParameter(m), units, incrementParameter(m), units, time(m), timeUnits);
        end

        % appends the step number on to the beginning
        listString{m} = [num2str(m), ': ', listString{m}];
    end

    % if its the last one, convert it into char
    if size(advList, 1) == 1
        % convert it
        listString = listString{1};

        % enables the remove button
        set(handles.remove, 'Enable', 'on')

    elseif isempty(advList)
        % define it as empty
        listString = '';

        % disable the remove button
        set(handles.remove, 'Enable', 'off')
    end

    % gets the current list position
    listPosition = get(handles.rampList, 'Value');

    % if the current value of the ramp list is past the end, change it to the
    % last one
    if any(listPosition > size(advList, 1))
        % if its a scalar, just set it to the end one (otherwise you end up
        % with an empty value for the below logical
        if isscalar(listPosition)
            % change it
            set(handles.rampList, 'Value', size(advList, 1))

        else
            % changes it to those which can be selected
            set(handles.rampList, 'Value', listPosition(listPosition <= size(advList, 1)))
        end
    end

    % if any of the list are at the top
    if any(listPosition == 1)
        % disable the move up button
        set(handles.moveUp, 'Enable', 'off')

    else
        % enable it
        set(handles.moveUp, 'Enable', 'on')
    end

    % if any of the list are at the bottom
    if any(listPosition == size(advList, 1))
        % disable the move down button
        set(handles.moveDown, 'Enable', 'off')

    else
        % disable it
        set(handles.moveDown, 'Enable', 'on')
    end
    
    % applies the string
    set(handles.rampList, 'String', listString)
end


% --- Executes on selection change in rampList.
function rampList_Callback(hObject, eventdata, handles)
% hObject    handle to rampList (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 rampList contents as cell array
%        contents{get(hObject,'Value')} returns selected item from rampList

% updates the boxes with whats currently selected in the list

% gets the list of parameters from the main GUI
advList = getappdata(handles.plotRampGuiHandle, 'advList');

% gets the current position in the list
listPosition = get(hObject, 'Value');

% if its empty, do nothing for now
if ~isempty(advList)
    % then assign the values if it isn't empty (have to convert the time
    % back from seconds into minutes
    set(handles.startParameter, 'String', num2str(advList(listPosition(1), 1)))
    set(handles.endParameter, 'String', num2str(advList(listPosition(1), 2)))
    set(handles.incrementParameter, 'String', num2str(advList(listPosition(1), 3)))
    set(handles.time, 'String', num2str(advList(listPosition(1), 4) / 60))
    
    % disables the add and move buttons if more than one thing is selected
    set([   handles.allAddButtons;...
            handles.moveUp;...
            handles.moveDown], 'Enable', onoff(isscalar(listPosition)))
        
    % if its at the end, disable the move down button
    if listPosition == size(advList, 1)
        % disable it
        set(handles.moveDown, 'Enable', 'off')
        set(handles.moveUp, 'Enable', 'on')
    end
    
    % same for the move up
    if listPosition == 1
        % disable it
        set(handles.moveUp, 'Enable', 'off')
        set(handles.moveDown, 'Enable', 'on')
    end
    
    % re-runs the process list callback
    processList(hObject, eventdata, handles)
    
else
    % empty them all out
    set(handles.startParameter, 'String', '')
    set(handles.endParameter, 'String', '')
    set(handles.incrementParameter, 'String', '')
    set(handles.time, 'String', '')
end


% --- Executes during object creation, after setting all properties.
function rampList_CreateFcn(hObject, eventdata, handles)
% hObject    handle to rampList (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox 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 addToEnd.
function addToEnd_Callback(hObject, eventdata, handles)
% hObject    handle to addToEnd (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% collects everything
startParameter = str2double(get(handles.startParameter, 'String'));
endParameter = str2double(get(handles.endParameter, 'String'));
incrementParameter = str2double(get(handles.incrementParameter, 'String'));
time = str2double(get(handles.time, 'String'));

% stores them all for convenience, addToEnd converts the time into seconds too
allParameters = [startParameter, endParameter, incrementParameter, time * 60];

% if anything is a NaN, it was empty and is not ready to go (this shouldn't
% ever happen anyway because of the other error checking in place)
if any(isnan(allParameters))
    % errors
    warntooltip(hObject, 'One or more values is not valid so the new step has not been added.')
    
else
    % fetches the advList
    advList = getappdata(handles.plotRampGuiHandle, 'advList');
    
    % adds it to the bottom of the list and saves it
    setappdata(handles.plotRampGuiHandle, 'advList', [advList; allParameters])
    
    % process the data
    processList(hObject, eventdata, handles)
end


% --- Executes on button press in remove.
function remove_Callback(hObject, eventdata, handles)
% hObject    handle to remove (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% gets the advList
advList = getappdata(handles.plotRampGuiHandle, 'advList');

% if its empty, stop right there (it shouldn't get this far anyway)
if ~isempty(advList)
    % gets the list positions
    listPosition = get(handles.rampList, 'Value');
    
    % remove those empty slots
    advList(listPosition, :) = [];

    % saves it back into appdata
    setappdata(handles.plotRampGuiHandle, 'advList', advList)

    % re-populate the list
    processList(hObject, eventdata, handles)
end


% --- Executes on button press in ok.
function ok_Callback(hObject, eventdata, handles)
% hObject    handle to ok (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% closes the window (also running the closerequest function)
close(getfigure(hObject))


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

% gets the value
time = str2double(get(hObject, 'String'));

% is it OK?
if isnan(time) || ~isreal(time) || time <= 0
    % displays a warning
    warntooltip(hObject, 'Time must be a real number greater than 0.')

    % disables the add buttons
    set(handles.allAddButtons, 'Enable', 'off')
    
    % colour the background yellow
    set(hObject, 'BackgroundColor', 'y')
    
else
    % colour the background white
    set(hObject, 'BackgroundColor', 'w')
    
    % enables the add buttons
    set(handles.allAddButtons, 'Enable', 'on')
    
    % calculate the new parameters
    processList(hObject, eventdata, handles)
end


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



% --- Generic check parameter callback
function checkParameter(hObject, eventdata, handles)
% hObject    handle to calling object
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% gets the object types config
objectTypes = getappdata(handles.plotRampGuiHandles.mainGuiHandle, 'objectTypes');

% gets the new value
newValue = str2double(get(hObject, 'String'));

% gets the prospective serial object
serialObject = getappdata(  handles.plotRampGuiHandles.mainGuiHandle,...
                            ['serialObject', get(handles.plotRampGuiHandles.objectNumber, 'String')]);

% gets the userData
userData = serialObject.UserData;

% gets the command
command = get(handles.plotRampGuiHandles.command, 'String');

% gets the correct min and maximum values
if ~isempty(strfind(command, 'temp'))
    % defines the correct field name
    field = 'SetTemp';
    
elseif ~isempty(strfind(command, 'press'))
    % defines the correct field name
    field = 'SetPress';
    
else
    % defines the field
    field = 'Flow';
end

% gets the minimum and maximum values
minValue = objectTypes(userData.objectType).(['min', field]);
maxValue = objectTypes(userData.objectType).(['max', field]);

% checks contents to see if they are numeric, finite, real and in the
% allowed range
if ~isnumber(newValue) || (~isempty(minValue) && newValue < minValue) || (~isempty(maxValue) && newValue > maxValue)
    % decides on the formatting
    if minValue ~= round(minValue)
        % minimum formatting
        minFormat = '%.1g';
        
    else
        % formats it differently to ignore the decimal places for integers
        minFormat = '%d';
    end
    
    % decides on the formatting
    if maxValue ~= round(maxValue)
        % maximum formatting
        maxFormat = '%.1g';
        
    else
        % formats it differently to ignore the decimal places for integers
        maxFormat = '%d';
    end
    
    % brings up an error dialog
    warntooltip(hObject, sprintf(['Must enter a finite real number between ', minFormat, ' and ', maxFormat, '.'], minValue, maxValue))

    % disables the add buttons
    set(handles.allAddButtons, 'Enable', 'off')
    
    % colour the background yellow
    set(hObject, 'BackgroundColor', 'y')
    
else
    % enables the add buttons
    set(handles.allAddButtons, 'Enable', 'on')
    
    % colour the background white
    set(hObject, 'BackgroundColor', 'w')
    
    % updates the appdata
    processList(hObject, eventdata, handles)
end


% -- Run by all to update the main GUI plot
function processList(hObject, eventdata, handles)
% hObject   handle to the object which called this function
% handles   structure with handles and user data (see GUIDATA)

% gets the list of parameters
advList = getappdata(handles.plotRampGuiHandle, 'advList');

% if its empty, do nothing for now
if ~isempty(advList)
    % splits them up so they're easier to understand
    startParameter = advList(:, 1);
    endParameter = advList(:, 2);
    incrementParameter = advList(:, 3);
    rampTime = advList(:, 4);
    
    % set the total time
    set(handles.totalTime, 'String', num2str(sum(rampTime) / 60))
    
    % to start with, the first point is 0, and will be overwritten
    newTimes = 0;
    newValues = 0;

    % for each row, build a set of times and values - each ramp will give one
    % point more than is necessary, so that the next segment will overwrite
    % that last point - this is not memory efficient since we are not
    % pre-allocating, but it can't really be helped
    for m = 1:size(advList, 1)
        % if the start and end are the same, this is a hold
        if startParameter(m) == endParameter(m)
            % generates some numbers
            newTimesToAdd = [0, rampTime(m)];
            newValuesToAdd = repmat(startParameter(m), 1, 2);

        else
            % need to invert the incrementParameter if its a down ramp
            if startParameter(m) > endParameter(m)
                % invert it
                incrementParameter(m) = -incrementParameter(m);
            end            
            
            % defines the number of points (note this is slightly different to
            % the rampList system in plotrampgui since this DOES NOT allow for
            % time at the last point (i.e. is not suited to steps, but is more
            % like how the Shimadzu GC software behaves
            newValuesToAdd = startParameter(m):incrementParameter(m):endParameter(m);
                       
            % newTimes
            newTimesToAdd = 0:rampTime(m) / (numel(newValuesToAdd) - 1):rampTime(m);
        end

        % add them on
        newValues(end:end + numel(newValuesToAdd) - 1) = newValuesToAdd;

        % defines the points, and offsets them for the last one (as the
        % time needs to be shifted along)
        newTimes(end:end + numel(newTimesToAdd) - 1) = newTimesToAdd + newTimes(end);
    end

    % update the times and values in the main gui
    setappdata(handles.plotRampGuiHandle, 'advancedTimes', newTimes)
    setappdata(handles.plotRampGuiHandle, 'advancedValues', newValues)
    
    % adds in extra data for plotting to create a stepped effect
    plotTimes = newTimes(ones(1, 2), :);
    plotTimes = plotTimes(2:end)' / 60;
    plotValues = newValues(ones(1, 2), :);

    % essential to reshape matrix and remove the last point
    plotValues = plotValues(1:end - 1);
    
    % plot them on the graph
    plot(handles.timerAxes, plotTimes, plotValues)
    
    % format the graph
    xlabel(handles.timerAxes, 'Time/minutes')
    ylabel(handles.timerAxes, 'Parameter')
    
    % need to make the advList radio button is checked to update the plot
    set(handles.plotRampGuiHandles.advancedIncrementButton, 'Value', 1)
    
    % updates the preview function in the ramps GUI
    plotrampgui('calcTotalRampTime_Callback', handles.plotRampGuiHandle, [], handles.plotRampGuiHandles)
    
    % also gets the list position
    listPosition = get(handles.rampList, 'Value');
    
    % collects all the new parameters
    startParameter = str2double(get(handles.startParameter, 'String'));
    endParameter = str2double(get(handles.endParameter, 'String'));
    incrementParameter = str2double(get(handles.incrementParameter, 'String'));
    time = str2double(get(handles.time, 'String'));
    
    % collects them (and modifies the time to seconds - advList stores it
    % natively as seconds)
    allParameters = [startParameter, endParameter, incrementParameter, time * 60];
    
    % if they're different from the current values, enable the modify
    % button
    set(handles.modify, 'Enable', onoff(isscalar(listPosition) && any(allParameters ~= advList(listPosition, :))))
    
else
    % set the time to 0
    set(handles.totalTime, 'String', '0')
    
    % empty the plot (should probably be handled better by the main GUI,
    % but it will do for now)
    delete( [get(handles.plotRampGuiHandles.timerAxes, 'Children'),...
            get(handles.timerAxes, 'Children')])
end

% update the list
populateRampList(hObject, eventdata, handles)


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

% checks it
checkParameter(hObject, eventdata, handles)


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

% checks it
checkParameter(hObject, eventdata, handles)


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

% gets the value
incrementParameter = str2double(get(hObject, 'String'));

% is it OK?
if ~isnumber(incrementParameter)
    % displays a warning
    warntooltip(hObject, 'Increment must be a real number greater than or equal to 0.')
    
    % disable the add box
    set(handles.allAddButtons, 'Enable', 'off')
    
    % colour the background yellow
    set(hObject, 'BackgroundColor', 'y')
    
else
    % get some more numbers
    startParameter = str2double(get(handles.startParameter, 'String'));
    endParameter = str2double(get(handles.endParameter, 'String'));

    % if start and end have been filled in, make sure that they are smaller
    % than the range between the two
    if ~isnan(startParameter) && ~isnan(endParameter)
        % get more numbers
        range = abs(startParameter - endParameter);

        % checks to see that the increment is smaller than or equal to the gap
        if incrementParameter > range
            % brings up an error dialog
            warntooltip(hObject, 'The increment must be smaller than the parameter range!')

            % disable the add boxes
            set(handles.allAddButtons, 'Enable', 'off')

            % colour the background yellow
            set(hObject, 'BackgroundColor', 'y')

        else
            % enable the add boxes
            set(handles.allAddButtons, 'Enable', 'on')

            % colour the background white again
            set(hObject, 'BackgroundColor', 'w')
            
            % calculate the new parameters
            processList(hObject, eventdata, handles)
        end
        
    else
        % disable the add boxes
        set(handles.allAddButtons, 'Enable', 'off')

        % colour the backgrounds yellow
        set([   handles.startParameter;...
                handles.endParameter], 'BackgroundColor', 'y')
    end
end


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

% removes the handle from the plot ramp gui
% stores the window handle in the ramps gui appdata shutting it down
% cleanly
rmappdata(handles.plotRampGuiHandle, 'advRampWindowHandle')

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


% --- Executes on button press in moveUp.
function moveUp_Callback(hObject, eventdata, handles)
% hObject    handle to moveUp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% gets the list and the list positions
advList = getappdata(handles.plotRampGuiHandle, 'advList');
listPosition = get(handles.rampList, 'Value');

% only go further if advList is not empty, the top item isn't selected, and
% only 1 item is selected
if ~isempty(advList) && isscalar(listPosition) && listPosition ~= 1
    % processes it
    swapIndices = [listPosition - 1, listPosition];
    
    % move the item up, but by swapping it with the next one above
    advList(swapIndices, :) = advList(fliplr(swapIndices), :);
    
    % saves it
    setappdata(handles.plotRampGuiHandle, 'advList', advList)
    
    % moves the list position up 1 to follow the item
    set(handles.rampList, 'Value', listPosition - 1)
    
    % processes it
    processList(hObject, eventdata, handles)    
end


% --- Executes on button press in moveDown.
function moveDown_Callback(hObject, eventdata, handles)
% hObject    handle to moveDown (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% gets the list and the list positions
advList = getappdata(handles.plotRampGuiHandle, 'advList');
listPosition = get(handles.rampList, 'Value');

% only go further if advList is not empty, the bottom item isn't selected,
% and only 1 item is selected
if ~isempty(advList) && isscalar(listPosition) && listPosition ~= size(advList, 1)
    % processes it
    swapIndices = [listPosition, listPosition + 1];
    
    % move the item up, but by swapping it with the next one down
    advList(swapIndices, :) = advList(fliplr(swapIndices), :);
    
    % saves it
    setappdata(handles.plotRampGuiHandle, 'advList', advList)
    
    % moves the list position down 1 to follow the item
    set(handles.rampList, 'Value', listPosition + 1)
    
    % processes it
    processList(hObject, eventdata, handles)    
end


% --- Executes on button press in addBefore.
function addBefore_Callback(hObject, eventdata, handles)
% hObject    handle to addBefore (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% collects everything
startParameter = str2double(get(handles.startParameter, 'String'));
endParameter = str2double(get(handles.endParameter, 'String'));
incrementParameter = str2double(get(handles.incrementParameter, 'String'));
time = str2double(get(handles.time, 'String'));

% stores them all for convenience, addToEnd converts the time into seconds too
allParameters = [startParameter, endParameter, incrementParameter, time * 60];

% if anything is a NaN, it was empty and is not ready to go (this shouldn't
% ever happen anyway because of the other error checking in place)
if any(isnan(allParameters))
    % errors
    warntooltip(hObject, 'One or more values is not valid so the new step has not been added.')
    
else
    % fetches the advList
    advList = getappdata(handles.plotRampGuiHandle, 'advList');
    
    % gets the current list position
    listPosition = get(handles.rampList, 'Value');
    
    % only goes further if only one item is selected (shouldn't get this
    % far anyway)
    if isscalar(listPosition)
        % if the list position is already in the beginning...
        if listPosition == 1
            % modify it differently (because otherwise we'll end up with 0
            % indices
            advList = [allParameters; advList];

        else
            % saves the modified list
            advList = [advList(1:listPosition - 1, :); allParameters; advList(listPosition:end, :)];
        end

        % saves it
        setappdata(handles.plotRampGuiHandle, 'advList', advList)
        
        % process the data
        processList(hObject, eventdata, handles)
    end
end


% --- Executes on button press in addAfter.
function addAfter_Callback(hObject, eventdata, handles)
% hObject    handle to addAfter (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% collects everything
startParameter = str2double(get(handles.startParameter, 'String'));
endParameter = str2double(get(handles.endParameter, 'String'));
incrementParameter = str2double(get(handles.incrementParameter, 'String'));
time = str2double(get(handles.time, 'String'));

% stores them all for convenience, addToEnd converts the time into seconds too
allParameters = [startParameter, endParameter, incrementParameter, time * 60];

% if anything is a NaN, it was empty and is not ready to go (this shouldn't
% ever happen anyway because of the other error checking in place)
if any(isnan(allParameters))
    % errors
    warntooltip(hObject, 'One or more values is not valid so the new step has not been added.')
    
else
    % fetches the advList
    advList = getappdata(handles.plotRampGuiHandle, 'advList');
    
    % gets the current list position
    listPosition = get(handles.rampList, 'Value');
    
    % only goes further if only one item is selected (shouldn't get this
    % far anyway)
    if isscalar(listPosition)
        % if the list position is already in the beginning...
        if listPosition == size(advList, 1)
            % modify it differently (because otherwise we'll end up with 0
            % indices
            advList = [advList; allParameters];

        else
            % saves the modified list
            setappdata(handles.plotRampGuiHandle, 'advList', [advList(1:listPosition, :); allParameters; advList(listPosition + 1:end, :)])
        end

        % process the data
        processList(hObject, eventdata, handles)
    end
end


% --- Executes on button press in modify.
function modify_Callback(hObject, eventdata, handles)
% hObject    handle to modify (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% collects everything
startParameter = str2double(get(handles.startParameter, 'String'));
endParameter = str2double(get(handles.endParameter, 'String'));
incrementParameter = str2double(get(handles.incrementParameter, 'String'));
time = str2double(get(handles.time, 'String'));

% stores them all for convenience, addToEnd converts the time into seconds too
allParameters = [startParameter, endParameter, incrementParameter, time * 60];

% if anything is a NaN, it was empty and is not ready to go (this shouldn't
% ever happen anyway because of the other error checking in place)
if any(isnan(allParameters))
    % errors
    warntooltip(hObject, 'One or more values is not valid so the selected step has not been changed.')
    
else
    % fetches the advList
    advList = getappdata(handles.plotRampGuiHandle, 'advList');
    
    % gets the current list position
    listPosition = get(handles.rampList, 'Value');
    
    % only goes further if only one item is selected (shouldn't get this
    % far anyway)
    if isscalar(listPosition)
        % modify the list
        advList(listPosition, :) = allParameters;
        
        % saves the modified list
        setappdata(handles.plotRampGuiHandle, 'advList', advList)

        % process the data
        processList(hObject, eventdata, handles)
    end
end



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


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


Contact us