29#include "gimessages.h"
31#include "gifiberutils.h"
33#include "gislitgeometry.h"
59_giraffe_slitgeometry_insert(
GiSlitGeometry *self, cxint pos, cxint nrow,
71 if ((pos < 0) || (pos > self->
nsubslits)) {
76 cpl_matrix_delete(self->
subslits[pos]);
79 self->
subslits[pos] = cpl_matrix_new(nrow, ncol);
188 const cxchar *fctid =
"giraffe_slitgeometry_create";
191 const cxchar *c_xf =
"XF";
192 const cxchar *c_yf =
"YF";
193 const cxchar *c_fps =
"FPS";
194 const cxchar *c_ssn =
"SSN";
195 const cxchar *c_rindex = NULL;
199 cxint max_nsubslits = 0;
203 cxint column_index = 0;
205 cpl_matrix *nsubslits = NULL;
207 cpl_table *_slitgeometry = NULL;
212 if (slitgeometry == NULL) {
223 nfibers = cpl_table_get_nrow(_slitgeometry);
225 self->xf = cpl_matrix_new(nfibers, 1);
226 self->yf = cpl_matrix_new(nfibers, 1);
227 self->fps = cpl_matrix_new(nfibers, 1);
228 self->rindex = cpl_matrix_new(nfibers, 1);
230 nsubslits = cpl_matrix_new(nfibers, 1);
241 for (i = 0; i < nfibers; i++) {
243 cxint _nsubslits = cpl_table_get_int(_slitgeometry, c_ssn, i, NULL);
244 cxint _fps = cpl_table_get_int(_slitgeometry, c_fps, i, NULL) - 1;
245 cxint _index = cpl_table_get_int(_slitgeometry, c_rindex,
248 cxdouble _xf = cpl_table_get(_slitgeometry, c_xf, i, NULL);;
249 cxdouble _yf = cpl_table_get(_slitgeometry, c_yf, i, NULL);
252 if (_nsubslits > max_nsubslits) {
253 max_nsubslits = _nsubslits;
256 cpl_matrix_set(self->xf, i, 0, _xf);
257 cpl_matrix_set(self->yf, i, 0, _yf);
258 cpl_matrix_set(self->fps, i, 0, (cxdouble)_fps);
259 cpl_matrix_set(self->rindex, i, 0, (cxdouble)_index);
261 cpl_matrix_set(nsubslits, i, 0, (cxdouble)_nsubslits);
276 for (i = 1; i <= max_nsubslits; i++) {
280 cpl_matrix *ref_matrix = NULL;
283 for (j = 0; j < nfibers; j++) {
284 curr_ssn = (cxint) cpl_matrix_get(nsubslits, j, 0);
291 _giraffe_slitgeometry_insert(self, i - 1, count, 1);
296 for (j = 0; j < nfibers; j++) {
298 curr_ssn = (cxint) cpl_matrix_get(nsubslits, j, 0);
302 cpl_matrix_set(ref_matrix, column_index, 0,
309 cpl_msg_debug(fctid,
"Using multiple slits for Slit Geometry");
316 cpl_matrix *ref_matrix = NULL;
319 _giraffe_slitgeometry_insert(self, 0, nfibers, 1);
323 for (j = 0; j < nfibers; j++) {
325 cpl_matrix_set(ref_matrix, j, 0, (cxdouble)j);
329 cpl_msg_debug(fctid,
"Using single slit for Slit Geometry");
333 cpl_matrix_delete(nsubslits);
364 cpl_matrix_delete(self->
subslits[i]);
435 cpl_matrix_delete(self->
subslits[i]);
478 if ((pos < 0) || (pos > self->
nsubslits)) {
483 cpl_matrix_delete(self->
subslits[pos]);
487 self->
subslits[pos] = cpl_matrix_duplicate(nm);
523 if ((pos < 0) || (pos > self->
nsubslits)) {
546 const cxchar *fctid =
"giraffe_slitgeometry_print";
558 gi_message(fctid,
"Invalid slit geometry, no slit matrices "
568 cpl_matrix *ref = NULL;
571 nrow = cpl_matrix_get_nrow(ref);
603 cxint pos,
const cxchar *tag)
606 const cxchar *fctid =
"giraffe_slitgeometry_load";
609 const cxchar *fps_name =
"FPS";
610 const cxchar *ridx = NULL;
615 cpl_propertylist *properties = NULL;
617 cpl_table *_fibers = NULL;
618 cpl_table *_slit_geometry = NULL;
620 GiTable *slit_geometry = NULL;
622 GiInstrumentMode mode;
626 if (fibers == NULL) {
627 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
633 if (_fibers == NULL) {
634 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
643 properties = cpl_propertylist_load(filename, 0);
645 if (properties == NULL) {
646 cpl_msg_error(fctid,
"Cannot load properies of data set 0 "
647 "from `%s'!", filename);
648 cpl_propertylist_delete(properties);
655 if (mode == GIMODE_NONE) {
656 cpl_msg_error(fctid,
"Invalid instrument mode!");
658 cpl_propertylist_delete(properties);
664 cpl_propertylist_delete(properties);
673 giraffe_error_push();
676 if (cpl_error_get_code() == CPL_ERROR_BAD_FILE_FORMAT) {
677 cpl_msg_error(fctid,
"Data set %d in `%s' is not a slit "
678 "geometry table!", pos, filename);
683 cpl_msg_error(fctid,
"Cannot load data set %d (slit geometry) "
684 "from `%s!", pos, filename);
694 if (!cpl_table_has_column(_slit_geometry, fps_name)) {
695 if (cpl_table_has_column(_slit_geometry,
"NSPEC")) {
696 cpl_msg_warning(fctid,
"Slit geometry loaded from `%s' uses "
697 "deprecated OGL column names.", filename);
708 cpl_table_duplicate_column(_slit_geometry, fps_name,
709 _slit_geometry,
"NSPEC");
711 cpl_table_name_column(_slit_geometry,
"NSPEC",
"INDEX");
713 if (mode == GIMODE_ARGUS) {
715 cxint nrow = cpl_table_get_nrow(_slit_geometry);
717 for (i = 0; i < nrow; i++) {
719 cxint idx = cpl_table_get_int(_slit_geometry,
"INDEX",
722 cpl_table_set_int(_slit_geometry, fps_name, i, idx);
730 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
742 nfibers = cpl_table_get_nrow(_fibers);
744 cpl_table_unselect_all(_slit_geometry);
746 for (i = 0; i < cpl_table_get_nrow(_slit_geometry); i++) {
748 cxint fps = cpl_table_get_int(_slit_geometry, fps_name, i, NULL);
751 for (j = 0; j < nfibers; j++) {
753 cxint _fps = cpl_table_get_int(_fibers,
"FPS", j, NULL);
756 cpl_table_select_row(_slit_geometry, i);
764 _slit_geometry = cpl_table_extract_selected(_slit_geometry);
768 cpl_table_new_column(_slit_geometry,
"RINDEX", CPL_TYPE_INT);
770 for (i = 0; i < cpl_table_get_nrow(_slit_geometry); i++) {
772 cxint fps = cpl_table_get_int(_slit_geometry, fps_name, i, NULL);
775 for (j = 0; j < nfibers; j++) {
777 cxint _fps = cpl_table_get_int(_fibers,
"FPS", j, NULL);
781 cxint _ridx = cpl_table_get_int(_fibers, ridx, j , NULL);
783 cpl_table_set_int(_slit_geometry,
"RINDEX", i, _ridx);
798 if (strcmp(fps_name,
"FPS") != 0) {
799 cpl_table_name_column(_slit_geometry, fps_name,
"FPS");
807 for (i = 0; i < cpl_table_get_nrow(_slit_geometry); i++) {
808 cpl_table_set_int(_slit_geometry,
"INDEX", i, i + 1);
813 cpl_table_delete(_slit_geometry);
814 _slit_geometry = NULL;
816 return slit_geometry;
822giraffe_slitgeometry_save(
const GiTable *slitgeometry)
825 cpl_frame *frame = NULL;
842 CPL_FRAME_LEVEL_FINAL,
const cxchar * giraffe_fiberlist_query_index(const cpl_table *fibers)
Query a fiber list for the name of the fiber reference index column.
cpl_frame * giraffe_frame_create_table(GiTable *table, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create a table product frame.
void giraffe_matrix_dump(const cpl_matrix *matrix, cxint max_rows)
Output a maximum number of rows of the input matrix.
void gi_message(const cxchar *format,...)
Log a normal message.
GiSlitGeometry * giraffe_slitgeometry_new(void)
Create a new GiSlitGeometry.
void giraffe_slitgeometry_resize(GiSlitGeometry *self, cxint size)
Destructive resize of a GiSlitGeometry.
void giraffe_slitgeometry_print(GiSlitGeometry *self)
Dump the the information contained in a GiSlitGeometry to output.
cxint giraffe_slitgeometry_size(GiSlitGeometry *self)
Returns current size of a GiSlitGeometry.
cpl_matrix * giraffe_slitgeometry_get(GiSlitGeometry *self, cxint pos)
Gets a reference to the matrix at a specified position.
GiSlitGeometry * giraffe_slitgeometry_duplicate(GiSlitGeometry *other)
Creates a (deep) copy of the GiSlitGeometry.
GiTable * giraffe_slitgeometry_load(const GiTable *fibers, const cxchar *filename, cxint pos, const cxchar *tag)
Load the slit geometry information for a given fiber setup.
void giraffe_slitgeometry_set(GiSlitGeometry *self, cxint pos, cpl_matrix *nm)
Sets (copies) a cpl_matrix to a specified position of the GiSlitGeometry.
GiSlitGeometry * giraffe_slitgeometry_create(GiTable *slitgeometry, cxbool subslits)
Create a slit geometry object from a slit geometry table.
void giraffe_slitgeometry_delete(GiSlitGeometry *self)
Destroy an GiSlitGeometry.
cxint giraffe_table_set(GiTable *self, cpl_table *table)
Sets the table data.
GiTable * giraffe_table_new(void)
Creates a new, empty Giraffe table.
GiTable * giraffe_table_duplicate(const GiTable *src)
Duplicate a Giraffe table.
cxint giraffe_table_load(GiTable *self, const cxchar *filename, cxint position, const cxchar *id)
Reads a data set from a file into a Giraffe table.
void giraffe_table_delete(GiTable *self)
Destroys a Giraffe table.
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.
The slit geometry object definition.