function [A,urlList] = GetWebData(Name)
% Name is a string that names a valid web
% A is the adjacency matrix associate with the web. This means
% that
% 1 if there is a link from page j to page i
% A(i,j) =
% 0 if there is NOT a link from page j to page i
%
% A is represented as a sparse matrix
%
% urlList is a n-by-1 cell array where urlList(i) is the url
% of the ith webpage in the web
%
% The format of the data files used is described in
% ..\322\Data\LinkStructure\ReadMe.txt

% Obtain the adjacency data associated the web
f1 = [Name '_adj_list'];
fid = fopen(f1);
if fid == -1
disp('No data on the web with the name supplied')
A = [];
urlList = [];
return
end

% Read the adjacency information line-by-line
F = cell(1);
line=0;
while(~feof(fid))
line=line+1;
F{line} = fgetl(fid);
end
n = length(F);
% n = the number of pages in the web
% = the dimension of the matrix A

% Set up A. This means producing a pair of vector ivec and jvec
% that specify where the 1's are.
ivec=[];
jvec=[];
for j=1:n
% Where are the blanks in the jth line?
k = find(F{j}==' ');
for m=1:length(k)-1
% Grab the mth outlink index
ivec = [ivec;str2num(F{j}(k(m)+1:k(m+1)-1))+1];
jvec = [jvec;j];
end
end
A = sparse(ivec,jvec,ones(length(ivec),1),n,n);
fclose(fid);

% Get the urls associated the web pages
f2 = [Name '_nodes'];
fid = fopen(f2);
urlList = cell(n,1);
i=0;
while(~feof(fid))
str = fgetl(fid);
if length(str)>=4 & all(str(1:4)=='http')
i=i+1;
urlList{i} = str;
end
end
fclose(fid);