Skip to content

Commit

Permalink
Clean and simplify code in src/fitsw.c
Browse files Browse the repository at this point in the history
Small changes to simplify and streamline code in src/fitsw.c for nitpicky
purposes.

	modified:   src/fitsw.c
	modified:   src/images.c
  • Loading branch information
tbowers7 committed Jul 11, 2018
1 parent dfbb371 commit 4a1fc0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
32 changes: 15 additions & 17 deletions src/fitsw.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void fitsw_write2file(char *fileout, long naxes[2], double **array,
/* Variable Declarations & Initializations */
int k;
long fpixel[2];
char buf_date[FLEN_VALUE],buf_time[FLEN_VALUE],*mod_comm,*fn;
char buf_date[FLEN_VALUE],buf_time[FLEN_VALUE],fn[FLEN_FILENAME];
fitsfile *fitsfp;
time_t now;
struct tm *ptr;
Expand All @@ -55,13 +55,11 @@ void fitsw_write2file(char *fileout, long naxes[2], double **array,
*status = 0;



/* Open FITS file for writing, overwrite existing file */
fn = (char *)malloc(sizeof(char) * strlen(fileout)+1);
sprintf(fn,"!%s",fileout); // CFITSIO will overwrite file prepended w/ "!"
snprintf(fn,FLEN_FILENAME, "!%s",fileout);
// CFITSIO will overwrite file prepended w/ "!"
if( fits_create_file(&fitsfp, fn, status) )
fw_catcherror(status); // Send pointer not value
free(fn); // Free "!" filename

/* Create image HDU */
int naxis = 2; // Routine is specific for 2-D images
Expand All @@ -79,28 +77,28 @@ void fitsw_write2file(char *fileout, long naxes[2], double **array,
"UT time of observation", status);

/* Add various FITS keywords, specific to ScopeDesign */
fits_write_key(fitsfp, TSTRING, "OBSERVAT", "ScopeDesign Ray-Tracing Program",
NULL, status);
fits_write_key(fitsfp, TSTRING, "OBSERVAT",
"ScopeDesign Ray-Tracing Program", NULL, status);
fits_write_key(fitsfp, TSTRING, "TELESCOP", telname,
"modeled telescope for ray trace", status);
fits_write_key(fitsfp, TSTRING, "FILENAME", fileout, NULL, status);

/* Catch any CFITSIO errors from keyword writing */
fw_catcherror(status); // Send pointer not value

/* Write array to file */
fpixel[0] = 1;
for(k=0; k < naxes[1]; k++){ // Loop over size[1] rows (i.e. y)
fpixel[1] = k + 1;
if(fits_write_pix(fitsfp, TDOUBLE, fpixel, naxes[0], array[k],
status)){
fits_report_error(stderr,*status);
if( fits_write_pix(fitsfp, TDOUBLE, fpixel, // Use TDOUBLE because
naxes[0], array[k], status) ){ // array is double
fw_catcherror(status);
break;
}
}

/* Clean up */
fits_close_file(fitsfp, status);

/* Report any CFITSIO errors to stderr */
if(!*status)
if( fits_close_file(fitsfp, status) )
fw_catcherror(status); // Send pointer not value

return;
Expand Down Expand Up @@ -167,16 +165,16 @@ double **fitsw_read2array(fitsfile *fitsfp, long xystart[2], long xysize[2],
for(i=0; i < xysize[1]; i++){ // Loop over xysize[1] (i.e. y) rows
fpixel[1] = ystart + i; // Set initial y-coordinate here...

if(fits_read_pix(fitsfp, data_type, fpixel, xysize[0], NULL,
array[i], NULL, status)){
if( fits_read_pix(fitsfp, data_type, fpixel, xysize[0], NULL,
array[i], NULL, status)){
fits_report_error(stderr,*status);
break;
}
}

return array;
}


/***** Private Functions Internal to Fitsw *****/

Expand Down
2 changes: 1 addition & 1 deletion src/images.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ char *images_write_locations(scope_ray *rays, int location, char *telname,
/* Variable Declarations */
int gsl_status, bitpix;
long i,j,nx,ny;
char fn[256];
char fn[FLEN_FILENAME]; // CFITSIO max length of filename


/* Allocate 2-D Histogram to accumulate locations */
Expand Down

0 comments on commit 4a1fc0f

Please sign in to comment.