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

Linux Cross Reference
Tina6/tina-libs/tina/math/mathVec_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/mathVec_fmt.c,v $
 37  * Date    :  $Date: 2003/09/23 11:32:20 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: mathVec_fmt.c,v 1.4 2003/09/23 11:32:20 matts Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 /** 
 48  *  @file
 49  *  @brief  Functions for formatting/printing a Vector to screen/file.  
 50  *
 51  *
 52  * 
 53 */
 54 
 55 #include "mathVec_fmt.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/sysPro.h>
 64 
 65 
 66 
 67 static void     format_header(Vector * v)
 68 {
 69         format("vector: ");
 70         format("%d of ", v->n);
 71         format_vtype(v->vtype);
 72         format("\n");
 73 }
 74 
 75 void            vector_format(Vector * v)
 76 {
 77         int             i, n;
 78 
 79         if (v == NULL)
 80         {
 81                 format("vector: NULL");
 82                 return;
 83         }
 84         format_header(v);
 85         n = v->n;
 86         switch (v->vtype)
 87         {
 88         case char_v:
 89         case uchar_v:
 90                 for (i = 0; i < n; i++)
 91                 {
 92                         double          vi;
 93 
 94                         VECTOR_GET(v, i, vi);
 95                         format("%c ", (char) vi);
 96                 }
 97                 break;
 98         case short_v:
 99         case ushort_v:
100         case int_v:
101         case uint_v:
102                 for (i = 0; i < n; i++)
103                 {
104                         double          vi;
105 
106                         VECTOR_GET(v, i, vi);
107                         format("%d ", (int) vi);
108                 }
109                 break;
110         case float_v:
111         case double_v:
112                 for (i = 0; i < n; i++)
113                 {
114                         double          vi;
115 
116                         VECTOR_GET(v, i, vi);
117                         format("%f ", vi);
118                 }
119                 break;
120         case complex_v:
121                 for (i = 0; i < n; i++)
122                 {
123                         Complex         vi = {Complex_id};
124 
125                         VECTOR_GETZ(v, i, vi);
126                         format("(%f %f) ", vi.x, vi.y);
127                 }
128                 break;
129         default:
130                 error("vector_format: unsupported type", non_fatal);
131                 break;
132         }
133         format("\n");
134 }
135 
136 static void     print_header(FILE * fp, Vector * v)
137 {
138         fprintf(fp, "vector: ");
139         fprintf(fp, "%d of ", v->n);
140         print_vtype(fp, v->vtype);
141         fprintf(fp, "\n");
142 }
143 
144 void            vector_print(FILE * fp, Vector * v)
145 {
146         int             i, n;
147 
148         if (v == NULL)
149         {
150                 fprintf(fp, "vector: NULL");
151                 return;
152         }
153         print_header(fp, v);
154         n = v->n;
155         switch (v->vtype)
156         {
157         case char_v:
158                 for (i = 0; i < n; i++)
159                 {
160                         double          vi;
161 
162                         VECTOR_GET(v, i, vi);
163                         fprintf(fp, "%c ", (char) vi);
164                 }
165                 break;
166         case uchar_v:
167                 for (i = 0; i < n; i++)
168                 {
169                         double          vi;
170 
171                         VECTOR_GET(v, i, vi);
172                         fprintf(fp, "%d ", (char) vi);
173                 }
174                 break;
175         case short_v:
176         case ushort_v:
177         case int_v:
178         case uint_v:
179                 for (i = 0; i < n; i++)
180                 {
181                         double          vi;
182 
183                         VECTOR_GET(v, i, vi);
184                         fprintf(fp, "%d ", (int) vi);
185                 }
186                 break;
187         case float_v:
188         case double_v:
189                 for (i = 0; i < n; i++)
190                 {
191                         double          vi;
192 
193                         VECTOR_GET(v, i, vi);
194                         fprintf(fp, "%f ", vi);
195                 }
196                 break;
197         case complex_v:
198                 for (i = 0; i < n; i++)
199                 {
200                         Complex         vi = {Complex_id};
201 
202                         VECTOR_GETZ(v, i, vi);
203                         fprintf(fp, "(%f %f) ", vi.x, vi.y);
204                 }
205                 break;
206         default:
207                 error("vector_print: unsupported type", non_fatal);
208                 break;
209         }
210         fprintf(fp, "\n");
211 }
212 
213 void            vector_pprint(FILE * fp, Vector * v)
214 {
215         int             i, n;
216 
217         if (v == NULL)
218         {
219                 fprintf(fp, "vector: NULL");
220                 return;
221         }
222         print_header(fp, v);
223         n = v->n;
224         switch (v->vtype)
225         {
226         case char_v:
227                 for (i = 0; i < n; i++)
228                 {
229                         double          vi;
230 
231                         VECTOR_GET(v, i, vi);
232                         fprintf(fp, "%c ", (char) vi);
233                 }
234                 break;
235         case uchar_v:
236                 for (i = 0; i < n; i++)
237                 {
238                         double          vi;
239 
240                         VECTOR_GET(v, i, vi);
241                         fprintf(fp, "%3d ", (char) vi);
242                 }
243                 break;
244         case short_v:
245         case ushort_v:
246         case int_v:
247         case uint_v:
248                 for (i = 0; i < n; i++)
249                 {
250                         double          vi;
251 
252                         VECTOR_GET(v, i, vi);
253                         fprintf(fp, "%10d ", (int) vi);
254                 }
255                 break;
256         case float_v:
257         case double_v:
258                 for (i = 0; i < n; i++)
259                 {
260                         double          vi;
261 
262                         VECTOR_GET(v, i, vi);
263                         fprintf(fp, "%12.6f ", vi);
264                 }
265                 break;
266         case complex_v:
267                 for (i = 0; i < n; i++)
268                 {
269                         Complex         vi = {Complex_id};
270 
271                         VECTOR_GETZ(v, i, vi);
272                         fprintf(fp, "(%12.6f %12.6f) ", vi.x, vi.y);
273                 }
274                 break;
275         default:
276                 error("vector_pprint: unsupported type", non_fatal);
277                 break;
278         }
279         fprintf(fp, "\n");
280 }
281 

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