Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

sspiderio.cpp

Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  * 
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  * 
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  * 
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  * 
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  * 
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033  * 
00034  * */
00035 
00036 #include "sspiderio.h"
00037 #include "geometry.h"
00038 #include "portable_fileio.h"
00039 
00040 #include <iostream>
00041 
00042 using namespace EMAN;
00043 
00044 SingleSpiderIO::SingleSpiderIO(const string & file, IOMode rw)
00045 :       SpiderIO(file, rw)
00046 {
00047 }
00048 
00049 
00050 SingleSpiderIO::~SingleSpiderIO()
00051 {
00052 }
00053 
00054 
00055 int SingleSpiderIO::write_header(const Dict & dict, int , const Region* area,
00056                                                                  EMUtil::EMDataType, bool use_host_endian)
00057 {
00058         size_t offset = 0;
00059         int image_index = 0;
00060 //      if(!use_host_endian) {
00061 //              ByteOrder::swap_bytes((float*)first_h, NUM_FLOATS_IN_HEADER);
00062 //      }
00063         return write_single_header(dict, area, image_index, offset, first_h, SINGLE_IMAGE_HEADER, 1, 1, use_host_endian);
00064 }
00065 
00066 
00067 int SingleSpiderIO::write_data(float *data, int , const Region* area,
00068                                                            EMUtil::EMDataType, bool use_host_endian)
00069 {
00070         size_t offset = (int) first_h->headlen;
00071         return write_single_data(data, area, first_h, offset, 0, 1, use_host_endian);
00072 }
00073 
00074 
00075 bool SingleSpiderIO::is_valid(const void *first_block)
00076 {
00077         ENTERFUNC;
00078         bool result = false;
00079         
00080         if (first_block) {
00081                 const float *data = static_cast < const float *>(first_block);
00082                 float nslice = data[0];
00083                 float nrow = data[1];
00084                 float iform = data[4];
00085                 float nsam = data[11];
00086                 float labrec = data[12];        //NO. of records in file header
00087                 float labbyt = data[21];        //total NO. of bytes in header
00088                 float lenbyt = data[22];        //record length in bytes
00089                 float istack = data[23];
00090                 
00091                 bool big_endian = ByteOrder::is_float_big_endian(nslice);
00092                 if (big_endian != ByteOrder::is_host_big_endian()) {
00093                         ByteOrder::swap_bytes(&nslice);
00094                         ByteOrder::swap_bytes(&nrow);
00095                         ByteOrder::swap_bytes(&iform);
00096                         ByteOrder::swap_bytes(&nsam);
00097                         ByteOrder::swap_bytes(&labrec);
00098                         ByteOrder::swap_bytes(&labbyt);
00099                         ByteOrder::swap_bytes(&lenbyt);
00100                         ByteOrder::swap_bytes(&istack);
00101                 }
00102                 
00103                 if( int(nslice) != nslice || int(nrow) != nrow
00104                                 || int(iform) != iform || int(nsam) != nsam 
00105                                 || int(labrec) != labrec || int(labbyt) != labbyt
00106                                 || int(lenbyt) != lenbyt ) {
00107                         result =  false;
00108                 }
00109                 else {
00110                         int itype = static_cast < int >(iform);
00111                         if( int(istack) != SINGLE_IMAGE_HEADER ) {
00112                                 result = false; //istack>0 for overall header, istack<0 for indexed stack of image
00113                         }
00114                         else if( itype == IMAGE_2D_FFT_ODD || itype == IMAGE_2D_FFT_EVEN 
00115                                         || itype == IMAGE_3D_FFT_ODD || itype == IMAGE_3D_FFT_EVEN ) {
00116                                 result = false; //Complex SPIDER image not supported in EMAN2
00117                         }
00118                         else if (itype == IMAGE_2D || itype == IMAGE_3D) {
00119                                 result = true;
00120                         }
00121                 }
00122                 
00123                 int ilabrec = static_cast<int>(labrec);
00124                 int ilabbyt = static_cast<int>(labbyt);
00125                 int ilenbyt = static_cast<int>(lenbyt);
00126                 if( ilabbyt != ilabrec * ilenbyt ) {
00127                         result = false;
00128                 }
00129         }
00130 
00131         EXITFUNC;
00132         return result;
00133 }
00134 
00135 
00136 bool SingleSpiderIO::is_valid_spider(const void *first_block)
00137 {
00138         return SingleSpiderIO::is_valid(first_block);
00139 }

Generated on Tue Jun 11 13:46:19 2013 for EMAN2 by  doxygen 1.3.9.1