28 #include "gigrating.h"
30 #define GIFITS_KEYWORD_MISSING_MSG "FITS KEYWORD [%s] not found!! Aborting..."
41 static const cxdouble GI_WAVELENGTH_EPSILON = 1.e-8;
45 _giraffe_grating_copy(
GiGrating *
self, cpl_table *grating, cxint row,
46 GiInstrumentMode mode)
49 const cxchar *c_resolution = NULL;
52 cx_assert(
self != NULL);
53 cx_assert(grating != NULL);
56 if (row >= cpl_table_get_nrow(grating)) {
61 if (!cpl_table_has_column(grating,
"ORDER")) {
65 self->order = cpl_table_get_int(grating,
"ORDER", row, NULL);
69 if (!cpl_table_has_column(grating,
"WLEN0")) {
73 self->wlen0 = cpl_table_get_double(grating,
"WLEN0", row, NULL);
77 if (!cpl_table_has_column(grating,
"WLMIN")) {
81 self->wlenmin = cpl_table_get_double(grating,
"WLMIN", row, NULL);
85 if (!cpl_table_has_column(grating,
"WLMAX")) {
89 self->wlenmax = cpl_table_get_double(grating,
"WLMAX", row, NULL);
93 if (!cpl_table_has_column(grating,
"BAND")) {
97 self->band = cpl_table_get_double(grating,
"BAND", row, NULL);
103 c_resolution =
"RMED";
108 c_resolution =
"RIFA";
116 if (!cpl_table_has_column(grating, c_resolution)) {
120 self->resol = cpl_table_get_int(grating, c_resolution, row, NULL);
124 if (!cpl_table_has_column(grating,
"THETA")) {
128 self->theta = cpl_table_get_double(grating,
"THETA", row, NULL);
132 if (!cpl_table_has_column(grating,
"FCOLL")) {
136 self->fcoll = cpl_table_get_double(grating,
"FCOLL", row, NULL);
140 if (!cpl_table_has_column(grating,
"GCAM")) {
144 self->gcam = cpl_table_get_double(grating,
"GCAM", row, NULL);
148 if (!cpl_table_has_column(grating,
"SDX")) {
152 self->sdx = cpl_table_get_double(grating,
"SDX", row, NULL);
156 if (!cpl_table_has_column(grating,
"SDY")) {
160 self->sdy = cpl_table_get_double(grating,
"SDY", row, NULL);
164 if (!cpl_table_has_column(grating,
"SPHI")) {
168 self->sphi = cpl_table_get_double(grating,
"SPHI", row, NULL);
191 grating->
name = cx_string_new();
192 grating->
setup = cx_string_new();
193 grating->
filter = cx_string_new();
194 grating->
slit = cx_string_new();
221 const cxchar *
const c_setup =
"SETUP";
223 const cxchar *setup = NULL;
232 cpl_propertylist *properties = NULL;
234 cpl_table *_grating = NULL;
238 GiInstrumentMode mode;
242 if (spectra == NULL || grating == NULL) {
248 if (properties == NULL) {
254 if (_grating == NULL) {
271 if (!cpl_propertylist_has(properties, GIALIAS_GRATNAME)) {
276 cx_string_set(self->name,
277 cpl_propertylist_get_string(properties,
283 if (!cpl_propertylist_has(properties, GIALIAS_FILTNAME)) {
288 cx_string_set(self->filter,
289 cpl_propertylist_get_string(properties,
295 if (!cpl_propertylist_has(properties, GIALIAS_SLITNAME)) {
300 cx_string_set(self->slit,
301 cpl_propertylist_get_string(properties,
307 if (!cpl_propertylist_has(properties, GIALIAS_GRATGRV)) {
313 cxdouble grooves = cpl_propertylist_get_double(properties,
315 self->space = 1. / fabs(GI_MM_TO_NM * grooves);
328 if (!cpl_table_has_column(_grating,
"ORDER") ||
329 !cpl_table_has_column(_grating,
"WLEN0")) {
336 if (!cpl_propertylist_has(properties, GIALIAS_GRATWLEN)) {
341 wlen0 = cpl_propertylist_get_double(properties, GIALIAS_GRATWLEN);
344 if (!cpl_propertylist_has(properties, GIALIAS_GRATORDER)) {
349 order = cpl_propertylist_get_int(properties, GIALIAS_GRATORDER);
353 for (i = 0; i < cpl_table_get_nrow(_grating); i++) {
355 cxint _order = cpl_table_get_int(_grating,
"ORDER", i, NULL);
357 if (order == _order) {
359 cxdouble _wlen0 = cpl_table_get_double(_grating,
"WLEN0",
362 if (fabs(wlen0 - _wlen0) < GI_WAVELENGTH_EPSILON) {
384 if (cpl_propertylist_has(properties, GIALIAS_SETUPNAME)) {
385 setup = cpl_propertylist_get_string(properties, GIALIAS_SETUPNAME);
386 cx_string_set(self->setup, setup);
389 if (cpl_table_has_column(_grating, c_setup)) {
390 setup = cpl_table_get_string(_grating, c_setup, row);
391 cx_string_set(self->setup, setup);
396 status = _giraffe_grating_copy(
self, _grating, row, mode);
428 if (self->name != NULL) {
429 cx_string_delete(self->name);
432 if (self->setup != NULL) {
433 cx_string_delete(self->setup);
436 if (self->filter != NULL) {
437 cx_string_delete(self->filter);
440 if (self->slit != NULL) {
441 cx_string_delete(self->slit);
478 const cxchar*
const fctid =
"giraffe_grating_setup";
480 const cxchar* c_name_setup =
"SETUP";
481 const cxchar* c_name_order =
"ORDER";
482 const cxchar* c_name_wl0 =
"WLEN0";
483 const cxchar* c_name_wlmin =
"WLMIN";
484 const cxchar* c_name_wlmax =
"WLMAX";
485 const cxchar* c_name_band =
"BAND";
486 const cxchar* c_name_theta =
"THETA";
487 const cxchar* c_name_fcoll =
"FCOLL";
488 const cxchar* c_name_gcam =
"GCAM";
489 const cxchar* c_name_sdx =
"SDX";
490 const cxchar* c_name_sdy =
"SDY";
491 const cxchar* c_name_sdphi =
"SPHI";
492 const cxchar* c_name_rmed =
"RMED";
493 const cxchar* c_name_rifa =
"RIFA";
499 cxdouble wlen_match = 0.;
501 cxdouble tmp_gratgrv = 0.;
504 cx_string* slit_name = NULL;
506 cpl_propertylist* ref_plimg = NULL;
508 cpl_table* ref_gtable = NULL;
510 GiInstrumentMode instrument_mode;
517 if (grating_table == NULL) {
521 if (spectra == NULL) {
525 if (grating_setup == NULL) {
530 if (ref_plimg == NULL) {
535 if (ref_gtable == NULL) {
539 slit_name = cx_string_new();
549 if (cpl_propertylist_has(ref_plimg, GIALIAS_GRATWLEN) == FALSE) {
550 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATWLEN);
551 cx_string_delete(slit_name);
555 grating_setup->
wlen0 = cpl_propertylist_get_double(ref_plimg,
559 if (cpl_propertylist_has(ref_plimg, GIALIAS_SLITNAME) == FALSE) {
560 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_SLITNAME);
561 cx_string_delete(slit_name);
565 cx_string_set(slit_name,
566 cpl_propertylist_get_string(ref_plimg,
570 if (cpl_propertylist_has(ref_plimg, GIALIAS_GRATGRV) == FALSE) {
571 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATGRV);
572 cx_string_delete(slit_name);
576 tmp_gratgrv = cpl_propertylist_get_double(ref_plimg,
580 if (cpl_propertylist_has(ref_plimg, GIALIAS_GRATNAME) == FALSE) {
581 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_GRATNAME);
582 cx_string_delete(slit_name);
586 cx_string_set(grating_setup->
name,
587 cpl_propertylist_get_string(ref_plimg,
591 if (cpl_propertylist_has(ref_plimg, GIALIAS_FILTNAME) == FALSE) {
592 cpl_msg_error(fctid, GIFITS_KEYWORD_MISSING_MSG, GIALIAS_FILTNAME);
593 cx_string_delete(slit_name);
597 cx_string_set(grating_setup->
filter,
598 cpl_propertylist_get_string(ref_plimg,
607 for (i = 0; i < cpl_table_get_nrow(ref_gtable); i++) {
609 wlen = cpl_table_get(ref_gtable, c_name_wl0, i, &row_nulls);
611 if (fabs(wlen - grating_setup->
wlen0) <
612 fabs(wlen_match - grating_setup->
wlen0)) {
624 if (fabs(wlen_match - grating_setup->
wlen0) > GI_WAVELENGTH_EPSILON) {
626 cpl_msg_error(fctid,
"Central wavelength [%f] nout found in grating "
627 "table, aborting...", grating_setup->
wlen0);
628 cx_string_delete(slit_name);
632 cpl_msg_debug(fctid,
"Found wlen0 in grating table at position %d",
642 cx_string_set(grating_setup->
setup,
643 (cxchar*) cpl_table_get_string(ref_gtable, c_name_setup,
646 cx_string_set(grating_setup->
slit, cx_string_get(slit_name));
648 grating_setup->
order = cpl_table_get(ref_gtable, c_name_order,
649 row_match, &row_nulls);
651 grating_setup->
wlenmin = cpl_table_get(ref_gtable, c_name_wlmin,
652 row_match, &row_nulls);
654 grating_setup->
wlenmax = cpl_table_get(ref_gtable, c_name_wlmax,
655 row_match, &row_nulls);
657 grating_setup->
band = cpl_table_get(ref_gtable, c_name_band,
658 row_match, &row_nulls);
660 grating_setup->
theta = cpl_table_get(ref_gtable, c_name_theta,
661 row_match, &row_nulls);
663 grating_setup->
space = 1.0 / fabs(GI_MM_TO_NM * tmp_gratgrv);
668 switch (instrument_mode) {
670 grating_setup->
resol = cpl_table_get(ref_gtable, c_name_rmed,
671 row_match, &row_nulls);
675 grating_setup->
resol = cpl_table_get(ref_gtable, c_name_rifa,
676 row_match, &row_nulls);
680 grating_setup->
resol = cpl_table_get(ref_gtable, c_name_rifa,
681 row_match, &row_nulls);
685 grating_setup->
resol = -1.0;
689 grating_setup->
fcoll =
690 cpl_table_get(ref_gtable, c_name_fcoll, row_match, &row_nulls);
692 grating_setup->
gcam =
693 cpl_table_get(ref_gtable, c_name_gcam, row_match, &row_nulls);
696 cpl_table_get(ref_gtable, c_name_sdx, row_match, &row_nulls);
699 cpl_table_get(ref_gtable, c_name_sdy, row_match, &row_nulls);
701 grating_setup->
sphi =
702 cpl_table_get(ref_gtable, c_name_sdphi, row_match, &row_nulls);
704 cx_string_delete(slit_name);
725 const cxchar *fctid =
"giraffe_grating_dump";
727 if (grating == NULL) {
731 cpl_msg_debug(fctid,
"---- GiGrating -------------------------");
733 cpl_msg_debug(fctid,
"Grating Name : %s",
734 cx_string_get(grating->
name));
735 cpl_msg_debug(fctid,
"Grating Filter Name : %s",
736 cx_string_get(grating->
filter));
737 cpl_msg_debug(fctid,
"Grating Setup Name : %s",
738 cx_string_get(grating->
setup));
739 cpl_msg_debug(fctid,
"Grating Order : %12d", grating->
order);
740 cpl_msg_debug(fctid,
"Grating Wlen0 : %12.6f", grating->
wlen0);
741 cpl_msg_debug(fctid,
"Grating Wlen Min : %12.6f", grating->
wlenmin);
742 cpl_msg_debug(fctid,
"Grating Wlen Max : %12.6f", grating->
wlenmax);
743 cpl_msg_debug(fctid,
"Grating Band : %12.6f", grating->
band);
744 cpl_msg_debug(fctid,
"Grating Resol : %12d", grating->
resol);
745 cpl_msg_debug(fctid,
"Grating Space : %12.6f", grating->
space);
746 cpl_msg_debug(fctid,
"Grating Theta : %12.6f", grating->
theta);
747 cpl_msg_debug(fctid,
"Grating FColl : %12.6f", grating->
fcoll);
748 cpl_msg_debug(fctid,
"Grating GCam : %12.6f", grating->
gcam);
749 cpl_msg_debug(fctid,
"Grating SlitDx : %12.6f", grating->
sdx);
750 cpl_msg_debug(fctid,
"Grating SlitDy : %12.6f", grating->
sdy);
751 cpl_msg_debug(fctid,
"Grating SlitPhi : %12.6f", grating->
sphi);
GiGrating * giraffe_grating_new(void)
Create a new GiGrating.
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.
void giraffe_grating_delete(GiGrating *self)
Destroys an GiGrating object.
GiGrating * giraffe_grating_create(const GiImage *spectra, const GiTable *grating)
Create a GiGrating from a reference image.
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.