| 1 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 2 |
.IDENT alloc.c |
| 3 |
.MODULE subroutines |
| 4 |
.LANGUAGE C |
| 5 |
.AUTHOR Cristian Levin - ESO La Silla |
| 6 |
.PURPOSE Routines for memory [de]allocation |
| 7 |
.KEYWORDS Memory management. |
| 8 |
.VERSION 1.0 1-Feb-1991 Implementation |
| 9 |
|
| 10 |
090825 last modif |
| 11 |
------------------------------------------------------------*/ |
| 12 |
|
| 13 |
#include <stdio.h> |
| 14 |
#include <midas_def.h> |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
int *ivector( nl, nh ) |
| 19 |
int nl, nh; |
| 20 |
/* Allocates a int vector with range [nl..nh] */ |
| 21 |
{ |
| 22 |
int *v; |
| 23 |
|
| 24 |
v = (int *)osmmget( (unsigned) (nh-nl+1) * sizeof(int) ); |
| 25 |
return( v - nl ); |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
void free_ivector( v, nl, nh ) |
| 30 |
int *v; |
| 31 |
int nl, nh; |
| 32 |
/* Frees a vector allocated with ivector() */ |
| 33 |
{ |
| 34 |
osmmfree( (char *) (v + nl) ); |
| 35 |
} |
| 36 |
|
| 37 |
double **dmatrix( nrl, nrh, ncl, nch ) |
| 38 |
int nrl, nrh, ncl, nch; |
| 39 |
/* Allocates a double matrix with range [nrl..nrh][ncl..nch] */ |
| 40 |
{ |
| 41 |
int i; |
| 42 |
double **m; |
| 43 |
|
| 44 |
/* Allocate pointers to rows */ |
| 45 |
m = (double **)osmmget( (unsigned) (nrh-nrl+1) * sizeof(double *) ); |
| 46 |
m -= nrl; |
| 47 |
|
| 48 |
/* Allocate rows and set pointers to them */ |
| 49 |
for ( i = nrl; i <= nrh; i++ ) { |
| 50 |
m[i] = (double *)osmmget( (unsigned) (nch-ncl+1) * sizeof(double) ); |
| 51 |
m[i] -= ncl; |
| 52 |
} |
| 53 |
return( m ); |
| 54 |
} |
| 55 |
|
| 56 |
double *dvector( nl, nh ) |
| 57 |
int nl, nh; |
| 58 |
/* Allocates a double vector with range [nl..nh] */ |
| 59 |
{ |
| 60 |
double *v; |
| 61 |
|
| 62 |
v = (double *)osmmget( (unsigned) (nh-nl+1) * sizeof(double) ); |
| 63 |
return( v - nl ); |
| 64 |
} |
| 65 |
|
| 66 |
void free_dmatrix( m, nrl, nrh, ncl, nch ) |
| 67 |
double **m; |
| 68 |
int nrl, nrh, ncl, nch; |
| 69 |
/* Frees a matrix allocated with dmatrix() */ |
| 70 |
{ |
| 71 |
int i; |
| 72 |
|
| 73 |
for ( i = nrh; i >= nrl; i-- ) |
| 74 |
osmmfree( (char *) (m[i] + ncl) ); |
| 75 |
|
| 76 |
osmmfree( (char *) (m + nrl) ); |
| 77 |
} |
| 78 |
|
| 79 |
void free_dvector( v, nl, nh ) |
| 80 |
double *v; |
| 81 |
int nl, nh; |
| 82 |
/* Frees a vector allocated with dvector() */ |
| 83 |
{ |
| 84 |
osmmfree( (char *) (v + nl) ); |
| 85 |
} |
| 86 |
|
| 87 |
float **fmatrix( nrl, nrh, ncl, nch ) |
| 88 |
int nrl, nrh, ncl, nch; |
| 89 |
/* Allocates a float matrix with range [nrl..nrh][ncl..nch] */ |
| 90 |
{ |
| 91 |
int i; |
| 92 |
float **m; |
| 93 |
|
| 94 |
/* Allocate pointers to rows */ |
| 95 |
m = (float **)osmmget( (unsigned) (nrh-nrl+1) * sizeof(float *) ); |
| 96 |
m -= nrl; |
| 97 |
|
| 98 |
/* Allocate rows and set pointers to them */ |
| 99 |
for ( i = nrl; i <= nrh; i++ ) { |
| 100 |
m[i] = (float *)osmmget( (unsigned) (nch-ncl+1) * sizeof(float) ); |
| 101 |
m[i] -= ncl; |
| 102 |
} |
| 103 |
return( m ); |
| 104 |
} |
| 105 |
|
| 106 |
float *fvector( nl, nh ) |
| 107 |
int nl, nh; |
| 108 |
/* Allocates a float vector with range [nl..nh] */ |
| 109 |
{ |
| 110 |
float *v; |
| 111 |
|
| 112 |
v = (float *)osmmget( (unsigned) (nh-nl+1) * sizeof(float) ); |
| 113 |
return( v - nl ); |
| 114 |
} |
| 115 |
|
| 116 |
void free_fmatrix( m, nrl, nrh, ncl, nch ) |
| 117 |
float **m; |
| 118 |
int nrl, nrh, ncl, nch; |
| 119 |
/* Frees a matrix allocated with fmatrix() */ |
| 120 |
{ |
| 121 |
int i; |
| 122 |
|
| 123 |
for ( i = nrh; i >= nrl; i-- ) |
| 124 |
osmmfree( (char *) (m[i] + ncl) ); |
| 125 |
|
| 126 |
osmmfree( (char *) (m + nrl) ); |
| 127 |
} |
| 128 |
|
| 129 |
void free_fvector( v, nl, nh ) |
| 130 |
float *v; |
| 131 |
int nl, nh; |
| 132 |
/* Frees a vector allocated with fvector() */ |
| 133 |
{ |
| 134 |
osmmfree( (char *) (v + nl) ); |
| 135 |
} |
| 136 |
|
| 137 |
char **cmatrix( nrl, nrh, ncl, nch ) |
| 138 |
int nrl, nrh, ncl, nch; |
| 139 |
/* Allocates a char matrix with range [nrl..nrh][ncl..nch] */ |
| 140 |
{ |
| 141 |
int i; |
| 142 |
char **m; |
| 143 |
|
| 144 |
/* Allocate pointers to rows */ |
| 145 |
m = (char **)osmmget( (unsigned) (nrh-nrl+1) * sizeof(char *) ); |
| 146 |
m -= nrl; |
| 147 |
|
| 148 |
/* Allocate rows and set pointers to them */ |
| 149 |
for ( i = nrl; i <= nrh; i++ ) { |
| 150 |
m[i] = (char *)osmmget( (unsigned) (nch-ncl+1) * sizeof(char) ); |
| 151 |
m[i] -= ncl; |
| 152 |
} |
| 153 |
return( m ); |
| 154 |
} |
| 155 |
|
| 156 |
char *cvector( nl, nh ) |
| 157 |
int nl, nh; |
| 158 |
/* Allocates a char vector with range [nl..nh] */ |
| 159 |
{ |
| 160 |
char *v; |
| 161 |
|
| 162 |
v = (char *)osmmget( (unsigned) (nh-nl+1) * sizeof(char) ); |
| 163 |
return( v - nl ); |
| 164 |
} |
| 165 |
|
| 166 |
void free_cmatrix( m, nrl, nrh, ncl, nch ) |
| 167 |
char **m; |
| 168 |
int nrl, nrh, ncl, nch; |
| 169 |
/* Frees a matrix allocated with cmatrix() */ |
| 170 |
{ |
| 171 |
int i; |
| 172 |
|
| 173 |
for ( i = nrh; i >= nrl; i-- ) |
| 174 |
osmmfree( (char *) (m[i] + ncl) ); |
| 175 |
|
| 176 |
osmmfree( (char *) (m + nrl) ); |
| 177 |
} |
| 178 |
|
| 179 |
void free_cvector( v, nl, nh ) |
| 180 |
char *v; |
| 181 |
int nl, nh; |
| 182 |
/* Frees a vector allocated with cvector() */ |
| 183 |
{ |
| 184 |
osmmfree( (char *) (v + nl) ); |
| 185 |
} |