Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Simple Fortran 90 questions

  1. Nov 11, 2009 #1
    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: Nov 11, 2009
  2. jcsd
  3. Nov 12, 2009 #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 (Text):

    module foo

    subroutine bar(u)
    complex u

    subroutine bar1(u)
    integer u

    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: May 4, 2017
  4. Nov 13, 2009 #3
    Hi Silverfrost!

    Thanks for the reply! And the links are useful, it should make my programme a bit easier now :)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook