2 static char *RCSid() { return RCSid("$Id: bf_test.c,v 1.9.4.1 2007/10/02 18:20:30 sfeam Exp $"); }
7 * Test routines for binary files
8 * cc bf_test.c -o bf_test binary_files.o -lm
10 * Copyright (c) 1992 Robert K. Cunningham, MIT Lincoln Laboratory
14 /* Note that this file is not compiled into gnuplot, and so
15 * its more-restrictive copyright need not apply to gnuplot
16 * as a whole. (I think.)
29 /* we declare these here instead of including more header files */
30 void int_error __PROTO((int, const char *));
31 void FreeHelp __PROTO((void));
33 /* static functions */
34 static float function __PROTO((int p, double x, double y));
43 static range TheRange[] = {{-3,3,-2,2},
45 {-3,3,-3,3}}; /* Sampling rate causes this to go from -3:6*/
47 /*---- Stubs to make this work without including huge libraries ----*/
49 int_error(int dummy, const char *error_text)
51 (void) dummy; /* avoid -Wunused warning */
52 fprintf(stderr, "Fatal error..\n%s\n...now exiting to system ...\n",
63 /*---- End of stubs ----*/
67 function(int p, double x, double y)
69 float t = 0; /* HBB 990828: initialize */
73 t = 1.0 / (x * x + y * y + 1.0);
76 t = sin(x * x + y * y) / (x * x + y * y);
81 t = sin(x * x + y * y) / (x * x + y * y);
82 /* sinc modulated sinc */
83 t *= sin(4. * (x * x + y * y)) / (4. * (x * x + y * y));
88 fprintf(stderr, "Unknown function\n");
94 #define ISOSAMPLES 5.0
107 /* Create a few standard test interfaces */
109 for (plot = 0; plot < NUM_PLOTS; plot++) {
110 xsize = (TheRange[plot].xmax - TheRange[plot].xmin) * ISOSAMPLES + 1;
111 ysize = (TheRange[plot].ymax - TheRange[plot].ymin) * ISOSAMPLES + 1;
113 rt = alloc_vector(0, xsize - 1);
114 ct = alloc_vector(0, ysize - 1);
115 m = matrix(0, xsize - 1, 0, ysize - 1);
117 for (y = TheRange[plot].ymin, j = 0; j < ysize; j++, y += 1.0 / (double) ISOSAMPLES) {
121 for (x = TheRange[plot].xmin, i = 0; i < xsize; i++, x += 1.0 / (double) ISOSAMPLES) {
123 for (y = TheRange[plot].ymin, j = 0; j < ysize; j++, y += 1.0 / (double) ISOSAMPLES) {
124 m[i][j] = function(plot, x, y);
128 sprintf(buf, "binary%d", plot + 1);
129 if (!(fout = fopen(buf, "wb")))
130 int_error(0, "Could not open file");
132 fwrite_matrix(fout, m, 0, xsize - 1, 0, ysize - 1, rt, ct);
136 free_matrix(m, 0, xsize - 1, 0);
139 /* Show that it's ok to vary sampling rate, as long as x1<x2, y1<y2... */
140 xsize = (TheRange[plot].xmax - TheRange[plot].xmin) * ISOSAMPLES + 1;
141 ysize = (TheRange[plot].ymax - TheRange[plot].ymin) * ISOSAMPLES + 1;
143 rt = alloc_vector(0, xsize - 1);
144 ct = alloc_vector(0, ysize - 1);
145 m = matrix(0, xsize - 1, 0, ysize - 1);
147 for (y = TheRange[plot].ymin, j = 0; j < ysize; j++, y += 1.0 / (double) ISOSAMPLES) {
148 ct[j] = y > 0 ? 2 * y : y;
150 for (x = TheRange[plot].xmin, i = 0; i < xsize; i++, x += 1.0 / (double) ISOSAMPLES) {
151 rt[i] = x > 0 ? 2 * x : x;
152 for (y = TheRange[plot].ymin, j = 0; j < ysize; j++, y += 1.0 / (double) ISOSAMPLES) {
153 m[i][j] = function(plot, x, y);
157 sprintf(buf, "binary%d", plot + 1);
158 if (!(fout = fopen(buf, "wb")))
159 int_error(0, "Could not open file");
161 fwrite_matrix(fout, m, 0, xsize - 1, 0, ysize - 1, rt, ct);
165 free_matrix(m, 0, xsize - 1, 0);