MUSE Pipeline Reference Manual  2.1.1
muse_wave_plot_column.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) 2011-2015 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 /*----------------------------------------------------------------------------*/
70 /*----------------------------------------------------------------------------*/
71 
74 #define PRINT_USAGE(rc) \
75  fprintf(stderr, "Usage: %s [ -n nifu ] [ -s slice ] [ -i iteration ] " \
76  "[ -c column ] [ -r ] WAVECAL_TABLE WAVECAL_RESIDUALS\n", argv[0]); \
77  cpl_end(); return (rc);
78 
79 int main(int argc, char **argv)
80 {
81  cpl_init(CPL_INIT_DEFAULT);
83 
84  if (argc <= 1) {
85  /* filename is needed at least */
86  PRINT_USAGE(1);
87  }
88 
89  char *tcname = NULL,
90  *trname = NULL;
91  unsigned short slice = 24;
92  unsigned char nifu = 0; /* IFU number to load */
93  unsigned int iteration = 0,
94  column = 0; /* default to central column of slice */
95  cpl_boolean residuals = CPL_FALSE;
96 
97  /* argument processing */
98  int i;
99  for (i = 1; i < argc; i++) {
100  if (strncmp(argv[i], "-s", 3) == 0) {
101  /* skip to next arg to get slice number */
102  i++;
103  if (i < argc) {
104  slice = atol(argv[i]);
105  } else {
106  PRINT_USAGE(2);
107  }
108  } else if (strncmp(argv[i], "-i", 3) == 0) {
109  /* skip to next arg to get iteration value */
110  i++;
111  if (i < argc) {
112  iteration = atol(argv[i]);
113  } else {
114  PRINT_USAGE(3);
115  }
116  } else if (strncmp(argv[i], "-c", 3) == 0) {
117  /* skip to next arg to get iteration value */
118  i++;
119  if (i < argc) {
120  column = atol(argv[i]);
121  } else {
122  PRINT_USAGE(4);
123  }
124  } else if (strncmp(argv[i], "-n", 3) == 0) {
125  /* skip to next arg to get extension name */
126  i++;
127  if (i < argc) {
128  nifu = atoi(argv[i]);
129  if (nifu == 0 || nifu > kMuseNumIFUs) {
130  PRINT_USAGE(6);
131  }
132  } else {
133  PRINT_USAGE(5);
134  }
135  } else if (strncmp(argv[i], "-r", 3) == 0) {
136  residuals = CPL_TRUE;
137  } else if (strncmp(argv[i], "-", 1) == 0) { /* unallowed options */
138  PRINT_USAGE(9);
139  } else {
140  if (tcname && trname) {
141  break; /* we have the possible names, skip the rest */
142  }
143  if (!tcname) {
144  tcname = argv[i];
145  } else {
146  trname = argv[i];
147  }
148  }
149  }
150 
151  int iextc = 1,
152  iextr = 1;
153  if (nifu) {
154  iextc = muse_utils_get_extension_for_ifu(tcname, nifu);
155  iextr = muse_utils_get_extension_for_ifu(trname, nifu);
156  }
157  cpl_table *ctable = cpl_table_load(tcname, iextc, 1),
158  *rtable = cpl_table_load(trname, iextr, 1);
159  if (!ctable || !rtable) {
160  cpl_table_delete(ctable);
161  cpl_table_delete(rtable);
162  PRINT_USAGE(10);
163  }
164 
165  /* get extension names for the output messages */
166  char *extnamer = NULL,
167  *extnamec = NULL;
168  cpl_propertylist *header = cpl_propertylist_load(tcname, iextc);
169  if (cpl_propertylist_has(header, "EXTNAME")) {
170  extnamec = cpl_sprintf("[%s]", muse_pfits_get_extname(header));
171  }
172  cpl_propertylist_delete(header);
173  header = cpl_propertylist_load(trname, iextr);
174  if (cpl_propertylist_has(header, "EXTNAME")) {
175  extnamer = cpl_sprintf("[%s]", muse_pfits_get_extname(header));
176  }
177  cpl_propertylist_delete(header);
178 
179  /* report success of loading the tables */
180  printf("MUSE WAVECAL_TABLE table \"%s%s\", contains %"CPL_SIZE_FORMAT" rows\n",
181  tcname, extnamec ? extnamec : "", cpl_table_get_nrow(ctable));
182  printf("MUSE WAVECAL_RESIDUALS table \"%s%s\", contains %"CPL_SIZE_FORMAT
183  " rows\n", trname, extnamer ? extnamer : "", cpl_table_get_nrow(rtable));
184 
185  cpl_error_code rc = muse_wave_plot_column(ctable, rtable, nifu, slice, column,
186  iteration, residuals);
187  switch (rc) {
188  case CPL_ERROR_NONE:
189  rc = 0;
190  break;
191  case CPL_ERROR_ILLEGAL_INPUT:
192  fprintf(stderr, "%s: one of the tables \"%s%s\"/\"%s%s\" does not seem to "
193  "contain valid MUSE information!\n", argv[0],
194  tcname, extnamec ? extnamec : "", trname, extnamer ? extnamer : "");
195  rc = 11;
196  break;
197  case CPL_ERROR_DATA_NOT_FOUND:
198  if (iteration > 0) {
199  fprintf(stderr, "%s: \"%s%s\" does not seem to contain data for slice %d "
200  "and iteration %d!\n", argv[0], trname, extnamer ? extnamer : "",
201  slice, iteration);
202  } else {
203  fprintf(stderr, "%s: \"%s%s\" does not seem to contain data for slice %d "
204  "and the last iteration!\n", argv[0], trname,
205  extnamer ? extnamer : "", slice);
206  }
207  rc = 12;
208  break;
209  case CPL_ERROR_ACCESS_OUT_OF_RANGE:
210  fprintf(stderr, "%s: the requested slice number (%d) is invalid!\n",
211  argv[0], slice);
212  rc = 13;
213  break;
214  case CPL_ERROR_UNSUPPORTED_MODE:
215  fprintf(stderr, "%s: your platform does not seem to support pipes "
216  "[popen()/pclose()]!\n", argv[0]);
217  rc = 20;
218  break;
219  case CPL_ERROR_ASSIGNING_STREAM:
220  fprintf(stderr, "%s: could not open gnuplot (this tool uses it for "
221  "plotting)!\n", argv[0]);
222  rc = 21;
223  break;
224  default:
225  rc = 50;
226  } /* switch */
227  cpl_free(extnamec);
228  cpl_free(extnamer);
229 
230  cpl_table_delete(ctable);
231  cpl_table_delete(rtable);
232  cpl_end();
233  return rc;
234 }
235 
const char * muse_pfits_get_extname(const cpl_propertylist *aHeaders)
find out the extension name
Definition: muse_pfits.c:205
int muse_utils_get_extension_for_ifu(const char *aFilename, unsigned char aIFU)
Return extension number that corresponds to this IFU/channel number.
Definition: muse_utils.c:118
cpl_error_code muse_wave_plot_column(cpl_table *aCTable, cpl_table *aRTable, unsigned char aIFU, unsigned short aSlice, unsigned int aColumn, unsigned int aIter, cpl_boolean aPlotRes)
Plot wavelength calibration polynomial and data or residuals using gnuplot.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.