home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / xxalloc / example1.c next >
Encoding:
C/C++ Source or Header  |  1989-10-16  |  1.4 KB  |  71 lines

  1. /* example1.c */
  2.  
  3. #include <stdio.h>
  4. #include <xxalloc.h>
  5.  
  6. void mtxtsp(a, ib, ie, jb, je, b)
  7. double **a, **b;
  8. int ib, ie, jb, je;
  9. {
  10.     int i, j;
  11.     double tmp;
  12.     
  13.     for (i = ib; i <= ie; i++)
  14.          for (j = i; j <= je; j++)
  15.         {
  16.             tmp = a[i][j];
  17.             b[i][j] = a[j][i];
  18.             b[j][i] = tmp;
  19.         }
  20.     return;
  21. }
  22.  
  23. main()
  24. {
  25.     double **a;
  26.     int i, j;
  27.     
  28. /* allocate a two dimensional array of doubles */
  29.  
  30.     a = d2_alloc(0, 9, 0, 9);
  31.  
  32. /* initialize the array to 1.0 and print */
  33.  
  34.     d2_init(a, 0, 9, 0, 9, 1.0);
  35.     printf("\ninitialized to 1\n");
  36.     d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  37.  
  38. /* set the array equal to the 2*i + j and print*/
  39.  
  40.     for (i = 0; i < 10; i++)
  41.         for (j = 0; j < 10; j++)
  42.             a[i][j] = (double) (2*i + j);
  43.     printf("\n2*i + j\n");
  44.     d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  45.  
  46. /* take the transpose and print*/
  47.  
  48.     mtxtsp(a, 0, 9, 0, 9, a);
  49.     printf("\ntransposed\n");
  50.     d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  51.  
  52. /* renumber the indices a la FORTRAN and print*/
  53. /* the new indices must be used from now on */
  54.  
  55.     a = d2_renum(a, 0, 9, 0, 9, 1, 10, 1, 10);
  56.     printf("\nrenumbered\n");
  57.     d2_prnt(stdout, "%5.0f ", a, 1, 10, 1, 10);
  58.  
  59. /* renumber the indices a la C and print */
  60. /* the new indices must be used from now on */
  61.  
  62.     a = d2_renum(a, 1, 10, 1, 10, 0, 9, 0, 9);
  63.     printf("\nrenumbered again\n");
  64.     d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  65.  
  66. /* free the allocated memory */
  67.  
  68.     d2_free(a, 0, 9, 0, 9);
  69.     exit(0);
  70. }        
  71.