27#include <cxmessages.h>
33#define GIFITS_KEYWORD_MISSING_MSG "FITS KEYWORD [%s] not found!! Aborting..."
44static const cxdouble GI_WAVELENGTH_EPSILON = 1.e-8;
48_giraffe_grating_copy(
GiGrating *self, cpl_table *grating, cxint row,
49 GiInstrumentMode mode)
52 const cxchar *c_resolution = NULL;
55 cx_assert(self != NULL);
56 cx_assert(grating != NULL);
59 if (row >= cpl_table_get_nrow(grating)) {
64 if (!cpl_table_has_column(grating,
"ORDER")) {
68 self->
order = cpl_table_get_int(grating,
"ORDER", row, NULL);
72 if (!cpl_table_has_column(grating,
"WLEN0")) {
76 self->
wlen0 = cpl_table_get_double(grating,
"WLEN0", row, NULL);
80 if (!cpl_table_has_column(grating,
"WLMIN")) {
84 self->
wlenmin = cpl_table_get_double(grating,
"WLMIN", row, NULL);
88 if (!cpl_table_has_column(grating,
"WLMAX")) {
92 self->
wlenmax = cpl_table_get_double(grating,
"WLMAX", row, NULL);
96 if (!cpl_table_has_column(grating,
"BAND")) {
100 self->
band = cpl_table_get_double(grating,
"BAND", row, NULL);
106 c_resolution =
"RMED";
111 c_resolution =
"RIFA";
119 if (!cpl_table_has_column(grating, c_resolution)) {
123 self->
resol = cpl_table_get_int(grating, c_resolution, row, NULL);
127 if (!cpl_table_has_column(grating,
"THETA")) {
131 self->
theta = cpl_table_get_double(grating,
"THETA", row, NULL);
135 if (!cpl_table_has_column(grating,
"FCOLL")) {
139 self->
fcoll = cpl_table_get_double(grating,
"FCOLL", row, NULL);
143 if (!cpl_table_has_column(grating,
"GCAM")) {
147 self->
gcam = cpl_table_get_double(grating,
"GCAM", row, NULL);
151 if (!cpl_table_has_column(grating,
"SDX")) {
155 self->
sdx = cpl_table_get_double(grating,
"SDX", row, NULL);
159 if (!cpl_table_has_column(grating,
"SDY")) {
163 self->
sdy = cpl_table_get_double(grating,
"SDY", row, NULL);
167 if (!cpl_table_has_column(grating,
"SPHI")) {
171 self->
sphi = cpl_table_get_double(grating,
"SPHI", row, NULL);
194 grating->
name = cx_string_new();
195 grating->
setup = cx_string_new();
196 grating->
filter = cx_string_new();
197 grating->
slit = cx_string_new();
224 const cxchar *
const c_setup =
"SETUP";
226 const cxchar *setup = NULL;
235 cpl_propertylist *properties = NULL;
237 cpl_table *_grating = NULL;
241 GiInstrumentMode mode;
245 if (spectra == NULL || grating == NULL) {
251 if (properties == NULL) {
257 if (_grating == NULL) {
274 if (!cpl_propertylist_has(properties, GIALIAS_GRATNAME)) {
279 cx_string_set(self->
name,
280 cpl_propertylist_get_string(properties,
286 if (!cpl_propertylist_has(properties, GIALIAS_FILTNAME)) {
291 cx_string_set(self->
filter,
292 cpl_propertylist_get_string(properties,
298 if (!cpl_propertylist_has(properties, GIALIAS_SLITNAME)) {
303 cx_string_set(self->
slit,
304 cpl_propertylist_get_string(properties,
310 if (!cpl_propertylist_has(properties, GIALIAS_GRATGRV)) {
316 cxdouble grooves = cpl_propertylist_get_double(properties,
318 self->
space = 1. / fabs(GI_MM_TO_NM * grooves);
331 if (!cpl_table_has_column(_grating,
"ORDER") ||
332 !cpl_table_has_column(_grating,
"WLEN0")) {
339 if (!cpl_propertylist_has(properties, GIALIAS_GRATWLEN)) {
344 wlen0 = cpl_propertylist_get_double(properties, GIALIAS_GRATWLEN);
347 if (!cpl_propertylist_has(properties, GIALIAS_GRATORDER)) {
352 order = cpl_propertylist_get_int(properties, GIALIAS_GRATORDER);
356 for (i = 0; i < cpl_table_get_nrow(_grating); i++) {
358 cxint _order = cpl_table_get_int(_grating,
"ORDER", i, NULL);
360 if (order == _order) {
362 cxdouble _wlen0 = cpl_table_get_double(_grating,
"WLEN0",
365 if (fabs(wlen0 - _wlen0) < GI_WAVELENGTH_EPSILON) {
387 if (cpl_propertylist_has(properties, GIALIAS_SETUPNAME)) {
388 setup = cpl_propertylist_get_string(properties, GIALIAS_SETUPNAME);
389 cx_string_set(self->
setup, setup);
392 if (cpl_table_has_column(_grating, c_setup)) {
393 setup = cpl_table_get_string(_grating, c_setup, row);
394 cx_string_set(self->
setup, setup);
399 status = _giraffe_grating_copy(self, _grating, row, mode);
431 if (self->
name != NULL) {
432 cx_string_delete(self->
name);
435 if (self->
setup != NULL) {
436 cx_string_delete(self->
setup);
439 if (self->
filter != NULL) {
440 cx_string_delete(self->
filter);
443 if (self->
slit != NULL) {
444 cx_string_delete(self->
slit);
481 const cxchar*
const fctid =
"giraffe_grating_setup";
483 const cxchar* c_name_setup =
"SETUP";
484 const cxchar* c_name_order =
"ORDER";
485 const cxchar* c_name_wl0 =
"WLEN0";
486 const cxchar* c_name_wlmin =
"WLMIN";
487 const cxchar* c_name_wlmax =
"WLMAX";
488 const cxchar* c_name_band =
"BAND";
489 const cxchar* c_name_theta =
"THETA";
490 const cxchar* c_name_fcoll =
"FCOLL";
491 const cxchar* c_name_gcam =
"GCAM";
492 const cxchar* c_name_sdx =
"SDX";
493 const cxchar* c_name_sdy =
"SDY";
494 const cxchar* c_name_sdphi =
"SPHI";
495 const cxchar* c_name_rmed =
"RMED";
496 const cxchar* c_name_rifa =
"RIFA";
502 cxdouble wlen_match = 0.;
504 cxdouble tmp_gratgrv = 0.;
507 cx_string* slit_name = NULL;
509 cpl_propertylist* ref_plimg = NULL;
511 cpl_table* ref_gtable = NULL;
513 GiInstrumentMode instrument_mode;
520 if (grating_table == NULL) {
524 if (spectra == NULL) {
528 if (grating_setup == NULL) {
533 if (ref_plimg == NULL) {
538 if (ref_gtable == NULL) {
542 slit_name = cx_string_new();
552 if (cpl_propertylist_has(ref_plimg, GIALIAS_GRATWLEN) == FALSE) {
553 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATWLEN);
554 cx_string_delete(slit_name);
558 grating_setup->
wlen0 = cpl_propertylist_get_double(ref_plimg,
562 if (cpl_propertylist_has(ref_plimg, GIALIAS_SLITNAME) == FALSE) {
563 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_SLITNAME);
564 cx_string_delete(slit_name);
568 cx_string_set(slit_name,
569 cpl_propertylist_get_string(ref_plimg,
573 if (cpl_propertylist_has(ref_plimg, GIALIAS_GRATGRV) == FALSE) {
574 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATGRV);
575 cx_string_delete(slit_name);
579 tmp_gratgrv = cpl_propertylist_get_double(ref_plimg,
583 if (cpl_propertylist_has(ref_plimg, GIALIAS_GRATNAME) == FALSE) {
584 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATNAME);
585 cx_string_delete(slit_name);
589 cx_string_set(grating_setup->
name,
590 cpl_propertylist_get_string(ref_plimg,
594 if (cpl_propertylist_has(ref_plimg, GIALIAS_FILTNAME) == FALSE) {
595 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_FILTNAME);
596 cx_string_delete(slit_name);
600 cx_string_set(grating_setup->
filter,
601 cpl_propertylist_get_string(ref_plimg,
610 for (i = 0; i < cpl_table_get_nrow(ref_gtable); i++) {
612 wlen = cpl_table_get(ref_gtable, c_name_wl0, i, &row_nulls);
614 if (fabs(wlen - grating_setup->
wlen0) <
615 fabs(wlen_match - grating_setup->
wlen0)) {
627 if (fabs(wlen_match - grating_setup->
wlen0) > GI_WAVELENGTH_EPSILON) {
629 cpl_msg_error(fctid,
"Central wavelength [%f] nout found in grating "
630 "table, aborting...", grating_setup->
wlen0);
631 cx_string_delete(slit_name);
635 cpl_msg_debug(fctid,
"Found wlen0 in grating table at position %d",
645 cx_string_set(grating_setup->
setup,
646 (cxchar*) cpl_table_get_string(ref_gtable, c_name_setup,
649 cx_string_set(grating_setup->
slit, cx_string_get(slit_name));
651 grating_setup->
order = cpl_table_get(ref_gtable, c_name_order,
652 row_match, &row_nulls);
654 grating_setup->
wlenmin = cpl_table_get(ref_gtable, c_name_wlmin,
655 row_match, &row_nulls);
657 grating_setup->
wlenmax = cpl_table_get(ref_gtable, c_name_wlmax,
658 row_match, &row_nulls);
660 grating_setup->
band = cpl_table_get(ref_gtable, c_name_band,
661 row_match, &row_nulls);
663 grating_setup->
theta = cpl_table_get(ref_gtable, c_name_theta,
664 row_match, &row_nulls);
666 grating_setup->
space = 1.0 / fabs(GI_MM_TO_NM * tmp_gratgrv);
671 switch (instrument_mode) {
673 grating_setup->
resol = cpl_table_get(ref_gtable, c_name_rmed,
674 row_match, &row_nulls);
678 grating_setup->
resol = cpl_table_get(ref_gtable, c_name_rifa,
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 = -1.0;
692 grating_setup->
fcoll =
693 cpl_table_get(ref_gtable, c_name_fcoll, row_match, &row_nulls);
695 grating_setup->
gcam =
696 cpl_table_get(ref_gtable, c_name_gcam, row_match, &row_nulls);
699 cpl_table_get(ref_gtable, c_name_sdx, row_match, &row_nulls);
702 cpl_table_get(ref_gtable, c_name_sdy, row_match, &row_nulls);
704 grating_setup->
sphi =
705 cpl_table_get(ref_gtable, c_name_sdphi, row_match, &row_nulls);
707 cx_string_delete(slit_name);
728 const cxchar *fctid =
"giraffe_grating_dump";
730 if (grating == NULL) {
734 cpl_msg_debug(fctid,
"---- GiGrating -------------------------");
736 cpl_msg_debug(fctid,
"Grating Name : %s",
737 cx_string_get(grating->
name));
738 cpl_msg_debug(fctid,
"Grating Filter Name : %s",
739 cx_string_get(grating->
filter));
740 cpl_msg_debug(fctid,
"Grating Setup Name : %s",
741 cx_string_get(grating->
setup));
742 cpl_msg_debug(fctid,
"Grating Order : %12d", grating->
order);
743 cpl_msg_debug(fctid,
"Grating Wlen0 : %12.6f", grating->
wlen0);
744 cpl_msg_debug(fctid,
"Grating Wlen Min : %12.6f", grating->
wlenmin);
745 cpl_msg_debug(fctid,
"Grating Wlen Max : %12.6f", grating->
wlenmax);
746 cpl_msg_debug(fctid,
"Grating Band : %12.6f", grating->
band);
747 cpl_msg_debug(fctid,
"Grating Resol : %12d", grating->
resol);
748 cpl_msg_debug(fctid,
"Grating Space : %12.6f", grating->
space);
749 cpl_msg_debug(fctid,
"Grating Theta : %12.6f", grating->
theta);
750 cpl_msg_debug(fctid,
"Grating FColl : %12.6f", grating->
fcoll);
751 cpl_msg_debug(fctid,
"Grating GCam : %12.6f", grating->
gcam);
752 cpl_msg_debug(fctid,
"Grating SlitDx : %12.6f", grating->
sdx);
753 cpl_msg_debug(fctid,
"Grating SlitDy : %12.6f", grating->
sdy);
754 cpl_msg_debug(fctid,
"Grating SlitPhi : %12.6f", grating->
sphi);
cxint giraffe_grating_setup(GiTable *grating_table, GiImage *spectra, GiGrating *grating_setup)
Retrieves grating information and returns it in a GiGrating structure.
void giraffe_grating_dump(const GiGrating *grating)
Dump the the information contained in a GiGrating to output.
GiGrating * giraffe_grating_new(void)
Create a new GiGrating.
GiGrating * giraffe_grating_create(const GiImage *spectra, const GiTable *grating)
Create a GiGrating from a reference image.
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.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
GiInstrumentMode giraffe_get_mode(cpl_propertylist *properties)
Determines the instrument mode from a property list.
Structure to handle Grating Information.