X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fifinfo.cpp;h=6149c9e634faea48a2875c88677fca5070554dc2;hb=52107baf438f31ce8930b062e7fdebf95d3fd9ee;hp=136792db28bd586604bec92db0dc3bacdc1f064a;hpb=59ff52843f44bec1ecd1ad36625cdda305cc7ef8;p=ctsim.git diff --git a/src/ifinfo.cpp b/src/ifinfo.cpp index 136792d..6149c9e 100644 --- a/src/ifinfo.cpp +++ b/src/ifinfo.cpp @@ -1,28 +1,15 @@ /***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: ifinfo.cpp,v 1.3 2000/06/07 07:43:19 kevin Exp $ -** $Log: ifinfo.cpp,v $ -** Revision 1.3 2000/06/07 07:43:19 kevin -** Converted to IF data files and C++ -** -** Revision 1.2 2000/06/07 03:50:27 kevin -** *** empty log message *** -** -** Revision 1.1 2000/06/07 02:29:05 kevin -** Initial C++ versions +** FILE IDENTIFICATION ** -** 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 +** Name: ifinfo.cpp +** Purpose: Display information about an image file +** Programmer: Kevin Rosenberg +** Date Started: April 2000 ** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg ** +** $Id: ifinfo.cpp,v 1.13 2000/07/09 08:16:18 kevin Exp $ ** ** 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 @@ -62,26 +49,26 @@ static struct option my_options[] = void ifinfo_usage (const char *program) { - fprintf(stdout, "usage: %s infile [OPTIONS]\n", kbasename(program)); - fprintf(stdout, "Imagefile information\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"); + cout << "usage: " << fileBasename(program) << " image-filename [OPTIONS]" << endl; + cout << "Imagefile information" << endl; + cout << endl; + cout << " infile Name of input IF file" << endl; + cout << " --display Display image" << endl; + cout << " --labels Print image labels (default)" << endl; + cout << " --no-labels Do not print image labels" << endl; + cout << " --stats Print image statistics (default)" << endl; + cout << " --no-stats Do not print image statistics" << endl; + cout << " --debug Debug mode" << endl; + cout << " --verbose Verbose mode" << endl; + cout << " --version Print version" << endl; + cout << " --help Print this help message" << endl; } int ifinfo_main (int argc, char *const argv[]) { - ImageFile *im; - char *in_file; + ImageFile *im = NULL; + string in_file; int opt_verbose = 0; int opt_stats = 1; int opt_labels = 1; @@ -116,11 +103,11 @@ ifinfo_main (int argc, char *const argv[]) break; case O_VERSION: #ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); + cout << "Version " << VERSION << endl; #else - fprintf(stderr, "Unknown version number"); + cout << "Unknown version number" << endl; #endif - exit(0); + return (0); case O_HELP: case '?': ifinfo_usage(argv[0]); @@ -131,118 +118,27 @@ ifinfo_main (int argc, char *const argv[]) } } - if (optind + 1 != argc) - { - ifinfo_usage(argv[0]); - return (1); - } + if (optind + 1 != argc) { + ifinfo_usage (argv[0]); + return (1); + } in_file = argv[optind]; - im = new ImageFile (in_file); - if (! im->adf.fileRead ()) { - sys_error (ERR_WARNING, "Unable to read file %s", in_file); + im = new ImageFile (); + if (! im->fileRead (in_file)) { + sys_error (ERR_WARNING, "Unable to read file %s", in_file.c_str()); return (1); } if (opt_labels) - { - int nlabels = im->adf.getNumLabels(); - int i; - - for (i = 0; i < nlabels; i++) - { - Array2dFileLabel label; - im->adf.labelRead (label, i); - - string str; - label.getDateString (str); + im->printLabels (cout); - if (label.getLabelType() == Array2dFileLabel::L_HISTORY) { - cout << "History: " << label.getLabelString() << endl; - cout << " calc time = " << label.getCalcTime() << " secs" << endl; - cout << " Timestamp = " << str << endl; - } else if (label.getLabelType() == Array2dFileLabel::L_USER) { - cout << "Note: " << label.getLabelString() << endl; - cout << " Timestamp = %s" << str << endl; - } - } - } - - 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; - ImageFileArray v = im->getArray(); - int nx = im->nx(); - int ny = im->ny(); - - for (ix = 0; ix < nx; ix++) - { - for (iy = 0; iy < ny; iy++) - { - if (v[ix][iy] > maxfound) - maxfound = v[ix][iy]; - if (v[ix][iy] < minfound) - minfound = v[ix][iy]; - mean += 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 < nx; ix++) - { - for (iy = 0; iy < ny; iy++) - { - int b = (int) ((((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; - } + if (opt_stats) { + cout << "Size: (" << im->nx() << "," << im->ny() << ")" << endl; + im->printStatistics (cout); + } - mean /= nx * ny; - for (ix = 0; ix < nx; ix++) - { - for (iy = 0; iy < ny; iy++) - { - double diff = (v[ix][iy] - mean); - stddev += diff * diff; - } - } - stddev = sqrt(stddev / (nx * ny)); - cout << "nx=" << nx << endl; - cout << "nx=" << ny << endl; - cout << "min=" << minfound << endl; - cout << "max=" << maxfound << endl; - cout << "mean=" << mean << endl; - cout << "mode=" << mode << endl; - cout << "stddef=" << stddev << endl; - } - return (0); } @@ -250,6 +146,16 @@ ifinfo_main (int argc, char *const argv[]) int main (int argc, char *const argv[]) { - return (ifinfo_main(argc, argv)); + int retval = 1; + + try { + retval = ifinfo_main(argc, argv); + } catch (exception e) { + cerr << "Exception: " << e.what() << endl; + } catch (...) { + cerr << "Unknown exception" << endl; + } + + return (retval); } #endif