Fortran interface for character strings

Some time ago I asked some leading questions about adding a string primitive
to NetCDF and complained a bit about the redundant call requirements on
fortran for the current "CHAR" data type.  The latter can be seen, for
example, in the Get Attribute Value call:

    in C:               ncattget(cdfid,varid,name,value);

    in Fortran:         call ncagt(cdfid,varid,attnam,values,rcode)
                        call ncagtc(cdfid,varid,attnam,string,lenstr,rcode)

Ok, I'll admit that for proper fortran, data *types* must agree across calls
so one needs two calls to separate out the character versus the nonchar
arguments.  The totally unecessary part is the "lenstr" variable.  The called
routine can do a "len(string)" to determine this information if needed.
If not, it can merely assume that enough space is available (like the c
code), and deal with the variable as "character*(*) string".

The NetCDF User's Guide (vers 1.11) on page 92 seems to imply that the
len function is not part of the f77 standard.  Fortran does indeed support
the concept of variable length character strings.  Instead of the object
having a well defined termination as in c (a null), there is a character
count implicit in each character string that is available to the user
via a len() built-in function.

  In general, all fortran routines with a special call for characters have
this totally unneeded parameter.  There seem to be four routines:
    ncvptc, ncvgtc, ncaptc, ncagtc
and all lurk in ./fortran/jackets.c

  My proposal is to modify these routines to use the native fortran
method of passing string length information.  The method in VMS is already
available if we look at ./fortran/vms/jackets.c  In this routine the
passing of characters by descriptor is already set up and in fact the
length parameter is already explicitly named in this routine. So, for
VMS, use the existing

    int         stringlen       = stringd->dsc$w_length;

variable instead of the passed *lenstr

  There is a corresponding solution in the ./fortran/msoft/fortran.c
which uses the built-in fslen to setup but not use stringlen.

  For unix systems, the answer depends just as does the nature of
the fortran to c binding.  For *most* systems this is accomplished by
the implicit passing of the string length by value after all other
arguments.  In some systems, the string length is passed by value
immediately after each character variable.  This is already set up
for the defined systems and the int stringlen is already defined
(but not used).




  • 1991 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: