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

Re: mixed programming, C and Fortran and netcdf



>To: <address@hidden>
>From: "ufuk turuncoglu" <address@hidden>
>Subject: Re: 20040728:  mixed programming, C and Fortran and netcdf
>Organization: Informatics Institute, Istanbul Technical University
>Keywords: 200407281439.i6SEd0aW023381

Hi,

> i generate a netcdf file using C program but when i read the netcdf data
> from fortran, it comes wrong. I think, fortran (column) and c (row) stores
> array differently in memory and this generates problem. Is it possible to
> read data without any conversion (such as intercahage the data to fortran
> stored format)? If not, it means that netcdf formats depends on the creator
> programming language and it is not possible to always have information about
> it. Is there a way that solve the mixed language problem ? Why the netcdf
> library handles of this problem?

The netCDF library interfaces have been designed so that you can write
data in one language interface (for example C) and read it from
another (for example Fortran).  The data format is neutral to the
language used to write or read the data.  Another way of saying this
is that the on disk representation of the same data written from C,
Fortran, Java, or any other language interface will be bit-for-bit
identical.  In general, there is no way to tell from a netCDF file
what language was used to write it.

The C interface assumes the last dimensions varies fastest and the
Fortran interfaces assume the first dimension varies fastest.  This is
handled in the interface, just as is the characteristic that C
indices start at 0 and Fortran indices start at 1 by default.

The only place where an order for storing arrays shows through is
CDL, the text representation of netCDF files.  CDL had to use one
order or the other for declaring arrays and displaying data values,
so it uses C ordering, where the last dimension varies most rapidly.

But you can annotate CDL values in ncdump to see the corresponding
Fortran indices used for array values using the -bf or -ff options for
brief or full annotations, respectively.

If you have more questions about this, please send them to
address@hidden.

In particular, if you think you have an example of data written
through the C interface that is read incorrectly through the Fortran
interface, please send us that example and we'll try to determine what
the problem is.

--Russ

_____________________________________________________________________

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