[netcdf-java] Using Netcdf-Java in Servlet to access THREDDS Dataset

Hi,

 

I am a newbie for NetCDF-Java library. I try to use this library in the
Servlet environment to access THREDDS nc aggregation datasets. Here are some
codes I put together:

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

Set<Enhance> DATASET_ENHANCEMENTS =EnumSet.of(Enhance.ScaleMissingDefer,
Enhance.CoordSystems);

NetcdfDataset nc=NetcdfDataset.openDataset(

                        "MY_THREDDS_URL",
DATASET_ENHANCEMENTS,

                        -1,                                       null, 

                        null 

                        );

List<Variable> l=nc.getVariables();

//close NetcdfDataset before accessing data

nc.close();

Variable vv=null;

for(Variable v:l)

{

    if(v.getName().equals("time"))

    {

        vv=v;

        break;                

    }

}

Array arr;

List<Range> ranges=new ArrayList<Range>();

try {

    r = new Range(8759,8759);

    ranges.add(r);

    arr=vv.read(ranges);

} catch (InvalidRangeException e) {

      e.printStackTrace();

}

 

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

 

Three questions regarding to the codes above:

      1.   Are the codes above the typical way to access THREDDS data?

2.   If yes, it seems OK for reading the data from a variable after
"NetcdfDataset" is closed. Is it valid?

3.      If the THREDDS dataset is an archive (static, no update), can I
cache the instance of Variable class as a member variable of the Servlet
class? In other words, are the operations on Variable class thread-safe?

 

Thanks a lot!

 

Guan

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