From ce2060aa1de454cb718c043a885e60114adc86cd Mon Sep 17 00:00:00 2001 From: Timothy Ellsworth Bowers Date: Wed, 27 Jun 2018 17:15:18 -0700 Subject: [PATCH] Update FITS header writing for fitsw routine 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 --- src/demo.c | 54 ++++++++++++++++++++++++++------------------------ src/demo.h | 2 +- src/fitswrap.c | 26 +++++++++++++++--------- src/fitswrap.h | 4 ++-- src/images.c | 9 +++++---- src/images.h | 5 +++-- src/main.c | 3 ++- src/sd_defs.h | 1 + src/setup.c | 3 +-- 9 files changed, 60 insertions(+), 47 deletions(-) diff --git a/src/demo.c b/src/demo.c index b1d4155..aa75dac 100644 --- a/src/demo.c +++ b/src/demo.c @@ -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 */ diff --git a/src/demo.h b/src/demo.h index dc3ef4c..c55de2e 100644 --- a/src/demo.h +++ b/src/demo.h @@ -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 */ diff --git a/src/fitswrap.c b/src/fitswrap.c index 048432e..a18c5dc 100644 --- a/src/fitswrap.c +++ b/src/fitswrap.c @@ -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; @@ -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; @@ -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); diff --git a/src/fitswrap.h b/src/fitswrap.h index 4b05aa7..da0114f 100644 --- a/src/fitswrap.h +++ b/src/fitswrap.h @@ -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 *****/ diff --git a/src/images.c b/src/images.c index 21b8f7f..1ab76a5 100644 --- a/src/images.c +++ b/src/images.c @@ -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; @@ -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); @@ -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"; @@ -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; diff --git a/src/images.h b/src/images.h index 60bd3e7..cc0732a 100644 --- a/src/images.h +++ b/src/images.h @@ -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); diff --git a/src/main.c b/src/main.c index 8020811..1dda50a 100644 --- a/src/main.c +++ b/src/main.c @@ -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 */ diff --git a/src/sd_defs.h b/src/sd_defs.h index aead3dd..c36c6ac 100644 --- a/src/sd_defs.h +++ b/src/sd_defs.h @@ -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; // diff --git a/src/setup.c b/src/setup.c index 85b1cec..b4007ad 100644 --- a/src/setup.c +++ b/src/setup.c @@ -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; }