#define NumRec 1 /*------------------------------------------------------------------------*/ /* Numerical Recipes Routines */ /*------------------------------------------------------------------------*/ #if !defined(COMPLEX) #define COMPLEX typedef struct { double re,im; } Complex; #endif /* ===============> functions for error handling <================= */ void nrerror(char error_text[]) /* standard error handler */ { fprintf(stderr,"Run-time error...\n"); fprintf(stderr,"%s\n",error_text); fprintf(stderr,"...now exiting to system...\n"); exit(1); } /* ===============> functions for (de)allocation <================= */ double *dvector(long nl, long nh) /* allocate a double vector with subscript range v[nl..nh] */ { double *v; v=(double *)malloc((size_t) ((nh-nl+1+1)*sizeof(double))); if (!v) nrerror("allocation failure in dvector()"); return v-nl+1; } Complex *Cvector(long nl, long nh) /* allocate a Complex vector with subscript range v[nl..nh] */ { Complex *v; v=(Complex *)malloc((size_t) ((nh-nl+1+1)*sizeof(Complex))); if (!v) nrerror("allocation failure in Cvector()"); return v-nl+1; } int *intvector(long nl, long nh) /* allocate a integer vector with subscript range v[nl..nh] */ { int *v; v=(int *)malloc((size_t) ((nh-nl+1+1)*sizeof(long))); if (!v) nrerror("allocation failure in intvector()"); return v-nl+1; } long *Intvector(long nl, long nh) /* allocate a long vector with subscript range v[nl..nh] */ { long *v; v=(long *)malloc((size_t) ((nh-nl+1+1)*sizeof(long))); if (!v) nrerror("allocation failure in Intvector()"); return v-nl+1; } void free_dvector(double *v, long nl, long nh) /* free a double vector allocated with dvector() */ { free((char*) (v+nl-1)); } void free_Cvector(Complex *v, long nl, long nh) /* free a double vector allocated with dvector() */ { free((char*) (v+nl-1)); } void free_Ivector(long *v, long nl, long nh) /* free a double vector allocated with dvector() */ { free((char*) (v+nl-1)); } void free_ivector(int *v, long nl, long nh) /* free a double vector allocated with dvector() */ { free((char*) (v+nl-1)); }