MUSE Pipeline Reference Manual  0.18.5
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  muse_pixtable *table = muse_pixtable_load_window(tname, start, count);
106  if (!table) {
107  PRINT_USAGE(10);
108  }
109 
110  if (count == CPL_SIZE_MAX) {
111  count = muse_pixtable_get_nrow(table);
112  }
113  /* find out original table length from the table FITS header */
114  cpl_propertylist *theader = cpl_propertylist_load(tname, 1);
115  cpl_size nrow = cpl_propertylist_get_long_long(theader, "NAXIS2");
116  cpl_propertylist_delete(theader);
117 
118  printf("# MUSE pixel table \"%s\", showing %"CPL_SIZE_FORMAT" rows starting "
119  "at index %"CPL_SIZE_FORMAT" of %"CPL_SIZE_FORMAT"\n", tname, count,
120  start, nrow);
121  cpl_error_code rc = muse_pixtable_dump(table, 0, count, 1);
122  switch (rc) {
123  case CPL_ERROR_NONE:
124  rc = 0;
125  break;
126  case CPL_ERROR_BAD_FILE_FORMAT:
127  fprintf(stderr, "%s: \"%s\" does not seem to contain a MUSE pixel table!\n",
128  argv[0], tname);
129  rc = 11;
130  break;
131  case CPL_ERROR_ILLEGAL_INPUT:
132  fprintf(stderr, "%s: Illegal data range given (start index=%"CPL_SIZE_FORMAT
133  " count=%"CPL_SIZE_FORMAT") for table with %"CPL_SIZE_FORMAT
134  " rows!\n", argv[0], start, count, muse_pixtable_get_nrow(table));
135  rc = 12;
136  break;
137  default:
138  rc = 50;
139  } /* switch */
140 
141  muse_pixtable_delete(table);
142  cpl_end();
143  return rc;
144 }
145 
cpl_size muse_pixtable_get_nrow(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.