|
|
Up |
|
|
  |
Author: rudrarudra Date: Aug 10, 2008 00:46
dear friends, i am using a C code to calculate time in my program(this
is a copy from PWScf package):
#include
#include
#include
#include "c_defs.h"
double F77_FUNC(cclock,CCLOCK)()
/* Return the second elapsed since Epoch (00:00:00 UTC, January 1,
1970)
*/
{
struct timeval tmp;
double sec;
gettimeofday( &tmp, (struct timezone *)0 );
sec = tmp.tv_sec + ((double)tmp.tv_usec)/1000000.0;
return sec;
}
double F77_FUNC(scnds,SCNDS) ( )
|
| Show full article (0.96Kb) |
|
| | 10 Comments |
|
  |
Author: rudrarudra Date: Aug 10, 2008 01:09
this is the c_defs.h file:
#define F77_FUNC(name,NAME) name ## _
#define F77_FUNC_(name,NAME) name ## _
#define HAVE_MALLINFO 1
|
| |
|
| | no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: Aug 10, 2008 07:57
On 10 aug, 10:09, rudra gmail.com> wrote:
> this is the c_defs.h file:
>
> #define F77_FUNC(name,NAME) name ## _
> #define F77_FUNC_(name,NAME) name ## _
>
> #define HAVE_MALLINFO 1
I assume that you use FORTRAN 77, because otherwise you could just as
well
use the Fortran 90/95/... intrinsic routines for this.
The C part is already taken care of. What you need now is a way to
tell
the FORTRAN 77 compiler about the type of the functions:
program testtime
external secnds, cclock
real*8 secnds, cclock
C or, more standard conforming:
C double precision secnds, cclock
|
| Show full article (1.06Kb) |
| no comments |
|
  |
Author: nospamnospam Date: Aug 10, 2008 07:58
rudra gmail.com> wrote:
> dear friends, i am using a C code to calculate time in my program
Why not just use the standard Fortran intrinsics for the purpose
instead? See the standard date_and_time and cpu_time intrinsics.
> but due to my lack of knowledge in C, i am unable to make an explicit
> interface of C code to my program.
Is there some particular reason why you need an explicit interface, or
are you just wanting to do one on general principles... or do you
actually mean something other than explicit interface?
It seems to me that if you know how the functions are supposed to be
invoked from Fortran, then you know what the interface is and thus
should not need any knowledge of C to write an interface body to make
the interface explicit. That seems purely a Fortran matter; you wouldn't
even need to see the C code at all. That's why I wonder whether that is
really what you are talking about.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|
| |
| no comments |
|
  |
Author: nospamnospam Date: Aug 10, 2008 08:04
> The C part is already taken care of. What you need now is a way to tell
> the FORTRAN 77 compiler about the type of the functions:
While that might well be what he actually wanted (just to figure out how
to call the procedures), note that this isn't literally what the OP
asked. He asked how to make the interfaces explicit. It did occur to me
that what he really wanted might just be to figure out how to invoke
them.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|
| |
| no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: Aug 10, 2008 08:20
On 10 aug, 17:04, nos...@see.signature (Richard Maine) wrote:
>> The C part is already taken care of. What you need now is a way to tell
>> the FORTRAN 77 compiler about the type of the functions:
>
> While that might well be what he actually wanted (just to figure out how
> to call the procedures), note that this isn't literally what the OP
> asked. He asked how to make the interfaces explicit. It did occur to me
> that what he really wanted might just be to figure out how to invoke
> them.
Uh, yes, but all the pieces seem to be there, including
a bit of FORTRAN code. So, perhaps rudra merely needs confirmation
that this will work? (The declaration that the functions are
double precision is still needed though, perhaps that is
what triggered the question).
Regards,
Arjen
|
| |
| no comments |
|
  |
Author: rudrarudra Date: Aug 10, 2008 10:42
Dear Arjen and Richard,
i can invoke the C code without any explicit interface and then it is
running fine. the problem is when i am trying to create an explicit
interface.i also tried to create something like:
interface F77_FUNC
function F77_FUNC(cclock,scnds) &
bind(C,name='F77_FUNC')
use iso_c_binding
end function
end interface
but its just a blind man making his way. and this is where i need your
help.
|
| |
| no comments |
|
  |
Author: nospamnospam Date: Aug 10, 2008 15:34
rudra gmail.com> wrote:
> Dear Arjen and Richard,
> i can invoke the C code without any explicit interface and then it is
> running fine. the problem is when i am trying to create an explicit
> interface.i also tried to create something like:
>
>
> interface F77_FUNC
> function F77_FUNC(cclock,scnds) &
> bind(C,name='F77_FUNC')
> use iso_c_binding
> end function
> end interface
>
> but its just a blind man making his way. and this is where i need your
> help.
Why are you trying to make an explicit interface anyway?
|
| Show full article (1.12Kb) |
| no comments |
|
  |
Author: rudrarudra Date: Aug 10, 2008 21:21
dear Richard,
let me show the code again and the warnning messages!!
The interface is
interface F77_FUNC
function F77_FUNC(cclock) &
bind(C,name="F77_FUNC")
use iso_c_binding
end function
end interface
and the warnnings are:
gcc -Wall -c lib/cptimer.c
~/gfortran/bin/gfortran -c main.f90
main.f90:38.1:
function F77_FUNC(cclock) &
1
Warning: Implicitly declared BIND(C) variable 'f77_func' at (1) may
not be C interoperable
main.f90:38.25-1:
|
| Show full article (1.01Kb) |
| no comments |
|
  |
|
|
  |
Author: rudrarudra Date: Aug 10, 2008 21:23
dear Richard,
let me show the code again and the warnning messages!!
The interface is
interface F77_FUNC
function F77_FUNC(cclock) &
bind(C,name="F77_FUNC")
use iso_c_binding
end function
end interface
and the warnnings are:
gcc -Wall -c lib/cptimer.c
~/gfortran/bin/gfortran -c main.f90
main.f90:38.1:
function F77_FUNC(cclock) &
1
Warning: Implicitly declared BIND(C) variable 'f77_func' at (1) may
not be C interoperable
main.f90:38.25-1:
|
| Show full article (1.01Kb) |
| no comments |
|
|
|
|