NEURON
zcopy.c
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 /**************************************************************************
4 **
5 ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
6 **
7 ** Meschach Library
8 **
9 ** This Meschach Library is provided "as is" without any express
10 ** or implied warranty of any kind with respect to this software.
11 ** In particular the authors shall not be liable for any direct,
12 ** indirect, special, incidental or consequential damages arising
13 ** in any way from use of the software.
14 **
15 ** Everyone is granted permission to copy, modify and redistribute this
16 ** Meschach Library, provided:
17 ** 1. All copies contain this copyright notice.
18 ** 2. All modified copies shall carry a notice stating who
19 ** made the last modification and the date of such modification.
20 ** 3. No charge is made for this software or works derived from it.
21 ** This clause shall not be construed as constraining other software
22 ** distributed on the same medium as this software, nor is a
23 ** distribution fee considered a charge.
24 **
25 ***************************************************************************/
26 
27 
28 static char rcsid[] = "zcopy.c,v 1.1 1997/12/04 17:56:04 hines Exp";
29 #include <stdio.h>
30 #include "zmatrix.h"
31 
32 
33 
34 /* _zm_copy -- copies matrix into new area */
35 ZMAT *_zm_copy(in,out,i0,j0)
36 ZMAT *in,*out;
37 u_int i0,j0;
38 {
39  u_int i /* ,j */;
40 
41  if ( in==ZMNULL )
42  error(E_NULL,"_zm_copy");
43  if ( in==out )
44  return (out);
45  if ( out==ZMNULL || out->m < in->m || out->n < in->n )
46  out = zm_resize(out,in->m,in->n);
47 
48  for ( i=i0; i < in->m; i++ )
49  MEM_COPY(&(in->me[i][j0]),&(out->me[i][j0]),
50  (in->n - j0)*sizeof(complex));
51  /* for ( j=j0; j < in->n; j++ )
52  out->me[i][j] = in->me[i][j]; */
53 
54  return (out);
55 }
56 
57 /* _zv_copy -- copies vector into new area */
58 ZVEC *_zv_copy(in,out,i0)
59 ZVEC *in,*out;
60 u_int i0;
61 {
62  /* u_int i,j; */
63 
64  if ( in==ZVNULL )
65  error(E_NULL,"_zv_copy");
66  if ( in==out )
67  return (out);
68  if ( out==ZVNULL || out->dim < in->dim )
69  out = zv_resize(out,in->dim);
70 
71  MEM_COPY(&(in->ve[i0]),&(out->ve[i0]),(in->dim - i0)*sizeof(complex));
72  /* for ( i=i0; i < in->dim; i++ )
73  out->ve[i] = in->ve[i]; */
74 
75  return (out);
76 }
77 
78 
79 /*
80  The z._move() routines are for moving blocks of memory around
81  within Meschach data structures and for re-arranging matrices,
82  vectors etc.
83 */
84 
85 /* zm_move -- copies selected pieces of a matrix
86  -- moves the m0 x n0 submatrix with top-left cor-ordinates (i0,j0)
87  to the corresponding submatrix of out with top-left co-ordinates
88  (i1,j1)
89  -- out is resized (& created) if necessary */
90 ZMAT *zm_move(in,i0,j0,m0,n0,out,i1,j1)
91 ZMAT *in, *out;
92 int i0, j0, m0, n0, i1, j1;
93 {
94  int i;
95 
96  if ( ! in )
97  error(E_NULL,"zm_move");
98  if ( i0 < 0 || j0 < 0 || i1 < 0 || j1 < 0 || m0 < 0 || n0 < 0 ||
99  i0+m0 > in->m || j0+n0 > in->n )
100  error(E_BOUNDS,"zm_move");
101 
102  if ( ! out )
103  out = zm_resize(out,i1+m0,j1+n0);
104  else if ( i1+m0 > out->m || j1+n0 > out->n )
105  out = zm_resize(out,max(out->m,i1+m0),max(out->n,j1+n0));
106 
107  for ( i = 0; i < m0; i++ )
108  MEM_COPY(&(in->me[i0+i][j0]),&(out->me[i1+i][j1]),
109  n0*sizeof(complex));
110 
111  return out;
112 }
113 
114 /* zv_move -- copies selected pieces of a vector
115  -- moves the length dim0 subvector with initial index i0
116  to the corresponding subvector of out with initial index i1
117  -- out is resized if necessary */
118 ZVEC *zv_move(in,i0,dim0,out,i1)
119 ZVEC *in, *out;
120 int i0, dim0, i1;
121 {
122  if ( ! in )
123  error(E_NULL,"zv_move");
124  if ( i0 < 0 || dim0 < 0 || i1 < 0 ||
125  i0+dim0 > in->dim )
126  error(E_BOUNDS,"zv_move");
127 
128  if ( (! out) || i1+dim0 > out->dim )
129  out = zv_resize(out,i1+dim0);
130 
131  MEM_COPY(&(in->ve[i0]),&(out->ve[i1]),dim0*sizeof(complex));
132 
133  return out;
134 }
135 
136 
137 /* zmv_move -- copies selected piece of matrix to a vector
138  -- moves the m0 x n0 submatrix with top-left co-ordinate (i0,j0) to
139  the subvector with initial index i1 (and length m0*n0)
140  -- rows are copied contiguously
141  -- out is resized if necessary */
142 ZVEC *zmv_move(in,i0,j0,m0,n0,out,i1)
143 ZMAT *in;
144 ZVEC *out;
145 int i0, j0, m0, n0, i1;
146 {
147  int dim1, i;
148 
149  if ( ! in )
150  error(E_NULL,"zmv_move");
151  if ( i0 < 0 || j0 < 0 || m0 < 0 || n0 < 0 || i1 < 0 ||
152  i0+m0 > in->m || j0+n0 > in->n )
153  error(E_BOUNDS,"zmv_move");
154 
155  dim1 = m0*n0;
156  if ( (! out) || i1+dim1 > out->dim )
157  out = zv_resize(out,i1+dim1);
158 
159  for ( i = 0; i < m0; i++ )
160  MEM_COPY(&(in->me[i0+i][j0]),&(out->ve[i1+i*n0]),n0*sizeof(complex));
161 
162  return out;
163 }
164 
165 /* zvm_move -- copies selected piece of vector to a matrix
166  -- moves the subvector with initial index i0 and length m1*n1 to
167  the m1 x n1 submatrix with top-left co-ordinate (i1,j1)
168  -- copying is done by rows
169  -- out is resized if necessary */
170 ZMAT *zvm_move(in,i0,out,i1,j1,m1,n1)
171 ZVEC *in;
172 ZMAT *out;
173 int i0, i1, j1, m1, n1;
174 {
175  int dim0, i;
176 
177  if ( ! in )
178  error(E_NULL,"zvm_move");
179  if ( i0 < 0 || i1 < 0 || j1 < 0 || m1 < 0 || n1 < 0 ||
180  i0+m1*n1 > in->dim )
181  error(E_BOUNDS,"zvm_move");
182 
183  if ( ! out )
184  out = zm_resize(out,i1+m1,j1+n1);
185  else
186  out = zm_resize(out,max(i1+m1,out->m),max(j1+n1,out->n));
187 
188  dim0 = m1*n1;
189  for ( i = 0; i < m1; i++ )
190  MEM_COPY(&(in->ve[i0+i*n1]),&(out->me[i1+i][j1]),n1*sizeof(complex));
191 
192  return out;
193 }
double max(double a, double b)
Definition: geometry3d.cpp:22
u_int dim
Definition: zmatrix.h:45
#define ZVNULL
Definition: zmatrix.h:57
u_int m
Definition: zmatrix.h:51
#define ZMNULL
Definition: zmatrix.h:58
Definition: zmatrix.h:50
Definition: zmatrix.h:44
ZMAT * zvm_move(ZVEC *in, int i0, ZMAT *out, int i1, int j1, int m1, int n1)
Definition: zcopy.c:170
uint32_t u_int
Definition: machine.h:38
ZMAT * zm_resize(ZMAT *A, int new_m, int new_n)
Definition: zmemory.c:227
complex * ve
Definition: zmatrix.h:46
ZVEC * _zv_copy(ZVEC *in, ZVEC *out, u_int i0)
Definition: zcopy.c:58
#define E_BOUNDS
Definition: err.h:96
void MEM_COPY(char *from, char *to, int len)
Definition: extras.c:37
#define E_NULL
Definition: err.h:102
ZVEC * zv_resize(ZVEC *x, int new_dim)
Definition: zmemory.c:362
u_int n
Definition: zmatrix.h:51
#define i
Definition: md1redef.h:12
#define error(err_num, fn_name)
Definition: err.h:73
ZMAT * _zm_copy(ZMAT *in, ZMAT *out, u_int i0, u_int j0)
Definition: zcopy.c:35
complex ** me
Definition: zmatrix.h:54
ZVEC * zmv_move(ZMAT *in, int i0, int j0, int m0, int n0, ZVEC *out, int i1)
Definition: zcopy.c:142
ZMAT * zm_move(ZMAT *in, int i0, int j0, int m0, int n0, ZMAT *out, int i1, int j1)
Definition: zcopy.c:90
static char rcsid[]
Definition: zcopy.c:28
ZVEC * zv_move(ZVEC *in, int i0, int dim0, ZVEC *out, int i1)
Definition: zcopy.c:118