55 #define PRINT_USAGE(rc) \
56 fprintf(stderr, "Usage: %s PIXTABLE_IN IFU SLICE PIXTABLE_OUT\n", argv[0]); \
57 cpl_end(); return (rc);
75 cpl_ensure_code(aPixtable && aPixtable->
header && aPixtable->
table,
76 CPL_ERROR_NULL_INPUT);
77 if (cpl_table_count_selected(aPixtable->
table) < 1) {
78 return CPL_ERROR_NONE;
80 cpl_array *sel = cpl_table_where_selected(aPixtable->
table);
81 cpl_size narray = cpl_array_get_size(sel),
84 const cpl_size *asel = cpl_array_get_data_cplsize_const(sel);
85 unsigned int nexp = 0;
90 if (!cpl_propertylist_has(aPixtable->
header, kwfst) ||
91 !cpl_propertylist_has(aPixtable->
header, kwlst)) {
96 ifst = cpl_propertylist_get_long_long(aPixtable->
header, kwfst);
97 ilst = cpl_propertylist_get_long_long(aPixtable->
header, kwlst);
100 for (i = 0; i < narray; i++) {
101 if (asel[i] >= ifst && asel[i] <= ilst) {
105 cpl_size ifst2 = ifst - nselprev,
106 ilst2 = ilst - nsel - nselprev;
107 cpl_msg_debug(__func__,
"exp %d old %"CPL_SIZE_FORMAT
"..%"CPL_SIZE_FORMAT
108 ", %"CPL_SIZE_FORMAT
" selected (previous: %"CPL_SIZE_FORMAT
109 "), new %"CPL_SIZE_FORMAT
"..%"CPL_SIZE_FORMAT, nexp,
110 ifst, ilst, nsel, nselprev, ifst2, ilst2);
117 }
while (ilst >= ifst);
118 cpl_array_delete(sel);
119 return CPL_ERROR_NONE;
142 static cpl_error_code
144 unsigned short aSlice)
146 cpl_ensure_code(aPixtable, CPL_ERROR_NULL_INPUT);
148 cpl_ensure_code(nrow > 0, CPL_ERROR_DATA_NOT_FOUND);
150 cpl_table_unselect_all(aPixtable->
table);
151 uint32_t *origin = (uint32_t *)cpl_table_get_data_int(aPixtable->
table,
152 MUSE_PIXTABLE_ORIGIN);
154 for (irow = 0; irow < nrow; irow++) {
157 if (ifu == aIFU && slice == aSlice) {
158 cpl_table_select_row(aPixtable->
table, irow);
161 cpl_size nsel = cpl_table_count_selected(aPixtable->
table);
162 cpl_error_code rc = cpl_table_erase_selected(aPixtable->
table);
163 cpl_msg_debug(__func__,
"Erased %"CPL_SIZE_FORMAT
" rows from pixel table",
171 int main(
int argc,
char **argv)
173 cpl_init(CPL_INIT_DEFAULT);
174 cpl_errorstate prestate = cpl_errorstate_get();
183 unsigned char ifu = 0;
184 unsigned short slice = 0;
188 for (i = 1; i < argc; i++) {
189 if (tiname && toname) {
197 slice = atoi(argv[i]);
202 if (ifu == 0 || ifu > kMuseNumIFUs) {
203 printf(
"Illegal IFU number %hhu given\n", ifu);
206 if (slice == 0 || slice > kMuseSlicesPerCCD) {
207 printf(
"Illegal slice number %hhu given\n", slice);
216 printf(
"Loaded pixel table \"%s\" with %"CPL_SIZE_FORMAT
" rows\n",
221 if (rc == CPL_ERROR_NONE) {
222 printf(
"Erased slice %hu of IFU %hhu (%"CPL_SIZE_FORMAT
" pixels removed)\n",
223 slice, ifu, nrow - nrow2);
225 printf(
"Error while erasing slice %hu of IFU %hhu: %s\n", slice, ifu,
226 cpl_error_get_message());
230 printf(
"MUSE pixel table \"%s\" (%"CPL_SIZE_FORMAT
" rows) saved\n", toname,
233 rc = cpl_errorstate_is_equal(prestate) ? 0 : 50;
#define MUSE_HDR_PT_EXP_FST
FITS header keyword defining the first row index for a given exposure.
muse_pixtable * muse_pixtable_load(const char *aFilename)
Load the table itself and the FITS headers of a MUSE pixel table from a file.
unsigned short muse_pixtable_origin_get_slice(uint32_t aOrigin)
Get the slice number from the encoded 32bit origin number.
cpl_size muse_pixtable_get_nrow(muse_pixtable *aPixtable)
get the number of rows within the pixel table
#define MUSE_HDR_PT_EXP_LST
FITS header keyword defining the last row index for a given exposure.
cpl_table * table
The pixel table.
Structure definition of MUSE pixel table.
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
cpl_error_code muse_cplpropertylist_update_long_long(cpl_propertylist *aHeader, const char *aKeyword, cpl_size aValue)
Update an integer-like property irrespective of the real type.
cpl_error_code muse_pixtable_save(muse_pixtable *aPixtable, const char *aFilename)
Save a MUSE pixel table to a file on disk.
unsigned short muse_pixtable_origin_get_ifu(uint32_t aOrigin)
Get the IFU number from the encoded 32bit origin number.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
cpl_error_code muse_pixtable_compute_limits(muse_pixtable *aPixtable)
(Re-)Compute the limits of the coordinate columns of a pixel table.
cpl_propertylist * header
The FITS header.