C-Munipack 1.2 / Application programming interface
C-Munipack 1.2 / Application programming interface
The following text describes the implementation of very simple application, which performs a photometry of a single CCD frame using a functions from the C-Munipack library. It is supposed, that you have got the C-Munipack library and its headers installed.
Let's start - make a new project in your favorite IDE and make a big cup of cofee for yourself. First of all, we need to include some standard headers:
#include <stdio.h> #include <stdlib.h>
The declaration from the C-Munipack library are sorted into several header files, but all we need to include just one header file, which in turn includes all other public ones.
#include <cmunipack.h>
We will use command-line arguments to specify the name of the file with an input CCD frame and the name of the file where the result shall be saved to. Because of this, our declaration of the main function looks like this:
int main(int argc, char *argv[]) { CmpackPhot *lc;
The lc variable is called the context. It stores the configuration parameters and keeps the internal data used during the photometry process. It allows the caller to process multiple frames in different threads without interference between each other.
Before calling any other function from the C-Munipack library, call the initialization function. This function initializes the internal static structures.
/* Library initialization */ cmpack_init();
Check the command line parameters. This demo expects two parameters, the first one is the name of the input file with a CCD frame in the FITS format, the second one is the name of the file where the result of photometry shall be written to.
/* Command line checking */ if (argc!=3) { fprintf(stderr, "Syntax: test <ccd frame> <photometry file>"); return 1; }
Before we do any real work, we need the context to be initialized. The cmpack_phot_init allocate the new photometry context and returns a new reference to it. Let's set up at least two most important configuration parameters - the filter half-width (FWHM) and the detection threshold.
/* Create context */ lc = cmpack_phot_init(); cmpack_phot_set_fwhm(lc, 2.5); cmpack_phot_set_thresh(lc, 4.0);
Now everything is ready to do a real work. The photometry is executed by calling the cmpack_phot, which takes the context as its first parameter, the names of the input and output files as the second and third parameter. The fourth parameter is NULL.
cmpack_phot(lc, argv[1], argv[2], NULL);
Before we finish the program, we should destroy our reference to the photometry context and since this is the last reference, the context is destroyed as well. Before terminating the program, you should call the library clean-up function.
/* Destroy context */ cmpack_unref(lc); /* Library cleanup */ cmpack_cleanup(); return 0; }