International
Tables for
Crystallography
Volume G
Definition and exchange of crystallographic data
Edited by S. R. Hall and B. McMahon

International Tables for Crystallography (2006). Vol. G, ch. 5.6, pp. 555-556

Section 5.6.5. Example programs

P. J. Ellisa and H. J. Bernsteinb*

aStanford Linear Accelerator Center, 2575 Sand Hill Road, Menlo Park, CA 94025, USA, and bDepartment of Mathematics and Computer Science, Kramer Science Center, Dowling College, Idle Hour Blvd, Oakdale, NY 11769, USA
Correspondence e-mail:  yaya@bernstein-plus-sons.com

5.6.5. Example programs

| top | pdf |

The CBFlib API comes with example programs and sample templates. The example program convert_image reads either of the templates described in Section 5.6.4[link], template_adscquantum4_2304x2304.cbf and template_mar­345_2300x2300.cbf, and uses the higher-level CBFlib routines to convert an image file to a CBF.

The example programs makecbf and img2cif read an image file from a MAR300, MAR345 or ADSC CCD detector and then use CBFlib to convert that image to CBF format (makecbf) or to either imgCIF or CBF format (img2cif). makecbf writes the CBF-format image to disk, reads it in again, and then compares it with the original. img2cif just writes the desired file without a verification pass. makecbf works only from files on disk, so that random input/output can be used. img2cif includes code to process files from stdin and to stdout. The example program cif2cbf copies an ASCII CIF to a binary CBF/imgCIF file.

5.6.5.1. convert_image

| top | pdf |

The program convert_image takes two arguments, imagefile and cbffile. These are the primary input and output. The detector type is extracted from the image file, converted to lower case and used to construct the name of a template CBF to use for the copy. The template file name is of the form template_name_columnsxrows. The program comes with img.c and img.h to read image files. It uses the img_... routines to extract data and metadata from the image and uses the higher-level CBFlib routines to populate the template. Fig. 5.6.5.1[link] is a portion of the code that reads in the template and inserts the wavelength, the distance to the detector, and the oscillation start and range.

[Figure 5.6.5.1]

Figure 5.6.5.1 | top | pdf |

An extract of program code for the conversion of image data to CBF format.

5.6.5.2. makecbf

| top | pdf |

makecbf is a good example of how to use many of the lower-level CBFlib functions. An example MAR345 image can be found at http://smb.slac.stanford.edu/~ellis/ and on the CD-ROM accompanying this volume. To run makecbf with the example image, type: [Scheme scheme4]

The typical code fragment from makecbf.c shown in Fig. 5.6.5.2[link] creates the DIFFRN_FRAME_DATA category.

[Figure 5.6.5.2]

Figure 5.6.5.2 | top | pdf |

Code fragment to illustrate the creation of the DIFFRN_FRAME_DATA category.

The program img2cif is an extended version of makecbf that allows the user to choose the details of the format of the output CBF. img2cif has the following command-line interface: [Scheme scheme126] -i takes the name of the input image file in MAR300, MAR345 or ADSC CCD detector format. If no input_image file is specified or is given as `-', an image is copied from stdin to a temporary file. -o takes the name of the output CIF (if BASE64 or quoted-printable encoding is used) or CBF (if no encoding is used). If no output_cif is specified or is given as `-', the output is written to stdout. -c specifies the compression scheme (packed, canonical or none; the default is packed). -m selects MIME (Freed & Borenstein, 1996[link]) headers within binary data value text fields. The default is headers for CIFs, no headers for CBFs. -d specifies the use of digests. The default is the MD5 digest (Rivest, 1992[link]) when MIME headers are selected. -e specifies one of the standard MIME encodings: BASE64 (the default) or quoted-printable; or a non-standard decimal, hexadecimal or octal encoding for an ASCII CIF; or `none' for a binary CBF. -b specifies the direction of mapping of bytes into words for decimal, hexadecimal or octal output, marked by `>' for forwards or `<' for backwards as the second character of each line of output, and in # comment lines. The default is backwards.

5.6.5.3. cif2cbf

| top | pdf |

The test program cif2cbf (Fig. 5.6.5.3[link]) uses the same command-line options as img2cif, but accepts either a CIF or a CBF as input instead of an image file. The heart of the code is a series of nested loops. The outermost loop scans through all the data blocks. The next innermost loop scans through all the categories within each data block. The first of the two next innermost loops scans through the columns to copy the column headings. Then the second of these two loops scans through the rows. Finally, the innermost loop scans through the columns for each row.

[Figure 5.6.5.3]

Figure 5.6.5.3 | top | pdf |

Listing of the main code fragment in the program cif2cbf for conversion of an ASCII CIF to a CBF file.

References

Freed, N. & Borenstein, N. (1996). Multipurpose Internet Mail Extensions (MIME) part one: format of internet message bodies. RFC 2045. Internet Engineering Task Force. http://www.ietf.org/rfc/rfc2045.txt .
Rivest, R. (1992). The MD5 message-digest algorithm. RFC 1321. Internet Engineering Task Force. http://www.ietf.org/rfc/rfc1321.txt .








































to end of page
to top of page