proteus  1.8.1
C/C++/Fortran libraries
Util.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stddef.h>
3 #include <stdlib.h>
4 #define NR_END 1
5 #define FREE_ARG char*
6 
7 double *dvector(long nl, long nh)
8 /* allocate a double vector with subscript range v[nl..nh] */
9 {
10  double *v;
11 
12  v=(double *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(double)));
13  return v-nl+NR_END;
14 }
15 
16 double **dmatrix(long nrl, long nrh, long ncl, long nch)
17 /* allocate a double matrix with subscript range m[nrl..nrh][ncl..nch] */
18 {
19  long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
20  double **m;
21 
22  /* allocate pointers to rows */
23  m=(double **) malloc((size_t)((nrow+NR_END)*sizeof(double*)));
24  m += NR_END;
25  m -= nrl;
26 
27  /* allocate rows and set pointers to them */
28  m[nrl]=(double *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(double)));
29  m[nrl] += NR_END;
30  m[nrl] -= ncl;
31 
32  for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
33 
34  /* return pointer to array of pointers to rows */
35  return m;
36 }
37 
38 void free_dvector(double *v, long nl, long nh)
39 /* free a double vector allocated with dvector() */
40 {
41  free((FREE_ARG) (v+nl-NR_END));
42 }
43 
44 void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch)
45 /* free a double matrix allocated by dmatrix() */
46 {
47  free((FREE_ARG) (m[nrl]+ncl-NR_END));
48  free((FREE_ARG) (m+nrl-NR_END));
49 }
50 
FREE_ARG
#define FREE_ARG
Definition: Util.cpp:5
nl
#define nl(x)
Definition: jf.h:17
free_dvector
void free_dvector(double *v, long nl, long nh)
Definition: Util.cpp:38
v
Double v
Definition: Headers.h:95
dmatrix
double ** dmatrix(long nrl, long nrh, long ncl, long nch)
Definition: Util.cpp:16
NR_END
#define NR_END
Definition: Util.cpp:4
free_dmatrix
void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch)
Definition: Util.cpp:44
dvector
double * dvector(long nl, long nh)
Definition: Util.cpp:7