Changeset 6eaf89ea in sasview for src/sas/sascalc/file_converter/c_ext
- Timestamp:
- Aug 5, 2016 3:49:33 AM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- c3f0114
- Parents:
- e5308b6
- Location:
- src/sas/sascalc/file_converter/c_ext
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/file_converter/c_ext/bsl_loader.c
r28e2b3a r6eaf89ea 24 24 const int n_pixels; 25 25 const int n_rasters; 26 const int swap_bytes; 26 27 if (self != NULL) { 27 if (!PyArg_ParseTuple(args, "siii ", &filename, &frame, &n_pixels, &n_rasters))28 if (!PyArg_ParseTuple(args, "siiii", &filename, &frame, &n_pixels, &n_rasters, &swap_bytes)) 28 29 Py_RETURN_NONE; 29 30 if (!(self->params.filename = malloc(strlen(filename) + 1))) … … 33 34 self->params.n_pixels = n_pixels; 34 35 self->params.n_rasters = n_rasters; 36 self->params.swap_bytes = swap_bytes; 35 37 } 36 38 … … 46 48 char str[100]; 47 49 sprintf(str, 48 "Filename: %s\nframe: %d\nn_pixels: %d\nn_rasters: %d\n ",50 "Filename: %s\nframe: %d\nn_pixels: %d\nn_rasters: %d\nswap_bytes: %d", 49 51 self->params.filename, 50 52 self->params.frame, 51 53 self->params.n_pixels, 52 self->params.n_rasters); 54 self->params.n_rasters, 55 self->params.swap_bytes); 53 56 return Py_BuildValue("s", str); 54 57 } … … 104 107 105 108 return Py_BuildValue("i", self->params.n_rasters); 109 } 110 111 static PyObject *get_swap_bytes(CLoader *self, PyObject *args) { 112 return Py_BuildValue("i", self->params.swap_bytes); 113 } 114 115 static PyObject *set_swap_bytes(CLoader *self, PyObject *args) { 116 int new_swap; 117 if (!PyArg_ParseTuple(args, "i", &new_swap)) 118 return NULL; 119 self->params.swap_bytes = new_swap; 120 121 return Py_BuildValue("i", self->params.swap_bytes); 122 } 123 124 float reverse_float(const float in_float){ 125 float retval; 126 char *to_convert = (char *)&in_float; 127 char *return_float = (char *)&retval; 128 129 return_float[0] = to_convert[3]; 130 return_float[1] = to_convert[2]; 131 return_float[2] = to_convert[1]; 132 return_float[3] = to_convert[0]; 133 134 return retval; 106 135 } 107 136 … … 138 167 for (pixel = 0; pixel < self->params.n_pixels; pixel++) { 139 168 fread(&cur_val, sizeof(float), 1, input_file); 169 if (self->params.swap_bytes == 0) 170 cur_val = reverse_float(cur_val); 140 171 PyArray_SETITEM(data, PyArray_GETPTR2(data, raster, pixel), PyFloat_FromDouble(cur_val)); 141 172 read_val = PyArray_GETITEM(data, PyArray_GETPTR2(data, raster, pixel)); … … 161 192 { "get_n_rasters", (PyCFunction)get_n_rasters, METH_VARARGS, "Get n_rasters" }, 162 193 { "set_n_rasters", (PyCFunction)set_n_rasters, METH_VARARGS, "Set n_rasters" }, 194 { "get_swap_bytes", (PyCFunction)get_swap_bytes, METH_VARARGS, "Get swap_bytes" }, 195 { "set_swap_bytes", (PyCFunction)set_swap_bytes, METH_VARARGS, "Set swap_bytes" }, 163 196 { "load_data", (PyCFunction)load_data, METH_VARARGS, "Load the data into a numpy array" }, 164 197 {NULL} -
src/sas/sascalc/file_converter/c_ext/bsl_loader.h
r18e7309 r6eaf89ea 11 11 // Number of rasters in the file 12 12 int n_rasters; 13 // Whether or not the bytes are in reverse order 14 int swap_bytes; 13 15 } CLoader_params; 14 16
Note: See TracChangeset
for help on using the changeset viewer.