#include "little-nr.h" void nrerror(char error_text[]) { fprintf(stderr,"Run-time error...\n"); fprintf(stderr,"%s\n",error_text); exit(1); } float *vector(long nl, long nh) { float *v; v=(float *)malloc((size_t) ((nh-nl+1+MY_END)*sizeof(float))); if (!v) nrerror("allocation error in vector()"); return v-nl+MY_END; } double *dvector(long nl, long nh) { double *v; v=(double *)malloc((size_t) ((nh-nl+1+MY_END)*sizeof(double))); if (!v) nrerror("allocation error in dvector()"); return v-nl+MY_END; } float **matrix(long nrl, long nrh, long ncl, long nch) { long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; float **m; m=(float **) malloc((size_t)((nrow+MY_END)*sizeof(float*))); if (!m) nrerror("allocation error 1 in matrix()"); m += MY_END; m -= nrl; m[nrl]=(float *) malloc((size_t)((nrow*ncol+MY_END)*sizeof(float))); if (!m[nrl]) nrerror("allocation error 2 in matrix()"); m[nrl] += MY_END; m[nrl] -= ncl; for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; return m; } double **dmatrix(long nrl, long nrh, long ncl, long nch) { long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; double **m; m=(double **) malloc((size_t)((nrow+MY_END)*sizeof(double*))); if (!m) nrerror("allocation error 1 in matrix()"); m += MY_END; m -= nrl; m[nrl]=(double *) malloc((size_t)((nrow*ncol+MY_END)*sizeof(double))); if (!m[nrl]) nrerror("allocation error 2 in matrix()"); m[nrl] += MY_END; m[nrl] -= ncl; for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; return m; } void free_vector(float *v, long nl, long nh) { free((char*) (v+nl-MY_END)); } void free_dvector(double *v, long nl, long nh) { free((char*) (v+nl-MY_END)); } void free_matrix(float **m, long nrl, long nrh, long ncl, long nch) { free((char*) (m[nrl]+ncl-MY_END)); free((char*) (m+nrl-MY_END)); } void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch) { free((char*) (m[nrl]+ncl-MY_END)); free((char*) (m+nrl-MY_END)); } int *ivector(long nl, long nh) { int *v; v=(int *)malloc((size_t) ((nh-nl+1+MY_END)*sizeof(int))); if (!v) nrerror("allocation failure in ivector()"); return v-nl+MY_END; } void free_ivector(int *v, long nl, long nh) { free((char *) (v+nl-MY_END)); }