1
function Problem = UFget (matrix, UF_Index)
2
%UFGET loads a matrix from the UF Sparse Matrix Collection.
4
% Problem = UFget(matrix) loads a matrix from the UF sparse matrix collection,
5
% specified as either a number (1 to the # of matrices in the collection) or
6
% as a string (the name of the matrix). With no input parameters, index=UFget
7
% returns an index of matrices in the collection. A local copy of the matrix
8
% is saved (be aware that as of May 2007 the entire collection is over 8GB
9
% in size). If no input or output arguments are provided, the index is
10
% printed. With a 2nd parameter (Problem = UFget (matrix, index)), the index
11
% file is not loaded. This is faster if you are loading lots of matrices.
16
% Problem = UFget ('HB/arc130')
17
% Problem = UFget (6, index)
18
% Problem = UFget ('HB/arc130', index)
20
% See also UFgrep, UFweb, UFget_example, UFget_defaults, urlwrite.
22
% Copyright 2007, Tim Davis, University of Florida.
24
%-------------------------------------------------------------------------------
25
% get the parameter settings
26
%-------------------------------------------------------------------------------
28
params = UFget_defaults ;
29
indexfile = sprintf ('%sUF_Index.mat', params.dir) ;
30
indexurl = sprintf ('%s/UF_Index.mat', params.url) ;
32
%-------------------------------------------------------------------------------
33
% get the index file (download a new one if necessary)
34
%-------------------------------------------------------------------------------
37
% load the existing index file
41
% see if the index file is old; if so, download a fresh copy
42
refresh = (UF_Index.DownloadTimeStamp + params.refresh < now) ;
44
% oops, no index file. download it.
49
% a new UF_Index.mat file to get access to new matrices (if any)
50
fprintf ('downloading %s\n', indexurl) ;
51
fprintf ('to %s\n', indexfile) ;
52
urlwrite (indexurl, indexfile) ;
54
UF_Index.DownloadTimeStamp = now ;
55
save (indexfile, 'UF_Index') ;
58
%-------------------------------------------------------------------------------
59
% return the index file if requested
60
%-------------------------------------------------------------------------------
62
% if the user passed in a zero or no argument at all, return the index file
69
% no output arguments have been passed, so print the index file
70
fprintf ('\nUF sparse matrix collection index: %s\n', ...
71
UF_Index.LastRevisionDate) ;
72
fprintf ('\nLegend:\n') ;
73
fprintf ('(p,n)sym: symmetry of the pattern and values\n') ;
74
fprintf (' (0 = unsymmetric, 1 = symmetric, - = not computed)\n') ;
75
fprintf ('type: real\n') ;
76
fprintf (' complex\n') ;
77
fprintf (' binary: all entries are 0 or 1\n') ;
78
nmat = length (UF_Index.nrows) ;
82
fprintf ('ID Group/Name nrows-by- ncols nonzeros (p,n)sym type\n') ;
84
s = sprintf ('%s/%s', UF_Index.Group {j}, UF_Index.Name {j}) ;
85
fprintf ('%4d %-30s %7d-by-%7d %9d ', ...
86
j, s, UF_Index.nrows (j), UF_Index.ncols (j), UF_Index.nnz (j)) ;
87
psym = UF_Index.pattern_symmetry (j) ;
88
nsym = UF_Index.numerical_symmetry (j) ;
92
fprintf (' %4.2f', psym) ;
97
fprintf (' %4.2f', nsym) ;
99
if (UF_Index.isBinary (j))
100
fprintf (' binary\n') ;
101
elseif (~UF_Index.isReal (j))
102
fprintf (' complex\n') ;
104
fprintf (' real\n') ;
113
%-------------------------------------------------------------------------------
114
% determine if the matrix parameter is a matrix index or name
115
%-------------------------------------------------------------------------------
117
[group matrix id] = UFget_lookup (matrix, UF_Index) ;
120
error ('invalid matrix') ;
123
%-------------------------------------------------------------------------------
124
% download the matrix (if needed) and load it into MATLAB
126
matdir = sprintf ('%s%s%s%s.mat', params.dir, group) ;
127
matfile = sprintf ('%s%s%s.mat', matdir, filesep, matrix) ;
128
maturl = sprintf ('%s/%s/%s.mat', params.url, group, matrix) ;
130
if (~exist (matdir, 'dir'))
134
if (exist (matfile, 'file'))
137
fprintf ('downloading %s\n', maturl) ;
138
fprintf ('to %s\n', matfile) ;
139
urlwrite (maturl, matfile) ;
141
save (matfile, 'Problem') ;