Re: Fortran and C - a simple example that is working
From: Herman D. Knoble (SkipKnobleLESS_at_SPAMpsu.DOT.edu)
Date: 08/09/04
- Next message: Paul Van Delst: "Re: PGF90 problem with adjustl(trim(..))"
- Previous message: Herman D. Knoble: "Re: Fortran and C - a simple example that is working"
- In reply to: Herman D. Knoble: "Re: Fortran and C - a simple example that is working"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 09 Aug 2004 09:18:32 -0400
Whoops: The F-Compiler Examples URL is: ftp://ftp.swcp.com/pub/walt/F/Examples/
On Mon, 09 Aug 2004 09:13:32 -0400, Herman D. Knoble <SkipKnobleLESS@SPAMpsu.DOT.edu>
wrote:
-|If you use the free F-compiler, the install creates an Examples folder which
-|contains both the Fortran and C parts and directional comments.
-|
-|Other examples (not related to F) may be found at:
-|http://www.personal.psu.edu/faculty/h/d/hdk/fortran.html#MixedLanguageProgramming
-|
-|Skip Knoble
-|
-|On 7 Aug 2004 11:41:14 -0700, emmendes@cpdee.ufmg.br (emammendes) wrote:
-|
-|-|Hello
-|-|
-|-|I am trying to link c void function to a fortran code. I have followed the
-|-|example on Intel fortran manual but unfortunately it didn' work.
-|-|
-|-|The pieces of code are:
-|-|
-|-|mtrandom.c
-|-|
-|-|#include <stdio.h>
-|-|#include <gsl/gsl_rng.h>
-|-|
-|-|#define GSL_RNG_TYPE mrg
-|-|
-|-|extern void mtrandom (long int seed, float *x, int n)
-|-|{
-|-|
-|-| gsl_rng * r = gsl_rng_alloc (gsl_rng_mt19937);
-|-|
-|-| int i;
-|-|
-|-| gsl_rng_set(r, seed);
-|-|
-|-| for (i = 0; i < n; i++)
-|-| {
-|-| unsigned long int u = gsl_rng_get (r);
-|-| x[i] = (float) u;
-|-| printf ("%lu %f\n", u,x[i]);
-|-| }
-|-|
-|-| gsl_rng_free (r);
-|-|
-|-|}
-|-|
-|-|cmtradom.for
-|-|
-|-| MODULE CMTRANDOM
-|-| INTERFACE
-|-| SUBROUTINE MTRANDOM (seed,x,n)
-|-| !DECS$ ATTRIBUTES C :: MTRANDOM
-|-| !DECS$ ATTRIBUTES REFERENCE :: x
-|-| INTEGER n
-|-| INTEGER(8) seed
-|-| real x(n)
-|-| END SUBROUTINE
-|-| END INTERFACE
-|-| END MODULE
-|-|
-|-|test_mtrandom.for
-|-|
-|-| USE CMTRANDOM
-|-|
-|-| ALLOCATABLE::x
-|-| REAL :: x(:)
-|-| INTEGER :: i,n
-|-|
-|-| n=50
-|-| ALLOCATE(x(1:n),stat=ibad)
-|-| if(ibad/=0) then
-|-| write(6,*) 'Unable to allocate work space for array x'
-|-| stop
-|-| endif
-|-|
-|-| CALL MTRANDOM(1000,x,n)
-|-|
-|-| if(ibad/=0) then
-|-| write(6,*) 'Deallocate error in x = ',ibad
-|-| stop
-|-| endif
-|-| end
-|-|
-|-|
-|-|The error message is
-|-|
-|-|ifort -o test_mtfortan test_mtfortan.for cmtrandom.o mtrandom.o -lgsl -lgslcblas -lm
-|-|/home/eduardo/tmp/ifortoFY7MJ.o(.text+0x105): In function `MAIN__':
-|-|: undefined reference to `mtrandom_'
-|-|
-|-|What am I missing?
-|-|
-|-|Thanks for your help and patience
-|-|
-|-|Ed
-|
-|
-| Herman D. (Skip) Knoble, Research Associate
-| (a computing professional for 38 years)
-| Email: SkipKnobleLESS at SPAMpsu dot edu
-| Web: http://www.personal.psu.edu/hdk
-| Penn State Information Technology Services
-| Academic Services and Emerging Technologies
-| Graduate Education and Research Services
-| Penn State University
-| 214C Computer Building
-| University Park, PA 16802-21013
-| Phone:+1 814 865-0818 Fax:+1 814 863-7049
Herman D. (Skip) Knoble, Research Associate
(a computing professional for 38 years)
Email: SkipKnobleLESS at SPAMpsu dot edu
Web: http://www.personal.psu.edu/hdk
Penn State Information Technology Services
Academic Services and Emerging Technologies
Graduate Education and Research Services
Penn State University
214C Computer Building
University Park, PA 16802-21013
Phone:+1 814 865-0818 Fax:+1 814 863-7049
- Next message: Paul Van Delst: "Re: PGF90 problem with adjustl(trim(..))"
- Previous message: Herman D. Knoble: "Re: Fortran and C - a simple example that is working"
- In reply to: Herman D. Knoble: "Re: Fortran and C - a simple example that is working"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|