File: ssget_lookup.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, 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 (84 lines) | stat: -rw-r--r-- 2,780 bytes parent folder | download | duplicates (6)
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
function [group, name, id] = ssget_lookup (matrix, ss_index)
%SSGET_LOOKUP gets the group, name, and id of a matrix.
%   This is a helper function for ssget, sssvd, and ssweb.
%   The 'matrix' argument is a number (matrix id) or string containing
%   group/name, as in 'HB/arc130' for example.
%
%   Example:
%       [group name id] = ssget_lookup (matrix, ss_index)
%
%   See also ssget.

% ssget, Copyright (c) 2009-2022, Timothy A. Davis. All Rights Reserved.
% SPDX-License-Identifier: BSD-3-clause

if (isnumeric (matrix))

    % make sure that the matrix parameter is only one integer value
    % this means that if we get an array, just use the first value
    id = fix (full (matrix (1))) ;

    % if the index is less than one or bigger than the length of the array,
    % then no particular matrix is accessed
    if (id > length (ss_index.nrows) | id < 1)                              %#ok
        id = 0 ;
        group = '' ;
        name = '' ;
    else
        % assign the group and name for the given id
        group = ss_index.Group {matrix} ;
        name = ss_index.Name {matrix} ;
    end

elseif (ischar (matrix))

    % the group and matrix name are in the string as in GroupName/MatrixName

    % find the group index for the file separator
    % check both types of slashes, and a colon
    gi = find (matrix == '/') ;
    if (length (gi) == 0)                                                   %#ok
        gi = find (matrix == '\') ;
    end
    if (length (gi) == 0)                                                   %#ok
        gi = find (matrix == ':') ;
    end

    % if no name divider is in the string, a whole group is specified
    if (length (gi) == 0)                                                   %#ok

        id = 0 ;
        group = matrix ;
        name = '' ;

    else

        % group equals the first part of the string up to the character before
        % the last file separator
        group = matrix (1:gi(end)-1) ;

        % group equals the last section of the string after the last file
        % separator
        name = matrix (gi(end)+1:end) ;

        % validate the given name and group by checking the index for a match
        % refName = strmatch (name, ss_index.Name) ;
        % refGroup = strmatch (group, ss_index.Group) ;
        % id = intersect (refName, refGroup) ;
        refName  = strcmp (name,  ss_index.Name) ;
        refGroup = strcmp (group, ss_index.Group) ;
        id = find (refName & refGroup) ;
        if (length (id) >= 1)
            id = id (1) ;
        else
            % the given group/matrix does not exist in the index file
            id = 0 ;
        end
    end

else

    % there is an error in the argument types passed into the function
    error ('invalid input') ;

end