print.c 1.45 KB
#include "tabledesign.h"

int
print_entry(FILE *op, double *entry, int order)

{
    int i, j, k, r;
    double **cmat, e;
    int overflow = 0;
    
    cmat = (double **) malloc(VECTORSIZE*sizeof(double *));
    for (i=0; i<VECTORSIZE; i++)
        cmat[i] = (double *) malloc(order*sizeof(double));
    
    /*
     * Initialize matrix
     */
    for (i=0; i<order; i++){
        for (j=0; j<i; j++)
            cmat[i][j] = 0.0;
        for (j=i; j<order; j++)
            cmat[i][j] = -entry[order-(j-i)];
    }
    for (i=order; i<VECTORSIZE; i++)
        for (j=0; j<order; j++)
            cmat[i][j] = 0.0;
    
    /*
     * Now recursively compute the VECTORSIZE rows
     */

    for (i=1; i<VECTORSIZE; i++)
        for (j=1; j<=order; j++)
            if (i-j >= 0)
                for (k=0; k<order; k++)
                    cmat[i][k] -= entry[j]*cmat[i-j][k];

    /*
     * Now print them out in columns
     */
    for (i=0; i<order; i++){
        for (j=0; j<VECTORSIZE; j++){
            e = VSCALE*cmat[j][i];
            if (e<0){
                r = (int) (e-0.5);
                if (r<MINCOEF)
                    overflow++;
            }
            else {
                r = (int) (e+0.5);
                if (r>MAXCOEF)
                    overflow++;
            }
            fprintf(op, "%5d ", r);
        }
        fprintf(op,"\n");
    }
                
    for (i=0; i<VECTORSIZE; i++)
        free(cmat[i]);
    free(cmat);

    return overflow;
}