EMAN2
iminfo.cpp
Go to the documentation of this file.
00001 /*
00002  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00003  * Copyright (c) 2000-2006 Baylor College of Medicine
00004  *
00005  * This software is issued under a joint BSD/GNU license. You may use the
00006  * source code in this file under either license. However, note that the
00007  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00008  * so you are responsible for compliance with the licenses of these packages
00009  * if you opt to use BSD licensing. The warranty disclaimer below holds
00010  * in either instance.
00011  *
00012  * This complete copyright notice must be included in any revised version of the
00013  * source code. Additional authorship citations may be added, but existing
00014  * author citations must be preserved.
00015  *
00016  * This program is free software; you can redistribute it and/or modify
00017  * it under the terms of the GNU General Public License as published by
00018  * the Free Software Foundation; either version 2 of the License, or
00019  * (at your option) any later version.
00020  *
00021  * This program is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00024  * GNU General Public License for more details.
00025  *
00026  * You should have received a copy of the GNU General Public License
00027  * along with this program; if not, write to the Free Software
00028  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00029  *
00030  * */
00031 
00032 #include <cstring>
00033 #include "emdata.h"
00034 #include "ctf.h"
00035 
00036 using namespace EMAN;
00037 
00038 void usage(const char *progname)
00039 {
00040     printf("\n%s [-H] [-vN] [-stat] <image file>\n", progname);
00041     printf("    -H: show all header information.\n");
00042     printf("   -vN: set verbosity level. N=0,1,2,3. large N means more verbose.\n");
00043     printf(" -stat: show statistical information about the image(s).\n");
00044     printf("\n");
00045 }
00046 
00047 int main(int argc, char* argv[])
00048 {
00049     if (argc < 2) {
00050                 usage(argv[0]);
00051                 exit(1);
00052     }
00053 
00054     bool show_all_header = false;
00055     bool stat = false;
00056 
00057     Util::set_log_level(argc, argv);
00058     for (int i = 1; i < argc - 1; i++) {
00059                 if (strcmp(argv[i], "-H") == 0) {
00060                         show_all_header = true;
00061                 }
00062                 else if (strcmp(argv[i], "-stat") == 0) {
00063                         stat = true;
00064                 }
00065     }
00066 
00067     const char* imagefile = argv[argc-1];
00068     EMData* d = 0;
00069         try {
00070                 int nimg = EMUtil::get_image_count(imagefile);
00071         EMUtil::ImageType imgtype = EMUtil::get_image_type(imagefile);
00072                 const char* imgtypename = EMUtil::get_imagetype_name(imgtype);
00073                 int image_index = 0;
00074         if (imgtype == EMUtil::IMAGE_SPIDER && !stat) {
00075             image_index = -1;
00076         }
00077                 printf("\n%20s: %d\n", "Number of Images", nimg);
00078                 printf("%20s: %s\n", "Image Format", imgtypename);
00079 
00080                 d = new EMData();
00081 
00082                 if (!stat) {
00083                         d->read_image(imagefile, image_index, true);
00084                 }
00085                 else {
00086                         d->read_image(imagefile, image_index, false);
00087                 }
00088 
00089                 printf("%20s: %d x %d x %d\n", "Image Dimensions",
00090                            d->get_xsize(), d->get_ysize(), d->get_zsize());
00091 
00092                 printf("%20s: %s\n", "Image Data Type",
00093                                 EMUtil::get_datatype_string((EMUtil::EMDataType)((int)(d->get_attr("datatype")))));
00094 
00095                 if (stat) {
00096                         printf("mean=%1.3g sigma=%1.3g skewness=%1.3g kurtosis=%1.3g\n",
00097                                    (float) d->get_attr("mean"),
00098                                    (float) d->get_attr("sigma"),
00099                                    (float) d->get_attr("skewness"),
00100                                    (float) d->get_attr("kurtosis"));
00101                 }
00102 
00103                 Ctf* ctf = d->get_ctf();
00104                 if (ctf) {
00105                         printf("CTF: %s\n", ctf->to_string().c_str());
00106                         delete ctf;
00107                         ctf = 0;
00108                 }
00109 
00110                 if (show_all_header) {
00111                         Dict dict = d->get_attr_dict();
00112                         printf("\nDetailed Header Information:\n");
00113                         EMUtil::dump_dict(dict);
00114                 }
00115                 printf("\n");
00116 
00117 
00118 
00119         if( d )
00120         {
00121                         delete d;
00122                         d = 0;
00123         }
00124         }
00125         catch(E2Exception  & e) {
00126                 if (d) {
00127                         delete d;
00128                         d = 0;
00129                 }
00130                 printf("%s\n", e.what());
00131         }
00132 
00133 
00134         return 0;
00135 }
00136 
00137 
00138