Re: F.03 C Interoperability doubt. Argument types



On Feb 5, 1:12 pm, glen herrmannsfeldt <g...@xxxxxxxxxxxxxxxx> wrote:
Eduardo <edumlo...@xxxxxxxxx> wrote:
I have the following function written in C (available code downloaded
from the net) that i need to call from my fortran subroutine written
using F.03 standards
int write_xtc(XDR *xd,
             int natoms,int step,real time,
             matrix box,rvec *x,real prec)

Looking at:http://www.gromacs.org/documentation/reference/online/xtc.html

Since the Fortran and C routines have different names, it seems like
they might have used wrapper routines.

Within my subroutine these "matrix box" and  and "*x"  are allocatable
arrays. My problem is whether should i replace those real arguments
to pointers in my C subroutine AND create pointers in my f.03
subroutine to use as the arguments in the Call statement OR create
those variables and arrays in my f.03 subroutine as they are in the C
called function.

matrix is (float[3][3]) which should interoperate fine with a
Fortran (3,3) array, except the subscripts will be in the opposite
order.  

In most cases, calling a C routine from Fortran, the address of
(C pointer to) a variable or array is automatically passed.  

More interesting is (XDR*)

ftp://ftp.back2roots.org/pub/back2roots/cds/fred_fish/goldfish_vol2_9...

which presumably should be a C_PTR pointing to an appropriate
sized array.  It might be that an INTEGER array of the appropriate
size would be fine.

Or is there any other way to approach this problem?

Well, the other approach is wrapper routines which come
between your Fortran and the C routines.  

-- glen

Thank you Glen, i was thinking on writting a wraper indeed since my
corresponding matrix array is of allocatable type and because of that
i asked about the possibility to modify the c routine.


What's your caller look like?
--
larry gates

stab_val(stab)->str_nok = 1; /* what a wonderful hack! */
-- Larry Wall in stab.c from the perl source code

Hello Larry, this is how my previous (Fortran 77 standard) Call looks
like

CALL WRITEXTC(IDW,NATXTC,STEP,TIMEXTC,BOX,X1XTC,PREC,NRET)

X1XTC looks like this now
Real, Dimension(:), Allocatable, INTENT(INOUT)::X1XTC

Indeede BOX has a fixed form and the rest of the arguments are just
standard variables.
.



Relevant Pages

  • blas1 man page
    ... numerical analysis software community in quickly allowing subroutine ... The Level 1 BLAS perform basic vector-vector operations. ... Routines for scaling, copying, swapping, and computing linear ... the eariler indexes in an array declaration toggle first. ...
    (comp.lang.fortran)
  • blas1 man page
    ... numerical analysis software community in quickly allowing subroutine ... The Level 1 BLAS perform basic vector-vector operations. ... Routines for scaling, copying, swapping, and computing linear ... the eariler indexes in an array declaration toggle first. ...
    (sci.math.num-analysis)
  • Re: Need debugging help!
    ... The big question I have now is regarding the IBI dummy argument - it is ... The dummy argument is associated w/ the actual argument by sequence association so as long as the actual allocation of space in the caller is large enough to match the sizes passed to the subroutine there is sufficient space. ... Now, it's always possible there's a bug in the subroutine and the addressing computation is fouled up and exceeds the bounds, but that's not fundamentally because of the treatment of the 2D array as 1D vector per se. ... And, of course, it's always possible the corruption even if it is in this array or past is actually from some one or more of the other routines clobbering it instead. ...
    (comp.lang.fortran)
  • Re: F.03 C Interoperability doubt. Argument types
    ... from the net) that i need to call from my fortran subroutine written ... Since the Fortran and C routines have different names, ... Fortran array, except the subscripts will be in the opposite ...
    (comp.lang.fortran)
  • Re: Little help with recursion
    ... inner routines will be called multiple times with the same parameters. ... which will serve as a 'driver' subroutine. ... PRIVATE and the only thing PUBLIC is the driver subroutines, ... that is the Fortran 66 and Fortran 77 solution. ...
    (comp.lang.fortran)