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

Re: long's, short's and absence of int's



> Organization: NCAR/SCD
> Keywords: 199407190016.AA04150 netCDF NC_INTEGER

Hi Ethan,

>       Are there plans to include an NC_INTEGER type to netCDF? It seems
> like this would be needed now that machines like the alpha have 2,4 and 8
> byte integers.

No, but there are plans to eventually add NC_HYPERINT or something like that
for 64-bit ints, when they are supported on most platforms and by XDR.  The
current version of netCDF works on the DEC Alpha with the NC_LONG type
associated with 32-bit integers.  The interface still requires that
these are declared "long" so that netCDF client code is portable to Alpha
platforms as well as other platforms.  We have provided for forward and
backward compatibility by defining a new typedef, "nclong", that can be used
to declare data associated with the NC_LONG netCDF type.  Here's the
explanation from the announcement notes for netCDF 2.3.2:

        * The FORTRAN interface has been ported to DEC's new (64-bit) Alpha 
          platform (this completes the port to that platform);

    You should know, however, that the port of the FORTRAN interface to DEC's
    64-bit Alpha machine uncovered an ambiguity in the netCDF specification.
    In order to allow the writing of portable netCDF code, we have decided,
    after considerable discussion, to make a slight change to the netCDF
    specification.  This change will not affect the operation or portability
    of existing or future netCDF code that is not intended to run on machines
    such as DEC's Alpha.  netCDF code for which such a machine is a possible
    platform, however, should be modified or written to adhere to the new
    specification.

    The change is the introduction of a new data type, which is defined in the
    netCDF header file `netcdf.h'.  This new data type is `nclong'.  Maximally
    portable C code should use this data type to hold all values of type
    NC_LONG.  For example:

            #include "netcdf.h"
            ...
            int    ncid, lid, status, dimids[NDIM];
            long   start[NDIM], count[NDIM];
            nclong data[SIZE];              /* NB: new datatype */
            ...
            lid    = ncvardef(ncid, "somelongvar", NC_LONG, dimids);
            ...
            status = ncvarput(ncid, lid, start, count, data);
            ...
            status = ncvarget(ncid, lid, start, count, data);

    Note that only variables for NC_LONG values should have type `nclong'.
    Other, traditionally `long' variables (such as the `count' and `start'
    vectors for hyperslab access) should remain as C `long's.

    FORTRAN programmers needn't worry about this change because portable
    FORTRAN code only has INTEGER values to play with (and not, for example,
    INTEGER*4, which is a non-portable datatype).  Thus, no change to the
    FORTRAN netCDF interface specification is required.

    This is the extent of the change.  The rest of this message gives the
    rationale for the change.

    The netCDF implementation and interface assume that a C `long' maps
    naturally into the 32 bit external integer representation of an NC_LONG.
    This is rooted in historical networking code traceable to the BSD functions
    ntohl() and htonl().

    With the introduction of DEC's Alpha machine, we are seeing reasons to
    question this.  The Alpha has 64 bit `long's and 32 bit `int's.  The
    natural and efficient choice for a C datatype which maps to an NC_LONG
    would, therefore, be `int' rather than `long'.  (We have encountered 64 bit
    `long's before on the Cray, but there the `int' is also 64 bits, so there
    is no advantage to using different types).

    Furthermore, on the Alpha, the FORTRAN INTEGER type is 32 bits; therefore,
    keeping the C type as `long' for NC_LONG values would add costly
    transformations to the FORTRAN interface on this platform.

    On all platforms known to us (with the exception of the Alpha) the typedef
    for the new `nclong' datatype is

            typedef long nclong;

    and existing netCDF code will run without modification.  On the Alpha,
    however, the `nclong' typedef is

            typedef int nclong;

    We realize that changes to the interface specification are a hassle.  The
    alternative in this case is to burden the Alpha platform (and any future
    system which makes similar design decisions) with greater memory usage and
    poor FORTRAN performance.

> BTW, I sent a message to support about 2-3 weeks ago and didn't get a
> response other than my message was being forwarded.

Sorry, this was forwarded to me and got mixed in with about 200 messages I
had to answer after getting back from vacation.  I've found it and will try
to compose a reply later today. Thanks for the reminder.

--
Russ Rew                                                   UCAR Unidata Program
address@hidden                                             P.O. Box 3000
http://www.unidata.ucar.edu/                             Boulder, CO 80307-3000