Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a Fortran subroutine with arbitrary number of arguments?

Tags:

fortran

First I want to say the answer is not about something like optional or present.

I want to define a function that looks like write(*,*) .... As we see, the number of input variants can be arbitrary. If we use the optional keyword, we need to define all the possible inputs. Assume that we have 1000 (possible) inputs, what can we do?

like image 839
hengyue li Avatar asked Nov 01 '25 05:11

hengyue li


1 Answers

You can't do anything with simple subroutine or Fortran arguments. It is simply not possible. You can only use arguments that are defined in the function.

You will have to either place everything into an array, if the types of all inputs are the same, or you will have to create some more complicated derived types - maybe a polymorphic linked list or similar.

Note that what you ask for does exist in some languages (C variadic functions, for example), but it does not exist in Fortran.

like image 167
Vladimir F Героям слава Avatar answered Nov 04 '25 01:11

Vladimir F Героям слава