| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995-2005 European Southern Observatory (ESO) |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License as |
| 6 |
published by the Free Software Foundation; either version 2 of |
| 7 |
the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public |
| 15 |
License along with this program; if not, write to the Free |
| 16 |
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, |
| 17 |
MA 02139, USA. |
| 18 |
|
| 19 |
Correspondence concerning ESO-MIDAS should be addressed as follows: |
| 20 |
Internet e-mail: [email protected] |
| 21 |
Postal address: European Southern Observatory |
| 22 |
Data Management Division |
| 23 |
Karl-Schwarzschild-Strasse 2 |
| 24 |
D 85748 Garching bei Muenchen |
| 25 |
GERMANY |
| 26 |
===========================================================================*/ |
| 27 |
|
| 28 |
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ |
| 29 |
/* .IDENT .prg */ |
| 30 |
/* .AUTHORS Pascal Ballester (ESO/Garching) */ |
| 31 |
/* Cristian Levin (ESO/La Silla) */ |
| 32 |
/* .KEYWORDS Spectroscopy, Long-Slit */ |
| 33 |
/* .PURPOSE */ |
| 34 |
/* .VERSION 1.0 Package Creation 17-MAR-1993 |
| 35 |
|
| 36 |
051021 last modif */ |
| 37 |
/* ------------------------------------------------------- */ |
| 38 |
|
| 39 |
/* |
| 40 |
* Define _POSIX_SOURCE to indicate |
| 41 |
* that this is a POSIX program |
| 42 |
*/ |
| 43 |
#define _POSIX_SOURCE 1 |
| 44 |
|
| 45 |
#include <stdlib.h> |
| 46 |
#include <stdio.h> |
| 47 |
|
| 48 |
void nrerror(error_text) |
| 49 |
char error_text[]; |
| 50 |
{ |
| 51 |
fprintf(stderr,"Exiting to system on run-time error...\n"); |
| 52 |
fprintf(stderr,"%s\n",error_text); |
| 53 |
fprintf(stderr,"...now exiting to system...\n"); |
| 54 |
exit(1); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
float *vector(nl,nh) |
| 60 |
int nl,nh; |
| 61 |
{ |
| 62 |
float *v; |
| 63 |
|
| 64 |
v = (float *)malloc((size_t)(nh-nl+1)*sizeof(float)); |
| 65 |
if (!v) nrerror("allocation failure in vector()"); |
| 66 |
return(v-nl); |
| 67 |
} |
| 68 |
|
| 69 |
int *ivector(nl,nh) |
| 70 |
int nl,nh; |
| 71 |
{ |
| 72 |
int *v; |
| 73 |
|
| 74 |
v = (int *)malloc((size_t) (nh-nl+1)*sizeof(int)); |
| 75 |
if (!v) nrerror("allocation failure in ivector()"); |
| 76 |
return(v-nl); |
| 77 |
} |
| 78 |
|
| 79 |
double *dvector(nl,nh) |
| 80 |
int nl,nh; |
| 81 |
{ |
| 82 |
double *v; |
| 83 |
|
| 84 |
v = (double *)malloc((size_t) (nh-nl+1)*sizeof(double)); |
| 85 |
if (!v) nrerror("allocation failure in dvector()"); |
| 86 |
return(v-nl); |
| 87 |
} |
| 88 |
|
| 89 |
float *fvector(nl,nh) |
| 90 |
int nl,nh; |
| 91 |
{ |
| 92 |
float *v; |
| 93 |
|
| 94 |
v = (float *)malloc((size_t) (nh-nl+1)*sizeof(float)); |
| 95 |
if (!v) nrerror("allocation failure in fvector()"); |
| 96 |
return(v-nl); |
| 97 |
} |
| 98 |
|
| 99 |
char *cvector(nl,nh) |
| 100 |
int nl,nh; |
| 101 |
{ |
| 102 |
char *v; |
| 103 |
|
| 104 |
v = (char *)malloc((size_t) (nh-nl+1) * sizeof(char)); |
| 105 |
if (!v) nrerror("allocation failure in cvector()"); |
| 106 |
return(v-nl); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
float **matrix(nrl,nrh,ncl,nch) |
| 111 |
int nrl,nrh,ncl,nch; |
| 112 |
{ |
| 113 |
int i; |
| 114 |
float **m; |
| 115 |
|
| 116 |
m = (float **)malloc((size_t) (nrh-nrl+1)*sizeof(float*)); |
| 117 |
if (!m) nrerror("allocation failure 1 in matrix()"); |
| 118 |
m -= nrl; |
| 119 |
|
| 120 |
for(i=nrl;i<=nrh;i++) { |
| 121 |
m[i]= (float *)malloc((size_t) (nch-ncl+1)*sizeof(float)); |
| 122 |
if (!m[i]) nrerror("allocation failure 2 in matrix()"); |
| 123 |
m[i] -= ncl; |
| 124 |
} |
| 125 |
return(m); |
| 126 |
} |
| 127 |
|
| 128 |
float **fmatrix(nrl,nrh,ncl,nch) |
| 129 |
int nrl,nrh,ncl,nch; |
| 130 |
{ |
| 131 |
return matrix(nrl,nrh,ncl,nch); |
| 132 |
} |
| 133 |
|
| 134 |
double **dmatrix(nrl,nrh,ncl,nch) |
| 135 |
int nrl,nrh,ncl,nch; |
| 136 |
{ |
| 137 |
int i; |
| 138 |
double **m; |
| 139 |
|
| 140 |
m = (double **)malloc((size_t) (nrh-nrl+1)*sizeof(double*)); |
| 141 |
if (!m) nrerror("allocation failure 1 in dmatrix()"); |
| 142 |
m -= nrl; |
| 143 |
|
| 144 |
for(i=nrl;i<=nrh;i++) { |
| 145 |
m[i] = (double *)malloc((size_t) (nch-ncl+1)*sizeof(double)); |
| 146 |
if (!m[i]) nrerror("allocation failure 2 in dmatrix()"); |
| 147 |
m[i] -= ncl; |
| 148 |
} |
| 149 |
return(m); |
| 150 |
} |
| 151 |
|
| 152 |
int **imatrix(nrl,nrh,ncl,nch) |
| 153 |
int nrl,nrh,ncl,nch; |
| 154 |
{ |
| 155 |
int i,**m; |
| 156 |
|
| 157 |
m = (int **)malloc((size_t) (nrh-nrl+1)*sizeof(int*)); |
| 158 |
if (!m) nrerror("allocation failure 1 in imatrix()"); |
| 159 |
m -= nrl; |
| 160 |
|
| 161 |
for(i=nrl;i<=nrh;i++) { |
| 162 |
m[i] = (int *)malloc((size_t) (nch-ncl+1)*sizeof(int)); |
| 163 |
if (!m[i]) nrerror("allocation failure 2 in imatrix()"); |
| 164 |
m[i] -= ncl; |
| 165 |
} |
| 166 |
return(m); |
| 167 |
} |
| 168 |
|
| 169 |
float **submatrix(a,oldrl,oldrh,oldcl,oldch,newrl,newcl) |
| 170 |
float **a; |
| 171 |
int oldrl,oldrh,oldcl,oldch,newrl,newcl; |
| 172 |
{ |
| 173 |
int i,j; |
| 174 |
float **m; |
| 175 |
|
| 176 |
oldch++; /* Not use. This is to avoid LintPlus warning */ |
| 177 |
m = (float **)malloc((size_t) (oldrh-oldrl+1)*sizeof(float*)); |
| 178 |
if (!m) nrerror("allocation failure in submatrix()"); |
| 179 |
m -= newrl; |
| 180 |
|
| 181 |
for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+oldcl-newcl; |
| 182 |
|
| 183 |
return(m); |
| 184 |
} |
| 185 |
|
| 186 |
char **cmatrix(nrl,nrh,ncl,nch) |
| 187 |
int nrl,nrh,ncl,nch; |
| 188 |
{ |
| 189 |
int i; |
| 190 |
char **m; |
| 191 |
|
| 192 |
m = (char **)malloc((size_t) (nrh-nrl+1) * sizeof(char *)); |
| 193 |
if (!m) nrerror("allocation failure in cmatrix()"); |
| 194 |
m -= nrl; |
| 195 |
|
| 196 |
for (i=nrl;i<=nrh;i++) { |
| 197 |
m[i] = (char *)malloc((size_t) (nch-ncl+1)*sizeof(char)); |
| 198 |
m[i] -= ncl; |
| 199 |
} |
| 200 |
return(m); |
| 201 |
} |
| 202 |
|
| 203 |
float **convert_matrix(a,nrl,nrh,ncl,nch) |
| 204 |
float *a; |
| 205 |
int nrl,nrh,ncl,nch; |
| 206 |
{ |
| 207 |
int i,j,nrow,ncol; |
| 208 |
float **m; |
| 209 |
|
| 210 |
nrow=nrh-nrl+1; |
| 211 |
ncol=nch-ncl+1; |
| 212 |
m = (float **)malloc((size_t) (nrow)*sizeof(float*)); |
| 213 |
if (!m) nrerror("allocation failure in convert_matrix()"); |
| 214 |
m -= nrl; |
| 215 |
for(i=0,j=nrl;i<=nrow-1;i++,j++) m[j]=a+ncol*i-ncl; |
| 216 |
return(m); |
| 217 |
} |
| 218 |
|
| 219 |
void free_vector(v,nl,nh) |
| 220 |
float *v; |
| 221 |
int nl,nh; |
| 222 |
{ |
| 223 |
nh++; /* No use. Just to avoid LintPlus warning */ |
| 224 |
free((v+nl)); |
| 225 |
} |
| 226 |
|
| 227 |
void free_ivector(v,nl,nh) |
| 228 |
int *v,nl,nh; |
| 229 |
{ |
| 230 |
nh++; /* No use. Just to avoid LintPlus warning */ |
| 231 |
free((v+nl)); |
| 232 |
} |
| 233 |
|
| 234 |
void free_dvector(v,nl,nh) |
| 235 |
double *v; |
| 236 |
int nl,nh; |
| 237 |
{ |
| 238 |
nh++; /* No use. Just to avoid LintPlus warning */ |
| 239 |
free((v+nl)); |
| 240 |
} |
| 241 |
|
| 242 |
void free_fvector(v,nl,nh) |
| 243 |
float *v; |
| 244 |
int nl,nh; |
| 245 |
{ |
| 246 |
nh++; /* No use. Just to avoid LintPlus warning */ |
| 247 |
free((v+nl)); |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
void free_cvector(v,nl,nh ) |
| 252 |
char *v; |
| 253 |
int nl,nh; |
| 254 |
{ |
| 255 |
nh++; /* No use. Just to avoid LintPlus warning */ |
| 256 |
free((v+nl)); |
| 257 |
} |
| 258 |
|
| 259 |
void free_matrix(m,nrl,nrh,ncl,nch) |
| 260 |
float **m; |
| 261 |
int nrl,nrh,ncl,nch; |
| 262 |
{ |
| 263 |
int i; |
| 264 |
|
| 265 |
nch++; /* No use. Just to avoid LintPlus warning */ |
| 266 |
for(i=nrh;i>=nrl;i--) free((m[i]+ncl)); |
| 267 |
free((m+nrl)); |
| 268 |
} |
| 269 |
|
| 270 |
void free_dmatrix(m,nrl,nrh,ncl,nch) |
| 271 |
double **m; |
| 272 |
int nrl,nrh,ncl,nch; |
| 273 |
{ |
| 274 |
int i; |
| 275 |
|
| 276 |
nch++; /* No use. Just to avoid LintPlus warning */ |
| 277 |
for(i=nrh;i>=nrl;i--) free((m[i]+ncl)); |
| 278 |
free((m+nrl)); |
| 279 |
} |
| 280 |
|
| 281 |
void free_imatrix(m,nrl,nrh,ncl,nch) |
| 282 |
int **m; |
| 283 |
int nrl,nrh,ncl,nch; |
| 284 |
{ |
| 285 |
int i; |
| 286 |
|
| 287 |
nch++; /* No use. Just to avoid LintPlus warning */ |
| 288 |
for(i=nrh;i>=nrl;i--) free((m[i]+ncl)); |
| 289 |
free((m+nrl)); |
| 290 |
} |
| 291 |
|
| 292 |
void free_submatrix(b,nrl,nrh,ncl,nch) |
| 293 |
float **b; |
| 294 |
int nrl,nrh,ncl,nch; |
| 295 |
{ |
| 296 |
nrh++;ncl++;nch++; /* No use. Just to avoid LintPlus warning */ |
| 297 |
free((b+nrl)); |
| 298 |
} |
| 299 |
|
| 300 |
void free_fmatrix(m,nrl,nrh,ncl,nch ) |
| 301 |
float **m; |
| 302 |
int nrl,nrh,ncl,nch; |
| 303 |
{ |
| 304 |
int i; |
| 305 |
|
| 306 |
nch++; /* No use. Just to avoid LintPlus warning */ |
| 307 |
for (i=nrh;i>=nrl;i--) |
| 308 |
free((m[i]+ncl)); |
| 309 |
free((m+nrl)); |
| 310 |
} |
| 311 |
|
| 312 |
void free_cmatrix(m,nrl,nrh,ncl,nch ) |
| 313 |
char **m; |
| 314 |
int nrl,nrh,ncl,nch; |
| 315 |
{ |
| 316 |
int i; |
| 317 |
|
| 318 |
nch++; /* No use. Just to avoid LintPlus warning */ |
| 319 |
for (i=nrh;i>=nrl;i--) |
| 320 |
free((m[i]+ncl)); |
| 321 |
free((m+nrl)); |
| 322 |
} |
| 323 |
|
| 324 |
void free_convert_matrix(b,nrl,nrh,ncl,nch) |
| 325 |
float **b; |
| 326 |
int nrl,nrh,ncl,nch; |
| 327 |
{ |
| 328 |
nrh++;ncl++;nch++; /* No use. Just to avoid LintPlus warning */ |
| 329 |
free((b+nrl)); |
| 330 |
} |