예제 #1
0
  protected DataItem getDataItem(int[] iStartPos, int[] iShape) throws NexusException {
    DataItem dsData = readDataInfo();

    NexusNode nnNode = getCurrentPath().getCurrentNode();
    String sNodeClass = nnNode.getClassName();
    if (!sNodeClass.equals("NXtechnical_data")) {
      dsData.setStart(iStartPos);
      dsData.setSlabSize(iShape);

      int[] iDataInf = new int[] {dsData.getSize().length, dsData.getType()};

      // We want a iNbDim dimension array of data, so dimensions are the
      // iNbDim last ones of the opened DataItem
      int[] length = {1};

      for (int iDim : iShape) {
        length[0] *= iDim;
      }

      // Prepare an array data
      Object oOutput;
      Object oInput = defineArrayObject(iDataInf[1], length);

      // Set data into temporary array having a single raw shape
      openFile();
      getNexusFile().getslab(iStartPos, iShape, oInput);
      closeFile();

      if (m_bResultAsSingleRaw) {
        oOutput = oInput;
      } else {
        // Changing the array into matrix (having iDimSize dimensions'
        // sizes) instead of single row
        oOutput = defineArrayObject(iDataInf[1], iShape);
      }

      // Converting byte[] to string in case of NX_CHAR data
      if (iDataInf[1] == NexusFile.NX_CHAR) {
        oOutput = new String((byte[]) oOutput).toCharArray();
      }

      // Setting DataItem's data
      if (iDataInf[1] == NexusFile.NX_BOOLEAN) {
        oOutput = convertArray(new DataItem(oOutput));
      }

      dsData.setData(new SoftReference<Object>(oOutput));
    }
    dsData.isSingleRawArray(m_bResultAsSingleRaw);
    return dsData;
  }
예제 #2
0
  /**
   * readDataInfo Return the DataItem fitting the opened DataItem, without main data. The DataItem
   * is initialized with dimsize, type... but the DataItem isn't read.
   */
  public DataItem readDataInfo() throws NexusException {
    NexusNode nnNode = getCurrentPath().getCurrentNode();
    if (!nnNode.isGroup() && nnNode.getClassName().equals("NXtechnical_data")) {
      return getDataItem();
    }

    // Get infos on DataItem (data type, rank, dimsize)
    int[] iNodeSize = new int[RANK_MAX]; // whole DataItem dimension's sizes
    int[] iDimSize; // data dimension's sizes
    int[] iDataInf = new int[2]; // iDataInf[0] = DataItem rank ;
    // iDataInf[1]= data type

    openFile();
    getNexusFile().getinfo(iNodeSize, iDataInf);

    // Initialize dimension's sizes
    iDimSize = new int[iDataInf[0]];
    System.arraycopy(iNodeSize, 0, iDimSize, 0, iDataInf[0]);

    // Check if DataItem is linked to an external DataItem
    DataItem dsData = new DataItem();
    dsData.setType(iDataInf[1]);
    dsData.setSize(iDimSize);
    dsData.setSlabSize(iDimSize);
    dsData.setStart(new int[iDimSize.length]);
    dsData.setNodeName(getCurrentPath().getDataItemName());
    dsData.setPath(getCurrentPath().clone());
    dsData.isSingleRawArray(m_bResultAsSingleRaw);

    if (dsData.getType() == NexusFile.NX_CHAR) {
      dsData.setData(readNodeValue(iDataInf, dsData.getSize(), iDimSize.length));
    }
    closeFile();

    // Initialize DataItem's attributes
    getDataItemAttribute(dsData);
    return dsData;
  }