Skip to content

Commit

Permalink
fix alloc arrays def
Browse files Browse the repository at this point in the history
  • Loading branch information
jemorrison committed Jul 20, 2021
1 parent 5e8958e commit 64d4bfa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
3 changes: 1 addition & 2 deletions jwst/cube_build/src/cube_match_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ extern double sh_find_overlap(const double xcenter, const double ycenter,
double xPixelCorner[],double yPixelCorner[]);



extern double find_area_quad(double MinX, double MinY, double Xcorner[], double Ycorner[]);


extern alloc_flux_arrays(int nelem, double **fluxv, double **weightv, double **varv, double **ifluxv);
extern int alloc_flux_arrays(int nelem, double **fluxv, double **weightv, double **varv, double **ifluxv);


//_______________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion jwst/cube_build/src/cube_match_sky.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extern double sh_find_overlap(const double xcenter, const double ycenter,
const double xlength, const double ylength,
double xPixelCorner[],double yPixelCorner[]);

extern alloc_flux_arrays(int nelem, double **fluxv, double **weightv, double **varv, double **ifluxv);
extern int alloc_flux_arrays(int nelem, double **fluxv, double **weightv, double **varv, double **ifluxv);


//________________________________________________________________________________
Expand Down
45 changes: 45 additions & 0 deletions jwst/cube_build/src/cube_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,51 @@
#define CP_BOTTOM 2
#define CP_TOP 3


//_______________________________________________________________________
// Allocate the memory to for the spaxel arrays in the cube
//_______________________________________________________________________

int alloc_flux_arrays(int nelem, double **fluxv, double **weightv, double **varv, double **ifluxv) {

const char *msg = "Couldn't allocate memory for output arrays.";

printf(" going to allocate memory \n");
// flux:
if (!(*fluxv = (double*)calloc(nelem, sizeof(double)))) {
PyErr_SetString(PyExc_MemoryError, msg);
goto failed_mem_alloc;
}

//weight
if (!(*weightv = (double*)calloc(nelem, sizeof(double)))) {
PyErr_SetString(PyExc_MemoryError, msg);
goto failed_mem_alloc;
}

//variance
if (!(*varv = (double*)calloc(nelem, sizeof(double)))) {
PyErr_SetString(PyExc_MemoryError, msg);
goto failed_mem_alloc;
}

//iflux
if (!(*ifluxv = (double*)calloc(nelem, sizeof(double)))) {
PyErr_SetString(PyExc_MemoryError, msg);
goto failed_mem_alloc;
}

return 0;

failed_mem_alloc:
printf("Problem allocating \n");
free(*fluxv);
free(*weightv);
free(*varv);
free(*ifluxv);

}

// support function for sh_find_overlap
void addpoint (double x, double y, double xnew[], double ynew[], int *nVertices2){
xnew[*nVertices2] = x;
Expand Down

0 comments on commit 64d4bfa

Please sign in to comment.