function [tmplat, tmplon] = wvstest(rindex, bindex, lat, lon)
%
% This is part of WVS file, builds proper lat/lon with NaNs in between
%

% The preceding empty line is important
% $Log: wvstest.m,v $
% Revision 1.1  1999/11/29 17:28:24  kwoklin
% Adding World Vector Shoreline as a data set.  klee
%

% $Id: wvstest.m,v 1.1 1999/11/29 17:28:24 kwoklin Exp $
% klee 11/26/99

start = bindex(1);
tmplat = -9999;
tmplon = -9999;
% initial is the starting index, final is the last one
initial = rindex(1);
final = rindex(length(rindex));
% tmpb is the -9999 (nan) index within the initial and final
tmpb = find(bindex >= initial & bindex <= final);
% if starts from lat(1), k == 2, else, k == 1
if tmpb(1) == initial, k = 2; else, k = 1; end

for i = k:length(tmpb)
  if i == 1 
    % not starting from lat(1), get the first few lat/lon before 
    % the first nan
    c = find(rindex < bindex(tmpb(i)));
  else
    c = find(rindex > initial & rindex < bindex(tmpb(i)));
  end
  if ~isempty(c)
    tmplat = [tmplat; lat(c); -9999];
    tmplon = [tmplon; lon(c); -9999];
  end
  % reset initial
  initial = bindex(tmpb(i));
end

tmpb = find(tmplat == -9999);
tmplat(tmpb) = nan*ones(size(tmpb));
tmplon(tmpb) = nan*ones(size(tmpb));