~logan/ubuntu/trusty/suitesparse/4.2.1-3ubuntu1

« back to all changes in this revision

Viewing changes to CXSparse/MATLAB/UFget/UFget.m

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function Problem = UFget (matrix, UF_Index)
 
2
%UFGET loads a matrix from the UF Sparse Matrix Collection.
 
3
%
 
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.
 
12
%
 
13
%   Examples:
 
14
%       index = UFget ;
 
15
%       Problem = UFget (6)
 
16
%       Problem = UFget ('HB/arc130')
 
17
%       Problem = UFget (6, index)
 
18
%       Problem = UFget ('HB/arc130', index)
 
19
%
 
20
%   See also UFgrep, UFweb, UFget_example, UFget_defaults, urlwrite.
 
21
 
 
22
%   Copyright 2007, Tim Davis, University of Florida.
 
23
 
 
24
%-------------------------------------------------------------------------------
 
25
% get the parameter settings
 
26
%-------------------------------------------------------------------------------
 
27
 
 
28
params = UFget_defaults ;
 
29
indexfile = sprintf ('%sUF_Index.mat', params.dir) ;
 
30
indexurl = sprintf ('%s/UF_Index.mat', params.url) ;
 
31
 
 
32
%-------------------------------------------------------------------------------
 
33
% get the index file (download a new one if necessary)
 
34
%-------------------------------------------------------------------------------
 
35
 
 
36
try
 
37
    % load the existing index file
 
38
    if (nargin < 2)
 
39
        load (indexfile) ;
 
40
    end
 
41
    % see if the index file is old; if so, download a fresh copy
 
42
    refresh = (UF_Index.DownloadTimeStamp + params.refresh < now) ;
 
43
catch
 
44
    % oops, no index file.  download it.
 
45
    refresh = 1 ;
 
46
end
 
47
 
 
48
if (refresh)
 
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) ;
 
53
    load (indexfile) ;
 
54
    UF_Index.DownloadTimeStamp = now ;
 
55
    save (indexfile, 'UF_Index') ;
 
56
end
 
57
 
 
58
%-------------------------------------------------------------------------------
 
59
% return the index file if requested
 
60
%-------------------------------------------------------------------------------
 
61
 
 
62
% if the user passed in a zero or no argument at all, return the index file
 
63
if nargin == 0
 
64
    matrix = 0 ;
 
65
end
 
66
 
 
67
if (matrix == 0)
 
68
    if (nargout == 0)
 
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) ;
 
79
        for j = 1:nmat
 
80
            if (mod (j, 25) == 1)
 
81
                fprintf ('\n') ;
 
82
                fprintf ('ID   Group/Name                nrows-by-  ncols  nonzeros  (p,n)sym  type\n') ;
 
83
            end
 
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) ;
 
89
            if (psym < 0)
 
90
                fprintf ('  -  ') ;
 
91
            else
 
92
                fprintf (' %4.2f', psym) ;
 
93
            end
 
94
            if (nsym < 0)
 
95
                fprintf ('  -  ') ;
 
96
            else
 
97
                fprintf (' %4.2f', nsym) ;
 
98
            end
 
99
            if (UF_Index.isBinary (j))
 
100
                fprintf (' binary\n') ;
 
101
            elseif (~UF_Index.isReal (j))
 
102
                fprintf (' complex\n') ;
 
103
            else
 
104
                fprintf (' real\n') ;
 
105
            end
 
106
        end
 
107
    else
 
108
        Problem = UF_Index ;
 
109
    end
 
110
    return ;
 
111
end
 
112
 
 
113
%-------------------------------------------------------------------------------
 
114
% determine if the matrix parameter is a matrix index or name
 
115
%-------------------------------------------------------------------------------
 
116
 
 
117
[group matrix id] = UFget_lookup (matrix, UF_Index) ;
 
118
 
 
119
if (id == 0)
 
120
    error ('invalid matrix') ;
 
121
end
 
122
 
 
123
%-------------------------------------------------------------------------------
 
124
% download the matrix (if needed) and load it into MATLAB
 
125
 
 
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) ;
 
129
 
 
130
if (~exist (matdir, 'dir'))
 
131
    mkdir (matdir) ;
 
132
end
 
133
 
 
134
if (exist (matfile, 'file'))
 
135
    load (matfile)
 
136
else
 
137
    fprintf ('downloading %s\n', maturl) ;
 
138
    fprintf ('to %s\n', matfile) ;
 
139
    urlwrite (maturl, matfile) ;
 
140
    load (matfile)
 
141
    save (matfile, 'Problem') ;
 
142
end