summaryrefslogtreecommitdiffstats
path: root/funtools/fitsy/fitsfile.c
blob: 035726cf94831ab3b3037a5f73fdc846219d9cb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Fitsy FITS routines to handle a complete multi extension FITS file.
 */

typedef struct Ft_fileread {
	int	n;
	int	flag;
	int	pixtype;
} Ft_fileread;

ft_fileimageread(file, fits, data, x)
	File		 file;
	FITSHead	 fits;
	FITSFile	*data;
	Ft_fileread	*x;
{
	int	size;

	(void)ReAlloc(*data, sizeof(struct FITSFile) * ++x->n);

    (*data)[x->n-1].bitpix = x->pixtype;

    if ( x->flag || ft_seek(fits) == -1 ) {
	if ( ((*data)[x->n-1].data = ft_dataread(file, fits, NULL, x->pixtype))
	  == NULL ) {
	    return 0;
	}
    }
}

/* Read an entire FITS file.
 */
FITSFile ft_fileread(file, flag, pixtype, n)
	File	 file;
	int	 flag;
	int	 pixtype;
	int	*n;
{
		Ft_fileread 	x;
		FITSFile	data;

	x.n	  = 0;
	x.flag 	  = flag;
	x.pixtype = pixtype;

	data = (FITSFile) ft_fileparse(file, ft_fileimageread, &x);
	*n = x.n;

	return data;
}

/* Return a pointer the data poriton of a FITS HDU.
 */
void *ft_filedata(file, ft)
	File		file;
	FITSFile	ft;
{
    if ( ft->data != NULL ) 		return ft->data;
    if ( ft_seek(ft->head) == -1 )	return NULL;

    if ( ftSeek(file, ft_seek(ft->head), 0) == -1 )
	return NULL;

    return ft->data = ft_dataread(file, ft->head, NULL, ft->bitpix);
}