MUSE Pipeline Reference Manual  0.18.5
muse_wave_plot_residuals.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 /*----------------------------------------------------------------------------*/
64 /*----------------------------------------------------------------------------*/
65 
68 #define PRINT_USAGE(rc) \
69  fprintf(stderr, "Usage: %s [ -s slice ] [ -i iteration ] [ -l ] " \
70  "[ -c c1 c2 ] WAVECAL_RESIDUALS\n", argv[0]); \
71  cpl_end(); return (rc);
72 
73 int main(int argc, char **argv)
74 {
75  cpl_init(CPL_INIT_DEFAULT);
76 
77  if (argc <= 1) {
78  /* filename is needed at least */
79  PRINT_USAGE(1);
80  }
81 
82  char *tname = NULL;
83  unsigned short slice = 0;
84  unsigned int iteration = 0;
85  cpl_boolean lambda = CPL_FALSE;
86  cpl_vector *cuts = NULL;
87 
88  /* argument processing */
89  int i;
90  for (i = 1; i < argc; i++) {
91  if (strncmp(argv[i], "-s", 3) == 0) {
92  /* skip to next arg to get slice number */
93  i++;
94  if (i < argc) {
95  slice = atol(argv[i]);
96  } else {
97  PRINT_USAGE(2);
98  }
99  } else if (strncmp(argv[i], "-i", 3) == 0) {
100  /* skip to next arg to get iteration value */
101  i++;
102  if (i < argc) {
103  iteration = atol(argv[i]);
104  } else {
105  cpl_vector_delete(cuts);
106  PRINT_USAGE(3);
107  }
108  } else if (strncmp(argv[i], "-c", 3) == 0) {
109  cuts = cpl_vector_new(2);
110  /* skip to next arg to get iteration value */
111  i++;
112  if (i + 1 < argc) {
113  cpl_vector_set(cuts, 0, atof(argv[i++]));
114  cpl_vector_set(cuts, 1, atof(argv[i]));
115  } else {
116  PRINT_USAGE(3);
117  }
118  } else if (strncmp(argv[i], "-l", 3) == 0) {
119  lambda = CPL_TRUE;
120  } else if (strncmp(argv[i], "-", 1) == 0) { /* unallowed options */
121  PRINT_USAGE(9);
122  } else {
123  tname = argv[i];
124  break; /* we have the required name, skip the rest */
125  }
126  }
127 
128  cpl_table *table = cpl_table_load(tname, 1, 0);
129  if (!table) {
130  PRINT_USAGE(10);
131  }
132 
133  printf("MUSE WAVECAL_RESIDUALS table \"%s\", contains %"CPL_SIZE_FORMAT
134  " rows\n", tname, cpl_table_get_nrow(table));
135  cpl_error_code rc = muse_wave_plot_residuals(table, slice, iteration, lambda,
136  cuts);
137  cpl_vector_delete(cuts);
138  switch (rc) {
139  case CPL_ERROR_NONE:
140  rc = 0;
141  break;
142  case CPL_ERROR_ILLEGAL_INPUT:
143  fprintf(stderr, "%s: \"%s\" does not seem to contain a MUSE wavelength "
144  "calibration residuals table!\n", argv[0], tname);
145  rc = 11;
146  break;
147  case CPL_ERROR_DATA_NOT_FOUND:
148  if (iteration > 0) {
149  fprintf(stderr, "%s: \"%s\" does not seem to contain data for slice %d "
150  "and iteration %d!\n", argv[0], tname, slice, iteration);
151  } else {
152  fprintf(stderr, "%s: \"%s\" does not seem to contain data for slice %d "
153  "and the last iteration!\n", argv[0], tname, slice);
154  }
155  rc = 12;
156  break;
157  case CPL_ERROR_UNSUPPORTED_MODE:
158  fprintf(stderr, "%s: your platform does not seem to support pipes "
159  "[popen()/pclose()]!\n", argv[0]);
160  rc = 20;
161  break;
162  case CPL_ERROR_ASSIGNING_STREAM:
163  fprintf(stderr, "%s: could not open gnuplot (this tool uses it for "
164  "plotting)!\n", argv[0]);
165  rc = 21;
166  break;
167  default:
168  rc = 50;
169  } /* switch */
170 
171  cpl_table_delete(table);
172  cpl_end();
173  return rc;
174 }
175 
cpl_error_code muse_wave_plot_residuals(cpl_table *aTable, const unsigned short aSlice, unsigned int aIter, cpl_boolean aPlotLambda, cpl_vector *aCuts)
Fancy plotting of wavelength calibration residuals (color coded over x/y-position) using gnuplot...