function [lon,lat,topo,status] = get_topo_doit (file,lonlim,latlim);
%
% function [lon,lat,topo,status] = get_topo_doit (file,lonlim,latlim);
%
% This function reads in topography in the given range from a netCDF topography
% file.  If the requested range contains the topography file plus some, as
% much topography as possible is extracted.
%
% ------
% Input:
% ------
%
%    file.....Name of netCDF topography file.
%    lonlim...Longitude range to extract.
%    latlim...Latitude range to extract.
%
% -------
% Output:
% -------
%
%    lon......Extracted longitudes.
%    lat......Extracted latitudes.
%    topo.....Extracted topography.
%    status...Exit status.  [<0] Error  [other] no error.
%

%-------------------------------------------------------------------------------
% Initialize netCDF parameters and output variables.
%-------------------------------------------------------------------------------

status = mexcdf ('setopts',0);
nc_nowrite = mexcdf ('parameter','nc_nowrite');
topo = [];

%-------------------------------------------------------------------------------
% Open netCDF file.
%-------------------------------------------------------------------------------

ncid = mexcdf ('ncopen',file,nc_nowrite);
if (ncid < 0),
   disp([setstr(7),'***Error:  GET_TOPO - unable to open file:', ...
                                                         setstr(7)]);
   disp([setstr(7),'           ',setstr(34),file,setstr(34),setstr(7)]);
   status = ncid;
   return
end;

%-------------------------------------------------------------------------------
% Determine position characteristics of topography.
%-------------------------------------------------------------------------------

[londat,latdat,status] = depth_init (ncid);

if (status < 0),
   disp([setstr(7),'***Error:  GET_TOPO - unable to read file:',setstr(7)]);
   disp([setstr(7),'           ',setstr(34),file,setstr(34),setstr(7)]);
   return
end;

%-------------------------------------------------------------------------------
% Extract topography at desired point.
%-------------------------------------------------------------------------------

[lon,lat,topo,status] = depth_doit (ncid,londat,latdat,lonlim,latlim);

if (status < 0),
   disp([setstr(7),'***Error:  GET_TOPO - unable to read file:',setstr(7)]);
   disp([setstr(7),'           ',setstr(34),file,setstr(34),setstr(7)]);
   return
end;

%-------------------------------------------------------------------------------
% Close netCDF file.
%-------------------------------------------------------------------------------

status = mexcdf ('ncclose',ncid);
if (status < 0),
   disp([setstr(7),'***Error:  GET_TOPO - unable to close file:', ...
                                                          setstr(7)]);
   disp([setstr(7),'           ',setstr(34),file,setstr(34),setstr(7)]);
   return
end;
