1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sdfinfo.c,v 1.3 2000/05/16 04:33:59 kevin Exp $
7 ** Revision 1.3 2000/05/16 04:33:59 kevin
8 ** Improved option processing
10 ** Revision 1.2 2000/05/08 20:02:32 kevin
13 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
14 ** Initial CVS import for first public release
18 ** This program is free software; you can redistribute it and/or modify
19 ** it under the terms of the GNU General Public License (version 2) as
20 ** published by the Free Software Foundation.
22 ** This program is distributed in the hope that it will be useful,
23 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ** GNU General Public License for more details.
27 ** You should have received a copy of the GNU General Public License
28 ** along with this program; if not, write to the Free Software
29 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 ******************************************************************************/
33 * sdfinfo.c Display info on sdf files
38 enum { O_LABELS, O_STATS, O_NO_STATS, O_NO_LABELS, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG };
40 static struct option my_options[] =
42 {"labels", 0, 0, O_LABELS},
43 {"no-labels", 0, 0, O_NO_LABELS},
44 {"stats", 0, 0, O_STATS},
45 {"no-stats", 0, 0, O_NO_STATS},
46 {"debug", 0, 0, O_DEBUG},
47 {"verbose", 0, 0, O_VERBOSE},
48 {"help", 0, 0, O_HELP},
49 {"version", 0, 0, O_VERSION},
54 sdfinfo_usage (const char *program)
56 fprintf(stdout, "sdfinfo_usage: %s infile [OPTIONS]\n", kbasename(program));
57 fprintf(stdout, "Analyze an SDF2D file\n");
58 fprintf(stdout, "\n");
59 fprintf(stdout, " infile Name of input SDF file\n");
60 fprintf(stdout, " --display Display image\n");
61 fprintf(stdout, " --labels Print image labels (default)\n");
62 fprintf(stdout, " --no-labels Do not print image labels\n");
63 fprintf(stdout, " --stats Print image statistics (default)\n");
64 fprintf(stdout, " --no-stats Do not print image statistics\n");
65 fprintf(stdout, " --debug Debug mode\n");
66 fprintf(stdout, " --verbose Verbose mode\n");
67 fprintf(stdout, " --version Print version\n");
68 fprintf(stdout, " --help Print this help message\n");
72 sdfinfo_main (int argc, char *const argv[])
83 int c = getopt_long (argc, argv, "", my_options, NULL);
110 fprintf(stdout, "Version %s\n", VERSION);
112 fprintf(stderr, "Unknown version number");
117 sdfinfo_usage(argv[0]);
120 sdfinfo_usage(argv[0]);
125 if (optind + 1 != argc)
127 sdfinfo_usage(argv[0]);
131 in_file = argv[optind];
133 im = image_load (in_file);
137 int nlabels = im->dfp_2d->dfp->num_label;
140 for (i = 0; i < nlabels; i++)
143 if (sdf_read_label(&blk.lab, i, im->dfp_2d->dfp) != SDF_OK)
145 if (blk.lab.label_type == LT_HISTORY) {
146 fprintf(stdout, "History: %s\n", blk.lab.label_str);
147 fprintf(stdout, " calc time = %.2f secs\n", blk.lab.calc_time);
148 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
149 } else if (blk.lab.label_type == LT_TITLE) {
150 fprintf(stdout, "Title: %s\n", blk.lab.label_str);
151 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
152 } else if (blk.lab.label_type == LT_NOTE) {
153 fprintf(stdout, "Note: %s\n", blk.lab.label_str);
154 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
161 double minfound = HUGE_VAL, maxfound = -HUGE_VAL;
162 double mode = 0, mean = 0, stddev = 0;
165 int ibin, nbin = 256;
166 int max_bin, max_binindex;
171 for (ix = 0; ix < im->nx; ix++)
173 for (iy = 0; iy < im->ny; iy++)
175 if (im->v[ix][iy] > maxfound)
176 maxfound = im->v[ix][iy];
177 if (im->v[ix][iy] < minfound)
178 minfound = im->v[ix][iy];
179 mean += im->v[ix][iy];
182 spread = maxfound - minfound;
187 for (ibin = 0; ibin < nbin; ibin++)
189 for (ix = 0; ix < im->nx; ix++)
191 for (iy = 0; iy < im->ny; iy++)
193 int b = (int) ((((im->v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5);
199 for (ibin = 0; ibin < nbin; ibin++)
201 if (hist[ibin] > max_bin)
203 max_bin = hist[ibin];
207 mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound;
210 mean /= im->nx * im->ny;
211 for (ix = 0; ix < im->nx; ix++)
213 for (iy = 0; iy < im->ny; iy++)
215 double diff = (im->v[ix][iy] - mean);
216 stddev += diff * diff;
219 stddev = sqrt(stddev / (im->nx * im->ny));
220 fprintf(stdout,"nx=%d\n", im->nx);
221 fprintf(stdout,"ny=%d\n", im->ny);
222 fprintf(stdout,"min=%f\n", minfound);
223 fprintf(stdout,"max=%f\n", maxfound);
224 fprintf(stdout,"mean=%f\n", mean);
225 fprintf(stdout,"mode=%f\n", mode);
226 fprintf(stdout,"stddev=%f\n", stddev);
234 main (int argc, char *const argv[])
236 return (sdfinfo_main(argc, argv));