header.c 2.85 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*
*				header.c
*
* Read external ASCII headers.
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*
*	This file part of:	SExtractor
*
Emmanuel Bertin's avatar
Emmanuel Bertin committed
10
*	Copyright:		(C) 2010 Emmanuel Bertin -- IAP/CNRS/UPMC
11
*
12
*	License:		GNU General Public License
13
*
14
15
16
17
18
19
20
21
22
23
*	SExtractor is free software: you can redistribute it and/or modify
*	it under the terms of the GNU General Public License as published by
*	the Free Software Foundation, either version 3 of the License, or
*	(at your option) any later version.
*	SExtractor is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY; without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*	GNU General Public License for more details.
*	You should have received a copy of the GNU General Public License
*	along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
24
*
Emmanuel Bertin's avatar
Emmanuel Bertin committed
25
*	Last modified:		07/09/2022
26
*
27
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

#ifdef HAVE_CONFIG_H
#include	"config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "define.h"
#include "globals.h"
#include "fits/fitscat.h"
#include "header.h"
#include "prefs.h"

/****** read_aschead ********************************************************
PROTO	int	read_aschead(char *filename, int frameno, tabstruct *tab)
PURPOSE	Read a ASCII header file and update the current field's tab
INPUT	Name of the ASCII file,
47
	Frame number (if extensions): 0=first,
48
49
50
51
	Tab structure.
OUTPUT	RETURN_OK if the file was found, RETURN_ERROR otherwise.
NOTES	-.
AUTHOR	E. Bertin (IAP)
Emmanuel Bertin's avatar
Emmanuel Bertin committed
52
VERSION	07/09/2022
53
54
55
56
57
58
59
60
61
62
63
64
 ***/
int     read_aschead(char *filename, int frameno, tabstruct *tab)
  {
   char         keyword[88],data[88],comment[88], str[88];
   FILE         *file;
   h_type       htype;
   t_type       ttype;
   int          i, flag;

  if ((file=fopen(filename, "r")))
    {
/*- Skip previous ENDs in multi-FITS extension headers */
65
    for (i=frameno-1; i--;)
Emmanuel Bertin's avatar
Emmanuel Bertin committed
66
      while (fgets(str, 88, file)
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
		&& strncmp(str,"END ",4)
		&& strncmp(str,"END\n",4));
    memset(str, ' ', 80);
    flag = RETURN_ERROR;
    while (fgets(str, 81, file) && strncmp(str,"END ",4)
			&& strncmp(str,"END\n",4))
      {
      if (fitspick(str, keyword, data, &htype, &ttype, comment) != RETURN_OK)
        {
        memset(str, ' ', 80);
        continue;
        }
/*---- Block critical keywords */
      if (!wstrncmp(keyword, "SIMPLE  ", 8)
	||!wstrncmp(keyword, "BITPIX  ", 8)
	||!wstrncmp(keyword, "NAXIS   ", 8)
	||!wstrncmp(keyword, "BSCALE  ", 8)
	||!wstrncmp(keyword, "BZERO   ", 8))
        continue;
      addkeywordto_head(tab, keyword, comment);
      fitswrite(tab->headbuf, keyword, data, htype, ttype);
      memset(str, ' ', 80);
      flag = RETURN_OK;
      }
    fclose(file);
/*-- Update the tab data */
    readbasic_head(tab);
    return flag;
    }
  else
    return RETURN_ERROR;
  }