X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fsdfinfo.cpp;fp=src%2Fsdfinfo.cpp;h=b6d71f8397e245547ec5e2d4b669e02cb0345d6c;hb=f173363bba9997045e5ec825e64d6253ec4da235;hp=0000000000000000000000000000000000000000;hpb=98f0fd3cec5ca685966017168efca4f14ebbf0b9;p=ctsim.git diff --git a/src/sdfinfo.cpp b/src/sdfinfo.cpp new file mode 100644 index 0000000..b6d71f8 --- /dev/null +++ b/src/sdfinfo.cpp @@ -0,0 +1,241 @@ +/***************************************************************************** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: sdfinfo.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $ +** $Log: sdfinfo.cpp,v $ +** Revision 1.1 2000/06/07 02:29:05 kevin +** Initial C++ versions +** +** Revision 1.3 2000/05/16 04:33:59 kevin +** Improved option processing +** +** Revision 1.2 2000/05/08 20:02:32 kevin +** ANSI C changes +** +** Revision 1.1.1.1 2000/04/28 13:02:44 kevin +** Initial CVS import for first public release +** +** +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License (version 2) as +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +/* FILE + * sdfinfo.c Display info on sdf files + */ + +#include "ct.h" + +enum { O_LABELS, O_STATS, O_NO_STATS, O_NO_LABELS, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG }; + +static struct option my_options[] = +{ + {"labels", 0, 0, O_LABELS}, + {"no-labels", 0, 0, O_NO_LABELS}, + {"stats", 0, 0, O_STATS}, + {"no-stats", 0, 0, O_NO_STATS}, + {"debug", 0, 0, O_DEBUG}, + {"verbose", 0, 0, O_VERBOSE}, + {"help", 0, 0, O_HELP}, + {"version", 0, 0, O_VERSION}, + {0, 0, 0, 0} +}; + +void +sdfinfo_usage (const char *program) +{ + fprintf(stdout, "sdfinfo_usage: %s infile [OPTIONS]\n", kbasename(program)); + fprintf(stdout, "Analyze an SDF2D file\n"); + fprintf(stdout, "\n"); + fprintf(stdout, " infile Name of input SDF file\n"); + fprintf(stdout, " --display Display image\n"); + fprintf(stdout, " --labels Print image labels (default)\n"); + fprintf(stdout, " --no-labels Do not print image labels\n"); + fprintf(stdout, " --stats Print image statistics (default)\n"); + fprintf(stdout, " --no-stats Do not print image statistics\n"); + fprintf(stdout, " --debug Debug mode\n"); + fprintf(stdout, " --verbose Verbose mode\n"); + fprintf(stdout, " --version Print version\n"); + fprintf(stdout, " --help Print this help message\n"); +} + +int +sdfinfo_main (int argc, char *const argv[]) +{ + IMAGE *im; + char *in_file; + int opt_verbose = 0; + int opt_stats = 1; + int opt_labels = 1; + int opt_debug = 0; + + while (1) + { + int c = getopt_long (argc, argv, "", my_options, NULL); + + if (c == -1) + break; + + switch (c) + { + case O_LABELS: + opt_labels = 1; + break; + case O_STATS: + opt_stats = 1; + break; + case O_NO_LABELS: + opt_labels = 0; + break; + case O_NO_STATS: + opt_stats = 0; + break; + case O_VERBOSE: + opt_verbose = 1; + break; + case O_DEBUG: + opt_debug = 0; + break; + case O_VERSION: +#ifdef VERSION + fprintf(stdout, "Version %s\n", VERSION); +#else + fprintf(stderr, "Unknown version number"); +#endif + exit(0); + case O_HELP: + case '?': + sdfinfo_usage(argv[0]); + return (0); + default: + sdfinfo_usage(argv[0]); + return (1); + } + } + + if (optind + 1 != argc) + { + sdfinfo_usage(argv[0]); + return (1); + } + + in_file = argv[optind]; + + im = image_load (in_file); + + if (opt_labels) + { + int nlabels = im->dfp_2d->dfp->num_label; + int i; + + for (i = 0; i < nlabels; i++) + { + SDF_BLK blk; + if (sdf_read_label(&blk.lab, i, im->dfp_2d->dfp) != SDF_OK) + break; + if (blk.lab.label_type == LT_HISTORY) { + fprintf(stdout, "History: %s\n", blk.lab.label_str); + fprintf(stdout, " calc time = %.2f secs\n", blk.lab.calc_time); + fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate)); + } else if (blk.lab.label_type == LT_TITLE) { + fprintf(stdout, "Title: %s\n", blk.lab.label_str); + fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate)); + } else if (blk.lab.label_type == LT_NOTE) { + fprintf(stdout, "Note: %s\n", blk.lab.label_str); + fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate)); + } + } + } + + if (opt_stats) + { + double minfound = HUGE_VAL, maxfound = -HUGE_VAL; + double mode = 0, mean = 0, stddev = 0; + double spread; + int hist[256]; + int ibin, nbin = 256; + int max_bin, max_binindex; + double maxbin; + int ix, iy; + + maxbin = nbin - 1; + for (ix = 0; ix < im->nx; ix++) + { + for (iy = 0; iy < im->ny; iy++) + { + if (im->v[ix][iy] > maxfound) + maxfound = im->v[ix][iy]; + if (im->v[ix][iy] < minfound) + minfound = im->v[ix][iy]; + mean += im->v[ix][iy]; + } + } + spread = maxfound - minfound; + if (spread == 0) + mode = minfound; + else + { + for (ibin = 0; ibin < nbin; ibin++) + hist[ibin] = 0; + for (ix = 0; ix < im->nx; ix++) + { + for (iy = 0; iy < im->ny; iy++) + { + int b = (int) ((((im->v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5); + hist[b]++; + } + } + max_binindex = 0; + max_bin = -1; + for (ibin = 0; ibin < nbin; ibin++) + { + if (hist[ibin] > max_bin) + { + max_bin = hist[ibin]; + max_binindex = ibin; + } + } + mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound; + } + + mean /= im->nx * im->ny; + for (ix = 0; ix < im->nx; ix++) + { + for (iy = 0; iy < im->ny; iy++) + { + double diff = (im->v[ix][iy] - mean); + stddev += diff * diff; + } + } + stddev = sqrt(stddev / (im->nx * im->ny)); + fprintf(stdout,"nx=%d\n", im->nx); + fprintf(stdout,"ny=%d\n", im->ny); + fprintf(stdout,"min=%f\n", minfound); + fprintf(stdout,"max=%f\n", maxfound); + fprintf(stdout,"mean=%f\n", mean); + fprintf(stdout,"mode=%f\n", mode); + fprintf(stdout,"stddev=%f\n", stddev); + } + + return (0); +} + +#ifndef NO_MAIN +int +main (int argc, char *const argv[]) +{ + return (sdfinfo_main(argc, argv)); +} +#endif