void cMRC<T>::readData(const std::string& fileName, cData3<T>& object, cMapHeader& header) { const std::string funcName("void cMRC::readData(const std::string& fileName, " "cData3<T>& object, cMapHeader& header)"); checkExtension(fileName); std::ifstream fileHandle; fileHandle.open(fileName.c_str(), std::ifstream::binary); assure(fileHandle, fileName.c_str()); // allocate new memory object.memReAlloc(cVector3<size_t>((size_t) header.map_dim[0], (size_t) header.map_dim[1], (size_t) header.map_dim[2])); // seek to data starting point fileHandle.seekg(CCP4_HEADER_SIZE + header.sym_byte, std::ios::beg); unsigned char* bufferData = NULL; size_t bufferLength = (size_t) std::pow(2,header.data_mode) * header.getNelement(); array_new(bufferData, bufferLength); fileHandle.read((char*) bufferData, bufferLength); switch (header.data_mode) { case 0: // int8 array_index_col2row((int8_t*) bufferData, object.getAddrData(), object.getNrow(), object.getNcol(), object.getNsec()); break; case 1: // int16 if (header.edian_swap) { swap2_aligned(bufferData, header.getNelement()); } array_index_col2row((int16_t*) bufferData, object.getAddrData(), object.getNrow(), object.getNcol(), object.getNsec()); break; case 2: // float32 if (header.edian_swap) { swap4_aligned(bufferData, header.getNelement()); } array_index_col2row((float*) bufferData, object.getAddrData(), object.getNrow(), object.getNcol(), object.getNsec()); break; case 6: // uint16 if (header.edian_swap) { swap2_aligned(bufferData, header.getNelement()); } array_index_col2row((uint16_t*) bufferData, object.getAddrData(), object.getNrow(), object.getNcol(), object.getNsec()); break; default: ERROR(funcName, "unsupported data mode in reading " + fileName); } array_delete(bufferData); fileHandle.close(); }
static int read_rawgraphics(void *v, int *nelem, const molfile_graphics_t **data) { grasp_t *grasp = (grasp_t *)v; FILE *infile = grasp->fd; // Reverse engineering is your friend, and combined with FORTRAN code, voila! // od -c shows the header starts off: // \0 \0 \0 P f o r m a t = 2 // and according to ungrasp, this is a 1 for grasp versions 1.0 // and 1.1, and 2 for grasp version 1.2 // Also, the header lines are of length 80 characters + 4 header chars // + 4 trailer chars // The 4 bytes at the beginning/end are standard Fortran array trash /// Pointers grassp type GRASSP datax; char trash[4]; #define TRASH fread(trash, 4, 1, infile) char line[81]; // FIRST LINE OF HEADER; contains format type TRASH; fread(line, 1, 80, infile); // make sure it says 'format=' if (strncmp(line, "format=", 7) != 0) { printf("graspplugin) First characters of file don't look like a GRASP file\n"); return MOLFILE_ERROR; } TRASH; // next char should be a 0 or 1 char gfiletype = line[7]; if (gfiletype == '1') { gfiletype = 1; } else if (gfiletype == '2') { gfiletype = 2; } else { printf("graspplugin) GRASP file is in format %c, but only '1' or '2' is supported\n", gfiletype); return MOLFILE_ERROR; } // SECOND LINE: contains "vertices,accessibles,normals,triangles" TRASH; fread(line, 1, 80, infile); TRASH; // THIRD LINE: contains (0 or more of)? // "potentials,curvature,distances,gproperty,g2property,vertexcolor TRASH; line3(infile, &datax);/// Reads line 3 TRASH; // FOURTH LINE stores vertices, triangles, gridsize, lattice spacing int nvert, ntriangles, gridsize; float lattice; TRASH; fread(line, 1, 80, infile); TRASH; sscanf(line, "%d%d%d%f", &nvert, &ntriangles, &gridsize, &lattice); /// Stores color float *colores = new float [3*nvert]; // FIFTH LINE stores the center (x,y,z) position float center[3]; TRASH; fread(line, 1, 80, infile); TRASH; sscanf(line, "%f%f%f", center, center+1, center+2); float *vertex = new float[3 * nvert]; float *access = new float[3 * nvert]; float *normal = new float[3 * nvert]; int *triangle = new int[3 * ntriangles]; float *properties = new float[3* nvert]; if (!vertex || !access || !normal || !triangle || !properties) { delete [] vertex; delete [] access; delete [] normal; delete [] triangle; delete [] properties; printf("graspplugin) Failed vertex/access/normal/triangle allocations.\n"); return MOLFILE_ERROR; } // ungrasp says: // if (filetype.eq.1) then integer*2 // if (filetype.eq.2) then integer*4 // And read them in. Who needs error checking? TRASH; fread(vertex, 3 * sizeof(float), nvert, infile); TRASH; TRASH; fread(access, 3 * sizeof(float), nvert, infile); TRASH; TRASH; fread(normal, 3 * sizeof(float), nvert, infile); TRASH; if (is_little_endian()) { swap4_aligned(vertex, 3*nvert); swap4_aligned(access, 3*nvert); swap4_aligned(normal, 3*nvert); } if (gfiletype == 2) { TRASH; fread(triangle, 3 * sizeof(int), ntriangles, infile); TRASH; TRASH; fread(properties, 3 * sizeof(float), nvert, infile); if (is_little_endian()) { swap4_aligned(triangle, 3*ntriangles); swap4_aligned(properties, 3*nvert); } } else { #if 1 int i; short *striangle = new short[3 * ntriangles]; if (!striangle) { delete [] vertex; delete [] access; delete [] normal; delete [] triangle; delete [] properties; printf("graspplugin) Failed short triangle allocation.\n"); return MOLFILE_ERROR; } TRASH; fread(striangle, sizeof(short), 3 * ntriangles, infile); TRASH; TRASH; fread(properties, sizeof(float), 3 * nvert, infile); if (is_little_endian()) { swap2_aligned(striangle, 3 * ntriangles); swap4_aligned(properties, 3*nvert);} for (i=0; i<3*ntriangles; i++) { triangle[i] = striangle[i]; } delete [] striangle; #else // do it the slow way (converting from short to int) int i; short tmp[3]; TRASH; for (i=0; i<ntriangles; i++) { fread(tmp, sizeof(short), 3, infile); if (is_little_endian()) swap2_aligned(tmp, 3); triangle[3*i+0] = tmp[0]; triangle[3*i+1] = tmp[1]; triangle[3*i+2] = tmp[2]; } TRASH; TRASH; fread(properties, sizeof(float), 3 * nvert, infile); if (is_little_endian()) swap4_aligned(properties, 3*nvert); #endif } /// Gets properties: potentials, curvature, distances, gproperty, g2property or vertexcolor Get_Property_Values(&datax, properties, colores, nvert); // And draw things grasp->graphics = new molfile_graphics_t[3*ntriangles]; int vert1, vert2, vert3; for (int tri_count = 0; tri_count < ntriangles; tri_count++) { vert1 = triangle[3*tri_count+0] - 1; // from 1-based FORTRAN vert2 = triangle[3*tri_count+1] - 1; // to 0-based C++ vert3 = triangle[3*tri_count+2] - 1; if (vert1 < 0 || vert2 < 0 || vert3 < 0 || vert1 >= nvert || vert2 >= nvert || vert3 >= nvert) { printf("graspplugin) Error, out-of-range vertex index, aborting.\n"); delete [] vertex; delete [] access; delete [] normal; delete [] triangle; delete [] properties; return MOLFILE_ERROR; } grasp->graphics[2*tri_count ].type = MOLFILE_TRINORM; grasp->graphics[2*tri_count+1].type = MOLFILE_NORMS; grasp->graphics[2*tri_count+2].type = MOLFILE_COLOR; float *tridata = grasp->graphics[2*tri_count ].data; float *normdata = grasp->graphics[2*tri_count+1].data; float *colordata = grasp->graphics[2*tri_count+2].data; memcpy(tridata , vertex+3*vert1, 3*sizeof(float)); memcpy(tridata+3, vertex+3*vert2, 3*sizeof(float)); memcpy(tridata+6, vertex+3*vert3, 3*sizeof(float)); memcpy(normdata , normal+3*vert1, 3*sizeof(float)); memcpy(normdata+3, normal+3*vert2, 3*sizeof(float)); memcpy(normdata+6, normal+3*vert3, 3*sizeof(float)); memcpy(colordata , properties+3*vert1, 3*sizeof(float)); memcpy(colordata+3, properties+3*vert2, 3*sizeof(float)); memcpy(colordata+6, properties+3*vert3, 3*sizeof(float)); } *nelem = 2*ntriangles; *data = grasp->graphics; delete [] triangle; delete [] normal; delete [] access; delete [] vertex; delete [] properties; return MOLFILE_SUCCESS; }
static int read_js_structure(void *mydata, int *optflags, molfile_atom_t *atoms) { jshandle *js = (jshandle *) mydata; int i; *optflags = MOLFILE_NOOPTIONS; /* set to no options until we read them */ /* write flags data to the file */ fio_read_int32(js->fd, &js->optflags); if (js->reverseendian) swap4_aligned(&js->optflags, 1); printf("jsplugin) read option flags: %0x08x\n", js->optflags); /* determine whether or not this file contains structure info or not */ if (js->optflags & JSOPT_STRUCTURE) { int numatomnames, numatomtypes, numresnames, numsegids, numchains; char **atomnames = NULL; char **atomtypes = NULL; char **resnames = NULL; char **segids = NULL; char **chains = NULL; short *shortbuf = NULL; /* temp buf for decoding atom records */ int *intbuf = NULL; /* temp buf for decoding atom records */ float *fltbuf = NULL; /* temp buf for decoding atom records */ /* read in block of name string table sizes */ fio_read_int32(js->fd, &numatomnames); fio_read_int32(js->fd, &numatomtypes); fio_read_int32(js->fd, &numresnames); fio_read_int32(js->fd, &numsegids); fio_read_int32(js->fd, &numchains); if (js->reverseendian) { swap4_aligned(&numatomnames, js->natoms); swap4_aligned(&numatomtypes, js->natoms); swap4_aligned(&numresnames, js->natoms); swap4_aligned(&numsegids, js->natoms); swap4_aligned(&numchains, js->natoms); } printf("jsplugin) reading string tables...\n"); printf("jsplugin) %d %d %d %d %d\n", numatomnames, numatomtypes, numresnames, numsegids, numchains); /* allocate string tables */ atomnames = (char **) malloc(numatomnames * sizeof(char *)); atomtypes = (char **) malloc(numatomtypes * sizeof(char *)); resnames = (char **) malloc(numresnames * sizeof(char *)); segids = (char **) malloc(numsegids * sizeof(char *)); chains = (char **) malloc(numchains * sizeof(char *)); printf("jsplugin) atom names...\n"); /* read in the string tables */ for (i=0; i<numatomnames; i++) { atomnames[i] = (char *) malloc(16 * sizeof(char)); fio_fread(atomnames[i], 16 * sizeof(char), 1, js->fd); } printf("jsplugin) atom types...\n"); for (i=0; i<numatomtypes; i++) { atomtypes[i] = (char *) malloc(16 * sizeof(char)); fio_fread(atomtypes[i], 16 * sizeof(char), 1, js->fd); } printf("jsplugin) residue names...\n"); for (i=0; i<numresnames; i++) { resnames[i] = (char *) malloc(8 * sizeof(char)); fio_fread(resnames[i], 8 * sizeof(char), 1, js->fd); } printf("jsplugin) segment names...\n"); for (i=0; i<numsegids; i++) { segids[i] = (char *) malloc(8 * sizeof(char)); fio_fread(segids[i], 8 * sizeof(char), 1, js->fd); } printf("jsplugin) chain names...\n"); for (i=0; i<numchains; i++) { chains[i] = (char *) malloc(2 * sizeof(char)); fio_fread(chains[i], 2 * sizeof(char), 1, js->fd); } printf("jsplugin) reading numeric field tables...\n"); /* read in all of the atom fields */ shortbuf = (void *) malloc(js->natoms * sizeof(short)); printf("jsplugin) atom name indices...\n"); /* read in atom names */ fio_fread(shortbuf, js->natoms * sizeof(short), 1, js->fd); if (js->reverseendian) swap2_aligned(shortbuf, js->natoms); for (i=0; i<js->natoms; i++) { strcpy(atoms[i].name, atomnames[shortbuf[i]]); } printf("jsplugin) atom type indices...\n"); /* read in atom types */ fio_fread(shortbuf, js->natoms * sizeof(short), 1, js->fd); if (js->reverseendian) swap2_aligned(shortbuf, js->natoms); for (i=0; i<js->natoms; i++) { strcpy(atoms[i].type, atomtypes[shortbuf[i]]); } printf("jsplugin) residue name indices...\n"); /* read in resnames */ fio_fread(shortbuf, js->natoms * sizeof(short), 1, js->fd); if (js->reverseendian) swap2_aligned(shortbuf, js->natoms); for (i=0; i<js->natoms; i++) { strcpy(atoms[i].resname, resnames[shortbuf[i]]); } printf("jsplugin) segment name indices...\n"); /* read in segids */ fio_fread(shortbuf, js->natoms * sizeof(short), 1, js->fd); if (js->reverseendian) swap2_aligned(shortbuf, js->natoms); for (i=0; i<js->natoms; i++) { strcpy(atoms[i].segid, segids[shortbuf[i]]); } printf("jsplugin) chain name indices...\n"); /* read in chains */ fio_fread(shortbuf, js->natoms * sizeof(short), 1, js->fd); if (js->reverseendian) swap2_aligned(shortbuf, js->natoms); for (i=0; i<js->natoms; i++) { strcpy(atoms[i].chain, chains[shortbuf[i]]); } if (shortbuf != NULL) { free(shortbuf); shortbuf=NULL; } /* * read in integer data blocks */ intbuf = (int *) malloc(js->natoms * sizeof(int)); printf("jsplugin) residue indices...\n"); /* read in resid */ fio_fread(intbuf, js->natoms * sizeof(int), 1, js->fd); if (js->reverseendian) swap4_aligned(intbuf, js->natoms); for (i=0; i<js->natoms; i++) { atoms[i].resid = intbuf[i]; } if (intbuf != NULL) { free(intbuf); intbuf = NULL; } printf("jsplugin) reading optional per-atom tables...\n"); /* * read in optional single-precision float data blocks */ if (js->optflags & (JSOPT_OCCUPANCY | JSOPT_BFACTOR | JSOPT_MASS | JSOPT_RADIUS | JSOPT_CHARGE)) fltbuf = (void *) malloc(js->natoms * sizeof(float)); /* read in optional data if it exists */ if (js->optflags & JSOPT_OCCUPANCY) { printf("jsplugin) occupancy...\n"); *optflags |= MOLFILE_OCCUPANCY; fio_fread(fltbuf, js->natoms * sizeof(float), 1, js->fd); if (js->reverseendian) swap4_aligned(fltbuf, js->natoms); for (i=0; i<js->natoms; i++) { atoms[i].occupancy = fltbuf[i]; } } if (js->optflags & JSOPT_BFACTOR) { printf("jsplugin) bfactor...\n"); *optflags |= MOLFILE_BFACTOR; fio_fread(fltbuf, js->natoms * sizeof(float), 1, js->fd); if (js->reverseendian) swap4_aligned(fltbuf, js->natoms); for (i=0; i<js->natoms; i++) { atoms[i].bfactor = fltbuf[i]; } } if (js->optflags & JSOPT_MASS) { printf("jsplugin) mass...\n"); *optflags |= MOLFILE_MASS; fio_fread(fltbuf, js->natoms * sizeof(float), 1, js->fd); if (js->reverseendian) swap4_aligned(fltbuf, js->natoms); for (i=0; i<js->natoms; i++) { atoms[i].mass = fltbuf[i]; } } if (js->optflags & JSOPT_CHARGE) { printf("jsplugin) charge...\n"); *optflags |= MOLFILE_CHARGE; fio_fread(fltbuf, js->natoms * sizeof(float), 1, js->fd); if (js->reverseendian) swap4_aligned(fltbuf, js->natoms); for (i=0; i<js->natoms; i++) { atoms[i].charge = fltbuf[i]; } } if (js->optflags & JSOPT_RADIUS) { printf("jsplugin) radius...\n"); *optflags |= MOLFILE_RADIUS; fio_fread(fltbuf, js->natoms * sizeof(float), 1, js->fd); if (js->reverseendian) swap4_aligned(fltbuf, js->natoms); for (i=0; i<js->natoms; i++) { atoms[i].radius = fltbuf[i]; } } if (fltbuf != NULL) { free(fltbuf); fltbuf=NULL; } /* * read in optional integer data blocks */ if (js->optflags & JSOPT_ATOMICNUMBER) intbuf = (void *) malloc(js->natoms * sizeof(int)); if (js->optflags & JSOPT_ATOMICNUMBER) { printf("jsplugin) atomic number...\n"); *optflags |= MOLFILE_ATOMICNUMBER; fio_fread(intbuf, js->natoms * sizeof(int), 1, js->fd); if (js->reverseendian) swap4_aligned(intbuf, js->natoms); for (i=0; i<js->natoms; i++) { atoms[i].atomicnumber = intbuf[i]; } } if (intbuf != NULL) { free(intbuf); intbuf = NULL; } /* * read in bonds and fractional bond orders */ if (js->optflags & JSOPT_BONDS) { fio_fread(&js->nbonds, sizeof(int), 1, js->fd); if (js->reverseendian) swap4_aligned(&js->nbonds, 1); printf("jsplugin) %d bonds...\n", js->nbonds); js->bondfrom = (int *) malloc(js->nbonds * sizeof(int)); js->bondto = (int *) malloc(js->nbonds * sizeof(int)); fio_fread(js->bondfrom, js->nbonds * sizeof(int), 1, js->fd); fio_fread(js->bondto, js->nbonds * sizeof(int), 1, js->fd); if (js->reverseendian) { swap4_aligned(js->bondfrom, js->nbonds); swap4_aligned(js->bondto, js->nbonds); } if (js->optflags & JSOPT_BONDORDERS) { printf("jsplugin) bond orders...\n"); js->bondorders = (void *) malloc(js->nbonds * sizeof(float)); fio_fread(js->bondorders, js->nbonds * sizeof(float), 1, js->fd); if (js->reverseendian) swap4_aligned(js->bondorders, js->nbonds); } } if (js->optflags & JSOPT_ANGLES) { fio_fread(&js->numangles, sizeof(int), 1, js->fd); if (js->reverseendian) swap4_aligned(&js->numangles, 1); printf("jsplugin) %d angles...\n", js->numangles); js->angles = (int *) malloc(3 * js->numangles * sizeof(int)); fio_fread(js->angles, sizeof(int)*3*js->numangles, 1, js->fd); if (js->reverseendian) swap4_aligned(&js->angles, 3*js->numangles); fio_fread(&js->numdihedrals, sizeof(int), 1, js->fd); if (js->reverseendian) swap4_aligned(&js->numdihedrals, 1); printf("jsplugin) %d dihedrals...\n", js->numdihedrals); js->dihedrals = (int *) malloc(4 * js->numdihedrals * sizeof(int)); fio_fread(js->dihedrals, sizeof(int)*4*js->numdihedrals, 1, js->fd); if (js->reverseendian) swap4_aligned(&js->dihedrals, 4*js->numdihedrals); fio_fread(&js->numimpropers, sizeof(int), 1, js->fd); if (js->reverseendian) swap4_aligned(&js->numimpropers, 1); js->impropers = (int *) malloc(4 * js->numimpropers * sizeof(int)); printf("jsplugin) %d impropers...\n", js->numimpropers); fio_fread(js->impropers, sizeof(int)*4*js->numimpropers, 1, js->fd); if (js->reverseendian) swap4_aligned(&js->impropers, 4*js->numimpropers); } if (js->optflags & JSOPT_CTERMS) { fio_fread(&js->numcterms, sizeof(int), 1, js->fd); if (js->reverseendian) swap4_aligned(&js->numcterms, 1); js->cterms = (int *) malloc(8 * js->numcterms * sizeof(int)); printf("jsplugin) %d cterms...\n", js->numcterms); fio_fread(js->cterms, sizeof(int)*8*js->numcterms, 1, js->fd); if (js->reverseendian) swap4_aligned(&js->cterms, 8*js->numcterms); } printf("jsplugin) final optflags: %08x\n", *optflags); printf("jsplugin) structure information complete\n"); return MOLFILE_SUCCESS; } printf("jsplugin) no structure information available\n"); /* else, we have no structure information */ return MOLFILE_NOSTRUCTUREDATA; }
static int read_ccp4_data(void *v, int set, float *datablock, float *colorblock) { ccp4_t *ccp4 = (ccp4_t *)v; int x, y, z, xSize, ySize, zSize, extent[3], coord[3]; long xySize; FILE *fd = ccp4->fd; xSize = ccp4->vol[0].xsize; ySize = ccp4->vol[0].ysize; zSize = ccp4->vol[0].zsize; xySize = xSize * ySize; // coord = <col, row, sec> // extent = <colSize, rowSize, secSize> extent[ccp4->xyz2crs[0]] = xSize; extent[ccp4->xyz2crs[1]] = ySize; extent[ccp4->xyz2crs[2]] = zSize; fseek(fd, ccp4->dataOffset, SEEK_SET); // Read entire rows of data from the file, then write into the // datablock with the correct slice ordering. if ((ccp4->voxtype == MRC_TYPE_BYTE) && (ccp4->dataflags & DATA_FLAG_SIGNED)) { printf("ccp4plugin) reading signed-byte voxel data\n"); signed char *rowdata = new signed char[extent[0]]; for (coord[2] = 0; coord[2] < extent[2]; coord[2]++) { for (coord[1] = 0; coord[1] < extent[1]; coord[1]++) { if (feof(fd)) { printf("ccp4plugin) Unexpected end-of-file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (ferror(fd)) { printf("ccp4plugin) Problem reading the file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if ( fread(rowdata, sizeof(char), extent[0], fd) != extent[0] ) { printf("ccp4plugin) Error reading data row.\n"); delete [] rowdata; return MOLFILE_ERROR; } for (coord[0] = 0; coord[0] < extent[0]; coord[0]++) { x = coord[ccp4->xyz2crs[0]]; y = coord[ccp4->xyz2crs[1]]; z = coord[ccp4->xyz2crs[2]]; datablock[x + long(y*xSize) + long(z*xySize)] = rowdata[coord[0]]; } } } delete [] rowdata; } else if ((ccp4->voxtype == MRC_TYPE_BYTE) && !(ccp4->dataflags & DATA_FLAG_SIGNED)) { printf("ccp4plugin) reading unsigned-byte voxel data\n"); unsigned char *rowdata = new unsigned char[extent[0]]; for (coord[2] = 0; coord[2] < extent[2]; coord[2]++) { for (coord[1] = 0; coord[1] < extent[1]; coord[1]++) { if (feof(fd)) { printf("ccp4plugin) Unexpected end-of-file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (ferror(fd)) { printf("ccp4plugin) Problem reading the file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if ( fread(rowdata, sizeof(unsigned char), extent[0], fd) != extent[0] ) { printf("ccp4plugin) Error reading data row.\n"); delete [] rowdata; return MOLFILE_ERROR; } for (coord[0] = 0; coord[0] < extent[0]; coord[0]++) { x = coord[ccp4->xyz2crs[0]]; y = coord[ccp4->xyz2crs[1]]; z = coord[ccp4->xyz2crs[2]]; datablock[x + long(y*xSize) + long(z*xySize)] = rowdata[coord[0]]; } } } delete [] rowdata; } else if (ccp4->voxtype == MRC_TYPE_FLOAT) { printf("ccp4plugin) reading float (32-bit real) voxel data\n"); float *rowdata = new float[extent[0]]; int x, y, z; for (coord[2] = 0; coord[2] < extent[2]; coord[2]++) { for (coord[1] = 0; coord[1] < extent[1]; coord[1]++) { if (feof(fd)) { printf("ccp4plugin) Unexpected end-of-file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (ferror(fd)) { printf("ccp4plugin) Problem reading the file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (fread(rowdata, sizeof(float), extent[0], fd) != extent[0] ) { printf("ccp4plugin) Error reading data row.\n"); delete [] rowdata; return MOLFILE_ERROR; } for (coord[0] = 0; coord[0] < extent[0]; coord[0]++) { x = coord[ccp4->xyz2crs[0]]; y = coord[ccp4->xyz2crs[1]]; z = coord[ccp4->xyz2crs[2]]; datablock[x + long(y*xSize) + long(z*xySize)] = rowdata[coord[0]]; } } } delete [] rowdata; if (ccp4->swap == 1) swap4_aligned(datablock, xySize * zSize); } else if (ccp4->voxtype == MRC_TYPE_SHORT) { printf("ccp4plugin) reading short (16-bit int) voxel data\n"); short *rowdata = new short[extent[0]]; for (coord[2] = 0; coord[2] < extent[2]; coord[2]++) { for (coord[1] = 0; coord[1] < extent[1]; coord[1]++) { if (feof(fd)) { printf("ccp4plugin) Unexpected end-of-file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (ferror(fd)) { printf("ccp4plugin) Problem reading the file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (fread(rowdata, sizeof(short), extent[0], fd) != extent[0] ) { printf("ccp4plugin) Error reading data row.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (ccp4->swap == 1) swap2_aligned(rowdata, extent[0]); for (coord[0] = 0; coord[0] < extent[0]; coord[0]++) { x = coord[ccp4->xyz2crs[0]]; y = coord[ccp4->xyz2crs[1]]; z = coord[ccp4->xyz2crs[2]]; datablock[x + long(y*xSize) + long(z*xySize)] = rowdata[coord[0]]; } } } delete [] rowdata; } else if (ccp4->voxtype == MRC_TYPE_SHORT2) { /* IMOD developers said that this is not used anymore and not worth our time to implement */ printf("TYPE_SHORT2 not implemented yet...\n"); return MOLFILE_ERROR; } else if (ccp4->voxtype == MRC_TYPE_USHORT) { printf("ccp4plugin) reading unsigned short (16-bit int) voxel data\n"); unsigned short *rowdata = new unsigned short[extent[0]]; for (coord[2] = 0; coord[2] < extent[2]; coord[2]++) { for (coord[1] = 0; coord[1] < extent[1]; coord[1]++) { if (feof(fd)) { printf("ccp4plugin) Unexpected end-of-file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (ferror(fd)) { printf("ccp4plugin) Problem reading the file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (fread(rowdata, sizeof(unsigned short), extent[0], fd) != extent[0] ) { printf("ccp4plugin) Error reading data row.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (ccp4->swap == 1) swap2_aligned(rowdata, extent[0]); for (coord[0] = 0; coord[0] < extent[0]; coord[0]++) { x = coord[ccp4->xyz2crs[0]]; y = coord[ccp4->xyz2crs[1]]; z = coord[ccp4->xyz2crs[2]]; datablock[x + long(y*xSize) + long(z*xySize)] = rowdata[coord[0]]; } } } delete [] rowdata; } else if (ccp4->voxtype == MRC_TYPE_UCHAR3) { printf("ccp4plugin) reading unsigned char * 3 (8-bit uchar * 3) voxel data\n"); uchar3 *rowdata = new uchar3[extent[0]]; float grayscale; for (coord[2] = 0; coord[2] < extent[2]; coord[2]++) { for (coord[1] = 0; coord[1] < extent[1]; coord[1]++) { if (feof(fd)) { printf("ccp4plugin) Unexpected end-of-file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if (ferror(fd)) { printf("ccp4plugin) Problem reading the file.\n"); delete [] rowdata; return MOLFILE_ERROR; } if ( fread(rowdata, sizeof(uchar3), extent[0], fd) != extent[0] ) { printf("ccp4plugin) Error reading data row.\n"); delete [] rowdata; return MOLFILE_ERROR; } for (coord[0] = 0; coord[0] < extent[0]; coord[0]++) { x = coord[ccp4->xyz2crs[0]]; y = coord[ccp4->xyz2crs[1]]; z = coord[ccp4->xyz2crs[2]]; grayscale = rowdata[coord[0]].red + rowdata[coord[0]].blue + rowdata[coord[0]].green; datablock[x + long(y*xSize) + long(z*xySize)] = grayscale/3.0; } } } delete [] rowdata; } return MOLFILE_SUCCESS; }