[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fwd: Re: Problem Reading GRIB Data]



i read the file into ToolsUI, created geo grid and display the salinity
var in the viewer.  cool dataset.  the problem is his code and maybe his
approach to extracting the data.  so do you want to look at the code or do
you want me to make a small program at the grib level to extract the data
using the parameters from the grib file index?



On Thu, 5 May 2005, John Caron wrote:

> can you have a first look
>
> -------- Original Message --------
> Subject:      Re: Problem Reading GRIB Data
> Date:         Thu, 5 May 2005 16:07:17 +0100
> From:         Adityarajsingh Santokhee <address@hidden>
> Organization:         UCAR/Unidata
> To:   John Caron <address@hidden>
> References:   <address@hidden>
> <address@hidden>
>
>
>
> Hello John,
>
> The GRIB file can be downloaded from:
>
>  http://www.nerc-essc.ac.uk/~ads/FOAM_atl19_anal.130502.scal.grb
>
> Version of jar file: 2.2.08
>
>
> Java Program used:
>
> import ucar.nc2.*;
> import ucar.ma2.*;
> import ucar.nc2.dataset.*;
>
> import java.io.*;
> import java.util.*;
> import java.text.DateFormat;
> import java.text.SimpleDateFormat;
>
>
> public class Test2netcdf
> {
>
>     public void readData(NetcdfDataset ncFile, int numDimensions, int[] start,
> int[] stride, int[] count)
>     {
>         try
>         {
>               String variableName = "Salinity";
>               Variable var = ncFile.findVariable(variableName);
>
>               List myList = new ArrayList();
>               for (int i = 0; i < numDimensions; i++)
>               {
>                       int lastElement = start[i] + (count[i] - 1) * stride[i];
>                       myList.add(i, new Range(start[i], lastElement, 
> stride[i]));
>               }
>
>               /*
>               this is the original range definition
>               myList.add(0, new Range(0, 0, 1));
>               myList.add(1, new Range(0, 19, 1));
>               myList.add(2, new Range(0, 629, 1));
>               myList.add(3, new Range(0, 899, 1));
>               */
>
>
>               Calendar calendar = Calendar.getInstance();
>               long start1 = calendar.getTimeInMillis();
>
>               Array arr = var.read(myList);
>               //Array subsetArr = arr.sectionNoReduce(myList);
>
>               Calendar calendar2 = Calendar.getInstance();
>               long end1 = calendar2.getTimeInMillis();
>
>               long timeTaken = end1 - start1;
>               System.out.println("Time Taken (ms) :  " + timeTaken);
>
>               // Get the data as an array of floats
>               //float[] data = (float[])subsetArr.copyTo1DJavaArray();
>               /*
>               int[] myShape = arr.getShape();
>               for (int i=0; i<myShape.length; i++)
>                       System.out.println("Shape :  " + myShape[i]);
>               */
>
>               ncFile.close();
>         }
>         catch(Exception ioe)
>         {
>               ioe.printStackTrace();
>         }
>     }
>
>
>
>
>       public static void main (String[] args)
>       {
>               try
>               {
>                       Test2netcdf myTest = new Test2netcdf();
>
>                       String [] filenames =
>                       {
>                               "130502/FOAM_atl19_anal.130502.scal.grb"
>                       };
>
>
>                       for (int i=0; i<filenames.length; i++)
>                       {
>
>                               String path = 
> "/data/cadfael/marine/FOAM/FOAM_9th/" + filenames[i];
>                               NetcdfDataset ds = 
> NetcdfDataset.openDataset(path);
>
>                               int[] start  = {0,0,0,0};
>                               int[] stride = {1,1,1,1};
>                               int[] count  = {1,1,2,2};
>                               myTest.readData(ds,4,start,stride,count);
>                        }
>               }
>               catch (Exception e)
>               {
>                       e.printStackTrace();
>               }
>       }
> }
>
>
>
> Cheers,
>
> Adit
>
>
>
>
>
>
>
>
>
>
> Quoting John Caron <address@hidden>:
>
> > Adityarajsingh Santokhee wrote:
> >
> > >Hello,
> > >
> > >I am trying to read a variable's data from a GRIB file. The
> > read(java.util.List
> > >section) function is giving an array out of bounds error message for any
> > >section apart from the whole range. Are there any workarounds to this
> > problem
> > >or should I load whole data for that variable and then do subsetting. This
> > >might be a problem if I have to read hundred's of files.
> > >
> > >Error Message:
> > >
> > >java.lang.ArrayIndexOutOfBoundsException: 4
> > >        at ucar.ma2.ArrayFloat.setFloat(ArrayFloat.java:193)
> > >        at ucar.ma2.IteratorFast.setFloatNext(IteratorFast.java:61)
> > >        at
> > >ucar.nc2.iosp.grib.GribServiceProvider.readXY(GribServiceProvider.java:177)
> > >        at
> >
> >ucar.nc2.iosp.grib.GribServiceProvider.readLevel(GribServiceProvider.java:150)
> > >        at
> >
> >ucar.nc2.iosp.grib.GribServiceProvider.readData(GribServiceProvider.java:134)
> > >        at ucar.nc2.NetcdfFile.readData(NetcdfFile.java:848)
> > >        at ucar.nc2.Variable._read(Variable.java:737)
> > >        at ucar.nc2.Variable.read(Variable.java:451)
> > >        at ucar.nc2.dataset.VariableDS._read(VariableDS.java:206)
> > >        at ucar.nc2.Variable.read(Variable.java:451)
> > >        at ucar.nc2.dataset.VariableDS._read(VariableDS.java:206)
> > >        at ucar.nc2.Variable.read(Variable.java:475)
> > >        at Test2netcdf.readData(Test2netcdf.java:76)
> > >        at Test2netcdf.main(Test2netcdf.java:128)
> > >
> > >
> > >Cheers,
> > >
> > >Adit.
> > >
> > >
> > >----------------------------------------------------------------
> > >This message was sent using IMP, the Internet Messaging Program.
> > >
> > >
> > Hi Adit:
> >
> > send us the file or URL to the file so we can try to reproduce the
> > problem. also, what version of jar file are you using ? (see README
> > inside it)
> >
> >
>
>
> -----------------------------------------------------------------------
>  Adityarajsingh Santokhee         Tel: +44 118 378 5213 (direct line)
>  eScience Data Manager            Tel: +44 118 378 8741 (ESSC)
>  Reading e-Science Centre         Fax: +44 118 378 6413
>  ESSC                             Email: address@hidden
>  University of Reading
>  3 Earley Gate
>  Reading RG6 6AL, UK
>
> -----------------------------------------------------------------------
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
>

===============================================================================
Robb Kambic                                Unidata Program Center
Software Engineer III                      Univ. Corp for Atmospheric Research
address@hidden             WWW: http://www.unidata.ucar.edu/
===============================================================================


NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.