Skip to content

Commit

Permalink
Align function names in images.c
Browse files Browse the repository at this point in the history
Update function names to prefix images_ for routines needed long-term.

	modified:   fitswrap.c
	modified:   images.c
	modified:   images.h
	modified:   main.c
  • Loading branch information
tbowers7 committed Jun 25, 2018
1 parent bd9677c commit d069336
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/fitswrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ double **fitsw_read2array(fitsfile *fitsfp, long xystart[2], long xysize[2],
*status=0;

/* Allocate space for array */
double **array = imutil_alloc_2darray(xysize);
double **array = images_alloc_2darray(xysize);


/* Read in FITS file using CFITSIO library routines - w/ error checking */
Expand Down
94 changes: 54 additions & 40 deletions src/images.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,43 @@
#include "images.h"
#include "fitswrap.h"

int write_focal_plane(){

char *fn="filename";
char *hd="hd";
double **array;
long size[2];
int status=0;

printf("We're in illumunation.c...\n");

fitsw_write2file(fn, hd, array, size, &status);

return status;

/***** Array Allocation and Freeing Functions *****/

/* Function to allocate space for a 2-D array of double */
double **images_alloc_2darray(long *size){

/* Variable Declarations */
int mm;
double **new_array;

new_array = (double **)malloc(size[1] * sizeof(double *));
for(mm=0; mm<size[1]; mm++)
new_array[mm] = (double *)calloc(size[0], sizeof(double));

return new_array;
}


/* Function to free space occupied by 2-D array */
void images_free_2darray(double **array, long *size){

/* Variable Declarations */
int nn;

for(nn=0; nn < size[1]; nn++)
free(array[nn]);
free(array);

return;
}


/***** High-Level Write-to-File Functions *****/



/* Function (in progress) to write ray locations to a FITS file. */
char *illum_write_locations(scope_ray *rays, int location, int *status){
char *images_write_locations(scope_ray *rays, int location, int *status){

/* Variable Declarations */
int errval;
Expand All @@ -74,7 +91,7 @@ char *illum_write_locations(scope_ray *rays, int location, int *status){

gsl_histogram2d *h = gsl_histogram2d_alloc(nx, ny);
long n_sq[2] = {nx,ny};
double **imarr = imutil_alloc_2darray(n_sq);
double **imarr = images_alloc_2darray(n_sq);


/* Set range for histogram */
Expand Down Expand Up @@ -128,35 +145,30 @@ char *illum_write_locations(scope_ray *rays, int location, int *status){
return strdup(fn); // Return a properly malloc'd and sized string
}

/* Function to allocate space for a 2-D array of double */
double **imutil_alloc_2darray(long *size){

/* Variable Declarations */
int mm;
double **new_array;

new_array = (double **)malloc(size[1] * sizeof(double *));
for(mm=0; mm<size[1]; mm++)
new_array[mm] = (double *)calloc(size[0], sizeof(double));

return new_array;
}

/***** Other Left-Over Functions, Possibly to Use *****/

/* Function to free space occupied by 2-D array */
void imutil_free_2darray(double **array, long *size){
int write_focal_plane(){

char *fn="filename";
char *hd="hd";
double **array;
long size[2];
int status=0;

printf("We're in illumunation.c...\n");

fitsw_write2file(fn, hd, array, size, &status);

return status;


/* Variable Declarations */
int nn;

for(nn=0; nn < size[1]; nn++)
free(array[nn]);
free(array);

return;
}



/* Function for reading 2-D image array into 1-D array for statistics */
/* IMPORTANT: returned array must be freed by calling function */
double *imutil_2d_to_1d(double **two_d, long *arrsize){
Expand Down Expand Up @@ -185,7 +197,7 @@ double **imutil_get_subsection(double **full, long *f_size, long *s_size, long *
double **sub;

/* Allocate space for subsection array */
sub = imutil_alloc_2darray(s_size);
sub = images_alloc_2darray(s_size);

/* Check that subsection does not go beyond the bounds of the image */
if(start[0] + s_size[0] - 1 > f_size[0] ||
Expand All @@ -202,6 +214,8 @@ double **imutil_get_subsection(double **full, long *f_size, long *s_size, long *
}




/* imutil_transpose() takes an (n x m) array and builds the (m x n) transpose.
Care is taken in case input and transpose are the same array in calling
routine. */
Expand All @@ -213,7 +227,7 @@ void imutil_transpose(double **a, double **at, int n, int m){
double **trans;

/* Allocate transpose array */
trans = imutil_alloc_2darray(size);
trans = images_alloc_2darray(size);

/* Build the transpose array */
for(x=0;x<n;x++){
Expand All @@ -230,7 +244,7 @@ void imutil_transpose(double **a, double **at, int n, int m){
}

/* Free the temproary transpose array */
imutil_free_2darray(trans,size);
images_free_2darray(trans,size);

return;
}
13 changes: 9 additions & 4 deletions src/images.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@


/* Function declarations */
int write_focal_plane();
char *illum_write_locations(scope_ray *rays, int location, int *status);

double **imutil_alloc_2darray(long *);
void imutil_free_2darray(double **, long *);
/***** Array Allocation and Freeing Functions *****/
double **images_alloc_2darray(long *);
void images_free_2darray(double **, long *);

/***** High-Level Write-to-File Functions *****/
char *images_write_locations(scope_ray *rays, int location, int *status);

/***** Other Left-Over Functions, Possibly to Use *****/
int write_focal_plane();
double *imutil_2d_to_1d(double **, long *);
double **imutil_get_subsection(double **, long *, long *, long *);
void imutil_transpose(double **, double **, int, int);
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int main(int argc, char *argv[])
printf("Ray status = %d, Overshoot = %0.3f, Theory = %0.3f\n",
ir_stat,over,4./M_PI);

fn_startpos = illum_write_locations(rays, OPTIC_INF, &wfp_stat);
fn_startpos = images_write_locations(rays, OPTIC_INF, &wfp_stat);
printf("File location and status: %s %d\n",fn_startpos, wfp_stat);

/* Display ray starting location in the DS9 window */
Expand Down

0 comments on commit d069336

Please sign in to comment.