00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <muse.h>
00023 #include <string.h>
00024
00025
00067
00068
00071 #define PRINT_USAGE(rc) \
00072 fprintf(stderr, "Usage: %s [ -n nifu ] [ -s slice ] [ -i iteration ] [ -l ] "\
00073 "[ -c c1 c2 ] WAVECAL_RESIDUALS\n", argv[0]); \
00074 cpl_end(); return (rc);
00075
00076 int main(int argc, char **argv)
00077 {
00078 cpl_init(CPL_INIT_DEFAULT);
00079 muse_processing_recipeinfo(NULL);
00080
00081 if (argc <= 1) {
00082
00083 PRINT_USAGE(1);
00084 }
00085
00086 char *tname = NULL;
00087 unsigned char nifu = 0;
00088 unsigned short slice = 0;
00089 unsigned int iteration = 0;
00090 cpl_boolean lambda = CPL_FALSE;
00091 cpl_vector *cuts = NULL;
00092
00093
00094 int i;
00095 for (i = 1; i < argc; i++) {
00096 if (strncmp(argv[i], "-s", 3) == 0) {
00097
00098 i++;
00099 if (i < argc) {
00100 slice = atol(argv[i]);
00101 } else {
00102 PRINT_USAGE(2);
00103 }
00104 } else if (strncmp(argv[i], "-i", 3) == 0) {
00105
00106 i++;
00107 if (i < argc) {
00108 iteration = atol(argv[i]);
00109 } else {
00110 cpl_vector_delete(cuts);
00111 PRINT_USAGE(3);
00112 }
00113 } else if (strncmp(argv[i], "-c", 3) == 0) {
00114 cuts = cpl_vector_new(2);
00115
00116 i++;
00117 if (i + 1 < argc) {
00118 cpl_vector_set(cuts, 0, atof(argv[i++]));
00119 cpl_vector_set(cuts, 1, atof(argv[i]));
00120 } else {
00121 PRINT_USAGE(4);
00122 }
00123 } else if (strncmp(argv[i], "-n", 3) == 0) {
00124
00125 i++;
00126 if (i < argc) {
00127 nifu = atoi(argv[i]);
00128 if (nifu == 0 || nifu > kMuseNumIFUs) {
00129 PRINT_USAGE(6);
00130 }
00131 } else {
00132 PRINT_USAGE(5);
00133 }
00134 } else if (strncmp(argv[i], "-l", 3) == 0) {
00135 lambda = CPL_TRUE;
00136 } else if (strncmp(argv[i], "-", 1) == 0) {
00137 PRINT_USAGE(9);
00138 } else {
00139 tname = argv[i];
00140 break;
00141 }
00142 }
00143
00144 int iext = 1;
00145 if (nifu) {
00146 iext = muse_utils_get_extension_for_ifu(tname, nifu);
00147 }
00148 cpl_table *table = cpl_table_load(tname, iext, 1);
00149 if (!table) {
00150 PRINT_USAGE(10);
00151 }
00152
00153 char *extname = NULL;
00154 cpl_propertylist *header = cpl_propertylist_load(tname, iext);
00155 if (cpl_propertylist_has(header, "EXTNAME")) {
00156 extname = cpl_sprintf("[%s]", muse_pfits_get_extname(header));
00157 }
00158 cpl_propertylist_delete(header);
00159
00160 printf("MUSE WAVECAL_RESIDUALS table \"%s%s\", contains %"CPL_SIZE_FORMAT
00161 " rows\n", tname, extname ? extname : "", cpl_table_get_nrow(table));
00162 cpl_error_code rc = muse_wave_plot_residuals(table, nifu, slice, iteration,
00163 lambda, cuts);
00164 cpl_vector_delete(cuts);
00165 switch (rc) {
00166 case CPL_ERROR_NONE:
00167 rc = 0;
00168 break;
00169 case CPL_ERROR_ILLEGAL_INPUT:
00170 fprintf(stderr, "%s: \"%s%s\" does not seem to contain a MUSE wavelength "
00171 "calibration residuals table!\n", argv[0], tname,
00172 extname ? extname : "");
00173 rc = 11;
00174 break;
00175 case CPL_ERROR_DATA_NOT_FOUND:
00176 if (iteration > 0) {
00177 fprintf(stderr, "%s: \"%s%s\" does not seem to contain data for slice %d "
00178 "and iteration %d!\n", argv[0], tname, extname ? extname : "",
00179 slice, iteration);
00180 } else {
00181 fprintf(stderr, "%s: \"%s%s\" does not seem to contain data for slice %d "
00182 "and the last iteration!\n", argv[0], tname,
00183 extname ? extname : "", slice);
00184 }
00185 rc = 12;
00186 break;
00187 case CPL_ERROR_UNSUPPORTED_MODE:
00188 fprintf(stderr, "%s: your platform does not seem to support pipes "
00189 "[popen()/pclose()]!\n", argv[0]);
00190 rc = 20;
00191 break;
00192 case CPL_ERROR_ASSIGNING_STREAM:
00193 fprintf(stderr, "%s: could not open gnuplot (this tool uses it for "
00194 "plotting)!\n", argv[0]);
00195 rc = 21;
00196 break;
00197 default:
00198 rc = 50;
00199 }
00200 cpl_free(extname);
00201
00202 cpl_table_delete(table);
00203 cpl_end();
00204 return rc;
00205 }
00206