Re: changing data in a field

Hello Adele,

I won't try to answer your second question because it's probably more
fun for you to work out a  more optimal way of calculating your
new values, but I can try to answer your first question. :)

In the ClassAverage.actionPerformed() method, instead of
just assigning the old field to the newly created one, you
need to tell the data reference that the data has changed.

There's no mention of a DataReferenceImpl, but I assume
that you've left it out to improve readability.

If you had:
DataReferenceImpl blurDataRef = new DataReferenceImpl( "blur_data_ref" );
blurDataRef.setData(pfield);

then, in your ClassAverage.actionPerformed() method, you would
need to do pass the new FlatField to the data reference. ie.
blurDataRef.setData(afield);

Hope this helps and answers your first question.
Jim.
---
Jim Koutsovasilis
Bureau of Meteorology, Australia
jimk@xxxxxxxxxx

Adele Cutler wrote:

Hi Everyone,

I have a FieldImpl:

RealType x = RealType.getRealType("coordinate");
RealType y = RealType.getRealType("value");
RealType col = RealType.getRealType("color");
RealType z = RealType.getRealType("density");
RealTupleType rxy = new RealTupleType(x,y);
RealTupleType zc = new RealTupleType(z,col);
FunctionType blur = new FunctionType(rxy,zc);
FunctionType ptype = new FunctionType(index, blur);
FieldImpl pfield = new FieldImpl(ptype, index_set);
for (int i=0; i<nrows; i++) {
     float[][] locs = new float[2][3*ncoords];
     float[][] coldens = new float[2][3*ncoords];
     // a bunch of stuff in here that creates locs and coldens
        Gridded2DSet set = new Gridded2DSet(rxy, locs, 3, ncoords);
        FlatField vals_ff = new FlatField(blur,set);
        vals_ff.setSamples( coldens , false );
        pfield.setSample(i, vals_ff, false);
}
// tons more code in here
ClassAverage ca = new ClassAverage(pfield, afield);
aveButton.addActionListener(ca);

When a button is pressed, I want to average locs[1][] over several subsets
of values of i, di similar things to coldens, and replace pfield with this
new (much smaller) FieldImpl. So, nrows might be several thousands, but the
new version of pfield may have only a handful of samples. I tried to do this
by creating a new FieldImpl, "afield", that holds the appropriate averages.
Then exchanging the two FieldImpls:

 class ClassAverage implements ActionListener {

   FieldImpl pfield;
   FieldImpl afield;

   ClassAverage(FieldImpl pfield, FieldImpl afield){
     this.pfield = pfield;
        this.afield = afield;
   }

   public void actionPerformed(ActionEvent e) {
     String cmd = e.getActionCommand();

     if (cmd.equals("ave")) {
       FieldImpl sfield = pfield;
       pfield = afield;
       afield = sfield;
     }
   }
 }

But nothing happens.

My first question is: how do I get pfield to change in the place where
ClassAverage is used.

My second question is: is there a better/easier/more efficient way to do
this?

Of course, the first question is moot if the answer to the second is "yes",
but right now I'll be delighted if anyone can help me with either!

Thanks

Adele






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