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