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

Re: netCDF subroutines



Hi Mike,

>       Hello.  I am working on a program that converts our gridded data 
> files into netCDF format, which can then be read in by VCS, Visualization
> and Computation System.  In the program, I include the line ( much of
> the program was given to me so I don't understand parts of it ) :
>   
>   call ncapt(ncid1,longitudeid,'source',NCCHAR,0,charval,iret)
> 
> Could you explain the meaning of charval and the subroutine ncapt?  

If you are trying to store a character-string attribute, you should be using
NCAPTC rather than NCAPT.  An on-line copy of the NetCDF Users Guide is
accessible with a WWW browser such as Netscape or Mosaic from

    http://www.unidata.ucar.edu/packages/netcdf/

In the chapter on Attributes, the NetCDF Users Guide says:

    There are two FORTRAN subroutines, NCAPT and NCAPTC, for creating
    attributes. The first is for attributes of numeric type, and the second
    is for attributes of character-string type.

The correct NCAPTC call should probably be something like

    call ncapt(ncid1,longitudeid,'source',NCCHAR,charvallen,charval,iret)
 
where charval is the character-string value of the attribute, declared with
something like

    CHARACTER*80 charval
   
The meaning of the 5th argument, charvallen, is described in the
documentation as:

    In NCAPTC, the total declared length (in characters) of the STRING
    parameter. Note that this is not necessarily the same as the value
    returned by the FORTRAN LEN function, because an array argument may be
    provided.

so in the case above it should be 80.

> Is there a way that I can look at the fortran code for ncapt and all the 
> other subroutines used by netCDF, such as ncaptc, ncvdef, etc..?

Yes, the source code for all of these is generated as part of the process of
building and installing netCDF from the netCDF source distribution, in the
file netcdf/fortran/jackets.c.  The source code for NCAPTC is not in
Fortran, but in C meant to be called from Fortran.  The file containing
source code for all the functions meant to be called from Fortran,
netcdf/fortran/jackets.c, is different for different platforms. It is
generated as part of the process of building netCDF from the file
netcdf/fortran/jackets.src that abstracts out what's common on all
platforms, with system-dependent differences isolated to *.m4 files in the
same directory.

> Charval is giving me trouble in the program since when I run the program, 
> the compilation stops and the computer says that charval was never defined.
> When I include the statement, CHARACTER*80 charval, the compilation works
> fine but I receive a 'bus error' when I run it.  DO you have any 
> recommendations?

You probably got a bus error because you gave the length of charval as "0"
(the 5th argument to NCAPT) and because you used a routine meant to be used
for numeric values (NCAPT) rather than character-string values (NCAPT).  I
recommend that you look at the example code in the NetCDF Users Guide that
shows an example of how each subroutine should be called, in the context of
the necessary declarations and other related calls.

If you need a printed copy of the NetCDF Users Guide, please supply us with
a mailing address and we will be happy to send you one.

______________________________________________________________________________

Russ Rew                                           UCAR Unidata Program
address@hidden                              http://www.unidata.ucar.edu