#include #include #include "fitsio.h" /* Compile using: gcc rod_uvfits2txt.c -L/astro/cfitsio/ -lcfitsio -lm -o rod_uvfits2txt or change -L to the directory containing the fitsio library in your system. You also need to have fitsio.h and longnam.h available in the local directory (don't ask me why) */ int main(int argc, char *argv[]) { fitsfile *fptr; /* FITS file pointer, defined in fitsio.h */ char *val, value[1000], nullstr[]="*"; char keyword[FLEN_KEYWORD], colname[FLEN_VALUE]; int COLUMNS = atoi(argv[2]); int count; int status = 0; /* CFITSIO status value MUST be initialized to zero! */ int hdunum, hdutype, ncols, ii, anynul, dispwidth[1000]; int firstcol, lastcol = 0, linewidth; long jj, nrows; char name[100]; sprintf(name,"%s%s",argv[1],"[3]"); if (argc != 3) { printf("List the contents of a UV data - FITS file \n"); printf("\n"); printf("Use: \n\n"); printf(" rod_list FITSFILE N\n\n"); printf("Where FITSFILE is a file written using the AIPS task FITAB\n"); printf("and N is the number of columns in the visbility table.\n"); printf("For example: 8 IFs x 16 channels x 4 Stokes => 512 complex numbers\n"); printf("so the table has 512 x 2 = 1024 columns.\n\n"); printf("The output file contains 9 columns followed by the N visibility columns\n"); printf("(See the FITSFILE header for more information.) \n\n"); return(0); } if (!fits_open_file(&fptr, name, READONLY, &status)) { if ( fits_get_hdu_num(fptr, &hdunum) == 1 ) /* This is the primary array; try to move to the */ /* first extension and see if it is a table */ fits_movabs_hdu(fptr, 2, &hdutype, &status); else fits_get_hdu_type(fptr, &hdutype, &status); /* Get the HDU type */ if (hdutype == IMAGE_HDU) printf("Error: this program only displays tables, not images\n"); else { fits_get_num_rows(fptr, &nrows, &status); fits_get_num_cols(fptr, &ncols, &status); /* find the number of columns that will fit within 1000 characters */ while(lastcol < ncols) { firstcol = lastcol+1; for (lastcol = firstcol; lastcol <= ncols; lastcol++) { fits_get_col_display_width (fptr, lastcol, &dispwidth[lastcol], &status); linewidth += dispwidth[lastcol] + 1; if (linewidth > 1000)break; } if (lastcol > firstcol)lastcol--; /* the last col didn't fit */ /* print each column, row by row (there are faster ways to do this) */ val = value; for (jj = 1; jj <= nrows && !status; jj++) { printf("%4d ", jj); /* read value as a string, regardless of intrinsic datatype */ /* COLUMNS 1 to 9 -------------------------------------------------*/ for (count = 1; count <= 9; count++) { if (fits_read_col_str (fptr,count,jj, 1, 1, nullstr, &val, &anynul, &status) ) break; /* jump out of loop on error */ printf("%-*s ",dispwidth[count], value); } /* COLUMN 10 (actually COLUMNS 10 to 10 + N-------------------------*/ for (count = 1; count <= COLUMNS; count++) { if (fits_read_col_str (fptr,10,jj, count, 1, nullstr, &val, &anynul, &status) ) break; /* jump out of loop on error */ printf("%-*s ",dispwidth[10], value); } printf("\n"); } } } fits_close_file(fptr, &status); } if (status) fits_report_error(stderr, status); /* print any error message */ return(status); }