function OUT = vdm_bounds_test(varsfile, ncfile)

%% Read the vars data file.
% This assumes that only the default fields are outputed.

[associations, conceptNames, depths, imageUrls, latitudes, longitudes, ...
    observationIds, recordedDates, timecodes, videoArchiveNames] = textread( ...
    varsfile, '%s%s%s%s%s%s%s%s%s%s', ...
    'headerlines', 10, 'delimiter', '\t');

depths = str2double(depths);
latitudes = str2double(latitudes);
longitudes = str2double(longitudes);
%observationIds = str2double(observationIds);
%recordedDates = datestr(recordedDates, 31);

%% Read the netcdf file
lat = nc_varget(ncfile, 'latitude');
lon = nc_varget(ncfile, 'longitude');

%% Check that the data point is within the bounds of the ncfile
altitudes = ones(size(depths)) * NaN;
ok = zeros(size(depths));
lat = sort(lat);
lon = sort(lon);
for i = 1:length(depths)
    ok(i) = (latitudes(i) >= lat(1)) & (latitudes(i) <= lat(end)) & ...
        (longitudes(i) >= lon(1)) & (longitudes(i) <= lon(end)) & ~isnan(depths(i));
    if ok(i)
        iy = near(lat, latitudes(i));
        ix = near(lon, longitudes(i));

        nix = ix - 1; % NEtcdf are 0 based indices
        niy = iy - 1; % NEtcdf are 0 based indices
        z = nc_varget(ncfile, 'elevation', [niy nix] , [1 1]);
        altitudes(i) = -z - depths(i);
    end
end

fprintf(1, 'Found %f annotations within the maps bounds\n', size(find(ok ~= 0)));

OUT.associations = associations;
OUT.conceptNames = conceptNames;
OUT.depths = depths;
OUT.imageUrls = imageUrls;
OUT.latitudes = latitudes;
OUT.longitudes = longitudes;
OUT.observationIds = observationIds;
OUT.recordedDates = recordedDates;
OUT.timecodes = timecodes;
OUT.videoArchiveNames = videoArchiveNames;
OUT.inBounds = ok;
OUT.altitudes = altitudes;
