Ignore:
Timestamp:
Aug 5, 2016 9:48:33 AM (8 years ago)
Author:
lewis
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
Message:

Begin implementing 2D BSL loader into GUI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/file_converter/c_ext/bsl_loader.c

    rc3f0114 r535e181  
    2121static PyObject *CLoader_init(CLoader *self, PyObject *args, PyObject *kwds) { 
    2222    const char *filename; 
    23     const int frame; 
     23    const int n_frames; 
    2424    const int n_pixels; 
    2525    const int n_rasters; 
     
    2727 
    2828    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)) 
    3030            Py_RETURN_NONE; 
    3131        if (!(self->params.filename = malloc(strlen(filename) + 1))) 
    3232            Py_RETURN_NONE; 
    3333        strcpy(self->params.filename, filename); 
    34         self->params.frame = frame; 
     34        self->params.n_frames = n_frames; 
    3535        self->params.n_pixels = n_pixels; 
    3636        self->params.n_rasters = n_rasters; 
     
    4949    char str[100]; 
    5050    sprintf(str, 
    51         "Filename: %s\nframe: %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", 
    5252        self->params.filename, 
     53        self->params.n_frames, 
    5354        self->params.frame, 
    5455        self->params.n_pixels, 
     
    7374} 
    7475 
     76static PyObject *get_n_frames(CLoader *self, PyObject *args) { 
     77    return Py_BuildValue("i", self->params.n_frames); 
     78} 
     79 
     80static 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 
    7589static PyObject *get_frame(CLoader *self, PyObject *args) { 
    7690    return Py_BuildValue("i", self->params.frame); 
     
    144158    int pixel; 
    145159    int frame_pos; 
    146     int size[2] = {self->params.n_rasters, self->params.n_pixels}; 
     160    npy_intp size[2] = {self->params.n_rasters, self->params.n_pixels}; 
    147161    float cur_val; 
    148162    FILE *input_file; 
    149163    PyArrayObject *data; 
    150164 
    151     if (!PyArg_ParseTuple(args, "O!", &PyArray_Type, &data)) { 
    152         return NULL; 
    153     } 
     165    data = (PyArrayObject *)PyArray_SimpleNew(2, size, NPY_FLOAT); 
    154166 
    155167    input_file = fopen(self->params.filename, "rb"); 
     
    171183 
    172184    fclose(input_file); 
    173     Py_DECREF(data); 
    174  
    175     return Py_BuildValue("O", data); 
     185 
     186    return Py_BuildValue("N", data); 
    176187} 
    177188 
     
    182193    { "get_filename", (PyCFunction)get_filename, METH_VARARGS, "Get the filename" }, 
    183194    { "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" }, 
    184197    { "get_frame", (PyCFunction)get_frame, METH_VARARGS, "Get the frame that will be loaded" }, 
    185198    { "set_frame", (PyCFunction)set_frame, METH_VARARGS, "Set the frame that will be loaded" }, 
Note: See TracChangeset for help on using the changeset viewer.