00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00061
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];
00087 float labbyt = data[21];
00088 float lenbyt = data[22];
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;
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;
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 }