"Fossies" - the Fresh Open Source Software Archive

Member "cfitsio-4.0.0/scalnull.c" (20 May 2021, 8973 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 "scalnull.c" see the Fossies "Dox" file reference documentation.

    1 /*  This file, scalnull.c, contains the FITSIO routines used to define     */
    2 /*  the starting heap address, the value scaling and the null values.      */
    3 
    4 /*  The FITSIO software was written by William Pence at the High Energy    */
    5 /*  Astrophysic Science Archive Research Center (HEASARC) at the NASA      */
    6 /*  Goddard Space Flight Center.                                           */
    7 
    8 #include <string.h>
    9 #include "fitsio2.h"
   10 /*--------------------------------------------------------------------------*/
   11 int ffpthp(fitsfile *fptr,      /* I - FITS file pointer */
   12            long theap,          /* I - starting addrss for the heap */
   13            int *status)         /* IO - error status     */
   14 /*
   15   Define the starting address for the heap for a binary table.
   16   The default address is NAXIS1 * NAXIS2.  It is in units of
   17   bytes relative to the beginning of the regular binary table data.
   18   This routine also writes the appropriate THEAP keyword to the
   19   FITS header.
   20 */
   21 {
   22     if (*status > 0 || theap < 1)
   23         return(*status);
   24 
   25     /* reset position to the correct HDU if necessary */
   26     if (fptr->HDUposition != (fptr->Fptr)->curhdu)
   27         ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status);
   28 
   29     (fptr->Fptr)->heapstart = theap;
   30 
   31     ffukyj(fptr, "THEAP", theap, "byte offset to heap area", status);
   32 
   33     return(*status);
   34 }
   35 /*--------------------------------------------------------------------------*/
   36 int ffpscl(fitsfile *fptr,      /* I - FITS file pointer               */
   37            double scale,        /* I - scaling factor: value of BSCALE */
   38            double zero,         /* I - zero point: value of BZERO      */
   39            int *status)         /* IO - error status                   */
   40 /*
   41   Define the linear scaling factor for the primary array or image extension
   42   pixel values. This routine overrides the scaling values given by the
   43   BSCALE and BZERO keywords if present.  Note that this routine does not
   44   write or modify the BSCALE and BZERO keywords, but instead only modifies
   45   the values temporarily in the internal buffer.  Thus, a subsequent call to
   46   the ffrdef routine will reset the scaling back to the BSCALE and BZERO
   47   keyword values (or 1. and 0. respectively if the keywords are not present).
   48 */
   49 {
   50     tcolumn *colptr;
   51     int hdutype;
   52 
   53     if (*status > 0)
   54         return(*status);
   55 
   56     if (scale == 0)
   57         return(*status = ZERO_SCALE);  /* zero scale value is illegal */
   58 
   59     if (ffghdt(fptr, &hdutype, status) > 0)  /* get HDU type */
   60         return(*status);
   61 
   62     if (hdutype != IMAGE_HDU)
   63         return(*status = NOT_IMAGE);         /* not proper HDU type */
   64 
   65     if (fits_is_compressed_image(fptr, status)) /* compressed images */
   66     {
   67         (fptr->Fptr)->cn_bscale = scale;
   68         (fptr->Fptr)->cn_bzero  = zero;
   69         return(*status);
   70     }
   71 
   72     /* set pointer to the first 'column' (contains group parameters if any) */
   73     colptr = (fptr->Fptr)->tableptr; 
   74 
   75     colptr++;   /* increment to the 2nd 'column' pointer  (the image itself) */
   76 
   77     colptr->tscale = scale;
   78     colptr->tzero = zero;
   79 
   80     return(*status);
   81 }
   82 /*--------------------------------------------------------------------------*/
   83 int ffpnul(fitsfile *fptr,      /* I - FITS file pointer                */
   84            LONGLONG nulvalue,   /* I - null pixel value: value of BLANK */
   85            int *status)         /* IO - error status                    */
   86 /*
   87   Define the value used to represent undefined pixels in the primary array or
   88   image extension. This only applies to integer image pixel (i.e. BITPIX > 0).
   89   This routine overrides the null pixel value given by the BLANK keyword
   90   if present.  Note that this routine does not write or modify the BLANK
   91   keyword, but instead only modifies the value temporarily in the internal
   92   buffer. Thus, a subsequent call to the ffrdef routine will reset the null
   93   value back to the BLANK  keyword value (or not defined if the keyword is not
   94   present).
   95 */
   96 {
   97     tcolumn *colptr;
   98     int hdutype;
   99 
  100     if (*status > 0)
  101         return(*status);
  102 
  103     if (ffghdt(fptr, &hdutype, status) > 0)  /* get HDU type */
  104         return(*status);
  105 
  106     if (hdutype != IMAGE_HDU)
  107         return(*status = NOT_IMAGE);         /* not proper HDU type */
  108 
  109     if (fits_is_compressed_image(fptr, status)) /* ignore compressed images */
  110         return(*status);
  111 
  112     /* set pointer to the first 'column' (contains group parameters if any) */
  113     colptr = (fptr->Fptr)->tableptr; 
  114 
  115     colptr++;   /* increment to the 2nd 'column' pointer  (the image itself) */
  116 
  117     colptr->tnull = nulvalue;
  118 
  119     return(*status);
  120 }
  121 /*--------------------------------------------------------------------------*/
  122 int fftscl(fitsfile *fptr,      /* I - FITS file pointer */
  123            int colnum,          /* I - column number to apply scaling to */
  124            double scale,        /* I - scaling factor: value of TSCALn   */
  125            double zero,         /* I - zero point: value of TZEROn       */
  126            int *status)         /* IO - error status     */
  127 /*
  128   Define the linear scaling factor for the TABLE or BINTABLE extension
  129   column values. This routine overrides the scaling values given by the
  130   TSCALn and TZEROn keywords if present.  Note that this routine does not
  131   write or modify the TSCALn and TZEROn keywords, but instead only modifies
  132   the values temporarily in the internal buffer.  Thus, a subsequent call to
  133   the ffrdef routine will reset the scaling back to the TSCALn and TZEROn
  134   keyword values (or 1. and 0. respectively if the keywords are not present).
  135 */
  136 {
  137     tcolumn *colptr;
  138     int hdutype;
  139 
  140     if (*status > 0)
  141         return(*status);
  142 
  143     if (scale == 0)
  144         return(*status = ZERO_SCALE);  /* zero scale value is illegal */
  145 
  146     if (ffghdt(fptr, &hdutype, status) > 0)  /* get HDU type */
  147         return(*status);
  148 
  149     if (hdutype == IMAGE_HDU)
  150         return(*status = NOT_TABLE);         /* not proper HDU type */
  151 
  152     colptr = (fptr->Fptr)->tableptr;   /* set pointer to the first column */
  153     colptr += (colnum - 1);     /* increment to the correct column */
  154 
  155     colptr->tscale = scale;
  156     colptr->tzero = zero;
  157 
  158     return(*status);
  159 }
  160 /*--------------------------------------------------------------------------*/
  161 int fftnul(fitsfile *fptr,      /* I - FITS file pointer                  */
  162            int colnum,          /* I - column number to apply nulvalue to */
  163            LONGLONG nulvalue,   /* I - null pixel value: value of TNULLn  */
  164            int *status)         /* IO - error status                      */
  165 /*
  166   Define the value used to represent undefined pixels in the BINTABLE column.
  167   This only applies to integer datatype columns (TFORM = B, I, or J).
  168   This routine overrides the null pixel value given by the TNULLn keyword
  169   if present.  Note that this routine does not write or modify the TNULLn
  170   keyword, but instead only modifies the value temporarily in the internal
  171   buffer. Thus, a subsequent call to the ffrdef routine will reset the null
  172   value back to the TNULLn  keyword value (or not defined if the keyword is not
  173   present).
  174 */
  175 {
  176     tcolumn *colptr;
  177     int hdutype;
  178 
  179     if (*status > 0)
  180         return(*status);
  181 
  182     if (ffghdt(fptr, &hdutype, status) > 0)  /* get HDU type */
  183         return(*status);
  184 
  185     if (hdutype != BINARY_TBL)
  186         return(*status = NOT_BTABLE);        /* not proper HDU type */
  187  
  188     colptr = (fptr->Fptr)->tableptr;   /* set pointer to the first column */
  189     colptr += (colnum - 1);    /* increment to the correct column */
  190 
  191     colptr->tnull = nulvalue;
  192 
  193     return(*status);
  194 }
  195 /*--------------------------------------------------------------------------*/
  196 int ffsnul(fitsfile *fptr,      /* I - FITS file pointer                  */
  197            int colnum,          /* I - column number to apply nulvalue to */
  198            char *nulstring,     /* I - null pixel value: value of TNULLn  */
  199            int *status)         /* IO - error status                      */
  200 /*
  201   Define the string used to represent undefined pixels in the ASCII TABLE
  202   column. This routine overrides the null  value given by the TNULLn keyword
  203   if present.  Note that this routine does not write or modify the TNULLn
  204   keyword, but instead only modifies the value temporarily in the internal
  205   buffer. Thus, a subsequent call to the ffrdef routine will reset the null
  206   value back to the TNULLn keyword value (or not defined if the keyword is not
  207   present).
  208 */
  209 {
  210     tcolumn *colptr;
  211     int hdutype;
  212 
  213     if (*status > 0)
  214         return(*status);
  215 
  216     if (ffghdt(fptr, &hdutype, status) > 0)  /* get HDU type */
  217         return(*status);
  218 
  219     if (hdutype != ASCII_TBL)
  220         return(*status = NOT_ATABLE);        /* not proper HDU type */
  221  
  222     colptr = (fptr->Fptr)->tableptr;   /* set pointer to the first column */
  223     colptr += (colnum - 1);    /* increment to the correct column */
  224 
  225     colptr->strnull[0] = '\0';
  226     strncat(colptr->strnull, nulstring, 19);  /* limit string to 19 chars */
  227 
  228     return(*status);
  229 }