improper fortran casting
Jim Edwards
edwards.jim at gmail.com
Mon Mar 9 15:13:55 CDT 2009
In a declaration:
integer(kind=MPI_OFFSET), parameter :: one = 1
or inline:
int(1,kind=MPI_OFFSET)
On Mon, Mar 9, 2009 at 2:05 PM, Robert Latham <robl at mcs.anl.gov> wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/parallel-netcdf/attachments/20090309/f7a699e8/attachment.htm>
More information about the parallel-netcdf
mailing list