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

Re: 20020522: RE: 20020315: Question about nc files



>To: "'Unidata Support'" <address@hidden>
>cc: MELLION Gatien <address@hidden>
>From: MELLION Gatien <address@hidden>
>Subject: RE: 20020315: Question about nc files 
>Organization: UCAR/Unidata
>Keywords: 200205220910.g4M9AMa27562

Hi Gatien,

> I use NetCdf 3.4 and C++ API.
> 
> I created a toto.cdl valid file under Windows 2000. I use ncgen (compiled
> VC++ under Windows2000) to create a toto.nc file. My test program read this
> file. There's no problem when I run it under Windows 2000.
> 
> I ported Netcdf3.4 and my test program code under SGI. Compilation is ok. I
> put the toto.nc on my SGI disk, and when I run my test program, the integer
> fiels are correctly read. But the float fields are bad. They become good if
> I apply the Big2LittleEndian conversion (swap bytes). 
> 
> I believed this conversion was implicit with API Netcdf??
> 
> could you help me on this point?

You should never have to swap bytes with netCDF, and I'm surprised
this even worked.  NetCDF files use a platform-independent
representation that permits the same file to be read on little-endian
or big-endian platforms with identical results.  Therefor, either
there is a problem with the way ncgen was built on your Windows 2000
system, a problem with the way you transferred the file from the
Windows system to the SGI system, or a problem with the netCDF library
on your SGI system.

For some ideas of how this might happen, see these earlier replies to
similar netCDF support questions:

  http://www.unidata.ucar.edu/cgi-bin/mfs/70/3289
  http://www.unidata.ucar.edu/cgi-bin/mfs/70/3290
  http://www.unidata.ucar.edu/cgi-bin/mfs/70/3291

To isolate the problem, you can use the fact that a netCDF file
created on every platform should be identical, and should always begin
with the same 4 bytes:

   'C', 'D', 'F', 0x01

which in emacs looks like

   CDF

or using "od -c" on the SGI machine should look like:

   $ od -c owens1.nc
   0000000   C   D   F 001  ...

If the file created on the Windows machine begins with these 4 bytes
it's OK.  If the version of the file transferred to the SGI machine
still begins with these 4 bytes, it was probably transfered OK, etc.

> I use 
> 
>       float *ptrValeurs = (float *) pVar->values()->base();
> 
> to get my array of float. maybe I shouldn't.?

That looks like it should work OK.  There is an example,
src/cxx/nctst.cpp, in the netCDF source distribution that uses

        NcValues* vals = vp->values();

instead to get the array of values from the Variable vp.  Or you could
use the NcVar::get(float* vals, const long* counts) member function to
get a subset of the values or all the values if counts = vp->edges();

--Russ

_____________________________________________________________________

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