~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/math/mathMatr_io.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/math/mathMatr_io.c,v $
 37  * Date    :  $Date: 2003/09/23 11:32:20 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: mathMatr_io.c,v 1.4 2003/09/23 11:32:20 matts Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : Matrix input/output (various types and shapes)
 44  *
 45  *********
 46 */
 47 
 48 /** 
 49  *  @file
 50  *  @brief  Functions for printing Matrices (various types and shapes) to file..        
 51  * 
 52 */
 53 
 54 
 55 #include "mathMatr_io.h"
 56 
 57 #if HAVE_CONFIG_H
 58 #include <config.h>
 59 #endif
 60 
 61 #include <stdio.h>
 62 #include <tina/sys/sysDef.h>
 63 #include <tina/sys/sysGen_error.h>
 64 #include <tina/math/math_MatrDef.h>
 65 #include <tina/math/mathMatr_get.h>
 66 
 67 
 68 void            matrix_print(FILE * fp, Matrix * mat)
 69 {
 70         (void) fprintf(fp, "matrix ");
 71 
 72         if (mat == NULL)
 73         {
 74                 (void) fprintf(fp, "nil ");
 75                 return;
 76         }
 77         switch (mat->vtype)
 78         {
 79         case int_v:
 80                 imatrix_print(fp, mat);
 81                 break;
 82         case float_v:
 83                 fmatrix_print(fp, mat);
 84                 break;
 85         case double_v:
 86                 dmatrix_print(fp, mat);
 87                 break;
 88         default:
 89                 error("matrix_print: unsupported type", non_fatal);
 90                 break;
 91         }
 92 }
 93 
 94 void            imatrix_print(FILE * fp, Matrix * mat)
 95 {
 96         int             i, j;
 97         int             m = mat->m;
 98         int             n = mat->n;
 99         int           **el = mat->el.int_v;
100 
101         (void) fprintf(fp, "int ");
102         switch (mat->shape)
103         {
104         case matrix_full:
105                 (void) fprintf(fp, "full ");
106                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
107                 for (i = 0; i < m; ++i)
108                         for (j = 0; j < n; ++j)
109                                 (void) fprintf(fp, "%d ", el[i][j]);
110                 break;
111         case matrix_lower:
112                 (void) fprintf(fp, "lower ");
113                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
114                 for (i = 0; i < m; ++i)
115                         for (j = 0; j <= i; ++j)
116                                 (void) fprintf(fp, "%d ", el[i][j]);
117                 break;
118         case matrix_upper:
119                 (void) fprintf(fp, "upper ");
120                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
121                 for (i = 0; i < m; ++i)
122                         for (j = i; j < m; ++j)
123                                 (void) fprintf(fp, "%d ", el[i][j]);
124                 break;
125         case matrix_symmetric:
126                 (void) fprintf(fp, "symmetric ");
127                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
128                 for (i = 0; i < m; ++i)
129                         for (j = 0; j <= i; ++j)
130                                 (void) fprintf(fp, "%d ", el[i][j]);
131                 break;
132         default:
133                 {
134                         (void) fprintf(fp, "full ");
135                         (void) fprintf(fp, "%d %d ", mat->m, mat->n);
136                         for (i = 0; i < m; ++i)
137                                 for (j = 0; j < n; ++j)
138                                         (void) fprintf(fp, "%d ", matrix_get(mat, i, j));
139                 }
140         }
141 }
142 
143 void            fmatrix_print(FILE * fp, Matrix * mat)
144 {
145         int             i, j;
146         int             m = mat->m;
147         int             n = mat->n;
148         float         **el = mat->el.float_v;
149 
150         (void) fprintf(fp, "float ");
151         switch (mat->shape)
152         {
153         case matrix_full:
154                 (void) fprintf(fp, "full ");
155                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
156                 for (i = 0; i < m; ++i)
157                         for (j = 0; j < n; ++j)
158                                 (void) fprintf(fp, "%f ", el[i][j]);
159                 break;
160         case matrix_lower:
161                 (void) fprintf(fp, "lower ");
162                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
163                 for (i = 0; i < m; ++i)
164                         for (j = 0; j <= i; ++j)
165                                 (void) fprintf(fp, "%f ", el[i][j]);
166                 break;
167         case matrix_upper:
168                 (void) fprintf(fp, "upper ");
169                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
170                 for (i = 0; i < m; ++i)
171                         for (j = i; j < m; ++j)
172                                 (void) fprintf(fp, "%f ", el[i][j]);
173                 break;
174         case matrix_symmetric:
175                 (void) fprintf(fp, "symmetric ");
176                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
177                 for (i = 0; i < m; ++i)
178                         for (j = 0; j <= i; ++j)
179                                 (void) fprintf(fp, "%f ", el[i][j]);
180                 break;
181         default:
182                 {
183                         (void) fprintf(fp, "full ");
184                         (void) fprintf(fp, "%d %d ", mat->m, mat->n);
185                         for (i = 0; i < m; ++i)
186                                 for (j = 0; j < n; ++j)
187                                         (void) fprintf(fp, "%f ", matrix_getf(mat, i, j));
188                 }
189         }
190 }
191 
192 void            dmatrix_print(FILE * fp, Matrix * mat)
193 {
194         int             i, j;
195         int             m = mat->m;
196         int             n = mat->n;
197         double        **el = mat->el.double_v;
198 
199         (void) fprintf(fp, "double ");
200         switch (mat->shape)
201         {
202         case matrix_full:
203                 (void) fprintf(fp, "full ");
204                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
205                 for (i = 0; i < m; ++i)
206                         for (j = 0; j < n; ++j)
207                                 (void) fprintf(fp, "%f ", el[i][j]);
208                 break;
209         case matrix_lower:
210                 (void) fprintf(fp, "lower ");
211                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
212                 for (i = 0; i < m; ++i)
213                         for (j = 0; j <= i; ++j)
214                                 (void) fprintf(fp, "%f ", el[i][j]);
215                 break;
216         case matrix_upper:
217                 (void) fprintf(fp, "upper ");
218                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
219                 for (i = 0; i < m; ++i)
220                         for (j = i; j < m; ++j)
221                                 (void) fprintf(fp, "%f ", el[i][j]);
222                 break;
223         case matrix_symmetric:
224                 (void) fprintf(fp, "symmetric ");
225                 (void) fprintf(fp, "%d %d ", mat->m, mat->n);
226                 for (i = 0; i < m; ++i)
227                         for (j = 0; j <= i; ++j)
228                                 (void) fprintf(fp, "%f ", el[i][j]);
229                 break;
230         default:
231                 {
232                         (void) fprintf(fp, "full ");
233                         (void) fprintf(fp, "%d %d ", mat->m, mat->n);
234                         for (i = 0; i < m; ++i)
235                                 for (j = 0; j < n; ++j)
236                                         (void) fprintf(fp, "%f ", matrix_getf(mat, i, j));
237                 }
238         }
239 }
240 
241 void            matrix_pprint(FILE * fp, Matrix * mat)
242 {
243         (void) fprintf(fp, "matrix ");
244 
245         if (mat == NULL)
246         {
247                 (void) fprintf(fp, "nil\n");
248                 return;
249         }
250         switch (mat->vtype)
251         {
252         case int_v:
253                 imatrix_pprint(fp, mat);
254                 break;
255         case float_v:
256                 fmatrix_pprint(fp, mat);
257                 break;
258         case double_v:
259                 dmatrix_pprint(fp, mat);
260                 break;
261         default:
262                 error("matrix_pprint: unsupported type", non_fatal);
263                 break;
264         }
265 }
266 
267 void            imatrix_pprint(FILE * fp, Matrix * mat)
268 {
269         int             i, j;
270         int             m = mat->m;
271         int             n = mat->n;
272         int           **el = mat->el.int_v;
273 
274         (void) fprintf(fp, "int ");
275         switch (mat->shape)
276         {
277         case matrix_full:
278                 (void) fprintf(fp, "full ");
279                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
280                 for (i = 0; i < m; ++i)
281                 {
282                         for (j = 0; j < n; ++j)
283                                 (void) fprintf(fp, "%10d", el[i][j]);
284                         (void) fprintf(fp, "\n");
285                 }
286                 break;
287         case matrix_lower:
288                 (void) fprintf(fp, "lower ");
289                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
290                 for (i = 0; i < m; ++i)
291                 {
292                         for (j = 0; j <= i; ++j)
293                                 (void) fprintf(fp, "%10d", el[i][j]);
294                         (void) fprintf(fp, "\n");
295                 }
296                 break;
297         case matrix_upper:
298                 (void) fprintf(fp, "upper ");
299                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
300                 for (i = 0; i < m; ++i)
301                 {
302                         for (j = 0; j < i; ++j)
303                                 (void) fprintf(fp, "          ");
304                         for (j = i; j < m; ++j)
305                                 (void) fprintf(fp, "%10d", el[i][j]);
306                         (void) fprintf(fp, "\n");
307                 }
308                 break;
309         case matrix_symmetric:
310                 (void) fprintf(fp, "symmetric ");
311                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
312                 for (i = 0; i < m; ++i)
313                 {
314                         for (j = 0; j <= i; ++j)
315                                 (void) fprintf(fp, "%10d", el[i][j]);
316                         (void) fprintf(fp, "\n");
317                 }
318                 break;
319         default:
320                 (void) fprintf(fp, "full ");
321                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
322                 for (i = 0; i < m; ++i)
323                 {
324                         for (j = 0; j < n; ++j)
325                                 (void) fprintf(fp, "%10d", matrix_get(mat, i, j));
326                         (void) fprintf(fp, "\n");
327                 }
328         }
329         (void) fprintf(fp, "\n");
330 }
331 
332 void            fmatrix_pprint(FILE * fp, Matrix * mat)
333 {
334         int             i, j;
335         int             m = mat->m;
336         int             n = mat->n;
337         float         **el = mat->el.float_v;
338 
339         (void) fprintf(fp, "float ");
340         switch (mat->shape)
341         {
342         case matrix_full:
343                 (void) fprintf(fp, "full ");
344                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
345                 for (i = 0; i < m; ++i)
346                 {
347                         for (j = 0; j < n; ++j)
348                                 (void) fprintf(fp, "%15.6f", el[i][j]);
349                         (void) fprintf(fp, "\n");
350                 }
351                 break;
352         case matrix_lower:
353                 (void) fprintf(fp, "lower ");
354                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
355                 for (i = 0; i < m; ++i)
356                 {
357                         for (j = 0; j <= i; ++j)
358                                 (void) fprintf(fp, "%15.6f", el[i][j]);
359                         (void) fprintf(fp, "\n");
360                 }
361                 break;
362         case matrix_upper:
363                 (void) fprintf(fp, "upper ");
364                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
365                 for (i = 0; i < m; ++i)
366                 {
367                         for (j = 0; j < i; ++j)
368                                 (void) fprintf(fp, "               ");
369                         for (j = i; j < m; ++j)
370                                 (void) fprintf(fp, "%15.6f", el[i][j]);
371                         (void) fprintf(fp, "\n");
372                 }
373                 break;
374         case matrix_symmetric:
375                 (void) fprintf(fp, "symmetric ");
376                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
377                 for (i = 0; i < m; ++i)
378                 {
379                         for (j = 0; j <= i; ++j)
380                                 (void) fprintf(fp, "%15.6f", el[i][j]);
381                         (void) fprintf(fp, "\n");
382                 }
383                 break;
384         default:
385                 (void) fprintf(fp, "full ");
386                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
387                 for (i = 0; i < m; ++i)
388                 {
389                         for (j = 0; j < n; ++j)
390                                 (void) fprintf(fp, "%15.6f", matrix_getf(mat, i, j));
391                         (void) fprintf(fp, "\n");
392                 }
393         }
394         (void) fprintf(fp, "\n");
395 }
396 
397 void            dmatrix_pprint(FILE * fp, Matrix * mat)
398 {
399         int             i, j;
400         int             m = mat->m;
401         int             n = mat->n;
402         double        **el = mat->el.double_v;
403 
404         (void) fprintf(fp, "double ");
405         switch (mat->shape)
406         {
407         case matrix_full:
408                 (void) fprintf(fp, "full ");
409                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
410                 for (i = 0; i < m; ++i)
411                 {
412                         for (j = 0; j < n; ++j)
413                                 (void) fprintf(fp, "%15.6f", el[i][j]);
414                         (void) fprintf(fp, "\n");
415                 }
416                 break;
417         case matrix_lower:
418                 (void) fprintf(fp, "lower ");
419                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
420                 for (i = 0; i < m; ++i)
421                 {
422                         for (j = 0; j <= i; ++j)
423                                 (void) fprintf(fp, "%15.6f", el[i][j]);
424                         (void) fprintf(fp, "\n");
425                 }
426                 break;
427         case matrix_upper:
428                 (void) fprintf(fp, "upper ");
429                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
430                 for (i = 0; i < m; ++i)
431                 {
432                         for (j = 0; j < i; ++j)
433                                 (void) fprintf(fp, "               ");
434                         for (j = i; j < m; ++j)
435                                 (void) fprintf(fp, "%15.6f", el[i][j]);
436                         (void) fprintf(fp, "\n");
437                 }
438                 break;
439         case matrix_symmetric:
440                 (void) fprintf(fp, "symmetric ");
441                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
442                 for (i = 0; i < m; ++i)
443                 {
444                         for (j = 0; j <= i; ++j)
445                                 (void) fprintf(fp, "%15.6f", el[i][j]);
446                         (void) fprintf(fp, "\n");
447                 }
448                 break;
449         default:
450                 (void) fprintf(fp, "full ");
451                 (void) fprintf(fp, "%d %d\n", mat->m, mat->n);
452                 for (i = 0; i < m; ++i)
453                 {
454                         for (j = 0; j < n; ++j)
455                                 (void) fprintf(fp, "%15.6f", matrix_getf(mat, i, j));
456                         (void) fprintf(fp, "\n");
457                 }
458         }
459         (void) fprintf(fp, "\n");
460 }
461 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.