improper fortran casting
Robert Latham
robl at mcs.anl.gov
Mon Mar 9 15:05:49 CDT 2009
A question for the Fortran experts on this list:
We have a C routine with this prototype:
int ncmpi_put_att_int(int ncid, int varid, const char *name,
nc_type type, MPI_Offset nelems, const int *value)
(In this example, as would be by far the most common case, let's make
MPI_Offset an 8 byte value)
I run into problems when I call the fortran binding for the routine
like this:
integer ncid
integer ierr
integer n_elem
ierr = nfmpi_put_att_int(ncid, NF_GLOBAL, 'my_attribute', NF_INT, 1, n_elem)
The problem is that '1' there is treated as an array of MPI_Offset by
the C function, but passed to pnetcdf's fortran binding as an array of
integer (a 4 byte integer, at that). The C function recieves a
1-element array of MPI_Offset with contents of some enormous garbage
number.
If I define
integer(KIND=MPI_OFFSET_KIND) one
and pass that to nfmpi_put_att_int, then I have no problems.
To make life as easy as possible for our Fortran users, how can I get
Fortran to treat that constant '1' as an 8 byte value? In C, the
compiler consults the prototype and promotes the type.
Thanks
==rob
--
Rob Latham
Mathematics and Computer Science Division A215 0178 EA2D B059 8CDF
Argonne National Lab, IL USA B29D F333 664A 4280 315B
More information about the parallel-netcdf
mailing list