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

Linux Cross Reference
Tina5/tina-libs/tina/math/mathMatr_fmt.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_fmt.c,v $
 37  * Date    :  $Date: 2003/09/23 11:32:20 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: mathMatr_fmt.c,v 1.5 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  *  @file
 49  *  @brief  Matrix formatting (to screen) according to type and shape.  
 50  * 
 51 */
 52 
 53 #include "mathMatr_fmt.h"
 54 
 55 #if HAVE_CONFIG_H
 56 #include <config.h>
 57 #endif
 58 
 59 #include <math.h>
 60 #include <stdio.h>
 61 #include <tina/sys/sysDef.h>
 62 #include <tina/sys/sysPro.h>
 63 #include <tina/math/math_MatrDef.h>
 64 #include <tina/math/mathMatr_get.h>
 65 #include <tina/math/mathMatr_fmt2.h>
 66 
 67 
 68 
 69 static void     format_header(Matrix * mat)
 70 {
 71         format("matrix: ");
 72         format_shape(mat->shape);
 73         format(" %d by %d  of ", mat->m, mat->n);
 74         format_vtype(mat->vtype);
 75         format("\n");
 76 }
 77 
 78 void            mat_format(Matrix * mat)
 79 {
 80         int             i, j;
 81         int             m = mat->m;
 82         int             n = mat->n;
 83         float         **el = mat->el.float_v;
 84 
 85         format_header(mat);
 86 
 87         for (i = 0; i < m; ++i)
 88         {
 89                 for (j = 0; j < n; ++j)
 90                         format("%12.6f ", el[i][j]);
 91                 format("\n");
 92         }
 93 }
 94 
 95 void            matrix_format(Matrix * mat)
 96 {
 97         if (mat == NULL)
 98         {
 99                 format("nil ");
100                 return;
101         }
102         switch (mat->vtype)
103         {
104         case char_v:
105         case uchar_v:
106                 cmatrix_format(mat);
107                 break;
108         case short_v:
109         case ushort_v:
110                 smatrix_format(mat);
111                 break;
112         case int_v:
113         case uint_v:
114                 imatrix_format(mat);
115                 break;
116         case float_v:
117                 fmatrix_format(mat);
118                 break;
119         case double_v:
120                 dmatrix_format(mat);
121                 break;
122         case complex_v:
123                 zmatrix_format(mat);
124                 break;
125         case ptr_v:
126                 pmatrix_format(mat);
127                 break;
128         default:
129                 error("matrix_format: unsupported type", non_fatal);
130                 break;
131         }
132 }
133 
134 void            cmatrix_format(Matrix * mat)
135 {
136         switch (mat->shape)
137         {
138                 case matrix_full:
139                 cmatrix_format_full(mat);
140                 break;
141         case matrix_lower:
142         case matrix_symmetric:
143                 cmatrix_format_lower(mat);
144                 break;
145         default:
146                 cmatrix_format_gen(mat);
147                 break;
148         }
149 }
150 
151 void            cmatrix_format_full(Matrix * mat)
152 {
153         int             i, j;
154         int             m = mat->m;
155         int             n = mat->n;
156         char          **el = mat->el.char_v;
157 
158         format_header(mat);
159 
160         for (i = 0; i < m; ++i)
161         {
162                 for (j = 0; j < n; ++j)
163                         format("%c ", el[i][j]);
164                 format("\n");
165         }
166 }
167 
168 void            cmatrix_format_lower(Matrix * mat)
169 {
170         int             i, j;
171         int             m = mat->m;
172         char          **el = mat->el.char_v;
173 
174         format_header(mat);
175 
176         for (i = 0; i < m; ++i)
177         {
178                 for (j = 0; j <= i; ++j)
179                         format("%c ", el[i][j]);
180                 format("\n");
181         }
182 }
183 
184 void            cmatrix_format_gen(Matrix * mat)
185 {
186         int             i, j;
187         int             m = mat->m;
188         int             n = mat->n;
189 
190         format_header(mat);
191 
192         for (i = 0; i < m; ++i)
193         {
194                 for (j = 0; j < n; ++j)
195                         format("%c ", matrix_get(mat, i, j));
196                 format("\n");
197         }
198 }
199 
200 void            smatrix_format(Matrix * mat)
201 {
202         switch (mat->shape)
203         {
204                 case matrix_full:
205                 smatrix_format_full(mat);
206                 break;
207         case matrix_lower:
208         case matrix_symmetric:
209                 smatrix_format_lower(mat);
210                 break;
211         default:
212                 smatrix_format_gen(mat);
213                 break;
214         }
215 }
216 
217 
218 void            smatrix_format_full(Matrix * mat)
219 {
220         int             i, j;
221         int             m = mat->m;
222         int             n = mat->n;
223         short         **el = mat->el.short_v;
224 
225         format_header(mat);
226 
227         for (i = 0; i < m; ++i)
228         {
229                 for (j = 0; j < n; ++j)
230                         format("%10d ", el[i][j]);
231                 format("\n");
232         }
233 }
234 
235 void            smatrix_format_lower(Matrix * mat)
236 {
237         int             i, j;
238         int             m = mat->m;
239         short         **el = mat->el.short_v;
240 
241         format_header(mat);
242 
243         for (i = 0; i < m; ++i)
244         {
245                 for (j = 0; j <= i; ++j)
246                         format("%10d ", el[i][j]);
247                 format("\n");
248         }
249 }
250 
251 void            smatrix_format_gen(Matrix * mat)
252 {
253         int             i, j;
254         int             m = mat->m;
255         int             n = mat->n;
256 
257         format_header(mat);
258 
259         for (i = 0; i < m; ++i)
260         {
261                 for (j = 0; j < n; ++j)
262                         format("%10d ", matrix_get(mat, i, j));
263                 format("\n");
264         }
265 }
266 
267 void            imatrix_format(Matrix * mat)
268 {
269         switch (mat->shape)
270         {
271                 case matrix_full:
272                 imatrix_format_full(mat);
273                 break;
274         case matrix_lower:
275         case matrix_symmetric:
276                 imatrix_format_lower(mat);
277                 break;
278         default:
279                 imatrix_format_gen(mat);
280                 break;
281         }
282 }
283 
284 
285 void            imatrix_format_full(Matrix * mat)
286 {
287         int             i, j;
288         int             m = mat->m;
289         int             n = mat->n;
290         int           **el = mat->el.int_v;
291 
292         format_header(mat);
293 
294         for (i = 0; i < m; ++i)
295         {
296                 for (j = 0; j < n; ++j)
297                         format("%10d ", el[i][j]);
298                 format("\n");
299         }
300 }
301 
302 void            imatrix_format_lower(Matrix * mat)
303 {
304         int             i, j;
305         int             m = mat->m;
306         int           **el = mat->el.int_v;
307 
308         format_header(mat);
309 
310         for (i = 0; i < m; ++i)
311         {
312                 for (j = 0; j <= i; ++j)
313                         format("%10d ", el[i][j]);
314                 format("\n");
315         }
316 }
317 
318 void            imatrix_format_gen(Matrix * mat)
319 {
320         int             i, j;
321         int             m = mat->m;
322         int             n = mat->n;
323 
324         format_header(mat);
325 
326         for (i = 0; i < m; ++i)
327         {
328                 for (j = 0; j < n; ++j)
329                         format("%10d ", matrix_get(mat, i, j));
330                 format("\n");
331         }
332 }
333 
334 void            fmatrix_format(Matrix * mat)
335 {
336         switch (mat->shape)
337         {
338                 case matrix_full:
339                 fmatrix_format_full(mat);
340                 break;
341         case matrix_lower:
342         case matrix_symmetric:
343                 fmatrix_format_lower(mat);
344                 break;
345         default:
346                 fmatrix_format_gen(mat);
347                 break;
348         }
349 }
350 
351 void            fmatrix_format_full(Matrix * mat)
352 {
353         int             i, j;
354         int             m = mat->m;
355         int             n = mat->n;
356         float         **el = mat->el.float_v;
357 
358         format_header(mat);
359 
360         for (i = 0; i < m; ++i)
361         {
362                 for (j = 0; j < n; ++j)
363                         format("%12.6f ", el[i][j]);
364                 format("\n");
365         }
366 }
367 
368 void            fmatrix_format_lower(Matrix * mat)
369 {
370         int             i, j;
371         int             m = mat->m;
372         float         **el = mat->el.float_v;
373 
374         format_header(mat);
375 
376         for (i = 0; i < m; ++i)
377         {
378                 for (j = 0; j <= i; ++j)
379                         format("%12.6f ", el[i][j]);
380                 format("\n");
381         }
382 }
383 
384 void            fmatrix_format_gen(Matrix * mat)
385 {
386         int             i, j;
387         int             m = mat->m;
388         int             n = mat->n;
389 
390         format_header(mat);
391 
392         for (i = 0; i < m; ++i)
393         {
394                 for (j = 0; j < n; ++j)
395                         format("%12.6f ", matrix_getf(mat, i, j));
396                 format("\n");
397         }
398 }
399 
400 void            dmatrix_format(Matrix * mat)
401 {
402         switch (mat->shape)
403         {
404                 case matrix_full:
405                 dmatrix_format_full(mat);
406                 break;
407         case matrix_lower:
408         case matrix_symmetric:
409                 dmatrix_format_lower(mat);
410                 break;
411         default:
412                 dmatrix_format_gen(mat);
413                 break;
414         }
415 }
416 
417 void            dmatrix_format_full(Matrix * mat)
418 {
419         int             i, j;
420         int             m = mat->m;
421         int             n = mat->n;
422         double        **el = mat->el.double_v;
423 
424         format_header(mat);
425 
426         for (i = 0; i < m; ++i)
427         {
428                 for (j = 0; j < n; ++j)
429                         format("%12.6f ", el[i][j]);
430                 format("\n");
431         }
432 }
433 
434 void            dmatrix_format_lower(Matrix * mat)
435 {
436         int             i, j;
437         int             m = mat->m;
438         double        **el = mat->el.double_v;
439 
440         format_header(mat);
441 
442         for (i = 0; i < m; ++i)
443         {
444                 for (j = 0; j <= i; ++j)
445                         format("%12.6f ", el[i][j]);
446                 format("\n");
447         }
448 }
449 
450 void            dmatrix_format_gen(Matrix * mat)
451 {
452         int             i, j;
453         int             m = mat->m;
454         int             n = mat->n;
455 
456         format_header(mat);
457 
458         for (i = 0; i < m; ++i)
459         {
460                 for (j = 0; j < n; ++j)
461                         format("%12.6f ", matrix_getf(mat, i, j));
462                 format("\n");
463         }
464 }
465 
466 void            zmatrix_format(Matrix * mat)
467 {
468         switch (mat->shape)
469         {
470                 case matrix_full:
471                 zmatrix_format_full(mat);
472                 break;
473         case matrix_lower:
474         case matrix_symmetric:
475                 zmatrix_format_lower(mat);
476                 break;
477         default:
478                 zmatrix_format_gen(mat);
479                 break;
480         }
481 }
482 
483 void            zmatrix_format_full(Matrix * mat)
484 {
485         int             i, j;
486         int             m = mat->m;
487         int             n = mat->n;
488         Complex       **el = mat->el.complex_v;
489 
490         format_header(mat);
491 
492         for (i = 0; i < m; ++i)
493         {
494                 for (j = 0; j < n; ++j)
495                         format("(%12.6f,%12.6f) ", el[i][j].x, el[i][j].y);
496                 format("\n");
497         }
498 }
499 
500 void            zmatrix_format_lower(Matrix * mat)
501 {
502         int             i, j;
503         int             m = mat->m;
504         Complex       **el = mat->el.complex_v;
505 
506         format_header(mat);
507 
508         for (i = 0; i < m; ++i)
509         {
510                 for (j = 0; j <= i; ++j)
511                         format("(%12.6f,%12.6f) ", el[i][j].x, el[i][j].y);
512                 format("\n");
513         }
514 }
515 
516 void            zmatrix_format_gen(Matrix * mat)
517 {
518         int             i, j;
519         int             m = mat->m;
520         int             n = mat->n;
521 
522         format_header(mat);
523 
524         for (i = 0; i < m; ++i)
525         {
526                 for (j = 0; j < n; ++j)
527                 {
528                         Complex         val = {Complex_id};
529 
530                         val = matrix_getz(mat, i, j);
531                         format("(%12.6f,%12.6f) ", val.x, val.y);
532                 }
533                 format("\n");
534         }
535 }
536 
537 void            ptr_default_print(void *ptr)
538 {
539         if (ptr == NULL)
540                 format(" 0");
541         else
542                 format(" *");
543 }
544 
545 static void     (*ptr_print) () = ptr_default_print;            /* static data! */
546 
547 void            ptr_set_print(void (*newprint) ( /* ??? */ ))
548 {
549         ptr_print = newprint;
550 }
551 
552 void            (*ptr_get_print(void)) ( /* ??? */ )
553 {
554         return (ptr_print);
555 }
556 
557 void            pmatrix_format(Matrix * mat)
558 {
559         switch (mat->shape)
560         {
561                 case matrix_full:
562                 pmatrix_format_full(mat);
563                 break;
564         case matrix_lower:
565         case matrix_symmetric:
566                 pmatrix_format_lower(mat);
567                 break;
568         default:
569                 pmatrix_format_gen(mat);
570                 break;
571         }
572 }
573 
574 void            pmatrix_format_full(Matrix * mat)
575 {
576         int             i, j;
577         int             m = mat->m;
578         int             n = mat->n;
579         void         ***el = mat->el.ptr_v;
580 
581         format_header(mat);
582 
583         for (i = 0; i < m; ++i)
584         {
585                 for (j = 0; j < n; ++j)
586                         ptr_print(el[i][j]);
587                 format("\n");
588         }
589 }
590 
591 void            pmatrix_format_lower(Matrix * mat)
592 {
593         int             i, j;
594         int             m = mat->m;
595         void         ***el = mat->el.ptr_v;
596 
597         format_header(mat);
598 
599         for (i = 0; i < m; ++i)
600         {
601                 for (j = 0; j <= i; ++j)
602                         ptr_print(el[i][j]);
603                 format("\n");
604         }
605 }
606 
607 void            pmatrix_format_gen(Matrix * mat)
608 {
609         int             i, j;
610         int             m = mat->m;
611         int             n = mat->n;
612 
613         format_header(mat);
614 
615         for (i = 0; i < m; ++i)
616         {
617                 for (j = 0; j < n; ++j)
618                 {
619                         void           *val;
620 
621                         val = matrix_getp(mat, i, j);
622                         ptr_print(val);
623                 }
624                 format("\n");
625         }
626 }
627 

~ [ 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.