-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmcmlnr.c
91 lines (79 loc) · 2.21 KB
/
mcmlnr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/***********************************************************
* Copyright Univ. of Texas M.D. Anderson Cancer Center
* 1992.
*
* Some routines modified from Numerical Recipes in C,
* including error report, array or matrix declaration
* and releasing.
****/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
/***********************************************************
* Report error message to stderr, then exit the program
* with signal 1.
****/
void nrerror(char error_text[])
{
fprintf(stderr,"%s\n",error_text);
fprintf(stderr,"...now exiting to system...\n");
exit(1);
}
/***********************************************************
* Allocate an array with index from nl to nh inclusive.
*
* Original matrix and vector from Numerical Recipes in C
* don't initialize the elements to zero. This will
* be accomplished by the following functions.
****/
double *AllocVector(short nl, short nh)
{
double *v;
short i;
v=(double *)malloc((unsigned) (nh-nl+1)*sizeof(double));
if (!v) nrerror("allocation failure in vector()");
v -= nl;
for(i=nl;i<=nh;i++) v[i] = 0.0; /* init. */
return v;
}
/***********************************************************
* Allocate a matrix with row index from nrl to nrh
* inclusive, and column index from ncl to nch
* inclusive.
****/
double **AllocMatrix(short nrl,short nrh,
short ncl,short nch)
{
short i,j;
double **m;
m=(double **) malloc((unsigned) (nrh-nrl+1)
*sizeof(double*));
if (!m) nrerror("allocation failure 1 in matrix()");
m -= nrl;
for(i=nrl;i<=nrh;i++) {
m[i]=(double *) malloc((unsigned) (nch-ncl+1)
*sizeof(double));
if (!m[i]) nrerror("allocation failure 2 in matrix()");
m[i] -= ncl;
}
for(i=nrl;i<=nrh;i++)
for(j=ncl;j<=nch;j++) m[i][j] = 0.0;
return m;
}
/***********************************************************
* Release the memory.
****/
void FreeVector(double *v,short nl,short nh)
{
free((char*) (v+nl));
}
/***********************************************************
* Release the memory.
****/
void FreeMatrix(double **m,short nrl,short nrh,
short ncl,short nch)
{
short i;
for(i=nrh;i>=nrl;i--) free((char*) (m[i]+ncl));
free((char*) (m+nrl));
}