On Mon, 5 Jul 2004, Ingmar Visser wrote:
>
> Hello All,
>
> In some package I use a c-routine which calls a fortran routine which
> expects a char-string as input.
>
> As per the writing R-extensions manual,
> the Fortran routine is declared in C as:
> void F77_NAME (setoptions) (char **option);
That's not in that manual. It says
The following table gives the mapping between the modes of R vectors and
the types of arguments to a C function or FORTRAN subroutine.
and not between the latter two.
> and then it is calles as follows:
>
> char **option;
> option = new char*[1];
> option[0] = new char[256];
> option[0] = strcpy(option[0],"Iteration Limit = 100");
> Rprintf(option[0]);
> F77_CALL (setoptions) (option);
>
> Unfortunately this does not work, ie the fortran routine setoptions does
> not correctly get the intended character string. Can anyone point me to a
> working example of passing characters from C to Fortran? Or tell me
what's
> wrong in my code above?
It's not C! (It looks like C++.) Where did you get the idea that Fortran
character corresponds to char** in C? It probably corresponds to char*,
possibly with a length passed separately. Since you are probably using
g77 I expect passing char * from C to Fortran will work, but passing back
might not.
R is a C program and it manages to pass characters to Fortran in quite a
few places, such as Lapack.c and loessc.c/loessf.f.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595