previous up next print clean
Next: Other primitive vectors Up: Vectors Previous: Vectors

Regularly sampled function

An example of a concrete vector is a SEP data cube, a set of real values on a regular grid. In Java, the Rsf (Regular Sampled Function) class stores a SEP data cube as a native Java array. An Rsf supports all vector methods that are implied by the mathematical definition of a vector. For example, the expression data1.add(data2)[*] adds vector data2 to vector data1 by adding the underlying array elements. Or data1.scale(alpha) scales all elements of vector data1 by the floating point number alpha.

The Rsf vector space, RsfSpace is an array of axes. Each axes object knows its number of samples n1, its increment d1, its offset o1, its physical unit, and a label. An RsfSpace can identify an equal vector space by checking the other spaces type (RsfSpace or not) and, in the case of an RsfSpace, by comparing their individual axes. Furthermore, an RsfSpace object gives access to its axes and their parameters.

In most cases, an Rsf and its space are created with the help of an existing Rsf or by invoking a method that reads a traditional SEPlib file from a file or input stream. In return, Rsfs can write their contents to a file or output stream in SEP IO format. Using SEPLib format allows us to use the existing SEPlib programs for preprocessing and graphical display. We also wrote a simple Matlab IO method.

The progVector[*] class creates two Rsf, one from a local SEPlib file and the other one from an URL that points to a SEPlib file. The program adds the two vectors and scales the result. Finally, it writes the result to a local file.

The class fragment progNmo[*] implements the NMO operator's arithmetic core. In the beginning, the apply method queries various axis parameters from the vector space object of a given Vector x. Later the operator accesses the Rsf vector elements through array referencing.

 

package book.web;
import  rsf.vector.*;
import  java.net.*;
import  java.io.*;

public class progVector { public static void main(String[] args) { // Read data from a stanford URL and from a local file "cmp.HH" Rsf data1 = new Rsf(); try { URL data = new URL("http://sepwww.stanford.edu/matt/book/web/cmp.HH"); data1 = RsfFactory.newRsf(data.openStream()); } catch (Exception e) { System.err.println(e); } Rsf data2 = new Rsf("./cmp.HH"); // data1 = data1 + data2; data1 = data1 / |data1| data1.add(data2); data1.scale( 1f / data1.norm() ); // Write data1 to a file "out.H" data1.write("./out.H"); } }

We feel that geophysical algorithms require simple data indexing for clarity and performance. Since Java does not allow the overloading of its indexing operator [], we decided to permit native access to an Rsf's vector elements. Unfortunately, such native access violates the object-oriented goal of encapsulation; the class access depends on the classes internal representation. For example, we currently experiment with two Rsf versions: An RsfF uses a Java one-dimensional array to store all its elements. A programmer writes a simple arithmetic indexing expression, dat(i1 + i2 * n1), to access an element. Alternatively, RsfC uses a multi-dimensional array and a programmer writes the standard indexing expression dat[i2][i1]. Additionally, both Rsf versions offer a programmer a pair of encapsulating indexing methods, float getDatum(int[] index) and void setValue(int[] index, float value). We currently favor the multi-dimensional array implementation of Rsf.


previous up next print clean
Next: Other primitive vectors Up: Vectors Previous: Vectors
Stanford Exploration Project
11/11/1997