Fortran Understanding Fortran 90 Arrays and Variables: A Few Simple Questions

  • Thread starter Thread starter napster
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The discussion focuses on several key questions regarding Fortran 90 programming, specifically related to complex arrays and variable scope. The user confirms that the declaration "Complex (Kind=pr), Allocatable :: U(:,:,:)" indeed defines U as an array of complex numbers. They seek clarification on the use of the colon in array indexing, which allows for dynamic changes to indices J and K within loops. The user also inquires about the case sensitivity of variable names in Fortran, confirming that "Complex :: U(N,N)" and "Complex :: u(N,N)" are equivalent, although maintaining consistent casing is advisable. Lastly, they explore the concept of variable scope, noting that parameters declared in different modules or subroutines do not interfere with each other unless explicitly called. If a subroutine calls a module where a variable is defined, the variable's type will depend on the context in which it is called. The discussion includes helpful resources for further understanding of arrays and scope in Fortran.
napster
Messages
2
Reaction score
0
Hey all!

I have a few simple questions but they have been wrecking my head for a while now, for Fortran 90:
1. I have the following Complex (Kind=pr), Allocatable :: U(:,:,:)
Does that mean that U is a complex array? And if so, I thought a complex number in Fortran is followed by an assignment of say Complex :: C C=(1.0,2.0). So I am probably just over thinking it, but is my U then an array, or a complex array?

I figured out this part, it's an array of complex numbers. Yay!


Then, I have something like U(:, J,K)=U_j, I am not sure how to phrase the question properly so I can google it, but the : part in the bracket, does that mean that whatever value I have there stays as is and I can have DO loops that can change J and K?

2. This is more of a general question, I know FORTRAN is not case sensitive, but when I am declaring variables, if I declare say Complex :: U(N,N) is it the same as declaring Complex :: u(N,N) ?

3. My code has a bunch of modules and subroutines that get called in different modules, subroutines and parts of the main code. So if I have a paramter U complex, declared in module1 and a different subroutine, say subroutine1 declares a parameter U but real, and subroutine1 doesn't call module1, then I guess my two differently declared U don't interfere? Both module1 and subroutine1 are in the same main code. And if subroutine1 did call module1 to execute something, which value would U have, real or complex?


Thanks for any help at all, I am currently trying to comment a code and have never programmed, so learning as I go along... I have several books but they don't seem to be as
 
Last edited:
Technology news on Phys.org
Hi Napster

1. You might like to take a look at this documentation, it explains all about Fortran arrays (much better than I can). When using a colon it is called an assumed shape array: http://publib.boulder.ibm.com/infoc.../com.ibm.xlf101a.doc/xlflr/arrays.htm#arrays"

2. You are correct that Fortran is not case sensitive, so u(80) and U(80) refer to the same thing. As a general principle it is probably best to keep the case the same though.

3. There is a conecpt called 'scope' and it controls what variables are visible where. So in

Code:
module foo

subroutine bar(u)
complex u
end

subroutine bar1(u)
integer u
end

end

The argument u in bar and bar1 is different in each case. The 'u'-ness, if you like, is restricted to the place it is contained within. A bit more to read: http://www1.gantep.edu.tr/~andrew/ep241/docs/scope/"
 
Last edited by a moderator:
Hi Silverfrost!

Thanks for the reply! And the links are useful, it should make my programme a bit easier now :)
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
20
Views
3K
Replies
3
Views
2K
Replies
59
Views
11K
Replies
8
Views
4K
Replies
4
Views
2K
Replies
4
Views
2K
Replies
16
Views
6K
Replies
5
Views
3K
Back
Top