[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #UCV-396130]: Mixing F90 and F77 Function Calls



Good afternoon,

This is an interesting issue, and I will start by answering one of your later 
questions: this is not a known issue.  I suspect you are correct regarding this 
being an issue between C/Fortran integers/interfacing. May I ask what version 
of netCDF-Fortran (the Fortran interface library) you are using?  I am setting 
up an environment to try to begin duplicating this issue and want to ensure it 
is as close as possible.  Along those lines, if you can provide which OS you 
are working on, and whether it is 32/64 bit, that will also help.

Thank you very much!

-Ward


> Hi NetCDF team,
> 
> My name is Sasha, I'm a software engineer on MethaneSat, a satellite 
> atmospheric observatory. I have a question about the Fortran bindings of the 
> NetCDF library. I'm working with some legacy code, which uses the old style 
> Fortran bindings like so:
> 
> INCLUDE 'netcdf.inc'
> ...
> NF_OPEN("filename", NF_WRITE, ncid)
> 
> I've noticed that even with relatively small test files, this leads to a 
> weird segfault problem:
> 
> Program received signal SIGSEGV: Segmentation fault - invalid memory 
> reference.
> Backtrace for this error:
> #0  0x7f01a1b77692 in ???
> #1  0x7f01a1b76865 in ???
> #2  0x7f01a17e00bf in ???
> #3  0x7f01a1e543c5 in ???
> #4  0x7f01a1e4072f in ???
> #5  0x7f01a1e409a3 in ???
> #6  0x7f01a1f8f497 in ???
> #7  0x7f01a2035135 in ???
> #8  0x4011be in ???
> #9  0x401320 in ???
> #10  0x7f01a17c10b2 in ???
> #11  0x4010cd in ???
> #12  0xffffffffffffffff in ???
> Segmentation fault
> 
> I've been able to reproduce in a very minimal example, attached. Even when 
> switch to using a module import (use netcdf) and the nf90 function, the 
> problem appears to be the NF_WRITE constant. If I switch to using the 
> NF90_WRITE constant, though, the problem disappears. This works for my 
> minimal example, but in my larger codebase, even changing the constant does 
> not appear to fix the problem - possibly because I can replace all calls in a 
> single file, but replacing throughout the codebase is a heavier lift. I 
> imagine there's some C/Fortran integer style problems coming out here, but 
> I've been unable to build the C code from source in order to dive deeper. I 
> was wondering if this was a known problem and if there are any solutions? 
> I've tried using built versions of the code from both apt (4.7.3) and brew 
> (4.8.1) and see the same problem in both. I've been compiling with gfortran 
> 11.2.0_3 (command: gfortran repro.f90 -o repro `nf-config --fflags --flibs`). 
> Unfortunately, any a
 ttempts to run with valgrind magically resolve the issue and other debugging 
tools just show me the nf_open call as the lowest level I can see without 
building the NetCDF library with debug symbols.
> 
> Any guidance or advice would be greatly appreciated. I'm happy to keep 
> digging, so if there is any guidance on getting or building the netcdf tools 
> with debug symbols, that would also be helpful.
> 
> Best,
> Sasha.
> 
> 


Ticket Details
===================
Ticket ID: UCV-396130
Department: Support netCDF
Priority: Normal
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.