Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

INDEX statement or INDEX intrinsic function?

INDEX statement or INDEX intrinsic function?

INDEX statement or INDEX intrinsic function?

Hello everyone, I have the following subroutine code (it is a textual copy of a document):

1 subroutine contin(grid,nx,ny,dx,dy,dz,store)
2 dimension grid(nx*ny),store(2*nx*ny),nn(2)
3 real kx,ky,k
4 complex cgrid,cmplx
5 data pi/3.14159265/
6 index(i,j,ncol)=(j-l)*ncol+i
7 nn(1)=ny
8 nn(2)=nx
9 ndim=2
10 dkx=2.*pi/(nx*dx)
11 dky=2.*pi/(ny*dy)
12 do 10 j=l,nx
13 do 10 i=l,ny
14 ij=index(i,j,ny)
15 store(2*ij-l)=grid(ij)
16 10 store(2*ij)=0.

My doubt is in line 5, with the INDEX function in the the index(i,j,ncol)=(j-l)*ncol+i. I have been checking and the INDEX is a fortran intrinsic function but in this case they are using it as a variable. I am using GFORTRAN to compile the subroutine.

Does anyone understand what they are trying to do whit the INDEX statement in line 5?

I appreciate any coments. Best regards.

RE: INDEX statement or INDEX intrinsic function?

Hhhmmm...you say is a textual copy, but it does not look correct at all...did you copy/paste or re-typed it? There are typos and a bunch of variables not being declared, etc. For example, there seem to be several letters 'l' (lower case 'L') instead of the number 1.

In any case, the function "index(i,j,ncol) = (j-1)*ncol + i " is basically turning a 2D index set (i,j) into a single 1D index.

In other words, when you have a 2D matrix, you typically refer to the entries in the various locations via both row and column indices (i,j)...but in reality, all this memory is actually stored in a way that behaves as a one-dimensional array, i.e., you use a single memory address to find something...a single array index, if you will.

Fortran stores matrices in column-major order, this means that if you go to the computer memory, you will find entry (1,1) followed by entry (2,1), all the way to the bottom entry of the first column and then the entire first column followed by the second column.

The index function listed above does the conversion from (i,j) to a single column-major index.

And yes, INDEX is already a Fortran intrinsic to find out where a substring starts within a string...I would stay away from re-using names...best to rename your index function to something else: indx or something.

RE: INDEX statement or INDEX intrinsic function?


Yes, I copy/paste.
The typos like 'l' instead of '1' are my mistake, I did not notice them.
Yes, there are a bunch of variables that are not declare, like the variable 'ncol'. This 'ncol' is the one that made me think that I had to use INDEX as an intrinsic function.

Thank you for your answer, I will now check how to work with the 'single column-major index' that you mentioned.

Best regards.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close