123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #include "defs.h"
- #define NR_END 1
- #define FREE_ARG char*
- extern char errstr[200];
- void nrerror(char error_text[])
- {
- fprintf(stderr,"Numerical Recipes run-time error...\n");
- fprintf(stderr,"%s\n",error_text);
- fprintf(stderr,"...now exiting to system...\n");
- exit(1);
- }
- float *fvector(int nl, int nh)
- {
- float *v;
- v=(float *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float)));
- if (!v) nrerror("allocation failure in fvector()");
- return v-nl+NR_END;
- }
- void free_fvector(float *v, int nl, int nh)
- {
- free((FREE_ARG) (v+nl-NR_END));
- }
- float **fmatrix(int nrl, int nrh, int ncl, int nch)
- {
- int i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
- float **m;
-
- m=(float **) malloc((size_t)((nrow+NR_END)*sizeof(float*)));
- if (!m) nrerror("allocation failure 1 in matrix()");
- m += NR_END;
- m -= nrl;
-
- m[nrl]=(float *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float)));
- if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
- m[nrl] += NR_END;
- m[nrl] -= ncl;
- for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-
- return m;
- }
- void free_fmatrix(float **m, int nrl, int nrh, int ncl, int nch)
- {
- free((FREE_ARG) (m[nrl]+ncl-NR_END));
- free((FREE_ARG) (m+nrl-NR_END));
- }
- int copy_grid_geometry(FLOAT_GRID *grid_old, FLOAT_GRID *grid_new)
- {
- grid_new->start.x = grid_old->start.x;
- grid_new->start.y = grid_old->start.y;
- grid_new->start.z = grid_old->start.z;
- grid_new->inc.x = grid_old->inc.x;
- grid_new->inc.y = grid_old->inc.y;
- grid_new->inc.z = grid_old->inc.z;
- grid_new->x_count = grid_old->x_count;
- grid_new->y_count = grid_old->y_count;
- grid_new->z_count = grid_old->z_count;
- return(SUCCESS);
- }
- int binSearch(float *a, float searchnum, int M)
- {
- int found, mid, top, bottom;
- bottom = 0;
- top = M-1;
- found = 0;
-
-
- if(searchnum >= a[top])
- return(M);
- if(searchnum <= a[bottom])
- return(-1);
- while(!found)
- {
- mid = (top + bottom) / 2;
- if(searchnum == a[mid])
- found = 1;
- else
- if(searchnum < a[mid])
- top = mid - 1;
- else
- if(searchnum > a[mid + 1])
- bottom = mid + 1;
- else
- found = 1;
- }
- return(mid);
- }
|