function varargout = drawBoundaries(areaName)
% function [rloc] = drawBoundaries(areaName)
% 
% draw basemap for NADCON5 regions of analysis:
%   CONUS             contiguous US
%   Alaska            all islands which are not mainland
%   PRVI              Puerto Rico and Virgin Islands
%   Hawaii            all Hawaiian islands
%   AS                American Samoa
%   GuamCNMI          Guam and Commonwealth of the Northern
%                         Mariana Islands
% 
% call this function to create basemap, before overlay vectors

NADCONpath; % load 'boundaries' and 'borders' toolboxes and files

% defaults
areaList = {};
basemapName = [];

% load list of filesnames
switch lower(areaName)
    case 'conus'
        basemapName = 'continental us';
        rloc = [-118+360 30];
    case 'alaska'
        basemapName = 'alaska';
        %areaList = {'AK'}; % seemingly duplicated by 'borders'
    case 'prvi'
        areaList = {'PR' 'VQ'};
    case 'hawaii'
        areaList = {'HI'};
    case 'as'
        areaList = {'AS'};
    case 'guamcnmi'
        areaList = {'GQ' 'CQ'};
    case 'stlawrence'
        areaList = {'AK'};
    otherwise
        error('areaName not recognized')
end

% draw state boundaries
if ~isempty(basemapName)
    borders(basemapName,'k');
end

hold on; % hold figure

% supplement with GMT files, if needed for area
bb = strrep(userpath,';','\');
str = sprintf('%s//boundaries/',bb);
for k = 1:length(areaList)
    % get list of files for each area
    ff = dir(sprintf('%s%s*.gmt',str,areaList{k}));
    for i = 1:length(ff)
        % load and plot file
        x{i} = load([str ff(i).name]);
        plot(x{i}(:,1)-360, x{i}(:,2),'k'); hold on
    end
end

% if requested and variable exists, send "rloc" as good location
% for reference vector in this region
if nargout==1
    if exist('rloc')
        varargout{1} = rloc;
    else
        varargout{1} = []; % send empty if rloc not specified 
                    % for this region
    end
end

return

function d = listFiles(prefix)
  for i = 1:length(prefix)
      d{i} = ff.name;
  end
return