Changeset 535e181 in sasview for src/sas/sascalc
- Timestamp:
- Aug 5, 2016 11:48: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:
- 05595c4
- Parents:
- c3f0114
- Location:
- src/sas/sascalc/file_converter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/file_converter/bsl_loader.py
rc3f0114 r535e181 8 8 # TODO: Change to __init__(self, filename, frame) 9 9 # and parse n_(pixels/rasters) from header file 10 def __init__(self, filename , frame):10 def __init__(self, filename): 11 11 header_file = open(filename, 'r') 12 12 data_info = {} … … 56 56 data_info['pixels'] = 1 57 57 58 CLoader.__init__(self, data_info['filename'], frame,58 CLoader.__init__(self, data_info['filename'], data_info['frames'], 59 59 data_info['pixels'], data_info['rasters'], data_info['swap_bytes']) 60 60 … … 62 62 if name == 'filename': 63 63 return self.set_filename(value) 64 elif name == 'n_frames': 65 return self.set_n_frames(value) 64 66 elif name == 'frame': 65 67 return self.set_frame(value) … … 75 77 if name == 'filename': 76 78 return self.get_filename() 79 elif name == 'n_frames': 80 return self.get_n_frames() 77 81 elif name == 'frame': 78 82 return self.get_frame() … … 84 88 return self.get_swap_bytes() 85 89 return CLoader.__getattr__(self, name) 86 87 def create_arr(self):88 return np.zeros((self.n_rasters, self.n_pixels)) -
src/sas/sascalc/file_converter/c_ext/bsl_loader.c
rc3f0114 r535e181 21 21 static PyObject *CLoader_init(CLoader *self, PyObject *args, PyObject *kwds) { 22 22 const char *filename; 23 const int frame;23 const int n_frames; 24 24 const int n_pixels; 25 25 const int n_rasters; … … 27 27 28 28 if (self != NULL) { 29 if (!PyArg_ParseTuple(args, "siiii", &filename, & frame, &n_pixels, &n_rasters, &swap_bytes))29 if (!PyArg_ParseTuple(args, "siiii", &filename, &n_frames, &n_pixels, &n_rasters, &swap_bytes)) 30 30 Py_RETURN_NONE; 31 31 if (!(self->params.filename = malloc(strlen(filename) + 1))) 32 32 Py_RETURN_NONE; 33 33 strcpy(self->params.filename, filename); 34 self->params. frame = frame;34 self->params.n_frames = n_frames; 35 35 self->params.n_pixels = n_pixels; 36 36 self->params.n_rasters = n_rasters; … … 49 49 char str[100]; 50 50 sprintf(str, 51 "Filename: %s\n frame: %d\nn_pixels: %d\nn_rasters: %d\nswap_bytes: %d",51 "Filename: %s\nn_frames: %d\nframe: %d\nn_pixels: %d\nn_rasters: %d\nswap_bytes: %d", 52 52 self->params.filename, 53 self->params.n_frames, 53 54 self->params.frame, 54 55 self->params.n_pixels, … … 73 74 } 74 75 76 static PyObject *get_n_frames(CLoader *self, PyObject *args) { 77 return Py_BuildValue("i", self->params.n_frames); 78 } 79 80 static PyObject *set_n_frames(CLoader *self, PyObject *args) { 81 int new_frames; 82 if (!PyArg_ParseTuple(args, "i", &new_frames)) 83 return NULL; 84 self->params.n_frames = new_frames; 85 86 return Py_BuildValue("i", self->params.n_frames); 87 } 88 75 89 static PyObject *get_frame(CLoader *self, PyObject *args) { 76 90 return Py_BuildValue("i", self->params.frame); … … 144 158 int pixel; 145 159 int frame_pos; 146 intsize[2] = {self->params.n_rasters, self->params.n_pixels};160 npy_intp size[2] = {self->params.n_rasters, self->params.n_pixels}; 147 161 float cur_val; 148 162 FILE *input_file; 149 163 PyArrayObject *data; 150 164 151 if (!PyArg_ParseTuple(args, "O!", &PyArray_Type, &data)) { 152 return NULL; 153 } 165 data = (PyArrayObject *)PyArray_SimpleNew(2, size, NPY_FLOAT); 154 166 155 167 input_file = fopen(self->params.filename, "rb"); … … 171 183 172 184 fclose(input_file); 173 Py_DECREF(data); 174 175 return Py_BuildValue("O", data); 185 186 return Py_BuildValue("N", data); 176 187 } 177 188 … … 182 193 { "get_filename", (PyCFunction)get_filename, METH_VARARGS, "Get the filename" }, 183 194 { "set_filename", (PyCFunction)set_filename, METH_VARARGS, "Set the filename" }, 195 { "get_n_frames", (PyCFunction)get_n_frames, METH_VARARGS, "Get n_frames" }, 196 { "set_n_frames", (PyCFunction)set_n_frames, METH_VARARGS, "Set n_frames" }, 184 197 { "get_frame", (PyCFunction)get_frame, METH_VARARGS, "Get the frame that will be loaded" }, 185 198 { "set_frame", (PyCFunction)set_frame, METH_VARARGS, "Set the frame that will be loaded" }, -
src/sas/sascalc/file_converter/c_ext/bsl_loader.h
r6eaf89ea r535e181 5 5 // File to load 6 6 char *filename; 7 // Number of frames in the file 8 int n_frames; 7 9 // Frame to load 8 10 int frame;
Note: See TracChangeset
for help on using the changeset viewer.