| 1 |
/***************************************************************************** |
| 2 |
** FILE IDENTIFICATION |
| 3 |
** |
| 4 |
** Name: ifinfo.cpp |
| 5 |
** Purpose: Display information about an image file |
| 6 |
** Programmer: Kevin Rosenberg |
| 7 |
** Date Started: April 2000 |
| 8 |
** |
| 9 |
** This is part of the CTSim program |
| 10 |
** Copyright (C) 1983-2009 Kevin Rosenberg |
| 11 |
** |
| 12 |
** This program is free software; you can redistribute it and/or modify |
| 13 |
** it under the terms of the GNU General Public License (version 2) as |
| 14 |
** published by the Free Software Foundation. |
| 15 |
** |
| 16 |
** This program is distributed in the hope that it will be useful, |
| 17 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
** GNU General Public License for more details. |
| 20 |
** |
| 21 |
** You should have received a copy of the GNU General Public License |
| 22 |
** along with this program; if not, write to the Free Software |
| 23 |
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 |
******************************************************************************/ |
| 25 |
|
| 26 |
/* FILE |
| 27 |
* ifinfo.c Display info on sdf files |
| 28 |
*/ |
| 29 |
|
| 30 |
#include "ct.h" |
| 31 |
|
| 32 |
enum { O_LABELS, O_STATS, O_NO_STATS, O_NO_LABELS, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG }; |
| 33 |
|
| 34 |
static struct option my_options[] = |
| 35 |
{ |
| 36 |
{"labels", 0, 0, O_LABELS}, |
| 37 |
{"no-labels", 0, 0, O_NO_LABELS}, |
| 38 |
{"stats", 0, 0, O_STATS}, |
| 39 |
{"no-stats", 0, 0, O_NO_STATS}, |
| 40 |
{"debug", 0, 0, O_DEBUG}, |
| 41 |
{"verbose", 0, 0, O_VERBOSE}, |
| 42 |
{"help", 0, 0, O_HELP}, |
| 43 |
{"version", 0, 0, O_VERSION}, |
| 44 |
{0, 0, 0, 0} |
| 45 |
}; |
| 46 |
|
| 47 |
static const char* g_szIdStr = "$Id$"; |
| 48 |
|
| 49 |
|
| 50 |
void |
| 51 |
ifinfo_usage (const char *program) |
| 52 |
{ |
| 53 |
std::cout << "usage: " << fileBasename(program) << " image-filename [OPTIONS]\n"; |
| 54 |
std::cout << "Imagefile information\n"; |
| 55 |
std::cout << std::endl; |
| 56 |
std::cout << " infile Name of input IF file\n"; |
| 57 |
std::cout << " --display Display image\n"; |
| 58 |
std::cout << " --labels Print image labels (default)\n"; |
| 59 |
std::cout << " --no-labels Do not print image labels\n"; |
| 60 |
std::cout << " --stats Print image statistics (default)\n"; |
| 61 |
std::cout << " --no-stats Do not print image statistics\n"; |
| 62 |
std::cout << " --debug Debug mode\n"; |
| 63 |
std::cout << " --verbose Verbose mode\n"; |
| 64 |
std::cout << " --version Print version\n"; |
| 65 |
std::cout << " --help Print this help message\n"; |
| 66 |
} |
| 67 |
|
| 68 |
int |
| 69 |
ifinfo_main (int argc, char *const argv[]) |
| 70 |
{ |
| 71 |
ImageFile *im = NULL; |
| 72 |
std::string in_file; |
| 73 |
int opt_verbose = 0; |
| 74 |
int opt_stats = 1; |
| 75 |
int opt_labels = 1; |
| 76 |
int opt_debug = 0; |
| 77 |
UNUSED(opt_verbose); |
| 78 |
UNUSED(opt_debug); |
| 79 |
|
| 80 |
while (1) |
| 81 |
{ |
| 82 |
int c = getopt_long (argc, argv, "", my_options, NULL); |
| 83 |
|
| 84 |
if (c == -1) |
| 85 |
break; |
| 86 |
|
| 87 |
switch (c) |
| 88 |
{ |
| 89 |
case O_LABELS: |
| 90 |
opt_labels = 1; |
| 91 |
break; |
| 92 |
case O_STATS: |
| 93 |
opt_stats = 1; |
| 94 |
break; |
| 95 |
case O_NO_LABELS: |
| 96 |
opt_labels = 0; |
| 97 |
break; |
| 98 |
case O_NO_STATS: |
| 99 |
opt_stats = 0; |
| 100 |
break; |
| 101 |
case O_VERBOSE: |
| 102 |
opt_verbose = 1; |
| 103 |
break; |
| 104 |
case O_DEBUG: |
| 105 |
opt_debug = 0; |
| 106 |
break; |
| 107 |
case O_VERSION: |
| 108 |
#ifdef VERSION |
| 109 |
std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl; |
| 110 |
#else |
| 111 |
std::cout << "Unknown version number\n"; |
| 112 |
#endif |
| 113 |
return (0); |
| 114 |
case O_HELP: |
| 115 |
case '?': |
| 116 |
ifinfo_usage(argv[0]); |
| 117 |
return (0); |
| 118 |
default: |
| 119 |
ifinfo_usage(argv[0]); |
| 120 |
return (1); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
if (optind + 1 != argc) { |
| 125 |
ifinfo_usage (argv[0]); |
| 126 |
return (1); |
| 127 |
} |
| 128 |
|
| 129 |
in_file = argv[optind]; |
| 130 |
|
| 131 |
im = new ImageFile (); |
| 132 |
if (! im->fileRead (in_file)) { |
| 133 |
sys_error (ERR_WARNING, "Unable to read file %s", in_file.c_str()); |
| 134 |
return (1); |
| 135 |
} |
| 136 |
|
| 137 |
if (opt_labels) |
| 138 |
im->printLabels (std::cout); |
| 139 |
|
| 140 |
if (opt_stats) { |
| 141 |
std::cout << "Size: (" << im->nx() << "," << im->ny() << ")\n"; |
| 142 |
std::cout << "Data type: "; |
| 143 |
if (im->dataType() == Array2dFile::DATA_TYPE_COMPLEX) |
| 144 |
std::cout << "Complex\n"; |
| 145 |
else |
| 146 |
std::cout << "Real\n"; |
| 147 |
|
| 148 |
im->printStatistics (std::cout); |
| 149 |
} |
| 150 |
|
| 151 |
return (0); |
| 152 |
} |
| 153 |
|
| 154 |
#ifndef NO_MAIN |
| 155 |
int |
| 156 |
main (int argc, char *const argv[]) |
| 157 |
{ |
| 158 |
int retval = 1; |
| 159 |
|
| 160 |
try { |
| 161 |
retval = ifinfo_main(argc, argv); |
| 162 |
} catch (exception e) { |
| 163 |
std::cerr << "Exception: " << e.what() << std::endl; |
| 164 |
} catch (...) { |
| 165 |
std::cerr << "Unknown exception\n"; |
| 166 |
} |
| 167 |
|
| 168 |
return (retval); |
| 169 |
} |
| 170 |
#endif |