Headers to include: mrcfiles.h, iimage.h
Reads an MRC header into hdata from the file with pointer fin. Determines whether byte-swapping is necessary by requiring that nx, ny, and nz are positive, that one of them is < 65536, and that mapc, mapr, and maps be between 0 and 4. Leaves the file pointer fin in the fp member of hdata. Returns -1 for I/O error, or 1 if these requirements are not met or if the mode or number of labels are inappropriate.
Tests the image size and map entries in MRC header hdata to see if they are within allowed ranges: nx, ny, and nz all positive, and at least one of them less than 65536; and map values between 0 and 3. Returns 0 if that is the case, 1 if not.
Write the MRC header in hdata to the file with pointer fout. Returns 1 for error.
Adds label to the header hdata or replaces the last one if there are already 10 labels. The label will be truncated at 55 characters or padded with spaces to that length, and a standard date-time stamp will be added. Returns 0.
Copies all labels from header hin to header hout. Returns 0.
Copy extra header data from MRC file whose header is in hin to MRC file whose header is in hout, swapping data if necessary after determining whether it consists of short integers or floats and ints. Returns 1 if hin or hout is NULL or the output file is swapped, 2 for seek errors, 3 for memory allocation error, 4 for read or write errors.
Fills in the header structure hdata to default settings for the given file size x, y, z and the given mode. Returns 0.
Initialize the header in hdata for a new output file by eliminating extra header data, setting the MAP stamp, setting the swapped member to 0, and setting the bytesSigned member appropriately.
Computes the pixel size or scale values in the MRC header h and returns them in xs, ys, and zs.
Sets values in the MRC header h so that the pixel size or scale is x, y, and z. If x is nonzero, it sets the xlen element to h to be x times the mx element; otherwise it sets xlen and mx equal to nx. y and z are treated similarly.
Copies the scale values, current tilt angles, and origin values from the MRC header hin to header hout.
Determines the min, max and mean values of the byte data in idata and places them into header hdata. idata must be an array of pointers to hdata->nz planes of data. Returns -1 for error.
Swaps each section of the header hdata as appropriate for its data type.
Returns the value of a single pixel at x, y, z from the file with pointer fin given the header properties in hdata. Gives the value directly for byte, short, and float data, and the magnitude for complex data. Returns the file minimum hdata->amin for coordinates out of bounds.
Allocates and returns one plane of data at the coordinate given by slice along the axis given by axis, which must be one of x, X, y, Y, z, or Z. Reads from the file with pointer fin according to the header in hdata and swaps bytes if necessary. Returns NULL for errors.
Reads one plane of data into the buffer buf at the coordinate given by slice along the axis given by axis, which must be one of x, X, y, Y, z, or Z. Reads from the file with pointer fin according to the header in hdata and swaps bytes if necessary. Should work with planes > 4 GB on 64-bit systems. Returns -1 for errors.
Reads a whole Z slice at Z value slice from the MRC file whose header is is in hdata, and returns it into buf. Works only for real data (byte, integer, float). Simply calls mrcReadZFloat . Returns 1 for an illegal request, 2 for a memory error, or 3 for an error reading the file.
Reads an MRC file into an array of unsigned bytes and returns an array of pointers to the planes of data. fin is the pointer to the file, hdata is the MRC header structure, li is an IloadInfo structure specifying the limits and scaling of the load, and func is a function to receive a status string after each slice. If li is NULL, sensible defaults are used. Scaling is set from the smin, smax, black, white and ramptype members of li using mrcContrastScaling , where ramptype can be MRC_RAMP_LIN, MRC_RAMP_LOG, or MRC_RAMP_EXP, but the latter two should be used only for integer and float input data. Data memory is allocated with mrcGetDataMemory and should be freed with mrcFreeDataMemory . Should work with planes > 4 GB on 64-bit systems. The dimensions and mode in hdata (as well as the mx and xlen members, etc.), are modified so as to be appropriate if the data volume is written. Returns NULL for error.
Computes scaling of data to bytes with potentially two levels of scaling. The first level of scaling maps smin and smax to 0 to 255; if these two values are equal, then the file min and max in hdata are used instead. The second level of scaling maps black and white in these scaled values to 0 to 255 to mimic the effect of black and white sliders in 3dmod. ramptype can be MRC_RAMP_LIN, MRC_RAMP_LOG, or MRC_RAMP_EXP. The factors for scaling by pixel * slope + offset are returned in slope and offset.
Writes byte data in data to the file with pointer fout according to the dimensions in header hdata. data must be an array of pointers to hdata->nz planes of data. Returns 0 (no error checks). Unused 5/7/05. Should write bytes as signed when appropriate, but this is untested.
Writes byte, short, or float image data to the file with pointer fout according to the dimensions and mode in header hdata. data must be an array of pointers to hdata->nz planes of data. Should be able to handle planes > 4 GB. Returns -1 for attempt to write a byte-swapped file, 0 for improper mode, -2 for a write error, or 1 for success. Was used by mrcbyte until 5/30/08. Should write bytes as signed when appropriate, but this is untested.
Writes one plane of data from the buffer buf at the coordinate given by slice along the axis given by axis, which must be one of x, X, y, Y, z, or Z. Writes to the file with pointer fout according to the header in hdata and swaps bytes if necessary. Should handle planes > 4 GB on 64-bit systems. Returns -1 for errors.
Writes one Z slice of data at Z = slice from the buffer buf to file fout according the header in hdata. If parallel writing has been initialized, lines will be written to a boundary file if appropriate. Returns errors from writing the slice with mrc_write_slice and also returns other non-zero values from opening the boundary file, writing its header, or writing to the file.
Reads one Z slice of raw data at Z value z into the buffer buf from the MRC file whose header is in hdata. The IloadInfo structure li controls the subarea loaded through its members xmin, xmax, ymin, and ymax. Returns 1 for an illegal request, 2 for a memory error, or 3 for an error reading the file.
Reads one Z slice of data, like mrcReadZ, and scales it to bytes. Scaling is controlled by li members slope, offset, and ramp, but ramp should be MRC_RAMP_LIN unless reading in integers or floats.
Reads one Z slice of data, like mrcReadZ, and scales it to unsigned short integers. Scaling is controlled by li members slope, offset, and ramp, but ramp should be MRC_RAMP_LIN unless reading in integers or floats.
Reads one Z slice of data, like mrcReadZ, and returns it as floats. Only works for real modes: byte, signed and unsigned short, float.
Reads one Y slice of raw data at Y value z into the buffer buf from the MRC file whose header is in hdata. The IloadInfo structure li controls the subarea loaded through its members xmin, xmax, zmin, and zmax. Returns 1 for an illegal request, 2 for a memory error, or 3 for an error reading the file.
Reads one Y slice of data, like mrcReadY, and scales it to bytes. Scaling is controlled by li members slope, offset, and ramp, but ramp should be MRC_RAMP_LIN unless reading in integers or floats.
Reads one Y slice of data, like mrcReadY, and scales it to unsigned short integers. Scaling is controlled by li members slope, offset, and ramp, but ramp should be MRC_RAMP_LIN unless reading in integers or floats.
Reads one Y slice of data, like mrcReadY, and returns it as floats. Only works for real modes: byte, signed and unsigned short, and float.
Reads one slice of raw data into the buffer buf from the MRC file whose header is in hdata. A Y slice at Y = z is loaded if the axis member of li is 2; otherwise a Z slice at Z = z is loaded. The subarea loaded is determined by li members xmin, xmax, and ymin and ymax (for a Z slice) or zmin and zmax (for a Y slice). Returns 1 for an illegal request, 2 for a memory error, or 3 for an error reading the file.
Reads one slice of data, like mrcReadSection, and scales it to bytes. Scaling is controlled by li members slope, offset, and ramp, but ramp should be MRC_RAMP_LIN unless reading in integers or floats.
Reads one slice of data, like mrcReadSection, and scales it to bytes. Scaling is controlled by li members slope, offset, and ramp, but ramp should be MRC_RAMP_LIN unless reading in integers or floats.
Reads one slice of data, like mrcReadSection, and returns it as floats. Only works for real modes: byte, signed and unsigned short, and float.
Allocates memory for zsize planes of data to contain xysize pixels at pixsize bytes per pixel, and returns an array of pointers to the planes. It attempts to allocate the data in contigous memory if li is non-NULL and the contig element of li is non-zero. If this fails it falls back to allocating planes separately, sets contig to 0, and issues a warning with b3dError. Should be able to allocate planes > 4GB on 64-bit systems. Returns NULL for error.
Frees data memory allocated by mrcGetDataMemory; zsize specifies the number of Z planes and contig indicates if the memory was allocated contiguously
Returns a pointer to a lookup table of 256 scaled intensities, given a scaling specified by index * slope + offset. Output values will be truncated at outmin and outmax. If outmax is <= 255 then the map will indeed be unsigned bytes, but if outmax is > 255 then the map will be unsigned shorts instead. If bytesSigned is nonzero, then the map will be wrapped around so that signed values read from file and used as unsigned values when indexing the map will be shifted up by 128.
Returns a pointer to a lookup table of scaled intensities for 65536 index values, which can be either unsigned or signed short integers. The scaling will be index * slope + offset for ramptype = MRC_RAMP_LIN, exp(index) * slope + offset for ramptype = MRC_RAMP_EXP, and log(index) * slope + offset for ramptype = MRC_RAMP_LOG. Output values will be truncated at outmin and outmax. If outmax is <= 255 then the map will indeed be unsigned bytes, but if outmax is > 255 then the map will be unsigned shorts instead. Set swapbytes nonzero to for a table that swaps bytes, and signedint nonzero for signed integer indices. The table is allocated with malloc and should be freed by the caller. Returns NULL for error allocating memory.
Returns a standard scaling factor for taking the log of complex data by log (1 + scale * value)
Computes the min and max for log scaling of complex numbers between inMin and inMax and returns them in outMin and outMax
For a mirrored FFT whose full size is nx by ny, computes where the location imageX, imageY in the image comes from in the file and returns this location in fileX, fileY.
Initialize the IloadInfo structure li with some sensible default values if hd is NULL; otherwise it just calls mrc_fix_li with the sizes defined in the header hd. For proper initialization, this function must be called once with a hd NULL, then again with a header if needed. Returns -1 if hd is NULL.
Fixes the min and max loading parameters (xmin, xmax, etc) in the IloadInfo structure * li based on the image dimensions given either in nx, ny, nz or in the px, py, and pz elements of li if there is a piece list. Undefined parameters are changed to full-range values and values are fixed to be within 0 to the dimension - 1.
Gets x, y, and z loading limits for a MRC file whose header is in hdata and places them in the IloadInfo structure * li, using interactive input from standard input. Returns 1 for no errors.
For the given MRC file mode in mode, returns the number of bytes of the basic data element in dsize and the number of data channels in csize. Returns -1 for an unsupported or undefined mode.
Swaps the bytes in 16-bit integers in data; amt specifies the number of values to swap.
Swaps the bytes in 32-bit integers in data; amt specifies the number of values to swap.
Swaps the bytes in 32-bit floats in data; amt specifies the number of values to swap.
#define MRC_MODE_BYTE 0 #define MRC_MODE_SHORT 1 #define MRC_MODE_FLOAT 2 #define MRC_MODE_COMPLEX_SHORT 3 #define MRC_MODE_COMPLEX_FLOAT 4 #define MRC_MODE_USHORT 6 #define MRC_MODE_RGB 16
typedef struct MRCheader { b3dInt32 nx; /* # of Columns */ b3dInt32 ny; /* # of Rows */ b3dInt32 nz; /* # of Sections. */ b3dInt32 mode; /* given by #define MRC_MODE... */ b3dInt32 nxstart; /* Starting point of sub image. */ b3dInt32 nystart; b3dInt32 nzstart; b3dInt32 mx; /* Number of rows to read. */ b3dInt32 my; b3dInt32 mz; b3dFloat xlen; /* length of x element in um. */ b3dFloat ylen; /* get scale = xlen/nx ... */ b3dFloat zlen; b3dFloat alpha; /* cell angles, ignore */ b3dFloat beta; b3dFloat gamma; b3dInt32 mapc; /* map coloumn 1=x,2=y,3=z. */ b3dInt32 mapr; /* map row 1=x,2=y,3=z. */ b3dInt32 maps; /* map section 1=x,2=y,3=z. */ b3dFloat amin; b3dFloat amax; b3dFloat amean; b3dInt16 ispg; /* image type */ b3dInt16 nsymbt; /* space group number */ /* 64 bytes */ b3dInt32 next; b3dInt16 creatid; /* Used to be creator id, hvem = 1000, now 0 */ b3dByte blank[30]; b3dInt16 nint; b3dInt16 nreal; b3dInt16 sub; b3dInt16 zfac; b3dFloat min2; b3dFloat max2; b3dFloat min3; b3dFloat max3; b3dInt32 imodStamp; b3dInt32 imodFlags; /* UINT extra[MRC_NEXTRA];*/ /* HVEM extra data */ /* DNM 3/16/01: divide idtype into two shorts */ b3dInt16 idtype; b3dInt16 lens; b3dInt16 nd1; /* Devide by 100 to get float value. */ b3dInt16 nd2; b3dInt16 vd1; b3dInt16 vd2; b3dFloat tiltangles[6]; /* 0,1,2 = original: 3,4,5 = current */ #ifdef OLD_STYLE_HEADER /* before 2.6.20 */ /* DNM 3/16/01: redefine the last three floats as wavelength numbers */ b3dInt16 nwave; /* # of wavelengths and values */ b3dInt16 wave1; b3dInt16 wave2; b3dInt16 wave3; b3dInt16 wave4; b3dInt16 wave5; b3dFloat zorg; /* origin */ b3dFloat xorg; b3dFloat yorg; #else /* MRC 2000 standard */ b3dFloat xorg; b3dFloat yorg; b3dFloat zorg; b3dByte cmap[4]; b3dByte stamp[4]; b3dFloat rms; #endif b3dInt32 nlabl; b3dByte labels[MRC_NLABELS][MRC_LABEL_SIZE + 1]; /* Internal data not stored in file header */ b3dUByte *symops; FILE *fp; int pos; struct LoadInfo *li; int headerSize; int sectionSkip; int swapped; int bytesSigned; int yInverted; char *pathname; char *filedesc; char *userData; } MrcHeader;
typedef struct LoadInfo { /* Sub area to load. */ int xmin; int xmax; int ymin; int ymax; int zmin; int zmax; int ramp; /* Contrast ramp type. */ int scale; int black; /* Change contrast values. */ int white; int axis; /* 1=x, 2=y, 3=z , 0 = default */ float slope; /* Scale input by value * slope + offset */ float offset; float smin,smax; /* Scale range smin-smax in input to 0-255 */ int contig; /* Load idata in contigous memory if possible */ int outmin, outmax; /* clamp values to outmin and outmax after scaling. */ int mirrorFFT; /* Return mirrored FFT when scaling to bytes */ int plist; /* Size of piece list. */ float opx, opy, opz; /* origin of pieces. */ float px, py, pz; /* size of final pieced image. */ int pdz; /* number of zsections that have data. */ int *pcoords; /* The piece list. */ } IloadInfo;