Re: [R] FORTRAN charcter strings

About this list Date view Thread view Subject view Author view

From: Duncan Murdoch (dmurdoch@pair.com)
Date: Thu 21 Jun 2001 - 22:07:06 EST


Message-ID: <u7o3jtclioq2e0hmm66m3n7i4d39fkumfd@4ax.com>

On Thu, 21 Jun 2001 09:25:51 +0100 (BST), Prof Brian D Ripley
<ripley@stats.ox.ac.uk> wrote:

>Otherwise write a wrapper in Fortran that avoids having to pass character
>variables around.

More specifically: Thomas needs a routine to translate R character
variables into Fortran character strings, and a routine to translate
them back. R isn't doing anything very strange, so the first of these
is probably provided by a library routine for your compiler. Look in
the manual under "Interfacing to C" or something similar.

To translate strings back, you need to be sure to allocate the memory
in the R memory space, using the R_alloc routine from R.dll.

I doubt if this will help him much, but maybe it'll help someone else:
The translations you are talking about go like this in Delphi:

1. R character variables are arrays of pchar in Delphi. Delphi knows
how to convert pchars to Delphi strings automatically.

2. The routine Rpchar translates Delphi strings to R character
variables:

function R_alloc(n,size:integer):pchar; cdecl; external 'R.dll';

function Rpchar(s:string):pchar;
begin
  result := R_alloc(1,length(s)+1);
  strpcopy(result,s);
end;

Duncan Murdoch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2b30 : Fri 22 Jun 2001 - 18:58:45 EST