public software.sextractor

[/] [trunk/] [src/] [fits/] [fitshead.c] - Diff between revs 39 and 173

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 39 Rev 173
Line 7... Line 7...
*
*
*       Author:         E.BERTIN, DeNIS/LDAC
*       Author:         E.BERTIN, DeNIS/LDAC
*
*
*       Contents:       general functions for handling FITS file headers.
*       Contents:       general functions for handling FITS file headers.
*
*
*       Last modify:    25/09/2004
*       Last modify:    20/06/2007
*
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
*/
 
 
#ifdef  HAVE_CONFIG_H
#ifdef  HAVE_CONFIG_H
Line 313... Line 313...
PURPOSE Update a FITS header according to what's in the table.
PURPOSE Update a FITS header according to what's in the table.
INPUT   Table structure.
INPUT   Table structure.
OUTPUT  RETURN_OK if tab is a binary table, or RETURN_ERROR otherwise.
OUTPUT  RETURN_OK if tab is a binary table, or RETURN_ERROR otherwise.
NOTES   The headbuf pointer in the tabstruct might be reallocated.
NOTES   The headbuf pointer in the tabstruct might be reallocated.
AUTHOR  E. Bertin (IAP & Leiden observatory)
AUTHOR  E. Bertin (IAP & Leiden observatory)
VERSION 25/09/2004
VERSION 11/06/2007
 ***/
 ***/
int     update_head(tabstruct *tab)
int     update_head(tabstruct *tab)
 
 
  {
  {
   keystruct    *key;
   keystruct    *key;
Line 351... Line 351...
      }
      }
    return RETURN_ERROR;
    return RETURN_ERROR;
    }
    }
 
 
/*First, remove all existing TTYPE, TFORM, etc...*/
/*First, remove all existing TTYPE, TFORM, etc...*/
  fitsremove(tab->headbuf, "TTYPE???");
  removekeywordfrom_head(tab, "TTYPE???");
  fitsremove(tab->headbuf, "TFORM???");
  removekeywordfrom_head(tab, "TFORM???");
  fitsremove(tab->headbuf, "TUNIT???");
  removekeywordfrom_head(tab, "TUNIT???");
  fitsremove(tab->headbuf, "TZERO???");
  removekeywordfrom_head(tab, "TZERO???");
  fitsremove(tab->headbuf, "TSCAL???");
  removekeywordfrom_head(tab, "TSCAL???");
  fitsremove(tab->headbuf, "TDIM???");
  removekeywordfrom_head(tab, "TDIM???");
  fitsremove(tab->headbuf, "TDISP???");
  removekeywordfrom_head(tab, "TDISP???");
 
 
 
 
/*Change NAXIS1 in order to take into account changes in width*/
/*Change NAXIS1 in order to take into account changes in width*/
  naxis1 = 0;
  naxis1 = 0;
  key = tab->key;
  key = tab->key;
Line 463... Line 463...
PROTO   int prim_head(tabstruct *tab)
PROTO   int prim_head(tabstruct *tab)
PURPOSE Update a FITS header to make it "primary" (not extension)
PURPOSE Update a FITS header to make it "primary" (not extension)
INPUT   Table structure.
INPUT   Table structure.
OUTPUT  RETURN_OK if tab header was already primary, or RETURN_ERROR otherwise.
OUTPUT  RETURN_OK if tab header was already primary, or RETURN_ERROR otherwise.
NOTES   -.
NOTES   -.
AUTHOR  E. Bertin (IAP & Leiden observatory)
AUTHOR  E. Bertin (IAP & Leiden observatory) C. Marmo (IAP)
VERSION 08/05/2002
VERSION 11/06/2007
 ***/
 ***/
int     prim_head(tabstruct *tab)
int     prim_head(tabstruct *tab)
 
 
  {
  {
  if (!tab->headbuf)
  if (!tab->headbuf)
    return RETURN_ERROR;
    return RETURN_ERROR;
  if (!strncmp(tab->headbuf, "XTENSION",8))
  if (!strncmp(tab->headbuf, "XTENSION",8))
      {
      {
      strncpy(tab->headbuf, "SIMPLE  =                    T  "
      strncpy(tab->headbuf, "SIMPLE  =                    T  "
        "/ This is a FITS file                            ", 80);
        "/ This is a FITS file                            ", 80);
 
/* fitsverify 4.13 (CFITSIO V3.002) return an error
 
   if PCOUNT and GCOUNT are in a primary header (23/05/2007)*/
 
      removekeywordfrom_head(tab, "PCOUNT");
 
      removekeywordfrom_head(tab, "GCOUNT");
      return RETURN_ERROR;
      return RETURN_ERROR;
      }
      }
 
 
  return RETURN_OK;
  return RETURN_OK;
  }
  }
 
 
 
 
/****** ext_head *************************************************************
/****** ext_head *************************************************************
Line 488... Line 493...
PURPOSE Update a FITS header to make it "extension" (not primary)
PURPOSE Update a FITS header to make it "extension" (not primary)
INPUT   Table structure.
INPUT   Table structure.
OUTPUT  RETURN_OK if tab header was already extension, or RETURN_ERROR
OUTPUT  RETURN_OK if tab header was already extension, or RETURN_ERROR
        otherwise.
        otherwise.
NOTES   -.
NOTES   -.
AUTHOR  E. Bertin (IAP & Leiden observatory)
AUTHOR  E. Bertin (IAP & Leiden observatory) C. Marmo (IAP)
VERSION 08/05/2002
VERSION 20/06/2007
 ***/
 ***/
int     ext_head(tabstruct *tab)
int     ext_head(tabstruct *tab)
 
 
  {
  {
  if (!tab->headbuf)
  if (!tab->headbuf)
    return RETURN_ERROR;
    return RETURN_ERROR;
  if (!strncmp(tab->headbuf, "SIMPLE  ",8))
  if (!strncmp(tab->headbuf, "SIMPLE  ",8))
      {
      {
      strncpy(tab->headbuf, "XTENSION= 'IMAGE   '           "
      strncpy(tab->headbuf, "XTENSION= 'IMAGE   '           "
                "/ Image extension                                ", 80);
                "/ Image extension                                ", 80);
 
/* fitsverify 4.13 (CFITSIO V3.002) return an error
 
   if EXTEND are in an extension header (20/06/2007)*/
 
      removekeywordfrom_head(tab, "EXTEND");
 
/* fitsverify 4.13 (CFITSIO V3.002) return an error
 
   if PCOUNT and GCOUNT are not in the extension header (23/05/2007) */
 
      addkeywordto_head(tab, "PCOUNT  ", "required keyword; must = 0");
 
      addkeywordto_head(tab, "GCOUNT  ", "required keyword; must = 1");
 
      fitswrite(tab->headbuf,"PCOUNT  ", &tab->pcount, H_INT, T_LONG);
 
      fitswrite(tab->headbuf,"GCOUNT  ", &tab->gcount, H_INT, T_LONG);
      return RETURN_ERROR;
      return RETURN_ERROR;
      }
      }
 
 
  return RETURN_OK;
  return RETURN_OK;
  }
  }
Line 562... Line 576...
 
 
  return n;
  return n;
  }
  }
 
 
 
 
 
/****** removekeywordfrom_head ************************************************
 
PROTO   int removekeywordfrom_head(tabstruct *tab, char *keyword)
 
PURPOSE Remove a keyword from a table header.
 
INPUT   Table structure,
 
        String containing the keyword.
 
OUTPUT  RETURN_OK if the keyword was found, RETURN_ERROR otherwise..
 
NOTES   The headbuf pointer in the tabstruct might be reallocated.
 
        '?' wildcard allowed; Don't remove the ``END'' keyword with this!!!
 
AUTHOR  E. Bertin (IAP)
 
VERSION 11/06/2007
 
 ***/
 
int     removekeywordfrom_head(tabstruct *tab, char *keyword)
 
 
 
  {
 
   int  nb;
 
 
 
  if (fitsremove(tab->headbuf, keyword) == RETURN_OK)
 
    {
 
    if ((nb=fitsfind(tab->headbuf, "END     ")/(FBSIZE/80)+1) < tab->headnblock)
 
      {
 
      tab->headnblock = nb;
 
      QREALLOC(tab->headbuf, char, tab->headnblock*FBSIZE);
 
      }
 
    return RETURN_OK;
 
    }
 
  else
 
    return RETURN_ERROR;
 
  }
 
 
 
 
/****** tformof ***************************************************************
/****** tformof ***************************************************************
PROTO   int tformof(char *str, t_type ttype, int n)
PROTO   int tformof(char *str, t_type ttype, int n)
PURPOSE Return the ``TFORM'' string corresponding to a t_type
PURPOSE Return the ``TFORM'' string corresponding to a t_type
        and the number of elements.
        and the number of elements.
INPUT   a char pointer (to be filled with the T_FORM string),
INPUT   a char pointer (to be filled with the T_FORM string),