Fortran Beginner fortran question - starting with a new slate

  • Thread starter Thread starter Moly
  • Start date Start date
  • Tags Tags
    Beginner Fortran
AI Thread Summary
In the discussion, a new Fortran 77 user seeks guidance on two main issues. First, they want to ensure that variables start with zero values to avoid using old or random data, similar to MATLAB's "clear all" function. The response emphasizes that there are no shortcuts in Fortran; users must manually set each variable to zero. Second, the user inquires about efficiently assigning the value 4 to all elements of a 3x3 matrix. They note that their attempt to use A=4 was unsuccessful and express a desire for a simpler method than looping through each element. The reply confirms that initializing arrays in Fortran typically requires loops, reinforcing the need for manual assignments in this programming environment.
Moly
Messages
20
Reaction score
0
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.
 
Technology news on Phys.org
Unfortunately, there are no shortcuts. Set every variable to zero, use loops to initialize array.
 
Thanks for the prompt reply Borek. I am glad I asked instead of banging my head against the screen until next week. Thanks again.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
3
Views
2K
Replies
2
Views
3K
Replies
2
Views
2K
Replies
4
Views
2K
Replies
8
Views
2K
Replies
3
Views
1K
Replies
8
Views
4K
Back
Top