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

Re: netCDF Java question...



Matt,

> I was able to write a simple copy program using the netCDF (v1) Java library.
> 
> However, I would like to know if there is some way of reading
> multidimensional
> variables (like time,X,Y,Z) out of one netCDF file, writing them directly to
> a new netCDF file.  Do you know if there is some high performance way of
> doing this in either version 1 or 2 of the netCDF Java library?  Currently, I
> 
> am using toArray() to read the data from the source file and it puts it in
> a 1d array.  I am having to convert the 1d array to a multidimensional array
> then use ArrayMultiArray to copyin() the data.  This process is very time
> consuming.  Do know of some way where I could take the data in as a 1d
> array, then write it out using the 1d array?

A really high-performance variable copy method would just copy the
bytes from the source file to the destination file, without bothering
to decode from XDR to native representation and then encode again
before writing to disk.  This would violate all the encapsulation, but
might be an appropriate optimization to do inside the package where
the details of the disk representation are known.  For non-record
variables, it would just copy a single block of contiguous bytes,
whereas for a record variable, it would need to do one copy for each
record.  However, no methods exist currently in either version 1 or 2
to do this.

In version 1, I'm afraid I don't know of any way to avoid the
inefficiency you are encountering.  I had thought the copyin() method
could take values from a 1D array, but it looks like that isn't the
case.  However, there's a reply to a support message dealing with a
very similar problem in version 1 that might give you a lead on how to
avoid the inefficiency you are seeing, if you want to continue to use
the version 1 interface.

  
http://www.unidata.ucar.edu/projects/coohl/mhonarc/MailArchives/netcdf/msg02956.html

I believe it's possible to do what you want more efficiently in
version 2, and am CC:ing John Caron for further advice on this.
Version 2 at least has a reshape() method in ucar.ma2.Array that makes
it easy to change the shape of an array.

--Russ