function orca_vary_env_hdf(hdf_root,svp,geo_bot)
%
% Call orca_vary_env_hdf(hdf_root,svp,geo_bot);
%
% svp	= [nsvp_max,2,nrun] array with z (m) in first column, c (m/s) in second.
%		  Trailing NaNs in rows are ignored;
% geo_bot(1:nlay,1:16,1:nrun)	= geoacoustic profile parameters in ORCA input format.
%
% 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.
[nsvp_max,ncol_svp,nrun]=size(svp);
if ncol_svp~=2 & ncol_svp~=4, disp(['# columns of svp input should be 2 or 4.']); end
[nbot_max,ncol,nrun2]=size(geo_bot);
if ncol~=16 disp(['# columns of geo_bot input should be 16.']); end
if nrun2~=nrun, disp(['nrun not same for svp and geo_bot']); end
nlay=zeros(3,nrun);
for jrun=1:nrun,
    ii=find(isnan(svp(:,1,jrun)));
    if isempty(ii), nlay(1,jrun)=nsvp_max; else, nlay(1,jrun)=ii(1)-1; end
    ii=find(isnan(geo_bot(:,1,jrun)));
    if isempty(ii), nlay(2,jrun)=nbot_max-1; else, nlay(2,jrun)=ii(1)-1; end
    nlay(3,jrun)=0;     % No top layers for now;
end
[SDw,stat]=hdfsd_write_open(hdf_root,[],1,'Number of Layers',[3,nrun], ...
 	{[1:3],[1:nrun]},{'nsvp/nbot/ntop','ORCA Run Number'});
if stat<0, error(['Error opening output HDF file for set 1.']); end
[stat]=hdfsd_write(SDw,1,[],nlay);
%
if ncol_svp==2,
    svp=repmat(svp,[1,2,1]);
    svp(:,3,:)=1; svp(:,4,:)=999;
end
[SDw,stat]=hdfsd_write_open(hdf_root,SDw,2,'Ocean',[nsvp_max,4,nrun], ...
 	{[1:nsvp_max],[1:4],[1:nrun]},{'Depth Index','z/c/rho/alpha','ORCA Run Number'});
if stat<0, error(['Error opening output HDF file for set 2.']); end
[stat]=hdfsd_write(SDw,2,[],svp);
%
[SDw,stat]=hdfsd_write_open(hdf_root,SDw,3,'Bottom',[nbot_max,2,8,nrun], ...
 	{[1:nbot_max],[1:2],[1:8],[1:nrun]}, ...
    {'Layer Index','top/bottom','ii&h/cp/cs/rho/ap/as/beta&ctol/fexpp&fexps','ORCA Run Number'});
if stat<0, error(['Error opening output HDF file for set 3.']); end
geo_bot=reshape(geo_bot,[nbot_max,2,8,nrun]);
[stat]=hdfsd_write(SDw,3,[],geo_bot);
%
geo_top=reshape([1 1e20 343 343 0 0 .00121 .00121 0 0 0 0 0 0 1 1],[2,8]);
geo_top=reshape(geo_top,[1,2,8]);
geo_top=repmat(geo_top,[1,1,1,nrun]); 
[SDw,stat]=hdfsd_write_open(hdf_root,SDw,4,'Top',[1,2,8,nrun], ...
 	{[1],[1:2],[1:8],[1:nrun]}, ...
    {'Layer Index','top/bottom','ii&h/cp/cs/rho/ap/as/beta&ctol/fexpp&fexps','ORCA Run Number'});
if stat<0, error(['Error opening output HDF file for set 4.']); end
[stat]=hdfsd_write(SDw,4,[],geo_top);
