This section reprises the steps of the walkthroughs-python
--- evaluating spectra and photometric colors for Sirius A --- but now using the MSG C interface.
In your working directory, create a new file c-walkthrough.c
with the following source code:
c-walkthrough.c
A few brief comments on the code:
- The
#include "cmsg.h"
statement includes the header definitions for the MSG C interface. - Because C doesn't have :py
dict
datatypes, the photospheric parameters must be passed to MSG as a plain array (here, stored in the variable :cx_vec
). A loop with :cstrcmp()
calls is used to make sure the correct values are stored in each array element. - Many of the calls to MSG routines (e.g., :c
load_specgrid
, :cinterp_specgrid_flux
) containNULL
trailing arguments; these correspond to omitted optional arguments.
The next step is to compile the demo program. Make sure the MSG_DIR
environment variable is set, as described in the quick-start
chapter. Then, enter the following on the command line:
bash
gcc -o c-walkthrough c-walkthrough.c -I$MSG_DIR/include $MSG_DIR/scripts/cmsg_link
The -I$MSG_DIR/include
option tells the compiler where to find the header file, while the $MSG_DIR/scripts/cmsg_link
clause (note the enclosing backticks) runs a link script that returns the compiler flags necessary to link the program against the appropriate libraries.
To run the code, first create a symbolic link to the demo grid:
bash
ln -s $MSG_DIR/data/grids/sg-demo.h5
Then, execute the command
bash
./c-walkthrough
The code will create a file spectrum.dat
containing the flux spectrum for Sirius A (as an ASCII table), and print out the apparent V-band magnitude and colors of the star.