"no valid lines found for this format" error when using readcol to read a FITS file

431 views Asked by At

I'm trying to write a script that not only reads in FITS files, but will then print and save the data to a table. So far my code does not seem to have a problem reading the files; printing them seems to be the issue. This is my code so far (when I run this I get the error message "no valid lines found for this format":

;Planck File read (used to read in and print individual fits files)
pro planck_file_read

readcol,'COM_PCCS_857_R1.20.fits',name,glon,glat,ra,dec,detflux,detflux_err,aperflux,aperflux_err,psfflux,psfflux_err,gauflux,gauflux_err,gau_semi1,gau_semi1_err,gau_semi2,gau_semi2_err,gau_theta,gau_theta_err,gau_fwhm_eff,extended,cirrus_n,ext_val,ercsc

openw,lun,'fits_857.tbl',/get_lun,width=400
printf,lun,'; ;    name                    GLON            GLAT             RA              DEC         DETFLUX    DETFLUXERR    APERFLUX   APERFLUXERR     PSFFLUX    PSFFLUXERR     GAUFLUX    GAUFLUXERR    GAUSEMI1   GAUSEMI1ERR    GAUSEMI2   GAUSEMI2ERR    GAUTHETA   GAUTHETAERR  GAUFWHMEFF  EXTENDED  CIRRUSN  EXTVAL  ERCSC
printf,lun,'; ;                            DEG             DEG              DEG             DEG           MJY          MJY          MJY          MJY          MJY          MJY          MJY          MJY        ARCMIN       ARCMIN       ARCMIN       ARCMIN         DEG         DEG        ARCMIN      NONE      NONE    NONE    NONE
for i=0,n_elements(fits_name)-1 do printf,lun,name[i],glon[i],glat[i],ra[i],dec[i],detflux[i],detflux_err[i],aperflux[i],aperflux_err[i],psfflux[i],psfflux_err[i],gauflux[i],gauflux_err[i],gau_semi1[i],gau_semi1_err[i],gau_semi2[i],gau_semi2_err[i],gau_theta[i],gau_theta_err[i],gau_fwhm_eff[i],extended[i],cirrus_n[i],ext_val[i],ercsc[i]
free_lun,lun

end
2

There are 2 answers

0
mgalloy On

That error message is coming from READCOL. READCOL is designed to read ASCII files, not FITS files. Use FITS routines like FITS_OPEN, FITS_READ, and FITS_CLOSE to read the data.

0
janmarander On

READCOL is designed to read free-format ASCII files with columns of data into vectors. You have to provide it with the exact number of columns you have in your data file in order to read the file in correctly. For instance, if I write

READCOL, 'file.txt', name, date, ID, num_cookies 

and the file actually has another column of number of cakes, it won't read anything in because it will look for lines where there are only 4 variables. You can skip variables you don't want if you include a FORMAT string in your call to READCOL, like

READCOL, 'file.txt', name, date, ID, num_cookies, FORMAT = '(A,F,F,I,X)' 

where 'X' indicates that there is a variable there that you are skipping.

But, if your file is a fits file it is probably formatted differently and you should look into the FITS routines as @mgalloy suggested above.