MUSE Pipeline Reference Manual  0.18.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-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 /*----------------------------------------------------------------------------*/
67 /*----------------------------------------------------------------------------*/
68 
71 #define PRINT_USAGE(rc) \
72  fprintf(stderr, "Usage: %s [ -s slice ] [ -i iteration ] [ -c column ] [-r]" \
73  " WAVECAL_TABLE WAVECAL_RESIDUALS\n", argv[0]); \
74  cpl_end(); return (rc);
75 
76 int main(int argc, char **argv)
77 {
78  cpl_init(CPL_INIT_DEFAULT);
79 
80  if (argc <= 1) {
81  /* filename is needed at least */
82  PRINT_USAGE(1);
83  }
84 
85  char *tcname = NULL,
86  *trname = NULL;
87  unsigned short slice = 24;
88  unsigned int iteration = 0,
89  column = 0; /* default to central column of slice */
90  cpl_boolean residuals = CPL_FALSE;
91 
92  /* argument processing */
93  int i;
94  for (i = 1; i < argc; i++) {
95  if (strncmp(argv[i], "-s", 3) == 0) {
96  /* skip to next arg to get slice number */
97  i++;
98  if (i < argc) {
99  slice = atol(argv[i]);
100  } else {
101  PRINT_USAGE(2);
102  }
103  } else if (strncmp(argv[i], "-i", 3) == 0) {
104  /* skip to next arg to get iteration value */
105  i++;
106  if (i < argc) {
107  iteration = atol(argv[i]);
108  } else {
109  PRINT_USAGE(3);
110  }
111  } else if (strncmp(argv[i], "-c", 3) == 0) {
112  /* skip to next arg to get iteration value */
113  i++;
114  if (i < argc) {
115  column = atol(argv[i]);
116  } else {
117  PRINT_USAGE(4);
118  }
119  } else if (strncmp(argv[i], "-r", 3) == 0) {
120  residuals = CPL_TRUE;
121  } else if (strncmp(argv[i], "-", 1) == 0) { /* unallowed options */
122  PRINT_USAGE(9);
123  } else {
124  if (tcname && trname) {
125  break; /* we have the possible names, skip the rest */
126  }
127  if (!tcname) {
128  tcname = argv[i];
129  } else {
130  trname = argv[i];
131  }
132  }
133  }
134 
135  cpl_table *ctable = cpl_table_load(tcname, 1, 0),
136  *rtable = cpl_table_load(trname, 1, 0);
137  if (!ctable || !rtable) {
138  cpl_table_delete(ctable);
139  cpl_table_delete(rtable);
140  PRINT_USAGE(10);
141  }
142 
143  printf("MUSE WAVECAL_TABLE table \"%s\", contains %"CPL_SIZE_FORMAT" rows\n",
144  tcname, cpl_table_get_nrow(ctable));
145  printf("MUSE WAVECAL_RESIDUALS table \"%s\", contains %"CPL_SIZE_FORMAT
146  " rows\n", trname, cpl_table_get_nrow(rtable));
147  cpl_error_code rc = muse_wave_plot_column(ctable, rtable, slice, column,
148  iteration, residuals);
149  switch (rc) {
150  case CPL_ERROR_NONE:
151  rc = 0;
152  break;
153  case CPL_ERROR_ILLEGAL_INPUT:
154  fprintf(stderr, "%s: one of the tables \"%s\"/\"%s\" does not seem to "
155  "contain valid MUSE information!\n", argv[0], tcname, trname);
156  rc = 11;
157  break;
158  case CPL_ERROR_DATA_NOT_FOUND:
159  if (iteration > 0) {
160  fprintf(stderr, "%s: \"%s\" does not seem to contain data for slice %d "
161  "and iteration %d!\n", argv[0], trname, slice, iteration);
162  } else {
163  fprintf(stderr, "%s: \"%s\" does not seem to contain data for slice %d "
164  "and the last iteration!\n", argv[0], trname, slice);
165  }
166  rc = 12;
167  break;
168  case CPL_ERROR_ACCESS_OUT_OF_RANGE:
169  fprintf(stderr, "%s: the requested slice number (%d) is invalid!\n",
170  argv[0], slice);
171  rc = 13;
172  break;
173  case CPL_ERROR_UNSUPPORTED_MODE:
174  fprintf(stderr, "%s: your platform does not seem to support pipes "
175  "[popen()/pclose()]!\n", argv[0]);
176  rc = 20;
177  break;
178  case CPL_ERROR_ASSIGNING_STREAM:
179  fprintf(stderr, "%s: could not open gnuplot (this tool uses it for "
180  "plotting)!\n", argv[0]);
181  rc = 21;
182  break;
183  default:
184  rc = 50;
185  } /* switch */
186 
187  cpl_table_delete(ctable);
188  cpl_table_delete(rtable);
189  cpl_end();
190  return rc;
191 }
192 
cpl_error_code muse_wave_plot_column(cpl_table *aCTable, cpl_table *aRTable, const unsigned short aSlice, unsigned int aColumn, unsigned int aIter, cpl_boolean aPlotRes)
Plot wavelength calibration polynomial and data or residuals using gnuplot.