/* * A sample code drawing an image with gnuplot * A.Date * 3 May 2009 * */ #include /* drand48() */ #include #define N_XPIXELS 20 #define N_YPIXELS 20 #define RAND_SEED 20090503 #define SLEEP 100000000 void write_2d_data(unsigned char *img); unsigned char *alloc_1d_uchar(int n); FILE *gp; int main (int argc, char *argv[] ) { int i, n; int nx, ny; unsigned char *img; long seed = RAND_SEED; srand48(seed); nx = N_XPIXELS; ny = N_YPIXELS; n = nx*ny; img = alloc_1d_uchar(n); for (i=0; i < n; i++){ img[i] = (unsigned char)(255.0*drand48()); } gp = popen("gnuplot -geometry 480x480","w"); // gp = popen("gnuplot","w"); // fprintf(gp, "set terminal postscript eps color \"Times\" 20\n"); // fprintf(gp, "set terminal tgif\n"); // fprintf(gp, "set term x11\n"); fprintf(gp, "set yrange [] reverse\n"); fprintf(gp, "unset key\n"); // fprintf(gp, "set out 'image000.eps'\n"); // fprintf(gp, "set out 'image000.obj'\n"); fprintf(gp, "plot '-' matrix with image\n"); write_2d_data(img); fprintf(gp,"e\n"); fprintf(gp,"e\n"); fflush(gp); usleep(SLEEP); /* comment out when generate a file */ fclose(gp); free(img); } /* write data for gnuplot */ void write_2d_data(unsigned char *img){ int n_pixels = N_XPIXELS*N_YPIXELS; int i; for (i=0; i