1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sdfinfo.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $
6 ** $Log: sdfinfo.cpp,v $
7 ** Revision 1.1 2000/06/07 02:29:05 kevin
8 ** Initial C++ versions
10 ** Revision 1.3 2000/05/16 04:33:59 kevin
11 ** Improved option processing
13 ** Revision 1.2 2000/05/08 20:02:32 kevin
16 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
17 ** Initial CVS import for first public release
21 ** This program is free software; you can redistribute it and/or modify
22 ** it under the terms of the GNU General Public License (version 2) as
23 ** published by the Free Software Foundation.
25 ** This program is distributed in the hope that it will be useful,
26 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ** GNU General Public License for more details.
30 ** You should have received a copy of the GNU General Public License
31 ** along with this program; if not, write to the Free Software
32 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 ******************************************************************************/
36 * sdfinfo.c Display info on sdf files
41 enum { O_LABELS, O_STATS, O_NO_STATS, O_NO_LABELS, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG };
43 static struct option my_options[] =
45 {"labels", 0, 0, O_LABELS},
46 {"no-labels", 0, 0, O_NO_LABELS},
47 {"stats", 0, 0, O_STATS},
48 {"no-stats", 0, 0, O_NO_STATS},
49 {"debug", 0, 0, O_DEBUG},
50 {"verbose", 0, 0, O_VERBOSE},
51 {"help", 0, 0, O_HELP},
52 {"version", 0, 0, O_VERSION},
57 sdfinfo_usage (const char *program)
59 fprintf(stdout, "sdfinfo_usage: %s infile [OPTIONS]\n", kbasename(program));
60 fprintf(stdout, "Analyze an SDF2D file\n");
61 fprintf(stdout, "\n");
62 fprintf(stdout, " infile Name of input SDF file\n");
63 fprintf(stdout, " --display Display image\n");
64 fprintf(stdout, " --labels Print image labels (default)\n");
65 fprintf(stdout, " --no-labels Do not print image labels\n");
66 fprintf(stdout, " --stats Print image statistics (default)\n");
67 fprintf(stdout, " --no-stats Do not print image statistics\n");
68 fprintf(stdout, " --debug Debug mode\n");
69 fprintf(stdout, " --verbose Verbose mode\n");
70 fprintf(stdout, " --version Print version\n");
71 fprintf(stdout, " --help Print this help message\n");
75 sdfinfo_main (int argc, char *const argv[])
86 int c = getopt_long (argc, argv, "", my_options, NULL);
113 fprintf(stdout, "Version %s\n", VERSION);
115 fprintf(stderr, "Unknown version number");
120 sdfinfo_usage(argv[0]);
123 sdfinfo_usage(argv[0]);
128 if (optind + 1 != argc)
130 sdfinfo_usage(argv[0]);
134 in_file = argv[optind];
136 im = image_load (in_file);
140 int nlabels = im->dfp_2d->dfp->num_label;
143 for (i = 0; i < nlabels; i++)
146 if (sdf_read_label(&blk.lab, i, im->dfp_2d->dfp) != SDF_OK)
148 if (blk.lab.label_type == LT_HISTORY) {
149 fprintf(stdout, "History: %s\n", blk.lab.label_str);
150 fprintf(stdout, " calc time = %.2f secs\n", blk.lab.calc_time);
151 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
152 } else if (blk.lab.label_type == LT_TITLE) {
153 fprintf(stdout, "Title: %s\n", blk.lab.label_str);
154 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
155 } else if (blk.lab.label_type == LT_NOTE) {
156 fprintf(stdout, "Note: %s\n", blk.lab.label_str);
157 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
164 double minfound = HUGE_VAL, maxfound = -HUGE_VAL;
165 double mode = 0, mean = 0, stddev = 0;
168 int ibin, nbin = 256;
169 int max_bin, max_binindex;
174 for (ix = 0; ix < im->nx; ix++)
176 for (iy = 0; iy < im->ny; iy++)
178 if (im->v[ix][iy] > maxfound)
179 maxfound = im->v[ix][iy];
180 if (im->v[ix][iy] < minfound)
181 minfound = im->v[ix][iy];
182 mean += im->v[ix][iy];
185 spread = maxfound - minfound;
190 for (ibin = 0; ibin < nbin; ibin++)
192 for (ix = 0; ix < im->nx; ix++)
194 for (iy = 0; iy < im->ny; iy++)
196 int b = (int) ((((im->v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5);
202 for (ibin = 0; ibin < nbin; ibin++)
204 if (hist[ibin] > max_bin)
206 max_bin = hist[ibin];
210 mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound;
213 mean /= im->nx * im->ny;
214 for (ix = 0; ix < im->nx; ix++)
216 for (iy = 0; iy < im->ny; iy++)
218 double diff = (im->v[ix][iy] - mean);
219 stddev += diff * diff;
222 stddev = sqrt(stddev / (im->nx * im->ny));
223 fprintf(stdout,"nx=%d\n", im->nx);
224 fprintf(stdout,"ny=%d\n", im->ny);
225 fprintf(stdout,"min=%f\n", minfound);
226 fprintf(stdout,"max=%f\n", maxfound);
227 fprintf(stdout,"mean=%f\n", mean);
228 fprintf(stdout,"mode=%f\n", mode);
229 fprintf(stdout,"stddev=%f\n", stddev);
237 main (int argc, char *const argv[])
239 return (sdfinfo_main(argc, argv));