- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
I would like to make a function or subroutine that handles arguments as flexibly as the MAX function. That is, pass in 1 to n individual integer variables . But I have no idea how to declare the variables. All the examples of optional variables I see have optional variables with individual names. Ideally, I would like them assigned to a single dimension array within the function (or subroutine) but passed in as individual values. Its too cumbersome to name (for example) 20 individual variables and check them all with separate if present statements. I need a do loop construct to check if they are present and if so do an operation with them. Is this possible with FORTRAN?
- Etiquetas:
- Intel® Fortran Compiler
Enlace copiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
No. If the variables are all scalars, all integer (or all of the same type) and their position in the argument list doesn't matter, why don't you directly pass in an array instead? [fortran]! In a module somewhere...
FUNCTION my_function(arr) INTEGER, INTENT(IN) :: arr(:) INTEGER :: my_function
!****
! Some fancy operation on an array here...
END FUNCTION
my_function r = my_function([1, 2, 3, some_integer_scalar_variable, ix * iy])[/fortran]
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
I don't think the solution with 2*20 optional arguments need be all that bad, see opt1.f90. You could define a UDT with default initialization and invoke with an extra layer like [fortran]call opt2(t20(label1,var1,label2,var2,label3,var3))[/fortran] see opt2.f90. Or you could use an assumed-shape array of structures like call [fortran]opt3([a1(label1,var1),a1(label2,var2),a1(label3,var3)])[/fortran] see opt3.f90.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado

- Suscribirse a un feed RSS
- Marcar tema como nuevo
- Marcar tema como leído
- Flotar este Tema para el usuario actual
- Favorito
- Suscribir
- Página de impresión sencilla