"Fossies" - the Fresh Open Source Software Archive

Member "cfitsio-4.0.0/iter_image.c" (20 May 2021, 3076 Bytes) of package /linux/misc/cfitsio-4.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "iter_image.c" see the Fossies "Dox" file reference documentation.

    1 #include <string.h>
    2 #include <stdio.h>
    3 #include <stdlib.h>
    4 #include "fitsio.h"
    5 
    6 /*
    7   This program illustrates how to use the CFITSIO iterator function.
    8   It reads and modifies the input 'iter_image.fit' image file by setting
    9   all the pixel values to zero (DESTROYING THE ORIGINAL IMAGE!!!)
   10 */
   11 main()
   12 {
   13     extern zero_image(); /* external work function is passed to the iterator */
   14     fitsfile *fptr;
   15     iteratorCol cols[3];  /* structure used by the iterator function */
   16     int n_cols;
   17     long rows_per_loop, offset;
   18 
   19     int status, nkeys, keypos, hdutype, ii, jj;
   20     char filename[]  = "iter_image.fit";     /* name of rate FITS file */
   21 
   22     status = 0; 
   23 
   24     fits_open_file(&fptr, filename, READWRITE, &status); /* open file */
   25 
   26 
   27     n_cols = 1;
   28 
   29     /* define input column structure members for the iterator function */
   30     fits_iter_set_file(&cols[0], fptr);
   31     fits_iter_set_iotype(&cols[0], InputOutputCol);
   32     fits_iter_set_datatype(&cols[0], 0);
   33 
   34     rows_per_loop = 0;  /* use default optimum number of rows */
   35     offset = 0;         /* process all the rows */
   36 
   37     /* apply the rate function to each row of the table */
   38     printf("Calling iterator function...%d\n", status);
   39 
   40     fits_iterate_data(n_cols, cols, offset, rows_per_loop,
   41                       zero_image, 0L, &status);
   42 
   43     fits_close_file(fptr, &status);      /* all done */
   44 
   45     if (status)
   46         fits_report_error(stderr, status);  /* print out error messages */
   47 
   48     return(status);
   49 }
   50 /*--------------------------------------------------------------------------*/
   51 int zero_image(long totalrows, long offset, long firstrow, long nrows,
   52              int ncols, iteratorCol *cols, void *user_strct ) 
   53 
   54 /*
   55    Sample iterator function that calculates the output flux 'rate' column
   56    by dividing the input 'counts' by the 'time' column.
   57    It also applies a constant deadtime correction factor if the 'deadtime'
   58    keyword exists.  Finally, this creates or updates the 'LIVETIME'
   59    keyword with the sum of all the individual integration times.
   60 */
   61 {
   62     int ii, status = 0;
   63 
   64     /* declare variables static to preserve their values between calls */
   65     static int *counts;
   66 
   67     /*--------------------------------------------------------*/
   68     /*  Initialization procedures: execute on the first call  */
   69     /*--------------------------------------------------------*/
   70     if (firstrow == 1)
   71     {
   72        if (ncols != 1)
   73            return(-1);  /* number of columns incorrect */
   74 
   75        /* assign the input pointers to the appropriate arrays and null ptrs*/
   76        counts       = (int *)  fits_iter_get_array(&cols[0]);
   77     }
   78 
   79     /*--------------------------------------------*/
   80     /*  Main loop: process all the rows of data */
   81     /*--------------------------------------------*/
   82 
   83     /*  NOTE: 1st element of array is the null pixel value!  */
   84     /*  Loop from 1 to nrows, not 0 to nrows - 1.  */
   85 
   86     for (ii = 1; ii <= nrows; ii++)
   87     {
   88        counts[ii] = 1.;
   89     }
   90     printf("firstrows, nrows = %d %d\n", firstrow, nrows);
   91     
   92     return(0);  /* return successful status */
   93 }