function orca_act(action)
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
orca_global
%
cback_fig=Obox.figno;
hval=findobj(cback_fig,'Tag',action);
hlab=findobj(cback_fig,'Tag',[action,'label']);
val=get(hval,'Value');
str=get(hval,'String');
tip=get(hval,'TooltipString');
%%disp([action,' - ',num2str(val)]);
%
switch action
%
case 'Program',
    ORC.iiprog=Obox.prog_order(val);
% Make correct GUI boxes visible:
	for jbox=1:Obox.nboxtot,
		set(Obox.handle(:,jbox),'Visible','Off');
    end
	iiprog=ORC.iiprog;
	for j=1:Obox.nbox_prog(iiprog),
		jbox=Obox.prog(iiprog,j);
		set(Obox.handle(:,jbox),'Visible','On');
	end
	orca_name_update(cback_fig);
	switch ORC.iiprog,
	case {1,9,10}
		ORC.type_opts(1)=1; ORC.type_opts(2:3)=0;
	case 2,
		ORC.type_opts(1)=2; ORC.type_opts(2:3)=0;
	case 3,
		ORC.type_opts(2)=1; ORC.type_opts([1,3])=0;
	case 4,
		ORC.type_opts(3)=1; ORC.type_opts([1:2])=0;		% Bottom Loss
	end
	orca_help('Program',cback_fig);
%%%
case 're-init',
% Re-initialize _svg files and _adi files available:
	orca_name_update(cback_fig);
case 'Load _orca root',
	if no_files(val,str,'_gui.mat'), return; end
	ORC.gui_root=ORC.gui_files{val};
	orca_gui_load(hval);
case 'Output File Root',
	ORC.out_root=str;
%
case 'Ocean SSP: [z,c]',
	ORC.ssp=str2num(char(str));
case 'Plot Ocean SSP';
	if ~ORC.v_opts(1), figure(189); clf; end
	if ORC.iiprog==6,
		svp_plot(ORC.ssp,ORC.v_opts(1),Odef.SSP);
	else
		svp_plot(ORC.GAP.ssp,ORC.v_opts(1),Odef.SSP);
	end
    zoom on;
	disp('See Odef.SSP in orca_global to set default SSP plotting paramters.');
case 'Input SSP on Graph',
	[nr,nc]=size(ORC.ssp);
	if nr>1,
		clim=[min(ORC.ssp(:,2)),max(ORC.ssp(:,2))];
		if clim(1)==clim(2), clim=clim + [-15,15]; end
		zlim=[0,max(ORC.ssp(:,1))];
		if zlim(2)==zlim(1), zlim(2)=200; end
	else
		clim=[1450,1520]; zlim=[0,200];
	end
	disp(' ');
	disp('Control z,c limits on input plot by setting two points of "Ocean SSP: [z,c]" points');
	figure(188); clf;
	[c,z,npt]=graph_input(ORC.psize,clim,zlim,'Sound Speed - m/s','Depth - m',1,0);
	[zsort,indx]=sort(z); csort=c(indx); zsort(1)=0; zsort(end)=round(zsort(end));
	ORC.ssp=[zsort,csort];
	h1=findobj(cback_fig,'Tag','Ocean SSP: [z,c]');
	set(h1,'String',sprintf('%1.1f,%1.1f\n',ORC.ssp'));
case 'No. Bot Layers',
	ORC.nlay=str2num(char(str));
% Make edit-layer-number listbox reflect number of layers to expect:
	h1=findobj(cback_fig,'Tag','Layer 1 Parms'); 
	h2=findobj(cback_fig,'Tag','Layer 2+ Parms'); 
	if ORC.nlay<1,
		set(h1,'Visible','Off'); set(h2,'Visible','Off');
	elseif ORC.nlay<2,
		set(h1,'Visible','On'); set(h2,'Visible','Off');
	else
		set(h1,'Visible','On'); set(h2,'Visible','On');
	end		
% Make 2+ edit-layer-number listbox reflect number of layers to expect:
	nlay=max(2,ORC.nlay);	
	h1=findobj(cback_fig,'Tag','2+EditLayer');
	str=int2str([2:nlay]'); set(h1,'Max',nlay); set(h1,'String',str);
% Check if current value greater than new # layers; if so, reduce it to avoid listbox error msgs:
	jlay_now=get(h1,'Value');
	if jlay_now>nlay, ORC.jlay=nlay; set(h1,'Value',ORC.jlay); end
	orca_act('2+EditLayer')
case '2+EditLayer',
	ORC.jlay=1+val; jlay=ORC.jlay;
	h1=findobj(cback_fig,'Tag','Layer 2+ Parms');
	set(h1,'String',ORC.parm_str{jlay});
case 'Parms',
	disp('Don''t change this column, dummy!');
case 'Layer 1 Parms',
	[nline,nc]=size(str);
	if nline~=16,
		disp('USER ERROR: Layer spec for geo profile must have 16 lines'); return; 
	end
	ORC.parm_str{1}=cellstr(str); 
case 'Layer 2+ Parms',
	[nline,nc]=size(str);
	if nline~=16,
		disp('USER ERROR: Layer spec for geo profile must have 14 lines'); return; 
	end
	ORC.parm_str{ORC.jlay}=cellstr(str); 
case 'H-space Parms',
	[nline,nc]=size(str);
	if nline~=7, 
        disp('USER ERROR: Halfspace parms must have 5 entries: cp,ap,rho,cs,as,fexpp,fexps].'); return; 
    end
	jlay_hsp=max(1,ORC.nlay+1);
	ORC.parm_str{jlay_hsp}([3:2:11,15,16])=cellstr(str);
case 'SSP from _SSP.mat',
	if no_files(val,str,'_SSP.mat'), return; end
    ORC.SSP_root=ORC.SSP_files{val};
    str=['load ',ORC.adi_dir,ORC.SSP_root]; eval(str);
    ORC.SSP=SSP;
    h1=findobj(cback_fig,'Tag','SSP: #, Hw, cs, cb, cmin');
    nssp=SSP.dims(2); str=[];
    jssp=get(h1,'Value');
    set(h1,'Max',SSP.dims(2),'Value',min(jssp,nssp));
    for j=1:nssp,
        csurf=SSP.data(1,j);
        cbot=SSP.data(SSP.nz(j),j);
        cmin=min(SSP.data(1:SSP.nz(j),j));
        str=strvcat(str,sprintf('%2.0i,%4.0i,%4.0i,%4.0i,%4.0i',round([j,SSP.hw(j),csurf,cbot,cmin])));
    end
    set(h1,'String',str);
%    orca_act('SSP: #, Hw, cs, cb, cmin');
case 'SSP: #, Hw, cs, cb, cmin',
    ORC.SSP_parms(1)=val; jssp=val; nz=ORC.SSP.nz(jssp); cssp=ORC.SSP.data(1:nz,jssp);
    zax=ORC.SSP.scales{1}(1:nz);
    ORC.ssp=[zax',ORC.SSP.data(1:nz,jssp)];
case 'Import SSP',
    orca_act('SSP: #, Hw, cs, cb, cmin');
	h1=findobj(cback_fig,'Tag','Ocean SSP: [z,c]');
	set(h1,'String',sprintf('%1.1f,%1.1f\n',ORC.ssp'));    
case 'Import SVP',
	if no_files(val,str,'SVP'), return; end
	ORC.svp_import=ORC.svp_files{val};
	GAP=adi_svp_read([ORC.adi_dir,ORC.svp_import]);
	ORC.ssp=GAP.ssp; 
	h1=findobj(cback_fig,'Tag','Ocean SSP: [z,c]');
	set(h1,'String',sprintf('%1.1f,%1.1f\n',ORC.ssp'));
	ORC.nlay=GAP.nlay; 
	for jlay=1:GAP.nlay,
		for jp=1:16,
			ORC.parm_str{jlay}{jp}=num2str(GAP.bot_layers(jlay,jp));
		end
	end
	h1=findobj(cback_fig,'Tag','No. Bot Layers');
	set(h1,'String',int2str(ORC.nlay));
	orca_act('No. Bot Layers');
	h1=findobj(cback_fig,'Tag','Layer 1 Parms');
	set(h1,'String',ORC.parm_str{1}); iip=[3:2:11,15,16]; jlay=GAP.nlay+1;
	for j=1:length(iip),
        jp=iip(j);
		ORC.parm_str{jlay}{jp}=num2str(GAP.hsp_bot(j));
	end
	h1=findobj(cback_fig,'Tag','H-space Parms');
	set(h1,'String',ORC.parm_str{ORC.nlay+1}([3:2:11,15,16]));
case 'Create SVP File',
	if isempty(ORC.out_root), 
% 		disp('USER ERROR: Fill in Output File Root before running'); break
        %tms for v7
		disp('USER ERROR: Fill in Output File Root before running'); return
	end
	svp_path=[ORC.adi_dir,ORC.out_root];
	if ~over_write(svp_path,'.svp'), return; end
	orca_save_run
	nlay=ORC.nlay; ORC.geo_layers=zeros(nlay,16); ORC.geo_layers(:,15:16)=1;
	for jlay=1:nlay,
		parms=str2num(char(ORC.parm_str{jlay}(ORC.parm_ord))); nl=length(parms);
		ORC.geo_layers(jlay,1:nl)=parms(:)';
	end
	ORC.geo_hsp=str2num(char(ORC.parm_str{nlay+1}(ORC.parm_ord([3:2:11,15,16]))))',
	svp_write(svp_path,ORC.ssp,ORC.geo_layers,ORC.geo_hsp);
	eval(['type(''',svp_path,'.svp'')']);
%	
%	
% Run ORCA:
case 'SVP File',
	if no_files(val,str,'SVP'), return; end
	ORC.svp_root=ORC.svp_files{val};
% Read SVP file and fill in info in SVP Info text boxes:
	ORC.GAP=adi_svp_read([ORC.adi_dir,ORC.svp_root]);
	nsvp=ORC.GAP.nsvp; nlay=ORC.GAP.nlay;
	Hw=ORC.GAP.ssp(nsvp,1);
    cw1=ORC.GAP.ssp(1,2); cw2=ORC.GAP.ssp(nsvp,2); 
	if nlay>0, 
        csed=ORC.GAP.bot_layers(1,3); if csed<0, csed=-cw2*csed; end
    else, 
        csed=ORC.GAP.hsp_bot(1); 
    end
    Hsed=sum(ORC.GAP.bot_layers(1:nlay,2)); if Hsed<0, Hsed=-Hsed*csed/2; end
	ORC.svp_info(1:6)=[Hw,Hsed,nlay,cw1,cw2,csed];
	h1=findobj(cback_fig,'Tag','Hw,Hsed,nlay');
	set(h1,'String',sprintf('%1.0f,%1.0f,%1.0f',ORC.svp_info(1:3)));
	h1=findobj(cback_fig,'Tag','cw1,cw2,csed');
	set(h1,'String',sprintf('%1.0f,%1.0f,%1.0f',ORC.svp_info(4:6)));
case 'Set ADI Dir',
    ORC.adi_dir=ekw_get_dir(ORC.adi_dir,'ADI');
    orca_name_update(cback_fig);    
case 'CW Frequencies',
	ORC.cw_freqs=str2num(char(str));
case 'Center Frequencies',
	ORC.cw_freqs=str2num(char(str));
case 'fs,+NF/-Tw,fmin,fmax',
	ORC.bb_parms=str2num(char(str));
	if length(ORC.bb_parms)<4, disp('WARNING: Broadband frequency parms must have 4 elements'); end
case 'Parms: rmin,dBcut',
	orca_parm1=str2num(char(str)); 
	if length(orca_parm1)~=2, disp('Parms must be [rmin,dBcut]'); return; end
	ORC.gen_opts([4,5])=orca_parm1;
case 'k-Plane [Real Axis]',
% Do real axis broadband in brute force manner (PC compiler flaky for rx_bb):
	if val, ORC.gen_opts(1)=0; else, ORC.gen_opts(1)=2; end
	gui_box_vis(cback_fig,'Mode Traj',val)
case 'Compute TL',
	ORC.cw_opts(1)=val;
	gui_box_vis(cback_fig,{'Incoherent TL Also','TL Phase Also','Source Depths','Receiver Depths','Ranges (km)'},val)
	orca_act('Spec Receiver Array');
case 'Create FFT File ',
	ORC.bb_opts(1)=val;
	gui_box_vis(cback_fig,{'Source Depths','Receiver Depths','Ranges (km)'},val)
	orca_act('Spec Receiver Array');
case 'Incoherent TL Also',
	ORC.cw_opts(12)=val;
case 'TL Phase Also',
	ORC.cw_opts(13)=val;
case 'Source Depths',
	ORC.zs_lims=str2num(char(str));
case 'Receiver Depths',
	ORC.zr_lims=str2num(char(str));
case 'Ranges (km)',
	ORC.rng_lims=str2num(char(str));
case 'Spec Receiver Array',
    ORC.iiarr=val;
% Don't show Receiver Depths or Array File if Compute TL not selected:
    if ORC.iiprog==1,
        gui_box_vis(cback_fig,{'Receiver Depths'},ORC.cw_opts(1)*(1-val)); 
        gui_box_vis(cback_fig,{'Rec Array','Set ARR Dir'},any(ORC.cw_opts(1:2))*val);
% Don't show MF Depths if Mode Functions not selected:
        gui_box_vis(cback_fig,{'MF Depths'},ORC.cw_opts(2)*(1-val));
     elseif ORC.iiprog==2,
        gui_box_vis(cback_fig,{'Receiver Depths'},ORC.bb_opts(1)*(1-val)>0); 
        gui_box_vis(cback_fig,{'Rec Array','Set ARR Dir'},any(ORC.bb_opts([1,6]))*val);
% Don't show MF Depths if Mode Functions not selected:
        gui_box_vis(cback_fig,{'MF Depths'},ORC.bb_opts(6)*(1-val));
     elseif ORC.iiprog==9,
        gui_box_vis(cback_fig,{'Receiver Depths'},ORC.bb_opts(1)*(1-val)); 
        gui_box_vis(cback_fig,{'Rec Array','Set ARR Dir'},any(ORC.bb_opts([1,6]))*val);
     elseif ORC.iiprog==8,
        gui_box_vis(cback_fig,{'Receiver Depths'},(1-val)); 
        gui_box_vis(cback_fig,{'Rec Array','Set ARR Dir'},val);
     end
case 'Rec Array',
	if no_files(val,str,'Array Geometry'), return; end
    ORC.geom_root=ORC.geom_files{val};
    geom_file=[ORC.arr_dir,ORC.geom_root];
	[ORC.rec_xyz,ORC.cavg,nph,iif]=arr_geom(geom_file); 
    if ~iif, error(['USER ERROR: Could not find array geometry file ',geom_file]); end
    if max(ORC.rec_xyz(:,3))>ORC.svp_info(1),
        disp(['WARNING: Array geometry file has receivers deeper than water depth of SVP file = ',ORC.svp_info(1)]);
        disp('Receiver depths = '); disp(ORC.rec_xyz(:,3))
    end
case 'Set ARR Dir',
    ORC.arr_dir=ekw_get_dir(ORC.arr_dir,'Array Geometry');
    orca_name_update(cback_fig);    
case 'Make Array File ...',
    ORC.ii_make=val;
    gui_box_vis(cback_fig,{'Array x,y,z'},val); 
    gui_box_vis(cback_fig,{'Make Array Geometry File'},val);
case 'Array x,y,z',
    vals=str2num(str); if size(vals,2)~=3, error('Array x,y,z must have 3 columns.'); end
    ORC.arr_xyz=vals;
case 'Make Array Geometry File',
    if size(ORC.arr_xyz,2)~=3, error('Array x,y,z must have 3 columns.'); end
	if isempty(ORC.out_root), error('USER ERROR: Fill in Output File Root before running.'); end
    array_root=[ORC.nav_dir,ORC.out_root]; ORC.cavg=1500;
    adi_array_make(array_root,ORC.arr_xyz,ORC.cavg,-1);
    disp(['NOTE: Set ORC.cavg manually to set cavg in array file to a value different from ',num2str(ORC.cavg)])
case 'CW Mode Functions',
	ORC.cw_opts(2)=val;
   gui_box_vis(cback_fig,{'MF Depths','Re,Im(dphi) Also'},val)
   orca_act('Spec Receiver Array');
case 'BB Mode Functions',
	ORC.bb_opts(6)=val;
   gui_box_vis(cback_fig,{'MF Depths','Re,Im(dphi) Also'},val)
   orca_act('Spec Receiver Array');
%case 'mag(phi) [Re/Im]',
%    ORC.cw_opts(14)=val;
%case 'Arg/Im(phi) Also',
%    ORC.cw_opts(15)=val;
case 'Re,Im(dphi) Also',
    ORC.cw_opts(16)=val;
case 'MF Depths',
	ORC.zmf_lims=str2num(char(str));
   if isempty(ORC.zmf_lims), 
      ORC.zmf_lims=ORC.zr_lims;
      h1=findobj(cback_fig,'Tag','Receiver Depths'); set(hval,'String',get(h1,'String'));
   end
case 'Mode Traj',
	ORC.cw_opts(4)=val;
	ORC.bb_opts(4)=val;
case 'Mode Eigenvalues',
	ORC.cw_opts(6)=val;
case 'Output Group Velocity',
	ORC.cw_opts(5)=3*val;		% Request both vg and cph for dispersion curves;
	ORC.bb_opts(5)=3*val;
case 'Mode List',
	ORC.cw_opts(7)=val;
case 'Auto View',
    ORC.auto=val;
case 'Copy Data to Odat.xx',
    ORC.iidata=val;
case 'ORCA Diagnostics',
    ORC.gen_opts(12)=2*val;
%
case 'Number of Runs',
    ORC.var_parm1(1)=str2num(char(str));
case '# Parms to Vary',
    ORC.var_parm1(2)=str2num(char(str));
case 'Parm Codes: [obt,nlay,ktb,pc,val1,val2] (nparm rows)',
    vparms=str2num(char(str)); [nr,nc]=size(vparms);
    if nr~=ORC.var_parm1(2), disp('Parm Codes must have nparm rows.'); return; end
    if nc~=6, disp('Parm Codes must have 6 columns on each row'); return; end
    ORC.var_parm2=vparms;
case 'Vary Parms',
	ORC.type_opts(4)=val;
    tags={'Parm Codes: [obt,nlay,ktb,pc,val1,val2] (nparm rows)','# Parms to Vary','Number of Runs'};
    gui_box_vis(cback_fig,tags,ORC.type_opts(4));
%
% k-Plane Images:
case 'k-Plane Frequency',
	ORC.kpl_parms(1)=str2num(char(str));
case 'Re(k)/K Limits',
	ORC.kpl_parms(4:6)=str2num(char(str));
case 'Im(k) - dB/km',
	ORC.kpl_parms(7:9)=str2num(char(str));
% Bottom Loss:
case 'BL Frequencies',
	ORC.rc_parms{1}=str2num(char(str));
case 'BL Angles (deg)',
	ORC.rc_parms{2}=str2num(char(str));
case 'RUN ORCA',
	if isempty(ORC.out_root), 
        disp('Please fill in "Output File Root" first ("auto" for automatic naming).'); return; 
    end
    iiauto=0;
    if strcmp(ORC.out_root,'auto'),
%        sufs={'_CW','_BB','_KPL','_BL','_PS'}; iiauto=1;
        sufs={'_CW','_BB','_KPL','_BL','_PS','','','_NBA'}; iiauto=1;
        ORC.out_root=[ORC.svp_root,sufs{ORC.iiprog}];
        h1=findobj(cback_fig,'Tag','Output File Root'); set(h1,'String',ORC.out_root);
        disp(['Automatic "Output File Root" set to: ',ORC.out_root]);
    end
	orca_save_run
	iicomm=0; 
    ORC.cw_opts(15)=1;      % Automatically get Im(phi)
%    ORC.gen_opts(12)=1; % For diagnostics
    iiarr=ORC.iiarr; 
    if ~any(ORC.iiprog==[1,2]), 
       iiarr=0;
    elseif ORC.iiprog==1 & ~any(ORC.cw_opts([1,2])),
       iiarr=0;
    elseif ORC.iiprog==2 & ~any(ORC.bb_opts([1,6])),
       iiarr=0;
    end
    zr_lims=ORC.zr_lims; zmf_lims=ORC.zmf_lims; bb_opts=ORC.bb_opts; iicw=ORC.type_opts(1);
    if iicw==2 & ORC.iiarr & bb_opts(1),
        orca_act('Rec Array');
        ii_hla=any(ORC.rec_xyz(:,1)~=ORC.rec_xyz(1,1) | ORC.rec_xyz(:,2)~=ORC.rec_xyz(1,2)),
        if ii_hla,
            bb_opts(1)=2; zr_lims=[ORC.arr_dir,ORC.geom_root]; zmf_lims=ORC.zmf_lims;
        end
    end
% Output OPT file:
	orca_opt_write(ORC.out_root,iicomm,ORC.type_opts,ORC.gen_opts,ORC.cw_freqs,ORC.cw_opts(1:16), ...
		ORC.zs_lims,zr_lims,ORC.rng_lims,zmf_lims,ORC.bb_parms,bb_opts, ...
		ORC.var_parm1,ORC.var_parm2,ORC.kpl_parms,ORC.rc_parms);
	eval(['type(''',ORC.out_root,'.opt'')']);
%
% Run orca90:
	svp_file=[ORC.adi_dir,ORC.svp_root,'.svp'];
	opt_file=[ORC.out_root,'.opt'];
	stat=orca90(svp_file,opt_file,ORC.out_root);
    if stat==0, disp('ORCA did not run succesfully'); return; end
    str=['type(''',ORC.out_root,'_out'')']; disp(str); eval(str);
% Plot all datasets in output HDF file:
    if ORC.auto,
        orca_plot_all(cback_fig,0)
    end
    if iiauto, 
        ORC.out_root='auto';         
        h1=findobj(cback_fig,'Tag','Output File Root'); set(h1,'String',ORC.out_root);
	end
case 'Meld in Freq [block]',
    ORC.nba_opts(1)=val;
case 'Create FFT File',
    ORC.nba_opts(2)=val;
case 'View Transfer Function',
    ORC.nba_opts(3)=val;
case 'BW,+Tw/-df',
    ORC.nba_opts([4,5])=str2num(char(str));
case 'RUN ORCA NB Approx',
	 if isempty(ORC.out_root), 
        disp('Please fill in "Output File Root" first.'); return; 
    end
    if ORC.iiarr & isempty(ORC.geom_root), 
       error(sprintf('\nUSER ERROR: No geometry file chosen.')); 
    end
    orca_save_run
    iimeld=ORC.nba_opts(1); iifft=ORC.nba_opts(2); iifig=ORC.nba_opts(3);
    BW=ORC.nba_opts(4); Tw=ORC.nba_opts(5);
    TF=orca_nba_ri_run(BW,Tw,iimeld,iifft,iifig);
    if ORC.iidata, Odat.TF=TF; end
case 'Compute Dom Beta',
	if isempty(ORC.out_root), 
		disp('USER ERROR: Fill in Output File Root before running'); return
	end
    iifig=1; iisave=1; 
    [Odat.BDOM,Odat.BETA]=orca_beta_dom_run(iifig,iisave);
case 'Beta HDF File',
	if strcmp(ORC.hdf_files{val},'None Available'), return; end
	ORC.hdf_root=ORC.hdf_files{val};
case 'Compute Beta vs. Mode',
    BETA=orca_beta_calc(ORC.hdf_root,0);
	if ORC.v_opts(1), iinewfig=1; else, figure(190); clf; iinewfig=0; end
    view5(BETA,[],[],iinewfig,ORC.psize,1);
case 'RUN RAM PE',
	if isempty(ORC.out_root), 
		disp('USER ERROR: Fill in Output File Root before running'); return
	end
	if ~over_write(ORC.out_root,'_ram_atl.mat'), return; end
	if isempty(ORC.svp_root), 
		disp('User must choose an SVP file for bottom properties first'); return
	end
	orca_save_run;
    orca_ram_run;
    if ORC.auto, orca_plot_all(cback_fig,0); end
% Plot all datasets in output HDF file:
% View output:
case 'HDF File',
	if strcmp(ORC.hdf_files{val},'None Available'), return; end
	ORC.hdf_root=ORC.hdf_files{val};
	[ORC.SD,status]=hdfsd_open([ORC.hdf_root,'.hdf']); if status<0, return; end
	ORC.hdf_nset=ORC.SD.nset;
	ORC.hdf_sets=ORC.SD.data_name;
	h1=findobj(cback_fig,'Tag','HDF Set Names'); jset=get(h1,'Value');
	if jset>ORC.hdf_nset, set(h1,'Value',1); end
	set(h1,'String',ORC.hdf_sets);
	orca_act('HDF Set Names');
case 'HDF Set Names',
	ORC.hdf_jset=val; jset=ORC.hdf_jset; ORC.hdf_rank=ORC.SD.rank{jset};
	h1=findobj(cback_fig,'Tag','HDF Set Rank'); str2=sprintf('%1i',ORC.hdf_rank);
	set(h1,'String',str2);
	h1=findobj(cback_fig,'Tag','Set Dim Names');
	set(h1,'String',ORC.SD.dim_names{jset});
	h1=findobj(cback_fig,'Tag','Dims [min,max]'); str2=cell(ORC.SD.rank{jset},1);
	for jdim=1:ORC.SD.rank{jset},
		ldim=ORC.SD.dim_sizes{jset}(jdim); scales=ORC.SD.scales{jset}{jdim}; 
        if ldim==1, 
 			str2{jdim}=sprintf('%5i (%1.2f)',[ldim,scales(1)]);
        else, 
%%            [ldim,scales(1),scales(end)],
			str2{jdim}=sprintf('%5i (%1.2f,%1.2f)',[ldim,scales(1),scales(end)]);
        end
	end
%%	str2=cellstr(int2str(ORC.SD.dim_sizes{jset}'));
	set(h1,'String',str2);
case 'Dim Limits',
	ORC.hdf_dim_lims=cellstr(str);
% Convert each cell to a number:
	for j=1:length(ORC.hdf_dim_lims),
		if isempty(ORC.hdf_dim_lims{j}), ORC.hdf_dim_lims{j}='0'; end
		ORC.hdf_dim_lims{j}=str2num(ORC.hdf_dim_lims{j}); 
	end
%
	jset=ORC.hdf_jset; rank=ORC.SD.rank{jset}; nrow=length(ORC.hdf_dim_lims);
	if nrow>rank,
		lims=ORC.hdf_dim_lims; ORC.hdf_dim_lims=cell(rank,1);
		for j=1:rank, ORC.hdf_dim_lims{j}=lims{j}; end
	elseif nrow<rank,
		for j=nrow+1:rank, ORC.hdf_dim_lims{j}=0; end
	end
case 'Mode Trajectory File',
    if no_files(val,str,'Mode Trajectory',0), return; end
    ORC.mtraj_root=ORC.mtraj_files{val};
case 'Plot Mode Trajectory',
    if isempty(ORC.mtraj_root) | strcmp(ORC.mtraj_root,'None Available'),
        disp('No ORCA Mode Trajectory Files (suffix="_mtraj") available'); return
    end
    iilog=-3; iilab=1; sym='o'; col='r'; dotsize=Odef.dotsize; iivg=1;
	if ORC.v_opts(1), iinewfig=1; else, figure(195); clf; iinewfig=0; end
    eigs=orca_mode_traj([ORC.mtraj_root,'_mtraj'],iilog,iilab,sym,col,Odef.dotsize,ORC.psize, ...
        iivg,iinewfig);
case 'Size [w,h]',
	ORC.psize=str2num(char(str));
case 'Cmin,Cmax',
    ORC.clim=str2num(char(str));
case 'Create New Fig',
	ORC.v_opts(1)=val;
case 'View HDF Set',
    if ~isfield(ORC,'SD') | isempty(ORC.SD) | ~exist(ORC.SD.hdf_file,'file'),
        error('HDF not selected or HDF file selected does not exist locally.'); 
    end
	orca_act('Dim Limits');
	if ORC.v_opts(1), iinewfig=1; else, figure(190); clf; iinewfig=0; end
    [DATA,status]=hdfsd_read(ORC.SD,ORC.hdf_dim_lims,ORC.hdf_jset); if status<0, return; end
    if ORC.iidata,
        ii=findstr(DATA.dlab,' - '); if isempty(ii), ii=length(DATA.dlab)+1; end
        name=DATA.dlab(1:ii(1)-1); 
        name=strrep(name,' ','_'); name=strrep(name,'(','_'); name=strrep(name,')','_');  
        name=strrep(name,'|','_'); name=strrep(name,'[','_'); name=strrep(name,']','_');
        name=strrep(name,'.','_'); name=strrep(name,':','_'); name=strrep(name,'/','_');
        name=strrep(name,'\','_');
        str=['Odat.',name,'=DATA;']; eval(str);
    end
    c_diff=diff(ORC.clim); d_diff=diff(DATA.clim); rat=c_diff/max(1.e-10,d_diff);
    if (abs(ORC.clim(2)-DATA.clim(2)) < .4*c_diff & rat<3 & rat>.3) | ...
            ~isempty(findstr(DATA.dlab,'TL')),   %% 
        V.clim=ORC.clim; DATA.clim=ORC.clim;
    end
    view5(DATA,[],1,iinewfig,ORC.psize,ORC.v_opts(4));
case 'Plot All HDF Sets',
    orca_plot_all(cback_fig,1);
case 'Log Axis for Im(k)',
    ORC.v_opts(4)=val;
case 'Plot Modes in k Plane',
% Select Re(kn) under HDF Set Names:
    jset_kn=find(strcmp(ORC.hdf_sets,'Re(kn)'));
    if isempty(jset_kn), disp('Current HDF file does not contain Re(kn), Im(kn).'); return; end
    h1=findobj(cback_fig,'Tag','HDF Set Names'); set(h1,'val',jset_kn); orca_act('HDF Set Names');
% Set Dim Limits to all:
	orca_act('Dim Limits');
	if ORC.v_opts(1), figure; else, figure(191); clf; end
    [KNR,status]=hdfsd_read(ORC.SD,ORC.hdf_dim_lims,jset_kn); if status<0, return; end
    [KNI,status]=hdfsd_read(ORC.SD,ORC.hdf_dim_lims,jset_kn+1); if status<0, return; end
    if ORC.iidata, Odat.Re_kn_=KNR; Odat.Im_kn_=KNI; end
    if isfield(ORC,'GAP') & ~isempty(ORC.GAP), cref=min(ORC.GAP.ssp(:,2)); else, cref=1500; end
    disp(['Sound Speed used to convert knr to cos(theta) = ',num2str(cref)]);
    orca_kn_plot(KNR,KNI,cref,ORC.psize,'rbgmck',ORC.v_opts(4));
case 'Plot Dispersion Curves',
	orca_act('Dim Limits');
    jset_vg=find(strncmp(ORC.hdf_sets,'Group Speed',11));
    if isempty(jset_vg), disp('Current HDF file does not contain Group Speed.'); return; end
	if ORC.v_opts(1), figure; else, figure(190); clf; end
    [VG,status]=hdfsd_read(ORC.SD,ORC.hdf_dim_lims,jset_vg); if status<0, return; end
    orca_vg_plot(VG,ORC.psize,'rbgmck');
case 'Time Delays, BW',
    vals=str2num(str); 
    if length(vals)~=4, 
        disp('"Time Delay, BW" Box must be have 4 elements: [tau1,tau2,+ntau/-dt,BW]'); return;
    end
    ORC.tau_lims=vals;
case 'Norm Pulse Envelopes',
    ORC.v_opts(2)=val;
case 'Plot Pulse Envelopes',
    if ~any(strcmp(ORC.hdf_sets,'Re(phi)')), disp('HDF File must contain Re(phi) data set.'); return; end
    if ~strcmp(ORC.hdf_sets{ORC.hdf_jset},'Re(phi)'),
        disp('Select Re(phi) dataset and choose Depth and Frequency dimension limits to plot.'); return
    end
	orca_act('Dim Limits');
    f_lims=ORC.hdf_dim_lims{3}; iinorm=ORC.v_opts(2);
    if ORC.hdf_rank>3, p_lims=ORC.hdf_dim_lims{4}; else; p_lims=[]; end
	if ORC.v_opts(1), iinewfig=1; else, figure(190); clf; iinewfig=0; end
    PULSE=orca_pulse_env(ORC.SD,f_lims,ORC.zs_lims,ORC.hdf_dim_lims{1},ORC.rng_lims, ...
        ORC.tau_lims(1:3),p_lims,ORC.tau_lims(4),iinorm,ORC.psize,1,iinewfig);
    Tsp=tspread(PULSE);
    if ORC.iidata, Odat.PULSE=PULSE; Odat.Tsp=Tsp; end
    [dim_sort,ii]=sort(Tsp.dims); vdims=[ii(end),ii(end-1),ii(end-2)];
    if ~iinewfig, figure(192); clf; end
    view6(Tsp,vdims,[],iinewfig,ORC.psize);
%
case 'Meas TL File',
	if strcmp(ORC.mtl_files{val},'None Available'), return; end
	ORC.mtl_root=ORC.mtl_files{val};    
case 'Overlay TL',
    if ~isfield(ORC,'SD') | isempty(ORC.SD) | ~exist(ORC.SD.hdf_file,'file'),
        error('HDF not selected or HDF file selected does not exist locally.'); 
    end
	orca_act('Dim Limits');
	if ORC.v_opts(1), iinewfig=1; else, figure(190); clf; iinewfig=0; end
    [DATA,status]=hdfsd_read(ORC.SD,ORC.hdf_dim_lims,ORC.hdf_jset); if status<0, return; end
	if ORC.v_opts(1), iinewfig=1; else, figure(190); clf; iinewfig=0; end
    TL_ovlay(DATA,ORC.mtl_root,[],ORC.psize,[],[],ORC.clim,iinewfig)    
otherwise,
	disp(['UNKNOWN ACTION in orca_act: ',action]); 
%
end
%
%%%
%
function over_wr=over_write(out_root,out_suf)
%
out_file=[out_root,out_suf]; over_wr=1;
if exist(out_file,'file') == 2,
	disp(['WARNING: Output file ',out_file,' already exists!!!'])
	inp=input('Press return to overwrite, any other key to abort: ','s');
	if ~isempty(inp), over_wr=0; disp('Run aborted'); end
end
%
%%%
%
function iiret=no_files(val,str,file_kind,iipr), 
%
if nargin<4, iipr=1; end
iiret=0;
if val==0 | strcmp(str,'None Available'), 
	if iipr,
        disp(['No ',file_kind,' files in currect directory!! cd to desired directory']);
    end
    iiret=1;
end
%
function TLm=tlm2_get(tlm_root2);
%
str=['load ',tlm_root2,'_TLm.mat']; disp(str); eval(str);
%
%%%
%

