changing array dimensions in fortran

See the RESHAPE intrinsic, e.g. http://gcc.gnu.org/onlinedocs/gfortran/RESHAPE.html Alternatively, if you want to avoid the copy (in some cases an optimizing compiler might be able to do a reshape without copying, e.g. if the RHS array is not used afterwards, but I wouldn’t count on it), as of Fortran 2003 you can assign pointers to targets of … Read more

OS X package installation depends on gfortran-4.8

Type these two lines in your terminal, direct quote: curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2 sudo tar fvxj gfortran-4.8.2-darwin13.tar.bz2 -C / It will download you the gfortran for Mavericks (which is missing in your system at the moment) and will install it in your system. At least, this solved the same problem for me (I’m running late 2011 … Read more

Correct use of modules, subroutines and functions in Fortran

Modules are always the right thing to use 😉 If you have a very simple F90 program you can include functions and subroutines in the ‘contains’ block: program simple implicit none integer :: x, y x = … y = myfunc(x) contains function myfunc(x) result(y) implicit none integer, intent(in) :: x integer :: y … … Read more

Reading a binary file with python

Read the binary file content like this: with open(fileName, mode=”rb”) as file: # b is important -> binary fileContent = file.read() then “unpack” binary data using struct.unpack: The start bytes: struct.unpack(“iiiii”, fileContent[:20]) The body: ignore the heading bytes and the trailing byte (= 24); The remaining part forms the body, to know the number of … Read more

Passing external function of multiple variables as a function of one variable in Fortran

You cannot make similar tricks with functions in Fortran directly. You also cannot return a closure in Fortran. Just write a wrapper. function wrap_f(x) result(res) … res = f(a,b,…) end function It can be an internal or module function and get a and b by the host association or it can use the module containing … Read more

Procedure with assumed-shape dummy argument must have an explicit interface [duplicate]

Assumed shape dummy arguments (those with (:)) require explicit interface to the procedure to be available at the call site. That means the calling code must know how exactly the subroutine header looks like. See also Module calling an external procedure with implicit interface That explicit interface can be provided in several ways 1. preferred … Read more