There are several small peculiarities of the C interface to the NDF_ library which arise from the fact that the library itself is implemented mainly in Fortran. You must be aware of these when writing software in C, otherwise your program may give unpredictable results (including crashing):
However, to avoid problems in standalone (non-ADAM) applications which have a C ``main'' function, you MUST invoke the C-specific ndfInit initialisation function as follows, before using any other facilities from the NDF_ library:
#include "ndf.h" /* Define NDF interface */
#include "sae_par.h" /* Define SAI__OK */
int main( int argc, char *argv[] ) {
int status = SAI__OK;
/* Initialise the NDF_ library for use from a C main routine. */
ndfInit( argc, argv, &status );
...
}
Note that you should pass to ndfInit the argument count and argument vector which the operating system passes to your program via the standard arguments of the C ``main'' function. If, for any reason, this argument information is not accessible, then you should pass an argument count of zero (the argument vector is then ignored). This tells the NDF_ library that argument information is not available.
This means that it is usually best to decide which language will
perform I/O throughout your program and stick with that
choice. Fortunately, the NDF_ library does not perform input and
generates no significant output, apart from error
messages. However, it is designed to integrate with the MERS message
and error reporting system (SUN/104), for example
through its use of message tokens, and it uses MERS for reporting its
own errors. MERS, in turn, uses Fortran to output these error messages
(in ADAM applications it may also pass output to other
tasks for delivery).
This means that if you are writing standalone software in C which calls the NDF_ library, then you should be able to use the standard I/O functions provided by C for most purposes quite safely, so long as you do so consistently. However, you should use MERS (or EMS, see SSN/4) for reporting errors, in order to be compatible with the error reporting performed by the NDF_ library.
In ADAM applications, you should always use MERS (or EMS) for both textual output intended for the user and error messages, otherwise output may be lost if the application is not run from the normal command line.