31#if defined(HAVE_LIBCFITSIO)
34#pragma GCC diagnostic ignored "-Wstrict-prototypes"
36#pragma GCC diagnostic pop
38#error CFITSIO library is not available
43 return floor( log10( abs(
x ) ) ) + 1;
46int main(
int argc,
char *argv[] )
49 char *val = 0, value[1000], nullstr[] =
"NAN";
50 char keyword[FLEN_KEYWORD], colname[1000][FLEN_VALUE];
52 int hdunum = 0, hdutype = 0, ncols = 0, ii = 0, anynul = 0, typecode[1000], dispwidth[1000], nd = 0;
53 long jj = 0, nrows = 0, nvecelem[1000], kk = 0, repeat, width = 0;
55 int printhelp = ( argc == 2 && ( strcmp( argv[1],
"-h" ) == 0 || strcmp( argv[1],
"--help" ) == 0 ) );
59 if ( !printhelp && argc == 3 && strcmp( argv[1],
"-n" ) == 0 ) {
62 }
else if ( !printhelp && argc == 2 ) {
66 fprintf( stderr,
"Usage: %s filename[ext][col filter][row filter] \n", argv[0] );
68 fprintf( stderr,
"List the contents of a FITS table \n" );
70 fprintf( stderr,
"Examples: \n" );
71 fprintf( stderr,
" %s tab.fits[GTI] - list the GTI extension\n", argv[0] );
72 fprintf( stderr,
" %s tab.fits[1][#row < 101] - list first 100 rows\n", argv[0] );
73 fprintf( stderr,
" %s tab.fits[1][col X;Y] - list X and Y cols only\n", argv[0] );
74 fprintf( stderr,
" %s tab.fits[1][col -PI] - list all but the PI col\n", argv[0] );
75 fprintf( stderr,
" %s tab.fits[1][col -PI][#row < 101] - combined case\n", argv[0] );
76 fprintf( stderr,
" %s -n ... - list without table header\n", argv[0] );
78 fprintf( stderr,
"Display formats can be modified with the TDISPn keywords.\n" );
82#if defined(PAGER) && defined(HAVE_POPEN) && defined(HAVE_PCLOSE)
83 FILE *fout = popen( PAGER,
"w" );
85 fprintf( stderr,
"Could not execute '%s'\n", PAGER );
92 if ( !fits_open_file( &fptr, argfile, READONLY, &
status ) ) {
93 if ( fits_get_hdu_num( fptr, &hdunum ) == 1 )
97 fits_movabs_hdu( fptr, 2, &hdutype, &
status );
99 fits_get_hdu_type( fptr, &hdutype, &
status );
102 if ( hdutype == IMAGE_HDU ) {
103 fprintf( stderr,
"Error: this program only displays tables, not images\n" );
105 fits_get_num_rows( fptr, &nrows, &
status );
106 fits_get_num_cols( fptr, &ncols, &
status );
108 for ( ii = 1; ii <= ncols; ii++ ) {
109 fits_make_keyn(
"TTYPE", ii, keyword, &
status );
110 fits_read_key( fptr, TSTRING, keyword, colname[ii], NULL, &
status );
111 fits_get_col_display_width( fptr, ii, &dispwidth[ii], &
status );
112 fits_get_coltype( fptr, ii, &typecode[ii], &repeat, &width, &
status );
113 if ( typecode[ii] != TSTRING && repeat > 1 ) {
114 nvecelem[ii] = repeat;
115 dispwidth[ii] +=
ndigits( nvecelem[ii] ) + 2;
119 if ( dispwidth[ii] < (
int )strlen( colname[ii] ) ) {
120 dispwidth[ii] = (
int )strlen( colname[ii] );
127 for ( ii = 1; ii <= ncols; ii++ ) {
128 if ( nvecelem[ii] > 1 ) {
129 for ( kk = 1; kk <= nvecelem[ii]; kk++ ) {
131 fprintf( fout,
"%*s[%*li] ", dispwidth[ii] - nd - 2, colname[ii], nd, kk );
134 fprintf( fout,
"%*s ", dispwidth[ii], colname[ii] );
142 for ( jj = 1; jj <= nrows && !
status; jj++ ) {
144 for ( ii = 1; ii <= ncols && !
status; ii++ ) {
147 for ( kk = 1; kk <= nvecelem[ii] && !
status; kk++ ) {
148 if ( fits_read_col_str( fptr, ii, jj, kk, 1, nullstr, &val, &anynul, &
status ) ) {
151 fprintf( fout,
"%*s ", dispwidth[ii], value );
158 fits_close_file( fptr, &
status );
161#if defined(PAGER) && defined(HAVE_POPEN) && defined(HAVE_PCLOSE)
166 fits_report_error( stderr,
status );
int main(int argc, char *argv[])
static int ndigits(int x)