Compilation program to read NetCDF file with fortran90 
Author Message
 Compilation program to read NetCDF file with fortran90

I am a student in Kyoto University in Kyoto, Japan.

I want to read and write files in NetCDF, so at first I am going to
read values of files written in NetCDF.
The file to read is below.

*********************************************
implicit none
include 'netcdf.inc'

integer :: ncid,status,varid
real,dimension(100,100,26) :: UDATA
!real,dimension(99,99,27)   :: WDATA

status   =  NF_OPEN ('wrfout_d01_2006-01-01_00:00:00',0,ncid)
if (status .ne. NF_NOERR) call HANDLE_ERR(STATUS)

status = nf_inq_varid (ncid, "U", varid)
if (status .ne. NF_NOERR) then
  write(6,*) "VAR ERROR"
  stop
endif

status = nf_get_var_real (ncid,varid,UDATA)
if(status .ne. NF_NOERR) then
  write(6,*) "READ ERROR"
  stop
endif

status = nf_close(ncid)

write(6,*) ncid,varid

stop
end
*************************************************

And then, I typed

$ ifort -c -I/usr/local/netcdf-3.6.2/include 1st.f90
$ ifort -lnetcdf -L/usr/local/netcdf-3.6.2/lib 1st.o -o a.out

Then, I got these errors.

1st.o -o a.out
1st.o: In function `MAIN__':
1st.f90:(.text+0x46): undefined reference to `nf_open_'
1st.f90:(.text+0x76): undefined reference to `nf_inq_varid_'
1st.f90:(.text+0xa1): undefined reference to `nf_get_var_real_'
1st.f90:(.text+0x11a): undefined reference to `nf_close_'
1st.f90:(.text+0x30a): undefined reference to `handle_err_'

If you know something about these errors, please give me information
anything you have.

Hiroshi



Mon, 05 Sep 2011 16:27:17 GMT  
 Compilation program to read NetCDF file with fortran90

Quote:
> I am a student in Kyoto University in Kyoto, Japan.

> I want to read and write files in NetCDF, so at first I am going to
> read values of files written in NetCDF.
> The file to read is below.

> *********************************************
> implicit none
> include 'netcdf.inc'

> integer :: ncid,status,varid
> real,dimension(100,100,26) :: UDATA
> !real,dimension(99,99,27) ? :: WDATA

> status ? = ?NF_OPEN ('wrfout_d01_2006-01-01_00:00:00',0,ncid)
> if (status .ne. NF_NOERR) call HANDLE_ERR(STATUS)

> status = nf_inq_varid (ncid, "U", varid)
> if (status .ne. NF_NOERR) then
> ? write(6,*) "VAR ERROR"
> ? stop
> endif

> status = nf_get_var_real (ncid,varid,UDATA)
> if(status .ne. NF_NOERR) then
> ? write(6,*) "READ ERROR"
> ? stop
> endif

> status = nf_close(ncid)

> write(6,*) ncid,varid

> stop
> end
> *************************************************

> And then, I typed

> $ ifort -c -I/usr/local/netcdf-3.6.2/include 1st.f90
> $ ifort -lnetcdf -L/usr/local/netcdf-3.6.2/lib 1st.o -o a.out

> Then, I got these errors.


> 1st.o -o a.out
> 1st.o: In function `MAIN__':
> 1st.f90:(.text+0x46): undefined reference to `nf_open_'
> 1st.f90:(.text+0x76): undefined reference to `nf_inq_varid_'
> 1st.f90:(.text+0xa1): undefined reference to `nf_get_var_real_'
> 1st.f90:(.text+0x11a): undefined reference to `nf_close_'
> 1st.f90:(.text+0x30a): undefined reference to `handle_err_'

> If you know something about these errors, please give me information
> anything you have.

> Hiroshi

You should probably change the order of the arguments:

ifort -L/usr/local/netcdf-3.6.2/lib -lnetcdf 1st.o -o a.out

and you need additional libraries. Here is a compile/link command I
use
myself:

ifort -o program program.f90 -Inetcdf-4.0/f90 netcdf-4.0/f90/.libs/
libnetcdff90.a netcdf-4.0/fortran/.libs/libnetcdff.a netcdf-4.0/
libsrc/.libs/libnetcdf.a

Not the most efficient perhaps, but for my particular case it works.
As you can see you need a few more libraries.

Regards,

Arjen



Mon, 05 Sep 2011 20:04:19 GMT  
 Compilation program to read NetCDF file with fortran90

Quote:

> I am a student in Kyoto University in Kyoto, Japan.

> I want to read and write files in NetCDF, so at first I am going to
> read values of files written in NetCDF.
> The file to read is below.

> *********************************************
> implicit none
> include 'netcdf.inc'

> integer :: ncid,status,varid
> real,dimension(100,100,26) :: UDATA
> !real,dimension(99,99,27)   :: WDATA

> status   =  NF_OPEN ('wrfout_d01_2006-01-01_00:00:00',0,ncid)
> if (status .ne. NF_NOERR) call HANDLE_ERR(STATUS)

> status = nf_inq_varid (ncid, "U", varid)
> if (status .ne. NF_NOERR) then
>   write(6,*) "VAR ERROR"
>   stop
> endif

> status = nf_get_var_real (ncid,varid,UDATA)
> if(status .ne. NF_NOERR) then
>   write(6,*) "READ ERROR"
>   stop
> endif

> status = nf_close(ncid)

> write(6,*) ncid,varid

> stop
> end
> *************************************************

> And then, I typed

> $ ifort -c -I/usr/local/netcdf-3.6.2/include 1st.f90
> $ ifort -lnetcdf -L/usr/local/netcdf-3.6.2/lib 1st.o -o a.out

> Then, I got these errors.


> 1st.o -o a.out
> 1st.o: In function `MAIN__':
> 1st.f90:(.text+0x46): undefined reference to `nf_open_'
> 1st.f90:(.text+0x76): undefined reference to `nf_inq_varid_'
> 1st.f90:(.text+0xa1): undefined reference to `nf_get_var_real_'
> 1st.f90:(.text+0x11a): undefined reference to `nf_close_'
> 1st.f90:(.text+0x30a): undefined reference to `handle_err_'

> If you know something about these errors, please give me information
> anything you have.

> Hiroshi

You are trying to use the Netcdf F77 interface.  You can make it work,
but I recommend the F90 interface instead, since your main program is
F90.  See the Netcdf on-line documentation for the Fortran 90 API.

Also, check with your system administrator to make sure that the F90
interface is installed.  It is an optional part of Netcdf.  In
particular, make sure that the file netcdf.mod is available and
specified on your compile command line.

--Dave



Tue, 06 Sep 2011 01:16:24 GMT  
 Compilation program to read NetCDF file with fortran90

Quote:


>> And then, I typed

>> $ ifort -c -I/usr/local/netcdf-3.6.2/include 1st.f90
>> $ ifort -lnetcdf -L/usr/local/netcdf-3.6.2/lib 1st.o -o a.out

>> Then, I got these errors.


>> 1st.o -o a.out
>> 1st.o: In function `MAIN__':
>> 1st.f90:(.text+0x46): undefined reference to `nf_open_'
>> 1st.f90:(.text+0x76): undefined reference to `nf_inq_varid_'
>> 1st.f90:(.text+0xa1): undefined reference to `nf_get_var_real_'
>> 1st.f90:(.text+0x11a): undefined reference to `nf_close_'
>> 1st.f90:(.text+0x30a): undefined reference to `handle_err_'

>> If you know something about these errors, please give me information
>> anything you have.

>> Hiroshi

> You should probably change the order of the arguments:

> ifort -L/usr/local/netcdf-3.6.2/lib -lnetcdf 1st.o -o a.out

> and you need additional libraries. Here is a compile/link command I
> use
> myself:

> ifort -o program program.f90 -Inetcdf-4.0/f90 netcdf-4.0/f90/.libs/
> libnetcdff90.a netcdf-4.0/fortran/.libs/libnetcdff.a netcdf-4.0/
> libsrc/.libs/libnetcdf.a

> Not the most efficient perhaps, but for my particular case it works.
> As you can see you need a few more libraries.

Not for v3.6.2 he doesn't. You're using netCDF v4.0.

To the OP: Once you solve your link problems, why not try using the Fortran90 API to netCDF?

As an aside, I've been thinking about upgrading to v4.0 but the reason I use netCDF (as
opposed to, say, HDF) is that netCDF is simple (both the library build and usage). If the
above explosion of required libraries to use netCDF v4.0 is true, I may stick with the old
version (netCDF v3.6.x).

cheers,

paulv



Tue, 06 Sep 2011 21:59:15 GMT  
 Compilation program to read NetCDF file with fortran90

Quote:


> >> And then, I typed

> >> $ ifort -c -I/usr/local/netcdf-3.6.2/include 1st.f90
> >> $ ifort -lnetcdf -L/usr/local/netcdf-3.6.2/lib 1st.o -o a.out

> >> Then, I got these errors.


> >> 1st.o -o a.out
> >> 1st.o: In function `MAIN__':
> >> 1st.f90:(.text+0x46): undefined reference to `nf_open_'
> >> 1st.f90:(.text+0x76): undefined reference to `nf_inq_varid_'
> >> 1st.f90:(.text+0xa1): undefined reference to `nf_get_var_real_'
> >> 1st.f90:(.text+0x11a): undefined reference to `nf_close_'
> >> 1st.f90:(.text+0x30a): undefined reference to `handle_err_'

> >> If you know something about these errors, please give me information
> >> anything you have.

> >> Hiroshi

> > You should probably change the order of the arguments:

> > ifort -L/usr/local/netcdf-3.6.2/lib -lnetcdf 1st.o -o a.out

> > and you need additional libraries. Here is a compile/link command I
> > use
> > myself:

> > ifort -o program program.f90 -Inetcdf-4.0/f90 netcdf-4.0/f90/.libs/
> > libnetcdff90.a netcdf-4.0/fortran/.libs/libnetcdff.a netcdf-4.0/
> > libsrc/.libs/libnetcdf.a

> > Not the most efficient perhaps, but for my particular case it works.
> > As you can see you need a few more libraries.

> Not for v3.6.2 he doesn't. You're using netCDF v4.0.

> To the OP: Once you solve your link problems, why not try using the Fortran90 API to netCDF?

> As an aside, I've been thinking about upgrading to v4.0 but the reason I use netCDF (as
> opposed to, say, HDF) is that netCDF is simple (both the library build and usage). If the
> above explosion of required libraries to use netCDF v4.0 is true, I may stick with the old
> version (netCDF v3.6.x).

> cheers,

> paulv

For everyone, thanks for your attention.

The file I want to read is made by WRF (Weather Research and
Forecasting) model.
I built up WRF with NetCDF, and both were compiled with ifort and icc.
Can I use only F77 interface with default setting?

Hiroshi



Thu, 08 Sep 2011 20:18:20 GMT  
 Compilation program to read NetCDF file with fortran90

Quote:


> >> And then, I typed

> >> $ ifort -c -I/usr/local/netcdf-3.6.2/include 1st.f90
> >> $ ifort -lnetcdf -L/usr/local/netcdf-3.6.2/lib 1st.o -o a.out

> >> Then, I got these errors.


> >> 1st.o -o a.out
> >> 1st.o: In function `MAIN__':
> >> 1st.f90:(.text+0x46): undefined reference to `nf_open_'
> >> 1st.f90:(.text+0x76): undefined reference to `nf_inq_varid_'
> >> 1st.f90:(.text+0xa1): undefined reference to `nf_get_var_real_'
> >> 1st.f90:(.text+0x11a): undefined reference to `nf_close_'
> >> 1st.f90:(.text+0x30a): undefined reference to `handle_err_'

> >> If you know something about these errors, please give me information
> >> anything you have.

> >> Hiroshi

> > You should probably change the order of the arguments:

> > ifort -L/usr/local/netcdf-3.6.2/lib -lnetcdf 1st.o -o a.out

> > and you need additional libraries. Here is a compile/link command I
> > use
> > myself:

> > ifort -o program program.f90 -Inetcdf-4.0/f90 netcdf-4.0/f90/.libs/
> > libnetcdff90.a netcdf-4.0/fortran/.libs/libnetcdff.a netcdf-4.0/
> > libsrc/.libs/libnetcdf.a

> > Not the most efficient perhaps, but for my particular case it works.
> > As you can see you need a few more libraries.

> Not for v3.6.2 he doesn't. You're using netCDF v4.0.

> To the OP: Once you solve your link problems, why not try using the Fortran90 API to netCDF?

> As an aside, I've been thinking about upgrading to v4.0 but the reason I use netCDF (as
> opposed to, say, HDF) is that netCDF is simple (both the library build and usage). If the
> above explosion of required libraries to use netCDF v4.0 is true, I may stick with the old
> version (netCDF v3.6.x).

> cheers,

> paulv

For everyone, thanks for your attention.

The file I want to read is made by WRF (Weather Research and
Forecasting) model.
I built up WRF with NetCDF, and both were compiled with ifort and icc.
Can I use only F77 interface with default setting?

Hiroshi



Thu, 08 Sep 2011 20:18:36 GMT  
 Compilation program to read NetCDF file with fortran90

Quote:

> I am a student in Kyoto University in Kyoto, Japan.

> I want to read and write files in NetCDF, so at first I am going to
> read values of files written in NetCDF.
> The file to read is below.

> *********************************************
> implicit none
> include 'netcdf.inc'

> integer :: ncid,status,varid
> real,dimension(100,100,26) :: UDATA
> !real,dimension(99,99,27)   :: WDATA

> status   =  NF_OPEN ('wrfout_d01_2006-01-01_00:00:00',0,ncid)
> if (status .ne. NF_NOERR) call HANDLE_ERR(STATUS)

> status = nf_inq_varid (ncid, "U", varid)
> if (status .ne. NF_NOERR) then
>   write(6,*) "VAR ERROR"
>   stop
> endif

> status = nf_get_var_real (ncid,varid,UDATA)
> if(status .ne. NF_NOERR) then
>   write(6,*) "READ ERROR"
>   stop
> endif

> status = nf_close(ncid)

> write(6,*) ncid,varid

> stop
> end
> *************************************************

> And then, I typed

> $ ifort -c -I/usr/local/netcdf-3.6.2/include 1st.f90
> $ ifort -lnetcdf -L/usr/local/netcdf-3.6.2/lib 1st.o -o a.out

> Then, I got these errors.


> 1st.o -o a.out
> 1st.o: In function `MAIN__':
> 1st.f90:(.text+0x46): undefined reference to `nf_open_'
> 1st.f90:(.text+0x76): undefined reference to `nf_inq_varid_'
> 1st.f90:(.text+0xa1): undefined reference to `nf_get_var_real_'
> 1st.f90:(.text+0x11a): undefined reference to `nf_close_'
> 1st.f90:(.text+0x30a): undefined reference to `handle_err_'

> If you know something about these errors, please give me information
> anything you have.

> Hiroshi

Yes, you should be able to use only F77 interface.  Based on your
original post, I think you have at least three specific problems.  Arjen
addressed two of them, I will try to explain:

1.  -lnetcdf should be positioned to the right of the -L option.

2.  You may need a second library libnetcdff.  Try adding -lnetcdff to
your command.

3.  handle_error is a user-supplied subroutine.  Just insert this after
the end of your main program (untested):

subroutine handle_error (status)
   implicit none
   integer, intent (in) :: status
   print *, 'Netcdf error number = ', status
   stop
end subroutine handle_error

Here is a modification of your original compile commands.  Only the
second line is changed:

ifort -c -I/usr/local/netcdf-3.6.2/include 1st.f90
ifort -L/usr/local/netcdf-3.6.2/lib -lnetcdf -lnetcdff 1st.o -o a.out

First try this without -lnetcdff .  If you still get the missing symbol
errors for nf_open_ etc., then add -lnetcdff .  You may need to search
all file names under /usr/local/netcdf-3.6.2 to find this library, and
add a second -L command to give its correct path if different than the
one in the first -L option.

I am unsure about libnetcdff because they changed the Fortran API
library configuration somewhere around version 3.6.2 or 3.6.3.  The
Fortran library was split off into the separate library libnetcdff.
This is further complicated by a newly introduced configure option to
build the Fortran libraries either way.  I do not have all the details
memorized.   ;-)

You can examine the Netcdf library file(s) yourself to locate symbols
like nf_open_ which are part of the F77 interface.  Something like this,
it may vary between platforms:

  cd /usr/local/netcdf-3.6.2/lib
  nm libnetcdf* | grep nf_open_

If you can't figure this out here in c.l.f., then try the Netcdf users
list.  They are very helpful.

--Dave



Fri, 09 Sep 2011 01:59:38 GMT  
 Compilation program to read NetCDF file with fortran90

Quote:

> > I am a student in Kyoto University in Kyoto, Japan.

> > I want to read and write files in NetCDF, so at first I am going to
> > read values of files written in NetCDF.
> > The file to read is below.

> > *********************************************
> > implicit none
> > include 'netcdf.inc'

> > integer :: ncid,status,varid
> > real,dimension(100,100,26) :: UDATA
> > !real,dimension(99,99,27) ? :: WDATA

> > status ? = ?NF_OPEN ('wrfout_d01_2006-01-01_00:00:00',0,ncid)
> > if (status .ne. NF_NOERR) call HANDLE_ERR(STATUS)

> > status = nf_inq_varid (ncid, "U", varid)
> > if (status .ne. NF_NOERR) then
> > ? write(6,*) "VAR ERROR"
> > ? stop
> > endif

> > status = nf_get_var_real (ncid,varid,UDATA)
> > if(status .ne. NF_NOERR) then
> > ? write(6,*) "READ ERROR"
> > ? stop
> > endif

> > status = nf_close(ncid)

> > write(6,*) ncid,varid

> > stop
> > end
> > *************************************************

> > And then, I typed

> > $ ifort -c -I/usr/local/netcdf-3.6.2/include 1st.f90
> > $ ifort -lnetcdf -L/usr/local/netcdf-3.6.2/lib 1st.o -o a.out

> > Then, I got these errors.


> > 1st.o -o a.out
> > 1st.o: In function `MAIN__':
> > 1st.f90:(.text+0x46): undefined reference to `nf_open_'
> > 1st.f90:(.text+0x76): undefined reference to `nf_inq_varid_'
> > 1st.f90:(.text+0xa1): undefined reference to `nf_get_var_real_'
> > 1st.f90:(.text+0x11a): undefined reference to `nf_close_'
> > 1st.f90:(.text+0x30a): undefined reference to `handle_err_'

> > If you know something about these errors, please give me information
> > anything you have.

> > Hiroshi

> Yes, you should be able to use only F77 interface. ?Based on your
> original post, I think you have at least three specific problems. ?Arjen
> addressed two of them, I will try to explain:

> 1. ?-lnetcdf should be positioned to the right of the -L option.

> 2. ?You may need a second library libnetcdff. ?Try adding -lnetcdff to
> your command.

> 3. ?handle_error is a user-supplied subroutine. ?Just insert this after
> the end of your main program (untested):

> subroutine handle_error (status)
> ? ?implicit none
> ? ?integer, intent (in) :: status
> ? ?print *, 'Netcdf error number = ', status
> ? ?stop
> end subroutine handle_error

> Here is a modification of your original compile commands. ?Only the
> second line is changed:

> ifort -c -I/usr/local/netcdf-3.6.2/include 1st.f90
> ifort -L/usr/local/netcdf-3.6.2/lib -lnetcdf -lnetcdff 1st.o -o a.out

> First try this without -lnetcdff . ?If you still get the missing symbol
> errors for nf_open_ etc., then add -lnetcdff . ?You may need to search
> all file names under /usr/local/netcdf-3.6.2 to find this library, and
> add a second -L command to give its correct path if different than the
> one in the first -L option.

> I am unsure about libnetcdff because they changed the Fortran API
> library configuration somewhere around version 3.6.2 or 3.6.3. ?The
> Fortran library was split off into the separate library libnetcdff.
> This is further complicated by a newly introduced configure option to
> build the Fortran libraries either way. ?I do not have all the details
> memorized. ? ;-)

> You can examine the Netcdf library file(s) yourself to locate symbols
> like nf_open_ which are part of the F77 interface. ?Something like this,
> it may vary between platforms:

> ? cd /usr/local/netcdf-3.6.2/lib
> ? nm libnetcdf* | grep nf_open_

> If you can't figure this out here in c.l.f., then try the Netcdf users
> list. ?They are very helpful.

> --Dave

I've just been through the process of setting up read/write of netCDF
files using gfortran on Ubuntu 8.04.
First, I downloaded netCDF 4.0 sources, then CDed to the directory
and:
./configure
make
sudo su
make install

This generated and installed a static library in /usr/local/lib

Now to compile and link Test.f90 I do this:
gfortran -o Test Test.f90 /usr/local/lib/libnetcdf.a



Fri, 09 Sep 2011 03:20:10 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. reading netcdf data files with fortran

2. Reading Windows Binary File in MIPSPro Fortran90 on Unix

3. Reading Little-Endian Binary File in Fortran90

4. A problem to read a SEG-file using Fortran90 code on PC

5. non-gridded ASCII data file to netCDF data file

6. read netCDF data

7. NetCDF Files?

8. Reading program files from the directory.

9. VM/CMS Release 5 Assembler Program To Read Huge Files

10. reading multiple files into awk program

11. help sql error 47 in read file in program

12. C program for reading VRML-file ?

 

 
Powered by phpBB® Forum Software