help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Flexible Image Transport System (FITS) file format support


From: Thomas D. Dean
Subject: Re: Flexible Image Transport System (FITS) file format support
Date: Mon, 29 Mar 2010 01:08:51 -0700

I compiled and installed the latest cfitsio and ccfits libraries.
I downloaded the sample fits files like rosat_pspc_rdf2_3_bk1.fits from
the fits site.  The code from CCfits seems to not read this correctly
with a simple read.  See the cc code below.

I believe the reason is the header in the rosat file is more than one
block long, as can be seen from applying the octave function.

==== octave =================================================
function [hdr,bin]=readfits(fname,binsize)
  ## read a fits file
  ##   [hdr,hcnt,bin,bcnt]=readfits(fname,binsize)
  ##     fname   - a file name 'rosat_pspc_rdf2_3_bk1.fits'
  ##     binsize - size of the binary array [80,200]
  ##     ndr     - an array containing the header of the fits file
  ##     hcnt    - number of bytes in the fits file
  ##     bin     - binary data from the fits file header
  ##     bcnt    - number of elements in the binary array
  ##
  ##
  #############################################################
  ## work on header to determine how to read the binary part of the file
  ## [bitpix,c] = sscanf(hdr{strncmp(hdr,'BITPIX  =',9)},'BITPIX  =%d');
  ## [naxis,c]  = sscanf(hdr{strncmp(hdr,'NAXIS ',6)},'NAXIS   =%d');
  ## [naxis1,c] = sscanf(hdr{strncmp(hdr,'NAXIS1',6)},'NAXIS1  =%d');
  ## [naxis2,c] = sscanf(hdr{strncmp(hdr,'NAXIS2',6)},'NAXIS2  =%d');
  hdr={};
  [fid, msg]=fopen(fname,"r");
  while (sum(strcmp(hdr,'END'))==0)
    [tmp_hdr,cnt]=fread(fid,[80,36],"uchar",0);
    hdr=[hdr;cellstr(tmp_hdr')];
  end;
  [bin,cnt]=fread(fid,binsize,"uint16",0);
  fclose(fid);
endfunction;

==== ccfits =================================================
// doread.cxx - read a fits file
// g++ doread.cxx -o doread -l CCfits -l cfitsio
//////////////////////////////////////////////////////////////////
// includes
#include <CCfits/CCfits>
#include <iostream>

//////////////////////////////////////////////////////////////////
// main
int main(int argc, char **argv) {
  CCfits::FITS myimage(argv[1],CCfits::Read,true);
  std::cout << myimage;

  return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]