Re: [R] passing char's from C to Fortran (mac os x)

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue 06 Jul 2004 - 00:43:14 EST


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@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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Jul 06 00:46:23 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:41 EST