1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
|
/* File: pycbf.i */
// Indicate that we want to generate a module call pycbf
%module pycbf
%pythoncode %{
__author__ = "Jon Wright <wright@esrf.fr>"
__date__ = "14 Dec 2005"
__version__ = "CBFlib 0.9"
__credits__ = """Paul Ellis and Herbert Bernstein for the excellent CBFlib!"""
__doc__=""" pycbf - python bindings to the CBFlib library
A library for reading and writing ImageCIF and CBF files
which store area detector images for crystallography.
This work is a derivative of the CBFlib version 0.7.7 library
by Paul J. Ellis of Stanford Synchrotron Radiation Laboratory
and Herbert J. Bernstein of Bernstein + Sons
See:
http://www.bernstein-plus-sons.com/software/CBF/
Licensing is GPL based, see:
http://www.bernstein-plus-sons.com/software/CBF/doc/CBFlib_NOTICES.html
These bindings were automatically generated by SWIG, and the
input to SWIG was automatically generated by a python script.
We very strongly recommend you do not attempt to edit them
by hand!
Copyright (C) 2007 Jonathan Wright
ESRF, Grenoble, France
email: wright@esrf.fr
Revised, August 2010 Herbert J. Bernstein
Add defines from CBFlib 0.9.1
"""
%}
// Used later to pass back binary data
%include "cstring.i"
// Attempt to autogenerate what SWIG thinks the call looks like
// Typemaps are a SWIG mechanism for many things, not least multiple
// return values
%include "typemaps.i"
// Arrays are needed
%include "carrays.i"
%array_class(double, doubleArray)
%array_class(int, intArray)
%array_class(short, shortArray)
%array_class(long, longArray)
// Following the SWIG 1.3 documentation at
// http://www.swig.org/Doc1.3/Python.html
// section 31.9.5, we map sequences of
// PyFloat, PyLong and PyInt to
// C arrays of double, long and int
//
// But with the strict checking of being a float
// commented out to allow automatic conversions
%{
static int convert_darray(PyObject *input, double *ptr, int size) {
int i;
if (!PySequence_Check(input)) {
PyErr_SetString(PyExc_TypeError,"Expecting a sequence");
return 0;
}
if (PyObject_Length(input) != size) {
PyErr_SetString(PyExc_ValueError,"Sequence size mismatch");
return 0;
}
for (i =0; i < size; i++) {
PyObject *o = PySequence_GetItem(input,i);
/*if (!PyFloat_Check(o)) {
Py_XDECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats");
return 0;
}*/
ptr[i] = PyFloat_AsDouble(o);
Py_DECREF(o);
}
return 1;
}
%}
%typemap(in) double [ANY](double temp[$1_dim0]) {
if ($input == Py_None) $1 = NULL;
else
if (!convert_darray($input,temp,$1_dim0)) {
return NULL;
}
$1 = &temp[0];
}
%{
static long convert_larray(PyObject *input, long *ptr, int size) {
int i;
if (!PySequence_Check(input)) {
PyErr_SetString(PyExc_TypeError,"Expecting a sequence");
return 0;
}
if (PyObject_Length(input) != size) {
PyErr_SetString(PyExc_ValueError,"Sequence size mismatch");
return 0;
}
for (i =0; i < size; i++) {
PyObject *o = PySequence_GetItem(input,i);
/*if (!PyLong_Check(o)) {
Py_XDECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of long integers");
return 0;
}*/
ptr[i] = PyLong_AsLong(o);
Py_DECREF(o);
}
return 1;
}
%}
%typemap(in) long [ANY](long temp[$1_dim0]) {
if (!convert_larray($input,temp,$1_dim0)) {
return NULL;
}
$1 = &temp[0];
}
%{
static int convert_iarray(PyObject *input, int *ptr, int size) {
int i;
if (!PySequence_Check(input)) {
PyErr_SetString(PyExc_TypeError,"Expecting a sequence");
return 0;
}
if (PyObject_Length(input) != size) {
PyErr_SetString(PyExc_ValueError,"Sequence size mismatch");
return 0;
}
for (i =0; i < size; i++) {
PyObject *o = PySequence_GetItem(input,i);
/*if (!PyInt_Check(o)) {
Py_XDECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of long integers");
return 0;
}*/
ptr[i] = (int)PyInt_AsLong(o);
Py_DECREF(o);
}
return 1;
}
%}
%typemap(in) int [ANY](int temp[$1_dim0]) {
if (!convert_iarray($input,temp,$1_dim0)) {
return NULL;
}
$1 = &temp[0];
}
%{ // Here is the c code needed to compile the wrappers, but not
// to be wrapped
#include "../include/cbf.h"
#include "../include/cbf_simple.h"
// Helper functions to generate error message
static int error_status = 0;
static char error_message1[17] ;
static char error_message[1042] ; // hope that is long enough
/* prototype */
void get_error_message(void);
void get_error_message(){
sprintf(error_message1,"%s","CBFlib Error(s):");
if (error_status & CBF_FORMAT )
sprintf(error_message,"%s %s",error_message1,"CBF_FORMAT ");
if (error_status & CBF_ALLOC )
sprintf(error_message,"%s %s",error_message1,"CBF_ALLOC ");
if (error_status & CBF_ARGUMENT )
sprintf(error_message,"%s %s",error_message1,"CBF_ARGUMENT ");
if (error_status & CBF_ASCII )
sprintf(error_message,"%s %s",error_message1,"CBF_ASCII ");
if (error_status & CBF_BINARY )
sprintf(error_message,"%s %s",error_message1,"CBF_BINARY ");
if (error_status & CBF_BITCOUNT )
sprintf(error_message,"%s %s",error_message1,"CBF_BITCOUNT ");
if (error_status & CBF_ENDOFDATA )
sprintf(error_message,"%s %s",error_message1,"CBF_ENDOFDATA ");
if (error_status & CBF_FILECLOSE )
sprintf(error_message,"%s %s",error_message1,"CBF_FILECLOSE ");
if (error_status & CBF_FILEOPEN )
sprintf(error_message,"%s %s",error_message1,"CBF_FILEOPEN ");
if (error_status & CBF_FILEREAD )
sprintf(error_message,"%s %s",error_message1,"CBF_FILEREAD ");
if (error_status & CBF_FILESEEK )
sprintf(error_message,"%s %s",error_message1,"CBF_FILESEEK ");
if (error_status & CBF_FILETELL )
sprintf(error_message,"%s %s",error_message1,"CBF_FILETELL ");
if (error_status & CBF_FILEWRITE )
sprintf(error_message,"%s %s",error_message1,"CBF_FILEWRITE ");
if (error_status & CBF_IDENTICAL )
sprintf(error_message,"%s %s",error_message1,"CBF_IDENTICAL ");
if (error_status & CBF_NOTFOUND )
sprintf(error_message,"%s %s",error_message1,"CBF_NOTFOUND ");
if (error_status & CBF_OVERFLOW )
sprintf(error_message,"%s %s",error_message1,"CBF_OVERFLOW ");
if (error_status & CBF_UNDEFINED )
sprintf(error_message,"%s %s",error_message1,"CBF_UNDEFINED ");
if (error_status & CBF_NOTIMPLEMENTED)
sprintf(error_message,"%s %s",error_message1,"CBF_NOTIMPLEMENTED");
if (error_status & CBF_NOCOMPRESSION)
sprintf(error_message,"%s %s",error_message1,"CBF_NOCOMPRESSION");
}
%} // End of code which is not wrapped but needed to compile
// The actual wrappers
// Constants needed from header files
/* Constants used for compression */
#define CBF_INTEGER 0x0010 /* Uncompressed integer */
#define CBF_FLOAT 0x0020 /* Uncompressed IEEE floating-point */
#define CBF_CANONICAL 0x0050 /* Canonical compression */
#define CBF_PACKED 0x0060 /* Packed compression */
#define CBF_PACKED_V2 0x0090 /* CCP4 Packed (JPA) compression V2 */
#define CBF_BYTE_OFFSET 0x0070 /* Byte Offset Compression */
#define CBF_PREDICTOR 0x0080 /* Predictor_Huffman Compression */
#define CBF_NONE 0x0040 /* No compression flag */
#define CBF_COMPRESSION_MASK \
0x00FF /* Mask to separate compression
type from flags */
#define CBF_FLAG_MASK 0x0F00 /* Mask to separate flags from
compression type */
#define CBF_UNCORRELATED_SECTIONS \
0x0100 /* Flag for uncorrelated sections */
#define CBF_FLAT_IMAGE 0x0200 /* Flag for flat (linear) images */
#define CBF_NO_EXPAND 0x0400 /* Flag to try not to expand */
/* Constants used for headers */
#define PLAIN_HEADERS 0x0001 /* Use plain ASCII headers */
#define MIME_HEADERS 0x0002 /* Use MIME headers */
#define MSG_NODIGEST 0x0004 /* Do not check message digests */
#define MSG_DIGEST 0x0008 /* Check message digests */
#define MSG_DIGESTNOW 0x0010 /* Check message digests immediately */
#define MSG_DIGESTWARN 0x0020 /* Warn on message digests immediately*/
#define PAD_1K 0x0020 /* Pad binaries with 1023 0's */
#define PAD_2K 0x0040 /* Pad binaries with 2047 0's */
#define PAD_4K 0x0080 /* Pad binaries with 4095 0's */
/* Constants used to control CIF parsing */
#define CBF_PARSE_BRC 0x0100 /* PARSE DDLm/CIF2 brace {,...} */
#define CBF_PARSE_PRN 0x0200 /* PARSE DDLm parens (,...) */
#define CBF_PARSE_BKT 0x0400 /* PARSE DDLm brackets [,...] */
#define CBF_PARSE_BRACKETS \
0x0700 /* PARSE ALL brackets */
#define CBF_PARSE_TQ 0x0800 /* PARSE treble quotes """...""" and '''...''' */
#define CBF_PARSE_CIF2_DELIMS \
0x1000 /* Do not scan past an unescaped close quote
do not accept {} , : " ' in non-delimited
strings'{ */
#define CBF_PARSE_DDLm 0x0700 /* For DDLm parse (), [], {} */
#define CBF_PARSE_CIF2 0x1F00 /* For CIF2 parse {}, treble quotes,
stop on unescaped close quotes */
#define CBF_PARSE_DEFINES \
0x2000 /* Recognize DEFINE_name */
#define CBF_PARSE_WIDE 0x4000 /* PARSE wide files */
#define CBF_PARSE_UTF8 0x10000 /* PARSE UTF-8 */
#define HDR_DEFAULT (MIME_HEADERS | MSG_NODIGEST)
#define MIME_NOHEADERS PLAIN_HEADERS
/* CBF vs CIF */
#define CBF 0x0000 /* Use simple binary sections */
#define CIF 0x0001 /* Use MIME-encoded binary sections */
/* Constants used for encoding */
#define ENC_NONE 0x0001 /* Use BINARY encoding */
#define ENC_BASE64 0x0002 /* Use BASE64 encoding */
#define ENC_BASE32K 0x0004 /* Use X-BASE32K encoding */
#define ENC_QP 0x0008 /* Use QUOTED-PRINTABLE encoding */
#define ENC_BASE10 0x0010 /* Use BASE10 encoding */
#define ENC_BASE16 0x0020 /* Use BASE16 encoding */
#define ENC_BASE8 0x0040 /* Use BASE8 encoding */
#define ENC_FORWARD 0x0080 /* Map bytes to words forward (1234) */
#define ENC_BACKWARD 0x0100 /* Map bytes to words backward (4321) */
#define ENC_CRTERM 0x0200 /* Terminate lines with CR */
#define ENC_LFTERM 0x0400 /* Terminate lines with LF */
#define ENC_DEFAULT (ENC_BASE64 | ENC_LFTERM | ENC_FORWARD)
// Exception handling
/* Convenience definitions for functions returning error codes */
%exception {
error_status=0;
$action
if (error_status){
get_error_message();
PyErr_SetString(PyExc_Exception,error_message);
return NULL;
}
}
/* Retain notation from cbf lib but pass on as python exception */
#define cbf_failnez(x) {(error_status = x);}
/* printf("Called \"x\", status %d\n",error_status);} */
#define cbf_onfailnez(x,c) {int err; err = (x); if (err) { fprintf (stderr, \
"\nCBFlib error %d in \"x\"\n", err); \
{ c; } return err; }}
%include "cbfgenericwrappers.i"
// cbf_goniometer object
%include "cbfgoniometerwrappers.i"
%include "cbfdetectorwrappers.i"
// cbfhandle object
%include "cbfhandlewrappers.i"
|