#include #include #include #include static void usage(char* progname) { fprintf(stderr, "usage: %s [options] \n" " -d output data only, do not produce gnuplot commands \n" " -h prints this message and exits \n" " -i [file] input file to use \n" ,progname); } static void header(FILE *fp, char *fname) { fprintf(fp, "set term x11\n" "set title '%s'\n" "set xlabel 'SECONDS'\n" "set ylabel 'OFFSET NANOSECONDS'\n" "set grid\n" "set xrange [180:1800]\n" "set yrange [0:1000]\n" "plot '-' notitle with points\n", fname); } int main(int argc, char *argv[]) { int sec, ns; int c, cnt, data_only = 0, index; FILE *infp, *outfp; char buf[PATH_MAX], *infile = NULL, *progname; /* Process the command line arguments. */ progname = strrchr(argv[0],'/'); progname = progname ? 1+progname : argv[0]; while (EOF != (c = getopt(argc,argv,"dhi:"))) { switch (c) { case 'd': data_only = 1; break; case 'i': infile = optarg; break; case 'h': usage(progname); return(0); case '?': usage(progname); return(-1); default: usage(progname); return(-1); } } if (!infile) { usage(progname); return -1; } snprintf(buf, sizeof(buf), "%s.gp", infile); infp = fopen(infile, "r"); if (!infp) { perror("fopen"); return -1; } outfp = fopen(buf, "w"); if (!outfp) { perror("fopen"); return -1; } if (!data_only) { header(outfp, infile); } while (fgets(buf, sizeof(buf), infp)) { cnt = sscanf(buf, "event index %d at %d.%d", &index, &sec, &ns); if (3 == cnt) { if (ns > 500000000) { ns = ns - 1000000000; } fprintf(outfp, "%d\n", ns); } if (feof(infp)) { break; } } if (!data_only) { fprintf(outfp, "e\n"); } fclose(infp); fclose(outfp); return 0; }