#include <math.h>
#include <malloc.h>
#include <stdio.h>
#include "matrix.h"


float **fmatrix(nrl, nrh, ncl, nch)
int nrl, nrh, ncl, nch;
{
    int i, j;
    float **m;
    
    m = (float **) malloc((unsigned) (nrh - nrl + 2) * sizeof(float *));
    if (!m)
	exit(printf("allocation failure 3 in matrix()"));
    m -= nrl;
    m++;

    m[nrl-1]=(float *) malloc((2 * sizeof(float)));
    m[nrl-1][0]= (float) (nrh - nrl + 1);
    m[nrl-1][1]= (float) (nch - ncl + 1);

    for (i = nrl; i <= nrh; i++) {
	m[i] = (float *) malloc((unsigned) (nch - ncl + 1) * sizeof(float));
	if (!m[i])
	    exit(printf("allocation failure 4 in matrix()"));
	m[i] -= ncl;
    }

    for (i = nrl; i <= nrh; i++)
	for (j = ncl; j <= nch; j++)
	    m[i][j] = 0.0;

   return(m);
}

