Re: visad field

Hello Isaac,

according to the email header, you have only sent your question to
me, instead of the list.  So, I'm cc-ing the list in my reply. :)

I have not used the TextAdapter, so I am not sure if the ordering
of the column headers is important.  ie. perhaps the second line
in the data file needs to be:
isotopicMass, pi, Ratio, name(text)
which follows the order of the field's math-type on the first line...

Before sending this email, I wrote some sample code and tested
it.  The ordering of the column names does not matter. :)

Note that the sample code is attached.  Place it in the same
directory as your data-file and run "java TestAdapter".

The sample code extracts each column into its own array.
It then prints the values out for each sample.

Hope this helps,
Jim.
---
Jim Koutsovasilis
Bureau of Meteorology, Australia
jim@xxxxxxxxxx <mailto:jim@xxxxxxxxxx>



Brobbey,Isaac wrote:

hi all,

i am having a little problem with how to retrive back my data from a field;

i have the following data in a file called flat54xe.txt

(isotopicMass, pi) -> (Ratio,name(Text)) Ratio, isotopicMass, pi,name(Text) 50 0 0 "ACTINA_HUMAN"
50 25000  0 "ACTINW_HUMAN"
50 25000  0 "ACTINQ_HUMAN"
50 0 0 "ACTINR_HUMAN"
50 0 0 "ACTINZ_HUMAN"
50 25000 14 "ACTINM_HUMAN"

then i make a field out of the file by doing
final FieldImpl fieldx
     (FieldImpl) new TextAdapter("flat54xe.txt").getData();

can you show me how to get back all the first column values(that is the
50's), then the second, followed by the third?
i have the following but it doesn't work:

for (int i=0; i<ratiox.length; i++) {
            Tuple data = (Tuple)fieldx.getSamples(i);
          double[][]   ratiox =data.getValues();
        System.out.println("i = "+i+"  ratiox = "+ratiox[0][i]);
        }
i want to get all the data back from the field
thank you hope to hear from you soon

Isaac



// Java
import java.io.IOException;
import java.rmi.RemoteException;

// VisAD
import visad.FieldImpl;
import visad.Real;
import visad.Set;
import visad.Text;
import visad.Tuple;
import visad.VisADException;
import visad.data.text.TextAdapter;


/**
 * A simple class to illustrate the use of a TextAdapter.
 */
public class TestAdapter {

        public static final void main( String [] args_IN )
                throws VisADException, RemoteException, IOException
        {

                final TextAdapter adapter = new TextAdapter( "flat54xe.txt" );
                final FieldImpl fieldx = (FieldImpl) adapter.getData();



                
                final int numSamples = fieldx.getLength();

                final float [] isotopicMassValues = new float[numSamples];
                final float [] piValues = new float[numSamples];
                final double [] ratioxValues = new double[numSamples];
                final String [] nameValues = new String[numSamples];

                // Get the domain samples.
                final Set set = fieldx.getDomainSet();
                final float [][] domainSamples = set.getSamples();

                // For each sample, extract the domain and
                // range values into separate arrays.
                for (int i=0; i<numSamples; i++)
                {

                        isotopicMassValues[i] = domainSamples[0][i];
                        piValues[i] = domainSamples[1][i];

                        // Get the range-data for this sample in the field.
                        final Tuple data = (Tuple)fieldx.getSample(i);

                        // Extract the "ratiox" value from the range-data.
                        final Real ratiox = (Real) data.getComponent(0);
                        ratioxValues[i] = ratiox.getValue();

                        // Extract the "name" value from the range-data.
                        final Text name = (Text) data.getComponent(1);
                        nameValues[i] = name.getValue();

                } // for (i<numSamples)

                for ( int j = 0; j < numSamples; ++j )
                {
                        System.out.println( "Sample " + j +
                                ": isotopicMass = " + isotopicMassValues[j] +
                                ", pi = " + piValues[j] +
                                ", ratiox = " + ratioxValues[j] +
                                ", name = " + nameValues[j]
                                );

                } // for (j<numSamples)

        } // TestAdapter.main()

} // class TestAdapter


// EndOfFile


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