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