Understanding Fortran 90 Arrays and Variables: A Few Simple Questions

  • Fortran
  • Thread starter napster
  • Start date
  • Tags
    Fortran
In summary, the complex number in Fortran is preceded by an assignment of say Complex :: C C=(1.0,2.0). So the U in the example is an array.
  • #1
napster
2
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
  • #2
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/" [Broken]
 
Last edited by a moderator:
  • #3
Hi Silverfrost!

Thanks for the reply! And the links are useful, it should make my programme a bit easier now :)
 

1. What is Fortran 90?

Fortran 90 is a high-level programming language used for scientific and engineering applications. It was released in 1991 and is an extension of the earlier Fortran 77 language, with added features for modern programming practices.

2. How is Fortran 90 different from previous versions?

Fortran 90 introduced many new features, such as free-form source code, modules, and dynamic memory allocation, that were not available in previous versions. It also removed some old features that were considered obsolete or restrictive.

3. What kind of programs can be written in Fortran 90?

Fortran 90 is primarily used for scientific and engineering applications, such as numerical analysis, computational fluid dynamics, and weather forecasting. It is also widely used in high-performance computing due to its ability to efficiently handle large datasets.

4. Is Fortran 90 still relevant today?

Yes, Fortran 90 is still widely used in scientific and engineering fields, and many legacy codes are written in this language. It is also continuously updated and improved, with the latest version being Fortran 2018.

5. Where can I learn Fortran 90?

There are many online resources and tutorials available for learning Fortran 90, such as the official Fortran website, online courses, and programming forums. You can also refer to textbooks and manuals for a more in-depth understanding of the language.

Similar threads

  • Programming and Computer Science
Replies
20
Views
3K
  • Programming and Computer Science
Replies
4
Views
463
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
16
Views
5K
  • Programming and Computer Science
7
Replies
235
Views
9K
  • Programming and Computer Science
Replies
4
Views
6K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top