Calling NAG Library Routines from Scilab
NAG Technical Report 5/2009

Calling NAG Library Routines from Scilab


Start of report   Skip to Example 1   Skip to Example 2   Skip to Example 3   Skip to Example 4   Skip to Example 5


Troubleshooting:

  • Be aware that if you have backup copies of any of your files as created by the emacs text editor, with names such as interface.c.~1~, Scilab may use these backup copies in preference to the proper files. If the backup file (an old version of the main file) contains incorrect code, then of course it may not compile, leading to error messages from Scilab. Worse, it may compile but not implement the routine you thought it would. Examine all messages from Scilab carefully when executing the build script to ensure the files you expected are being used. If necessary, remove offending backups and try again.
  • If you are attempting to link to an external shared library, and that library further depends on other shared libraries, you may see a message similar to this:
      Link failed for dynamic library '/fserver/nagprod/CL08/cll6a08dgl/acml/libnagc_acml.so'.
      An error occurred: libacml.so: cannot open shared object file: No such file or directory
    
    In this case you may need to set an environment variable to tell the system where to look to find shared libraries. The environment variable name is operating-system dependent. On Linux machines it is named LD_LIBRARY_PATH, and is a colon-separated list of directories to be searched for libacml.so. For example, if you use the C shell, the command
      % setenv LD_LIBRARY_PATH /opt/NAG/cll6a08dgl/lib:${LD_LIBRARY_PATH}
    
    will ensure that directory /opt/NAG/cll6a08dgl/lib gets searched.
  • If you link to an old version of the NAG library, it's possible that the NAG function or routine does not exist in that library. Check the NAG documentation associated with the NAG library you have.

Other useful things to know

  • Various Scilab examples can be found in $SCIHOME/share/scilab/modules/dynamic_link/examples/interfaces/c/ where $SCIHOME is the root directory of your Scilab installation.
  • A description of all the different building block functions, such as CreateVar etc. can be found in Introduction to Scilab 6.2.1
  • Character, integer, real, double and double complex type variables are respectively stored in the cstk, istk, sstk, stk, zstk Scilab internal stack at the addresses returned by GetRhsVar. Booleans are also stored on the istk.
  • Normally d stands for double, r for float (real), i for integer, c for character string and z for complex
  • If the variable you are getting with the GetRhsVar function is a matrix, then we can use:
    1. MATRIX_OF_INTEGER_DATATYPE on the istk
    2. MATRIX_OF_RATIONAL_DATATYPE on the sstk
    3. MATRIX OF DOUBLE DATATYPE on the stk
    4. MATRIX_OF_COMPLEX_DATATYPE on the zstk
    5. MATRIX_OF_BOOLEAN_DATATYPE on the istk
    6. STRING_DATATYPE on the cstk
  • We need to convert int to Integer to work with the NAG code, and need to be careful about comparing int variables to Integer variables.
  • The command link('show') shows what libraries are linked to Scilab
  • ulink() is a function for unlinking libraries in Scilab. Its only input is the number of the library as shown when link('show') is run.
  • Here is an example builder script nag_builder_all.sce for building many interfaces at once.
  • The interfaces only need to be built once. The loader script that is generated can then be renamed and run each time Scilab starts up by adding a line of code to the Scilab startup file, which in Linux may be named $HOME/.Scilab/.scilab-x.x.x/.scilab where x.x.x is the Scilab version number.

Useful Scilab links


Start of report   Skip to Example 1   Skip to Example 2   Skip to Example 3   Skip to Example 4   Skip to Example 5