home *** CD-ROM | disk | FTP | other *** search
- /* example1.c */
-
- #include <stdio.h>
- #include <xxalloc.h>
-
- void mtxtsp(a, ib, ie, jb, je, b)
- double **a, **b;
- int ib, ie, jb, je;
- {
- int i, j;
- double tmp;
-
- for (i = ib; i <= ie; i++)
- for (j = i; j <= je; j++)
- {
- tmp = a[i][j];
- b[i][j] = a[j][i];
- b[j][i] = tmp;
- }
- return;
- }
-
- main()
- {
- double **a;
- int i, j;
-
- /* allocate a two dimensional array of doubles */
-
- a = d2_alloc(0, 9, 0, 9);
-
- /* initialize the array to 1.0 and print */
-
- d2_init(a, 0, 9, 0, 9, 1.0);
- printf("\ninitialized to 1\n");
- d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
-
- /* set the array equal to the 2*i + j and print*/
-
- for (i = 0; i < 10; i++)
- for (j = 0; j < 10; j++)
- a[i][j] = (double) (2*i + j);
- printf("\n2*i + j\n");
- d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
-
- /* take the transpose and print*/
-
- mtxtsp(a, 0, 9, 0, 9, a);
- printf("\ntransposed\n");
- d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
-
- /* renumber the indices a la FORTRAN and print*/
- /* the new indices must be used from now on */
-
- a = d2_renum(a, 0, 9, 0, 9, 1, 10, 1, 10);
- printf("\nrenumbered\n");
- d2_prnt(stdout, "%5.0f ", a, 1, 10, 1, 10);
-
- /* renumber the indices a la C and print */
- /* the new indices must be used from now on */
-
- a = d2_renum(a, 1, 10, 1, 10, 0, 9, 0, 9);
- printf("\nrenumbered again\n");
- d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
-
- /* free the allocated memory */
-
- d2_free(a, 0, 9, 0, 9);
- exit(0);
- }
-