36 #include "gigrating.h"
38 #define GIFITS_KEYWORD_MISSING_MSG "FITS KEYWORD [%s] not found!! Aborting..."
49 static const cxdouble GI_WAVELENGTH_EPSILON = 1.e-8;
53 _giraffe_grating_copy(
GiGrating *
self, cpl_table *grating, cxint row,
54 GiInstrumentMode mode)
57 const cxchar *c_resolution = NULL;
60 cx_assert(
self != NULL);
61 cx_assert(grating != NULL);
64 if (row >= cpl_table_get_nrow(grating)) {
69 if (!cpl_table_has_column(grating,
"ORDER")) {
73 self->order = cpl_table_get_int(grating,
"ORDER", row, NULL);
77 if (!cpl_table_has_column(grating,
"WLEN0")) {
81 self->wlen0 = cpl_table_get_double(grating,
"WLEN0", row, NULL);
85 if (!cpl_table_has_column(grating,
"WLMIN")) {
89 self->wlenmin = cpl_table_get_double(grating,
"WLMIN", row, NULL);
93 if (!cpl_table_has_column(grating,
"WLMAX")) {
97 self->wlenmax = cpl_table_get_double(grating,
"WLMAX", row, NULL);
101 if (!cpl_table_has_column(grating,
"BAND")) {
105 self->band = cpl_table_get_double(grating,
"BAND", row, NULL);
111 c_resolution =
"RMED";
116 c_resolution =
"RIFA";
124 if (!cpl_table_has_column(grating, c_resolution)) {
128 self->resol = cpl_table_get_int(grating, c_resolution, row, NULL);
132 if (!cpl_table_has_column(grating,
"THETA")) {
136 self->theta = cpl_table_get_double(grating,
"THETA", row, NULL);
140 if (!cpl_table_has_column(grating,
"FCOLL")) {
144 self->fcoll = cpl_table_get_double(grating,
"FCOLL", row, NULL);
148 if (!cpl_table_has_column(grating,
"GCAM")) {
152 self->gcam = cpl_table_get_double(grating,
"GCAM", row, NULL);
156 if (!cpl_table_has_column(grating,
"SDX")) {
160 self->sdx = cpl_table_get_double(grating,
"SDX", row, NULL);
164 if (!cpl_table_has_column(grating,
"SDY")) {
168 self->sdy = cpl_table_get_double(grating,
"SDY", row, NULL);
172 if (!cpl_table_has_column(grating,
"SPHI")) {
176 self->sphi = cpl_table_get_double(grating,
"SPHI", row, NULL);
199 grating->
name = cx_string_new();
200 grating->
setup = cx_string_new();
201 grating->
filter = cx_string_new();
202 grating->
slit = cx_string_new();
229 const cxchar *
const c_setup =
"SETUP";
231 const cxchar *setup = NULL;
240 cpl_propertylist *properties = NULL;
242 cpl_table *_grating = NULL;
246 GiInstrumentMode mode;
250 if (spectra == NULL || grating == NULL) {
256 if (properties == NULL) {
262 if (_grating == NULL) {
279 if (!cpl_propertylist_has(properties, GIALIAS_GRATNAME)) {
284 cx_string_set(self->name,
285 cpl_propertylist_get_string(properties,
291 if (!cpl_propertylist_has(properties, GIALIAS_FILTNAME)) {
296 cx_string_set(self->filter,
297 cpl_propertylist_get_string(properties,
303 if (!cpl_propertylist_has(properties, GIALIAS_SLITNAME)) {
308 cx_string_set(self->slit,
309 cpl_propertylist_get_string(properties,
315 if (!cpl_propertylist_has(properties, GIALIAS_GRATGRV)) {
321 cxdouble grooves = cpl_propertylist_get_double(properties,
323 self->space = 1. / fabs(GI_MM_TO_NM * grooves);
336 if (!cpl_table_has_column(_grating,
"ORDER") ||
337 !cpl_table_has_column(_grating,
"WLEN0")) {
344 if (!cpl_propertylist_has(properties, GIALIAS_GRATWLEN)) {
349 wlen0 = cpl_propertylist_get_double(properties, GIALIAS_GRATWLEN);
352 if (!cpl_propertylist_has(properties, GIALIAS_GRATORDER)) {
357 order = cpl_propertylist_get_int(properties, GIALIAS_GRATORDER);
361 for (i = 0; i < cpl_table_get_nrow(_grating); i++) {
363 cxint _order = cpl_table_get_int(_grating,
"ORDER", i, NULL);
365 if (order == _order) {
367 cxdouble _wlen0 = cpl_table_get_double(_grating,
"WLEN0",
370 if (fabs(wlen0 - _wlen0) < GI_WAVELENGTH_EPSILON) {
392 if (cpl_propertylist_has(properties, GIALIAS_SETUPNAME)) {
393 setup = cpl_propertylist_get_string(properties, GIALIAS_SETUPNAME);
394 cx_string_set(self->setup, setup);
397 if (cpl_table_has_column(_grating, c_setup)) {
398 setup = cpl_table_get_string(_grating, c_setup, row);
399 cx_string_set(self->setup, setup);
404 status = _giraffe_grating_copy(
self, _grating, row, mode);
436 if (self->name != NULL) {
437 cx_string_delete(self->name);
440 if (self->setup != NULL) {
441 cx_string_delete(self->setup);
444 if (self->filter != NULL) {
445 cx_string_delete(self->filter);
448 if (self->slit != NULL) {
449 cx_string_delete(self->slit);
486 const cxchar*
const fctid =
"giraffe_grating_setup";
488 const cxchar* c_name_setup =
"SETUP";
489 const cxchar* c_name_order =
"ORDER";
490 const cxchar* c_name_wl0 =
"WLEN0";
491 const cxchar* c_name_wlmin =
"WLMIN";
492 const cxchar* c_name_wlmax =
"WLMAX";
493 const cxchar* c_name_band =
"BAND";
494 const cxchar* c_name_theta =
"THETA";
495 const cxchar* c_name_fcoll =
"FCOLL";
496 const cxchar* c_name_gcam =
"GCAM";
497 const cxchar* c_name_sdx =
"SDX";
498 const cxchar* c_name_sdy =
"SDY";
499 const cxchar* c_name_sdphi =
"SPHI";
500 const cxchar* c_name_rmed =
"RMED";
501 const cxchar* c_name_rifa =
"RIFA";
507 cxdouble wlen_match = 0.;
509 cxdouble tmp_gratgrv = 0.;
512 cx_string* slit_name = NULL;
514 cpl_propertylist* ref_plimg = NULL;
516 cpl_table* ref_gtable = NULL;
518 GiInstrumentMode instrument_mode;
525 if (grating_table == NULL) {
529 if (spectra == NULL) {
533 if (grating_setup == NULL) {
538 if (ref_plimg == NULL) {
543 if (ref_gtable == NULL) {
547 slit_name = cx_string_new();
557 if (cpl_propertylist_has(ref_plimg, GIALIAS_GRATWLEN) == FALSE) {
558 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATWLEN);
559 cx_string_delete(slit_name);
563 grating_setup->
wlen0 = cpl_propertylist_get_double(ref_plimg,
567 if (cpl_propertylist_has(ref_plimg, GIALIAS_SLITNAME) == FALSE) {
568 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_SLITNAME);
569 cx_string_delete(slit_name);
573 cx_string_set(slit_name,
574 cpl_propertylist_get_string(ref_plimg,
578 if (cpl_propertylist_has(ref_plimg, GIALIAS_GRATGRV) == FALSE) {
579 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATGRV);
580 cx_string_delete(slit_name);
584 tmp_gratgrv = cpl_propertylist_get_double(ref_plimg,
588 if (cpl_propertylist_has(ref_plimg, GIALIAS_GRATNAME) == FALSE) {
589 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATNAME);
590 cx_string_delete(slit_name);
594 cx_string_set(grating_setup->
name,
595 cpl_propertylist_get_string(ref_plimg,
599 if (cpl_propertylist_has(ref_plimg, GIALIAS_FILTNAME) == FALSE) {
600 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_FILTNAME);
601 cx_string_delete(slit_name);
605 cx_string_set(grating_setup->
filter,
606 cpl_propertylist_get_string(ref_plimg,
615 for (i = 0; i < cpl_table_get_nrow(ref_gtable); i++) {
617 wlen = cpl_table_get(ref_gtable, c_name_wl0, i, &row_nulls);
619 if (fabs(wlen - grating_setup->
wlen0) <
620 fabs(wlen_match - grating_setup->
wlen0)) {
632 if (fabs(wlen_match - grating_setup->
wlen0) > GI_WAVELENGTH_EPSILON) {
634 cpl_msg_error(fctid,
"Central wavelength [%f] nout found in grating "
635 "table, aborting...", grating_setup->
wlen0);
636 cx_string_delete(slit_name);
640 cpl_msg_debug(fctid,
"Found wlen0 in grating table at position %d",
650 cx_string_set(grating_setup->
setup,
651 (cxchar*) cpl_table_get_string(ref_gtable, c_name_setup,
654 cx_string_set(grating_setup->
slit, cx_string_get(slit_name));
656 grating_setup->
order = cpl_table_get(ref_gtable, c_name_order,
657 row_match, &row_nulls);
659 grating_setup->
wlenmin = cpl_table_get(ref_gtable, c_name_wlmin,
660 row_match, &row_nulls);
662 grating_setup->
wlenmax = cpl_table_get(ref_gtable, c_name_wlmax,
663 row_match, &row_nulls);
665 grating_setup->
band = cpl_table_get(ref_gtable, c_name_band,
666 row_match, &row_nulls);
668 grating_setup->
theta = cpl_table_get(ref_gtable, c_name_theta,
669 row_match, &row_nulls);
671 grating_setup->
space = 1.0 / fabs(GI_MM_TO_NM * tmp_gratgrv);
676 switch (instrument_mode) {
678 grating_setup->
resol = cpl_table_get(ref_gtable, c_name_rmed,
679 row_match, &row_nulls);
683 grating_setup->
resol = cpl_table_get(ref_gtable, c_name_rifa,
684 row_match, &row_nulls);
688 grating_setup->
resol = cpl_table_get(ref_gtable, c_name_rifa,
689 row_match, &row_nulls);
693 grating_setup->
resol = -1.0;
697 grating_setup->
fcoll =
698 cpl_table_get(ref_gtable, c_name_fcoll, row_match, &row_nulls);
700 grating_setup->
gcam =
701 cpl_table_get(ref_gtable, c_name_gcam, row_match, &row_nulls);
704 cpl_table_get(ref_gtable, c_name_sdx, row_match, &row_nulls);
707 cpl_table_get(ref_gtable, c_name_sdy, row_match, &row_nulls);
709 grating_setup->
sphi =
710 cpl_table_get(ref_gtable, c_name_sdphi, row_match, &row_nulls);
712 cx_string_delete(slit_name);
733 const cxchar *fctid =
"giraffe_grating_dump";
735 if (grating == NULL) {
739 cpl_msg_debug(fctid,
"---- GiGrating -------------------------");
741 cpl_msg_debug(fctid,
"Grating Name : %s",
742 cx_string_get(grating->
name));
743 cpl_msg_debug(fctid,
"Grating Filter Name : %s",
744 cx_string_get(grating->
filter));
745 cpl_msg_debug(fctid,
"Grating Setup Name : %s",
746 cx_string_get(grating->
setup));
747 cpl_msg_debug(fctid,
"Grating Order : %12d", grating->
order);
748 cpl_msg_debug(fctid,
"Grating Wlen0 : %12.6f", grating->
wlen0);
749 cpl_msg_debug(fctid,
"Grating Wlen Min : %12.6f", grating->
wlenmin);
750 cpl_msg_debug(fctid,
"Grating Wlen Max : %12.6f", grating->
wlenmax);
751 cpl_msg_debug(fctid,
"Grating Band : %12.6f", grating->
band);
752 cpl_msg_debug(fctid,
"Grating Resol : %12d", grating->
resol);
753 cpl_msg_debug(fctid,
"Grating Space : %12.6f", grating->
space);
754 cpl_msg_debug(fctid,
"Grating Theta : %12.6f", grating->
theta);
755 cpl_msg_debug(fctid,
"Grating FColl : %12.6f", grating->
fcoll);
756 cpl_msg_debug(fctid,
"Grating GCam : %12.6f", grating->
gcam);
757 cpl_msg_debug(fctid,
"Grating SlitDx : %12.6f", grating->
sdx);
758 cpl_msg_debug(fctid,
"Grating SlitDy : %12.6f", grating->
sdy);
759 cpl_msg_debug(fctid,
"Grating SlitPhi : %12.6f", grating->
sphi);
GiInstrumentMode giraffe_get_mode(cpl_propertylist *properties)
Determines the instrument mode from a property list.
cxint giraffe_grating_setup(GiTable *grating_table, GiImage *spectra, GiGrating *grating_setup)
Retrieves grating information and returns it in a GiGrating structure.
GiGrating * giraffe_grating_create(const GiImage *spectra, const GiTable *grating)
Create a GiGrating from a reference image.
GiGrating * giraffe_grating_new(void)
Create a new GiGrating.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
void giraffe_grating_dump(const GiGrating *grating)
Dump the the information contained in a GiGrating to output.
Structure to handle Grating Information.
void giraffe_grating_delete(GiGrating *self)
Destroys an GiGrating object.
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.