TEOS-10 / GSW-Fortran

Gibbs-SeaWater (GSW) Oceanographic Toolbox in Fortran
http://www.teos-10.org
15 stars 15 forks source link

compilation fails with gfortran 12.1.0 #23

Open jornbr opened 2 years ago

jornbr commented 2 years ago

With gfortran 12.1.0 a large number of errors like one below are reported. Compilation thus does not succeed.

.../GSW-Fortran/modules/gsw_mod_check_data.f90:781:30:

781 | "C_from_SP", 6.1638e-10_r8, (/ & | 1 Error: The rank of the element in the structure constructor at (1) does not match that of the component (1/2)

It seems that this gfortran release does not like 1D data to be assigned to a 2D array. This is not a problem for earlier gfortran releases, nor for intel fortran. I'm not sure whether gfortran 12 is overly strict in its interpretation of the Fortran standards here, or the others are too lenient...

jornbr commented 2 years ago

Just to add that gfortran 10.4.0 and 11.3.0 are also affected by this. gfortran 9.5.0 is ok.

bolding commented 2 years ago

I've found a fix - but it is quite tedious to implement. So before proceeding I have the following questions:

1) Shall we wait and see if gfortran is fixed?

2) Is the file gsw_mod_check_data.f90 auto generated - or created in an editor?

The fix is to explicit put a reshape in for all 2d arrays when they are part of a type. There is more than 200 places to fix. So if the file is auto generated the issue should be fixed during the generation. If not auto generated some clever search and replace might do the most of the work.

jornbr commented 2 years ago

Since this problem did not occur with any gfortran version from before May 2022, nor with ifort, it looked like it could be a gfortran bug. However, it is not: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106684. Thus the code would need a fix. Use of reshape as mentioned above is an option, and the bugzilla thread also mentions an alternative at the very bottom.

bolding commented 2 years ago

Code similar to this

image

fails.

There at least two solutions: 1) explicitly add a reshape to the array argument of the initialsation 2) explicitly specify the variables of the type during initialisation

The double reshape is more error prone so the 2. method have been chosen resulting in code similar to: image

And this solution is also more in line with how the simple variables are initialized.

The new code has been checked on gfortran (9.4.0, 10.3.0, 11.2.0 and 12.0.1) on Linux Mint (Ubuntu). The old code fails with 10.3.0, 11.2.0 and 12.0.1.

bolding commented 2 years ago

The pull request has been extended to include a Github Actions file - that - upon a git push - will compile GSW-Fortran and run the test programs gsw_check_functions.x and gsw_poly_check.x on the Github infrastructure.

Results can be inspected here - https://github.com/TEOS-10/GSW-Fortran/actions.

At present gfortran version 9, 10 and 11 are checked using Ubuntu.