Vector multiplication using MATMUL in Fortran
The problem is that x(1:9,1) isn’t of shape [9 1] but [9]. You need to use x(1:9, 1:1). The same goes for m.
The problem is that x(1:9,1) isn’t of shape [9 1] but [9]. You need to use x(1:9, 1:1). The same goes for m.
In Fortran 77 & 90/95/2003, if you want the value of a variable local to a subroutine preserved across subroutine calls, you should declare it the “save” attribute, e.g., (using Fortran 90 style): integer, save :: counter OR integer :: counter save :: counter . Or, if you want the “save” behavior to apply to … Read more
Here is a Stack Overflow question with some code examples showing several ways of using Fortran allocatable arrays: How to get priorly-unkown array as the output of a function in Fortran: declaring, allocating, testing for being already being allocated, using the new move_alloc and allocation on assignment. Not shown there is explicit deallocation, since the … Read more
Is it currently possible to override the structure constructor in Fortran? No. Anyway even using your approach is completely not about constructor overriding. The main reason is that structure constructor # OOP constructor. There is some similarity but this is just another idea. You can not use your non-intrinsic function in initialization expression. You can … Read more
According to The Fortran 2003 Handbook by Adams, et al., there is one difference between an intent(inout) argument and argument without specified intent. The actual argument (i.e., in the caller) in the intent(inout) case must always be definable. If the intent is not specified, the argument must be definable if execution of the subroutine attempts … Read more
You want to use allocatable arrays: PROGRAM mytest IMPLICIT NONE INTEGER :: i, j, k, mysum REAL, DIMENSION(:,:), allocatable :: c !<- c is allocatable, rank 2 ! Let array c be a k-by-k**2 array ! Determine k within the program by some means…for example, mysum=0 DO i=1, 3 mysum=mysum+1 END DO k=mysum WRITE(*,*) “k=”, … Read more
As already answered, you need to specify widths. Something like ES14.5 might work well for the floating point format. There is a short cut for the integer format: I0 will cause the compiler to use the number of digits needed.
Under the rules of current Fortran (Fortran 2008, but this is the same for when C interoperability was introduced in Fortran 2003), a Fortran procedure is not interoperable with C if it has an assumed shape dummy argument (other restrictions also apply). In your code degC, the dummy argument in the function DegCtoF, declared as … Read more
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
There are no templates in Fortran and hence no STL. You can try FLIBS for some generic libraries. It generally uses transfer() tricks to achieve generic programming. There is a preprocessor which adds some templates to Fortran and comes with some small STL, you can try that too named PyF95++. If you have access to … Read more