I am responding to your email rather late, because I just got g95 up
and running in the netCDF nightly build system.
Mark Hadfield <m.hadfield@xxxxxxxxxx> writes:
> When code is being generated by a C compiler to be called by Fortran
> programs, as in the netCDF F77 interface, we have to worry about the
> Fortran compiler's name mangling. The G95 documentation describes its
> default behaviour thus: "G95 follows the f2c convention of adding an
> underscore to public names, or two underscores if the name contains an
> underscore." The other commonly used compiler that follows this
> convention is G77 (but its Gnu successor Gfortran just uses a single
> The f2c one/two-underscore behaviour is rather difficult to handle, as
> I found out when trying to build the MITgcm ocean model, see here:
> So I have decided to become 100% second-underscore-free. To do this I
> had to rebuild netCDF. Here is the necessary configure statement (used
> successfully with 3.6.2-beta4 on Linux, Cygwin and MSYS+MinGW):
> CC=gcc FC=g95 CPPFLAGS=-DpgiFortran FFLAGS=-fno-second-underscore
> FCFLAGS=-fno-second-underscore ./configure
> If you get it wrong, "make" completes OK, but "make test" fails when
> testing the Fortran code.
> Why am I sharing this with the group? Partly for posterity (AKA Google
> searches). But I have three questions/comments:
> 1. Perhaps this could be made the default? It would break G77
> compatibility and cause a bit of confusion in the short term, but in
> the long term I think we would all be better off.
Can you tell me what the consequences of this are?
Do g95 users have to use -fno-second-underscore when compiling a
fortran program with the netCDF library?
If I just set -Df2cFortran when compiling netCDF, g95 works without
any further fuss. What is wrong with doing that?
I have just added g95 to a number of our nightly test platforms. The
intention is to have netCDF 3.6.2 do the "right thing" for g95. Now I
just have to know what the right thing is!
> 2. I have to set both FFLAGS and FCFLAGS? Why? Surely one would do.
One is for F77, one for F90.
> 3. I note that the configure script reports (for example): "checking
> for C-equivalent to Fortran routine SUB... sub_". I haven't looked at
> the configure code, but I assume it is trying different C names (sub,
> sub_, SUB, etc) until it gets the right one. The subroutine/function
> names in the netCDF-3 F77 interface all have underscores. So why not
> do the test with a name that includes an underscore? Then the f2c
> name-mangling could be handled automagically?
Given that it knows what name mangling is in use, what would you like
configure to do?
At the moment configure automatically sets -Df2cFortran for g95, and
everything seems to work. What's wrong with that?
When you write fortran code for g95, won't the mangled names contain
the second underscore that the netCDF library expects? What's wrong
Thanks for the help! We can't be experts with every fortran compiler,
but we want netCDF to work with g95, so we count on experienced g95
users to give us input...
Ed Hartnett -- ed@xxxxxxxxxxxxxxxx
To unsubscribe netcdfgroup, visit: