This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi Glenn, Thanks for the explanation of some of the netcdf/multiarray package details. I'm now a lot clearer on some of the package design issues. > The MultiArray framework actually allows you to avoid intermediate array > copies > altogether. The pattern of use is as follows. There is a MultiArray > that contains some numbers of interest that you are going to do something > with. > You isolate the numbers of interest (clipping, subsampling, and slicing) > using a MultiArrayProxy. Use the proxy's lengths to construct an > IndexIterator > to visit the numbers of interest, using the primitive MultiArray > get() or set() operations. This is pretty much what I'm doing at the moment (but without using the IndexIterator). Basically, I'm picking out 2d sections from a 3d Variable, using MultiArrayProxy, then constructing a 2d plot by looping over the 2d section and doing a get() call at each index. Something along the lines of: for ( int j = 0; j < height; j++ ) { for ( int i = 0; i < width; i++ ) { index[0] = j; index[1] = i; pixels[count++] = *** Some expression involving *** ma.getDouble(index) } } Essentially, my question is 'Can I avoid doing a getDouble call at every index, and instead do something like a single getAllDoubles() call which gets me all the primitive data in a single chunk?' Something like: double[] x = *** Somehow grab the contents of the full 2d array *** from ma in one go for ( int j = 0; j < height; j++ ) { for ( int i = 0; i < width; i++ ) { pixels[count++] = *** Some expression involving x[count] *** } } > Another aggregate copy is the MultiArrayImpl(MultiArray) constructor. > MultiArrayImpl exposesits internal storage, so java.lang.System.arraycopy() > can be used for aggregate copy into and out of a MultiArrayImpl. Aha. I think this is what I'm looking for!! Will try some tests on MultiArrayImpl. Basically I'm happy with the MultiArray framework, I think it expresses array manipulations in a very clean way, but I'm talking about that final step where we've now done all our various slicing/clipping/.. operations and we actually need to get out a piece of PRIMITIVE DATA to do some operation on, and the granularity of that data extraction process. Rather than just get the value at a single index out (and iterating over index values), I'd like to be able to grab with a single method call, say the first 10000 doubles into a double[], or ALL doubles in the MultiArray into a double[]. Anyway, thanks again for the info. I think that quite a few of the 'problems' that I've come across are actually just lack of familiarity with the packages on my part. Maybe some of this stuff could usefully go in a FAQ? Cheers Pete +--------------------------------------------------------+ | Pete Lockey, | Email: address@hidden | | Supercomputing Support, | | | Proudman Oceanographic Lab, | Tel: +44 151 653 8633 | | Bidston Observatory, | Fax: +44 151 653 6269 | | Birkenhead, L43 7RA, UK. | | +--------------------------------------------------------+