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

Beginner fortran question - starting with a new slate

  1. Sep 26, 2008 #1
    Hi All

    I am new to fortran and there are things that I believe fortran should do and don't know how to do it - I am using fortran 77.

    1- I know how to declare variables, but i do not know how to make sure that i start out with zeros and not use old data that might have been stored by a previous program run or randomly assigned by the memory. (the equivalent of clear all in matlab)

    2- If i declare a 3 by 3 matrix called A, and I want to assign the value 4 for each of the elements of the matrix, what is the simplest way of doing that? Setting A=4 did not work for me. I can put it in a loop but i feel there has to be an easier way if i am doing something as simple as this. [in matlab i would simply say A(:,:)=4]

    Thanks for your help in advance.
  2. jcsd
  3. Sep 26, 2008 #2


    User Avatar

    Staff: Mentor

    Unfortunately, there are no shortcuts. Set every variable to zero, use loops to initialize array.
  4. Sep 26, 2008 #3
    Thanks for the prompt reply Borek. I am glad I asked instead of banging my head against the screen until next week. Thanks again.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook