File: | gromacs/linearalgebra/mtxio.c |
Location: | line 178, column 5 |
Description: | Value stored to 'xd' is never read |
1 | /* |
2 | * This file is part of the GROMACS molecular simulation package. |
3 | * |
4 | * Copyright (c) 1991-2000, University of Groningen, The Netherlands. |
5 | * Copyright (c) 2001-2004, The GROMACS development team. |
6 | * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by |
7 | * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, |
8 | * and including many others, as listed in the AUTHORS file in the |
9 | * top-level source directory and at http://www.gromacs.org. |
10 | * |
11 | * GROMACS is free software; you can redistribute it and/or |
12 | * modify it under the terms of the GNU Lesser General Public License |
13 | * as published by the Free Software Foundation; either version 2.1 |
14 | * of the License, or (at your option) any later version. |
15 | * |
16 | * GROMACS is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | * Lesser General Public License for more details. |
20 | * |
21 | * You should have received a copy of the GNU Lesser General Public |
22 | * License along with GROMACS; if not, see |
23 | * http://www.gnu.org/licenses, or write to the Free Software Foundation, |
24 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
25 | * |
26 | * If you want to redistribute modifications to GROMACS, please |
27 | * consider that scientific software is very special. Version |
28 | * control is crucial - bugs must be traceable. We will be happy to |
29 | * consider code for inclusion in the official distribution, but |
30 | * derived work must not be called official GROMACS. Details are found |
31 | * in the README & COPYING files - if they are missing, get the |
32 | * official version at http://www.gromacs.org. |
33 | * |
34 | * To help us fund GROMACS development, we humbly ask that you cite |
35 | * the research papers on the package. Check out http://www.gromacs.org. |
36 | */ |
37 | #include "mtxio.h" |
38 | |
39 | #ifdef HAVE_CONFIG_H1 |
40 | #include <config.h> |
41 | #endif |
42 | |
43 | /* This module provides routines to read/write sparse or full storage |
44 | * matrices from/to files. It is normally used for the Hessian matrix |
45 | * in normal mode analysis. |
46 | */ |
47 | |
48 | #include "gromacs/legacyheaders/copyrite.h" |
49 | #include "gromacs/fileio/gmxfio.h" |
50 | #include "gromacs/fileio/xdrf.h" |
51 | #include "gromacs/linearalgebra/sparsematrix.h" |
52 | #include "gromacs/utility/fatalerror.h" |
53 | #include "gromacs/utility/smalloc.h" |
54 | |
55 | /* Just a number to identify our file type */ |
56 | #define GMX_MTXIO_MAGIC_NUMBER0x34ce8fd2 0x34ce8fd2 |
57 | |
58 | #define GMX_MTXIO_FULL_MATRIX0 0 |
59 | #define GMX_MTXIO_SPARSE_MATRIX1 1 |
60 | |
61 | |
62 | |
63 | /* Matrix file format definition: |
64 | * |
65 | * All entries are stored in XDR format. |
66 | * |
67 | * 1. Magic number integer, should be GMX_MTXIO_MAGIC_NUMBER |
68 | * 2. An XDR string specifying the Gromacs version used to generate the file. |
69 | * 3. Integer to denote precision. 1 if double, 0 if single precision. |
70 | * 4. Two integers specifying number of rows and columns. |
71 | * 5. Integer to denote storage type: |
72 | * GMX_MTXIO_FULL_MATRIX or GMX_MTXIO_SPARSE_MATRIX |
73 | * |
74 | * 6. Matrix data. |
75 | * a) In case of full matrix, this is nrow*ncol floating-point values. |
76 | * b) In case of sparse matrix the data is: |
77 | * - Integer specifying compressed_symmetric format (1=yes, 0=no) |
78 | * - Integer specifying number of rows (again) |
79 | * - nrow integers specifying the number of data entries on each row ("ndata") |
80 | * - All the actual entries for each row, stored contiguous. |
81 | * Each entry consists of an integer column index and floating-point data value. |
82 | */ |
83 | |
84 | void gmx_mtxio_write(const char * filename, |
85 | int nrow, |
86 | int ncol, |
87 | real * full_matrix, |
88 | gmx_sparsematrix_t * sparse_matrix) |
89 | { |
90 | t_fileio *fio; |
91 | XDR * xd; |
92 | int i, j, prec; |
93 | gmx_bool bDum = TRUE1; |
94 | gmx_bool bRead = FALSE0; |
95 | size_t sz; |
96 | |
97 | if (full_matrix != NULL((void*)0) && sparse_matrix != NULL((void*)0)) |
98 | { |
99 | gmx_fatal(FARGS0, "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 99, "Both full AND sparse matrix specified to gmx_mtxio_write().\n"); |
100 | } |
101 | |
102 | fio = gmx_fio_open(filename, "w"); |
103 | gmx_fio_checktype(fio); |
104 | xd = gmx_fio_getxdr(fio); |
105 | |
106 | /* Write magic number */ |
107 | i = GMX_MTXIO_MAGIC_NUMBER0x34ce8fd2; |
108 | gmx_fio_do_int(fio, i)gmx_fio_doe_int(fio, &i, ("i"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 108); |
109 | |
110 | /* Write generating Gromacs version */ |
111 | gmx_fio_write_string(fio, GromacsVersion())gmx_fio_writee_string(fio, GromacsVersion(), ("GromacsVersion()" ), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 111); |
112 | |
113 | /* Write 1 for double, 0 for single precision */ |
114 | if (sizeof(real) == sizeof(double)) |
115 | { |
116 | prec = 1; |
117 | } |
118 | else |
119 | { |
120 | prec = 0; |
121 | } |
122 | gmx_fio_do_int(fio, prec)gmx_fio_doe_int(fio, &prec, ("prec"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 122); |
123 | |
124 | gmx_fio_do_int(fio, nrow)gmx_fio_doe_int(fio, &nrow, ("nrow"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 124); |
125 | gmx_fio_do_int(fio, ncol)gmx_fio_doe_int(fio, &ncol, ("ncol"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 125); |
126 | |
127 | if (full_matrix != NULL((void*)0)) |
128 | { |
129 | /* Full matrix storage format */ |
130 | i = GMX_MTXIO_FULL_MATRIX0; |
131 | gmx_fio_do_int(fio, i)gmx_fio_doe_int(fio, &i, ("i"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 131); |
132 | sz = nrow*ncol; |
133 | bDum = gmx_fio_ndo_real(fio, full_matrix, sz)gmx_fio_ndoe_real(fio, full_matrix, sz, ("full_matrix"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 133); |
134 | } |
135 | else |
136 | { |
137 | /* Sparse storage */ |
138 | i = GMX_MTXIO_SPARSE_MATRIX1; |
139 | gmx_fio_do_int(fio, i)gmx_fio_doe_int(fio, &i, ("i"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 139); |
140 | |
141 | gmx_fio_do_gmx_bool(fio, sparse_matrix->compressed_symmetric)gmx_fio_doe_gmx_bool(fio, &sparse_matrix->compressed_symmetric , ("sparse_matrix->compressed_symmetric"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 141); |
142 | gmx_fio_do_int(fio, sparse_matrix->nrow)gmx_fio_doe_int(fio, &sparse_matrix->nrow, ("sparse_matrix->nrow" ), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 142); |
143 | if (sparse_matrix->nrow != nrow) |
144 | { |
145 | gmx_fatal(FARGS0, "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 145, "Internal inconsistency in sparse matrix.\n"); |
146 | } |
147 | bDum = gmx_fio_ndo_int(fio, sparse_matrix->ndata, sparse_matrix->nrow)gmx_fio_ndoe_int(fio, sparse_matrix->ndata, sparse_matrix-> nrow, ("sparse_matrix->ndata"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 147); |
148 | for (i = 0; i < sparse_matrix->nrow; i++) |
149 | { |
150 | for (j = 0; j < sparse_matrix->ndata[i]; j++) |
151 | { |
152 | gmx_fio_do_int(fio, sparse_matrix->data[i][j].col)gmx_fio_doe_int(fio, &sparse_matrix->data[i][j].col, ( "sparse_matrix->data[i][j].col"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 152); |
153 | gmx_fio_do_real(fio, sparse_matrix->data[i][j].value)gmx_fio_doe_real(fio, &sparse_matrix->data[i][j].value , ("sparse_matrix->data[i][j].value"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 153); |
154 | } |
155 | } |
156 | } |
157 | gmx_fio_close(fio); |
158 | } |
159 | |
160 | |
161 | void |
162 | gmx_mtxio_read (const char * filename, |
163 | int * nrow, |
164 | int * ncol, |
165 | real ** full_matrix, |
166 | gmx_sparsematrix_t ** sparse_matrix) |
167 | { |
168 | t_fileio *fio; |
169 | XDR * xd; |
170 | int i, j, prec; |
171 | gmx_bool bDum = TRUE1; |
172 | gmx_bool bRead = TRUE1; |
173 | char gmxver[256]; |
174 | size_t sz; |
175 | |
176 | fio = gmx_fio_open(filename, "r"); |
177 | gmx_fio_checktype(fio); |
178 | xd = gmx_fio_getxdr(fio); |
Value stored to 'xd' is never read | |
179 | |
180 | /* Read and check magic number */ |
181 | i = GMX_MTXIO_MAGIC_NUMBER0x34ce8fd2; |
182 | gmx_fio_do_int(fio, i)gmx_fio_doe_int(fio, &i, ("i"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 182); |
183 | |
184 | if (i != GMX_MTXIO_MAGIC_NUMBER0x34ce8fd2) |
185 | { |
186 | gmx_fatal(FARGS0, "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 186, |
187 | "No matrix data found in file. Note that the Hessian matrix format changed\n" |
188 | "in Gromacs 3.3 to enable portable files and sparse matrix storage.\n"); |
189 | } |
190 | |
191 | /* Read generating Gromacs version */ |
192 | gmx_fio_do_string(fio, gmxver)gmx_fio_doe_string(fio, gmxver, ("gmxver"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 192); |
193 | |
194 | /* Write 1 for double, 0 for single precision */ |
195 | if (sizeof(real) == sizeof(double)) |
196 | { |
197 | prec = 1; |
198 | } |
199 | else |
200 | { |
201 | prec = 0; |
202 | } |
203 | gmx_fio_do_int(fio, prec)gmx_fio_doe_int(fio, &prec, ("prec"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 203); |
204 | |
205 | fprintf(stderrstderr, "Reading %s precision matrix generated by Gromacs %s\n", |
206 | (prec == 1) ? "double" : "single", gmxver); |
207 | |
208 | gmx_fio_do_int(fio, i)gmx_fio_doe_int(fio, &i, ("i"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 208); |
209 | *nrow = i; |
210 | gmx_fio_do_int(fio, i)gmx_fio_doe_int(fio, &i, ("i"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 210); |
211 | *ncol = i; |
212 | |
213 | gmx_fio_do_int(fio, i)gmx_fio_doe_int(fio, &i, ("i"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 213); |
214 | |
215 | if (i == GMX_MTXIO_FULL_MATRIX0 && NULL((void*)0) != full_matrix) |
216 | { |
217 | printf("Full matrix storage format, nrow=%d, ncols=%d\n", *nrow, *ncol); |
218 | |
219 | sz = (*nrow) * (*ncol); |
220 | snew((*full_matrix), sz)((*full_matrix)) = save_calloc("(*full_matrix)", "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 220, (sz), sizeof(*((*full_matrix)))); |
221 | bDum = gmx_fio_ndo_real(fio, (*full_matrix), sz)gmx_fio_ndoe_real(fio, (*full_matrix), sz, ("(*full_matrix)") , "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 221); |
222 | } |
223 | else if (NULL((void*)0) != sparse_matrix) |
224 | { |
225 | /* Sparse storage */ |
226 | printf("Sparse matrix storage format, nrow=%d, ncols=%d\n", *nrow, *ncol); |
227 | |
228 | snew((*sparse_matrix), 1)((*sparse_matrix)) = save_calloc("(*sparse_matrix)", "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 228, (1), sizeof(*((*sparse_matrix)))); |
229 | gmx_fio_do_gmx_bool(fio, (*sparse_matrix)->compressed_symmetric)gmx_fio_doe_gmx_bool(fio, &(*sparse_matrix)->compressed_symmetric , ("(*sparse_matrix)->compressed_symmetric"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 229); |
230 | gmx_fio_do_int(fio, (*sparse_matrix)->nrow)gmx_fio_doe_int(fio, &(*sparse_matrix)->nrow, ("(*sparse_matrix)->nrow" ), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 230); |
231 | if ((*sparse_matrix)->nrow != *nrow) |
232 | { |
233 | gmx_fatal(FARGS0, "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 233, "Internal inconsistency in sparse matrix.\n"); |
234 | } |
235 | snew((*sparse_matrix)->ndata, (*sparse_matrix)->nrow)((*sparse_matrix)->ndata) = save_calloc("(*sparse_matrix)->ndata" , "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 235, ((*sparse_matrix)->nrow), sizeof(*((*sparse_matrix) ->ndata))); |
236 | snew((*sparse_matrix)->nalloc, (*sparse_matrix)->nrow)((*sparse_matrix)->nalloc) = save_calloc("(*sparse_matrix)->nalloc" , "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 236, ((*sparse_matrix)->nrow), sizeof(*((*sparse_matrix) ->nalloc))); |
237 | snew((*sparse_matrix)->data, (*sparse_matrix)->nrow)((*sparse_matrix)->data) = save_calloc("(*sparse_matrix)->data" , "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 237, ((*sparse_matrix)->nrow), sizeof(*((*sparse_matrix) ->data))); |
238 | bDum = gmx_fio_ndo_int(fio, (*sparse_matrix)->ndata,gmx_fio_ndoe_int(fio, (*sparse_matrix)->ndata, (*sparse_matrix )->nrow, ("(*sparse_matrix)->ndata"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 239) |
239 | (*sparse_matrix)->nrow)gmx_fio_ndoe_int(fio, (*sparse_matrix)->ndata, (*sparse_matrix )->nrow, ("(*sparse_matrix)->ndata"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 239); |
240 | |
241 | for (i = 0; i < (*sparse_matrix)->nrow; i++) |
242 | { |
243 | (*sparse_matrix)->nalloc[i] = (*sparse_matrix)->ndata[i] + 10; |
244 | snew(((*sparse_matrix)->data[i]), (*sparse_matrix)->nalloc[i])(((*sparse_matrix)->data[i])) = save_calloc("((*sparse_matrix)->data[i])" , "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 244, ((*sparse_matrix)->nalloc[i]), sizeof(*(((*sparse_matrix )->data[i])))); |
245 | |
246 | for (j = 0; j < (*sparse_matrix)->ndata[i]; j++) |
247 | { |
248 | gmx_fio_do_int(fio, (*sparse_matrix)->data[i][j].col)gmx_fio_doe_int(fio, &(*sparse_matrix)->data[i][j].col , ("(*sparse_matrix)->data[i][j].col"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 248); |
249 | gmx_fio_do_real(fio, (*sparse_matrix)->data[i][j].value)gmx_fio_doe_real(fio, &(*sparse_matrix)->data[i][j].value , ("(*sparse_matrix)->data[i][j].value"), "/home/alexxy/Develop/gromacs/src/gromacs/linearalgebra/mtxio.c" , 249); |
250 | } |
251 | } |
252 | } |
253 | gmx_fio_close(fio); |
254 | } |