MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / mm_read_banner

Function mm_read_banner

test/mmio/mmio.c:87–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87int mm_read_banner(FILE *f, MM_typecode *matcode) {
88 char line[MM_MAX_LINE_LENGTH];
89 char banner[MM_MAX_TOKEN_LENGTH];
90 char mtx[MM_MAX_TOKEN_LENGTH];
91 char crd[MM_MAX_TOKEN_LENGTH];
92 char data_type[MM_MAX_TOKEN_LENGTH];
93 char storage_scheme[MM_MAX_TOKEN_LENGTH];
94 char *p;
95
96 mm_clear_typecode(matcode);
97
98 if (fgets(line, MM_MAX_LINE_LENGTH, f) == NULL) return MM_PREMATURE_EOF;
99
100 if (sscanf(line, "%s %s %s %s %s", banner, mtx, crd, data_type,
101 storage_scheme) != 5)
102 return MM_PREMATURE_EOF;
103
104 for (p = mtx; *p != '\0'; *p = tolower(*p), p++)
105 ; /* convert to lower case */
106 for (p = crd; *p != '\0'; *p = tolower(*p), p++)
107 ;
108 for (p = data_type; *p != '\0'; *p = tolower(*p), p++)
109 ;
110 for (p = storage_scheme; *p != '\0'; *p = tolower(*p), p++)
111 ;
112
113 /* check for banner */
114 if (strncmp(banner, MatrixMarketBanner, strlen(MatrixMarketBanner)) != 0)
115 return MM_NO_HEADER;
116
117 /* first field should be "mtx" */
118 if (strcmp(mtx, MM_MTX_STR) != 0) return MM_UNSUPPORTED_TYPE;
119 mm_set_matrix(matcode);
120
121 /* second field describes whether this is a sparse matrix (in coordinate
122 storgae) or a dense array */
123
124 if (strcmp(crd, MM_SPARSE_STR) == 0)
125 mm_set_sparse(matcode);
126 else if (strcmp(crd, MM_DENSE_STR) == 0)
127 mm_set_dense(matcode);
128 else
129 return MM_UNSUPPORTED_TYPE;
130
131 /* third field */
132
133 if (strcmp(data_type, MM_REAL_STR) == 0)
134 mm_set_real(matcode);
135 else if (strcmp(data_type, MM_COMPLEX_STR) == 0)
136 mm_set_complex(matcode);
137 else if (strcmp(data_type, MM_PATTERN_STR) == 0)
138 mm_set_pattern(matcode);
139 else if (strcmp(data_type, MM_INT_STR) == 0)
140 mm_set_integer(matcode);
141 else
142 return MM_UNSUPPORTED_TYPE;
143
144 /* fourth field */

Callers 3

mtxReadSparseMatrixFunction · 0.85
mm_read_mtx_crdFunction · 0.85

Calls

no outgoing calls

Tested by 1

mtxReadSparseMatrixFunction · 0.68