1funref(3)                     SAORD Documentation                    funref(3)
2
3
4

NAME

6       FunRef: the Funtools Reference Handle
7

SYNOPSIS

9       A description of how to use a Funtools reference handle to connect a
10       Funtools input file to an output file.
11

DESCRIPTION

13       The Funtools reference handle connects a Funtools input file to a Fun‐
14       tools output file so that parameters (or even whole extensions) can be
15       copied from the one to the other. To make the connection, the Funtools
16       handle of the input file is passed to the final argument of the
17       FunOpen() call for the output file:
18
19         if( !(ifun = FunOpen(argv[1], "r", NULL)) )
20           gerror(stderr, "could not FunOpen input file: %s\n", argv[1]);
21         if( !(ofun = FunOpen(argv[2], "w", ifun)) )
22           gerror(stderr, "could not FunOpen output file: %s\n", argv[2]);
23
24       It does not matter what type of input or output file (or extension) is
25       opened, or whether they are the same type. When the output image or
26       binary table is written using FunImagePut() or FunTableRowPut() an
27       appropriate header will be written first, with parameters copied from
28       the input extension. Of course, invalid parameters will be removed
29       first, e.g., if the input is a binary table and the output is an image,
30       then binary table parameters such as TFORM, TUNIT, etc. parameters will
31       not be copied to the output.
32
33       Use of a reference handle also allows default values to be passed to
34       FunImagePut() in order to write out an output image with the same
35       dimensions and data type as the input image. To use the defaults from
36       the input, a value of 0 is entered for dim1, dim2, and bitpix. For
37       example:
38
39         fun = FunOpen(argv[1], "r", NULL);
40         fun2 = FunOpen(argv[2], "w", fun);
41         buf = FunImageGet(fun, NULL, NULL);
42         ... process image data ...
43         FunImagePut(fun2, buf, 0, 0, 0, NULL);
44
45       Of course, you often want to get information about the data type and
46       dimensions of the image for processing. The above code is equivalent to
47       the following:
48
49         fun = FunOpen(argv[1], "r", NULL);
50         fun2 = FunOpen(argv[2], "w", fun);
51         buf = FunImageGet(fun, NULL, NULL);
52         FunInfoGet(fun, FUN_SECT_DIM1, &dim1, FUN_SECT_DIM2, &dim2,
53                    FUN_SECT_BITPIX, &bitpix, 0);
54         ... process image data ...
55         FunImagePut(fun2, buf, dim1, dim2, bitpix, NULL);
56
57       It is possible to change the reference handle for a given output Fun‐
58       tools handle using the FunInfoPut() routine:
59
60         /* make the new extension the reference handle for the output file */
61         FunInfoPut(fun2, FUN_IFUN, &fun, 0);
62
63       When this is done, Funtools specially resets the output file to start a
64       new output extension, which is connected to the new input reference
65       handle. You can use this mechanism to process multiple input extensions
66       into a single output file, by successively opening the former and set‐
67       ting the reference handle for the latter. For example:
68
69         /* open a new output FITS file */
70         if( !(fun2 = FunOpen(argv[2], "w", NULL)) )
71           gerror(stderr, "could not FunOpen output file: %s\n", argv[2]);
72         /* process each input extension in turn */
73         for(ext=0; ;ext++){
74           /* get new extension name */
75           sprintf(tbuf, "%s[%d]", argv[1], ext);
76           /* open it -- if we cannot open it, we are done */
77           if( !(fun=FunOpen(tbuf, "r", NULL)) )
78             break;
79           /* make the new extension the reference handle for the output file */
80           FunInfoPut(fun2, FUN_IFUN, &fun, 0);
81           ... process ...
82           /* flush output extension (write padding, etc.) */
83           FunFlush(fun2, NULL);
84           /* close the input extension */
85           FunClose(fun);
86         }
87
88       In this example, the output file is opened first. Then each successive
89       input extension is opened, and the output reference handle is set to
90       the newly opened input handle. After data processing is performed, the
91       output extension is flushed and the input extension is closed, in
92       preparation for the next input extension.
93
94       Finally, a reference handle can be used to copy other extensions from
95       the input file to the output file.  Copy of other extensions is con‐
96       trolled by adding a "C" or "c" to the mode string of the FunOpen() call
97       of the input reference file.  If "C" is specified, then other exten‐
98       sions are always copied (i.e., copy is forced by the application).  If
99       "c" is used, then other extensions are copied if the user requests
100       copying by adding a plus sign "+" to the extension name in the bracket
101       specification.  For example, the funtable program utilizes user-speci‐
102       fied "c" mode so that the second example below will copy all exten‐
103       sions:
104
105         # copy only the EVENTS extension
106         csh> funtable "test.ev[EVENTS,circle(512,512,10)]" foo.ev
107         # copy ALL extensions
108         csh> funtable "test.ev[EVENTS+,circle(512,512,10)]" foo.ev
109
110       When extension copy is specified in the input file, the call to
111       FunOpen() on the input file delays the actual file open until the out‐
112       put file also is opened (or until I/O is performed on the input file,
113       which ever happens first). Then, when the output file is opened, the
114       input file is also opened and input extensions are copied to the output
115       file, up to the specific extension being opened. Processing of input
116       and output extensions then proceed.
117
118       When extension processing is complete, the remaining extensions need to
119       be copied from input to output. This can be done explicitly, using the
120       FunFlush() call with the "copy=remaining" plist:
121
122         FunFlush(fun, "copy=remaining");
123
124       Alternatively, this will happen automatically, if the output file is
125       closed before the input file:
126
127         /* we could explicitly flush remaining extensions that need copying */
128         /* FunFlush(fun2, "copy=remaining"); */
129         /* but if we close output before input, end flush is done automatically  */
130         FunClose(fun2);
131         FunClose(fun);
132

SEE ALSO

134       See funtools(n) for a list of Funtools help pages
135
136
137
138version 1.4.0                   August 15, 2007                      funref(3)
Impressum