% File: equipData.m  
%
% The program stores medical equipment data.
%
% Created 1/11/07 by Dr. C. S. Tritt

% I recommend clearing the workspace at the start of all
% programs.
clear;

% Preallocate space for stucture array.
eqData(10) = struct('desc', [], 'snum', [], 'loc', [], 'status', []);

% Define prompts for equipment data entry and continue dailog.
eq_dlg_title = 'Enter Equipment Data';
eq_prompt{1} = 'Description: ';
eq_prompt{2} = 'Serial Number: ';
eq_prompt{3} = 'Location: ';
eq_prompt{4} = 'Status: ';
cont_dlg_title = 'Continue?';
cont_prompt{1} = 'Do you wish to conintue? (y or n): ';

id = 0; % ID number (equipment array index).
exit = false; % Make true to exit program.

while ~exit
      
    id = id + 1; % Increment ID numeber (index).
    
    % Get data for a equipment data.
    eqResponse = inputdlg(eq_prompt, eq_dlg_title);
    eqData(id).desc = eqResponse{1};
    eqData(id).snum = str2double(eqResponse{2});
    eqData(id).loc = str2double(eqResponse{3});
    eqData(id).status = eqResponse{4};
    
    
 
    % Ask user if they wish to continue.
    contResponse = inputdlg(cont_prompt, cont_dlg_title);
    if contResponse{1} ~= 'y'
        exit = true;
    end
  
end

% Display data structure contents.

for n = 1:id
    outString = sprintf( ...
        'Description: %s\nSerial number: %d\nLocation: %d\nStatus %s', ...
        eqData(n).desc, eqData(n).snum, eqData(n).loc,  eqData(n).status);
    msgbox(outString);
end
