Re: [Rd] Generate random numbers in Fortran

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat, 14 Feb 2009 11:28:07 +0000 (GMT)

There are lots of invalid characters in your mail, but Fortran code starts in column 7 and that is what the compiler is telling you you have not done. (Some dialects will allow tabs instead, but I see no sing of those either.)

If you are that unfamiliar with Fortran, why not just use C?

On Sat, 14 Feb 2009, Fabio Mathias wrote:

> As I am wanting to generate a beta, then I created a function in C to
> generate a beta, but the problem appears when I go to compile
>
> My function in C is
>
> #include <R.h>
> #include <Rmath.h>
> #include <math.h>
>
> void F77_SUB(myrbeta)(double* px)
> {
> ?????? GetRNGstate();
> ?????? *px = rbeta(1.00,3.00);
> ?????? PutRNGstate();
> }
>
> My function in Fortran is
>
> subroutine blah(a)
> double precision (a)
> call myrbeta(RND)
> end
>
> The error
>
> fmcron_at_fmcron-desktop:~/teste$ R CMD SHLIB mat.c blah.f
> gcc -std=gnu99 -I/usr/share/R/include?????????? -fpic?? -g -O2 -c mat.c -o mat.o
> gfortran???? -fpic?? -g -O2 -c blah.f -o blah.o
> blah.f:1.1:
>
> subroutine blah(a)??????????????????????????????????????????????????????????????????????????????????????????????????????????
> 1
> Erro: Non-numeric character in statement label at (1)
> blah.f:1.1:
>
> subroutine blah(a)??????????????????????????????????????????????????????????????????????????????????????????????????????????
> 1
> Erro: Unclassifiable statement at (1)
> blah.f:2.1:
>
> double precision (a)??????????????????????????????????????????????????????????????????????????????????????????????????????
> 1
> Erro: Non-numeric character in statement label at (1)
> blah.f:2.1:
>
> double precision (a)??????????????????????????????????????????????????????????????????????????????????????????????????????
> 1
> Erro: Unclassifiable statement at (1)
> blah.f:4.1:
>
> end????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
> 1
> Erro: Non-numeric character in statement label at (1)
> blah.f:4.1:
>
> end????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
> 1
> Erro: Unclassifiable statement at (1)
> make: ** [blah.o] Erro 1
>
>
> ???????????????????????? F??bio Mathias Corr??a???????????????????????????????????????????? UFLA
>
>
> --- Em sex, 13/2/09, Kjell Konis <kjell.konis_at_epfl.ch> escreveu:
> De: Kjell Konis <kjell.konis_at_epfl.ch>
> Assunto: Re: [Rd] Generate random numbers in Fortran
> Para: "fabio.ufla_at_yahoo.com.br" <fabio.ufla_at_yahoo.com.br>
> Cc: "r-devel_at_r-project.org" <r-devel_at_r-project.org>
> Data: Sexta-feira, 13 de Fevereiro de 2009, 16:49
>
> Take a look at section 6.6 in Writing R Extensions. It describes how to call C
> functions from FORTRAN. Basically it just boils down to this, in a C file define
> the functions
>
> void F77_SUB(fseedi)(void)
> {
> int x = 100;
> seed_in(&x);
> }
>
>
> void F77_SUB(fseedo)(void)
> {
> int x = 100;
> seed_out(&x);
> }
>
>
> void F77_SUB(myrunif)(double* px)
> {
> *px = unif_rand();
> }
>
>
> Then you could write a FORTRAN subroutine like
>
> subroutine blah()
> implicit double precision (a-h,o-z)
> call fseedi()
> call myrunif(RND)
> call fseedo()
> end
>
> The fseed* subroutines only need to be called once, fseedi at the beginning of
> your FORTRAN code and fseedo at the end.
>
> HTH,
> Kjell
>
>
> On 13 f??vr. 09, at 17:32, Fabio Mathias wrote:
>
>> Hi!!!
>> It would like to know if it exists a form to use the functions to
>> generate variates in FORTRAN with the same easiness I use that them in
>> C? Or not?
>> If yes. They would have some example? I would like to use the functions
> rbeta, rlnorm and others!
>>
>>
>> Sorry my english..rsrsrs
>>
>> Thanks!!!
>>
>>
>> F??bio Mathias Corr??a University Federal of the Lavras -
> Brazil
>>
>>
>>
>> Veja quais s??o os assuntos do momento no Yahoo! +Buscados
>>
>> [[alternative HTML version deleted]]
>>
>> <ATT00001.txt>
>
>
>
>
> Veja quais s??o os assuntos do momento no Yahoo! +Buscados
>
> [[alternative HTML version deleted]]
>
>

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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sat 14 Feb 2009 - 10:31:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 14 Feb 2009 - 16:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive