Unidata / netcdf-fortran

Official GitHub repository for netCDF-Fortran libraries, which depend on the netCDF C library. Install the netCDF C library first.
Other
236 stars 95 forks source link

How to resolve ''Fatal Error: Can't open module file ‘netcdf.mod’ for reading....." #205

Open anserwei opened 4 years ago

anserwei commented 4 years ago

Hi, I am a beginner who is learning how to read and write a netcdf file with Fortran 90. I got some problems. Could someone help me?

So, could someone help me? I appreciate it. Thank you so much.

edhartnett commented 4 years ago

Try using -I/Users/Jim/anaconda3/include as an argument in gfortran.

anserwei commented 4 years ago

Try using -I/Users/Jim/anaconda3/include as an argument in gfortran.

Thank you. Could you tell me more details about how to use -I/Users/Jim/anaconda3/include as an argument in gfortran.

WardF commented 4 years ago

When you run make, you'll specify FFLAGS="-I/Users/Jim/anaconda3/include on the command line, or alternatively you can set the FFLAGS environmental variable.

anserwei commented 4 years ago

When you run make, you'll specify FFLAGS="-I/Users/Jim/anaconda3/include on the command line, or alternatively you can set the FFLAGS environmental variable.

Hi, thanks for your response. But, the error is still there.

image image

And, nothing is related to netcdf in ''/usr/local/include".

image image

image image

image image

image image

image image

Thus, so frustrated...... Could you help me more? Thank you so much.

edhartnett commented 4 years ago

Try:

gfortran -I/Users/Jim/anaconda3/include -L/Users/Jim/anaconda3/lib simple_xy_nc4_wr.f90

But I believe you will also need some additional arguments to make that work. Run nf_config to get more information about what arguments you need to set.

Frustration will continue until you learn about the -I and the -L options of your compiler. There is ample documentation online. For example, from https://linux.die.net/man/1/gfortran.

-Idir
    These affect interpretation of the "INCLUDE" directive (as well as of the "#include" directive of the cpp preprocessor).

    Also note that the general behavior of -I and "INCLUDE" is pretty much the same as of -I with "#include" in the cpp preprocessor, with regard to looking for header.gcc files and other such things.

    This path is also used to search for .mod files when previously compiled modules are required by a "USE" statement. 

Most users do not compile using gfortran from the command line, but using make, or (if they're extra-clever) automake/autoconf/libtool. Within such systems you will find respect for environmental flags like FCFLAGS, FFLAGS, CPPFLAGS, etc. More info is available on-line.

anserwei commented 4 years ago

Thank you! I read Unidata NetCDF Fortran Library on website:

https://www.unidata.ucar.edu/software/netcdf/docs-fortran/

And, I also read some information about how to set env variables. After trying many times, I can successfully read/write netCDF files with fortran90.

edwardhartnett commented 4 years ago

Seems like this issue can be closed now.

moslem1994 commented 3 years ago

My problem was solved with the following command, I hope it paves the way for you too. sudo apt-get install netcdf-bin