Annotation of OpenXM_contrib/gnuplot/bf_test.c, Revision 1.1
1.1 ! maekawa 1: #ifndef lint
! 2: static char *RCSid = "$Id: bf_test.c,v 1.11 1998/04/14 00:14:48 drd Exp $";
! 3: #endif
! 4:
! 5:
! 6: /*
! 7: * Test routines for binary files
! 8: * cc bf_test.c -o bf_test binary_files.o -lm
! 9: *
! 10: * Copyright (c) 1992 Robert K. Cunningham, MIT Lincoln Laboratory
! 11: *
! 12: */
! 13:
! 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.)
! 17: */
! 18:
! 19: #ifdef HAVE_CONFIG_H
! 20: #include "config.h"
! 21: #endif
! 22:
! 23: #include "ansichek.h"
! 24: #include "stdfn.h"
! 25: #define GPFAR /**/
! 26: #include "binary.h"
! 27: #include "alloc.h"
! 28:
! 29: void int_error __PROTO((char *error_text, int dummy));
! 30: void FreeHelp __PROTO((void));
! 31: float function __PROTO((int p, double x, double y));
! 32:
! 33:
! 34: typedef struct {
! 35: float xmin, xmax;
! 36: float ymin, ymax;
! 37: } range;
! 38:
! 39: #define NUM_PLOTS 2
! 40: range TheRange[] = {{-3,3,-2,2},
! 41: {-3,3,-3,3},
! 42: {-3,3,-3,3}};/* Sampling rate causes this to go from -3:6*/
! 43:
! 44: /*---- Stubs to make this work without including huge libraries ----*/
! 45: void int_error(error_text, dummy)
! 46: char *error_text;
! 47: int dummy;
! 48: {
! 49: fprintf(stderr, "Fatal error..\n%s\n...now exiting to system ...\n",
! 50: error_text);
! 51: exit(EXIT_FAILURE);
! 52: }
! 53:
! 54:
! 55: void FreeHelp()
! 56: {
! 57: }
! 58: /*---- End of stubs ----*/
! 59:
! 60:
! 61: float function(p, x, y)
! 62: int p;
! 63: double x, y;
! 64: {
! 65: float t;
! 66: switch (p) {
! 67: case 0:
! 68: t = 1.0 / (x * x + y * y + 1.0);
! 69: break;
! 70: case 1:
! 71: t = sin(x * x + y * y) / (x * x + y * y);
! 72: if (t > 1.0)
! 73: t = 1.0;
! 74: break;
! 75: case 2:
! 76: t = sin(x * x + y * y) / (x * x + y * y);
! 77: /* sinc modulated sinc */
! 78: t *= sin(4. * (x * x + y * y)) / (4. * (x * x + y * y));
! 79: if (t > 1.0)
! 80: t = 1.0;
! 81: break;
! 82: default:
! 83: fprintf(stderr, "Unknown function\n");
! 84: break;
! 85: }
! 86: return t;
! 87: }
! 88:
! 89: #define ISOSAMPLES (double)5
! 90: int main()
! 91: {
! 92: int plot;
! 93: int i, j;
! 94: float x, y;
! 95: float *rt, *ct;
! 96: float **m;
! 97: int xsize, ysize;
! 98: char buf[256];
! 99: FILE *fout;
! 100: /* Create a few standard test interfaces */
! 101:
! 102: for (plot = 0; plot < NUM_PLOTS; plot++) {
! 103: xsize = (TheRange[plot].xmax - TheRange[plot].xmin) * ISOSAMPLES + 1;
! 104: ysize = (TheRange[plot].ymax - TheRange[plot].ymin) * ISOSAMPLES + 1;
! 105:
! 106: rt = vector(0, xsize - 1);
! 107: ct = vector(0, ysize - 1);
! 108: m = matrix(0, xsize - 1, 0, ysize - 1);
! 109:
! 110: for (y = TheRange[plot].ymin, j = 0; j < ysize; j++, y += 1.0 / (double) ISOSAMPLES) {
! 111: ct[j] = y;
! 112: }
! 113:
! 114: for (x = TheRange[plot].xmin, i = 0; i < xsize; i++, x += 1.0 / (double) ISOSAMPLES) {
! 115: rt[i] = x;
! 116: for (y = TheRange[plot].ymin, j = 0; j < ysize; j++, y += 1.0 / (double) ISOSAMPLES) {
! 117: m[i][j] = function(plot, x, y);
! 118: }
! 119: }
! 120:
! 121: sprintf(buf, "binary%d", plot + 1);
! 122: if (!(fout = fopen(buf, "wb")))
! 123: int_error("Could not open file", 0);
! 124: else {
! 125: fwrite_matrix(fout, m, 0, xsize - 1, 0, ysize - 1, rt, ct);
! 126: }
! 127: free_vector(rt, 0, ysize - 1);
! 128: free_vector(ct, 0, xsize - 1);
! 129: free_matrix(m, 0, xsize - 1, 0, ysize - 1);
! 130: }
! 131:
! 132: /* Show that it's ok to vary sampling rate, as long as x1<x2, y1<y2... */
! 133: xsize = (TheRange[plot].xmax - TheRange[plot].xmin) * ISOSAMPLES + 1;
! 134: ysize = (TheRange[plot].ymax - TheRange[plot].ymin) * ISOSAMPLES + 1;
! 135:
! 136: rt = vector(0, xsize - 1);
! 137: ct = vector(0, ysize - 1);
! 138: m = matrix(0, xsize - 1, 0, ysize - 1);
! 139:
! 140: for (y = TheRange[plot].ymin, j = 0; j < ysize; j++, y += 1.0 / (double) ISOSAMPLES) {
! 141: ct[j] = y > 0 ? 2 * y : y;
! 142: }
! 143: for (x = TheRange[plot].xmin, i = 0; i < xsize; i++, x += 1.0 / (double) ISOSAMPLES) {
! 144: rt[i] = x > 0 ? 2 * x : x;
! 145: for (y = TheRange[plot].ymin, j = 0; j < ysize; j++, y += 1.0 / (double) ISOSAMPLES) {
! 146: m[i][j] = function(plot, x, y);
! 147: }
! 148: }
! 149:
! 150: sprintf(buf, "binary%d", plot + 1);
! 151: if (!(fout = fopen(buf, "wb")))
! 152: int_error("Could not open file", 0);
! 153: else {
! 154: fwrite_matrix(fout, m, 0, xsize - 1, 0, ysize - 1, rt, ct);
! 155: }
! 156: free_vector(rt, 0, ysize - 1);
! 157: free_vector(ct, 0, xsize - 1);
! 158: free_matrix(m, 0, xsize - 1, 0, ysize - 1);
! 159:
! 160: exit(EXIT_SUCCESS);
! 161: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>