示例#1
0
  /**
   * putData Put the item value in the currently opened DataItem
   *
   * @param dsData is a DataItem item (properly initiated), having dimensions, type and size
   *     corresponding to opened DataItem
   */
  protected void putData(DataItem dsData) throws NexusException {
    // Ensures the DataItem has an array value
    dsData.arrayify();

    // Getting data from DataItem
    Object iData = dsData.getData();

    // Converting from string to byte[]
    if (dsData.getType() == NexusFile.NX_CHAR) iData = ((String) iData).getBytes();

    // Converting from boolean[] to byte[]
    else if (dsData.getType() == NexusFile.NX_BOOLEAN) iData = convertArray(dsData);

    /* ******** Warning: jnexus API doesn't support NX_INT64 for writing
     *  those lines convert NX_INT64 into NX_FLOAT64, so long to double
    // Converting from long[] to double[]
    else if( dsData.getType() == NexusFile.NX_INT64 )
    {
      iData = convertArray(dsData);
      dsData.setType(NexusFile.NX_FLOAT64);
    }
     */

    // Putting data into opened DataItem
    getNexusFile().putdata(iData);
  }
示例#2
0
  /**
   * checkData Check if given data fits the currently opened DataItem
   *
   * @param dsData DataItem properly initiated containing data to compare with current node
   * @throws NexusException if node and data aren't compatible
   */
  protected void checkDataMatch(DataItem dsData) throws NexusException {
    // Get infos on DataItem (data type, rank, dimsize)
    int[] iDimSize = dsData.getSize(); // DataItem dimension's sizes
    int[] iNodSize = new int[RANK_MAX]; // whole DataItem dimension's sizes
    int[] iDataInf = new int[2]; // iDataInf[0] = DataItem rank ;
    // iDataInf[1] = data type
    openFile();
    getNexusFile().getinfo(iNodSize, iDataInf);
    closeFile();
    // Checking type compatibility
    if (dsData.getType() != iDataInf[1]) {
      throw new NexusException("Datas and target node do not have compatible type!");
    }
    // Checking rank compatibility
    if (iDimSize.length > iDataInf[0]) {
      throw new NexusException("Datas and target node do not have compatible rank!");
    }

    // Checking dimensions sizes compatibility
    {
      // The dimensions to check of the opened DataItem are
      // iDimSize.length
      // last ones
      int iDim = (iDataInf[0] - iDimSize.length);
      for (; iDim < iDataInf[0]; iDim++) {
        if (iDimSize[iDim + iDimSize.length - iDataInf[0]] != iNodSize[iDim])
          throw new NexusException("Datas and target node do not have compatible dimension sizes!");
      }
    }
  }
示例#3
0
  /**
   * readDataItem Return all datas and attributes of the currently opened DataItem
   *
   * @param iDataRank rank of the required data (1 spectrum, 2 images...) (optional)
   * @note if no rank is given, value of the DataItem will be return integrally: all slabs will be
   *     taken as one entire data
   */
  private DataItem readDataItem(int iDataRank) throws NexusException {
    DataItem dsData = readDataInfo();

    int[] dataInf = new int[] {dsData.getSize().length, dsData.getType()};
    Object data = readNodeValue(dataInf, dsData.getSize(), iDataRank);

    if (dsData.getType() == NexusFile.NX_CHAR) {
      dsData.setData(data);
    } else {
      dsData.setData(new SoftReference<Object>(data));
    }

    dsData.isSingleRawArray(m_bResultAsSingleRaw);

    return dsData;
  }
示例#4
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;
  }
示例#5
0
  /**
   * putAttr Write the attribute in the currently opened DataItem
   *
   * @param sAttrName name of the attribute
   * @param tData array of values for the attribute
   */
  @SuppressWarnings("unchecked")
  protected <type> void putAttr(String sAttrName, type tData) throws NexusException {
    Object tArrayData;
    if (!(tData instanceof String) && !tData.getClass().isArray()) {
      tArrayData = (type[]) java.lang.reflect.Array.newInstance(tData.getClass(), 1);
      java.lang.reflect.Array.set(tArrayData, 0, tData);
    } else tArrayData = tData;

    // Changing the array into a DataItem object to apply conversion methods if needed
    Object iData;
    DataItem dsData = new DataItem(tArrayData);

    // Converting from string to byte[]
    if (dsData.getType() == NexusFile.NX_CHAR) iData = ((String) dsData.getData()).getBytes();

    // Converting from boolean[] to byte[]
    else if (dsData.getType() == NexusFile.NX_BOOLEAN) iData = convertArray(dsData);

    /* ******** Warning: jnexus API doesn't support NX_INT64 for writing
     *  those lines convert NX_INT64 into NX_FLOAT64, so long to double
    // Converting from long[] to double[]
    else if( dsData.getType() == NexusFile.NX_INT64 )
    {
      iData = convertArray(dsData);
      dsData.setType(NexusFile.NX_FLOAT64);
    }
     */

    // Setting datas as they are
    else iData = dsData.getData();

    // Putting datas into the attribute
    getNexusFile().putattr(sAttrName, iData, dsData.getType());

    // Free ressources
    iData = null;
  }
示例#6
0
  /**
   * makeData Create a DataItem named sDataName that fit dsData in the currently opened group:
   * detecting type, size and dim
   *
   * @param sDataName name of the DataItem to create
   * @param oData shape of data that the DataItem will have to contain
   */
  protected void makeData(String sDataName, DataItem dsData) throws NexusException {
    /* ******** Warning: jnexus API doesn't support NX_INT64 for writing
     *  those lines convert NX_INT64 into NX_FLOAT64, so long to double
    // Converting long as double because the JAVA Nexus API uses C++ native methods whom don't support integer 64 bit
    if( dsData.getType() == NexusFile.NX_INT64 )
    {
      dsData.setData(convertArray(dsData));
      dsData.setType(NexusFile.NX_FLOAT64);
    }
     */
    long iLength = 1;
    int[] iDimSize = dsData.getSize();
    int iType = dsData.getType();
    int iRank = iDimSize.length;

    for (int i = 0; i < iRank; i++) {
      iLength *= iDimSize[i];
    }

    // Create the DataItem
    if (m_bCompressed && iLength > 1000 && iType != NexusFile.NX_CHAR) {
      getNexusFile()
          .compmakedata(sDataName, iType, iRank, iDimSize, NexusFile.NX_COMP_LZW, iDimSize);
    } else {
      getNexusFile().makedata(sDataName, iType, iRank, iDimSize);
    }

    // Update the buffer node list
    pushNodeInBuffer(sDataName, "SDS");

    // Init DataItem of type NX_CHAR
    if (iType == NexusFile.NX_CHAR) {
      openData(sDataName);
      Object oBuffer = defineArrayObject(iType, iDimSize);
      Arrays.fill((byte[]) oBuffer, (Byte) initTypeFromNexus(iType));
      getNexusFile().putdata(oBuffer);
      oBuffer = null;
      closeData();
    }
  }
示例#7
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;
  }