How to pass subroutine names as arguments in Fortran?

It is call action(mySubX) provided action looks as subroutine action(sub) !either – not recommmended, it is old FORTRAN77 style external sub !or – recommended interface subroutine sub(aA, aB) integer,intent(…) :: aA, aB end subroutine end interface ! NOT BOTH!! call sub(argA, argB) provided action knows what to put there as argA, argB to represent aA, … Read more

Skip a line from text file in Fortran90

One possible solution has already been presented to you which uses a “dummy variable”, but I just wanted to add that you don’t even need a dummy variable, just a blank read statement before entering the loop is enough: open(18, file=”m3dv.dat”) read(18,*) do … The other answers are correct but this can improve conciseness and … Read more

Difference between intent(out) and intent(inout)

intent(inout) and intent(out) are certainly not the same. You have noted why, although you don’t draw the correct conclusion. On entering the subroutine useless a is undefined, rather than defined. Having a variable “undefined” means that you cannot rely on a specific behaviour when you reference it. You observed that the variable a had a … Read more

Function in fortran, passing array in, receiving array out

With RESULT(FluxArray), fluxArray is the name of the result variable. As such, your attempt to declare the characteristics in the result clause are mis-placed. Instead, the result variable should be specified within the function body: function Flux(W1,W2) result(fluxArray) double precision, dimension(3), intent(in)::W1, W2 double precision, dimension(3) :: fluxArray ! Note, no intent for result. end … Read more

gfortran does not allow character arrays with varying component lengths

You have some lengths 12 in the constructor, so it may be better to use length 12. Also, use instead character(len=12), dimension(5) :: models = [character(len=12) :: “feddes.swp”, & “jarvis89.swp”, “jarvis10.swp”, “pem.swp”, “van.swp”] Possibly even better, if you have compiler support, is character(len=*), dimension(*) :: …

What are the ways to pass a set of variable values through the subroutine to a function without common block?

What you care about here is association: you want to be able to associate entities in the function f with those in the subroutine condat. Storage association is one way to do this, which is what the common block is doing. There are other forms of association which can be useful. These are use association … Read more

How do I do big integers in Fortran?

There is no built-in “big number” support, but we can first check whether there is a larger integer kind available (as mentioned by Francescalus above and also many previous pages (e.g. this page). On my computer with gfortran-6.1, the compiler seems to support 128-bit integer kind, so I could calculate the result up to n=160 … Read more

tech