Re: [Fwd: Bug?]

Hi Richard:

Yep, that's a bug, thanks for tracking it down.

Since you're working with source code, why dont you just modify your source with the following. It will take me a while to roll out a new release.


   * Create a new Array by copying this Array to a new one with given shape
   * @param shape the new shape
   * @return the new Array
   * @exception IllegalArgumentException a and b are not conformable
  public Array reshape( int [] shape) {
    ArrayAbstract result = factory( this.getElementType(), shape);
    if (result.getSize() != getSize())
throw new IllegalArgumentException("reshape arrays must have same total size");

    ArrayAbstract.arraycopy( this, 0, result, 0, (int) getSize());
    return result;

   * Cover for System.arrayCopy()
   * @param arraySrc: copy from here
   * @param srcPos: starting at
   * @param arrayDst: copy to here
   * @param dstPos: starting at
   * @param len: number of elements to copy
static public void arraycopy( ArrayAbstract arraySrc, int srcPos, ArrayAbstract arrayDst, int dstPos, int len) { System.arraycopy( arraySrc.getStorage(), srcPos, arrayDst.getStorage(), dstPos, len);

thanks again!

Subject: Bug?
Date: Wed, 9 Oct 2002 07:33:31 -0400
From: Gonzalez Richard Capt AFIT/ENP <Richard.Gonzalez@xxxxxxxx>
Organization: UCAR/Unidata
To: "Don Murray (E-mail)" <dmurray@xxxxxxxxxxxxxxxx>

Howdy and Good Morning,

If I have a 2D parameter, I'm trying to just copy the JGrib 1D array to a
ucar.ma2.ArrayFloat.1D, and then reshaping the 1D array to a 2D array with
size xSize by ySize. The reshape command fails, even though the storage has the exact number of elements because MAMath.copy checks to see if the 1D and
2D arrays are "conformable" where it compares only the ranks, which seems
wrong to me since the whole purpose of the reshape method is to change the

Here is the chunk of code I'm attempting.  Is there something wrong here?
                  int[] gridSize = new int[2];
                  gridSize[0] = xSize;
                  gridSize[1] = ySize;
                  ArrayFloat.D2 arr2d = new ArrayFloat.D2 (xSize,ySize);
                  record2 = (GribRecord)levelData.get(0);
                  ArrayFloat.D1 arr1d = new ArrayFloat.D1(xSize*ySize);
                  arr2d = (ArrayFloat.D2)arr1d.reshape(gridSize);

This is where the actual failure comes from:
  /** Check that two array shapes are conformable.
   *  The shapes must match exactly, except that dimensions of length 1 are
   *  @return true if conformable
  public static boolean conformable(int [] shapeA, int [] shapeB) {
    if (reducedRank(shapeA) != reducedRank( shapeB))
      return false;

I can simply copy the elements myself, but I was trying to use the methods
in ma2 to do it.  Do you see my error?

  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: