Understanding Fortran 90 Arrays and Variables: A Few Simple Questions

  • Context: Fortran 
  • Thread starter Thread starter napster
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary
SUMMARY

This discussion clarifies key concepts related to arrays and variable declarations in Fortran 90. The user confirms that an Allocatable complex array is indeed a complex array of numbers, as indicated by the declaration Complex (Kind=pr), Allocatable :: U(:,:,:). The colon notation in U(:, J, K) signifies an assumed shape array, allowing for dynamic indexing with DO loops. Additionally, it is established that Fortran's case insensitivity means Complex :: U(N,N) and Complex :: u(N,N) refer to the same variable, while variable scope ensures that differently declared variables do not interfere with each other.

PREREQUISITES
  • Understanding of Fortran 90 syntax and data types
  • Familiarity with complex numbers in Fortran
  • Knowledge of array declarations and indexing in Fortran
  • Concept of variable scope in programming
NEXT STEPS
  • Study Fortran 90 array handling and assumed shape arrays
  • Learn about variable scope and visibility in Fortran modules and subroutines
  • Explore Fortran 90 complex data types and their operations
  • Review best practices for variable naming conventions in Fortran
USEFUL FOR

This discussion is beneficial for novice Fortran programmers, students learning Fortran 90, and developers working with complex data structures in scientific computing.

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 :)
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 16 ·
Replies
16
Views
6K
  • · Replies 5 ·
Replies
5
Views
4K