Changeset e070dc0 in sasview for src/sas/sascalc/file_converter
- Timestamp:
- Aug 8, 2016 9:30:53 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:
- b61bd57
- Parents:
- 9b7c596
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/file_converter/c_ext/bsl_loader.c
r535e181 re070dc0 141 141 /* ----- Instance Methods ----- */ 142 142 143 float reverse_float(const float in_float){ 143 float reverse_float(const float in_float) { 144 // Reverse the order of the bytes of a float 144 145 float retval; 145 146 char *to_convert = (char *)&in_float; … … 163 164 PyArrayObject *data; 164 165 166 // Create a new numpy array to store the data in 165 167 data = (PyArrayObject *)PyArray_SimpleNew(2, size, NPY_FLOAT); 166 168 169 // Attempt to open the file specified 167 170 input_file = fopen(self->params.filename, "rb"); 168 171 if (!input_file) { … … 170 173 } 171 174 175 // Move the file cursor the the position where the data we're interested 176 // in begins 172 177 frame_pos = self->params.n_pixels * self->params.n_rasters * self->params.frame; 173 178 fseek(input_file, frame_pos*sizeof(float), SEEK_SET); … … 175 180 for (raster = 0; raster < self->params.n_rasters; raster++) { 176 181 for (pixel = 0; pixel < self->params.n_pixels; pixel++) { 177 fread(&cur_val, sizeof(float), 1, input_file); 182 // Try reading the file 183 if (fread(&cur_val, sizeof(float), 1, input_file) == 0) { 184 PyErr_SetString(PyExc_RuntimeError, "Error reading file or EOF reached."); 185 return NULL; 186 } 187 188 // Swap the order of the bytes read, if specified that we should do 189 // so in the header file 178 190 if (self->params.swap_bytes == 0) 179 191 cur_val = reverse_float(cur_val); 192 193 // Add the read value to the numpy array 180 194 PyArray_SETITEM(data, PyArray_GETPTR2(data, raster, pixel), PyFloat_FromDouble(cur_val)); 181 195 }
Note: See TracChangeset
for help on using the changeset viewer.