MUSE Pipeline Reference Manual  1.0.2
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-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 /*----------------------------------------------------------------------------*/
58 /*----------------------------------------------------------------------------*/
59 
62 #define PRINT_USAGE(rc) \
63  fprintf(stderr, "Usage: %s [ -s1 first_slice ] [ -s2 last_slice ] " \
64  "TRACE_SAMPLES\n", argv[0]); \
65  cpl_end(); return (rc);
66 
67 int main(int argc, char **argv)
68 {
69  cpl_init(CPL_INIT_DEFAULT);
70 
71  if (argc <= 1) {
72  /* filename is needed at least */
73  PRINT_USAGE(1);
74  }
75 
76  char *tsname = NULL; /* samples table */
77  short slice1 = 1,
78  slice2 = 48;
79 
80  /* argument processing */
81  int i;
82  for (i = 1; i < argc; i++) {
83  if (strncmp(argv[i], "-s1", 4) == 0) {
84  /* skip to next arg to first slice number */
85  i++;
86  if (i < argc) {
87  slice1 = atoi(argv[i]);
88  } else {
89  PRINT_USAGE(2);
90  }
91  } else if (strncmp(argv[i], "-s2", 4) == 0) {
92  /* skip to next arg to last slice number */
93  i++;
94  if (i < argc) {
95  slice2 = atoi(argv[i]);
96  } else {
97  PRINT_USAGE(3);
98  }
99  } else if (strncmp(argv[i], "-", 1) == 0) { /* unallowed options */
100  PRINT_USAGE(9);
101  } else {
102  if (tsname) {
103  break; /* we have the possible names, skip the rest */
104  }
105  tsname = argv[i]; /* set the name for the samples table */
106  }
107  } /* for i (all arguments) */
108 
109  cpl_table *ts = cpl_table_load(tsname, 1, 0);
110  if (!ts) {
111  fprintf(stderr, "%s: %s: %s\n", argv[0], tsname, cpl_error_get_message());
112  /* fail, this is mandatory */
113  PRINT_USAGE(10);
114  }
115  printf("MUSE TRACE_SAMPLES table \"%s\", contains %"CPL_SIZE_FORMAT" rows\n",
116  tsname, cpl_table_get_nrow(ts));
117 
118  cpl_error_code rc = muse_trace_plot_widths(ts, slice1, slice2);
119  switch (rc) {
120  case CPL_ERROR_NONE:
121  rc = 0;
122  break;
123  case CPL_ERROR_ILLEGAL_INPUT:
124  fprintf(stderr, "%s: \"%s\" does not seem to contain a MUSE tracing "
125  "samples table!\n", argv[0], tsname);
126  rc = 11;
127  break;
128  case CPL_ERROR_FILE_NOT_CREATED:
129  /* use manipulated CPL error message to show the failing file name */
130  fprintf(stderr, "%s: %s (temporary file for plotting)\n",
131  argv[0], cpl_error_get_message());
132  rc = 12;
133  break;
134  case CPL_ERROR_UNSUPPORTED_MODE:
135  fprintf(stderr, "%s: your platform does not seem to support pipes "
136  "[popen()/pclose()]!\n", argv[0]);
137  rc = 20;
138  break;
139  case CPL_ERROR_ASSIGNING_STREAM:
140  fprintf(stderr, "%s: could not open gnuplot (this tool uses it for "
141  "plotting)!\n", argv[0]);
142  rc = 21;
143  break;
144  default:
145  rc = 50;
146  } /* switch */
147 
148  cpl_table_delete(ts);
149  cpl_end();
150  return rc;
151 }
152 
cpl_error_code muse_trace_plot_widths(cpl_table *aSamples, unsigned short aSlice1, unsigned short aSlice2)
Plotting the width from trace sample points using gnuplot.