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

  • Context: Fortran 
  • Thread starter Thread starter krishvk
  • Start date Start date
  • Tags Tags
    Fortran Programming
Click For Summary
SUMMARY

This discussion addresses issues related to passing values between subroutines in FORTRAN, specifically when using INTENT(IN) for variables. The user encountered unexpected high values when attempting to print variables calculated in SUB3 after calling it from SUB2. The problem is likely due to variable scope, where values are assigned to local variables instead of being passed correctly. The discussion emphasizes the importance of understanding subroutine interactions and variable visibility in FORTRAN programming.

PREREQUISITES
  • Understanding of FORTRAN subroutines and their structure
  • Knowledge of variable scope in programming
  • Familiarity with the INTENT attribute in FORTRAN
  • Basic debugging techniques in FORTRAN
NEXT STEPS
  • Review FORTRAN subroutine structure and variable scope
  • Learn about the INTENT attribute and its proper usage in FORTRAN
  • Explore debugging techniques specific to FORTRAN programming
  • Examine examples of passing variables between subroutines in FORTRAN
USEFUL FOR

This discussion is beneficial for FORTRAN programmers, especially beginners, who are troubleshooting issues with subroutine interactions and variable management. It is also useful for educators teaching FORTRAN programming concepts.

krishvk
Messages
1
Reaction score
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
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!
 
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?
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
8K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K