/* IndexMem.C LAST MODIFIED: 04/11/97 */ /* Memory allocation subroutines from the */ /* test Numerical Computation Using C by */ /* R. Glassey and elsewhere... */ # include "Index.h" double *vecalloc(int nr) { double *x; x=(double *) calloc((unsigned) nr,sizeof(double)); if (x==NULL){ fprintf(stderr,"Unable to allocate dynamic memory"); exit(-1); } return x; } long *lvecalloc(int nr) { long *x; x=(long *) calloc((unsigned) nr,sizeof(long)); if (x==NULL){ fprintf(stderr,"Unable to allocate dynamic memory"); exit(-1); } return x; } /* See page 50 of Programs and Data Structures in C by Ammeraal */ /* for example from which the two following routines where drawn. */ char **cvecalloc(int nr) { char **x; x=(char **) malloc(nr * sizeof(char *)); if (x==NULL){ fprintf(stderr,"Unable to allocate dynamic memory"); exit(-1); } return x; } char *charalloc(int nr) { char *x; x=(char *) malloc(nr); if (x==NULL){ fprintf(stderr, "Unable to allocate dynamic memory"); exit(-1); } return x; } /* Alloc mem for the linked list structure. */ /* See Ammeraal, pg 102 */ node **nvecalloc(int nr) { node **x; x=(node **) malloc(nr * sizeof(node *)); if (x==NULL){ fprintf(stderr,"Unable to allocate dynamic memory"); exit(-1); } return x; } /* see Ammeraal, p 102 */ void AddNode(node **ND, char *zip, double gsamp, int nodenum) { node *p=ND[nodenum]; ND[nodenum]=(node *)malloc(sizeof(node)); if (ND[nodenum]==NULL) { printf("Unable to allocate dynamic memory"); exit(-1); } ND[nodenum]->zip=charalloc(strlen(zip)); strcpy(ND[nodenum]->zip,zip); ND[nodenum]->gsamp=gsamp; ND[nodenum]->var=0.0; ND[nodenum]->sigma=0.0; ND[nodenum]->accept=0; ND[nodenum]->index=0; ND[nodenum]->next=p; /* Uncomment to verify: */ /* printf("AddNode: %s \t %2.0f \t at %i\n", ND[nodenum]->zip,ND[nodenum]->index,nodenum); */ } float *fvecalloc(int nr) { float *x; x=(float *) calloc((unsigned) nr,sizeof(float)); if (x==NULL){ fprintf(stderr,"Unable to allocate dynamic memory"); exit(-1); } return x; } int *ivecalloc(int nr) { int *x; x=(int *) calloc((unsigned) nr,sizeof(int)); if (x==NULL){ fprintf(stderr,"Unable to allocate dynamic memory"); exit(-1); } return x; } double **matalloc(int nr, int nc) { int k; double **x; x=(double **) calloc((unsigned) nr, sizeof(double *)); if (x==NULL){ fprintf(stderr,"Unable to allocate dynamic memory"); exit(-1); } for (k=0;k= n) { allocp += n; return allocp - n; } else return 0; } double ****fouralloc(int nr1, int nc1, int nr2, int nc2) { int k, l, m; double ****x; x=(double ****) calloc((unsigned) nr1, sizeof(double ***)); if (x==NULL){ fprintf(stderr,"Unable to allocate dynamic memory"); exit(-1); } for (k=0;k