Can You Use Nested Subroutines in Fortran95 and How Do You Link Them?

In summary, the conversation discusses the possibility of having subroutines nested within subroutines in Fortran95 and if there are any other types of subprograms besides functions and subroutines that can pass back an array. The question of how to link nested subroutines is also raised. It is mentioned that returning an array is possible and the individual is looking for clarification on how to do so in their program for solving linear equations. The issue of passing the matrix back to the gauss seidel subroutine is also mentioned.
  • #1
dichotomy
24
0
basic question really...can you have subroutines nested within subroutines? or are there any other types of subprograms within fortran95 other than functions and subroutines? (need one that can pass back an array)

if you can [use subs within subs], how do you link them? like in the main program you have to use an INTERFACE-END INTERFACE construction to link to the subroutine...

ta in advance
 
Technology news on Phys.org
  • #2
Not sure about subroutines within a subroutine, gut feeling is that it won't work. As for returning an array, that is possible.
 
  • #3
erm...could you elaborate? I'm writing a program that solves linear equations with gauss seidel iteration (and gauss/gauss jordan elimination), so there's a main program which calls the various methods as subroutines...

except within the gauss seidel subroutine I want to separate a bit which makes the matrix diagonally dominant(ish)...obviously after rearranging the rows the matrix needs to be passed back to the gauss seidel subroutine.
 

1. What is the purpose of structuring a Fortran program?

The purpose of structuring a Fortran program is to make it easier to read, understand, and maintain. It also helps to organize the code into logical units, making it more efficient and less prone to errors.

2. What are the key elements of a Fortran program structure?

The key elements of a Fortran program structure include modules, subroutines, functions, and the main program. Modules allow for the encapsulation of related data and procedures, subroutines are used to perform specific tasks, functions return a value, and the main program is the starting point of the program execution.

3. How are modules used in Fortran program structuring?

Modules are used to group related data and procedures together, making it easier to access and use them within the program. They also help to avoid naming conflicts and improve the overall organization of the code.

4. What is the difference between a subroutine and a function in Fortran?

A subroutine is a set of code that performs a specific task and does not return a value. It can accept input parameters and modify them, but it cannot return a value. On the other hand, a function is a set of code that performs a specific task and returns a value. It can accept input parameters, process them, and return a single value as a result.

5. How can proper program structuring improve the performance of a Fortran program?

Proper program structuring can improve the performance of a Fortran program by reducing the amount of code that needs to be executed and optimizing the use of system resources. It also helps to identify and fix errors more efficiently, leading to faster and more efficient execution of the program.

Similar threads

  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
5
Views
7K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
22
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
6
Views
3K
Back
Top