/* LISTING 7 */

#define DM3init

#define DM3type                 double **

DM3init;

DM3type DM3alloc(int r, int c) {
    int i;
    DM3type p;

    p = (DM3type)
        malloc((unsigned)(1+r)*sizeof(double *));  
    for( i=0; i<r; ++i )
        p[i] = (double *)
            malloc((unsigned)c*sizeof(double));
    p[i] = (double *)0;
    return p;
}

#define DM3item(x,i,j)          x[i][j]

void DM3free(DM3type x) {
    int i;

    for( i=0; x[i] != (double *)0; ++i ) {
        free((void *)x[i]);
    }
    free((void *)x);
}

main()
{
    DM3type m;
    int i,j;

    m = DM3alloc(7,13);
    for(i=0; i<7; ++i)
        for(j=0; j<13; ++j)
            DM3item(m,i,j) = (double) (i*100)+j;

    for(i=0; i<7; ++i) {
        for(j=0; j<13; ++j)
            printf("%3g ",DM3item(m,i,j) );
        printf("\n");
    }
    DM3free(m);
}

