/*! * Test writing of files to disk. * * I have used it to benchmark and error-check NFS mounted file systems. */ int test_fwrite(const char *dir) { FILE *f; char fname[1024]; char path[1024]; uint m, n; uint i, j; char *buf; printf("m:"); scanf("%d", &m); printf("n:"); scanf("%d", &n); for (i = 0; i <= m; i++) { for (j = 1; j <= n; j++) { sprintf(fname, "fwritetest_%05d_%05d", i, j); sprintf(path, "%s/%s", dir, fname); f = fopen(path, "w"); if (f) { lprintf("successfully opened file: %s\n", path); } else { leprintf("error: could not open file: %s: %s\n", path, strerror(errno)); return -1; } buf = (char*)malloc(j); size_t ret = fwrite(buf, 1, j, f); if (ret == j) { lprintf("wrote %d bytes to file: %s\n", j, path); } else { leprintf("error: could not write to file: %s: %s\n", path, strerror(errno)); return -1; } free(buf); fclose(f); } } return 0; }
void x11_btv2d(const XDpy * dpy, XAnim * anim, int x, int y, uint w, uint h, Bitvec * btv) { uint i, j; if (w * h != btv->l) { leprintf("Dimension mismatch.\n"); return; } for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { x11_setFG(dpy, &anim->win, bitvec_get(btv, i * w + j) ? COLOR_WHITE : COLOR_BLACK); x11_dPnt(dpy, anim, x + j, y + i); } } }
void CPAL_gen(color_t* c, int l, CPAL_t cpal) { switch (cpal) { case CPAL_GRAY: { /* see: /usr/share/octave/2.1.34/m/image/gray.m */ color_t ctrl[] = { COLOR_BLACK, COLOR_WHITE }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); break; } case CPAL_HOT: { /* Borrowed from Matlab */ color_t ctrl[] = { COLOR_BLACK, COLOR_RED, COLOR_YELLOW, COLOR_WHITE }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); break; } case CPAL_COOL: { /* Borrowed from Matlab */ color_t ctrl[] = { COLOR_BLACK, COLOR_BLUE, COLOR_CYAN, COLOR_WHITE }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); ; break; } case CPAL_OCEAN: { /* Borrowed from /usr/share/octave/2.1.34/m/image/ocean.m */ color_t ctrl[] = { COLOR_BLACK, COLOR_RGB(0, 0, 255/3), COLOR_RGB(0, 255/2, 2*255/3), COLOR_RGB(255, 255, 255) }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); break; } case CPAL_SPECTRUM: { color_t ctrl[] = { COLOR_BLUE, COLOR_CYAN, COLOR_GREEN, COLOR_YELLOW, COLOR_RED }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); break; } case CPAL_CYCLIC_SPECTRUM: { color_t ctrl[] = { COLOR_BLUE, COLOR_CYAN, COLOR_GREEN, COLOR_YELLOW, COLOR_RED, COLOR_DARK_MAGENTA, COLOR_BLUE }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); break; } case CPAL_TRAFFIC_LIGHTS: { color_t ctrl[] = { COLOR_GREEN, COLOR_YELLOW, COLOR_RED }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); break; } case CPAL_RGBR: { color_t ctrl[] = { COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_RED }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); break; } case CPAL_GOTT_OCH_BLANDAT: { color_t ctrl[] = { COLOR_RED, COLOR_MEDIUM_SEA_GREEN, COLOR_ORANGE, color_genRGB(192,192,0) }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); break; } case CPAL_PASTELLS_MEDIUM: { color_t ctrl[] = { color_genRGB(244, 176, 176), color_genRGB(234, 215, 159), color_genRGB(244, 243, 154), color_genRGB(176, 244, 209), color_genRGB(176, 215, 244), color_genRGB(192, 176, 244), color_genRGB(239, 196, 235) }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); } case CPAL_RAINBOW: { color_t ctrl[] = { PURE_RED, PURE_ORANGE, PURE_YELLOW, PURE_GREEN, PURE_CYAN, PURE_BLUE, PURE_VIOLET }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); } case CPAL_NICE_ALPHA: { color_t ctrl[] = { LIGHT_YELLOW, NAVAJO_WHITE, color_genRGB(188, 232, 174) }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); } case CPAL_COLORS_ON_LIGHT: { color_t ctrl[] = { DARK_RED, FOREST_GREEN, ROYAL_BLUE, LIGHT_YELLOW2, LIGHT_CYAN2, DARK_MAGENTA, DARK_ORANGE2, VIOLET_RED2, MEDIUM_PURPLE2 }; colorarray_ramps(c, l, ctrl, ARRL(ctrl)); } default: { color_t ctrl[] = { COLOR_BLACK, COLOR_WHITE }; leprintf("Unknown color palette %d. Defaulting to GRAY.\n", cpal); colorarray_ramps(c, l, ctrl, ARRL(ctrl)); break; } } }
void x11_fplot(const XDpy * dpy, XAnim * anim, XFall * fall, color_t * pal, uint pal_len, int x, int y, uint w, uint h, double *xdat, double *ydat, uint l, double samp_rate, const char *xtitle, const char *ytitle, const char *fx_title, const char *fy_title, int is_log, box2d * taxx, box2d * faxx, uint axxhint) { int x1, y1, w1, h1; int x2, y2, w2, h2; int x3, y3, w3, h3; w1 = w; w2 = w; w3 = w; h1 = h / 3; h2 = h / 3; h3 = h - h1 - h2; x1 = x; x2 = x; x3 = x; y1 = y; y2 = y + h1; y3 = y + 2 * h1; if (taxx) { double xmin, xmax; double ymin, ymax; /* get extremes and spans */ darray_extremes(xdat, l, &xmin, &xmax); darray_extremes(ydat, l, &ymin, &ymax); if (axxhint == 0) { box2d_set(taxx, xmin, ymin, xmax, ymax); } else { /* extend it */ taxx->l.x = MIN2(taxx->l.x, xmin); taxx->l.y = MIN2(taxx->l.y, ymin); taxx->u.x = MAX2(taxx->u.x, xmax); taxx->u.y = MAX2(taxx->u.y, ymax); } x11_plot(dpy, anim, x1, y1, w1, h1, xdat, ydat, l, taxx->l.x, taxx->u.x, taxx->l.y, taxx->u.y, xtitle, ytitle); } else { x11_plot_autoaxis(dpy, anim, x1, y1, w1, h1, xdat, ydat, l, xtitle, ytitle); } double *xi = darray_calloc(l); /* zeros */ double *tre = darray_malloc(l); /* real part of time domain data */ double *tim = darray_malloc(l); /* imag part of time domain data */ double *abs = darray_malloc(l); uint lo2 = l / 2; double *fscale = darray_malloc(lo2); darray_ramp(fscale, lo2, 0, samp_rate / 2 / lo2); double *ydat_f = darray_malloc(l); uint i; /* windowing filter */ for (i = 0; i < l; i++) { ydat_f[i] = ydat[i] * double_blackman(i, l); } if (IS_BINPOW(l)) { /* only if length is a power of two */ /* can we perform an FFT */ darray_FFT(tre, tim, ydat_f, xi, l); darray_eud2D(abs, tre, tim, l); if (is_log) { uint i; for (i = 0; i < l; i++) { abs[i] = log10(abs[i]); } } if (faxx) { double xmin, xmax; double ymin, ymax; /* get extremes and spans */ darray_extremes(fscale, lo2, &xmin, &xmax); darray_extremes(abs, l, &ymin, &ymax); if (axxhint == 0) { box2d_set(faxx, xmin, ymin, xmax, ymax); } else { /* extend it */ faxx->l.x = MIN2(faxx->l.x, xmin); faxx->l.y = MIN2(faxx->l.y, ymin); faxx->u.x = MAX2(faxx->u.x, xmax); faxx->u.y = MAX2(faxx->u.y, ymax); } x11_plot(dpy, anim, x2, y2, w2, h2, fscale, abs, lo2, faxx->l.x, faxx->u.x, faxx->l.y, faxx->u.y, fx_title, fy_title); } else { x11_plot_autoaxis(dpy, anim, x2, y2, w2, h2, fscale, abs, lo2, fx_title, fy_title); } double ymin, ymax; darray_extremes(abs, l, &ymin, &ymax); double yspan = ymax - ymin; color_t * cols = (color_t*)malloc(lo2 * sizeof(color_t)); /* Waterfall */ for (i = 0; i < lo2; i++) { uint val = uint_clamp(0, (uint)((abs[i] - ymin) / yspan * (pal_len - 1)), pal_len - 1); cols[i] = pal[val]; } x11_appFall(dpy, anim, fall, cols, lo2); free(cols); x11_dWFall(dpy, anim, fall, x3, y3); } else { leprintf("%s: n=%u is not a power of two. Returning.\n", __FUNCTION__, l); } free(xi); free(tre); free(tim); free(abs); free(fscale); free(ydat_f); }