MUSE Pipeline Reference Manual  2.1.1
muse_pixtable_erase_slice.c
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set sw=2 sts=2 et cin: */
3 /*
4  * This file is part of the MUSE Instrument Pipeline
5  * Copyright (C) 2014 European Southern Observatory
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #include <muse.h>
23 #include <string.h>
24 
25 /*----------------------------------------------------------------------------*/
51 /*----------------------------------------------------------------------------*/
52 
55 #define PRINT_USAGE(rc) \
56  fprintf(stderr, "Usage: %s PIXTABLE_IN IFU SLICE PIXTABLE_OUT\n", argv[0]); \
57  cpl_end(); return (rc);
58 
59 int main(int argc, char **argv)
60 {
61  cpl_init(CPL_INIT_DEFAULT);
63  cpl_errorstate prestate = cpl_errorstate_get();
64 
65  if (argc != 5) {
66  /* four arguments are needed */
67  PRINT_USAGE(1);
68  }
69 
70  char *tiname = NULL, /* input table */
71  *toname = NULL; /* output table */
72  unsigned char ifu = 0;
73  unsigned short slice = 0;
74  int i;
75 
76  /* argument processing */
77  for (i = 1; i < argc; i++) {
78  if (tiname && toname) {
79  break; /* we have the required name, skip the rest */
80  }
81  if (!tiname) {
82  tiname = argv[i]; /* set the name for the input table */
83  } else if (!ifu) {
84  ifu = atoi(argv[i]);
85  } else if (!slice) {
86  slice = atoi(argv[i]);
87  } else {
88  toname = argv[i]; /* set the name for the output table */
89  }
90  } /* for i (all arguments) */
91  if (ifu == 0 || ifu > kMuseNumIFUs) {
92  printf("Illegal IFU number %hhu given\n", ifu);
93  PRINT_USAGE(2);
94  }
95  if (slice == 0 || slice > kMuseSlicesPerCCD) {
96  printf("Illegal slice number %hu given\n", slice);
97  PRINT_USAGE(3);
98  }
99 
100  muse_pixtable *table = muse_pixtable_load(tiname);
101  if (!table) {
102  PRINT_USAGE(10);
103  }
104  cpl_size nrow = muse_pixtable_get_nrow(table);
105  printf("Loaded pixel table \"%s\" with %"CPL_SIZE_FORMAT" rows\n",
106  tiname, nrow);
107 
108  cpl_error_code rc = muse_pixtable_erase_ifu_slice(table, ifu, slice);
109  cpl_size nrow2 = muse_pixtable_get_nrow(table);
110  if (rc == CPL_ERROR_NONE) {
111  printf("Erased slice %hu of IFU %hhu (%"CPL_SIZE_FORMAT" pixels removed)\n",
112  slice, ifu, nrow - nrow2);
113  } else {
114  printf("Error while erasing slice %hu of IFU %hhu: %s\n", slice, ifu,
115  cpl_error_get_message());
116  }
117 
118  muse_pixtable_save(table, toname);
119  printf("MUSE pixel table \"%s\" (%"CPL_SIZE_FORMAT" rows) saved\n", toname,
120  nrow2);
121  muse_pixtable_delete(table);
122  rc = cpl_errorstate_is_equal(prestate) ? 0 : 50;
123  if (rc) {
124  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
125  }
126  cpl_end();
127  return rc;
128 }
129 
muse_pixtable * muse_pixtable_load(const char *aFilename)
Load the table itself and the FITS headers of a MUSE pixel table from a file.
cpl_size muse_pixtable_get_nrow(const muse_pixtable *aPixtable)
get the number of rows within the pixel table
cpl_error_code muse_pixtable_erase_ifu_slice(muse_pixtable *aPixtable, unsigned char aIFU, unsigned short aSlice)
Erase pixel table rows related to one slice of one IFU.
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_pixtable_save(muse_pixtable *aPixtable, const char *aFilename)
Save a MUSE pixel table to a file on disk.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.