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

20040728: netCDF: solaris - mixed programming, C and Fortran



>From: "ufuk utku turuncoglu" <address@hidden>
>Organization: Istanbul Technical University
>Keywords: 200407281433.i6SEX60H002441 netCDF file format

Ufuk,

>Institution: istanbul technical university
>Package Version: 3.5
>Operating System: solaris
>Hardware Information: sunfire 12 k
>Inquiry: hi,

I apologize that I have not been able to get to your inquiry before today.

>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.

Yes, the Fortran and C conventions for array elements is different.

>Is it possible to read data without any conversion (such as intercahage
>the data to fortran stored format)?

Data is written to a netCDF file using the C convention and it matches
the convention used in CDLs.

Here are two comments from the netCDF Users Guide:

 ...

  "In FORTRAN, the dimensions are reversed from the CDL declaration
  with the first dimension varying fastest and the record dimension
  as the last dimension of a record variable."

 ...

  "Different dimension orders for the C, FORTRAN, or other language
  interfaces do not reflect a different order for values stored on the
  disk, but merely different orders supported by the procedural
  interfaces to the languages.  In general, it does not matter whether
  a netCDF dataset is written using the C, FORTRAN, or other language
  interface; netCDF datasets written from any supported language may be
  read by programs in other supported languages."

This means that you need to read data back from a netCDF making
adjustments for the interface (C or Fortran) you are using.  You do
not, however, have to worry about how the file was created.

>If not, it means that netcdf formats depends on the creator programming
>language and it is not possible to always have information about it.

The format in the file does not depend on the language the developer
was using; it is always done the same.

>Is there way that solve the mixed language problem?

Yes, you need to read the data from a netCDF knowing that it is written
using the array ordering of C.

>Why the netcdf library handles of this problem? 

The storage ordering matches the CDL syntax ordering which matches the
C ordering and that, in turn, matches the ordering in memory. It is
unfortunate that C and FORTRAN don't use the same ordering for array
elements in memory; programmers must take that into account when doing
mixed language programming.

In order to become better familiar with the issues involved, I would
suggest reviewing:

NetCDF User's Guide for C
http://my.unidata.ucar.edu/content/software/netcdf/guidec/index.html

NetCDF User's Guide for FORTRAN
http://my.unidata.ucar.edu/content/software/netcdf/guidef/index.html

>best regards,

Cheers,

Tom Yoksas
--
NOTE: All email exchanges with Unidata User Support are recorded in the
Unidata inquiry tracking system and then made publically available
through the web.  If you do not want to have your interactions made
available in this way, you must let us know in each email you send to us.