コード例 #1
0
ファイル: NexusFileReader.java プロジェクト: nhauser/cdma
  protected DataItem getDataItem(int iRank) throws NexusException {
    DataItem dataItem;
    NexusNode nnNode = getCurrentPath().getCurrentNode();
    String sNodeName = nnNode.getNodeName();
    String sNodeClass = nnNode.getClassName();

    // If encountered a DataItem get its datas
    if (!nnNode.isGroup() && !sNodeClass.equals("NXtechnical_data")) {
      dataItem = readDataItem(iRank);
      dataItem.setNodeName(sNodeName);

      return dataItem;
    }
    // else if we encountered a NXtechnical_data group: we get its "data"
    // and "description"
    else if (!nnNode.isGroup() && sNodeClass.equals("NXtechnical_data")) {
      // Get the "data" node
      openData("data");
      dataItem = readDataItem(iRank);
      dataItem.setNodeName(sNodeName);
      closeData();
      // Try to get a description for the technical data
      try {
        // Set to "data" as description attribute the "description" node
        // beside
        openData("description");
        dataItem.setDesc(readDataItem(iRank).getData());
        closeData();
      } catch (NexusException ne) {
        closeData();
      }
      dataItem.setPath(getCurrentPath().clone());

      return dataItem;
    } else {
      return null;
    }
  }
コード例 #2
0
ファイル: NexusFileWriter.java プロジェクト: nhauser/cdma
  protected void createPath(PathNexus paPath, boolean bKeepOpen) throws NexusException {
    String sCurClass = ""; // Class name of the group we are processing
    String sCurName = ""; // Name of the group we are processing
    NexusNode nCurStep = null; // Currently opened node name in the NexusFile
    int iCurDepth = 0; // Current depth in the path
    int iPathDepth = paPath.getDepth();

    // Return to root node
    closeAll();

    // Create each group
    NexusNode nnNode;
    while (iCurDepth < iPathDepth) {
      // Determine group and class names
      nnNode = paPath.getNode(iCurDepth);
      sCurName = nnNode.getNodeName();
      sCurClass = nnNode.getClassName();

      // Create appropriate group and open it
      nCurStep = getCurrentRealPath().getCurrentNode();
      if (nnNode.isGroup() || "NXtechnical_data".equals(nnNode.getClassName())) {
        try {
          openGroup(sCurName, sCurClass);
        } catch (NexusException ne) {
          // Ensure we are still in the expected group
          if (nCurStep != null && !nCurStep.equals(getCurrentRealPath().getCurrentNode()))
            closeGroup();

          // Create the requested group
          getNexusFile().makegroup(sCurName, sCurClass);

          // Force the buffer node list to be updated
          pushNodeInBuffer(sCurName, sCurClass);

          // Open created group
          openGroup(sCurName, sCurClass);
        }
      }
      // Go one step forward in path
      iCurDepth++;
    }

    // Return to root node if necessary
    if (!bKeepOpen) closeAll();
  }
コード例 #3
0
ファイル: NexusFileReader.java プロジェクト: nhauser/cdma
  /** getDescendantsDatas Read all DataItems that are descendants of the currently opened group */
  protected Stack<DataItem> getDescendantsDatas() throws NexusException {
    Stack<DataItem> sDatas = new Stack<DataItem>();

    // Get all direct descendants' datas
    sDatas.addAll(getChildrenDatas());

    // Get all direct descendants group
    ArrayList<NexusNode> nodes = listChildren();

    // Start recursion
    for (NexusNode node : nodes) {
      if (node.isGroup()) {
        openNode(node);
        sDatas.addAll(getDescendantsDatas());
        closeGroup();
      }
    }

    return sDatas;
  }
コード例 #4
0
ファイル: NexusFileReader.java プロジェクト: nhauser/cdma
  /**
   * getChildrenDatas Scan currently opened group, to get all direct descendants' DataItem and
   * instrument informations (such as NXtechnical_data). Then return a list of DataItem.
   *
   * @throws NexusException
   */
  @SuppressWarnings("unchecked")
  protected Stack<DataItem> getChildrenDatas() throws NexusException {
    // Defining variables
    NexusNode node;
    ArrayList<NexusNode> alNodeList;
    Stack<DataItem> alDataItem = new Stack<DataItem>();

    // Parse children
    alNodeList = (ArrayList<NexusNode>) listChildren().clone();
    for (int iIndex = 0; iIndex < alNodeList.size(); iIndex++) {
      node = alNodeList.get(iIndex);
      if (!node.isGroup()) {
        openData(node.getNodeName());
        alDataItem.push(getDataItem());
        closeData();
      }
    }
    alDataItem.trimToSize();
    return alDataItem;
  }
コード例 #5
0
ファイル: NexusFileWriter.java プロジェクト: nhauser/cdma
  /**
   * CopyNode make a full copy of the current source node (itself and its descendants) into the
   * currently opened destination path. The copy cares of all nodes' attributes.
   *
   * @param nfrSource handler on the opened source file
   */
  protected void copyNode(NexusFileReader nfrSource) throws NexusException {
    // Keep in buffer current path (used for recursion process)
    PathNexus pnSrcPath = nfrSource.getCurrentRealPath().clone();
    PathNexus pnTgtPath = getCurrentRealPath().clone();
    NexusNode nnCurNode = pnSrcPath.getCurrentNode();

    if (getCurrentRealPath().getCurrentNode() != null
        && !getCurrentRealPath().getCurrentNode().isRealGroup())
      throw new NexusException(
          "Invalid destination path: only a group can contain nodes!\n" + getCurrentRealPath());

    // Check the kind of the node
    if (nnCurNode == null
        || nnCurNode.isGroup()
        || "NXtechnical_data".equals(nnCurNode.getClassName())) {
      // Copy the current group
      PathNexus pnPath = pnTgtPath.clone();
      if (nnCurNode != null) pnPath.pushNode(nnCurNode);
      createPath(pnPath, true);
      copyAllAttr(nfrSource);

      // Copy all its descendants
      ArrayList<NexusNode> nodes = nfrSource.listChildren();
      for (NexusNode node : nodes) {
        nfrSource.openNode(node);
        copyNode(nfrSource);
      }
    } else {
      // Copy the current DataItem
      PathData pdDstPath = new PathData(pnTgtPath.getNodes(), nnCurNode.getNodeName());
      DataItem dsData = nfrSource.getDataItem();
      writeData(dsData, pdDstPath);
    }

    // Return back to the original position in both source and destination files
    closeAll();
    openPath(pnTgtPath);
    nfrSource.closeAll();
    nfrSource.openPath(pnSrcPath.getParentPath());
  }
コード例 #6
0
ファイル: NexusFileReader.java プロジェクト: nhauser/cdma
  /**
   * 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;
  }