/* * This method is used to implement the "hdu headings" subcommand. * It returns the table headings of the current FITS table as a * Tcl list. An error is returned if the current HDU is not a FITS * table. */ int RtdImage::getHDUHeadings(FitsIO* fits) { // return a list of table headings for the current FITS table char* type = (char*)fits->getHDUType(); if (!type || *type == 'i') return error("HDU is not a FITS table"); long nrows = 0; int ncols = 0; if (fits->getTableDims(nrows, ncols) != 0) return TCL_ERROR; reset_result(); for(int col = 1; col <= ncols; col++) { char* s = fits->getTableHead(col); if (!s) return TCL_ERROR; append_element(s); } return TCL_OK; }
/* * This method implements the main body of the hdu get subcommand. * If filename arg is not NULL, the contents of the current HDU are * written to the file as a local catalog. Otherwise, the contents * of the current HDU are returned as a Tcl list or rows. If the * entry arg is not null and a filename was specified, it specifies * the catalog config entry for the file's header, in Tcl list format * {{key value} {key value} ...}. */ int RtdImage::getHDU(FitsIO* fits, const char* filename, const char* entry) { const char* type = fits->getHDUType(); if (!type || *type == 'i') return error("HDU is not a FITS table"); long nrows = 0; int ncols = 0; if (fits->getTableDims(nrows, ncols) != 0) return TCL_ERROR; if (filename == NULL) { // return the contents of the table as a tcl list of rows reset_result(); for(int row = 1; row <= nrows; row++) { append_result(" {"); for(int col = 1; col <= ncols; col++) { char* s = fits->getTableValue(row, col); if (!s) return TCL_ERROR; append_element(s); } append_result("}"); } return TCL_OK; } // Otherwise write the contents of the table to a local catalog file ofstream os(filename); if (! os) return sys_error("can't open file: ", filename); // output the catalog header os << "QueryResult\n\n"; // PWD: locate special columns and their conversion factors (to degrees // from radians). int idcol = -1; int racol = -1; double rascale = 1.0; int deccol = -1; double decscale = 1.0; // output the catalog config entry, if there is one if (entry != NULL) { os << "# Config entry\n"; int nkeys = 0; char** keys = NULL; const char *p; const char *t; char buf[20]; if (Tcl_SplitList(interp_, (char*)entry, &nkeys, &keys) != TCL_OK) return TCL_ERROR; for(int i = 0; i < nkeys; i++) { int n = 0; char** v = NULL; if (Tcl_SplitList(interp_, keys[i], &n, &v) != TCL_OK) { Tcl_Free((char *)keys); return TCL_ERROR; } if (n != 2) { Tcl_Free((char *)keys); Tcl_Free((char *)v); return fmt_error("Invalid catalog config entry: '%s': Expected {key value}", keys[i]); } // PWD: record ra_col, dec_col and id_col columns. p = v[0]; while ( p && *p && *p == ' ' ) p++; // Trim leading blanks. if ( strncasecmp( p, "ra_col", 6 ) == 0 ) { sscanf( v[1], "%d", &racol ); // If these are radians we need to convert to degrees. sprintf( buf, "TUNIT%d", racol + 1 ); t = fits->get( buf ); while ( t && *t && *t == ' ' ) t++; // Trim leading blanks. if ( t && strncasecmp( t, "radian", 6 ) == 0 ) { rascale = r2d_; } } else if ( strncasecmp( p, "dec_col", 7 ) == 0 ) { sscanf( v[1], "%d", &deccol ); // If these are radians we need to convert to degrees. sprintf( buf, "TUNIT%d", deccol + 1 ); t = fits->get( buf ); while ( t && *t && *t == ' ' ) t++; // Trim leading blanks. if ( t && strncasecmp( t, "radian", 6 ) == 0 ) { decscale = r2d_; } } else if ( strncasecmp( p, "id_col", 6 ) == 0 ) { sscanf( v[1], "%d", &idcol ); } os << v[0] << ": " << v[1] << endl; Tcl_Free((char *)v); } // No id_col, so we fake an index at the end. if ( idcol == -1 ) { os << "id_col: " << ncols << endl; } Tcl_Free((char *)keys); os << "# End config entry\n\n"; } // PWD: add any comment cards so that context is preserved. const char *c; while ( ( c = fits->getComments() ) != NULL ) { os << "#C" << c << endl; } // output the column headings, if id_col is undefined then create a fake // column at the end (to keep ra_col & dec_col at current settings, which // are written out, could also be x_col and y_col to keep happy). int col; for(col = 1; col <= ncols; col++) { char* s = fits->getTableHead(col); if (!s) return TCL_ERROR; os << s; if (col < ncols) os << '\t'; } if ( idcol == -1 && entry != NULL ) { os << '\t' << "ID"; } os << "\n---\n"; // heading separator (dashed line) // output the data for(long row = 1; row <= nrows; row++) { for(col = 1; col <= ncols; col++) { char* s; if ( col == ( racol + 1 ) ) { s = fits->getTableValue(row, col, rascale); } else if ( col == ( deccol + 1 ) ) { s = fits->getTableValue(row, col, decscale); } else { s = fits->getTableValue(row, col, 1.0); } if (!s) return TCL_ERROR; os << s; if (col < ncols) os << '\t'; } if ( idcol == -1 && entry != NULL ) { os << '\t' << row; } os << endl; } return TCL_OK; }
int main(int argc, char **argv) { int i; ogg_int16_t int16_buffer[BUFFER_WIDTH * BUFFER_HEIGHT]; float float_buffer[BUFFER_WIDTH * BUFFER_HEIGHT]; ogg_uint32_t uint32_buffer[BUFFER_WIDTH * BUFFER_HEIGHT]; (void)argc; (void)argv; /* Test the basic functionality. */ setenv("OD_LOG_MODULES", "generic:3", 1); od_log_init(od_logging_test_emit); /* This should log. */ reset_result(); OD_LOG((OD_LOG_GENERIC, OD_LOG_ERR, "Blah blah %s:%d", "XXX", 9)); expected_result("Blah blah XXX:9"); /* This should not log (level too low) */ reset_result(); OD_LOG((OD_LOG_GENERIC, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9)); expected_nothing(); /* This should not log (facility not set) */ reset_result(); OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_ERR, "Blah blah %s:%d", "XXX", 9)); expected_nothing(); /* Test multiple modules */ setenv("OD_LOG_MODULES", "generic:3,entropy-coder:5", 1); od_log_init(od_logging_test_emit); reset_result(); OD_LOG((OD_LOG_GENERIC, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9)); expected_nothing(); reset_result(); OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9)); expected_something(); /* Test multiple modules in the other order*/ setenv("OD_LOG_MODULES", "entropy-coder:5,generic:3", 1); od_log_init(od_logging_test_emit); reset_result(); OD_LOG((OD_LOG_GENERIC, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9)); expected_nothing(); reset_result(); OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9)); expected_something(); /* Test bogus module string */ setenv("OD_LOG_MODULES", "generic:XXX,blahblah:9,entropy-coder:5", 1); od_log_init(od_logging_test_emit); reset_result(); OD_LOG((OD_LOG_GENERIC, OD_LOG_ERR, "Blah blah %s:%d", "XXX", 9)); expected_nothing(); reset_result(); OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9)); expected_something(); /* Test a ridiculous fmt string */ memset(bogus_fmt_string, 'X', sizeof(bogus_fmt_string)); bogus_fmt_string[sizeof(bogus_fmt_string) - 2] = 'Y'; bogus_fmt_string[sizeof(bogus_fmt_string) - 1] = '\0'; OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, bogus_fmt_string, "XXX", 9)); /* Test matrices */ for (i=0; i<(BUFFER_WIDTH * BUFFER_HEIGHT); ++i) { int16_buffer[i] = 1000 + i; } reset_result(); od_log_matrix_int16(OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "PREFIX:", int16_buffer, BUFFER_WIDTH, BUFFER_HEIGHT); expected_result(expected_matrix_int16); for (i=0; i<(BUFFER_WIDTH * BUFFER_HEIGHT); ++i) { float_buffer[i] = 1 + (float)i / 1000; } reset_result(); od_log_matrix_float(OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "PREFIX:", float_buffer, BUFFER_WIDTH, BUFFER_HEIGHT); expected_result(expected_matrix_float); for (i=0; i<(BUFFER_WIDTH * BUFFER_HEIGHT); ++i) { uint32_buffer[i] = 1000000 + i; } reset_result(); od_log_matrix_uint32(OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "PREFIX:", uint32_buffer, BUFFER_WIDTH, BUFFER_HEIGHT); expected_result(expected_matrix_uint32); if (failed) exit(1); exit(0); }