int main(int argc, char *args[]) { int argchar; char* progname = args[0]; plot_args_t pargs; plotxy_t* xy; plotimage_t* img; int loglvl = LOG_MSG; // log errors to stderr, not stdout. errors_log_to(stderr); plotstuff_init(&pargs); pargs.fout = stdout; pargs.outformat = PLOTSTUFF_FORMAT_PNG; xy = plotstuff_get_config(&pargs, "xy"); img = plotstuff_get_config(&pargs, "image"); assert(xy); assert(img); plotstuff_set_color(&pargs, "white"); plotstuff_set_bgcolor(&pargs, "black"); img->format = PLOTSTUFF_FORMAT_PPM; while ((argchar = getopt(argc, args, OPTIONS)) != -1) switch (argchar) { case 'v': loglvl++; break; case 'C': plotstuff_set_color(&pargs, optarg); break; case 'b': plotstuff_set_bgcolor(&pargs, "optarg"); break; case 'o': pargs.outfn = optarg; break; case 'X': plot_xy_set_xcol(xy, optarg); break; case 'Y': plot_xy_set_ycol(xy, optarg); break; case 'P': pargs.outformat = PLOTSTUFF_FORMAT_PPM; break; case 'J': pargs.outformat = PLOTSTUFF_FORMAT_PDF; break; case 'p': img->format = PLOTSTUFF_FORMAT_PNG; break; case 'I': plot_image_set_filename(img, optarg); break; case 'S': xy->scale = atof(optarg); break; case 'i': plot_xy_set_filename(xy, optarg); break; case 'x': xy->xoff = atof(optarg); break; case 'y': xy->yoff = atof(optarg); break; case 'W': pargs.W = atoi(optarg); break; case 'H': pargs.H = atoi(optarg); break; case 'n': xy->firstobj = atoi(optarg); break; case 'N': xy->nobjs = atoi(optarg); break; case 'e': xy->ext = atoi(optarg); break; case 'r': pargs.markersize = atof(optarg); break; case 'w': pargs.lw = atof(optarg); break; case 's': plotstuff_set_marker(&pargs, optarg); break; case 'h': printHelp(progname); exit(0); case '?': default: printHelp(progname); exit(-1); } if (optind != argc) { printHelp(progname); exit(-1); } if (!xy->fn) { printHelp(progname); exit(-1); } log_init(loglvl); log_to(stderr); fits_use_error_system(); if (img->fn) { if (plot_image_setsize(&pargs, img)) { ERROR("Failed to set plot size from image"); exit(-1); } plotstuff_run_command(&pargs, "image"); } else { if (pargs.W == 0 || pargs.H == 0) { if (plot_xy_setsize(&pargs, xy)) { ERROR("Failed to set plot size from xylist"); exit(-1); } } } plotstuff_run_command(&pargs, "xy"); plotstuff_output(&pargs); plotstuff_free(&pargs); return 0; }
void test_plot_wcs1(CuTest* tc) { plot_args_t myargs; plot_args_t* pargs = &myargs; int W, H; plotxy_t* xy; //plotimage_t* img; log_init(LOG_VERB); W = H = 5; plotstuff_init(pargs); plotstuff_set_size(pargs, W, H); pargs->outformat = PLOTSTUFF_FORMAT_PNG; pargs->outfn = "test-out1.png"; plotstuff_set_color(pargs, "black"); plotstuff_run_command(pargs, "fill"); plotstuff_output(pargs); plotstuff_free(pargs); // perfectly centered circle. plotstuff_init(pargs); plotstuff_set_size(pargs, W, H); pargs->outformat = PLOTSTUFF_FORMAT_PNG; pargs->outfn = "test-out2.png"; plotstuff_set_color(pargs, "black"); plotstuff_run_command(pargs, "fill"); xy = plotstuff_get_config(pargs, "xy"); plot_xy_vals(xy, 3, 3); plotstuff_set_color(pargs, "white"); plotstuff_set_marker(pargs, "circle"); plotstuff_set_markersize(pargs, 1); plotstuff_run_command(pargs, "xy"); plotstuff_output(pargs); plotstuff_free(pargs); // perfectly centered circle. plotstuff_init(pargs); plotstuff_set_size(pargs, W, H); pargs->outformat = PLOTSTUFF_FORMAT_PNG; pargs->outfn = "test-out3.png"; plotstuff_set_color(pargs, "black"); plotstuff_run_command(pargs, "fill"); xy = plotstuff_get_config(pargs, "xy"); plot_xy_vals(xy, 2, 2); plot_xy_set_offsets(xy, 0, 0); plotstuff_set_color(pargs, "white"); plotstuff_set_marker(pargs, "circle"); plotstuff_set_markersize(pargs, 1); plotstuff_run_command(pargs, "xy"); plotstuff_output(pargs); plotstuff_free(pargs); { unsigned char* img; int ww, hh; int i; img = cairoutils_read_png("test-out2.png", &ww, &hh); CuAssertPtrNotNull(tc, img); CuAssertIntEquals(tc, W, ww); CuAssertIntEquals(tc, H, hh); printf("image:\n"); for (i=0; i<W*H; i++) { printf("%02x ", (int)img[i*4]); if (i%W == (W-1)) printf("\n"); } printf("\n"); /* 00 00 00 00 00 00 80 e8 80 00 00 f3 44 f3 00 00 7c e8 7c 00 00 00 00 00 00 */ } }