1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: ifinfo.cpp,v 1.2 2000/06/07 03:50:27 kevin Exp $
6 ** $Log: ifinfo.cpp,v $
7 ** Revision 1.2 2000/06/07 03:50:27 kevin
8 ** *** empty log message ***
10 ** Revision 1.1 2000/06/07 02:29:05 kevin
11 ** Initial C++ versions
13 ** Revision 1.3 2000/05/16 04:33:59 kevin
14 ** Improved option processing
16 ** Revision 1.2 2000/05/08 20:02:32 kevin
19 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
20 ** Initial CVS import for first public release
24 ** This program is free software; you can redistribute it and/or modify
25 ** it under the terms of the GNU General Public License (version 2) as
26 ** published by the Free Software Foundation.
28 ** This program is distributed in the hope that it will be useful,
29 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
30 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 ** GNU General Public License for more details.
33 ** You should have received a copy of the GNU General Public License
34 ** along with this program; if not, write to the Free Software
35 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 ******************************************************************************/
39 * ifinfo.c Display info on sdf files
44 enum { O_LABELS, O_STATS, O_NO_STATS, O_NO_LABELS, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG };
46 static struct option my_options[] =
48 {"labels", 0, 0, O_LABELS},
49 {"no-labels", 0, 0, O_NO_LABELS},
50 {"stats", 0, 0, O_STATS},
51 {"no-stats", 0, 0, O_NO_STATS},
52 {"debug", 0, 0, O_DEBUG},
53 {"verbose", 0, 0, O_VERBOSE},
54 {"help", 0, 0, O_HELP},
55 {"version", 0, 0, O_VERSION},
60 ifinfo_usage (const char *program)
62 fprintf(stdout, "usage: %s infile [OPTIONS]\n", kbasename(program));
63 fprintf(stdout, "Imagefile information\n");
64 fprintf(stdout, "\n");
65 fprintf(stdout, " infile Name of input SDF file\n");
66 fprintf(stdout, " --display Display image\n");
67 fprintf(stdout, " --labels Print image labels (default)\n");
68 fprintf(stdout, " --no-labels Do not print image labels\n");
69 fprintf(stdout, " --stats Print image statistics (default)\n");
70 fprintf(stdout, " --no-stats Do not print image statistics\n");
71 fprintf(stdout, " --debug Debug mode\n");
72 fprintf(stdout, " --verbose Verbose mode\n");
73 fprintf(stdout, " --version Print version\n");
74 fprintf(stdout, " --help Print this help message\n");
78 ifinfo_main (int argc, char *const argv[])
89 int c = getopt_long (argc, argv, "", my_options, NULL);
116 fprintf(stdout, "Version %s\n", VERSION);
118 fprintf(stderr, "Unknown version number");
123 ifinfo_usage(argv[0]);
126 ifinfo_usage(argv[0]);
131 if (optind + 1 != argc)
133 ifinfo_usage(argv[0]);
137 in_file = argv[optind];
139 im = new ImageFile (in_file);
144 int nlabels = im->adf.getNumLabels();
147 for (i = 0; i < nlabels; i++)
149 Array2dFileLabel label;
152 im->adf.labelRead (label, i);
153 label.getDateString (str);
155 if (label.getLabelType() == Array2dFileLabel::L_HISTORY) {
156 cout << "History: " << label.getLabelString() << endl;
157 cout << " calc time = " << label.getCalcTime() << " secs" << endl;
158 cout << " Timestamp = " << str << endl;
159 } else if (label.getLabelType() == Array2dFileLabel::L_USER) {
160 cout << "Note: " << label.getLabelString() << endl;
161 cout << " Timestamp = %s" << str << endl;
168 double minfound = HUGE_VAL, maxfound = -HUGE_VAL;
169 double mode = 0, mean = 0, stddev = 0;
172 int ibin, nbin = 256;
173 int max_bin, max_binindex;
178 ImageFileArray v = im->adf.getArray();
179 int nx = im->adf.nx();
180 int ny = im->adf.ny();
182 for (ix = 0; ix < nx; ix++)
184 for (iy = 0; iy < ny; iy++)
186 if (v[ix][iy] > maxfound)
187 maxfound = v[ix][iy];
188 if (v[ix][iy] < minfound)
189 minfound = v[ix][iy];
193 spread = maxfound - minfound;
198 for (ibin = 0; ibin < nbin; ibin++)
200 for (ix = 0; ix < nx; ix++)
202 for (iy = 0; iy < ny; iy++)
204 int b = (int) ((((v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5);
210 for (ibin = 0; ibin < nbin; ibin++)
212 if (hist[ibin] > max_bin)
214 max_bin = hist[ibin];
218 mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound;
222 for (ix = 0; ix < nx; ix++)
224 for (iy = 0; iy < ny; iy++)
226 double diff = (v[ix][iy] - mean);
227 stddev += diff * diff;
230 stddev = sqrt(stddev / (nx * ny));
231 cout << "nx=" << nx << endl;
232 cout << "nx=" << ny << endl;
233 cout << "min=" << minfound << endl;
234 cout << "max=" << maxfound << endl;
235 cout << "mean=" << mean << endl;
236 cout << "mode=" << mode << endl;
237 cout << "stddef=" << stddev << endl;
245 main (int argc, char *const argv[])
247 return (ifinfo_main(argc, argv));