% Menu-driven version of surfer.m; allows user to enter values
% on menu screen, then calls original program.  Not necessary to run everything
% at the command line.

clear all, close all
h=figure(1); clf; set(h,'numbertitle','off');
set(h,'name','OC4213:  SURF PREDICTION MODEL');
global J;

wv_ht  = 1;           bch_slope  = 1/100;
st_depth   = 50;           SA_d_spd   = 0;
T_peak = 10;             SA_a_spd = 0;
wv_dir   = 0;           min_fuel  = 50;
max_spd   = 32;            min_spd   = 3;
C_I       = 90;            weather   = 1; 

BackColor          = [.0     1   .0];    %Individual panel bkgrd clr
%BackColor         =   [1      1   .1];      %Bkgrd clr of popup label

DefColor           = [1    .5   .1];    %Default background clr
%DefColor           = [.99    1   .4];    %Default background clr

answer_color       = [.95   .95  .95];    %Edit text background clr

bkgrd_side_console = [.0    .0  .5];    %Bkgrd clr for side console

%labelColor         =   [.25      1   .0];
%labelColor         = [.1    .95   .4];    %Bkgrd clr of popup label
labelColor          = [1      1   .1];    %Individual panel bkgrd clr

%label_inside_Color = [.5    .8   .95];    %Bkgrd clr of popup label
label_inside_Color = [.7     1  .7];    %Bkgrd clr for popup window

ForeColor          = [.0    .0   .0];    %Letters in main panel

Fore_but_Color     = [.0    .0   .0];    %Letters in side panel


    %===================================
    % Set up the Wave Height Window
    top=0.95;
    bottom=0.85;
    left=0.05;
    right=0.75;
    bottom=0.85;
    labelHt=0.05;
    spacing=0.005;
    %def_lenth = .1;
    def_lenth = .075;

    % First, the MiniCommand Window frame
    frmBorder=0.02;
    frmPos=[left-frmBorder bottom-frmBorder ...
	(right-left)+2*frmBorder (top-bottom)+2*frmBorder];
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
	'BackgroundColor',BackColor);
    % Then the text label
    labelPos=[left top-labelHt (right-left) labelHt];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',labelPos, ...
        'BackgroundColor',BackColor, ...
	'ForegroundColor',ForeColor, ...
        'String','Deep Water Significant Wave Height (0.1-5 m)');
   % Then the editable text field FRAME
    frmPos=[left-.002 bottom-.005 (right-left+.005)  top-bottom-labelHt-spacing+.008];
    uicontrol( ...
	'Style','frame', ...
        'Units','normalized', ...
        'BackgroundColor',ForeColor, ...
  	'ForegroundColor',ForeColor, ...
        'Position',frmPos);
   % Default value
    defPos=[(right-def_lenth) bottom (def_lenth) top-bottom-labelHt-spacing];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',defPos, ...
        'BackgroundColor',DefColor, ...
	'ForegroundColor',ForeColor, ...
        'String','( 1 )');
   % Then the editable text field
    txtPos=[left bottom (right-left-def_lenth) top-bottom-labelHt-spacing];
    tot_dis=uicontrol( ...
	'Style','edit', ...
        'Units','normalized', ...
        'BackgroundColor',answer_color, ...
  	'ForegroundColor',ForeColor, ...
        'HorizontalAlignment','left', ...
        'Position',txtPos, ...
 	'Callback',[...
        'wv_ht = str2num(get(tot_dis, ''String''));,',...
         'print  = 1;']);
  
    %===================================
    % Set up the Bottom Slope Window
    top=0.78;
    bottom=0.68;
    left=0.05;
    right=0.75;
    labelHt=0.05;
    spacing=0.005;

    % First, the MiniCommand Window frame
    frmBorder=0.02;
    frmPos=[left-frmBorder bottom-frmBorder ...
	(right-left)+2*frmBorder (top-bottom)+2*frmBorder];
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
	'BackgroundColor',BackColor);
    % Then the text label
    labelPos=[left top-labelHt (right-left) labelHt];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',labelPos, ...
        'BackgroundColor',BackColor, ...
	'ForegroundColor',ForeColor, ...
        'String','Bottom Slope');
   % Then the editable text field FRAME
    frmPos=[left-.002 bottom-.005 (right-left+.005)  top-bottom-labelHt-spacing+.008];
    uicontrol( ...
	'Style','frame', ...
        'Units','normalized', ...
        'BackgroundColor',ForeColor, ...
  	'ForegroundColor',ForeColor, ...
        'Position',frmPos);
    % Then the editable text field
    txtPos=[left bottom (right-left-def_lenth) top-bottom-labelHt-spacing];
    tot_tim=uicontrol( ...
	'Style','edit', ...
        'Units','normalized', ...
        'BackgroundColor',answer_color, ...
 	'ForegroundColor',ForeColor, ...
        'HorizontalAlignment','left', ...
        'Position',txtPos, ...
 	'Callback',[...
        'bch_slope =  str2num(get(tot_tim, ''String''));,',...
        'print  = 1;']);
   % Default value
    defPos=[(right-def_lenth) bottom (def_lenth) top-bottom-labelHt-spacing];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',defPos, ...
        'BackgroundColor',DefColor, ...
	'ForegroundColor',ForeColor, ...
        'String','(0.01)');
  

    %===================================
    %Set up the Offshore Depth Window
    top=0.61;
    bottom=0.48;
    left=0.05;
    right=0.75;
    labelHt=0.075;
    spacing=0.005;

    % First, the MiniCommand Window frame
    frmBorder=0.02;
    frmPos=[left-frmBorder bottom-frmBorder ...
	(right-left)+2*frmBorder (top-bottom)+2*frmBorder];
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
	'BackgroundColor',BackColor);
    % Then the text label
    labelPos=[left top-labelHt (right-left) labelHt];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',labelPos, ...
        'BackgroundColor',BackColor, ...
	'ForegroundColor',ForeColor, ...
        'String','Start Depth Outside Surf Zone (4xH or more)');
    % Then the editable text field FRAME
    frmPos=[left-.002 bottom-.005 (right-left+.005)  top-bottom-labelHt-spacing+.008];
    uicontrol( ...
	'Style','frame', ...
        'Units','normalized', ...
        'BackgroundColor',ForeColor, ...
  	'ForegroundColor',ForeColor, ...
        'Position',frmPos);
   % Then the editable text field
    txtPos=[left bottom (right-left-def_lenth) top-bottom-labelHt-spacing];
    SA_tim=uicontrol( ...
	'Style','edit', ...
        'Units','normalized', ...
        'BackgroundColor',answer_color, ...
	'ForegroundColor',ForeColor, ...
        'HorizontalAlignment','left', ...
        'Position',txtPos, ...
 	'Callback',[...
        'st_depth = str2num(get(SA_tim, ''String''));,',...
        'print  = 1;']);
  % Default value
    defPos=[(right-def_lenth) bottom (def_lenth) top-bottom-labelHt-spacing];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',defPos, ...
        'BackgroundColor',DefColor, ...
	'ForegroundColor',ForeColor, ...
        'String','( 50 )');

  
    %===================================
    %Set up the Peak Wave Period Window
    top=0.41;
    bottom=0.28;
    left=0.05;
    right=0.75;
    labelHt=0.075;
    spacing=0.005;

    % First, the MiniCommand Window frame
    frmBorder=0.02;
    frmPos=[left-frmBorder bottom-frmBorder ...
	(right-left)+2*frmBorder (top-bottom)+2*frmBorder];
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
	'BackgroundColor',BackColor);
    % Then the text label
    labelPos=[left top-labelHt (right-left) labelHt];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',labelPos, ...
        'BackgroundColor',BackColor, ...
	'ForegroundColor',ForeColor, ...
        'String','Peak Wave Period (7.5-17.49 sec)');
    % Then the editable text field FRAME
    frmPos=[left-.002 bottom-.005 (right-left+.005)  top-bottom-labelHt-spacing+.008];
    uicontrol( ...
	'Style','frame', ...
        'Units','normalized', ...
        'BackgroundColor',ForeColor, ...
  	'ForegroundColor',ForeColor, ...
        'Position',frmPos);
   % Then the editable text field
    txtPos=[left bottom (right-left-def_lenth) top-bottom-labelHt-spacing];
    SA_a_tim=uicontrol( ...
	'Style','edit', ...
        'Units','normalized', ...
        'BackgroundColor',answer_color, ...
  	'ForegroundColor',ForeColor, ...
        'HorizontalAlignment','left', ...
        'Position',txtPos, ...
 	'Callback',[...
        'T_peak = str2num(get(SA_a_tim, ''String''));,',...
        'print  = 1;']);
    % Default value
    defPos=[(right-def_lenth) bottom (def_lenth) top-bottom-labelHt-spacing];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',defPos, ...
        'BackgroundColor',DefColor, ...
	'ForegroundColor',ForeColor, ...
        'String','( 10 )');
  

    %===================================
    %Set up the Wave Direction Window
    top=0.21;
    bottom=0.08;
    left=0.05;
    right=0.75;
    labelHt=0.075;
    spacing=0.005;

    % First, the MiniCommand Window frame
    frmBorder=0.02;
    frmPos=[left-frmBorder bottom-frmBorder ...
	(right-left)+2*frmBorder (top-bottom)+2*frmBorder];
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
	'BackgroundColor',BackColor);
    % Then the text label
    labelPos=[left top-labelHt (right-left) labelHt];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',labelPos, ...
        'BackgroundColor',BackColor, ...
	'ForegroundColor',ForeColor, ...
        'String','Wave Direction (-60 to 60 degrees)');
   % Then the editable text field FRAME
    frmPos=[left-.002 bottom-.005 (right-left+.005)  top-bottom-labelHt-spacing+.008];
    uicontrol( ...
	'Style','frame', ...
        'Units','normalized', ...
        'BackgroundColor',ForeColor, ...
  	'ForegroundColor',ForeColor, ...
        'Position',frmPos);
    % Then the editable text field
    txtPos=[left bottom (right-left-def_lenth) top-bottom-labelHt-spacing];
    fuel_onb=uicontrol( ...
	'Style','edit', ...
        'Units','normalized', ...
        'BackgroundColor',answer_color, ...
 	'ForegroundColor',ForeColor, ...
        'HorizontalAlignment','left', ...
        'Position',txtPos, ...
 	'Callback',[...
        'wv_dir = str2num(get(fuel_onb, ''String''));,',...
        'print  = 1;']);
  % Default value
    defPos=[(right-def_lenth) bottom (def_lenth) top-bottom-labelHt-spacing];
    uicontrol( ...
	'Style','text', ...
        'Units','normalized', ...
        'Position',defPos, ...
        'BackgroundColor',DefColor, ...
	'ForegroundColor',ForeColor, ...
        'String','( 0 )');
  

%--------------------------------------------------------
%  Button Parameters
%-----------------------------------------------

    yInitLabelPos=0.80;
    xLabelPos=0.80;
    labelWid=0.15;
    labelHt=0.05;
    btnWid=0.15;
    btnHt=0.05;
    % Spacing between the label and the button for the same command
    btnOffset=0.005;
    % Spacing between the button and the next command's label
    spacing=0.05;

    %====================================
    % The CONSOLE frame
    frmBorder=0.02;
    yPos=0.05-frmBorder;
    frmPos=[xLabelPos-frmBorder yPos btnWid+2*frmBorder 0.3+2*frmBorder];
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
	'BackgroundColor',bkgrd_side_console);

vmat=version;
if vmat(1)=='5'
  %====================================
  % The INFO button
    ttlStr='Surf Prediction Model';
    hlpStr= ...                                              
        [' DESCRIPTION:                                   '  
         ' This program allows the user to enter initial  '
         ' values describing the swell and the (constant) '
         ' slope of a beach.  The default values are      '
         ' shown in parentheses to the right of each box. '
         '                                                '
         ' After entering the desired values, press the   '
         ' COMPUTE button to perform the computation.     '  
         '                                                '
         ' Program will display the percentage of waves   '
         ' that have broken, the significant wave height, '
         ' the longshore current, and the water depth on  '
         ' four plots in a single figure.                 '
         '                                                '
         ' Additional results of the analysis will be     '
         ' displayed in a second figure window.           '
         '                                                '
         ' When finished with the program, press QUIT to  '                 
         ' exit back to the matlab prompt.                '];

    uicontrol( ...
	'Style','push', ...
        'Units','normalized', ...
        'Position',[xLabelPos 0.15 btnWid 0.075], ...
        'BackgroundColor',labelColor, ...
 	'ForegroundColor',Fore_but_Color, ...
        'String','Info', ...
        'Callback',[...
        'surfinfo(ttlStr,hlpStr);']);
end

  %====================================
    % The COMPUTE button.
    uicontrol( ...
	'Style','push', ...
        'Units','normalized', ...
        'Position',[xLabelPos 0.250 btnWid 0.1], ...
        'BackgroundColor',labelColor, ...
 	'ForegroundColor',Fore_but_Color, ...
        'String','Compute', ...
        'Callback',[...
        'surfcomp(wv_ht,bch_slope,st_depth,T_peak,wv_dir);']);

%        'A = [wv_ht,bch_slope,st_depth,T_peak,wv_dir];',... 
%====================================
    % The QUIT button.
    uicontrol( ...
	'Style','push', ...
        'Units','normalized', ...
        'Position',[xLabelPos 0.05 btnWid 0.075], ...
        'BackgroundColor',labelColor, ...
	'ForegroundColor',Fore_but_Color, ...
        'String','Quit', ...
        'Callback','close all; clear all');


