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
00070
00071
00074 #define PRINT_USAGE(rc) \
00075 fprintf(stderr, "Usage: %s [ -n nifu ] [ -s slice ] [ -i iteration ] " \
00076 "[ -c column ] [ -r ] WAVECAL_TABLE WAVECAL_RESIDUALS\n", argv[0]); \
00077 cpl_end(); return (rc);
00078
00079 int main(int argc, char **argv)
00080 {
00081 cpl_init(CPL_INIT_DEFAULT);
00082 muse_processing_recipeinfo(NULL);
00083
00084 if (argc <= 1) {
00085
00086 PRINT_USAGE(1);
00087 }
00088
00089 char *tcname = NULL,
00090 *trname = NULL;
00091 unsigned short slice = 24;
00092 unsigned char nifu = 0;
00093 unsigned int iteration = 0,
00094 column = 0;
00095 cpl_boolean residuals = CPL_FALSE;
00096
00097
00098 int i;
00099 for (i = 1; i < argc; i++) {
00100 if (strncmp(argv[i], "-s", 3) == 0) {
00101
00102 i++;
00103 if (i < argc) {
00104 slice = atol(argv[i]);
00105 } else {
00106 PRINT_USAGE(2);
00107 }
00108 } else if (strncmp(argv[i], "-i", 3) == 0) {
00109
00110 i++;
00111 if (i < argc) {
00112 iteration = atol(argv[i]);
00113 } else {
00114 PRINT_USAGE(3);
00115 }
00116 } else if (strncmp(argv[i], "-c", 3) == 0) {
00117
00118 i++;
00119 if (i < argc) {
00120 column = atol(argv[i]);
00121 } else {
00122 PRINT_USAGE(4);
00123 }
00124 } else if (strncmp(argv[i], "-n", 3) == 0) {
00125
00126 i++;
00127 if (i < argc) {
00128 nifu = atoi(argv[i]);
00129 if (nifu == 0 || nifu > kMuseNumIFUs) {
00130 PRINT_USAGE(6);
00131 }
00132 } else {
00133 PRINT_USAGE(5);
00134 }
00135 } else if (strncmp(argv[i], "-r", 3) == 0) {
00136 residuals = CPL_TRUE;
00137 } else if (strncmp(argv[i], "-", 1) == 0) {
00138 PRINT_USAGE(9);
00139 } else {
00140 if (tcname && trname) {
00141 break;
00142 }
00143 if (!tcname) {
00144 tcname = argv[i];
00145 } else {
00146 trname = argv[i];
00147 }
00148 }
00149 }
00150
00151 int iextc = 1,
00152 iextr = 1;
00153 if (nifu) {
00154 iextc = muse_utils_get_extension_for_ifu(tcname, nifu);
00155 iextr = muse_utils_get_extension_for_ifu(trname, nifu);
00156 }
00157 cpl_table *ctable = cpl_table_load(tcname, iextc, 1),
00158 *rtable = cpl_table_load(trname, iextr, 1);
00159 if (!ctable || !rtable) {
00160 cpl_table_delete(ctable);
00161 cpl_table_delete(rtable);
00162 PRINT_USAGE(10);
00163 }
00164
00165
00166 char *extnamer = NULL,
00167 *extnamec = NULL;
00168 cpl_propertylist *header = cpl_propertylist_load(tcname, iextc);
00169 if (cpl_propertylist_has(header, "EXTNAME")) {
00170 extnamec = cpl_sprintf("[%s]", muse_pfits_get_extname(header));
00171 }
00172 cpl_propertylist_delete(header);
00173 header = cpl_propertylist_load(trname, iextr);
00174 if (cpl_propertylist_has(header, "EXTNAME")) {
00175 extnamer = cpl_sprintf("[%s]", muse_pfits_get_extname(header));
00176 }
00177 cpl_propertylist_delete(header);
00178
00179
00180 printf("MUSE WAVECAL_TABLE table \"%s%s\", contains %"CPL_SIZE_FORMAT" rows\n",
00181 tcname, extnamec ? extnamec : "", cpl_table_get_nrow(ctable));
00182 printf("MUSE WAVECAL_RESIDUALS table \"%s%s\", contains %"CPL_SIZE_FORMAT
00183 " rows\n", trname, extnamer ? extnamer : "", cpl_table_get_nrow(rtable));
00184
00185 cpl_error_code rc = muse_wave_plot_column(ctable, rtable, nifu, slice, column,
00186 iteration, residuals);
00187 switch (rc) {
00188 case CPL_ERROR_NONE:
00189 rc = 0;
00190 break;
00191 case CPL_ERROR_ILLEGAL_INPUT:
00192 fprintf(stderr, "%s: one of the tables \"%s%s\"/\"%s%s\" does not seem to "
00193 "contain valid MUSE information!\n", argv[0],
00194 tcname, extnamec ? extnamec : "", trname, extnamer ? extnamer : "");
00195 rc = 11;
00196 break;
00197 case CPL_ERROR_DATA_NOT_FOUND:
00198 if (iteration > 0) {
00199 fprintf(stderr, "%s: \"%s%s\" does not seem to contain data for slice %d "
00200 "and iteration %d!\n", argv[0], trname, extnamer ? extnamer : "",
00201 slice, iteration);
00202 } else {
00203 fprintf(stderr, "%s: \"%s%s\" does not seem to contain data for slice %d "
00204 "and the last iteration!\n", argv[0], trname,
00205 extnamer ? extnamer : "", slice);
00206 }
00207 rc = 12;
00208 break;
00209 case CPL_ERROR_ACCESS_OUT_OF_RANGE:
00210 fprintf(stderr, "%s: the requested slice number (%d) is invalid!\n",
00211 argv[0], slice);
00212 rc = 13;
00213 break;
00214 case CPL_ERROR_UNSUPPORTED_MODE:
00215 fprintf(stderr, "%s: your platform does not seem to support pipes "
00216 "[popen()/pclose()]!\n", argv[0]);
00217 rc = 20;
00218 break;
00219 case CPL_ERROR_ASSIGNING_STREAM:
00220 fprintf(stderr, "%s: could not open gnuplot (this tool uses it for "
00221 "plotting)!\n", argv[0]);
00222 rc = 21;
00223 break;
00224 default:
00225 rc = 50;
00226 }
00227 cpl_free(extnamec);
00228 cpl_free(extnamer);
00229
00230 cpl_table_delete(ctable);
00231 cpl_table_delete(rtable);
00232 cpl_end();
00233 return rc;
00234 }
00235