MUSE Pipeline Reference Manual  2.1.1
muse_pixtable_dump.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) 2007-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 /*----------------------------------------------------------------------------*/
57 /*----------------------------------------------------------------------------*/
58 
61 #define PRINT_USAGE(rc) \
62  fprintf(stderr, "Usage: %s [ -s startidx ] [ -c count ] PIXTABLE\n", \
63  argv[0]); \
64  cpl_end(); return (rc);
65 
66 int main(int argc, char **argv)
67 {
68  cpl_init(CPL_INIT_DEFAULT);
70 
71  if (argc <= 1) {
72  /* filename is needed at least */
73  PRINT_USAGE(1);
74  }
75 
76  char *tname = NULL;
77  cpl_size start = 0, count = CPL_SIZE_MAX;
78  int i;
79 
80  /* argument processing */
81  for (i = 1; i < argc; i++) {
82  if (strncmp(argv[i], "-s", 3) == 0) {
83  /* skip to next arg to get start value */
84  i++;
85  if (i < argc) {
86  start = atol(argv[i]);
87  } else {
88  PRINT_USAGE(2);
89  }
90  } else if (strncmp(argv[i], "-c", 3) == 0) {
91  /* skip to next arg to get count value */
92  i++;
93  if (i < argc) {
94  count = atol(argv[i]);
95  } else {
96  PRINT_USAGE(3);
97  }
98  } else if (strncmp(argv[i], "-", 1) == 0) { /* unallowed options */
99  PRINT_USAGE(9);
100  } else {
101  tname = argv[i];
102  break; /* we have the required name, skip the rest */
103  }
104  }
105 
106  cpl_msg_set_level(CPL_MSG_WARNING); /* swallow INFO output */
107  muse_pixtable *table = muse_pixtable_load_window(tname, start, count);
108  if (!table) {
109  PRINT_USAGE(10);
110  }
111 
112  if (count == CPL_SIZE_MAX) {
113  count = muse_pixtable_get_nrow(table);
114  }
115  /* find out original table length from the table FITS header */
116  cpl_propertylist *theader = cpl_propertylist_load(tname, 1);
117  cpl_size nrow = cpl_propertylist_get_long_long(theader, "NAXIS2");
118  cpl_propertylist_delete(theader);
119 
120  printf("# MUSE pixel table \"%s\", showing %"CPL_SIZE_FORMAT" rows starting "
121  "at index %"CPL_SIZE_FORMAT" of %"CPL_SIZE_FORMAT"\n", tname, count,
122  start, nrow);
123  cpl_error_code rc = muse_pixtable_dump(table, 0, count, 1);
124  switch (rc) {
125  case CPL_ERROR_NONE:
126  rc = 0;
127  break;
128  case CPL_ERROR_BAD_FILE_FORMAT:
129  fprintf(stderr, "%s: \"%s\" does not seem to contain a MUSE pixel table!\n",
130  argv[0], tname);
131  rc = 11;
132  break;
133  case CPL_ERROR_ILLEGAL_INPUT:
134  fprintf(stderr, "%s: Illegal data range given (start index=%"CPL_SIZE_FORMAT
135  " count=%"CPL_SIZE_FORMAT") for table with %"CPL_SIZE_FORMAT
136  " rows!\n", argv[0], start, count, muse_pixtable_get_nrow(table));
137  rc = 12;
138  break;
139  default:
140  rc = 50;
141  } /* switch */
142 
143  muse_pixtable_delete(table);
144  cpl_end();
145  return rc;
146 }
147 
cpl_size muse_pixtable_get_nrow(const muse_pixtable *aPixtable)
get the number of rows within the pixel table
cpl_error_code muse_pixtable_dump(muse_pixtable *aPixtable, cpl_size aStart, cpl_size aCount, unsigned char aDisplayHeader)
Dump a MUSE pixel table to the screen, resolving the origin column.
Structure definition of MUSE pixel table.
muse_pixtable * muse_pixtable_load_window(const char *aFilename, cpl_size aStart, cpl_size aNRows)
Load a range of rows from the table and all the FITS headers of a MUSE pixel table from a file...
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.