Re: [netcdf-java] Documentation or Direction on defining dimensions of variables in DODSNetcdfFile

Greetings Jake,

Give this a try:

-------------------

import ucar.nc2.NetcdfFile;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.Variable;
import ucar.ma2.*;
import java.io.IOException;
import java.util.ArrayList;

public class OpenDapTst {
    public static void main(String args[]) {
        try{
            NetcdfFile ncfile =
             
NetcdfDataset.openFile("http://nomads.ncdc.noaa.gov/thredds/dodsC/ruc13/201110/20111018/ruc2_130_20111018_1300_000.grb2";,
 null);
            Variable v = ncfile.findVariable("Temperature");
            Array data = null;
            try {
                //
                // This is the magic you are looking for!
                //
                data = v.read("0,2,100,300");
            } catch (InvalidRangeException e) {
                e.printStackTrace();  //To change body of catch statement use 
File | Settings | File Templates.
            }
            //
            // The following two lines are the proper way
            //   to index into the array
            //
            //Index idx = data.getIndex();
            //float val = data.getFloat(idx.set0(0));
            //
            // The following line will do the trick if you know that you
            //   will be getting a scalar back
            //
            float val = data.getFloat(0);
            System.out.format("The value of val is: %f%n", val);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

-------------------

Let me know if this works for you. Cheers!

Sean

On Fri, 21 Oct 2011, John Caron wrote:

> Hi Jake:
>
> Look at
>
> http://www.unidata.ucar.edu/software/netcdf-java/tutorial/NetcdfFile.html
> http://www.unidata.ucar.edu/software/netcdf-java/tutorial/NetcdfDataset.html
>
> especially the "Reading Data" in the first.
>
> The only difference for opendap is using NetcdfDataset.openFile()
> instead of NetcdfFile.open(), eg:
>
> NetcdfDataset.openFile("http://nomads.ncdc.noaa.gov/thredds/dodsC/ruc13/201110/20111018/ruc2_130_20111018_1300_000.grb2";,
> null);
>
> John
>
> On 10/20/2011 9:17 PM, Jake Sheck wrote:
> > UCAR NetCDF mail group,
> >
> > I am working on acquiring small amounts of GFS, NAM and RUC data from 
> > nomads.ncdc.noaa.gov.  As a test I am trying to collect the Temperature 
> > variable for a particular point.  I can easily acquire this data via my web 
> > browser with this link.  
> > http://nomads.ncdc.noaa.gov/thredds/dodsC/ruc13/201110/20111018/ruc2_130_20111018_1300_000.grb2.asc?Temperature[0][2][100][300]
> >
> > I would like to collect this variable via the netcdf java library.  However 
> > I can't seem to find documentation on the correct use of the dimensions 
> > variables in the readSection or readArrays methods of the DODSNetcdfFile.  
> > Could anyone please direct me to documentation for these?  I have found 
> > that even when I specifiy dimenions for a variable it still downloads the 
> > complete grid and takes much longer than the link above.
> >
> > Here is an example of what I am trying to do.
> >
> > String modelFile = 
> > "http://nomads.ncdc.noaa.gov/thredds/dodsC/ruc13/201110/20111018/ruc2_130_20111018_1300_000.grb2";;
> > DODSNetcdfFile ncfile = new DODSNetcdfFile( modelFile );
> >
> > Dimension time = new Dimension("time", 1);
> >                  Dimension pressure = new Dimension("pressure",1);
> >                  Dimension xd = new Dimension("x", 126);
> >                  Dimension yd = new Dimension("y", 557);
> >
> >                  List<Dimension>  ds = new ArrayList<Dimension>();
> >                  ds.add(time);
> >                  ds.add(pressure);
> >                  ds.add(xd);
> >                  ds.add(yd);
> >
> > for(Variable v : ncfile.getVariables()){
> >        if(v.getName.equals("Temperature_height_above_ground"))
> >               preloadVariables.add(v);
> > }
> >
> >
> > List<Array>  arrays = ncfile.readArrays( preloadVariables );
> >
> > Here I get the variable for temperature, but I get the whole set, and not a 
> > set limited by the dimensions that I set.
> >
> > Thanks
> > Jacob Sheck
> >
> >
> > CONFIDENTIALITY NOTICE: This e-mail message is for the sole use of the 
> > intended recipient(s) and may contain confidential and privileged 
> > information. Any unauthorized review, use, disclosure or distribution of 
> > any kind is strictly prohibited. If you are not the intended recipient, 
> > please contact the sender via reply e-mail and destroy all copies of the 
> > original message. Thank you.
> >
> > _______________________________________________
> > netcdf-java mailing list
> > netcdf-java@xxxxxxxxxxxxxxxx
> > For list information or to unsubscribe, visit: 
> > http://www.unidata.ucar.edu/mailing_lists/
>
> _______________________________________________
> netcdf-java mailing list
> netcdf-java@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe, visit: 
> http://www.unidata.ucar.edu/mailing_lists/
>



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