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 #define PRINT_USAGE(rc) \
00026 fprintf(stderr, "Usage: %s INFILE OUTFILE\n", argv[0]); \
00027 cpl_end(); return (rc);
00028
00029
00033
00034 int main(int argc, char **argv)
00035 {
00036 cpl_init(CPL_INIT_DEFAULT);
00037 muse_processing_recipeinfo(NULL);
00038
00039 if (argc <= 2) {
00040
00041 PRINT_USAGE(1);
00042 }
00043
00044 cpl_table *table = cpl_table_load(argv[1], 3, 1);
00045 if (!table) {
00046 PRINT_USAGE(10);
00047 }
00048 int nrow = cpl_table_get_nrow(table);
00049 cpl_msg_info(__func__, "read %d columns from \"%s\"", nrow, argv[1]);
00050
00051
00052 cpl_table_add_scalar(table, "xdet", 1);
00053 cpl_table_add_scalar(table, "ydet", 1);
00054
00055 cpl_table_new_column(table, "euro3d", CPL_TYPE_INT);
00056 int n, nhot = 0, ndark = 0, ntrap = 0;
00057 for (n = 0; n < nrow; n++) {
00058
00059 char type = cpl_table_get_string(table, "type", n)[0];
00060 switch (type) {
00061 case 'H':
00062 cpl_table_set(table, "euro3d", n, EURO3D_HOTPIXEL);
00063 nhot++;
00064 break;
00065 case 'D':
00066 cpl_table_set(table, "euro3d", n, EURO3D_DARKPIXEL);
00067 ndark++;
00068 break;
00069 case 'T':
00070 cpl_table_set(table, "euro3d", n, EURO3D_MUSE_TRAP);
00071 ntrap++;
00072 break;
00073 }
00074 }
00075 #if 0
00076 cpl_table_dump(table, 0, 100000, stdout);
00077 fflush(stdout);
00078 #endif
00079 cpl_msg_info(__func__, "%d hot, %d dark, and %d trap pixel%s",
00080 nhot, ndark, ntrap, nhot+ndark+ntrap != 1 ? "s" : "");
00081
00082
00083 muse_image *image = muse_image_new();
00084 image->data = cpl_image_load(argv[1], CPL_TYPE_INT, 0, 1);
00085 int nx = cpl_image_get_size_x(image->data),
00086 ny = cpl_image_get_size_y(image->data);
00087
00088 image->dq = cpl_image_new(nx, ny, CPL_TYPE_INT);
00089
00090 for (n = 0; n < nrow; n++) {
00091 int i = cpl_table_get_int(table, "xdet", n, NULL),
00092 j = cpl_table_get_int(table, "ydet", n, NULL),
00093 dq = cpl_table_get_int(table, "euro3d", n, NULL),
00094 err, val = cpl_image_get(image->dq, i, j, &err);
00095 cpl_image_set(image->dq, i, j, dq | val);
00096 }
00097
00098
00099 image->header = cpl_propertylist_load(argv[1], 1);
00100 muse_image *trimmed = muse_quadrants_trim_image(image);
00101 cpl_image_save(trimmed->dq, argv[2], CPL_TYPE_INT, NULL, CPL_IO_CREATE);
00102 cpl_msg_info(__func__, "saved to \"%s\"", argv[2]);
00103
00104 muse_image_delete(trimmed);
00105 cpl_table_delete(table);
00106 muse_image_delete(image);
00107 cpl_end();
00108 return 0;
00109 }