next up previous contents index
Next: 11.4.1 function ifeffit() Up: 11 Scripting and Programming with Previous: 11.3.8 integer function iffgetecho()


11.4 The C interface to IFEFFIT

Accessing IFEFFIT from a C program is very easy. The basic concepts and many of the details of the IFEFFIT application interface (or API for the programmers out there) given here also apply to using IFEFFIT from within scripting languages, as described later in this chapter. C++, by the way, is similar enough to C that calling IFEFFIT from it should be straightforward once the C interface is described. If you've read the previous section, you'll find that the C interface is also very similar to the Fortran interface.

The basic use of the IFEFFIT C interface is to send command strings to an ``IFEFFIT engine'' which acts just like an interactive IFEFFIT session run at the command prompt. The underlying engine has its own set of Program Variables that are kept in its own memory space, separate from the calling program. The session ``stays alive'' until the calling program ends. Though you could directly call any of the subroutines or functions in the IFEFFIT library, it is highly recommended that you not make such direct calls. Instead, you should use the functions provided in the application programming interface (API), as described here and encapsulated in the C include file ifeffit.h that can be found with the configuration files in the IFEFFIT distribution (typically in the /usr/local/share/ifeffit/config/ directory).

The IFEFFIT C API defines eight external functions, all of which are integer functions. To use these functions, you can simply put an include directive at the top of your program:

#!include "ifeffit.h"
int main() {
  int i; 
  i = ifeffit(" ");
  i = ifeffit("read_data(cu.xmu, group=cu, type=xmu)");
  i = ifeffit("spline(cu.energy, cu.xmu, rbkg = 1.2)");
  i = ifeffit("plot(cu.k, cu.chi)");
}
This shows a very simple IFEFFIT session converted into a C program, using only the function ifeffit(), the main interface to the underlying IFEFFIT engine.

As this example shows, it is recommended that you first call ifeffit() with an ``initialization string'', typically a blank line, but optionally setting system configuration variables.

How do you actually build an executable out of this program file? That, of course, depends on details of your system. Most of the settings needed are put in the file Config.mak in the same location as ifeffit.h. This file contains Makefile instructions needed for linking your IFEFFIT application with the IFEFFIT library and all the other libraries needed to make an executable. An example Makefile (using the above code and the settings of Config.mak from a fairly normal linux system) is included in the examples/scripting section of the source distribution.



Subsections
next up previous contents index
Next: 11.4.1 function ifeffit() Up: 11 Scripting and Programming with Previous: 11.3.8 integer function iffgetecho()
Matt Newville
2004-02-09