home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / fractal / kaos.lha / complib / imatrix.c < prev    next >
Encoding:
Text File  |  1990-01-26  |  592 b   |  34 lines

  1. /*
  2. ### allocate memory for an integer matrix ###
  3. */
  4.  
  5. int **imatrix(nrl,nrh,ncl,nch)
  6. int nrl,nrh,ncl,nch;
  7. {
  8.     int i;
  9.     int **m;
  10.     void free_ivector();
  11.  
  12.     m = (int **) malloc((unsigned) (nrh - nrl + 1) * sizeof(int *));
  13.     if(!m) {
  14.         system_mess_proc(1,"imatrix: memory allocation failure!");
  15.         return(0);
  16.     }
  17.     else {
  18.         m -= nrl;
  19.     }
  20.  
  21.     for(i=nrl;i<=nrh;i++){
  22.         m[i] = (int *) malloc((unsigned) (nch - ncl + 1) * sizeof(int));
  23.         if(!m[i]) {
  24.             system_mess_proc(1,"imatrix: memory allocation failure!");
  25.             free_imatrix(m,nrl,i-1,ncl,nch);
  26.             return(0);
  27.         }
  28.         else {
  29.             m[i] -= ncl;
  30.         }
  31.     }
  32.     return(m);
  33. }
  34.