DXJava library usage examples


Read a DX file and print it's "Positions"

An example of how it might be used to write the data positions to the standard output is:



/*
COPYRIGHT NOTICE
Copyright (c) 2006  Craig Schwartz and Arthur W. Toga

See README.license for license notices.
*/
package examples;

import java.io.File;
import java.io.IOException;

import javax.imageio.stream.FileImageInputStream;

import edu.ucla.loni.ccb.dx.DXArray;
import edu.ucla.loni.ccb.dx.DXField;
import edu.ucla.loni.ccb.dx.DXFile;
import edu.ucla.loni.ccb.dx.DXFileReader;

public class ExampleOne
  {
    /**
     * Start the example. In input file name is 
     * expected to be in args[0];
     * 
     * @param args first parameter is the path to an OpenDX general format
     *             data file.
     */
    public static void main(String[] args)
      {
        DXField dxField = null;
        try {
          FileImageInputStream iis = new FileImageInputStream(new File(args[0]));
          // create a DX file reader
          DXFileReader dxReader = new DXFileReader(iis);
          // read the field from the input stream
          dxField = dxReader.readDX();
        }  catch (IOException e) {
          System.err.println("Cannot read input file. Reason is: " + 
              e.getMessage());
        }

        // get the "positions" component from the field
        // if it is part of the data field
        String componentName = DXFile.POSITIONS;
        String [] fieldComponents = dxField.getComponents();
        
        // This will either contain the "positions" compoent
        // array , or be null if no component named "positions" exists.
        DXArray positions = null;
        for (int i=0;i