X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fifinfo.cpp;h=6149c9e634faea48a2875c88677fca5070554dc2;hb=6850134e4711a842cc7c0a306a9e4243df06b952;hp=8ef592a92e46d721527f5975bfe3ac844ae6586b;hpb=f173363bba9997045e5ec825e64d6253ec4da235;p=ctsim.git diff --git a/src/ifinfo.cpp b/src/ifinfo.cpp index 8ef592a..6149c9e 100644 --- a/src/ifinfo.cpp +++ b/src/ifinfo.cpp @@ -1,22 +1,15 @@ /***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: ifinfo.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $ -** $Log: ifinfo.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 +** FILE IDENTIFICATION ** -** 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 @@ -56,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; @@ -110,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]); @@ -125,115 +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); - im->adf.fileRead (); + 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; - string str; - - im->adf.labelRead (label, i); - label.getDateString (str); - - 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; + im->printLabels (cout); - maxbin = nbin - 1; - ImageFileArray v = im->adf.getArray(); - int nx = im->adf.nx; - int ny = im->adf.ny; + if (opt_stats) { + cout << "Size: (" << im->nx() << "," << im->ny() << ")" << endl; + im->printStatistics (cout); + } - 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; - } - - 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)); - fprintf(stdout,"nx=%d\n", nx); - fprintf(stdout,"ny=%d\n", 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); } @@ -241,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