MUSE Pipeline Reference Manual  2.1.1
muse_trace_plot_widths.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-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 /*----------------------------------------------------------------------------*/
62 /*----------------------------------------------------------------------------*/
63 
66 #define PRINT_USAGE(rc) \
67  fprintf(stderr, "Usage: %s [ -s1 first_slice ] [ -s2 last_slice ] " \
68  "[ -n nifu ] TRACE_SAMPLES\n", argv[0]); \
69  cpl_end(); return (rc);
70 
71 int main(int argc, char **argv)
72 {
73  cpl_init(CPL_INIT_DEFAULT);
75 
76  if (argc <= 1) {
77  /* filename is needed at least */
78  PRINT_USAGE(1);
79  }
80 
81  char *tsname = NULL; /* samples table */
82  short slice1 = 1,
83  slice2 = 48;
84  unsigned char nifu = 0; /* IFU number to load */
85 
86  /* argument processing */
87  int i;
88  for (i = 1; i < argc; i++) {
89  if (strncmp(argv[i], "-s1", 4) == 0) {
90  /* skip to next arg to first slice number */
91  i++;
92  if (i < argc) {
93  slice1 = atoi(argv[i]);
94  } else {
95  PRINT_USAGE(2);
96  }
97  } else if (strncmp(argv[i], "-s2", 4) == 0) {
98  /* skip to next arg to last slice number */
99  i++;
100  if (i < argc) {
101  slice2 = atoi(argv[i]);
102  } else {
103  PRINT_USAGE(3);
104  }
105  } else if (strncmp(argv[i], "-n", 3) == 0) {
106  /* skip to next arg to get extension name */
107  i++;
108  if (i < argc) {
109  nifu = atoi(argv[i]);
110  if (nifu == 0 || nifu > kMuseNumIFUs) {
111  PRINT_USAGE(5);
112  }
113  } else {
114  PRINT_USAGE(4);
115  }
116  } else if (strncmp(argv[i], "-", 1) == 0) { /* unallowed options */
117  PRINT_USAGE(9);
118  } else {
119  if (tsname) {
120  break; /* we have the possible names, skip the rest */
121  }
122  tsname = argv[i]; /* set the name for the samples table */
123  }
124  } /* for i (all arguments) */
125 
126  int iext = 1;
127  if (nifu) {
128  iext = muse_utils_get_extension_for_ifu(tsname, nifu);
129  }
130  cpl_table *ts = cpl_table_load(tsname, iext, 1);
131  if (!ts) {
132  fprintf(stderr, "%s: %s: %s\n", argv[0], tsname, cpl_error_get_message());
133  /* fail, this is mandatory */
134  PRINT_USAGE(10);
135  }
136  cpl_propertylist *header = cpl_propertylist_load(tsname, iext);
137  char *extname = NULL;
138  if (cpl_propertylist_has(header, "EXTNAME")) {
139  extname = cpl_sprintf("[%s]", muse_pfits_get_extname(header));
140  }
141  printf("MUSE TRACE_SAMPLES table \"%s%s\", contains %"CPL_SIZE_FORMAT" rows\n",
142  tsname, extname ? extname : "", cpl_table_get_nrow(ts));
143  extname = NULL;
144  cpl_propertylist_delete(header);
145 
146  cpl_error_code rc = muse_trace_plot_widths(ts, slice1, slice2, nifu);
147  switch (rc) {
148  case CPL_ERROR_NONE:
149  rc = 0;
150  break;
151  case CPL_ERROR_ILLEGAL_INPUT:
152  fprintf(stderr, "%s: \"%s%s\" does not seem to contain a MUSE tracing "
153  "samples table!\n", argv[0], tsname, extname ? extname : "");
154  rc = 11;
155  break;
156  case CPL_ERROR_FILE_NOT_CREATED:
157  /* use manipulated CPL error message to show the failing file name */
158  fprintf(stderr, "%s: %s (temporary file for plotting)\n",
159  argv[0], cpl_error_get_message());
160  rc = 12;
161  break;
162  case CPL_ERROR_UNSUPPORTED_MODE:
163  fprintf(stderr, "%s: your platform does not seem to support pipes "
164  "[popen()/pclose()]!\n", argv[0]);
165  rc = 20;
166  break;
167  case CPL_ERROR_ASSIGNING_STREAM:
168  fprintf(stderr, "%s: could not open gnuplot (this tool uses it for "
169  "plotting)!\n", argv[0]);
170  rc = 21;
171  break;
172  default:
173  rc = 50;
174  } /* switch */
175  cpl_free(extname);
176 
177  cpl_table_delete(ts);
178  cpl_end();
179  return rc;
180 }
181 
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
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.
cpl_error_code muse_trace_plot_widths(cpl_table *aSamples, unsigned short aSlice1, unsigned short aSlice2, unsigned char aIFU)
Plotting the width from trace sample points using gnuplot.