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

Linux Cross Reference
Tina5/tina-libs/tina/math/mathVec_max.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_max.c,v $
 37  * Date    :  $Date: 2003/09/23 11:32:20 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: mathVec_max.c,v 1.4 2003/09/23 11:32:20 matts Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : Vector (1 dimensional array) handling (biggest component etc)
 44  *
 45  *********
 46 */
 47 /** 
 48  *  @file
 49  *  @brief  Vector handling to find min/max elements in a vector.       
 50  *
 51  *  Functions to find both the absolute min and max of the elements in a vector
 52  *  as well as the mod min and max.
 53  * 
 54 */
 55 
 56 #include "mathVec_max.h"
 57 
 58 #if HAVE_CONFIG_H
 59 #include <config.h>
 60 #endif
 61 
 62 
 63 #include <math.h>
 64 #include <tina/sys/sysDef.h>
 65 #include <tina/sys/sysPro.h>
 66 #include <tina/math/math_TypPro.h>
 67 #include <tina/math/math_VecDef.h>
 68 
 69 
 70 double          vector_max(Vector * v, int *imax)
 71 {
 72         int             i;
 73         double          vi, vmax;
 74 
 75         if (imax != NULL)
 76                 *imax = 0;
 77         if (v == NULL)
 78                 return (0.0);
 79 
 80         VECTOR_GET(v, 0, vmax);
 81         for (i = 1; i < v->n; i++)
 82         {
 83                 VECTOR_GET(v, i, vi);
 84                 if (vmax < vi)
 85                 {
 86                         vmax = vi;
 87                         if (imax != NULL)
 88                                 *imax = i;
 89                 }
 90         }
 91         return (vmax);
 92 }
 93 
 94 double          vector_min(Vector * v, int *imin)
 95 {
 96         int             i;
 97         double          vi, vmin;
 98 
 99         if (imin != NULL)
100                 *imin = 0;
101         if (v == NULL)
102                 return (0.0);
103 
104         VECTOR_GET(v, 0, vmin);
105         for (i = 1; i < v->n; i++)
106         {
107                 VECTOR_GET(v, i, vi);
108                 if (vmin > vi)
109                 {
110                         vmin = vi;
111                         if (imin != NULL)
112                                 *imin = i;
113                 }
114         }
115         return (vmin);
116 }
117 
118 double          vector_maxmod(Vector * v, int *imax)
119 {
120         int             i;
121         double          vmod, vmax;
122 
123         if (imax != NULL)
124                 *imax = 0;
125         if (v == NULL)
126                 return (0.0);
127 
128         if (v->vtype == complex_v)
129         {
130                 Complex         vi = {Complex_id};
131 
132                 VECTOR_GETZ(v, 0, vi);
133                 vmax = cmplx_sqrmod(vi);
134                 for (i = 1; i < v->n; i++)
135                 {
136                         VECTOR_GETZ(v, i, vi);
137                         vmod = cmplx_sqrmod(vi);
138                         if (vmax < vmod)
139                         {
140                                 vmax = vmod;
141                                 if (imax != NULL)
142                                         *imax = i;
143                         }
144                 }
145         } else
146         {
147                 double          vi;
148 
149                 VECTOR_GET(v, 0, vi);
150                 vmax = fabs(vi);
151                 for (i = 1; i < v->n; i++)
152                 {
153                         VECTOR_GET(v, i, vi);
154                         vmod = fabs(vi);
155                         if (vmax < vmod)
156                         {
157                                 vmax = vmod;
158                                 if (imax != NULL)
159                                         *imax = i;
160                         }
161                 }
162         }
163         return (vmax);
164 }
165 
166 double          vector_minmod(Vector * v, int *imin)
167 {
168         int             i;
169         double          vmod, vmin;
170 
171         if (imin != NULL)
172                 *imin = 0;
173         if (v == NULL)
174                 return (0.0);
175 
176         if (v->vtype == complex_v)
177         {
178                 Complex         vi = {Complex_id};
179 
180                 VECTOR_GETZ(v, 0, vi);
181                 vmin = cmplx_sqrmod(vi);
182                 for (i = 1; i < v->n; i++)
183                 {
184                         VECTOR_GETZ(v, i, vi);
185                         vmod = cmplx_sqrmod(vi);
186                         if (vmin > vmod)
187                         {
188                                 vmin = vmod;
189                                 if (imin != NULL)
190                                         *imin = i;
191                         }
192                 }
193         } else
194         {
195                 double          vi;
196 
197                 VECTOR_GET(v, 0, vi);
198                 vmin = fabs(vi);
199                 for (i = 1; i < v->n; i++)
200                 {
201                         VECTOR_GET(v, i, vi);
202                         vmod = fabs(vi);
203                         if (vmin > vmod)
204                         {
205                                 vmin = vmod;
206                                 if (imin != NULL)
207                                         *imin = i;
208                         }
209                 }
210         }
211         return (vmin);
212 }
213 

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