Fortran: full array operations in fixed form source

I get the “Segmentation Error” error again and again when using my routines (I put them all in MODULE) with code written in a fixed form source (during fortran77 days).

The original make file (Linux platform) is a mess, it only compiles the source “.f”, so I had to change the extensions of my files from “.f90” to “.f” and left the first 7 columns empty in my modules. My modules make extensive use of whole massive operations and operations on array sections, and I declare F90-style variables, many of which are arrays of the estimated size.

My question is: although the compiler compiles these modules (with whole arrays / arrays) without any warnings / errors, it is a “segmentation error” due to the use of modules with whole arrays / arrays (stored in .f files) in outdated code ?

For example, I wrote the following code in the module "algorithm.f":

function dyad_vv(v1,v2) !dyadic product of two vectors real*8, dimension(:)::v1,v2 real*8, dimension(size(v1,1),size(v2,1))::dyad_vv integer i,j do i=1,size(v1,1) do j=1,size(v2,1) dyad_vv(i,j)=v1(i)*v2(j) end do end do end function !================================== function dot_mv(m,v) !dot product of a matrix and a vector real*8, dimension(:,:)::m real*8, dimension(:)::v real*8, dimension(size(m,1))::dot_mv integer i,j do i=1,size(m,1) dot_mv(i)=0.0000D0 do j=1,size(v,1) dot_mv(i)=dot_mv(i)+m(i,j)*v(j) end do end do end function !================================== function dot_vm(v,m) !dot product of a vector and a matrix real*8, dimension(:)::v real*8, dimension(:,:)::m real*8, dimension(size(m,2))::dot_vm integer i,j do i=1,size(m,2) dot_vm(i)=0.0000D0 do j=1,size(v,1) dot_vm(i)=dot_vm(i)+v(j)*m(j,i) end do end do end function 
+4
source share
1 answer

To expand on my already too long comment:

Segmentation errors in Fortran programs usually arise either from (a) an attempt to access an array element outside the boundaries of the array, or (b) valid mismatch procedure arguments and dummy arguments.

Fortunately, using your compiler intelligently can help you identify both of these situations. For (a) you need to enable checking the bounds of the array at runtime, and for (b) you need to enable checking the interface of the compile-time routine. In your compiler guide, you'll find out which checkboxes you need to set.

One of the advantages of modern Fortran, in particular modules is that, as a rule, you check the interface of the procedure, the compiler, at compile time, takes care of matching the dummy and actual arguments.

Therefore, I do not think that your problem is with writing modern Fortran in a form with a fixed source. But I think that writing modern Fortran in a fixed source format to avoid re-writing your makefile and avoiding updating any FORTRAN77 is a pretty perverted activity that will turn out to be painful in the short run, and regret it in the long run as you continue to develop degraded code.

Facing this, refactoring now.

+4
source

All Articles