funref(3)
π funref(3) β the Funtools Reference Handle π
okay bestie, this is a page from the SAORD Documentation set, and it's all about FunRef, aka the Funtools Reference Handle. it's literally the glow-up connector that links a Funtools input file to a Funtools output file. let's get into it π«Ά
β¨ SYNOPSIS β¨
a description of how to use a Funtools reference handle to connect a Funtools input file to an output file. that's it, that's the vibe π
πΈ DESCRIPTION πΈ
so the Funtools reference handle connects a Funtools input file to a Funtools output file so that parameters β or even whole entire extensions β can be copied from one to the other. iconic behavior honestly.
to make that connection happen, you pass the Funtools handle of the input file to the final argument of the FunOpen() call for the output file:
if( !(ifun = FunOpen(argv[1], "r", NULL)) )
gerror(stderr, "could not FunOpen input file: %s\n", argv[1]);
if( !(ofun = FunOpen(argv[2], "w", ifun)) )
gerror(stderr, "could not FunOpen output file: %s\n", argv[2]);
and ngl, it does not matter what type of input or output file (or extension) is opened, or whether they're even the same type. not a single care. when the output image or binary table is written using FunImagePut() or FunTableRowPut(), an appropriate header gets written first, with parameters copied from the input extension. π«
of course, invalid parameters get removed first, bestie β like, if the input is a binary table and the output is an image, then binary table parameters such as TFORM, TUNIT, etc. will not be copied to the output. they simply do not make the cut. π
π using defaults, the lazy girl way π
using a reference handle also lets default values be passed to FunImagePut() so you can write out an output image with the same dimensions and data type as the input image. to use the defaults from the input, you enter a value of 0 for dim1, dim2, and bitpix. for example:
fun = FunOpen(argv[1], "r", NULL);
fun2 = FunOpen(argv[2], "w", fun);
buf = FunImageGet(fun, NULL, NULL);
... process image data ...
FunImagePut(fun2, buf, 0, 0, 0, NULL);
but like, you often do want info about the data type and dimensions of the image for processing. so the code above is equivalent to this:
fun = FunOpen(argv[1], "r", NULL);
fun2 = FunOpen(argv[2], "w", fun);
buf = FunImageGet(fun, NULL, NULL);
FunInfoGet(fun, FUN_SECT_DIM1, &dim1, FUN_SECT_DIM2, &dim2,
FUN_SECT_BITPIX, &bitpix, 0);
... process image data ...
FunImagePut(fun2, buf, dim1, dim2, bitpix, NULL);
same energy, different outfit. π
π¦ swapping the reference handle (main character move) π¦
it is possible to change the reference handle for a given output Funtools handle using the FunInfoPut() routine:
/* make the new extension the reference handle for the output file */
FunInfoPut(fun2, FUN_IFUN, &fun, 0);
when this is done, Funtools specially resets the output file to start a new output extension, which is connected to the new input reference handle. you can use this mechanism to process multiple input extensions into a single output file, by successively opening the former and setting the reference handle for the latter. for example:
/* open a new output FITS file */
if( !(fun2 = FunOpen(argv[2], "w", NULL)) )
gerror(stderr, "could not FunOpen output file: %s\n", argv[2]);
/* process each input extension in turn */
for(ext=0; ;ext++){
/* get new extension name */
sprintf(tbuf, "%s[%d]", argv[1], ext);
/* open it -- if we cannot open it, we are done */
if( !(fun=FunOpen(tbuf, "r", NULL)) )
break;
/* make the new extension the reference handle for the output file */
FunInfoPut(fun2, FUN_IFUN, &fun, 0);
... process ...
/* flush output extension (write padding, etc.) */
FunFlush(fun2, NULL);
/* close the input extension */
FunClose(fun);
}
in this example, the output file is opened first. then each successive input extension is opened, and the output reference handle is set to the newly opened input handle. after data processing is performed, the output extension is flushed and the input extension is closed, in preparation for the next input extension. it's giving assembly line, it's giving organized. π
π copying other extensions π
finally, a reference handle can be used to copy other extensions from the input file to the output file. copy of other extensions is controlled by adding a "C" or "c" to the mode string of the FunOpen() call of the input reference file. π
- if
"C"is specified, then other extensions are always copied (i.e., copy is forced by the application). - if
"c"is used, then other extensions are copied if the user requests copying by adding a plus sign"+"to the extension name in the bracket specification.
for example, the funtable program utilizes user-specified "c" mode so that the second example below will copy all extensions:
# copy only the EVENTS extension
csh> funtable "test.ev[EVENTS,circle(512,512,10)]" foo.ev
# copy ALL extensions
csh> funtable "test.ev[EVENTS+,circle(512,512,10)]" foo.ev
see that little +? that's the whole difference. tiny but mighty. β¨
when extension copy is specified in the input file, the call to FunOpen() on the input file delays the actual file open until the output file also is opened (or until I/O is performed on the input file, whichever happens first). then, when the output file is opened, the input file is also opened and input extensions are copied to the output file, up to the specific extension being opened. processing of input and output extensions then proceed. lowkey coordinated, highkey slay. π
π§ cleaning up the leftovers π§
when extension processing is complete, the remaining extensions need to be copied from input to output. this can be done explicitly, using the FunFlush() call with the "copy=remaining" plist:
FunFlush(fun, "copy=remaining");
alternatively, this will happen automatically, if the output file is closed before the input file:
/* we could explicitly flush remaining extensions that need copying */
/* FunFlush(fun2, "copy=remaining"); */
/* but if we close output before input, end flush is done automatically */
FunClose(fun2);
FunClose(fun);
β bestie note: order matters here!! close output before input and the end flush does itself. the code is literally serving itself. no cap.
π₯ SEE ALSO π₯
see funtools(7) for a list of Funtools help pages π
and that's the whole page, bestie!! this one came from version 1.4.5, dated April 14, 2011 β a vintage classic that still eats, fr fr. go connect those files, you've got this πβ¨ππ¦πΈ
π¦ where this page comes from
- debian bookworm: libfuntools-dev 1.4.8-1 Β· GPL
- debian trixie: libfuntools-dev 1.4.8-1.1+b2 Β· GPL
- ubuntu jammy: libfuntools-dev 1.4.8-1 Β· GPL
- ubuntu noble: libfuntools-dev 1.4.8-1.1build2 Β· GPL
- ubuntu questing: libfuntools-dev 1.4.8-2
- ubuntu resolute: libfuntools-dev 1.4.8-2build1 Β· GPL
- ubuntu stonking: libfuntools-dev 1.4.8-2build1 Β· GPL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms