function getvelocity(command)
% Enter/Load the velocity profile(s)
global U V W z rho vel dep den
global h_edit_velocity h_edit_depths h_edit_density

if nargin == 0, command=0; end
if command == 0,
   figure(4);clf
   set(gcf,'Units', 'Normalized',...
      'Position',[.05 .02 .4 .225],...
      'Name','Load Velocity',...
      'Color',[.8 .8 .8],...
      'tag','getvelocity');
   h_push_entervel=uicontrol('Style','pushbutton',...
      'Callback','getvelocity(2)',...
      'String','Enter/Edit Velocities Manually',...
      'Units','normalized',...
      'Position',[.2 .8 .6 .125]);
   h_push_loadvel=uicontrol('Style','pushbutton',...
      'Callback','getvelocity(1)',...
      'String','Load Velocity File',...
      'Units','normalized',...
      'Position',[.05 .6 .4 .125]);
   h_push_savevel=uicontrol('Style','pushbutton',...
      'Callback','getvelocity(11)',...
      'String','Save Velocity File',...
      'Units','normalized',...
      'Position',[.55 .6 .4 .125]);
   h_push_enterden=uicontrol('Style','pushbutton',...
      'Callback','getvelocity(22)',...
      'String','Enter/Edit Densities Manually',...
      'Units','normalized',...
      'Position',[.2 .4 .6 .125]);
   h_push_loadden=uicontrol('Style','pushbutton',...
      'Callback','getvelocity(21)',...
      'String','Load Density File',...
      'Units','normalized',...
      'Position',[.05 .2 .4 .125]);
   h_push_saveden=uicontrol('Style','pushbutton',...
      'Callback','getvelocity(31)',...
      'String','Save Density File',...
      'Units','normalized',...
      'Position',[.55 .2 .4 .125]);
   h_help=uicontrol('Style','Pushbutton',...
      'String','Help',...
      'Units','normalized',...
      'Position',[.15 .03 .2 .125],...
      'Callback','getvelocity(12)');
   h_close=uicontrol('Style','Pushbutton',...
      'String','Close',...
      'Units','normalized',...
      'Position',[.65 .03 .2 .125],...
      'Callback','close');
   h_edit_velocity=[];
   h_edit_depths=[];
   if isempty(vel) | isempty(dep) | isempty(den),
      vel='1.0 0.6 0';
      dep='120 10 0';
      den='1024 1025 1026';
   end
   if isempty(U), U=str2num(vel); end
   if isempty(z), z=str2num(dep); end
   if isempty(rho), rho=str2num(den); end
end
if command == 1,
      [ifile,ipath]=uigetfile('*.mat','Load Existing Velocity File');
      eval(['load ',ipath,ifile]);
      clear ifile ipath
elseif command == 21,
      [ifile,ipath]=uigetfile('*.mat','Load Existing Density File');
      eval(['load ',ipath,ifile]);
      clear ifile ipath
elseif command == 2,
      figure(4);clf;
         h_push_uvel=uicontrol('Style','pushbutton',...
           'Callback','getvelocity(3)',...
           'String','Enter U Velocities',...
           'Units','normalized',...
           'Position',[.2 .85 .6 .1]);
         h_push_uvel=uicontrol('Style','pushbutton',...
           'Callback','getvelocity(5)',...
           'String','Enter Z Depths',...
           'Units','normalized',...
           'Position',[.2 .7 .6 .1]);
         h_push_vvel=uicontrol('Style','pushbutton',...
           'Callback','getvelocity(7)',...
           'String','Enter V Velocities',...
           'Units','normalized',...
           'Position',[.2 .55 .6 .1]);
         h_push_wvel=uicontrol('Style','pushbutton',...
           'Callback','getvelocity(9)',...
           'String','Enter W Velocities',...
           'Units','normalized',...
           'Position',[.2 .4 .6 .1]);
         h_push_uvwsave=uicontrol('Style','pushbutton',...
           'Callback','getvelocity(11)',...
           'String','Save Velocities',...
           'Units','normalized',...
           'Position',[.2 .25 .6 .1]);
         h_help=uicontrol('Style','Pushbutton',...
           'String','Help',...
           'Units','normalized',...
           'Position',[.15 .03 .2 .1],...
           'Callback','getvelocity(12)');
        h_close=uicontrol('Style','Pushbutton',...
           'String','Close',...
           'Units','normalized',...
           'Position',[.65 .03 .2 .1],...
           'Callback','getvelocity(0)');
elseif command == 22,
      figure(4);clf;
         h_push_den=uicontrol('Style','pushbutton',...
           'Callback','getvelocity(23)',...
           'String','Enter Densities',...
           'Units','normalized',...
           'Position',[.2 .75 .6 .2]);
         h_push_zden=uicontrol('Style','pushbutton',...
           'Callback','getvelocity(5)',...
           'String','Enter Z Depths',...
           'Units','normalized',...
           'Position',[.2 .45 .6 .2]);
         h_push_densave=uicontrol('Style','pushbutton',...
           'Callback','getvelocity(31)',...
           'String','Save Density Profile',...
           'Units','normalized',...
           'Position',[.2 .25 .6 .15]);
         h_help=uicontrol('Style','Pushbutton',...
           'String','Help',...
           'Units','normalized',...
           'Position',[.15 .03 .2 .1],...
           'Callback','getvelocity(12)');
         h_close=uicontrol('Style','Pushbutton',...
           'String','Close',...
           'Units','normalized',...
           'Position',[.65 .03 .2 .1],...
           'Callback','getvelocity(0)');
elseif command == 3,
   clf;
   if ~isempty(U), vel=num2str(U); end
   h_text_velocity=uicontrol('Style','text',...
      'String','Enter U Velocities [m/s]',...
      'Units','normalized',...
      'Position',[.05 .7 .3 .2]);
   h_edit_velocity=uicontrol('Style','edit',...
      'Callback','getvelocity(4)',...
      'String',vel,...
      'Units','Normalized',...
      'Position',[.4 .7 .5 .2]);
   h_ok=uicontrol('Style','Pushbutton',...
      'String','OK',...
      'Units','normalized',...
      'Position',[.4 .25 .2 .2],...
      'Callback','getvelocity(4)');
   h_help=uicontrol('Style','Pushbutton',...
      'String','Help',...
      'Units','normalized',...
      'Position',[.15 .03 .2 .15],...
      'Callback','getvelocity(12)');
   h_close=uicontrol('Style','Pushbutton',...
      'String','Close',...
      'Units','normalized',...
      'Position',[.65 .03 .2 .15],...
      'Callback','close');
elseif command == 23,
   clf;
   if ~isempty(rho), den=num2str(rho); end
   h_text_density=uicontrol('Style','text',...
      'String','Enter Densities [kg/m^3]',...
      'Units','normalized',...
      'Position',[.05 .7 .3 .2]);
   h_edit_density=uicontrol('Style','edit',...
      'Callback','getvelocity(24)',...
      'String',den,...
      'Units','Normalized',...
      'Position',[.4 .7 .5 .2]);
   h_ok=uicontrol('Style','Pushbutton',...
      'String','OK',...
      'Units','normalized',...
      'Position',[.4 .25 .2 .2],...
      'Callback','getvelocity(24)');
   h_help=uicontrol('Style','Pushbutton',...
      'String','Help',...
      'Units','normalized',...
      'Position',[.15 .03 .2 .15],...
      'Callback','getvelocity(12)');
   h_close=uicontrol('Style','Pushbutton',...
      'String','Close',...
      'Units','normalized',...
      'Position',[.65 .03 .2 .15],...
      'Callback','close');
elseif command == 4,
   U=str2num(get(h_edit_velocity,'String'));
   if length(V)~=length(U), V=zeros(size(U)); end
   if length(W)~=length(U), W=zeros(size(U)); end
   getvelocity(5);
elseif command == 24,
   rho=str2num(get(h_edit_density,'String'));
   getvelocity(5);
elseif command == 5,
   clf;
   if ~isempty(z), dep=num2str(z); end
   h_text_depths=uicontrol('Style','text',...
     'String','Enter Heights [m]',...
     'Units','normalized',...
     'Position',[.05 .7 .3 .2]);
   h_edit_depths=uicontrol('Style','edit',...
     'Callback','getvelocity(6)',...
     'String',dep,...
     'Units','Normalized',...
     'Position',[.4 .7 .5 .2]);
   h_ok=uicontrol('Style','Pushbutton',...
      'String','OK',...
      'Units','normalized',...
      'Position',[.4 .25 .2 .2],...
      'Callback','getvelocity(6)');
   h_help=uicontrol('Style','Pushbutton',...
      'String','Help',...
      'Units','normalized',...
      'Position',[.15 .03 .2 .15],...
      'Callback','getvelocity(12)');
   h_close=uicontrol('Style','Pushbutton',...
      'String','Close',...
      'Units','normalized',...
      'Position',[.65 .03 .2 .15],...
      'Callback','close');
elseif command == 6,
   z=str2num(get(h_edit_depths,'String'));
   if z(length(z)) == 0 | z(1) == 0,
      getvelocity(0);
   else
      msgbox(' Velocity profile must have value at the bottom (z=0) ');
      figure(4);
      getvelocity(0); 
   end
   if length(z) ~= length(U),
      msgbox(' Number of depth/height values must equal the number of velocity values.');
      dep=num2str(z);
      figure(4);
      getvelocity(0);
   end
   if length(z) ~= length(rho),
      msgbox(' Number of depth/height values must equal the number of density values.');
      dep=num2str(z);
      figure(4);
      getvelocity(0);
   end
elseif command == 7,
   clf;
   if ~isempty(V), vel=num2str(V); end
   if length(V) ~= length(U), V=zeros(size(U)); vel=num2str(V); end
   h_text_velocity=uicontrol('Style','text',...
      'String','Enter V Velocities [m/s]',...
      'Units','normalized',...
      'Position',[.05 .7 .3 .2]);
   h_edit_velocity=uicontrol('Style','edit',...
      'Callback','getvelocity(8)',...
      'String',vel,...
      'Units','Normalized',...
      'Position',[.4 .7 .5 .2]);
   h_ok=uicontrol('Style','Pushbutton',...
      'String','OK',...
      'Units','normalized',...
      'Position',[.4 .25 .2 .2],...
      'Callback','getvelocity(8)');
   h_help=uicontrol('Style','Pushbutton',...
      'String','Help',...
      'Units','normalized',...
      'Position',[.15 .03 .2 .15],...
      'Callback','getvelocity(12)');
   h_close=uicontrol('Style','Pushbutton',...
      'String','Close',...
      'Units','normalized',...
      'Position',[.65 .03 .2 .15],...
      'Callback','close');
elseif command == 8,
   V=str2num(get(h_edit_velocity,'String'));
   getvelocity(2);
elseif command == 9,
   clf;
   if ~isempty(W), vel=num2str(W); end
   if length(W) ~= length(U), W=zeros(size(U)); vel=num2str(W); end
   h_text_velocity=uicontrol('Style','text',...
      'String','Enter W Velocities [m/s]',...
      'Units','normalized',...
      'Position',[.05 .7 .3 .2]);
   h_edit_velocity=uicontrol('Style','edit',...
      'Callback','getvelocity(10)',...
      'String',vel,...
      'Units','Normalized',...
      'Position',[.4 .7 .5 .2]);
   h_ok=uicontrol('Style','Pushbutton',...
      'String','OK',...
      'Units','normalized',...
      'Position',[.4 .25 .2 .2],...
      'Callback','getvelocity(10)');
   h_help=uicontrol('Style','Pushbutton',...
      'String','Help',...
      'Units','normalized',...
      'Position',[.15 .03 .2 .15],...
      'Callback','getvelocity(12)');
   h_close=uicontrol('Style','Pushbutton',...
      'String','Close',...
      'Units','normalized',...
      'Position',[.65 .03 .2 .15],...
      'Callback','close');
elseif command == 10,
   W=str2num(get(h_edit_velocity,'String'));
   getvelocity(2);
elseif command == 11,
   [ofile,opath]=uiputfile('*.mat','Save Velocities File');
   if ofile~=0&opath~=0, eval(['save ',opath,ofile,' U V W z']);end
   clear ofile opath
   getvelocity(0);
elseif command == 31,
   [ofile,opath]=uiputfile('*.mat','Save Density File');
   if ofile~=0&opath~=0, eval(['save ',opath,ofile,' den z']);end
   clear ofile opath
   getvelocity(0);
elseif command == 12,
   load velhelp
   h_help=msgbox(velhelp);
   hpos=get(h_help,'Position');
   set(h_help,'Position',[hpos(1) 10 hpos(3) hpos(4)]);
   clear velhelp
elseif command==40,
   if isempty(vel) | isempty(dep),
      vel='1.0 0.6 0';
      dep='120 10 0';
   end
   if isempty(U), U=str2num(vel); end
   if isempty(V), V=zeros(size(U)); end
   if isempty(W), W=zeros(size(U)); end
   if isempty(z), z=str2num(dep); end
   if isempty(rho), rho=1025*ones(size(U)); end
   disp(' Height[m]    U [m/s]    V [m/s]    W [m/s] Density [kg/m^3]');
   %     12345678911234567892123456789312345678941234567895123456789
   for i=1:length(z),
      if z(i)>999.99,
         disp([' ',num2str([z(i) U(i) V(i) W(i) rho(i)],'%11.2f')]);
      elseif z(i)<1000&z(i)>99.99,
         disp(['  ',num2str([z(i) U(i) V(i) W(i) rho(i)],'%11.2f')]);
      elseif z(i)<100&z(i)>9.99,
         disp(['   ',num2str([z(i) U(i) V(i) W(i) rho(i)],'%11.2f')]);
      elseif z(i)<10,
         disp(['    ',num2str([z(i) U(i) V(i) W(i) rho(i)],'%11.2f')]);
      end
   end
end
% fini
