function selected = adcpmenu();
%
% Menu driver function for adcpview.m
%

%
% Written by Marinna Martini
% for the U.S. Geological Survey
% Marine and Coastal Program
% Woods Hole Center, Woods Hole, MA
% http://woodshole.er.usgs.gov/
%
% dependents:
%	adcpview.m	the script which executes the menu operations
%
% this code was originally 'LISTBOX1' by
% Copyright (C) 1993 Dr. Charles R. Denham, ZYDECO.
% All Rights Reserved.
% Modified by Marinna Martini, USGS

% make sure this is the only window
close all

list = [...
	'New File                         ';...	% 1
	'View global metadata             ';... % 2
	'Plot Variable Leader Data        ';... % 3
	'Plot Beam Related Data           ';... % 4
    'Plot Beam data in 3D             ';... % 5
	'Close plot windows               ';... % 6
	'Statistics                       ';... % 7
	'Convert beam to earth coord.     ';... % 8
    'Recover beam coord. data         ';... % 9
	'Save workspace to ******.mat     ';... % 10
	'Save workspace to matlab.mat     ';... % 11
	'Save an existing plot            ';... % 12
    'Toggle diary on and off          ';... % 13
	'Purge large matrices             ';... % 14
	];


prompt = 'ADCP Quick Look Menu';
position = [300 180 300 380];
container = figure('Color', 'b', ...
             'Name', prompt, ...
             'Position', position, ...
             'NumberTitle', 'off', ...
             'Resize', 'off',...
			 'Nextplot','new');

% Convert to local container coordinates.
position = position - [position(1) position(2) 0 0];
top = position(2) + position(4); bottom = position(2);
left = position(1); right = position(1) + position(3);
width = position(3); height = position(4);

% Create the frame for the list.
frame = uicontrol('Style', 'frame', 'Position', position);
[m, n] = size(list);

% Create a list of buttons.
nitems = min(20, m);
SEPARATION = 20;
box = [left, top - SEPARATION, width, SEPARATION];
step = [0 -SEPARATION 0 0];

% Create the list of strings for every button.
strings = '';
for i = 1:m
   strings = [strings list(i, :)];
   if i < m, strings = [strings '|']; end
end

% create the list of callbacks
callback=sprintf('cop=%2i;adcpview',1);
for i=2:nitems,
	buf=sprintf('cop=%2i;adcpview',i);
	callback=[callback; buf];
end

% Create the controls.

items = zeros(1, nitems);
for i = 1:nitems
   items(i) = uicontrol(container, 'Style', 'pushbutton', ...
		'Position', box, 'String', list(i,:), 'Value', i, ...
		'Interruptible','yes','Callback', callback(i,:));
   box = box + step;
end

% Stow the list of pop-ups.

for i = 1:nitems
	set(items(i), 'Userdata', items);
end
