MUSE Pipeline Reference Manual  2.1.1
muse_geo_smooth.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) 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 /*----------------------------------------------------------------------------*/
51 /*----------------------------------------------------------------------------*/
52 
55 #define PRINT_USAGE(rc) \
56  fprintf(stderr, "Usage: %s [ -s sigma ] [ -q ] GEOMETRY_TABLE FIXED_TABLE\n",\
57  argv[0]); \
58  cpl_end(); return (rc);
59 
60 int main(int argc, char **argv)
61 {
62  cpl_init(CPL_INIT_DEFAULT);
64  cpl_errorstate state = cpl_errorstate_get();
65 
66  if (argc <= 2) {
67  /* filename is needed at least */
68  PRINT_USAGE(1);
69  }
70 
71  /* argument processing */
72  char *tiname = NULL, /* input table */
73  *toname = NULL; /* output table */
74  double sigma = 3.; /* 3-sigma level rejection by default */
75  cpl_boolean qc = CPL_FALSE;
76  int i;
77  for (i = 1; i < argc; i++) {
78  if (strncmp(argv[i], "-s", 3) == 0) {
79  i++; /* skip to next arg (sigma level value) */
80  if (i < argc) {
81  sigma = atof(argv[i]);
82  } else {
83  PRINT_USAGE(2);
84  }
85  } else if (strncmp(argv[i], "-q", 3) == 0) {
86  qc = CPL_TRUE;
87  } else if (strncmp(argv[i], "-", 1) == 0) { /* unallowed options */
88  PRINT_USAGE(9);
89  } else {
90  if (tiname && toname) {
91  break; /* we have the required names, skip the rest */
92  }
93  if (!tiname) {
94  tiname = argv[i]; /* set the name for the input table */
95  } else {
96  toname = argv[i]; /* set the name for the output table */
97  }
98  }
99  } /* for i (all arguments) */
100  if (!tiname || !toname) {
101  PRINT_USAGE(1);
102  }
103  cpl_msg_set_level(CPL_MSG_DEBUG);
104 
105  muse_geo_table *gt = muse_geo_table_new(1, 1.);
106  cpl_table_delete(gt->table);
107  gt->table = cpl_table_load(tiname, 1, 1);
108  if (!gt->table) {
110  PRINT_USAGE(10);
111  }
112 
113  /* do the correction */
114  cpl_propertylist *pheader = cpl_propertylist_load(tiname, 0);
115  cpl_error_code rc = muse_geo_correct_slices(gt, pheader, sigma);
116  if (qc) {
117  muse_geo_qc_global(gt, pheader);
118  }
119  cpl_table_save(gt->table, pheader, NULL, toname, CPL_IO_CREATE);
120  cpl_propertylist_delete(pheader);
122 
123  if (rc != CPL_ERROR_NONE) {
124  cpl_msg_error(__func__, "Fixing the table failed: %s",
125  cpl_error_get_message());
126  } else if (!cpl_errorstate_is_equal(state)) {
127  cpl_msg_error(__func__, "An error occurred, unrelated to fixing the table: %s",
128  cpl_error_get_message());
129  rc = 50;
130  }
131  cpl_memory_dump();
132  cpl_end();
133  return rc;
134 }
135 
cpl_error_code muse_geo_correct_slices(muse_geo_table *aGeo, cpl_propertylist *aHeader, double aSigma)
Correct deviant slices in an existing MUSE geometry table.
Definition: muse_geo.c:3364
cpl_error_code muse_geo_qc_global(const muse_geo_table *aGeoTable, cpl_propertylist *aHeader)
Add the global QC parameters to the geometry table.
Definition: muse_geo.c:3508
cpl_table * table
The geometry table.
Definition: muse_geo.h:77
Structure definition of MUSE geometry table.
Definition: muse_geo.h:71
void muse_geo_table_delete(muse_geo_table *aGeo)
Deallocate memory associated to a geometry table object.
Definition: muse_geo.c:1237
muse_geo_table * muse_geo_table_new(cpl_size aNRows, double aScale)
Create a new MUSE geometry table.
Definition: muse_geo.c:1196
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.