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

Fortran array declarations

  1. Sep 3, 2014 #1

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    Hi, I'm just wondering real quick, are equations allowed in array declarations? For example:

    int :: y=2
    int, dimension(2*y):: x

    ?
     
  2. jcsd
  3. Sep 4, 2014 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

  4. Sep 4, 2014 #3

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    So even if y were a parameter, probably I still can't do that?

    EDIT: I looked at a later part of the lecture and he had something like what I have except y is a parameter. So I think I'm doing OK. Thanks. :)
     
  5. Sep 4, 2014 #4

    Mark44

    Staff: Mentor

    The whole point of a parameter in Fortran is that the parameter's value is known at compile time, so the compiler knows how much memory to allocate for the array. For a variable (not a parameter), the variable gets its value at run time, I believe.

    Minor point. A statement such as y = 2 is an assignment, or in this case an initialization, not an equation. It does not state that y and 2 are equal. Instead, it stores the constant value 2 in the location that is named y.

    Most programming languages make distinctions between assignment and testing for equality by using different symbols. For example, Fortran uses .EQ. to test for equality, and uses = for assignment. Languages based on C, such as C++, C#, Java, and others, use == to test for equality and = for assignment. Newer versions of Fortran now support the C-style notation, in addition to the older .EQ., .LT., GT., and other spelled-out relational operators.
     
  6. Sep 4, 2014 #5

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    Yes, I forgot to include that y is a parameter, and my language is lazy because I'm not a programmer really. Sorry for the confusion. :P

    I just wanted to make sure that the statement

    real, dimension(2*y)::x

    is legitimate if y is a parameter, and Steamking's link had something just like that in it.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran array declarations
  1. Fortran 3D array (Replies: 3)

Loading...