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