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

Linux Cross Reference
Tina5/tina-libs/tina/math/mathMatr_put.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_put.c,v $
 37  * Date    :  $Date: 2008/12/07 02:27:36 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: mathMatr_put.c,v 1.5 2008/12/07 02:27:36 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : Matrix elements setting. (Setting locations outside matrix is not an error).
 44  *
 45  *********
 46 */
 47 /** 
 48  *  @file
 49  *  @brief  Insert (set) an element into a Matrix according to element type and Matrix shape.   
 50  *
 51  *  Setting locations outside matrix is not an error.
 52  * 
 53 */
 54 
 55 #include "mathMatr_put.h"
 56 
 57 #if HAVE_CONFIG_H
 58 #include <config.h>
 59 #endif
 60 
 61 #include <math.h>
 62 #include <stdio.h>
 63 #include <tina/sys/sysDef.h>
 64 #include <tina/sys/sysGen_error.h>
 65 #include <tina/math/math_MatrDef.h>
 66 #include <tina/math/math_TypPro.h>
 67 
 68 
 69 /* 
 70  * PAB 07/12/2008 The cases for matrices of pointers in the following seven functions have been removed as
 71  * their operation is undefined: use matrix_putp instead.
 72 */
 73 
 74 /** puts integer value into matrix, casting if necessary **/
 75 
 76 void            mat_putf(float val, Matrix * mat, int i, int j)
 77 {
 78         if (i < 0 || i >= mat->m || j < 0 || j >= mat->n)
 79                 return;
 80         mat->el.float_v[i][j] = val;
 81 }
 82 
 83 void            matrix_put(int val, Matrix * mat, int i, int j)
 84 {
 85         if (mat == NULL)
 86                 return;
 87 
 88         if (i < 0 || i >= mat->m || j < 0 || j >= mat->n)
 89                 return;
 90 
 91         switch (mat->shape)
 92         {
 93         case matrix_full:
 94                 matrix_put_full(val, mat, i, j);
 95                 break;
 96         case matrix_lower:
 97         case matrix_symmetric:
 98                 if (i < j)
 99                         SWAP(int, i, j);
100                 matrix_put_full(val, mat, i, j);
101                 break;
102         case matrix_upper:
103                 if (j < i)
104                         SWAP(int, i, j);
105                 matrix_put_full(val, mat, i, j);
106                 break;
107         }
108 }
109 
110 void            matrix_put_full(int val, Matrix * mat, int i, int j)
111 {
112         switch (mat->vtype)
113         {
114                 case char_v:
115                 mat->el.char_v[i][j] = (char) val;
116                 break;
117         case uchar_v:
118                 mat->el.uchar_v[i][j] = (unsigned char) val;
119                 break;
120         case short_v:
121                 mat->el.short_v[i][j] = (short) val;
122                 break;
123         case ushort_v:
124                 mat->el.ushort_v[i][j] = (unsigned short) val;
125                 break;
126         case int_v:
127                 mat->el.int_v[i][j] = (int) val;
128                 break;
129         case uint_v:
130                 mat->el.uint_v[i][j] = (unsigned int) val;
131                 break;
132         case float_v:
133                 mat->el.float_v[i][j] = (float) val;
134                 break;
135         case double_v:
136                 mat->el.double_v[i][j] = (double) val;
137                 break;
138         case complex_v:
139                 mat->el.complex_v[i][j] = cmplx((double) val, 0.0);
140                 break;
141         default:
142                 error("matrix_put_full: unsupported type", non_fatal);
143                 break;
144         }
145 }
146 
147 /** puts double value into matrix, casting if necessary **/
148 
149 void            matrix_putf(double val, Matrix * mat, int i, int j)
150 {
151         if (mat == NULL)
152                 return;
153 
154         if (i < 0 || i >= mat->m || j < 0 || j >= mat->n)
155                 return;
156 
157         switch (mat->shape)
158         {
159         case matrix_full:
160                 matrix_putf_full(val, mat, i, j);
161                 break;
162         case matrix_lower:
163         case matrix_symmetric:
164                 if (i < j)
165                         SWAP(int, i, j);
166                 matrix_putf_full(val, mat, i, j);
167                 break;
168         case matrix_upper:
169                 if (j < i)
170                         SWAP(int, i, j);
171                 matrix_putf_full(val, mat, i, j);
172                 break;
173         }
174 }
175 
176 void            matrix_putf_full(double val, Matrix * mat, int i, int j)
177 {
178         switch (mat->vtype)
179         {
180                 case char_v:
181                 mat->el.char_v[i][j] = (char) val;
182                 break;
183         case uchar_v:
184                 mat->el.uchar_v[i][j] = (unsigned char) val;
185                 break;
186         case short_v:
187                 mat->el.short_v[i][j] = (short) val;
188                 break;
189         case ushort_v:
190                 mat->el.ushort_v[i][j] = (unsigned short) val;
191                 break;
192         case int_v:
193                 mat->el.int_v[i][j] = (int) val;
194                 break;
195         case uint_v:
196                 mat->el.uint_v[i][j] = (unsigned int) val;
197                 break;
198         case float_v:
199                 mat->el.float_v[i][j] = (float) val;
200                 break;
201         case double_v:
202                 mat->el.double_v[i][j] = (double) val;
203                 break;
204         case complex_v:
205                 mat->el.complex_v[i][j] = cmplx((double) val, 0.0);
206                 break;
207         default:
208                 error("matrix_putf_full: unsupported type", non_fatal);
209                 break;
210         }
211 }
212 
213 /** puts complex value into matrix, casting if necessary **/
214 
215 void            matrix_putz(Complex val, Matrix * mat, int i, int j)
216 {
217         if (mat == NULL)
218                 return;
219 
220         if (i < 0 || i >= mat->m || j < 0 || j >= mat->n)
221                 return;
222 
223         switch (mat->shape)
224         {
225         case matrix_full:
226                 matrix_putz_full(val, mat, i, j);
227                 break;
228         case matrix_lower:
229         case matrix_symmetric:
230                 if (i < j)
231                         SWAP(int, i, j);
232                 matrix_putz_full(val, mat, i, j);
233                 break;
234         case matrix_upper:
235                 if (j < i)
236                         SWAP(int, i, j);
237                 matrix_putz_full(val, mat, i, j);
238                 break;
239         }
240 }
241 
242 void            matrix_putz_full(Complex val, Matrix * mat, int i, int j)
243 {
244         switch (mat->vtype)
245         {
246         case char_v:
247                 mat->el.char_v[i][j] = (char) val.x;
248                 break;
249         case uchar_v:
250                 mat->el.uchar_v[i][j] = (unsigned char) val.x;
251                 break;
252         case short_v:
253                 mat->el.short_v[i][j] = (short) val.x;
254                 break;
255         case ushort_v:
256                 mat->el.ushort_v[i][j] = (unsigned short) val.x;
257                 break;
258         case int_v:
259                 mat->el.int_v[i][j] = (int) val.x;
260                 break;
261         case uint_v:
262                 mat->el.uint_v[i][j] = (unsigned int) val.x;
263                 break;
264         case float_v:
265                 mat->el.float_v[i][j] = (float) val.x;
266                 break;
267         case double_v:
268                 mat->el.double_v[i][j] = (double) val.x;
269                 break;
270         case complex_v:
271                 mat->el.complex_v[i][j] = val;
272                 break;
273         default:
274                 error("matrix_putz_full: unsupported type", non_fatal);
275                 break;
276         }
277 }
278 
279 /*
280  * puts ptr value into matrix, casting if necessary
281  * 
282  * PAB 05/12/2008 Changed the operation of the following two functions to
283  * avoid compiler warnings: void *val must now be a pointer to the variable
284  * to be entered into the matrix, not a void * cast of it.  For a matrix of
285  * pointers, the pointer is assigned to the matrix i.e. the calling function
286  * must copy or otherwise assign memory (and not free it afterwards): this is
287  * to maintain consistency wth matrix_getp_full.  Note that the original vtype
288  * of val must match the vtype of the matrix for this function to work properly.
289 */
290 
291 void            matrix_putp(void *val, Matrix * mat, int i, int j)
292 {
293         if (mat == NULL)
294                 return;
295 
296         if (i < 0 || i >= mat->m || j < 0 || j >= mat->n)
297                 return;
298 
299         switch (mat->shape)
300         {
301         case matrix_full:
302                 matrix_putp_full(val, mat, i, j);
303                 break;
304         case matrix_lower:
305         case matrix_symmetric:
306                 if (i < j)
307                         SWAP(int, i, j);
308                 matrix_putp_full(val, mat, i, j);
309                 break;
310         case matrix_upper:
311                 if (j < i)
312                         SWAP(int, i, j);
313                 matrix_putp_full(val, mat, i, j);
314                 break;
315         }
316 }
317 
318 void            matrix_putp_full(void *val, Matrix * mat, int i, int j)
319 {
320         switch (mat->vtype)
321         {
322         case char_v:
323                 mat->el.char_v[i][j] =  *((char *)val);
324                 break;
325         case uchar_v:
326                 mat->el.uchar_v[i][j] = *((unsigned char *)val);
327                 break;
328         case short_v:
329                 mat->el.short_v[i][j] = *((short *)val);
330                 break;
331         case ushort_v:
332                 mat->el.ushort_v[i][j] = *((unsigned short *)val);
333                 break;
334         case int_v:
335                 mat->el.int_v[i][j] =  *((int *)val);
336                 break;
337         case uint_v:
338                 mat->el.uint_v[i][j] = *((unsigned int *)val);
339                 break;
340         case float_v: 
341                 mat->el.float_v[i][j] = *((float *)val);
342                 break;
343         case double_v:
344                 mat->el.double_v[i][j] = *((double *)val);
345                 break;
346         case complex_v:
347                 mat->el.complex_v[i][j] = cmplx(*((double *)val), 0.0);
348                 break;
349         case ptr_v:
350                 mat->el.ptr_v[i][j] = val;
351                 break;
352         default:
353                 error("matrix_putf_full: unsupported type", non_fatal);
354                 break;
355         }
356 }
357 

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