Skip to content
Snippets Groups Projects
Select Git revision
  • bad7edb61852f6241c9938864801d4d7848f2ccb
  • main default protected
  • dev
3 results

cookbook.c

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    cookbook.c 21.35 KiB
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    /*
      Every program which uses the CFITSIO interface must include the
      the fitsio.h header file.  This contains the prototypes for all
      the routines and defines the error status values and other symbolic
      constants used in the interface.  
    */
    #include <fitsio.h>
    
    int main( void );
    void writeimage( void );
    void writeascii( void );
    void writebintable( void );
    void copyhdu( void );
    void selectrows( void );
    void readheader( void );
    void readimage( void );
    void readtable( void );
    void printerror( int status);
    
    int main()
    {
    /*************************************************************************
       This is a simple main program that calls the following routines:
    
        writeimage    - write a FITS primary array image
        writeascii    - write a FITS ASCII table extension
        writebintable - write a FITS binary table extension
        copyhdu       - copy a header/data unit from one FITS file to another
        selectrows    - copy selected row from one HDU to another
        readheader    - read and print the header keywords in every extension
        readimage     - read a FITS image and compute the min and max value
        readtable     - read columns of data from ASCII and binary tables
    
    **************************************************************************/
    
        writeimage();
        writeascii();
        writebintable();
        copyhdu();
        selectrows();
        readheader();
        readimage();
        readtable();
    
        printf("\nAll the cfitsio cookbook routines ran successfully.\n");
        return(0);
    }
    /*--------------------------------------------------------------------------*/
    void writeimage( void )
    
        /******************************************************/
        /* Create a FITS primary array containing a 2-D image */
        /******************************************************/
    {
        fitsfile *fptr;       /* pointer to the FITS file, defined in fitsio.h */
        int status, ii, jj;
        long  fpixel, nelements, exposure;
        unsigned short *array[200];
    
        /* initialize FITS image parameters */
        char filename[] = "atestfil.fit";             /* name for new FITS file */
        int bitpix   =  USHORT_IMG; /* 16-bit unsigned short pixel values       */
        long naxis    =   2;  /* 2-dimensional image                            */    
        long naxes[2] = { 300, 200 };   /* image is 300 pixels wide by 200 rows */
    
        /* allocate memory for the whole image */