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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unfinished loop accessing a C array from Fortran subroutine

Status
Not open for further replies.

Radamantis

Programmer
Jun 27, 2008
2
IT
Hi, i'm a new user in this forum and this is my first post.

That's my problem: i need to call a fortran subroutine using as input parameter an array declared in C, using malloc.

Code:
int *bin = (int*)malloc(sizeof(int)*natoms);
int *binpnt (int*)malloc(sizeof(int)*natoms);

the subroutine accepts and fills the array using this code:

Code:
      do i = 1,nbinx*nbiny*nbinz
        binpnt(i) = 0
      enddo
      
      do i = 1,natoms
        ix = (x(1,i) + xprd2) / binsizex
        iy = (x(2,i) + yprd2) / binsizey
        iz = (x(3,i) + zprd2) / binsizez
        ib = iz*nbiny*nbinx + iy*nbinx + ix + 1
        bin(i) = binpnt(ib)
        binpnt(ib) = i
      enddo

after, when executes this code:
Code:
   do i=nstart,nend
     <omitted>
        do k=0,26
          <omitted>
          ib = iz*nbiny*nbinx + iy*nbinx + ix + 1
          j = binpnt(ib)
 10       if (j.ne.0) then
          <omitted>
           j = bin(j)
            goto 10
           endif
        enddo
   enddo

(the parts marked as "omitted" doesn't affect the involved variables) it loops infinitely when i=17 and k=13. What's wrong?

If it could be helpful, the subroutine is declared as follows:

Code:
subroutine neighbor1(bin,binpnt,dim_bin,dim_binpnt)
    integer,intent(in)::dim_bin
    integer,intent(in)::dim_binpnt
    integer,intent(inout),dimension(dim_bin)::bin
    integer,intent(inout),dimension(dim_binpnt)::binpnt

Thanks a lot in advance.
 
Before Fortran 2003, this is implementation dependent.

1) Whose implementation of Fortran (Microsoft, GNU, Silverlight, Intel etc) and which version (77, 90, 95..) are you using?

2) Also whose version of C (GNU, Microsoft, etc) are you using? Sometimes, vendors' versions are compatible (eg IVF and MSC) sometimes they aren't (eg G77 and MSC). With some combinations, you're flogging a dead horse.

3) If it is Microsoft, which version of Visual Studio are you using? Need to know as IVF works OK with 2003 but I've had problems with 2005.
 
Hi xwb, thanks a lot for your answer.

I'm using the GNU implementation for both Fortran and C, and Fortran version is 95.

In the previous post i didn't say that i'm working on a PowerPC architecture with Fedora Core 7 as operating system...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top