MUSE Pipeline Reference Manual  1.0.2
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);
62  cpl_errorstate prestate = cpl_errorstate_get();
63 
64  if (argc != 5) {
65  /* four arguments are needed */
66  PRINT_USAGE(1);
67  }
68 
69  char *tiname = NULL, /* input table */
70  *toname = NULL; /* output table */
71  unsigned char ifu = 0;
72  unsigned short slice = 0;
73  int i;
74 
75  /* argument processing */
76  for (i = 1; i < argc; i++) {
77  if (tiname && toname) {
78  break; /* we have the required name, skip the rest */
79  }
80  if (!tiname) {
81  tiname = argv[i]; /* set the name for the input table */
82  } else if (!ifu) {
83  ifu = atoi(argv[i]);
84  } else if (!slice) {
85  slice = atoi(argv[i]);
86  } else {
87  toname = argv[i]; /* set the name for the output table */
88  }
89  } /* for i (all arguments) */
90  if (ifu == 0 || ifu > kMuseNumIFUs) {
91  printf("Illegal IFU number %hhu given\n", ifu);
92  PRINT_USAGE(2);
93  }
94  if (slice == 0 || slice > kMuseSlicesPerCCD) {
95  printf("Illegal slice number %hhu given\n", slice);
96  PRINT_USAGE(3);
97  }
98 
99  muse_pixtable *table = muse_pixtable_load(tiname);
100  if (!table) {
101  PRINT_USAGE(10);
102  }
103  cpl_size nrow = muse_pixtable_get_nrow(table);
104  printf("Loaded pixel table \"%s\" with %"CPL_SIZE_FORMAT" rows\n",
105  tiname, nrow);
106 
107  cpl_error_code rc = muse_pixtable_erase_ifu_slice(table, ifu, slice);
108  cpl_size nrow2 = muse_pixtable_get_nrow(table);
109  if (rc == CPL_ERROR_NONE) {
110  printf("Erased slice %hu of IFU %hhu (%"CPL_SIZE_FORMAT" pixels removed)\n",
111  slice, ifu, nrow - nrow2);
112  } else {
113  printf("Error while erasing slice %hu of IFU %hhu: %s\n", slice, ifu,
114  cpl_error_get_message());
115  }
116 
117  muse_pixtable_save(table, toname);
118  printf("MUSE pixel table \"%s\" (%"CPL_SIZE_FORMAT" rows) saved\n", toname,
119  nrow2);
120  muse_pixtable_delete(table);
121  rc = cpl_errorstate_is_equal(prestate) ? 0 : 50;
122  if (rc) {
123  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
124  }
125  cpl_end();
126  return rc;
127 }
128 
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.