Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using an array between C and FORTRAN

Status
Not open for further replies.

byter101

Programmer
Jul 6, 2009
10
US
Hello,
I cannot get a 3D array to work properly between c and fortran.
I put it in the fortran file (for.f90):

COMMON/ENVREAL/zwtemp(3,3,3)

so it should be global, then in the C file (c.c) it is:

extern struct {
double long zwtemp[3][3][3];
} envreal_;

yet when I try to assign a number to a position from the C file, say [1][1][1], it explodes all over my office. any ideas? I'm linking the two with the following commands:
gcc -c c.c
ifort -c for.f90
gcc -o out c.o for.o
 
sorry i figured it out. my value wasn't changing because I forgot that FORTRAN was 1 based and i was referencing the wrong spot. also, I concluded wrongly that a REAL(4) was equivalent to a double long, when it is simply a float. stupid stupid stupid
thank you for listening
 
You need to remember that Fortran and C store matrices in different orders. C can have two different ways to do a matrix. (1) vect(3)->matrix(3,3) or vect(3)->vect(3)->vect(3). Each entry in the first two vects are pointers. (2) matrix(3,3,3) but it is stored differently than Fortran.

BrooksVH
 
crap. well i'll take that into consideration if I get problems down the line.
i'm probably going to ask this in a separate post, but i have a simple question:
what does the ** mean in this line?

t1=2.0/(6316.0*zwtemp(ix,iy,iz)**(-1.55)+13609.0*zwtemp(ix,iy,iz)**(-1.86))

thanks bunches
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top