vector_write

Digital Signal Processing Library

Voice Lab

Program name: vector_write

Language: C

In file: file_lib.c

Objective: write vector to file.

Usage: void vector_write(double *vector, int vector_width, FILE *out_file, int options);

Parameters:

  • vector - vetor to be written.
  • vector_width - number of elements in each vector.
  • out_file - file pointer to write to
  • options - options define whether or not the first element is written out to the file.
Return:
  • void

Mathematical Description:

Comments: Routine to write vector to file

User Comments

Code:

void vector_write(double *vector, int vector_width, FILE *out_file, int options)
{
        int i, offset;

        /*
        ** The idea of the options flag is to make the program more flexible.
        ** The first bit is reserved for the offset.
        **   The offset can be 0 or 1. Under normal circumstances it will be 0.
        **   In the case of arrays being 1 more than the order,
        **   and needing to disregard the first element, set offset to 1.
        ** The fifth bit (0x10) is reserverd for the mode.
        **   If mode is 0, each value will be on a separate line.
        **   If mode is 1, each vector will occupy only one line.
        */

        offset = options & 0x01;

        if(options & 0x10) {
                for(i = offset; i < (vector_width+offset); i++) {
                        if(vector[i] >= 0) {
                                fprintf(out_file, " %lf ", vector[i]);
                        } else {
                                /* compensate for the minus sign */
                                fprintf(out_file, "%lf ", vector[i]);
                        }
                }
                fprintf(out_file, "\n");
        } else {
                for(i = offset; i < (vector_width+offset); i++) {
                        fprintf(out_file, "%lf\n", vector[i]);
                }
        }
        return;
}