This HTML automatically generated with rman for NEMO
Table of Contents

Name

ftoc - nemo_main() builder from fortran source code

Synopsis

ftoc [parameter=value]

Description

ftoc is a C-source extracter (from fortran) that can be useful if you need to add the NEMO user interface to a FORTRAN program. The FORTRAN PROGRAM statement must not appear in the source code, instead there must be a subroutine, preferably with the name NEMOMAIN, that the NEMO user interface will consider the MAIN fortran program. Example see below.

This manual page also documents the usage of the F77_FUNC macros to aid C programmers importing/exporting their fortran/C code to C/Fortran resp.

Parameters

The following parameters are recognized in any order if the keyword is also given:
in=
Input source code to extract defv[] from. No default.
out=
Output nemo_main module [- means stdout]. [Default: -].
call=
You fortran main subroutine (no args!) [Default: nemomain].
options=
options for symbols name conversions. Recognized are: lower, upper, under. By default, ftoc will try and figure it out by itself.

Example

Let’s take a routine, test.f displayed below, that needs the NEMO user interface:
C
C:      Test program for NEMO’s footran interface
C+
C   in=???\n            Required (dummy) filename
C   n=1000\n            Test integer value
C   pi=3.1415\n         Test real value
C   e=2.3\n             Another test value
C   text=hello world\n  Test string
C   VERSION=1.1\n       24-may-92 PJT
C-
C
      SUBROUTINE nemomain
C
      .......

with the following commands


    % ftoc test.f > test_main.c
    % gfortran -c test.f test_main.c -L$NEMOLIB -lnemo

a non-graphics program can be compiled. It is assumed, that the fortran callable getparam(3NEMO) has also been added to the NEMO library.

Nemomain

A NEMO C-main will use the routine name nemo_main, whereas a Fortran-main will use the name nemomain. ANSI rules do not clearly define (or may even forbid) use of embedded underscores. In fact, on linux a fortran symbol name like a_b will get exported as a_b__. You may have to add the -fno-underscoring and/or -fno-second-underscore options to the fortran compiler (FFLAGS).

F77_func

A macro called F77_FUNC is defined through config.h (created at installation time by the configure script) that aids the programmer to re-define the name of a C function, such that it can be used by fortran code, or by defining the name of an extern fortran module such that C can call it. For example, look at the following contrived example.

In fortran:

        DOUBLE PRECISION FUNCTION FUNCF(X)
        DOUBLE PRECISION X, FUNCC
        IF (X.LT.1.0d0) THEN
            FUNCF = SQRT(X)
        ELSE
            FUNCF = FUNCC(1.0d0/X)
        ENDIF 
        END
and in C:
    #define funcc F77_FUNC(funcc,FUNCC)
    #define funcf F77_FUNC(funcf,FUNCF)
        
    extern double funcf(double *);
   
    double funcc(double * xp) {
        double x = *xp;
        if (x < 1.0)
            return  sqrt(x);
        else {
            x = 1.0/x;
            return  funcf(&x);
        }
    }


See Alsonm(1) AuthorPeter Teuben Update History
xx-jun-92    V1.0 Created    PJT
25-May-92    V1.1 added c: to signal usage line    PJT
20-jan-98    more doc
7-jan-00    V2.0 changed to use F77_FUNC; machine -> options        PJT
30-apr-21    align man and bin    PJT


Table of Contents