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 [ -s1 first_slice ] [ -s2 last_slice ] " \
00076 "[ -n nifu ] TRACE_SAMPLES [ TRACE_TABLE ] [ MASTER_FLAT ]\n", \
00077 argv[0]); \
00078 cpl_end(); return (rc);
00079
00080 int main(int argc, char **argv)
00081 {
00082 cpl_init(CPL_INIT_DEFAULT);
00083 muse_processing_recipeinfo(NULL);
00084
00085 if (argc <= 1) {
00086
00087 PRINT_USAGE(1);
00088 }
00089
00090 char *tsname = NULL,
00091 *ttname = NULL,
00092 *iname = NULL;
00093 short slice1 = 24,
00094 slice2 = 25;
00095 unsigned char nifu = 0;
00096
00097
00098 int i;
00099 for (i = 1; i < argc; i++) {
00100 if (strncmp(argv[i], "-s1", 4) == 0) {
00101
00102 i++;
00103 if (i < argc) {
00104 slice1 = atoi(argv[i]);
00105 } else {
00106 PRINT_USAGE(2);
00107 }
00108 } else if (strncmp(argv[i], "-s2", 4) == 0) {
00109
00110 i++;
00111 if (i < argc) {
00112 slice2 = atoi(argv[i]);
00113 } else {
00114 PRINT_USAGE(3);
00115 }
00116 } else if (strncmp(argv[i], "-n", 3) == 0) {
00117
00118 i++;
00119 if (i < argc) {
00120 nifu = atoi(argv[i]);
00121 if (nifu == 0 || nifu > kMuseNumIFUs) {
00122 PRINT_USAGE(5);
00123 }
00124 } else {
00125 PRINT_USAGE(4);
00126 }
00127 } else if (strncmp(argv[i], "-", 1) == 0) {
00128 PRINT_USAGE(9);
00129 } else {
00130 if (tsname && ttname && iname) {
00131 break;
00132 }
00133 if (!tsname) {
00134 tsname = argv[i];
00135 } else if (!ttname) {
00136 ttname = argv[i];
00137 } else {
00138 iname = argv[i] ;
00139 }
00140 }
00141 }
00142
00143 int iext = 1;
00144 if (nifu) {
00145 iext = muse_utils_get_extension_for_ifu(tsname, nifu);
00146 }
00147 cpl_table *ts = cpl_table_load(tsname, iext, 1);
00148 if (!ts) {
00149
00150 PRINT_USAGE(10);
00151 }
00152 cpl_propertylist *header = cpl_propertylist_load(tsname, iext);
00153 char *extname = NULL;
00154 if (cpl_propertylist_has(header, "EXTNAME")) {
00155 extname = cpl_sprintf("[%s]", muse_pfits_get_extname(header));
00156 }
00157 printf("MUSE TRACE_SAMPLES table \"%s%s\", contains %"CPL_SIZE_FORMAT" rows\n",
00158 tsname, extname ? extname : "", cpl_table_get_nrow(ts));
00159 cpl_free(extname);
00160 extname = NULL;
00161 cpl_propertylist_delete(header);
00162
00163 cpl_table *tt = NULL;
00164 if (ttname) {
00165 iext = 1;
00166 if (nifu) {
00167 iext = muse_utils_get_extension_for_ifu(ttname, nifu);
00168 }
00169 tt = cpl_table_load(ttname, iext, 1);
00170 header = cpl_propertylist_load(ttname, iext);
00171 if (cpl_propertylist_has(header, "EXTNAME")) {
00172 extname = cpl_sprintf("[%s]", muse_pfits_get_extname(header));
00173 }
00174 cpl_propertylist_delete(header);
00175
00176
00177 if (!tt) {
00178 fprintf(stderr, "%s: loading the TRACE_TABLE \"%s%s\" failed: %s\n",
00179 argv[0], ttname, extname ? extname : "", cpl_error_get_message());
00180 } else {
00181 printf("MUSE TRACE table \"%s%s\", contains %"CPL_SIZE_FORMAT" rows\n",
00182 ttname, extname ? extname : "", cpl_table_get_nrow(tt));
00183 }
00184 cpl_free(extname);
00185 extname = NULL;
00186 }
00187 muse_image *image = NULL;
00188 if (iname) {
00189 if (nifu) {
00190 image = muse_image_load_from_extensions(iname, nifu);
00191 }
00192 if (!image) {
00193 image = muse_image_load(iname);
00194 }
00195
00196
00197 if (image) {
00198 extname = cpl_sprintf("[%s]", muse_pfits_get_extname(image->header));
00199 printf("MUSE MASTER_FLAT image \"%s%s\", has size "
00200 "%"CPL_SIZE_FORMAT"x%"CPL_SIZE_FORMAT"\n", iname, extname,
00201 cpl_image_get_size_x(image->data), cpl_image_get_size_y(image->data));
00202 cpl_free(extname);
00203 extname = NULL;
00204 }
00205 }
00206
00207 cpl_error_code rc = muse_trace_plot_samples(ts, tt, slice1, slice2, nifu,
00208 image);
00209 switch (rc) {
00210 case CPL_ERROR_NONE:
00211 rc = 0;
00212 break;
00213 case CPL_ERROR_ILLEGAL_INPUT:
00214 fprintf(stderr, "%s: \"%s\" does not seem to contain a MUSE tracing "
00215 "samples table!\n", argv[0], tsname);
00216 rc = 11;
00217 break;
00218 case CPL_ERROR_FILE_NOT_CREATED:
00219
00220 fprintf(stderr, "%s: %s (temporary file for plotting)\n",
00221 argv[0], cpl_error_get_message());
00222 rc = 12;
00223 break;
00224 case CPL_ERROR_UNSUPPORTED_MODE:
00225 fprintf(stderr, "%s: your platform does not seem to support pipes "
00226 "[popen()/pclose()]!\n", argv[0]);
00227 rc = 20;
00228 break;
00229 case CPL_ERROR_ASSIGNING_STREAM:
00230 fprintf(stderr, "%s: could not open gnuplot (this tool uses it for "
00231 "plotting)!\n", argv[0]);
00232 rc = 21;
00233 break;
00234 default:
00235 rc = 50;
00236 }
00237
00238 cpl_table_delete(ts);
00239 cpl_table_delete(tt);
00240 muse_image_delete(image);
00241 cpl_end();
00242 return rc;
00243 }
00244