[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netCDF #UFR-913429]: Error with nf90_create
- Subject: [netCDF #UFR-913429]: Error with nf90_create
- Date: Thu, 16 Oct 2014 10:53:13 -0600
Hi Manmeet,
I think both the problems you are seeing are due to not telling gfortran
where to find the declaration of functions provided by the netCDF-Fortran
library. If it doesn't know that the nf90_strerror() returns a character
string, then it will assume that the trim() function can't be used on its
return value.
For gfortran, you need to use the -I option to tell the compiler where to
find the necessary compiled Fortran modules, specifying the interface
types of all the functions and therri arguments.
When you built netCDF-Fortran, it should have installed the nf-config
in the bin/ subdirectory of wherever you specified with a --prefix=
option to the configure script. By default, this would be
/usr/local/bin/nf-config. Use that program to see what flags to use
when you compile Fortran programs to use netCDF. Try "nf-config --all"
or even use it on the command line, such as
gfortran myprogram.f90 -o myprogram `nf-config --fflags --flibs`
--Russ
nf-config
> I am trying to generate a netcdf file from my simulation using the sample
> example given on the website
> **************************************************************************************************************************************************************************************************
>
> This is part of the netCDF package.
> ! Copyright 2006 University Corporation for Atmospheric Research/Unidata.
> ! See COPYRIGHT file for conditions of use.
>
> ! This is a very simple example which writes a 2D array of
> ! sample data. To handle this in netCDF we create two shared
> ! dimensions, "x" and "y", and a netCDF variable, called "data".
>
> ! This example demonstrates the netCDF Fortran 90 API. This is part
> ! of the netCDF tutorial, which can be found at:
> ! http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-tutorial
>
> ! Full documentation of the netCDF Fortran 90 API can be found at:
> ! http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-f90
>
> ! $Id: simple_xy_wr.f90,v 1.7 2006/12/09 18:44:58 russ Exp $
>
> program simple_xy_wr
> use netcdf
> implicit none
>
> ! This is the name of the data file we will create.
> character (len = *), parameter :: FILE_NAME = "simple_xy.nc"
>
> ! We are writing 2D data, a 6 x 12 grid.
> integer, parameter :: NDIMS = 2
> integer, parameter :: NX = 6, NY = 12
>
> ! When we create netCDF files, variables and dimensions, we get back
> ! an ID for each one.
> integer :: ncid, varid, dimids(NDIMS)
> integer :: x_dimid, y_dimid
>
> ! This is the data array we will write. It will just be filled with
> ! a progression of integers for this example.
> integer :: data_out(NY, NX)
>
> ! Loop indexes, and error handling.
> integer :: x, y
>
> ! Create some pretend data. If this wasn't an example program, we
> ! would have some real data to write, for example, model output.
> do x = 1, NX
> do y = 1, NY
> data_out(y, x) = (x - 1) * NY + (y - 1)
> end do
> end do
>
> ! Always check the return code of every netCDF function call. In
> ! this example program, wrapping netCDF calls with "call check()"
> ! makes sure that any return which is not equal to nf90_noerr (0)
> ! will print a netCDF error message and exit.
>
> ! Create the netCDF file. The nf90_clobber parameter tells netCDF to
> ! overwrite this file, if it already exists.
> call check( nf90_create(FILE_NAME, NF90_CLOBBER, ncid) )
>
> ! Define the dimensions. NetCDF will hand back an ID for each.
> call check( nf90_def_dim(ncid, "x", NX, x_dimid) )
> call check( nf90_def_dim(ncid, "y", NY, y_dimid) )
>
> ! The dimids array is used to pass the IDs of the dimensions of
> ! the variables. Note that in fortran arrays are stored in
> ! column-major format.
> dimids = (/ y_dimid, x_dimid /)
>
> ! Define the variable. The type of the variable in this case is
> ! NF90_INT (4-byte integer).
> call check( nf90_def_var(ncid, "data", NF90_INT, dimids, varid) )
>
> ! End define mode. This tells netCDF we are done defining metadata.
> call check( nf90_enddef(ncid) )
>
> ! Write the pretend data to the file. Although netCDF supports
> ! reading and writing subsets of data, in this case we write all the
> ! data in one operation.
> call check( nf90_put_var(ncid, varid, data_out) )
>
> ! Close the file. This frees up any internal netCDF resources
> ! associated with the file, and flushes any buffers.
> call check( nf90_close(ncid) )
>
> print *, "*** SUCCESS writing example file simple_xy.nc! "
>
> contains
> subroutine check(status)
> integer, intent ( in) :: status
>
> if(status /= nf90_noerr) then
> print *, trim(nf90_strerror(status))
> stop "Stopped"
> end if
> end subroutine check
> end program simple_xy_wr
>
> ******************************************************************************************************************************************
>
> The change I have done is just increase the number of dimensions from
> 2 to 3. And the gfortran compiler is not picking up the nf90_create
> function somehow I have not been able to figure out. It is giving the
> error
>
> print *, trim(nf90_strerror(status))
> 1
> Error: 'string' argument of 'trim' intrinsic at (1) must be CHARACTER
>
> I believe this has something to do with the nf90_strerror function. Can you
> please help me out with this.
>
> Thanking You
>
> Manmeet Singh
> Trainee Scientist
> Indian Institute of Tropical Meteorology
> Pune, India
>
>
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
Ticket Details
===================
Ticket ID: UFR-913429
Department: Support netCDF
Priority: Normal
Status: Closed