1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: ifinfo.cpp,v 1.3 2000/06/07 07:43:19 kevin Exp $
6 ** $Log: ifinfo.cpp,v $
7 ** Revision 1.3 2000/06/07 07:43:19 kevin
8 ** Converted to IF data files and C++
10 ** Revision 1.2 2000/06/07 03:50:27 kevin
11 ** *** empty log message ***
13 ** Revision 1.1 2000/06/07 02:29:05 kevin
14 ** Initial C++ versions
16 ** Revision 1.3 2000/05/16 04:33:59 kevin
17 ** Improved option processing
19 ** Revision 1.2 2000/05/08 20:02:32 kevin
22 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
23 ** Initial CVS import for first public release
27 ** This program is free software; you can redistribute it and/or modify
28 ** it under the terms of the GNU General Public License (version 2) as
29 ** published by the Free Software Foundation.
31 ** This program is distributed in the hope that it will be useful,
32 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
33 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ** GNU General Public License for more details.
36 ** You should have received a copy of the GNU General Public License
37 ** along with this program; if not, write to the Free Software
38 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 ******************************************************************************/
42 * ifinfo.c Display info on sdf files
47 enum { O_LABELS, O_STATS, O_NO_STATS, O_NO_LABELS, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG };
49 static struct option my_options[] =
51 {"labels", 0, 0, O_LABELS},
52 {"no-labels", 0, 0, O_NO_LABELS},
53 {"stats", 0, 0, O_STATS},
54 {"no-stats", 0, 0, O_NO_STATS},
55 {"debug", 0, 0, O_DEBUG},
56 {"verbose", 0, 0, O_VERBOSE},
57 {"help", 0, 0, O_HELP},
58 {"version", 0, 0, O_VERSION},
63 ifinfo_usage (const char *program)
65 fprintf(stdout, "usage: %s infile [OPTIONS]\n", kbasename(program));
66 fprintf(stdout, "Imagefile information\n");
67 fprintf(stdout, "\n");
68 fprintf(stdout, " infile Name of input SDF file\n");
69 fprintf(stdout, " --display Display image\n");
70 fprintf(stdout, " --labels Print image labels (default)\n");
71 fprintf(stdout, " --no-labels Do not print image labels\n");
72 fprintf(stdout, " --stats Print image statistics (default)\n");
73 fprintf(stdout, " --no-stats Do not print image statistics\n");
74 fprintf(stdout, " --debug Debug mode\n");
75 fprintf(stdout, " --verbose Verbose mode\n");
76 fprintf(stdout, " --version Print version\n");
77 fprintf(stdout, " --help Print this help message\n");
81 ifinfo_main (int argc, char *const argv[])
92 int c = getopt_long (argc, argv, "", my_options, NULL);
119 fprintf(stdout, "Version %s\n", VERSION);
121 fprintf(stderr, "Unknown version number");
126 ifinfo_usage(argv[0]);
129 ifinfo_usage(argv[0]);
134 if (optind + 1 != argc)
136 ifinfo_usage(argv[0]);
140 in_file = argv[optind];
142 im = new ImageFile (in_file);
143 if (! im->adf.fileRead ()) {
144 sys_error (ERR_WARNING, "Unable to read file %s", in_file);
150 int nlabels = im->adf.getNumLabels();
153 for (i = 0; i < nlabels; i++)
155 Array2dFileLabel label;
156 im->adf.labelRead (label, i);
159 label.getDateString (str);
161 if (label.getLabelType() == Array2dFileLabel::L_HISTORY) {
162 cout << "History: " << label.getLabelString() << endl;
163 cout << " calc time = " << label.getCalcTime() << " secs" << endl;
164 cout << " Timestamp = " << str << endl;
165 } else if (label.getLabelType() == Array2dFileLabel::L_USER) {
166 cout << "Note: " << label.getLabelString() << endl;
167 cout << " Timestamp = %s" << str << endl;
174 double minfound = HUGE_VAL, maxfound = -HUGE_VAL;
175 double mode = 0, mean = 0, stddev = 0;
178 int ibin, nbin = 256;
179 int max_bin, max_binindex;
184 ImageFileArray v = im->getArray();
188 for (ix = 0; ix < nx; ix++)
190 for (iy = 0; iy < ny; iy++)
192 if (v[ix][iy] > maxfound)
193 maxfound = v[ix][iy];
194 if (v[ix][iy] < minfound)
195 minfound = v[ix][iy];
199 spread = maxfound - minfound;
204 for (ibin = 0; ibin < nbin; ibin++)
206 for (ix = 0; ix < nx; ix++)
208 for (iy = 0; iy < ny; iy++)
210 int b = (int) ((((v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5);
216 for (ibin = 0; ibin < nbin; ibin++)
218 if (hist[ibin] > max_bin)
220 max_bin = hist[ibin];
224 mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound;
228 for (ix = 0; ix < nx; ix++)
230 for (iy = 0; iy < ny; iy++)
232 double diff = (v[ix][iy] - mean);
233 stddev += diff * diff;
236 stddev = sqrt(stddev / (nx * ny));
237 cout << "nx=" << nx << endl;
238 cout << "nx=" << ny << endl;
239 cout << "min=" << minfound << endl;
240 cout << "max=" << maxfound << endl;
241 cout << "mean=" << mean << endl;
242 cout << "mode=" << mode << endl;
243 cout << "stddef=" << stddev << endl;
251 main (int argc, char *const argv[])
253 return (ifinfo_main(argc, argv));