[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/gnuplot/gnuplot-old/gnuplot-4-4-alpha/src/binary.c [Back]  [Original]

#ifndef lint
static char *RCSid() { return RCSid("$Id: binary.c,v 1.13 2007/10/02 18:18:57 sfeam Exp $"); }
#endif

/*
 * The addition of gnubin and binary, along with a small patch
 * to command.c, will permit gnuplot to plot binary files.
 * gnubin  - contains the code that relies on gnuplot include files
 *                     and other definitions
 * binary      - contains those things that are independent of those
 *                     definitions and files
 *
 * With these routines, hidden line removal of your binary data is possible!
 *
 * Last update:  3/29/92 memory allocation bugs fixed. jvdwoude@hut.nl
 *               3/09/92 spelling errors, general cleanup, use alloc with no
 *                       nasty fatal errors
 *               3/03/92 for Gnuplot 3.24.
 * Created from code for written by RKC for gnuplot 2.0b.
 *
 * Copyright (c) 1991,1992 Robert K. Cunningham, MIT Lincoln Laboratory
 *
 */

/* NOTE: a significant fraction of these routines is not called from
 * anywhere in gnuplot.  They're provided as a utility library for
 * people wanting to write binary files usable by gnuplot, as the
 * bf_test.c demo does it. */

#include "binary.h"

#include "alloc.h"
#include "util.h"

/* This routine scans the first block of the file to see if the file
 * is a binary file.  A file is considered binary if 10% of the
 * characters in it are not in the ascii character set. (values <
 * 128), or if a NUL is found.  I hope this doesn't break when used on
 * the bizzare PC's. */
int
is_binary_file(FILE *fp)
{
    int i, len;
    int odd;		/* Contains a count of the odd characters */
    long where;
    unsigned char *c;
    unsigned char buffer[512];

    if ((where = ftell(fp)) == -1) {	/* Find out where we start */
	fprintf(stderr, "Notice: Assuming unseekable data is not binary\n");
	return (FALSE);
    } else {
	rewind(fp);

	len = fread(buffer, sizeof(char), 512, fp);
	if (len = num_rows) {	/* We've got to make a bigger rowsize */
	    temp_array = extend_matrix(m, 0, num_rows - 1, 0, num_cols - 1,
				       num_rows + ADD_ROWS - 1, num_cols - 1);
	    rt = extend_vector(rt, 0, num_rows + ADD_ROWS - 1);

	    num_rows += ADD_ROWS;
	    m = temp_array;
	}
    }
    /*  finally we force the matrix to be the correct row size */
    /*  bug fixed. procedure called with incorrect 6th argument.
     *   jvdwoude@hut.nl */
    temp_array = retract_matrix(m, 0, num_rows - 1, 0, num_cols - 1, current_row - 1, num_cols - 1);
    /* Now save the things that change */
    *ret_matrix = temp_array;
    *row_title = retract_vector(rt, 0, current_row - 1);
    *column_title = ct;
    *nr = current_row;		/* Really the total number of rows */
    *nc = num_cols;
    return (TRUE);
}

/* This writes a matrix to a stream
 *
 * Note that our ranges are inclusive ranges--and we can specify
 * subsets.  This behaves similarly to the xrange and yrange operators
 * in gnuplot that we all are familiar with.
 */
int
fwrite_matrix(
    FILE *fout,
    float GPFAR * GPFAR *m,
    int nrl, int nrh, int ncl, int nch,
    float GPFAR *row_title,
    float GPFAR *column_title)
{
    int j;
    float length;
    int col_length;
    int status;
    float GPFAR *title = NULL;

    length = (float) (col_length = nch - ncl + 1);

    if ((status = fwrite((char *) &length, sizeof(float), 1, fout)) != 1) {
	fprintf(stderr, "fwrite 1 returned %d\n", status);
	return (FALSE);
    }
    if (!column_title) {
	column_title = title = alloc_vector(ncl, nch);
	for (j = ncl; j 

Web Proxy Viewer  |  New URL  |  Original Page