Beginner fortran question - starting with a new slate

In summary, the individual is new to Fortran 77 and is unfamiliar with certain tasks such as clearing old data and assigning values to a matrix. They were hoping for a simpler method but were informed that looping is necessary to initialize arrays.
  • #1
Moly
21
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
  • #2
Unfortunately, there are no shortcuts. Set every variable to zero, use loops to initialize array.
 
  • #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.
 

What is Fortran?

Fortran is a high-level programming language designed for scientific and engineering applications. It was developed in the 1950s and is known for its powerful array and mathematical manipulation capabilities.

How do I begin learning Fortran?

The best way to start learning Fortran is by familiarizing yourself with the basics of programming, such as data types, variables, and control structures. You can then move on to learning the specific syntax and features of Fortran through online tutorials, books, or courses.

Do I need any special tools to write and run Fortran programs?

Yes, you will need a Fortran compiler to convert your code into a format that the computer can understand and execute. Popular options include GNU Fortran and Intel Fortran. You will also need a text editor or integrated development environment (IDE) to write your code.

What are some common mistakes beginners make when learning Fortran?

Some common mistakes beginners make when learning Fortran include forgetting to declare variables, not following the correct syntax for statements, and using incorrect data types. It's important to carefully read through the documentation and practice writing and debugging code to avoid these mistakes.

Can I use Fortran for any type of programming?

While Fortran is primarily used for scientific and engineering applications, it can also be used for general purpose programming. However, it may not be as suitable as other languages for tasks such as web development or mobile app development.

Similar threads

  • Programming and Computer Science
2
Replies
37
Views
3K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
4
Views
7K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
5
Views
2K
Back
Top