home *** CD-ROM | disk | FTP | other *** search
- /*
- ### allocate memory for an integer matrix ###
- */
-
- int **imatrix(nrl,nrh,ncl,nch)
- int nrl,nrh,ncl,nch;
- {
- int i;
- int **m;
- void free_ivector();
-
- m = (int **) malloc((unsigned) (nrh - nrl + 1) * sizeof(int *));
- if(!m) {
- system_mess_proc(1,"imatrix: memory allocation failure!");
- return(0);
- }
- else {
- m -= nrl;
- }
-
- for(i=nrl;i<=nrh;i++){
- m[i] = (int *) malloc((unsigned) (nch - ncl + 1) * sizeof(int));
- if(!m[i]) {
- system_mess_proc(1,"imatrix: memory allocation failure!");
- free_imatrix(m,nrl,i-1,ncl,nch);
- return(0);
- }
- else {
- m[i] -= ncl;
- }
- }
- return(m);
- }
-