How can I fix issues with passing values between subroutines in FORTRAN?

In summary, A user is trying to modify a FORTRAN code by adding a subroutine to calculate a variable. However, when trying to print out the values, they are not what is expected. The user is asking for suggestions and help with debugging their code, and it is suggested that they provide a code snippet for easier understanding. The problem may be related to variable scope.
  • #1
krishvk
1
0
Hi all,

Greetings.

This could be a basic question, and if it is, pardon me for my ignorance as I am a newbie to FORTRAN. I am trying to modify a FORTRAN code where I have added a subroutine (say SUB1) to calculate a variable, say (QX). What I did is to call this subroutine in another one (called SUB2) where all the input variables, except two, needed to calculate QX is specified / calculated. In order to get the aforementioned two variables, I called the subroutine (lets call it SUB3) dealing with them in the beginning of SUB2. When I am trying to print it out they are not passing the values I expect, but are passing very high values.

What is it that I am doing wrong here? And please note that the two variables from SUB3 are not changed in the subroutine SUB2. I tried to use INTENT(IN) for these variables; and the code in return dumped an error "Error: Symbol at (1) is not a DUMMY variable".

Any suggestion would be appreciated. Thank you for your time.
Cheers.
 
Technology news on Phys.org
  • #2
It would help if you attach some code that doesn't work. You can probably remove all the calcs to make it shorter and easier for other people to understand.

Debugging code that you can see is sometimes hard. Debugging code that you can't see is even harder!
 
  • #3
Hi krishvk, as AlephZero said, you really need to post some code if we are to figure this out.

I think it's quite likely however that your problem is related to variable "scope". Are you perhaps assigning these values only to "local variables" in one of the subroutines?
 

FAQ: How can I fix issues with passing values between subroutines in FORTRAN?

What is Fortran programming?

Fortran (short for Formula Translation) is a high-level programming language used for scientific and engineering applications. It was first developed in the 1950s and is still widely used today due to its efficiency and performance in handling complex mathematical and scientific calculations.

What are the main features of Fortran?

Fortran is a compiled language, meaning the code is translated into machine-readable instructions before execution. It is also strongly typed, which means variables must be declared with a specific data type. Other key features include efficient handling of arrays and built-in support for mathematical operations and scientific notation.

How is Fortran different from other programming languages?

Fortran is primarily designed for scientific and numerical computing, which sets it apart from other general-purpose programming languages. It also has a fixed formatting style, with specific rules for indentation and line length, which may be different from the more flexible formatting of other languages.

How do I get started with Fortran programming?

You can download a Fortran compiler, such as GNU Fortran or Intel Fortran, to start writing and executing code. It is also helpful to have a basic understanding of programming concepts and algorithms, as well as some knowledge of mathematical and scientific principles.

What are some common applications of Fortran?

Fortran is commonly used in fields such as physics, engineering, and computational chemistry, where complex mathematical and scientific calculations are required. It is also used in developing weather forecasting and climate modeling systems, as well as in the design and optimization of software for high-performance computing.

Similar threads

Replies
59
Views
10K
Replies
4
Views
2K
Replies
5
Views
3K
Replies
4
Views
2K
Replies
5
Views
7K
Replies
4
Views
2K
Replies
11
Views
1K
Replies
2
Views
2K
Back
Top