Skip to content

Commit

Permalink
Update FITS header writing for fitsw routine
Browse files Browse the repository at this point in the history
Add various FITS header keywords for writing out images.  Addition of
telescope type required more significant rework of setup.c and demo.c.

	modified:   src/demo.c
	modified:   src/demo.h
	modified:   src/fitswrap.c
	modified:   src/fitswrap.h
	modified:   src/images.c
	modified:   src/images.h
	modified:   src/main.c
	modified:   src/sd_defs.h
	modified:   src/setup.c
  • Loading branch information
tbowers7 committed Jun 28, 2018
1 parent 951db89 commit ce2060a
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 47 deletions.
54 changes: 28 additions & 26 deletions src/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,40 @@
#include "setup.h"

/* Have a hard-wired Newtonian telescope as a DEMO, but also for code testing */
void demo_newtonian(scope_optic *primary,
scope_optic *secondary,
void demo_newtonian(scope_scope *telescope,
scope_element *elements,
int *nelem){

telescope->name = (char *)malloc(sizeof(char) * 256);
sprintf(telescope->name,"Newtonian Demo");

/* Set up the primary mirror */
primary->type = OPTIC_PARABOLA;
primary->dmaj = 10. *(2.54/100.); // 10" mirror, keep everything in meters
primary->dmin = 10. *(2.54/100.); // 10" mirror, keep everything in meters
primary->vmin = 0.; // Axially symmetric
primary->f = primary->dmaj * 6.; // f/6 parabola
primary->cx = 0.; // Center mirror at (0,0,0)
primary->cy = 0.;
primary->cz = 0.;
primary->nx = 0.; // Point mirror straight up along z-hat
primary->ny = 0.;
primary->nz = 1.;
primary->nhat = setup_orient_optic(&primary);
telescope->primary.type = OPTIC_PARABOLA;
telescope->primary.dmaj = 10. *(2.54/100.); // 10" mirror, keep everything in meters
telescope->primary.dmin = 10. *(2.54/100.); // 10" mirror, keep everything in meters
telescope->primary.vmin = 0.; // Axially symmetric
telescope->primary.f = telescope->primary.dmaj * 6.; // f/6 parabola
telescope->primary.cx = 0.; // Center mirror at (0,0,0)
telescope->primary.cy = 0.;
telescope->primary.cz = 0.;
telescope->primary.nx = 0.; // Point mirror straight up along z-hat
telescope->primary.ny = 0.;
telescope->primary.nz = 1.;
telescope->primary.nhat = setup_orient_optic(&telescope->primary);

/* Set up the secondary mirror */
secondary->type = OPTIC_PLANE;
secondary->dmaj = 2. *(2.54/100.) * M_SQRT2; // 2" plane mirror -- projection
secondary->dmin = 2. *(2.54/100.); // 2" plane mirror -- projection
secondary->vmin = NHAT_Y; // Minor axis along y-direction
secondary->f = posinf;
secondary->cx = 0.;
secondary->cy = 0.;
secondary->cz = primary->dmaj * 0.9; // 90% of the way to focus?
secondary->nx = M_SQRT1_2; // (1,0,-1)
secondary->ny = 0.;
secondary->nz = -M_SQRT1_2;
secondary->nhat = setup_orient_optic(&secondary);
telescope->secondary.type = OPTIC_PLANE;
telescope->secondary.dmaj = 2. *(2.54/100.) * M_SQRT2; // 2" plane mirror -- projection
telescope->secondary.dmin = 2. *(2.54/100.); // 2" plane mirror -- projection
telescope->secondary.vmin = NHAT_Y; // Minor axis along y-direction
telescope->secondary.f = posinf;
telescope->secondary.cx = 0.;
telescope->secondary.cy = 0.;
telescope->secondary.cz = telescope->primary.dmaj * 0.9; // 90% of the way to focus?
telescope->secondary.nx = M_SQRT1_2; // (1,0,-1)
telescope->secondary.ny = 0.;
telescope->secondary.nz = -M_SQRT1_2;
telescope->secondary.nhat = setup_orient_optic(&telescope->secondary);

/* Tell the calling function how many elements light passed by or reflects
off of before coming to the focal plane */
Expand Down
2 changes: 1 addition & 1 deletion src/demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


/* Function declarations */
void demo_newtonian(scope_optic *, scope_optic *, scope_element *, int *);
void demo_newtonian(scope_scope *, scope_element *, int *);


#endif /* DEMO_H */
Expand Down
26 changes: 17 additions & 9 deletions src/fitswrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/* NOTE: FUNCTION CURRENTLY COPIES HEADER FROM ANOTHER FILE... MODIFY TO
CREATE NEW HEADER AND POPULATE IT WITH REASONABLE THINGS! */
void fitsw_write2file(char *fileout, long naxes[2], double **array,
int bitpix, int *status){
int bitpix, char *telname, int *status){

/* Variable Declarations & Initializations */
int k;
Expand All @@ -68,6 +68,22 @@ void fitsw_write2file(char *fileout, long naxes[2], double **array,
if( fits_create_img(fitsfp, bitpix, naxis, naxes, status) )
fw_catcherror(status); // Send pointer not value

/* Write the UT date and time of file creation */
time(&now);
ptr = gmtime(&now);
strftime(buf_date, FLEN_VALUE, "%Y-%m-%d", ptr);
strftime(buf_time, FLEN_VALUE, "%H:%M:%S", ptr);
fits_update_key(fitsfp, TSTRING, "DATE-OBS", buf_date,
"UT date of observation", status);
fits_update_key(fitsfp, TSTRING, "TIME-OBS", buf_time,
"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, "TELESCOP", telname,
"Modeled Telescope for Ray Trace", status);
fits_write_key(fitsfp, TSTRING, "FILENAME", fileout, NULL, status);

/* Write array to file */
fpixel[0] = 1;
Expand All @@ -80,14 +96,6 @@ void fitsw_write2file(char *fileout, long naxes[2], double **array,
}
}

/* Add/modify keyword for date modified 'DATE-MOD' & 'TIME-MOD' */
time(&now);
ptr = localtime(&now);
strftime(buf_date, FLEN_VALUE, "%Y-%m-%d", ptr);
strftime(buf_time, FLEN_VALUE, "%H:%M:%S", ptr);
fits_update_key(fitsfp, TSTRING, "DATE-MOD", buf_date, mod_comm, status);
fits_update_key(fitsfp, TSTRING, "TIME-MOD", buf_time, NULL, status);

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

Expand Down
4 changes: 2 additions & 2 deletions src/fitswrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
/***** Public-Facing Functions *****/

double **fitsw_read2array(fitsfile *fitsfp, long xystart[2], long xysize[2],
int data_type, int *status);
int data_type, int *status);
void fitsw_write2file(char *fileout, long naxes[2], double **array,
int bitpix, int *status);
int bitpix, char *telname, int *status);

/***** Private Functions Internal to FitsWrap *****/

Expand Down
9 changes: 5 additions & 4 deletions src/images.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ void images_free_2darray(double **array, long *size){


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

/* Variable Declarations */
int errval, bitpix;
Expand Down Expand Up @@ -135,7 +136,7 @@ char *images_write_locations(scope_ray *rays, int location, int *status){

/* Write it out! */

fitsw_write2file(fn, n_sq, imarr, bitpix, status);
fitsw_write2file(fn, n_sq, imarr, bitpix, telname, status);

printf("In-function value of status: %d\n",*status);

Expand All @@ -150,7 +151,7 @@ char *images_write_locations(scope_ray *rays, int location, int *status){

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

int write_focal_plane(){
int write_focal_plane(char *telname){

char *fn="filename";
char *hd="hd";
Expand All @@ -160,7 +161,7 @@ int write_focal_plane(){

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

fitsw_write2file(fn, size, array, bitpix, &status);
fitsw_write2file(fn, size, array, bitpix, telname, &status);

return status;

Expand Down
5 changes: 3 additions & 2 deletions src/images.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ 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);
char *images_write_locations(scope_ray *rays, int location, char *telname,
int *status);

/***** Other Left-Over Functions, Possibly to Use *****/
int write_focal_plane();
int write_focal_plane(char *);
double *imutil_2d_to_1d(double **, long *);
double **imutil_get_subsection(double **, long *, long *, long *);
void imutil_transpose(double **, double **, int, int);
Expand Down
3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ 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 = images_write_locations(rays, OPTIC_INF, &wfp_stat);
fn_startpos = images_write_locations(rays, OPTIC_INF, telescope.name,
&wfp_stat);
printf("File location and status: %s %d\n",fn_startpos, wfp_stat);

/* Display ray starting location in the DS9 window */
Expand Down
1 change: 1 addition & 0 deletions src/sd_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ typedef struct{

// Telescope Structure for ScopeDesign Consumption
typedef struct{
char *name; // Name of telescope design
scope_optic primary; // Provide space for 10 optical elements
scope_optic secondary; //
scope_optic tertiary; //
Expand Down
3 changes: 1 addition & 2 deletions src/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ int setup_initialize_geometry(scope_scope *scope, // Info about elements
/* Variable Declarations */

/* Initialize the Newtonian */
demo_newtonian(&scope->primary, &scope->secondary, elements, nelem);

demo_newtonian(scope, elements, nelem);

return 0;
}
Expand Down

0 comments on commit ce2060a

Please sign in to comment.