NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: File Input

Hi Yuzhong,

> I have a binary file containing 2-D scalar data in raw format, I'd like
> to know how to read the file. Is there a class in VisAD that can read
> such raw file directly, or do I have to write codes in Java to read the
> file by myself? Thanks a lot.

VisAD has file readers for a variety of specific formats
(e.g., netCDF, HDF-5, McIDAS, GIF, etc) but for a new format
you'll need to write some code to read the file and build
a VisAD data object.  2-D scalar data shouldn't be too
difficult.  For example, if you read your data into an
array named "data" of size "float[nx][ny]" then you'd
construct a VisAD Data object like this:

  RealType x = new RealType("x");
  RealType y = new RealType("y");
  RealType scalar = new RealType("scalar");
  RealTupleType domain = new RealTupleType(new Real[] {x, y});
  FunctionType function_type = new FunctionType(domain, scalar);
  Integer2DSet domain_set = new Integer2DSet(nx, ny);
  FlatField field = new FlatField(function_type, domain_set);
  float[][] field_data = new float[1][nx * ny];
  int k = 0;
  for (int j=0; j<ny; j++) {
    for (int i=0; i<nx; i++) {
      field_data[0][k] = data[i][j];
      k++;
    }
  }
  field.setSamples(field_data);

Then you can visualize the "field" data object with
something like this:

  DisplayImplJ3D display = new DisplayImplJ3D("scalar display");
  display.addMap(new ScalarMap(x, Display.XAxis));
  display.addMap(new ScalarMap(y, Display.YAxis));
  display.addMap(new ScalarMap(scalar, Display.ZAxis));
  DataReference ref = new DataReferenceImpl("scalar data");
  ref.setData(field);
  display.addReference(ref);

Which should make a simple terrain surface.  Lots of other
possibilities exist.

Cheers,
Bill
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html


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