 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
38 machine_stamp[0] = machine_stamp[1] = 17;
41 machine_stamp[0] = 68;
42 machine_stamp[1] = 65;
45 machine_stamp[0] = 34;
46 machine_stamp[1] = 65;
83 ifstream* fimg =
new ifstream(p->
file_name());
84 if ( fimg->fail() )
return -1;
87 cout <<
"DEBUG readCCP4: File opened" << endl;
91 fimg->read((
char *)header,
CCP4SIZE);
92 if ( fimg->fail() )
return -2;
95 unsigned char* b = (
unsigned char *) header;
99 cerr <<
"Warning: Swapping header byte order for 4-byte types" << endl;
102 for ( i=0; i<extent; i+=4 )
103 if ( i < 208 || i > 212 )
swapbytes(b+i, 4);
106 if ( header->nx < 1 || header->ny < 1 || header->nz < 1 || header->mode < 0 ) {
107 cerr <<
"Error readCCP4: The file " << p->
file_name() <<
" is not a valid CCP4 image!" << endl;
108 cerr <<
"Size: " << header->nx <<
tab << header->ny <<
109 tab << header->nz << endl;
116 if ( ( header->machst[0] == 34 ) || ( header->amin > header->amax ) ) {
118 cerr <<
"Warning: Converting VAX floating point" << endl;
119 for ( i=40; i<64; i+=4 )
121 for ( i=76; i<88; i+=4 )
123 for ( i=100; i<204; i+=4 )
129 if ( strncmp(header->map,
"STK ", 4) == 0 ) {
131 p->
size(header->nx, header->ny, 1);
134 p->
size(header->nx, header->ny, header->nz);
137 switch ( header->mode ) {
146 if ( header->mode > 2 ) {
147 fimg->seekg(0, ios::end);
150 if ( header->mx%2 == 1 ) p->
sizeX(p->
sizeX() + 1);
152 fimg->seekg(0, ios::beg);
159 if ( header->mx && header->my && header->mz )
160 p->
sampling(header->a/header->mx, header->b/header->my, header->c/header->mz);
162 UnitCell uc(header->a, header->b, header->c, header->alpha, header->beta, header->gamma);
165 p->
label(header->labels);
168 p->
origin(-header->nxStart, -header->nyStart, -header->nzStart);
173 cout <<
"DEBUG rwCCP4: Header setup done" << endl;
176 unsigned char* data = NULL;
185 data =
new unsigned char[readsize];
198 cout <<
"DEBUG rwCCP4: Data read" << endl;
212 cout <<
"DEBUG rwCCP4: Writing CCP4 file" << endl;
229 cout <<
"DEBUG rwCCP4: data type = " << p->
data_type() << endl;
232 memset(header, 0,
sizeof(
CCP4head));
241 strncpy(header->
map,
"MAP ", 4);
244 strncpy(header->
map,
"STK ", 4);
252 default: header->
mode = 0;
break;
266 header->
mx = (int) (uc.
a()/p->
sampling(0)[0] + 0.5);
267 header->
my = (int) (uc.
b()/p->
sampling(0)[1] + 0.5);
268 header->
mz = (int) (uc.
c()/p->
sampling(0)[2] + 0.5);
282 if ( fabs(header->
a - p->
sampling(0)[0]*header->
mx) > 0.001 || fabs(header->
b - p->
sampling(0)[1]*header->
my) > 0.001 ||
283 fabs(header->
c - p->
sampling(0)[2]*header->
mz) > 0.001 ) {
288 cerr <<
"Warning: Resetting the unit cell to: " << header->
a <<
"," << header->
b <<
"," << header->
c << endl;
296 for ( i=k=0; i<3; i++ )
for ( j=0; j<3; j++, k++ ) header->
skwmat[k] = frac_mat[i][j];
301 cout <<
"DEBUG rwCCP4: Writing labels" << endl;
308 cout <<
"DEBUG rwCCP4: nlabl = " << header->
nlabl << endl;
309 for ( i=0; i<header->
nlabl; i++ )
310 if ( header->
labels[i*80] ) cout << &header->
labels[i*80] << endl;
324 cout <<
"DEBUG rwCCP4: nsymbt = " << header->
nsymbt << endl;
329 long datasize = (long)header->
nx*header->
ny*header->
nz*datatypesize;
332 cout <<
"DEBUG rwCCP4: offset=" << p->
data_offset() <<
" typesize=" << datatypesize <<
" datasize=" << datasize << endl;
334 unsigned char* data = NULL;
337 if ( fimg.fail() )
return -1;
339 fimg.write((
char *)header,
CCP4SIZE);
341 if ( header->nsymbt ) fimg.write((
char *)symop, header->nsymbt);
347 data =
new unsigned char[datasize];
349 fimg.write((
char *)data, datasize);
356 if ( symop )
delete[] symop;
360 cout <<
"DEBUG rwCCP4: Done writing" << endl;
Header file for reading and writing symmetry operators.
void vax2ieee(unsigned char *v, int sb)
Converts VAX floating point format to IEEE floating point format.
Header file for file checking functions.
int fread_large(unsigned char *aptr, size_t pagesize, size_t offset, ifstream *fimg)
Reads blocks of memeory no larger than 1Gb.
int set_CCP4_machine_stamp(char *machine_stamp)
Setting a CCP4 style machine stamp.
SysType systype(int show)
Finds the system type - mostly just for byte order.
void unit_cell(UnitCell uc)
Vector3< long > size() const
Header file for unit cell functions.
long data_type_size() const
Returns the size of the datatype in bytes.
double standard_deviation()
void origin(double x, double y, double z)
int pack_transform(unsigned char *data, FourierType tf)
Header file for reading and writing CCP4 files.
void swapbytes(unsigned char *v, size_t n)
Swaps bytes.
General image parameter class.
CompoundType compound_type()
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
unsigned char * data_alloc()
void color_to_simple()
A color image is converted to a simple image.
Matrix3 skew_matrix()
Calculates the skew matrix from the unit cell parameters.
Header file for general utilities.
ostream & tab(ostream &out)
int writeCCP4(Bimage *p)
Writing a CCP4 map image file format.
void origin(double ox, double oy, double oz)
void change_type(char letter)
Get the data type indicated by a single letter code.
unsigned char * data_pointer()
void sampling(long nn, Vector3< double > u)
char * read_symop(Bstring &filename, int spacegroup, int &nsym)
Reading crystallographic symmetry operators.
int unpack_transform(unsigned char *data, FourierType tf)
int readCCP4(Bimage *p, int readdata)
Reading a CCP4 map image file format.
void degrees_to_radians()