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
66
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
=pod
=head1 NAME
B<FunImagePut - put an image to a Funtools file>
=head1 SYNOPSIS
#include <funtools.h>
int FunImagePut(Fun fun, void *buf, int dim1, int dim2, int bitpix,
char *plist)
=head1 DESCRIPTION
The B<FunImagePut()> routine outputs an image array to a FITS
file. The image is written either as a primary header/data unit or as
an image extension, depending on whether other data have already been
written to the file. That is, if the current file position is at the
beginning of the file, a primary HDU is written. Otherwise, an
image extension is written.
The first argument is the Funtools handle returned by
FunOpen(). The second B<buf>
argument is a pointer to a data buffer to write. The B<dim1>and
B<dim2> arguments that follow specify the dimensions of the image,
where dim1 corresponds to naxis1 and dim2 corresponds to naxis2. The
B<bitpix> argument specifies the data type of the image and can
have the following FITS-standard values:
=over 4
=item *
8 unsigned char
=item *
16 short
=item *
32 int
=item *
-32 float
=item *
-64 double
=back
When FunTableRowPut() is first
called for a given image, Funtools checks to see if the primary header
has already been written (by having previously written an image or a
binary table.) If not, this image is written to the primary HDU.
Otherwise, it is written to an image extension.
Thus, a simple program to generate a FITS image might look like this:
int i;
int dim1=512, dim2=512;
double *dbuf;
Fun fun;
dbuf = malloc(dim1*dim2*sizeof(double));
/* open the output FITS image, preparing to copy input params */
if( !(fun = FunOpen(argv[1], "w", NULL)) )
gerror(stderr, "could not FunOpen output file: %s\n", argv[1]);
for(i=0; i<(dim1*dim2); i++){
... fill dbuf ...
}
/* put the image (header will be generated automatically */
if( !FunImagePut(fun, buf, dim1, dim2, -64, NULL) )
gerror(stderr, "could not FunImagePut: %s\n", argv[1]);
FunClose(fun);
free(dbuf);
In addition, if a
Funtools reference handle
was specified when this table was opened, the
parameters from this
Funtools reference handle
are merged into the new image
header. Furthermore, if a reference image was specified during
FunOpen(), the values of
B<dim1>, B<dim2>, and B<bitpix> in the calling sequence
can all be set to 0. In this case, default values are taken from the
reference image section. This is useful if you are reading an image
section in its native data format, processing it, and then writing
that section to a new FITS file. See the
imblank example code.
The data are assumed to be in the native machine format and will
automatically be swapped to FITS big-endian format if necessary. This
behavior can be over-ridden with the B<convert=[true|false]>
keyword in the B<plist> param list string.
When you are finished writing the image, you should call
FunFlush() to write out the FITS
image padding. However, this is not necessary if you subsequently call
FunClose() without doing any other I/O to the FITS file.
=head1 SEE ALSO
See funtools(n) for a list of Funtools help pages
=cut
|