File: ssexport.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (105 lines) | stat: -rw-r--r-- 3,305 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function ssexport (list, check, tmp)
%SSEXPORT export to Matrix Market and Rutherford/Boeing formats
%
% Example:
%   ssexport ;          % export the entire collection
%   ssexport (list) ;   % just export matrices whose id's are given in the list
%   ssexport (list, 'check') ;      % also read them back in, to check
%
% If the list is empty, all matrices in the collection are exported.
% A 3rd argument tmp changes the tmp directory for ssread.
%
% See also ssget, sswrite, RBio, mwrite.

% SuiteSparseCollection, Copyright (c) 2006-2019, Timothy A Davis.
% All Rights Reserved.
% SPDX-License-Identifier: GPL-2.0+

%-------------------------------------------------------------------------------
% get the input arguments
%-------------------------------------------------------------------------------

index = ssget ;
nmat = length (index.nrows) ;

if (nargin < 1 || isempty (list))
    list = 1:nmat ;
end

check = ((nargin > 1) && strcmp (check, 'check')) ;

if (nargin < 3)
    tmp = '' ;
end

%-------------------------------------------------------------------------------
% determine the top-level directory to use
%-------------------------------------------------------------------------------

topdir = sslocation ;
fprintf ('\nExport to topdir: %s\ncheck: %d\ntmp: %s\n', topdir, check, tmp) ;
for id = list
    fprintf ('%4d : %s/%s\n', id, index.Group {id}, index.Name {id}) ;
end

%-------------------------------------------------------------------------------
% export the matrices
%-------------------------------------------------------------------------------

format = { 'MM' , 'RB' } ;

for id = list

    % get the MATLAB version
    clear Problem
    Problem = ssget (id, index) ;
    disp (Problem) ;
    if (isfield (Problem, 'aux'))
        disp (Problem.aux) ;
    end

    % create the MM and RB versions
    for k = 1:2
        fprintf ('Exporting to %s format ...\n', format {k}) ;
        if (nnz (Problem.A) < 1e8)
            sswrite (Problem, [topdir format{k}], format{k}, 'tar') ;
        else
            % the MATLAB tar has problems with huge files
            fprintf ('File to big for MATLAB tar\n') ;
            sswrite (Problem, [topdir format{k}], format{k}) ;
        end
    end

    % check the new MM and RB versions
    if (check)
        for k = 1:2
            fprintf ('Reading %s format ...\n', format {k}) ;
	    try
		if (isempty (tmp))
		    P2 = ssread ([topdir format{k} '/' Problem.name]) ;
		else
		    P2 = ssread ([topdir format{k} '/' Problem.name], tmp) ;
		end
	    catch
		% The Problem may be too large for two copies to be in the
		% MATLAB workspace at the same time.  This is not an error,
		% but it means that the Problem cannot be checked.
		P2 = [ ] ;
		fprintf ('Unable to read %s/%s\n', format {k}, Problem.name) ;
		fprintf ('%s\n', lasterr) ;
	    end
            fprintf ('Comparing MATLAB and %s format ...\n', format {k}) ;
	    if (~isempty (P2) && ~isequal (Problem, P2))
                Problem
                P2
		warning ('%s version mismatch: %s\n', format {k}, Problem.name);
                e = norm (Problem.A - P2.A, 1) ;
                a = norm (Problem.A,1) ;
                fprintf ('norm (A1-A2,1): %g  relative: %g\n', e, e/a) ;
	    end
	    clear P2
	end
        fprintf ('OK.\n') ;
    end
end